diff options
Diffstat (limited to 'sdnr/wt/devicemanager-openroadm/provider/src/main/java/org')
15 files changed, 1435 insertions, 0 deletions
diff --git a/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/impl/DeviceManagerOpenroadmImpl.java b/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/impl/DeviceManagerOpenroadmImpl.java new file mode 100644 index 000000000..efda889b9 --- /dev/null +++ b/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/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.openroadm.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.registerNetworkElementFactory(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 + + /** + * Used to close all Services, that should support AutoCloseable Pattern + * + * @param toClose + * @throws Exception + */ + // private methods + 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-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/impl/InitialDeviceAlarmReader.java b/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/impl/InitialDeviceAlarmReader.java new file mode 100644 index 000000000..70bbfa5c0 --- /dev/null +++ b/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/impl/InitialDeviceAlarmReader.java @@ -0,0 +1,154 @@ +/* + * ============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.openroadm.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.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.NetconfAccessor; +import org.opendaylight.mdsal.common.api.LogicalDatastoreType; +import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.ActiveAlarmList; +import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.OrgOpenroadmAlarmListener; +import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.Severity; +import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.active.alarm.list.ActiveAlarms; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Faultlog; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.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 + private Integer count = 1; + private static final Logger log = LoggerFactory.getLogger(OrgOpenroadmAlarmListener.class); + private final NetconfAccessor netConfAccesor; + private final @NonNull FaultService faultEventListener; + private final DataProvider dataProvider; + // end of variables + + // constructors + public InitialDeviceAlarmReader(NetconfAccessor 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(); + if (this.getActiveAlarmList(this.netConfAccesor).getActiveAlarms() != null) { + List<ActiveAlarms> activeAlarms = this.getActiveAlarmList(this.netConfAccesor).getActiveAlarms(); + if (!activeAlarms.isEmpty()) { + for (ActiveAlarms activeAlarm : activeAlarms) { + faultData.add(this.netConfAccesor.getNodeId(), this.count, activeAlarm.getRaiseTime(), + activeAlarm.getResource().getDevice().getNodeId().getValue(), + activeAlarm.getProbableCause().getCause().getName(), + checkSeverityValue(activeAlarm.getSeverity())); + count = count + 1; + } + 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()); + } + // end of protected methods + + // private methods + + // Read Alarm Data + private ActiveAlarmList getActiveAlarmList(NetconfAccessor 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.toString()); + return alarmData; + } + + // Mapping Severity of AlarmNotification to SeverityType of FaultLog + private 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 private methods + + + +} diff --git a/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/impl/OpenroadmChangeNotificationListener.java b/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/impl/OpenroadmChangeNotificationListener.java new file mode 100644 index 000000000..1ba7e990c --- /dev/null +++ b/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/impl/OpenroadmChangeNotificationListener.java @@ -0,0 +1,144 @@ +/* + * ============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.openroadm.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.netconfnodestateservice.NetconfAccessor; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.ChangeNotification; +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.rev190801.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; + // end of variables + + // constructors + public OpenroadmChangeNotificationListener(NetconfAccessor netconfAccessor, DataProvider databaseService) { + this.netconfAccessor = netconfAccessor; + this.databaseService = databaseService; + } + // end of constructors + + // public methods + @Override + public void onNetconfConfirmedCommit(NetconfConfirmedCommit notification) { + log.info("onNetconfConfirmedCommit ", notification); + } + + @Override + public void onNetconfSessionStart(NetconfSessionStart notification) { + log.info("onNetconfSessionStart ", notification); + } + + @Override + public void onNetconfSessionEnd(NetconfSessionEnd notification) { + log.info("onNetconfSessionEnd ", notification); + } + + @Override + public void onNetconfCapabilityChange(NetconfCapabilityChange notification) { + log.info("onNetconfCapabilityChange ", notification); + } + + @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); + } + + public void onDeviceConfigChange(ChangeNotification notification) { + log.info("onDeviceConfigChange(1){}", notification); + StringBuffer sb = new StringBuffer(); + @NonNull + List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.change.notification.Edit> editList = + notification.nonnullEdit(); + for (org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.change.notification.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("onDeviceConfigChange (2) {}", sb); + } + // end of public methods + +} diff --git a/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/impl/OpenroadmDeviceChangeNotificationListener.java b/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/impl/OpenroadmDeviceChangeNotificationListener.java new file mode 100644 index 000000000..32f8cb0cb --- /dev/null +++ b/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/impl/OpenroadmDeviceChangeNotificationListener.java @@ -0,0 +1,122 @@ +/* + * ============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.openroadm.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.netconfnodestateservice.NetconfAccessor; +import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.OrgOpenroadmAlarmListener; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.ChangeNotification; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.CreateTechInfoNotification; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.OrgOpenroadmDeviceListener; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.OtdrScanResult; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.change.notification.Edit; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.EventlogBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.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(OrgOpenroadmAlarmListener.class); + private Integer counter = 1; + private final NetconfAccessor netconfAccessor; + private final DataProvider databaseProvider; + // end of variables + + // constructors + public OpenroadmDeviceChangeNotificationListener(NetconfAccessor netconfAccessor, DataProvider databaseService) { + this.netconfAccessor = netconfAccessor; + this.databaseProvider = databaseService; + } + // 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++; + } + } + + @Override + public void onCreateTechInfoNotification(CreateTechInfoNotification notification) { + // TODO Auto-generated method stub + 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); + databaseProvider.writeEventLog(eventlogBuilder.build()); + log.info("Create-techInfo Notification written "); + counter++; + + } + // end of public methods + +} diff --git a/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/impl/OpenroadmFaultNotificationListener.java b/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/impl/OpenroadmFaultNotificationListener.java new file mode 100644 index 000000000..69d0af350 --- /dev/null +++ b/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/impl/OpenroadmFaultNotificationListener.java @@ -0,0 +1,110 @@ +/* + * ============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.openroadm.impl; + + +import org.eclipse.jdt.annotation.NonNull; +//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.netconfnodestateservice.NetconfAccessor; +import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.AlarmNotification; +import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.OrgOpenroadmAlarmListener; +import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.Severity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.FaultlogBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.FaultlogEntity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.SeverityType; +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(OrgOpenroadmAlarmListener.class); + //private final NetconfAccessor accesor; + //private final DataProvider databaseProvider; + private final @NonNull FaultService faultEventListener; + private Integer count = 1; + + public OpenroadmFaultNotificationListener(NetconfAccessor netConfAccessor, + DeviceManagerServiceProvider serviceProvider) { + //this.databaseProvider = serviceProvider.getDataProvider(); + //this.accesor = netConfAccessor; + this.faultEventListener = serviceProvider.getFaultService(); + + } + + @Override + public void onAlarmNotification(AlarmNotification notification) { + + log.info("AlarmNotification {} \t {}", notification.getId(), notification.getAdditionalDetail()); + + FaultlogEntity faultAlarm = new FaultlogBuilder().setObjectId(notification.getCircuitId()) + .setProblem(notification.getProbableCause().getCause().getName()) + .setTimestamp(notification.getRaiseTime()).setId(notification.getId()) + .setNodeId(notification.getResource().getDevice().getNodeId().getValue()) + .setSeverity(checkSeverityValue(notification.getSeverity())).setCounter(count).build(); + + //this.databaseProvider.writeFaultLog(faultAlarm); + this.faultEventListener.faultNotification(faultAlarm); + count++; + log.info("Notification is written into the database {}", faultAlarm.getObjectId()); + + } + + + // Mapping Severity of AlarmNotification to SeverityType of FaultLog + private 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; + + } + +} diff --git a/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/impl/OpenroadmInventoryInput.java b/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/impl/OpenroadmInventoryInput.java new file mode 100644 index 000000000..be79c7ba7 --- /dev/null +++ b/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/impl/OpenroadmInventoryInput.java @@ -0,0 +1,147 @@ +/* + * ============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.openroadm.impl; + +import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.OrgOpenroadmDevice; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.circuit.packs.CircuitPacks; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.interfaces.grp.Interface; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.org.openroadm.device.Xponder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.shelves.Shelves; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Inventory; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.InventoryBuilder; +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 OrgOpenroadmDevice openRoadmDevice; + private final NetconfAccessor accessor; + // end of variables + + /** + * @param netconfAccessor + * @param readDevice + */ + + // constructors + public OpenroadmInventoryInput(NetconfAccessor netconfAccessor, OrgOpenroadmDevice readDevice) { + this.openRoadmDevice = readDevice; + this.accessor = netconfAccessor; + } + // end of constructors + + // public methods + public Inventory getInventoryData(long treeLevel) { + InventoryBuilder inventoryBuilder = new InventoryBuilder(); + inventoryBuilder.setNodeId(this.accessor.getNodeId().getValue()) + .setUuid(this.openRoadmDevice.getInfo().getNodeId().getValue()) + .setDate(this.openRoadmDevice.getInfo().getCurrentDatetime().getValue()) + .setId(this.openRoadmDevice.getInfo().getNodeId().getValue()) + .setManufacturerIdentifier(this.openRoadmDevice.getInfo().getVendor()) + .setModelIdentifier(this.openRoadmDevice.getInfo().getModel()) + .setSerial(this.openRoadmDevice.getInfo().getSerialId()).setTreeLevel(treeLevel) + .setVersion(this.openRoadmDevice.getInfo().getOpenroadmVersion().getName()) + .setDescription("org-openroadm-device").setParentUuid("None") + .setTypeName(this.openRoadmDevice.getInfo().getNodeType().getName()).setPartTypeId("device"); + log.info("Inventory data written for device {}", this.openRoadmDevice.getInfo().getNodeId().getValue()); + return inventoryBuilder.build(); + } + + public Inventory getShelvesInventory(Shelves shelf, long 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().getValue()); + log.info("Inventory data written for Shelf {}", shelf.getShelfName()); + return inventoryBuilder.build(); + } + + public Inventory getInterfacesInventory(Interface deviceInterface, long treeLevel) { + InventoryBuilder inventoryBuilder = new InventoryBuilder(); + inventoryBuilder.setNodeId(this.accessor.getNodeId().getValue()).setId(deviceInterface.getName()) + .setDescription((deviceInterface.getDescription() == null) ? "N/A" : deviceInterface.getDescription()) + .setUuid(deviceInterface.getName()).setSerial(deviceInterface.getName()) + .setParentUuid(deviceInterface.getSupportingCircuitPackName()).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, long treeLevel) { + InventoryBuilder inventoryBuilder = new InventoryBuilder(); + inventoryBuilder.setNodeId(this.accessor.getNodeId().getValue()).setUuid(circuitPack.getCircuitPackName()) + .setDate((circuitPack.getManufactureDate() == null) ? "N/A" + : 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, long 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-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/impl/OpenroadmNetworkElement.java b/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/impl/OpenroadmNetworkElement.java new file mode 100644 index 000000000..98e5e4659 --- /dev/null +++ b/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/impl/OpenroadmNetworkElement.java @@ -0,0 +1,325 @@ +/* + * ============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.openroadm.impl; + +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.List; +import java.util.Optional; +import org.eclipse.jdt.annotation.NonNull; +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.opendaylight.mdsal.common.api.LogicalDatastoreType; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.OrgOpenroadmDevice; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.circuit.packs.CircuitPacks; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.interfaces.grp.Interface; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.org.openroadm.device.Xponder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.shelf.Slots; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.shelves.Shelves; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.xponder.XpdrPort; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.NetworkElementDeviceType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.PmdataEntity; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; +import org.opendaylight.yangtools.concepts.ListenerRegistration; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.binding.NotificationListener; +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 implements NetworkElement { + + // variables + private final long equipmentLevel = 0; + private static final Logger log = LoggerFactory.getLogger(OpenroadmNetworkElement.class); + private final NetconfAccessor netconfAccessor; + private final DataProvider databaseService; + 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 List<PmdataEntity> pmDataEntity = new ArrayList<PmdataEntity>(); + // end of variables + + // constructors + public OpenroadmNetworkElement(NetconfAccessor netconfAccess, DeviceManagerServiceProvider serviceProvider) { + + log.info("Create {}", OpenroadmNetworkElement.class.getSimpleName()); + this.netconfAccessor = netconfAccess; + this.databaseService = serviceProvider.getDataProvider(); + this.openRdmListenerRegistrationResult = null; + this.openRdmListener = new OpenroadmChangeNotificationListener(netconfAccessor, databaseService); + this.opnRdmFaultListenerRegistrationResult = null; + this.opnRdmFaultListener = new OpenroadmFaultNotificationListener(netconfAccessor, serviceProvider); + this.opnRdmDeviceListenerRegistrationResult = null; + this.opnRdmDeviceListener = new OpenroadmDeviceChangeNotificationListener(netconfAccessor, databaseService); + this.opnRdmInventoryInput = new OpenroadmInventoryInput(netconfAccess, readDevice(netconfAccess)); + this.circuitPacksRecord = new Hashtable<String, Long>(); + this.shelfProvisionedcircuitPacks = new Hashtable<String, Long>(); + this.openRoadmPmData = new PmDataBuilderOpenRoadm(this.netconfAccessor); + this.initialAlarmReader = new InitialDeviceAlarmReader(this.netconfAccessor, serviceProvider); + log.info("NodeId {}", this.netconfAccessor.getNodeId().getValue()); + log.info("oScaMapper details{}", this.opnRdmInventoryInput.getClass().getName()); + + } + // end of constructors + + // public methods + public void initialReadFromNetworkElement() { + OrgOpenroadmDevice device = readDevice(this.netconfAccessor); + databaseService.writeInventory(this.opnRdmInventoryInput.getInventoryData(equipmentLevel)); + + readShelvesData(device); + readXpndrData(device); + readCircuitPacketData(device); + readInterfaceData(device); + // Writing initial alarms at the time of device registration + initialAlarmReader.faultService(); + // faultEventListener.initCurrentProblemStatus(this.netconfAccessor.getNodeId(), + // oScaFaultListener.writeFaultData(this.sequenceNumber)); + // oScaFaultListener.writeAlarmLog(oScaFaultListener.writeFaultData(this.sequenceNumber)); + // this.sequenceNumber = this.sequenceNumber + 1; + + 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 NetworkElementDeviceType getDeviceType() { + return NetworkElementDeviceType.OROADM; + } + + @Override + public void register() { + initialReadFromNetworkElement(); + + this.openRdmListenerRegistrationResult = netconfAccessor.doRegisterNotificationListener(openRdmListener); + this.opnRdmFaultListenerRegistrationResult = + netconfAccessor.doRegisterNotificationListener(opnRdmFaultListener); + this.opnRdmDeviceListenerRegistrationResult = + netconfAccessor.doRegisterNotificationListener(opnRdmDeviceListener); + // Register netconf stream + netconfAccessor.registerNotificationsStream(NetconfAccessor.DefaultNotificationsStream); + + } + + @Override + public void deregister() { + if (openRdmListenerRegistrationResult != null) { + this.openRdmListenerRegistrationResult.close(); + } + if (opnRdmFaultListenerRegistrationResult != null) { + this.opnRdmFaultListenerRegistrationResult.close(); + } + if (opnRdmDeviceListenerRegistrationResult != null) { + this.opnRdmDeviceListenerRegistrationResult.close(); + } + } + + @Override + public NodeId getNodeId() { + return netconfAccessor.getNodeId(); + } + + @Override + public <L extends NetworkElementService> Optional<L> getService(Class<L> clazz) { + return Optional.empty(); + } + + @Override + public void warmstart() {} + + @Override + public Optional<NetconfAccessor> getAcessor() { + return Optional.of(netconfAccessor); + } + // end of public methods + + // private methods + private void readShelvesData(OrgOpenroadmDevice device) { + List<Shelves> shelves = 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()); + databaseService + .writeInventory(this.opnRdmInventoryInput.getShelvesInventory(shelf, equipmentLevel + 1)); + List<Slots> slotList = shelf.getSlots(); + if (slotList != null) { + for (Slots slot : slotList) { + if (!slot.getProvisionedCircuitPack().isEmpty()) { + this.shelfProvisionedcircuitPacks.put(slot.getProvisionedCircuitPack(), equipmentLevel + 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(OrgOpenroadmDevice device) { + List<Xponder> xponderList = device.getXponder(); + if (xponderList != null) { + for (Xponder xponder : xponderList) { + databaseService + .writeInventory(this.opnRdmInventoryInput.getXponderInventory(xponder, equipmentLevel + 1)); + log.info("Xponders: No.: {} , \n Port: {} ,\n Type: {}", xponder.getXpdrNumber(), xponder.getXpdrPort(), + xponder.getXpdrType()); + List<XpdrPort> xpdrportlist = xponder.getXpdrPort(); + if (xpdrportlist != null) { + for (XpdrPort xpdrport : xpdrportlist) + if (!xpdrport.getCircuitPackName().isEmpty()) { + this.shelfProvisionedcircuitPacks.put(xpdrport.getCircuitPackName(), equipmentLevel + 2); + log.info("Size of dict{}", this.shelfProvisionedcircuitPacks.size()); + } + + + } + } + + } + } + + private void readCircuitPacketData(OrgOpenroadmDevice device) { + List<CircuitPacks> circuitpacklist = device.getCircuitPacks(); + + if (circuitpacklist != null) { + for (CircuitPacks cp : circuitpacklist) { + log.info("CP Name:{}", cp.getCircuitPackName()); + if (!this.shelfProvisionedcircuitPacks.isEmpty() + && this.shelfProvisionedcircuitPacks.containsKey(cp.getCircuitPackName())) { + + this.circuitPacksRecord.put(cp.getCircuitPackName(), (equipmentLevel + 2)); + databaseService.writeInventory(this.opnRdmInventoryInput.getCircuitPackInventory(cp, + this.shelfProvisionedcircuitPacks.get(cp.getCircuitPackName()))); + log.info("shelf has circuit pack"); + } else { + if (cp.getParentCircuitPack() == null) { + this.circuitPacksRecord.put(cp.getCircuitPackName(), (equipmentLevel + 1)); + databaseService.writeInventory( + this.opnRdmInventoryInput.getCircuitPackInventory(cp, equipmentLevel + 1)); + log.info("Cp has no parent circuit pack and no shelf"); + + } else { + if (this.shelfProvisionedcircuitPacks + .containsKey(cp.getParentCircuitPack().getCircuitPackName())) { + this.circuitPacksRecord.put(cp.getCircuitPackName(), (equipmentLevel + 3)); + databaseService.writeInventory( + this.opnRdmInventoryInput.getCircuitPackInventory(cp, equipmentLevel + 3)); + log.info("Cp {} has parent circuit pack and shelf", cp.getCircuitPackName()); + } else { + this.circuitPacksRecord.put(cp.getCircuitPackName(), (equipmentLevel + 2)); + databaseService.writeInventory( + this.opnRdmInventoryInput.getCircuitPackInventory(cp, equipmentLevel + 2)); + log.info("Cp {} has parent circuit pack but no shelf", cp.getCircuitPackName()); + + } + + + } + } + + + } + + } + + } + + private void readInterfaceData(OrgOpenroadmDevice device) { + List<Interface> interfaceList = 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())) { + databaseService.writeInventory(this.opnRdmInventoryInput.getInterfacesInventory(deviceInterface, + this.circuitPacksRecord.get(deviceInterface.getSupportingCircuitPackName()) + 1)); + } + + } else { + databaseService.writeInventory( + this.opnRdmInventoryInput.getInterfacesInventory(deviceInterface, equipmentLevel + 1)); + } + } + } + + } + + private OrgOpenroadmDevice readDevice(NetconfAccessor accessor) { + + final Class<OrgOpenroadmDevice> openRoadmDev = OrgOpenroadmDevice.class; + InstanceIdentifier<OrgOpenroadmDevice> deviceId = InstanceIdentifier.builder(openRoadmDev).build(); + + OrgOpenroadmDevice device = accessor.getTransactionUtils().readData(accessor.getDataBroker(), + LogicalDatastoreType.OPERATIONAL, deviceId); + + return device; + + } + // end of private methods + + +} diff --git a/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/impl/OpenroadmNetworkElementFactory.java b/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/impl/OpenroadmNetworkElementFactory.java new file mode 100644 index 000000000..f19d2b2f4 --- /dev/null +++ b/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/impl/OpenroadmNetworkElementFactory.java @@ -0,0 +1,65 @@ +/* + * ============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.openroadm.impl; + +import java.util.List; +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.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.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 acessor, DeviceManagerServiceProvider serviceProvider) { + List<String> capabilities = acessor.getCapabilites().getCapabilities(); + + capabilities.forEach(capability -> log.info("Capabilities for element are :{}", capability)); + if (acessor.getCapabilites().isSupportingNamespace(OrgOpenroadmDevice.QNAME)) { + log.info("Create OpenRoadm device {} ", OpenroadmNetworkElement.class.getName()); + log.info("Node Id read by Acessor {}:", acessor.getNodeId().getValue()); + + return Optional.of(new OpenroadmNetworkElement(acessor, serviceProvider)); + } else { + return Optional.empty(); + } + } + // end of public methods + +} diff --git a/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/impl/PmDataBuilderOpenRoadm.java b/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/impl/PmDataBuilderOpenRoadm.java new file mode 100644 index 000000000..755f8ed9f --- /dev/null +++ b/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/impl/PmDataBuilderOpenRoadm.java @@ -0,0 +1,139 @@ +/* + * ============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.openroadm.impl; + +import java.util.ArrayList; +import java.util.List; +import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor; +import org.opendaylight.mdsal.common.api.LogicalDatastoreType; +import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev191129.HistoricalPmList; +import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev191129.historical.pm.group.HistoricalPm; +import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev191129.historical.pm.list.HistoricalPmEntry; +import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev191129.historical.pm.val.group.Measurement; +import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev191129.PmGranularity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.GranularityPeriodType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.PmdataEntity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.PmdataEntityBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.pmdata.entity.PerformanceData; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.pmdata.entity.PerformanceDataBuilder; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +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(OpenroadmNetworkElement.class); + private PmdataEntityBuilder pmDataBuilder; + + // end of variables + // constructors + public PmDataBuilderOpenRoadm(NetconfAccessor accessor) { + this.pmDataBuilder = new PmdataEntityBuilder(); + this.pmDataBuilder.setNodeName(accessor.getNodeId().getValue()); + } + + // end of constructors + // public methods + // Read PM data + public HistoricalPmList getPmData(NetconfAccessor 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<>(); + List<HistoricalPmEntry> pmDataEntryList = historicalPmEnitityList.getHistoricalPmEntry(); + for (HistoricalPmEntry pmDataEntry : pmDataEntryList) { + pmDataBuilder.setUuidInterface(pmDataEntry.getPmResourceType().getName()); + List<HistoricalPm> historicalPmList = pmDataEntry.getHistoricalPm(); + for (HistoricalPm historicalPm : historicalPmList) { + log.info("PmName:{}", historicalPm.getType()); + this.pmDataBuilder.setScannerId(historicalPm.getType().getName()); + writeperformanceData(historicalPm); + log.info("NodeName: {}, Scanner Id:{}, Period: {}", this.pmDataBuilder.getNodeName(), + this.pmDataBuilder.getScannerId(), this.pmDataBuilder.getGranularityPeriod().getName()); + 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) { + List<Measurement> measurementList = historicalPm.getMeasurement(); + + for (Measurement measurementData : measurementList) { + this.pmDataBuilder.setGranularityPeriod(mapGranularityPeriod(measurementData.getGranularity())) + .setPerformanceData(getPerformancedata(measurementData)) + .setTimeStamp(measurementData.getCompletionTime()); + if (measurementData.getValidity().getName().equals("suspect")) { + this.pmDataBuilder.setSuspectIntervalFlag(true); + } + log.info("Time:d{}, \n Scannerid: {}, \n UUID: {}", this.pmDataBuilder.getGranularityPeriod().getName(), + this.pmDataBuilder.getScannerId(), this.pmDataBuilder.getUuidInterface()); + } + } + + //Map Performance data of PmDataEntity with MeasurmentData-HistoricalPm + private PerformanceData getPerformancedata(Measurement measurementData) { + PerformanceData performanceData; + PerformanceDataBuilder performanceDataBuilder = new PerformanceDataBuilder(); + performanceData = performanceDataBuilder.setCses(measurementData.getBinNumber()) + .setSes(measurementData.getPmParameterValue().getUint64().intValue()).build(); + return performanceData; + } + + // Mapping Granularity period of PmDataEntity with PmGranularity of MeasurmentData-HistoricalPm + private GranularityPeriodType mapGranularityPeriod(PmGranularity pmGranularity) { + + GranularityPeriodType granPeriod = null; + switch (pmGranularity.getName()) { + 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; + } + // end of private methods +} diff --git a/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/opendaylight/yang/gen/v1/http/org/openroadm/pm/types/rev191129/PmDataTypeBuilder.java b/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/opendaylight/yang/gen/v1/http/org/openroadm/pm/types/rev191129/PmDataTypeBuilder.java new file mode 100644 index 000000000..249da71fb --- /dev/null +++ b/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/opendaylight/yang/gen/v1/http/org/openroadm/pm/types/rev191129/PmDataTypeBuilder.java @@ -0,0 +1,21 @@ +package org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev191129; + +/** + * 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"); + } + +} diff --git a/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/alarms/rev190911/OperatorStateBuilder.java b/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/alarms/rev190911/OperatorStateBuilder.java new file mode 100644 index 000000000..30a55a203 --- /dev/null +++ b/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/alarms/rev190911/OperatorStateBuilder.java @@ -0,0 +1,21 @@ +package org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.alarms.rev190911; + +/** + * 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 OperatorStateBuilder { + private OperatorStateBuilder() { + //Exists only to defeat instantiation. + } + + public static OperatorState getDefaultInstance(String defaultValue) { + throw new UnsupportedOperationException("Not yet implemented"); + } + +} diff --git a/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/alarms/rev190911/ResourceBuilder.java b/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/alarms/rev190911/ResourceBuilder.java new file mode 100644 index 000000000..a803bae97 --- /dev/null +++ b/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/alarms/rev190911/ResourceBuilder.java @@ -0,0 +1,21 @@ +package org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.alarms.rev190911; + +/** + * 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 ResourceBuilder { + private ResourceBuilder() { + //Exists only to defeat instantiation. + } + + public static Resource getDefaultInstance(String defaultValue) { + throw new UnsupportedOperationException("Not yet implemented"); + } + +} diff --git a/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/alarms/rev190911/ResourceMatchBuilder.java b/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/alarms/rev190911/ResourceMatchBuilder.java new file mode 100644 index 000000000..bbfa37f40 --- /dev/null +++ b/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/alarms/rev190911/ResourceMatchBuilder.java @@ -0,0 +1,21 @@ +package org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.alarms.rev190911; + +/** + * 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 ResourceMatchBuilder { + private ResourceMatchBuilder() { + //Exists only to defeat instantiation. + } + + public static ResourceMatch getDefaultInstance(String defaultValue) { + throw new UnsupportedOperationException("Not yet implemented"); + } + +} diff --git a/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/alarms/rev190911/SeverityWithClearBuilder.java b/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/alarms/rev190911/SeverityWithClearBuilder.java new file mode 100644 index 000000000..9fb90b438 --- /dev/null +++ b/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/alarms/rev190911/SeverityWithClearBuilder.java @@ -0,0 +1,21 @@ +package org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.alarms.rev190911; + +/** + * 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 SeverityWithClearBuilder { + private SeverityWithClearBuilder() { + //Exists only to defeat instantiation. + } + + public static SeverityWithClear getDefaultInstance(String defaultValue) { + throw new UnsupportedOperationException("Not yet implemented"); + } + +} diff --git a/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/alarms/rev190911/alarms/ControlMaxAlarmStatusChangesBuilder.java b/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/alarms/rev190911/alarms/ControlMaxAlarmStatusChangesBuilder.java new file mode 100644 index 000000000..2b8e8af57 --- /dev/null +++ b/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/alarms/rev190911/alarms/ControlMaxAlarmStatusChangesBuilder.java @@ -0,0 +1,21 @@ +package org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.alarms.rev190911.alarms; + +/** + * 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 ControlMaxAlarmStatusChangesBuilder { + private ControlMaxAlarmStatusChangesBuilder() { + //Exists only to defeat instantiation. + } + + public static Control.MaxAlarmStatusChanges getDefaultInstance(String defaultValue) { + throw new UnsupportedOperationException("Not yet implemented"); + } + +} |