diff options
Diffstat (limited to 'sdnr/wt/devicemanager-onap/openroadm71/provider/src/main/java')
11 files changed, 1621 insertions, 0 deletions
diff --git a/sdnr/wt/devicemanager-onap/openroadm71/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm71/impl/DeviceManagerOpenroadmImpl.java b/sdnr/wt/devicemanager-onap/openroadm71/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm71/impl/DeviceManagerOpenroadmImpl.java new file mode 100644 index 000000000..9feee5171 --- /dev/null +++ b/sdnr/wt/devicemanager-onap/openroadm71/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm71/impl/DeviceManagerOpenroadmImpl.java @@ -0,0 +1,103 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ +package org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm71.impl; + +import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.factory.FactoryRegistration; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NetconfNetworkElementService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author Shabnam Sultana + * + * Class to initialize the OpenRoadm Device Manager + **/ +public class DeviceManagerOpenroadmImpl implements AutoCloseable { + + // variables + private static final Logger LOG = LoggerFactory.getLogger(DeviceManagerOpenroadmImpl.class); + private static final String APPLICATION_NAME = "DeviceManagerOpenRoadm"; + @SuppressWarnings("unused") + private static final String CONFIGURATIONFILE = "etc/devicemanager-opeenroadm.properties"; + private NetconfNetworkElementService netconfNetworkElementService; + private HtDatabaseClient htDatabaseClient; + private Boolean devicemanagerInitializationOk = false; + private FactoryRegistration<OpenroadmNetworkElementFactory> resOpenRoadm; + // end of variables + + // Blueprint begin + // constructors + public DeviceManagerOpenroadmImpl() { + LOG.info("Creating provider for {}", APPLICATION_NAME); + resOpenRoadm = null; + } + // end of constructors + + // public methods + public void setNetconfNetworkElementService(NetconfNetworkElementService netconfNetworkElementService) { + this.netconfNetworkElementService = netconfNetworkElementService; + } + + public void init() throws Exception { + + LOG.info("Session Initiated start {}", APPLICATION_NAME); + + resOpenRoadm = netconfNetworkElementService.registerBindingNetworkElementFactory(new OpenroadmNetworkElementFactory()); + + + netconfNetworkElementService.writeToEventLog(APPLICATION_NAME, "startup", "done"); + this.devicemanagerInitializationOk = true; + + LOG.info("Session Initiated end. Initialization done {}", devicemanagerInitializationOk); + } + // Blueprint end + + @Override + public void close() throws Exception { + LOG.info("closing ..."); + close(htDatabaseClient); + close(resOpenRoadm); + LOG.info("closing done"); + } + // end of public methods + + // private methods + /** + * Used to close all Services, that should support AutoCloseable Pattern + * + * @param toClose + * @throws Exception + */ + private void close(AutoCloseable... toCloseList) { + for (AutoCloseable element : toCloseList) { + if (element != null) { + try { + element.close(); + } catch (Exception e) { + LOG.warn("Fail during close: ", e); + } + } + } + } + // end of private methods +} diff --git a/sdnr/wt/devicemanager-onap/openroadm71/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm71/impl/InitialDeviceAlarmReader.java b/sdnr/wt/devicemanager-onap/openroadm71/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm71/impl/InitialDeviceAlarmReader.java new file mode 100644 index 000000000..5a9beaf9a --- /dev/null +++ b/sdnr/wt/devicemanager-onap/openroadm71/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm71/impl/InitialDeviceAlarmReader.java @@ -0,0 +1,159 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ +package org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm71.impl; + +import java.util.Collection; +import java.util.List; +import java.util.Optional; +import org.eclipse.jdt.annotation.NonNull; +import org.onap.ccsdk.features.sdnr.wt.common.YangHelper; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.FaultData; +import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor; +import org.opendaylight.mdsal.common.api.LogicalDatastoreType; +import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev200529.ActiveAlarmList; +import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev200529.Severity; +import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev200529.active.alarm.list.ActiveAlarms; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Faultlog; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SeverityType; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author Shabnam Sultana + * + * Class to read the initial alarms at the time of device registration + * + **/ + +public class InitialDeviceAlarmReader { + // variables + // in fact there is no alarm counter in the alarm obj, we have to do it on our own globally per device + private Integer alarmCounter = 1; + private static final Logger log = LoggerFactory.getLogger(InitialDeviceAlarmReader.class); + private final NetconfBindingAccessor netConfAccesor; + private final @NonNull FaultService faultEventListener; + private final DataProvider dataProvider; + // end of variables + + // constructors + public InitialDeviceAlarmReader(NetconfBindingAccessor accessor, DeviceManagerServiceProvider serviceProvider) { + this.netConfAccesor = accessor; + this.faultEventListener = serviceProvider.getFaultService(); + this.dataProvider = serviceProvider.getDataProvider(); + } + // end of constructors + + // protected methods + // Mapping the alarm data with the fault data + protected FaultData writeFaultData() { + FaultData faultData = new FaultData(); + Optional<ActiveAlarmList> list = this.getActiveAlarmList(this.netConfAccesor); + if (list.isPresent() && list.get().getActiveAlarms() != null) { + Collection<ActiveAlarms> activeAlarms = YangHelper.getCollection(list.get().getActiveAlarms()); + if (!activeAlarms.isEmpty()) { + for (ActiveAlarms activeAlarm : activeAlarms) { + faultData.add(this.netConfAccesor.getNodeId(), this.alarmCounter, activeAlarm.getRaiseTime(), + activeAlarm.getResource().getDevice().getNodeId().getValue(), + activeAlarm.getProbableCause().getCause().getName(), + checkSeverityValue(activeAlarm.getSeverity())); + this.alarmCounter++; + } + return faultData; + } + } + return faultData; + } + + // Write into the FaultLog + protected void writeAlarmLog(FaultData faultData) { + if (faultData != null) { + List<Faultlog> faultLog = faultData.getProblemList(); + for (Faultlog fe : faultLog) { + this.dataProvider.writeFaultLog(fe); + } + } + } + + // Use the FaultService for Alarm notifications + protected void faultService() { + this.faultEventListener.initCurrentProblemStatus(this.netConfAccesor.getNodeId(), writeFaultData()); + writeAlarmLog(writeFaultData()); + } + // Mapping Severity of AlarmNotification to SeverityType of FaultLog + protected static SeverityType checkSeverityValue(Severity severity) { + SeverityType severityType = null; + log.info("Device Severity: {}", severity.getName()); + + switch (severity.getName()) { + case ("warning"): + severityType = SeverityType.Warning; + break; + case ("major"): + severityType = SeverityType.Major; + break; + case ("minor"): + severityType = SeverityType.Minor; + break; + case ("clear"): + severityType = SeverityType.NonAlarmed; + break; + case ("critical"): + severityType = SeverityType.Critical; + break; + case ("indeterminate"): + severityType = SeverityType.Critical; + break; + default: + severityType = SeverityType.Critical; + break; + + } + return severityType; + + } + // end of protected methods + + // private methods + + // Read Alarm Data + private Optional<ActiveAlarmList> getActiveAlarmList(NetconfBindingAccessor accessor) { + final Class<ActiveAlarmList> classAlarm = ActiveAlarmList.class; + log.info("Get Alarm data for element {}", accessor.getNodeId().getValue()); + InstanceIdentifier<ActiveAlarmList> alarmDataIid = InstanceIdentifier.builder(classAlarm).build(); + + ActiveAlarmList alarmData = accessor.getTransactionUtils().readData(accessor.getDataBroker(), + LogicalDatastoreType.OPERATIONAL, alarmDataIid); + + log.info("AlarmData {}", alarmData); + return Optional.ofNullable(alarmData); + } + + + // end of private methods + + + +} diff --git a/sdnr/wt/devicemanager-onap/openroadm71/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm71/impl/OpenroadmChangeNotificationListener.java b/sdnr/wt/devicemanager-onap/openroadm71/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm71/impl/OpenroadmChangeNotificationListener.java new file mode 100644 index 000000000..d65017c51 --- /dev/null +++ b/sdnr/wt/devicemanager-onap/openroadm71/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm71/impl/OpenroadmChangeNotificationListener.java @@ -0,0 +1,130 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ +package org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm71.impl; + +import java.util.List; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.NetconfTimeStampImpl; +import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor; +import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.WebsocketManagerService; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.IetfNetconfNotificationsListener; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfCapabilityChange; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfConfigChange; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfConfirmedCommit; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfSessionEnd; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfSessionStart; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.netconf.config.change.Edit; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogBuilder; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * @author Shabnam Sultana + * + * Listener for change notifications + * + **/ +public class OpenroadmChangeNotificationListener implements IetfNetconfNotificationsListener { + + // variables + private static final Logger log = LoggerFactory.getLogger(OpenroadmChangeNotificationListener.class); + private final NetconfAccessor netconfAccessor; + private final DataProvider databaseService; + private final WebsocketManagerService notificationServiceService; + // end of variables + + // constructors + public OpenroadmChangeNotificationListener(NetconfAccessor netconfAccessor, DataProvider databaseService, + WebsocketManagerService notificationService) { + this.netconfAccessor = netconfAccessor; + this.databaseService = databaseService; + this.notificationServiceService = notificationService; + } + // end of constructors + + // public methods + @Override + public void onNetconfConfirmedCommit(NetconfConfirmedCommit notification) { + log.info("onNetconfConfirmedCommit {} ", notification); + this.notificationServiceService.sendNotification(notification, this.netconfAccessor.getNodeId(), + NetconfConfirmedCommit.QNAME, NetconfTimeStampImpl.getConverter().getTimeStamp()); + } + + @Override + public void onNetconfSessionStart(NetconfSessionStart notification) { + log.info("onNetconfSessionStart {} ", notification); + this.notificationServiceService.sendNotification(notification, this.netconfAccessor.getNodeId(), + NetconfSessionStart.QNAME, NetconfTimeStampImpl.getConverter().getTimeStamp()); + + } + + @Override + public void onNetconfSessionEnd(NetconfSessionEnd notification) { + log.info("onNetconfSessionEnd {}", notification); + this.notificationServiceService.sendNotification(notification, this.netconfAccessor.getNodeId(), + NetconfSessionEnd.QNAME, NetconfTimeStampImpl.getConverter().getTimeStamp()); + } + + @Override + public void onNetconfCapabilityChange(NetconfCapabilityChange notification) { + log.info("onNetconfCapabilityChange {}", notification); + this.notificationServiceService.sendNotification(notification, this.netconfAccessor.getNodeId(), + NetconfCapabilityChange.QNAME, NetconfTimeStampImpl.getConverter().getTimeStamp()); + } + + @Override + public void onNetconfConfigChange(NetconfConfigChange notification) { + log.info("onNetconfConfigChange (1) {}", notification); + StringBuffer sb = new StringBuffer(); + List<Edit> editList = notification.nonnullEdit(); + for (Edit edit : editList) { + if (sb.length() > 0) { + sb.append(", "); + } + sb.append(edit); + + EventlogBuilder eventlogBuilder = new EventlogBuilder(); + + InstanceIdentifier<?> target = edit.getTarget(); + if (target != null) { + eventlogBuilder.setObjectId(target.toString()); + log.info("TARGET: {} {}", target.getClass(), target.getTargetType()); + for (PathArgument pa : target.getPathArguments()) { + log.info("PathArgument {}", pa); + } + } + eventlogBuilder.setNodeId(netconfAccessor.getNodeId().getValue()); + eventlogBuilder.setNewValue(String.valueOf(edit.getOperation())); + databaseService.writeEventLog(eventlogBuilder.build()); + } + log.info("onNetconfConfigChange (2) {}", sb); + this.notificationServiceService.sendNotification(notification, this.netconfAccessor.getNodeId(), + NetconfConfigChange.QNAME, NetconfTimeStampImpl.getConverter().getTimeStamp()); + + } + + // end of public methods + +} diff --git a/sdnr/wt/devicemanager-onap/openroadm71/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm71/impl/OpenroadmDeviceChangeNotificationListener.java b/sdnr/wt/devicemanager-onap/openroadm71/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm71/impl/OpenroadmDeviceChangeNotificationListener.java new file mode 100644 index 000000000..3263e1de2 --- /dev/null +++ b/sdnr/wt/devicemanager-onap/openroadm71/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm71/impl/OpenroadmDeviceChangeNotificationListener.java @@ -0,0 +1,129 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ +package org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm71.impl; + +import java.util.List; +import org.eclipse.jdt.annotation.NonNull; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.NetconfTimeStamp; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.NetconfTimeStampImpl; +import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor; +import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.WebsocketManagerService; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.ChangeNotification; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.CreateTechInfoNotification; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.OrgOpenroadmDeviceListener; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.OtdrScanResult; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.change.notification.Edit; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SourceType; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author Shabnam Sultana + * + * Listener for Open roadm device specific change notifications + **/ + +public class OpenroadmDeviceChangeNotificationListener implements OrgOpenroadmDeviceListener { + // variables + private static final Logger log = LoggerFactory.getLogger(OpenroadmDeviceChangeNotificationListener.class); + private Integer counter = 1; + private final NetconfAccessor netconfAccessor; + private final DataProvider databaseProvider; + private final WebsocketManagerService notificationServiceService; + private static final NetconfTimeStamp ncTimeConverter = NetconfTimeStampImpl.getConverter(); + // end of variables + + // constructors + public OpenroadmDeviceChangeNotificationListener(NetconfAccessor netconfAccessor, DataProvider databaseService, + WebsocketManagerService faultService) { + this.netconfAccessor = netconfAccessor; + this.databaseProvider = databaseService; + this.notificationServiceService = faultService; + } + // end of constructors + + // public methods + @Override + public void onOtdrScanResult(OtdrScanResult notification) { + // TODO Auto-generated method stub + + } + + @Override + public void onChangeNotification(ChangeNotification notification) { + log.info("onDeviceConfigChange(1){}", notification); + StringBuffer sb = new StringBuffer(); + + @NonNull + List<Edit> editList = notification.nonnullEdit(); + for (Edit edit : editList) { + if (sb.length() > 0) { + sb.append(", "); + } + sb.append(edit); + EventlogBuilder eventlogBuilder = new EventlogBuilder(); + InstanceIdentifier<?> target = edit.getTarget(); + if (target != null) { + eventlogBuilder.setObjectId(target.getPathArguments().toString()); + log.info("TARGET: {} {}", target.getClass(), target.getTargetType()); + for (PathArgument pa : target.getPathArguments()) { + log.info("PathArgument {}", pa); + } + eventlogBuilder.setAttributeName(target.getTargetType().getName()); + } + eventlogBuilder.setNodeId(netconfAccessor.getNodeId().getValue()); + eventlogBuilder.setNewValue(String.valueOf(edit.getOperation())); + eventlogBuilder.setTimestamp(notification.getChangeTime()); + eventlogBuilder.setCounter(counter); + eventlogBuilder.setSourceType(SourceType.Netconf); + databaseProvider.writeEventLog(eventlogBuilder.build()); + log.info("onDeviceConfigChange (2) {}", sb); + counter++; + } + this.notificationServiceService.sendNotification(notification, this.netconfAccessor.getNodeId(), + ChangeNotification.QNAME, notification.getChangeTime()); + } + + @Override + public void onCreateTechInfoNotification(CreateTechInfoNotification notification) { + + DateAndTime now = NetconfTimeStampImpl.getConverter().getTimeStamp(); + log.info("onCreateTechInfoNotification(1){}", notification); + EventlogBuilder eventlogBuilder = new EventlogBuilder(); + eventlogBuilder.setId(notification.getShelfId()).setAttributeName(notification.getShelfId()) + .setObjectId(notification.getShelfId()).setNodeId(this.netconfAccessor.getNodeId().getValue()) + .setCounter(counter).setNewValue(notification.getStatus().getName()).setSourceType(SourceType.Netconf) + .setTimestamp(now); + databaseProvider.writeEventLog(eventlogBuilder.build()); + this.notificationServiceService.sendNotification(notification, this.netconfAccessor.getNodeId(), + CreateTechInfoNotification.QNAME, now); + log.info("Create-techInfo Notification written "); + counter++; + } + // end of public methods + +} diff --git a/sdnr/wt/devicemanager-onap/openroadm71/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm71/impl/OpenroadmFaultNotificationListener.java b/sdnr/wt/devicemanager-onap/openroadm71/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm71/impl/OpenroadmFaultNotificationListener.java new file mode 100644 index 000000000..7a1116515 --- /dev/null +++ b/sdnr/wt/devicemanager-onap/openroadm71/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm71/impl/OpenroadmFaultNotificationListener.java @@ -0,0 +1,159 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ +package org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm71.impl; + + +import org.eclipse.jdt.annotation.NonNull; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService; +import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor; +import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.WebsocketManagerService; +import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev200529.AlarmNotification; +import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev200529.OrgOpenroadmAlarmListener; +import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev200529.alarm.ProbableCause; +import org.opendaylight.yang.gen.v1.http.org.openroadm.probablecause.rev200529.ProbableCauseEnum; +import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev200529.resource.resource.Resource; +import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev200529.resource.resource.resource.CircuitPack; +import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev200529.resource.resource.resource.Connection; +import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev200529.resource.resource.resource.Degree; +import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev200529.resource.resource.resource.Device; +import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev200529.resource.resource.resource.Interface; +import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev200529.resource.resource.resource.InternalLink; +import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev200529.resource.resource.resource.LineAmplifier; +import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev200529.resource.resource.resource.OduSncpPg; +import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev200529.resource.resource.resource.Other; +import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev200529.resource.resource.resource.PhysicalLink; +import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev200529.resource.resource.resource.Port; +import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev200529.resource.resource.resource.Service; +import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev200529.resource.resource.resource.Shelf; +import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev200529.resource.resource.resource.Srg; +import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev200529.resource.resource.resource.TempService; +import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev200529.resource.resource.resource.VersionedService; +import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev200529.resource.resource.resource.Xponder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.FaultlogBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.FaultlogEntity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SourceType; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author Shabnam Sultana + * + * Listener for Open roadm device specific alarm notifications + **/ +public class OpenroadmFaultNotificationListener implements OrgOpenroadmAlarmListener { + private static final Logger log = LoggerFactory.getLogger(OpenroadmFaultNotificationListener.class); + + private final @NonNull FaultService faultEventListener; + private @NonNull WebsocketManagerService notificationService; + private Integer count = 1; + + private NetconfBindingAccessor netconfAccessor; + + + public OpenroadmFaultNotificationListener(NetconfBindingAccessor accessor, DeviceManagerServiceProvider serviceProvider) { + this.netconfAccessor = accessor; + this.faultEventListener = serviceProvider.getFaultService(); + this.notificationService = serviceProvider.getWebsocketService(); + + } + + @Override + public void onAlarmNotification(AlarmNotification notification) { + log.info("AlarmNotification is {} \t {}", notification.getId(), notification.getAdditionalDetail()); + String affectedResourceName = getAffectedResourceName(notification.getResource().getResource().getResource()); + String probableCauseName = getProbableCauseName(notification.getProbableCause()); + + if (notification.getId() == null) { + log.warn("Alarm ID is null. Not logging alarm information to the DB. Alarm ID should not be null. Please fix the same in the Device"); + return; + } + FaultlogEntity faultAlarm = new FaultlogBuilder().setObjectId(affectedResourceName) + .setProblem(probableCauseName).setSourceType(SourceType.Netconf) + .setTimestamp(notification.getRaiseTime()).setId(notification.getId()).setNodeId(netconfAccessor.getNodeId().getValue()) + .setSeverity(InitialDeviceAlarmReader.checkSeverityValue(notification.getSeverity())).setCounter(count) + .build(); + + this.faultEventListener.faultNotification(faultAlarm); + this.notificationService.sendNotification(notification,new NodeId(netconfAccessor.getNodeId().getValue()), AlarmNotification.QNAME, + notification.getRaiseTime()); + count++; + log.info("Notification is written into the database {}", faultAlarm.getObjectId()); + + } + + public String getAffectedResourceName(Resource affectedResource) { + if (affectedResource instanceof CircuitPack) { + return ((CircuitPack)affectedResource).getCircuitPackName(); + } else if (affectedResource instanceof Port) { + return ((Port)affectedResource).getPort().getPortName(); + } else if (affectedResource instanceof Connection) { + return ((Connection)affectedResource).getConnectionName(); + } else if (affectedResource instanceof PhysicalLink) { + return ((PhysicalLink)affectedResource).getPhysicalLinkName(); + } else if (affectedResource instanceof InternalLink) { + return ((InternalLink)affectedResource).getInternalLinkName(); + } else if (affectedResource instanceof Shelf) { + return ((Shelf)affectedResource).getShelfName(); + } else if (affectedResource instanceof Srg) { + return "SRG #- " + ((Srg)affectedResource).getSrgNumber().toString(); + } else if (affectedResource instanceof Degree) { + return "Degree - " + ((Degree)affectedResource).getDegreeNumber().toString(); + } else if (affectedResource instanceof Service) { + return ((Service)affectedResource).getServiceName(); + } else if (affectedResource instanceof Interface) { + return ((Interface)affectedResource).getInterfaceName(); + } else if (affectedResource instanceof OduSncpPg) { + return ((OduSncpPg)affectedResource).getOduSncpPgName(); + } else if (affectedResource instanceof Device) { + return ((Device)affectedResource).getNodeId().getValue(); + } else if (affectedResource instanceof LineAmplifier) { + return "LineAmplifier # - " + ((LineAmplifier)affectedResource).getAmpNumber().toString(); + } else if (affectedResource instanceof Xponder) { + return "Xponder # - "+ ((Xponder)affectedResource).getXpdrNumber().toString(); + } else if (affectedResource instanceof Other) { + return ((Other)affectedResource).getOtherResourceId(); + } else if (affectedResource instanceof VersionedService) { + return ((VersionedService)affectedResource).getVersionedServiceName(); + } else if (affectedResource instanceof TempService) { + return ((TempService)affectedResource).getCommonId(); + } + + log.warn("Unknown Resource {} received from Notification", affectedResource.getClass().getSimpleName()); + return "Unknown Resource"; + } + + public String getProbableCauseName(ProbableCause probableCause) { + if (probableCause != null) { + ProbableCauseEnum pce = probableCause.getCause(); + if (pce != null) { + return pce.getName(); + } + log.warn("ProbableCauseEnum is NULL"); + return "Unknown Cause"; + } + log.warn("ProbableCause is NULL"); + return "Unknown Cause"; + } + +} diff --git a/sdnr/wt/devicemanager-onap/openroadm71/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm71/impl/OpenroadmInventoryInput.java b/sdnr/wt/devicemanager-onap/openroadm71/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm71/impl/OpenroadmInventoryInput.java new file mode 100644 index 000000000..1f6cfd658 --- /dev/null +++ b/sdnr/wt/devicemanager-onap/openroadm71/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm71/impl/OpenroadmInventoryInput.java @@ -0,0 +1,151 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ +package org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm71.impl; + +import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.circuit.packs.CircuitPacks; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.interfaces.grp.Interface; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.org.openroadm.device.container.OrgOpenroadmDevice; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.org.openroadm.device.container.org.openroadm.device.Info; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.org.openroadm.device.container.org.openroadm.device.Xponder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.shelves.Shelves; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Inventory; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.InventoryBuilder; +import org.opendaylight.yangtools.yang.common.Uint32; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author Shabnam Sultana + * + * Reading the inventory data of an open roadm device + * + **/ +public class OpenroadmInventoryInput { + // variable + private static final Logger log = LoggerFactory.getLogger(OpenroadmInventoryInput.class); + private static final String NOT_AVAILABLE = "N/A"; + private OrgOpenroadmDevice openRoadmDevice; + private final NetconfAccessor accessor; + // end of variables + + // constructors + public OpenroadmInventoryInput(NetconfAccessor netconfAccessor, OrgOpenroadmDevice roadmDevice) { + this.openRoadmDevice = roadmDevice; + this.accessor = netconfAccessor; + } + // end of constructors + + // public methods + public Inventory getInventoryData(Uint32 treeLevel) { + InventoryBuilder inventoryBuilder = new InventoryBuilder(); + log.info("Info for device {}", this.openRoadmDevice.getInfo().getNodeId().getValue()); + Info info = this.openRoadmDevice.getInfo(); + inventoryBuilder.setNodeId(this.accessor.getNodeId().getValue()) + .setUuid(info.getNodeId() == null ? NOT_AVAILABLE : info.getNodeId().getValue()) + .setDate(info.getCurrentDatetime() != null ? info.getCurrentDatetime().getValue() : null) + .setId(info.getNodeId().getValue()).setManufacturerIdentifier(info.getVendor()) + .setModelIdentifier(info.getModel()).setSerial(info.getSerialId()).setTreeLevel(treeLevel) + .setVersion(info.getOpenroadmVersion() != null ? info.getOpenroadmVersion().getName() : null) + .setDescription("org-openroadm-device").setParentUuid("None").setTypeName(info.getNodeType().getName()) + .setPartTypeId("device"); + log.info("Inventory data written for device {}", this.openRoadmDevice.getInfo().getNodeId().getValue()); + return inventoryBuilder.build(); + } + + public Inventory getShelvesInventory(Shelves shelf, Uint32 treeLevel) { + InventoryBuilder inventoryBuilder = new InventoryBuilder(); + inventoryBuilder.setNodeId(this.accessor.getNodeId().getValue()).setId(shelf.getShelfName()) + .setDescription((shelf.getUserDescription() == null) + ? ("Position: " + shelf.getShelfPosition() + "\nState: " + shelf.getOperationalState()) + : (shelf.getUserDescription()) + "\nPosition: " + shelf.getShelfPosition() + "\nState: " + + shelf.getOperationalState()) + .setSerial(shelf.getSerialId()).setUuid(shelf.getShelfName()) + .setParentUuid(this.openRoadmDevice.getInfo().getNodeId().getValue()).setTreeLevel(treeLevel) + .setTypeName(shelf.getShelfType()).setPartTypeId(shelf.getClei()) + .setManufacturerIdentifier(shelf.getVendor()).setModelIdentifier(shelf.getModel()) + .setVersion(shelf.getHardwareVersion()) + .setDate(shelf.getManufactureDate() != null ? shelf.getManufactureDate().getValue() : NOT_AVAILABLE); + log.info("Inventory data written for Shelf {}", shelf.getShelfName()); + return inventoryBuilder.build(); + } + + public Inventory getInterfacesInventory(Interface deviceInterface, Uint32 treeLevel) { + InventoryBuilder inventoryBuilder = new InventoryBuilder(); + inventoryBuilder.setNodeId(this.accessor.getNodeId().getValue()).setId(deviceInterface.getName()) + .setDescription( + (deviceInterface.getDescription() == null) ? NOT_AVAILABLE : deviceInterface.getDescription()) + .setUuid(deviceInterface.getName()).setSerial(deviceInterface.getName()) + .setParentUuid((deviceInterface.getSupportingCircuitPackName() != null) + ? deviceInterface.getSupportingCircuitPackName() + // : ((deviceInterface.getSupportingInterface() != null) ? deviceInterface.getSupportingInterface() + : this.openRoadmDevice.getInfo().getNodeId().getValue()) + .setTreeLevel(treeLevel) + .setTypeName((deviceInterface.getType() == null) ? "Interface" + : deviceInterface.getType().getName().substring(69, + deviceInterface.getType().getName().length())) + .setPartTypeId("Interface").setManufacturerIdentifier(this.openRoadmDevice.getInfo().getVendor()) + .setModelIdentifier(this.openRoadmDevice.getInfo().getModel()).setVersion("N/A") + .setDate(this.openRoadmDevice.getInfo().getCurrentDatetime().getValue()); + log.info("Inventory data written for Interface {}", deviceInterface.getName()); + + return inventoryBuilder.build(); + } + + public Inventory getCircuitPackInventory(CircuitPacks circuitPack, Uint32 treeLevel) { + InventoryBuilder inventoryBuilder = new InventoryBuilder(); + inventoryBuilder.setNodeId(this.accessor.getNodeId().getValue()).setUuid(circuitPack.getCircuitPackName()) + .setDate((circuitPack.getManufactureDate() == null) ? NOT_AVAILABLE + : circuitPack.getManufactureDate().getValue().substring(0, 19)) + .setId(circuitPack.getCircuitPackName()).setManufacturerIdentifier(circuitPack.getVendor()) + .setModelIdentifier(circuitPack.getModel()).setSerial(circuitPack.getSerialId()).setTreeLevel(treeLevel) + .setVersion(circuitPack.getHardwareVersion()) + .setDescription("ProductCode: " + circuitPack.getProductCode() + " " + "Mode: " + + circuitPack.getCircuitPackMode()) + .setTypeName((circuitPack.getType() == null) ? circuitPack.getCircuitPackType() : circuitPack.getType()) + .setPartTypeId((circuitPack.getClei() == null) ? circuitPack.getType() : circuitPack.getClei()) + .setParentUuid((circuitPack.getParentCircuitPack() != null) + ? circuitPack.getParentCircuitPack().getCircuitPackName() + : ((circuitPack.getShelf() != null) ? circuitPack.getShelf() + : this.openRoadmDevice.getInfo().getNodeId().getValue())); + log.info("Inventory data written for CircuitPack {}", circuitPack.getCircuitPackName()); + + return inventoryBuilder.build(); + } + + public Inventory getXponderInventory(Xponder xpdr, Uint32 treeLevel) { + InventoryBuilder inventoryBuilder = new InventoryBuilder(); + inventoryBuilder.setNodeId(this.accessor.getNodeId().getValue()).setId(xpdr.getXpdrNumber().toString()) + .setDescription("Xponder\nLifecycleState: " + xpdr.getLifecycleState().getName()) + .setUuid(xpdr.getXpdrNumber().toString()).setSerial(xpdr.getXpdrNumber().toString()) + .setParentUuid(this.openRoadmDevice.getInfo().getNodeId().getValue()).setTreeLevel(treeLevel) + .setTypeName(xpdr.getXpdrType().getName()).setPartTypeId(xpdr.getXpdrType().getName()) + .setManufacturerIdentifier(this.openRoadmDevice.getInfo().getVendor()) + .setModelIdentifier(this.openRoadmDevice.getInfo().getModel()) + .setVersion(this.openRoadmDevice.getInfo().getOpenroadmVersion().getName()) + .setDate(this.openRoadmDevice.getInfo().getCurrentDatetime().getValue()); + log.info("Inventory data written for Xponder{}", xpdr.getXpdrNumber()); + + return inventoryBuilder.build(); + } + // end of public methods +} diff --git a/sdnr/wt/devicemanager-onap/openroadm71/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm71/impl/OpenroadmNetworkElement.java b/sdnr/wt/devicemanager-onap/openroadm71/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm71/impl/OpenroadmNetworkElement.java new file mode 100644 index 000000000..87fd14b72 --- /dev/null +++ b/sdnr/wt/devicemanager-onap/openroadm71/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm71/impl/OpenroadmNetworkElement.java @@ -0,0 +1,329 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ +package org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm71.impl; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Hashtable; +import java.util.List; +import org.eclipse.jdt.annotation.NonNull; +import org.onap.ccsdk.features.sdnr.wt.common.YangHelper; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.NetconfTimeStamp; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.NetconfTimeStampImpl; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider; +import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor; +import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor; +import org.opendaylight.mdsal.common.api.LogicalDatastoreType; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.circuit.packs.CircuitPacks; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.interfaces.grp.Interface; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.org.openroadm.device.container.OrgOpenroadmDevice; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.org.openroadm.device.container.org.openroadm.device.Xponder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.shelf.Slots; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.shelves.Shelves; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.xponder.XpdrPort; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Inventory; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.PmdataEntity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SourceType; +import org.opendaylight.yangtools.concepts.ListenerRegistration; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.binding.NotificationListener; +import org.opendaylight.yangtools.yang.common.Uint32; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author Shabnam Sultana + * + * Creating the openroadm device as an optical network element and writing inventory, fault, pm data to elastic + * search db + * + **/ +public class OpenroadmNetworkElement extends OpenroadmNetworkElementBase { + + // variables + private final long EQUIPMENTLEVEL_BASE = 1; + private static final Logger LOG = LoggerFactory.getLogger(OpenroadmNetworkElement.class); + private Hashtable<String, Long> circuitPacksRecord; + private Hashtable<String, Long> shelfProvisionedcircuitPacks; + private ListenerRegistration<NotificationListener> openRdmListenerRegistrationResult; + private @NonNull final OpenroadmChangeNotificationListener openRdmListener; + private ListenerRegistration<NotificationListener> opnRdmFaultListenerRegistrationResult; + private @NonNull OpenroadmFaultNotificationListener opnRdmFaultListener; + private ListenerRegistration<NotificationListener> opnRdmDeviceListenerRegistrationResult; + private OpenroadmDeviceChangeNotificationListener opnRdmDeviceListener; + private OpenroadmInventoryInput opnRdmInventoryInput; + private PmDataBuilderOpenRoadm openRoadmPmData; + private InitialDeviceAlarmReader initialAlarmReader; + + private static final NetconfTimeStamp ncTimeConverter = NetconfTimeStampImpl.getConverter(); + private int counter = 1; + // end of variables + + // constructors + public OpenroadmNetworkElement(NetconfBindingAccessor netconfAccess, DeviceManagerServiceProvider serviceProvider) { + + super(netconfAccess, serviceProvider); + + LOG.info("Create {}", OpenroadmNetworkElement.class.getSimpleName()); + this.openRdmListenerRegistrationResult = null; + this.openRdmListener = new OpenroadmChangeNotificationListener(netconfAccessor, databaseService, + serviceProvider.getWebsocketService()); + this.opnRdmFaultListenerRegistrationResult = null; + this.opnRdmFaultListener = new OpenroadmFaultNotificationListener(netconfAccessor, serviceProvider); + this.opnRdmDeviceListenerRegistrationResult = null; + this.opnRdmDeviceListener = new OpenroadmDeviceChangeNotificationListener(netconfAccessor, databaseService, + serviceProvider.getWebsocketService()); + this.circuitPacksRecord = new Hashtable<>(); + this.shelfProvisionedcircuitPacks = new Hashtable<>(); + this.openRoadmPmData = new PmDataBuilderOpenRoadm(this.netconfAccessor); + this.initialAlarmReader = new InitialDeviceAlarmReader(this.netconfAccessor, serviceProvider); + LOG.info("NodeId {}", this.netconfAccessor.getNodeId().getValue()); + + + } + // end of constructors + + // public methods + public void initialReadFromNetworkElement() { + + OrgOpenroadmDevice device = readDevice(this.netconfAccessor); + this.opnRdmInventoryInput = new OpenroadmInventoryInput(this.netconfAccessor, device); + LOG.info("openroadmMapper details{}", this.opnRdmInventoryInput.getClass().getName()); + List<Inventory> inventoryList = new ArrayList<>(); + inventoryList.add(this.opnRdmInventoryInput.getInventoryData(Uint32.valueOf(EQUIPMENTLEVEL_BASE))); + readShelvesData(inventoryList, device); + readXpndrData(inventoryList, device); + readCircuitPacketData(inventoryList, device); + readInterfaceData(inventoryList, device); + this.databaseService.writeInventory(this.netconfAccessor.getNodeId().getValue(), inventoryList); + // Writing initial alarms at the time of device registration + initialAlarmReader.faultService(); + // Writing historical PM data at the time of device registration + List<PmdataEntity> pmDataEntity = new ArrayList<>(); + pmDataEntity = this.openRoadmPmData.buildPmDataEntity(this.openRoadmPmData.getPmData(this.netconfAccessor)); + if (!pmDataEntity.isEmpty()) { + this.databaseService.doWritePerformanceData(pmDataEntity); + LOG.info("PmDatEntity is written with size {}", pmDataEntity.size()); + for (PmdataEntity ent : pmDataEntity) { + LOG.info("GetNode: {}, granPeriod: {}", ent.getNodeName(), ent.getGranularityPeriod().getName()); + } + } else { + LOG.info("PmDatEntity is empty"); + } + } + + + @Override + public void register() { + initialReadFromNetworkElement(); + + this.openRdmListenerRegistrationResult = netconfAccessor.doRegisterNotificationListener(openRdmListener); + this.opnRdmFaultListenerRegistrationResult = + netconfAccessor.doRegisterNotificationListener(opnRdmFaultListener); + this.opnRdmDeviceListenerRegistrationResult = + netconfAccessor.doRegisterNotificationListener(opnRdmDeviceListener); + if (netconfAccessor.isNotificationsRFC5277Supported()) { + // Register netconf stream + netconfAccessor.registerNotificationsStream(NetconfAccessor.DefaultNotificationsStream); + } + else { + LOG.info("device {} does not support netconf notification", netconfAccessor.getNodeId().getValue()); + } + } + + @Override + public void deregister() { + if (openRdmListenerRegistrationResult != null) { + this.openRdmListenerRegistrationResult.close(); + } + if (opnRdmFaultListenerRegistrationResult != null) { + this.opnRdmFaultListenerRegistrationResult.close(); + } + if (opnRdmDeviceListenerRegistrationResult != null) { + this.opnRdmDeviceListenerRegistrationResult.close(); + } + } + + // end of public methods + + // private methods + private void readShelvesData(List<Inventory> inventoryList, OrgOpenroadmDevice device) { + Collection<Shelves> shelves = YangHelper.getCollection(device.getShelves()); + if (shelves != null) { + for (Shelves shelf : shelves) { + LOG.info( + "Shelf Name: {}, \n Serial Id:{}, \n Product Code;{}, \n Position:{}, \n EquipmetState: {}, \n Hardware version: {}" + + "\n ShelfType:{}, \n Vendor: {}, \n LifecycleState: {} ", + shelf.getShelfName(), shelf.getSerialId(), shelf.getProductCode(), shelf.getShelfPosition(), + shelf.getEquipmentState(), shelf.getHardwareVersion(), shelf.getShelfType(), shelf.getVendor(), + shelf.getLifecycleState()); + inventoryList.add( + this.opnRdmInventoryInput.getShelvesInventory(shelf, Uint32.valueOf(EQUIPMENTLEVEL_BASE + 1))); + Collection<Slots> slotList = YangHelper.getCollection(shelf.getSlots()); + if (slotList != null) { + for (Slots slot : slotList) { + if (slot.getProvisionedCircuitPack() != null) { + this.shelfProvisionedcircuitPacks.put(slot.getProvisionedCircuitPack(), + EQUIPMENTLEVEL_BASE + 2); + } + LOG.info("Slots for the shelf: {}", shelf.getShelfName()); + LOG.info("\n Slot Name: {}, \n Status: {}, \n Slot label: {} ", slot.getSlotName(), + slot.getSlotStatus(), slot.getLabel()); + } + } + } + LOG.info("size of shelfProvisionedcircuitPacks: {} ", shelfProvisionedcircuitPacks.size()); + } + + } + + private void readXpndrData(List<Inventory> inventoryList, OrgOpenroadmDevice device) { + Collection<Xponder> xponderList = YangHelper.getCollection(device.getXponder()); + + if (xponderList != null) { + for (Xponder xponder : xponderList) { + + inventoryList.add(this.opnRdmInventoryInput.getXponderInventory(xponder, + Uint32.valueOf(EQUIPMENTLEVEL_BASE + 1))); + LOG.info("Xponders: No.: {} , \n Port: {} ,\n Type: {}", xponder.getXpdrNumber(), xponder.getXpdrPort(), + xponder.getXpdrType()); + Collection<XpdrPort> xpdrportlist = YangHelper.getCollection(xponder.getXpdrPort()); + if (xpdrportlist != null) { + for (XpdrPort xpdrport : xpdrportlist) + if (xpdrport.getCircuitPackName() != null) { + this.shelfProvisionedcircuitPacks.put(xpdrport.getCircuitPackName(), + EQUIPMENTLEVEL_BASE + 2); + LOG.info("Size of dict{}", this.shelfProvisionedcircuitPacks.size()); + } + } + + } + } + } + + private void readCircuitPacketData(List<Inventory> inventoryList, OrgOpenroadmDevice device) { + Collection<CircuitPacks> circuitpackCollection = YangHelper.getCollection(device.getCircuitPacks()); + List<String> cpNameList = new ArrayList<>(); + + if (circuitpackCollection != null) { + // collect all circuit pack names. Required to check for invalid parents later on + for (CircuitPacks cp : circuitpackCollection) { + cpNameList.add(cp.getCircuitPackName()); + } + + for (CircuitPacks cp : circuitpackCollection) { + LOG.info("CP Name:{}", cp.getCircuitPackName()); + + if (cp.getParentCircuitPack() == null + && !this.shelfProvisionedcircuitPacks.containsKey(cp.getCircuitPackName())) { + LOG.info("cp has no parent and no shelf"); + this.circuitPacksRecord.put(cp.getCircuitPackName(), (EQUIPMENTLEVEL_BASE + 1)); + inventoryList.add(this.opnRdmInventoryInput.getCircuitPackInventory(cp, + Uint32.valueOf(EQUIPMENTLEVEL_BASE + 1))); + } else { + // check for missing valid parent circuit name + if (cp.getParentCircuitPack().getCpSlotName() != null + && cp.getParentCircuitPack().getCircuitPackName() == null) { + + LOG.info("Cp {} has slotname of the parent circuit pack but no parent circuit pack name", + cp.getCircuitPackName()); + this.circuitPacksRecord.put(cp.getCircuitPackName(), (EQUIPMENTLEVEL_BASE + 3)); + inventoryList.add(this.opnRdmInventoryInput.getCircuitPackInventory(cp, + Uint32.valueOf(EQUIPMENTLEVEL_BASE + 3))); + databaseService.writeEventLog(writeIncorrectParentLog(cp.getCircuitPackName(), counter) + .setObjectId(device.getInfo().getNodeId().getValue()) + .setId(cp.getParentCircuitPack().getCpSlotName()) + .setNewValue("Missing parent circuit pack name").build()); + } else if (cp.getParentCircuitPack().getCircuitPackName() != null + && this.shelfProvisionedcircuitPacks + .containsKey(cp.getParentCircuitPack().getCircuitPackName())) { + LOG.info("Cp {} has parent circuit pack and shelf", cp.getCircuitPackName()); + this.circuitPacksRecord.put(cp.getCircuitPackName(), (EQUIPMENTLEVEL_BASE + 3)); + inventoryList.add(this.opnRdmInventoryInput.getCircuitPackInventory(cp, + Uint32.valueOf(EQUIPMENTLEVEL_BASE + 3))); + } else { + // check for incorrect hierarchy + if (cp.getParentCircuitPack().getCircuitPackName() != null + && !cpNameList.contains(cp.getParentCircuitPack().getCircuitPackName())) { + databaseService.writeEventLog(writeIncorrectParentLog(cp.getCircuitPackName(), counter) + .setObjectId(device.getInfo().getNodeId().getValue()) + .setId(cp.getParentCircuitPack().getCpSlotName()).build()); + } + + LOG.info("Cp has parent circuit pack but no shelf or a shelf but no parent circuit pack"); + this.circuitPacksRecord.put(cp.getCircuitPackName(), (EQUIPMENTLEVEL_BASE + 2)); + inventoryList.add(this.opnRdmInventoryInput.getCircuitPackInventory(cp, + Uint32.valueOf(EQUIPMENTLEVEL_BASE + 2))); + } + + } + } + + } + } + + private void readInterfaceData(List<Inventory> inventoryList, OrgOpenroadmDevice device) { + Collection<Interface> interfaceList = YangHelper.getCollection(device.getInterface()); + if (interfaceList != null) { + for (Interface deviceInterface : interfaceList) { + LOG.info("\n InterfaceName: {}", deviceInterface.getName()); + LOG.info("Supporting CP {}", this.circuitPacksRecord.size()); + for (String s : this.circuitPacksRecord.keySet()) { + LOG.info("{} value {}", s, this.circuitPacksRecord.get(s)); + } + LOG.info("Interface {} and their supporting CP {}", deviceInterface.getName(), + deviceInterface.getSupportingCircuitPackName()); + if (deviceInterface.getSupportingCircuitPackName() != null) { + if (this.circuitPacksRecord.containsKey(deviceInterface.getSupportingCircuitPackName())) { + inventoryList.add(this.opnRdmInventoryInput.getInterfacesInventory(deviceInterface, + Uint32.valueOf( + this.circuitPacksRecord.get(deviceInterface.getSupportingCircuitPackName()) + + 1))); + } + } else { + inventoryList.add(this.opnRdmInventoryInput.getInterfacesInventory(deviceInterface, + Uint32.valueOf(EQUIPMENTLEVEL_BASE + 1))); + } + } + } + } + + private OrgOpenroadmDevice readDevice(NetconfBindingAccessor accessor) { + InstanceIdentifier<OrgOpenroadmDevice> deviceId = InstanceIdentifier.create(OrgOpenroadmDevice.class); + return accessor.getTransactionUtils().readData(accessor.getDataBroker(), LogicalDatastoreType.OPERATIONAL, + deviceId); + } + + private EventlogBuilder writeIncorrectParentLog(String attributeName, Integer counter) { + EventlogBuilder eventlogBuilder = new EventlogBuilder(); + eventlogBuilder.setAttributeName(attributeName).setCounter(counter) + .setNodeId(this.netconfAccessor.getNodeId().getValue()).setSourceType(SourceType.Netconf) + .setNewValue("Invalid parent circuit-pack name") + .setTimestamp(new DateAndTime(ncTimeConverter.getTimeStamp())); + + return eventlogBuilder; + + } + // end of private methods +} diff --git a/sdnr/wt/devicemanager-onap/openroadm71/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm71/impl/OpenroadmNetworkElementBase.java b/sdnr/wt/devicemanager-onap/openroadm71/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm71/impl/OpenroadmNetworkElementBase.java new file mode 100644 index 000000000..4da2145fb --- /dev/null +++ b/sdnr/wt/devicemanager-onap/openroadm71/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm71/impl/OpenroadmNetworkElementBase.java @@ -0,0 +1,74 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ +package org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm71.impl; + +import java.util.Optional; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElement; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElementService; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider; +import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor; +import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.NetworkElementDeviceType; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; + +public class OpenroadmNetworkElementBase implements NetworkElement { + + protected final NetconfBindingAccessor netconfAccessor; + protected final DataProvider databaseService; + + public OpenroadmNetworkElementBase(NetconfBindingAccessor netconfAccess, + DeviceManagerServiceProvider serviceProvider) { + + this.netconfAccessor = netconfAccess; + this.databaseService = serviceProvider.getDataProvider(); + } + + @Override + public void register() {} + + @Override + public void deregister() {} + + @Override + public void warmstart() {} + + @Override + public NodeId getNodeId() { + return netconfAccessor.getNodeId(); + } + + @Override + public NetworkElementDeviceType getDeviceType() { + return NetworkElementDeviceType.OROADM; + } + + @Override + public <L extends NetworkElementService> Optional<L> getService(Class<L> clazz) { + return Optional.empty(); + } + + @Override + public Optional<NetconfAccessor> getAcessor() { + return Optional.of(netconfAccessor); + } +} diff --git a/sdnr/wt/devicemanager-onap/openroadm71/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm71/impl/OpenroadmNetworkElementFactory.java b/sdnr/wt/devicemanager-onap/openroadm71/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm71/impl/OpenroadmNetworkElementFactory.java new file mode 100644 index 000000000..552058fd8 --- /dev/null +++ b/sdnr/wt/devicemanager-onap/openroadm71/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm71/impl/OpenroadmNetworkElementFactory.java @@ -0,0 +1,64 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ + +package org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm71.impl; + +import java.util.Optional; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.factory.NetworkElementFactory; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElement; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider; +import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor; +import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.org.openroadm.device.container.OrgOpenroadmDevice; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author Shabnam Sultana + * + * Register the openroadm device as an optical network element + * + **/ + +public class OpenroadmNetworkElementFactory implements NetworkElementFactory { + + // variables + private static final Logger log = LoggerFactory.getLogger(OpenroadmNetworkElementFactory.class); + // end of variables + + // public methods + @Override + public Optional<NetworkElement> create(NetconfAccessor accessor, DeviceManagerServiceProvider serviceProvider) { + + if (accessor.getCapabilites().isSupportingNamespaceAndRevision(OrgOpenroadmDevice.QNAME)) { + log.info("Create OpenRoadm device {} ", OpenroadmNetworkElement.class.getName()); + log.info("Node Id read by Acessor {}:", accessor.getNodeId().getValue()); + Optional<NetconfBindingAccessor> bindingAccessor = accessor.getNetconfBindingAccessor(); + if (bindingAccessor.isPresent()) { + return Optional.of(new OpenroadmNetworkElement(bindingAccessor.get(), serviceProvider)); + } + } + return Optional.empty(); + } + // end of public methods + +} diff --git a/sdnr/wt/devicemanager-onap/openroadm71/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm71/impl/PmDataBuilderOpenRoadm.java b/sdnr/wt/devicemanager-onap/openroadm71/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm71/impl/PmDataBuilderOpenRoadm.java new file mode 100644 index 000000000..658c507cd --- /dev/null +++ b/sdnr/wt/devicemanager-onap/openroadm71/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm71/impl/PmDataBuilderOpenRoadm.java @@ -0,0 +1,300 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ +package org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm71.impl; + +import java.net.URL; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.onap.ccsdk.features.sdnr.wt.common.YangHelper; +import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor; +import org.opendaylight.mdsal.common.api.LogicalDatastoreType; +import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev200529.HistoricalPmList; +import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev200529.historical.pm.group.HistoricalPm; +import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev200529.historical.pm.list.HistoricalPmEntry; +import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev200529.historical.pm.val.group.Measurement; +import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev200327.PmDataType; +import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev200327.PmGranularity; +import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev200327.PmNamesEnum; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.g836.pm.types.rev200413.ErroredSecond; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.g836.pm.types.rev200413.SeverelyErroredSecond; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.openroadm.pm.types.rev200413.PerformanceMeasurementTypeId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.GranularityPeriodType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.PmdataEntity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.PmdataEntityBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.pmdata.entity.PerformanceDataBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.pmdata.grp.MeasurementBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.pmdata.grp.MeasurementKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.units.rev200413.Celsius; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.units.rev200413.DB; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.units.rev200413.DBm; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.units.rev200413.Fahrenheit; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.units.rev200413.KHz; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.units.rev200413.MW; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.units.rev200413.PerformanceMeasurementUnitId; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.FrameworkUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author shabnam + * + * Reading Openroadm PM data and returning as PmDataEntitiy data + */ +public class PmDataBuilderOpenRoadm { + // variables + private static final Logger log = LoggerFactory.getLogger(PmDataBuilderOpenRoadm.class); + private PmdataEntityBuilder pmDataBuilder; + private Bundle b = FrameworkUtil.getBundle(this.getClass()); + + // end of variables + // constructors + public PmDataBuilderOpenRoadm(NetconfBindingAccessor accessor) { + this.pmDataBuilder = new PmdataEntityBuilder(); + this.pmDataBuilder.setNodeName(accessor.getNodeId().getValue()); + } + + // end of constructors + // public methods + // Read PM data + public HistoricalPmList getPmData(NetconfBindingAccessor accessor) { + final Class<HistoricalPmList> pmDataClass = HistoricalPmList.class; + log.info("Get PM data for element {}", accessor.getNodeId().getValue()); + InstanceIdentifier<HistoricalPmList> pmDataIid = InstanceIdentifier.builder(pmDataClass).build(); + return accessor.getTransactionUtils().readData(accessor.getDataBroker(), LogicalDatastoreType.OPERATIONAL, + pmDataIid); + + } + + // Build PM entity for writing into the database + public List<PmdataEntity> buildPmDataEntity(HistoricalPmList historicalPmEnitityList) { + List<PmdataEntity> pmEntitiyList = new ArrayList<>(); + if (historicalPmEnitityList == null) { + return pmEntitiyList; + } + Collection<HistoricalPmEntry> pmDataEntryList = + YangHelper.getCollection(historicalPmEnitityList.getHistoricalPmEntry()); + for (HistoricalPmEntry pmDataEntry : pmDataEntryList) { + pmDataBuilder.setUuidInterface(pmDataEntry.getPmResourceType().getName()); + Collection<HistoricalPm> historicalPmList = YangHelper.getCollection(pmDataEntry.getHistoricalPm()); + for (HistoricalPm historicalPm : historicalPmList) { + log.info("PmName:{}", historicalPm.getType()); + // pmDataBuilder.setPerformanceData(value) + + try { + writeperformanceData(historicalPm); + } catch (ClassNotFoundException e) { + log.info("No relevant data found"); + } + pmEntitiyList.add(this.pmDataBuilder.build()); + + log.info("PmListSize before db writing: {}", pmEntitiyList.size()); + } + log.info("PmListSize before db writing: {}", pmEntitiyList.size()); + } + return pmEntitiyList; + } + // end of public methods + + // private methods + private void writeperformanceData(HistoricalPm historicalPm) throws ClassNotFoundException { + Collection<Measurement> measurementList = YangHelper.getCollection(historicalPm.getMeasurement()); + Map<MeasurementKey, org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.pmdata.grp.Measurement> measurementMap = + new HashMap<>(); + // Map Performance data of PmDataEntity with MeasurmentData-HistoricalPm + PerformanceDataBuilder performanceDataBuilder = new PerformanceDataBuilder(); + for (Measurement measurementData : measurementList) { + this.pmDataBuilder.setGranularityPeriod(mapGranularityPeriod(measurementData.getGranularity())) + .setTimeStamp(measurementData.getCompletionTime()); + if (measurementData.getValidity().getName().equals("suspect")) { + this.pmDataBuilder.setSuspectIntervalFlag(true); + } + measurementMap.put( + new MeasurementKey(measurementBuilder(historicalPm.getType(), measurementData.getPmParameterUnit(), + measurementData.getPmParameterValue()).getPmKey()), + measurementBuilder(historicalPm.getType(), measurementData.getPmParameterUnit(), + measurementData.getPmParameterValue())); + + + } + + pmDataBuilder.setPerformanceData(performanceDataBuilder.setMeasurement(measurementMap).build()); + } + + + + // Mapping Granularity period of PmDataEntity with PmGranularity of MeasurmentData-HistoricalPm + private GranularityPeriodType mapGranularityPeriod(PmGranularity pmGranularity) { + return this.mapGranularityPeriod(pmGranularity.getName()); + } + + private GranularityPeriodType mapGranularityPeriod(String pmGranularity) { + + GranularityPeriodType granPeriod = null; + switch (pmGranularity) { + case ("notApplicable"): + granPeriod = GranularityPeriodType.Unknown; + break; + case ("15min"): + granPeriod = GranularityPeriodType.Period15Min; + break; + case ("24Hour"): + granPeriod = GranularityPeriodType.Period24Hours; + break; + default: + granPeriod = GranularityPeriodType.Period15Min; + break; + } + return granPeriod; + } + + private List<Class<? extends PerformanceMeasurementTypeId>> setMeasurementTypeId() { + String packageName = + "org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.openroadm.pm.types.rev200413"; + String packageName1 = + "/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/data/provider/openroadm/pm/types/rev200413/"; + List<Class<? extends PerformanceMeasurementTypeId>> measTypeObjList = new ArrayList<>(); + URL root = Thread.currentThread().getContextClassLoader().getResource(packageName1); + + log.info("path for type package: {}", root); + + Enumeration<URL> results = getFileURL(b, packageName); + log.info("FOund Packages {}", results); + if (results != null) { + while (results.hasMoreElements()) { + URL path = results.nextElement(); + + Class<?> cls1 = loadClass(b, path.getFile()); + + if (PerformanceMeasurementTypeId.class.isAssignableFrom(cls1)) { + measTypeObjList.add((Class<? extends PerformanceMeasurementTypeId>) cls1); + + + } + if (cls1 != null) { + log.info("Class Added {}", cls1.getSimpleName()); + } + + } + + + } + + return measTypeObjList; + } + + private Class<? extends PerformanceMeasurementUnitId> setMeasurementUnit(String unitName) { + Class<? extends PerformanceMeasurementUnitId> measurementUnitClass = null; + switch (unitName) { + case ("celsius"): + measurementUnitClass = Celsius.class; + break; + case ("dB"): + measurementUnitClass = DB.class; + break; + case ("dBm"): + measurementUnitClass = DBm.class; + break; + case ("fahrenheit"): + measurementUnitClass = Fahrenheit.class; + break; + case ("kHz"): + measurementUnitClass = KHz.class; + break; + case ("mW"): + measurementUnitClass = MW.class; + break; + default: + break; + } + return measurementUnitClass; + } + + private org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.pmdata.grp.Measurement measurementBuilder( + PmNamesEnum pmType, String pmUnit, PmDataType pmDataType) { + + MeasurementBuilder measBuilder = new MeasurementBuilder(); + if (pmType.getName().equals("erroredSeconds")) { + measBuilder.setPmKey(ErroredSecond.class); + } else if (pmType.getName().equals("severelyErroredSeconds")) { + measBuilder.setPmKey(SeverelyErroredSecond.class); + } else { + for (Class<? extends PerformanceMeasurementTypeId> obj : setMeasurementTypeId()) { + if (obj.toString().contains(pmType.name())) { + measBuilder.setPmKey(obj); + } + } + } + measBuilder.setPmUnit(setMeasurementUnit(pmUnit)); + measBuilder.setPmValue(new org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev191129.PmDataType( + pmDataType.getDecimal64())); + return measBuilder.build(); + + } + + private Class<?> loadClass(Bundle bundle, String classFilePath) { + String className = classFilePath.replaceFirst("^/", "").replace('/', '.').replaceFirst(".class$", ""); + try { + return bundle.loadClass(className); + } catch (Exception e) { + log.info(String.format("Class [%s] could not be loaded. Message: [%s].", className, e.getMessage())); + } + return null; + } + + private static Enumeration<URL> getFileURL(Bundle b, String classPath) { + + BundleContext context = b == null ? null : b.getBundleContext(); + if (context == null) { + log.info("no bundle context available"); + return null; + } + Bundle[] bundles = context.getBundles(); + if (bundles == null || bundles.length <= 0) { + log.info("no bundles found"); + return null; + } + log.info("found {} bundles", bundles.length); + Enumeration<URL> resultUrl = null; + + for (Bundle bundle : bundles) { + resultUrl = bundle.findEntries("/" + classPath.replace(".", "/"), "*.class", false); + if (resultUrl != null) { + break; + + } + + } + + return resultUrl; + } + + + // end of private methods +} + diff --git a/sdnr/wt/devicemanager-onap/openroadm71/provider/src/main/java/org/opendaylight/yang/gen/v1/http/org/openroadm/pm/types/rev200327/PmDataTypeBuilder.java b/sdnr/wt/devicemanager-onap/openroadm71/provider/src/main/java/org/opendaylight/yang/gen/v1/http/org/openroadm/pm/types/rev200327/PmDataTypeBuilder.java new file mode 100644 index 000000000..f470fb6ba --- /dev/null +++ b/sdnr/wt/devicemanager-onap/openroadm71/provider/src/main/java/org/opendaylight/yang/gen/v1/http/org/openroadm/pm/types/rev200327/PmDataTypeBuilder.java @@ -0,0 +1,23 @@ +package org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev200327; +import java.lang.String; +import java.lang.UnsupportedOperationException; + +/** + * The purpose of generated class in src/main/java for Union types is to create new instances of unions from a string representation. + * In some cases it is very difficult to automate it since there can be unions such as (uint32 - uint16), or (string - uint32). + * + * The reason behind putting it under src/main/java is: + * This class is generated in form of a stub and needs to be finished by the user. This class is generated only once to prevent + * loss of user code. + * + */ +public class PmDataTypeBuilder { + private PmDataTypeBuilder() { + //Exists only to defeat instantiation. + } + + public static PmDataType getDefaultInstance(String defaultValue) { + throw new UnsupportedOperationException("Not yet implemented"); + } + +} |