X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=networkmodel%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Ftransportpce%2Fnetworkmodel%2Flisteners%2FAlarmNotificationListener221.java;h=d7336eb559d6cbdff72f373920e29569bde88d81;hb=d03abd5d1287ce81ae3c6c4ff58fe255c77fc427;hp=98cabb96e7bc018b0eda6e0e9e454669c869551b;hpb=38da8caec743f447c641ce0f414c242a5ece363b;p=transportpce.git diff --git a/networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/listeners/AlarmNotificationListener221.java b/networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/listeners/AlarmNotificationListener221.java index 98cabb96e..d7336eb55 100644 --- a/networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/listeners/AlarmNotificationListener221.java +++ b/networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/listeners/AlarmNotificationListener221.java @@ -10,9 +10,10 @@ package org.opendaylight.transportpce.networkmodel.listeners; import java.util.ArrayList; import java.util.List; import java.util.Optional; +import java.util.Set; import java.util.concurrent.ExecutionException; - import org.opendaylight.mdsal.binding.api.DataBroker; +import org.opendaylight.mdsal.binding.api.NotificationService.CompositeListener; import org.opendaylight.mdsal.binding.api.ReadTransaction; import org.opendaylight.mdsal.common.api.LogicalDatastoreType; import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102.ServiceNodelist; @@ -20,7 +21,6 @@ import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsupp import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102.service.nodelist.nodelist.Nodes; import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102.service.nodelist.nodelist.NodesBuilder; import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev181019.AlarmNotification; -import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev181019.OrgOpenroadmAlarmListener; import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev181019.alarm.ProbableCause; import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev181019.resource.ResourceType; import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev181019.resource.resource.Resource; @@ -38,7 +38,7 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class AlarmNotificationListener221 implements OrgOpenroadmAlarmListener { +public class AlarmNotificationListener221 { private static final Logger LOG = LoggerFactory.getLogger(AlarmNotificationListener221.class); private static final String PIPE = "|"; @@ -48,14 +48,17 @@ public class AlarmNotificationListener221 implements OrgOpenroadmAlarmListener { this.dataBroker = dataBroker; } + public CompositeListener getCompositeListener() { + return new CompositeListener(Set.of( + new CompositeListener.Component<>(AlarmNotification.class, this::onAlarmNotification))); + } /** * Callback for alarm-notification. * * @param notification AlarmNotification object */ - @Override - public void onAlarmNotification(AlarmNotification notification) { + private void onAlarmNotification(AlarmNotification notification) { List allNodeList = new ArrayList<>(); InstanceIdentifier serviceNodeListIID = InstanceIdentifier.create(ServiceNodelist.class); try { @@ -63,44 +66,37 @@ public class AlarmNotificationListener221 implements OrgOpenroadmAlarmListener { Optional serviceListObject = rtx.read(LogicalDatastoreType.OPERATIONAL, serviceNodeListIID).get(); if (serviceListObject.isPresent()) { - for (Nodelist nodelist : serviceListObject.get().getNodelist()) { - allNodeList.addAll(nodelist.getNodes()); + for (Nodelist nodelist : serviceListObject.orElseThrow().nonnullNodelist().values()) { + allNodeList.addAll(nodelist.nonnullNodes().values()); } } } catch (InterruptedException | ExecutionException ex) { LOG.warn("Exception thrown while reading Logical Connection Point value", ex); } - StringBuilder sb = new StringBuilder(notification.getResource().getDevice().getNodeId().getValue()) - .append(PIPE); - sb.append(buildCause(notification.getProbableCause())); - sb.append(notification.getId() != null ? notification.getId() : "").append(PIPE) - .append(notification.getRaiseTime() != null ? notification.getRaiseTime().toString() : "").append(PIPE) - .append(notification.getSeverity() != null ? notification.getSeverity().getName() : "").append(PIPE) - .append(notification.getCircuitId() != null ? notification.getCircuitId() : "").append(PIPE); - - sb.append(buildType(notification)); + String message = String.join(PIPE,notification.getResource().getDevice().getNodeId().getValue(), + buildCause(notification.getProbableCause()),notification.getId() != null ? notification.getId() : "", + notification.getRaiseTime() != null ? notification.getRaiseTime().toString() : "", + notification.getSeverity() != null ? notification.getSeverity().getName() : "", + notification.getCircuitId() != null ? notification.getCircuitId() : "", buildType(notification)); - String message = sb.toString(); Nodes build = new NodesBuilder().setNodeId(notification.getResource().getDevice().getNodeId().getValue()) .build(); if (allNodeList.contains(build)) { - LOG.info(message); + LOG.info("onAlarmNotification: {}", message); } else { - LOG.warn(message); + LOG.warn("onAlarmNotification: {}", message); } } private String buildCause(ProbableCause probableCause) { - StringBuilder sb = new StringBuilder(); if (probableCause == null) { return "||||"; } - sb.append((probableCause.getCause() != null) ? probableCause.getCause().getName() : "").append(PIPE) - .append((probableCause.getDirection() != null) ? probableCause.getDirection().getName() : "") - .append(PIPE).append((probableCause.getExtension() != null) ? probableCause.getExtension() : "") - .append(PIPE).append((probableCause.getLocation() != null) ? probableCause.getLocation().getName() : "") - .append(PIPE); - return sb.toString(); + return String.join(PIPE, + (probableCause.getCause() != null) ? probableCause.getCause().getName() : "", + (probableCause.getDirection() != null) ? probableCause.getDirection().getName() : "", + (probableCause.getExtension() != null) ? probableCause.getExtension() : "", + (probableCause.getLocation() != null) ? probableCause.getLocation().getName() : ""); } @SuppressWarnings("unchecked") @@ -108,13 +104,14 @@ public class AlarmNotificationListener221 implements OrgOpenroadmAlarmListener { Resource resource) { if (resource == null) { LOG.error("Resource is null."); - } else if (!resourceClass.isInstance(resource)) { + return Optional.empty(); + } + if (!resourceClass.isInstance(resource)) { LOG.error("Resource implement different type than expected. Expected {}, actual {}.", resourceClass.getSimpleName(), resource.getClass().getSimpleName()); - } else { - return Optional.of((T) resource); + return Optional.empty(); } - return Optional.empty(); + return Optional.of((T) resource); } private static String buildType(AlarmNotification notification) { @@ -137,82 +134,78 @@ public class AlarmNotificationListener221 implements OrgOpenroadmAlarmListener { case CircuitPack: Optional circuitPackOptional = tryCastToParticularResource(CircuitPack.class, resource); if (circuitPackOptional.isPresent()) { - circuitPack = circuitPackOptional.get().getCircuitPackName(); + circuitPack = circuitPackOptional.orElseThrow().getCircuitPackName(); } break; case Connection: Optional connectionOptional = tryCastToParticularResource(Connection.class, resource); if (connectionOptional.isPresent()) { - connection = connectionOptional.get().getConnectionName(); + connection = connectionOptional.orElseThrow().getConnectionName(); } break; case Degree: Optional degreeOptional = tryCastToParticularResource(Degree.class, resource); if (degreeOptional.isPresent()) { - degree = degreeOptional.get().getDegreeNumber().toString(); + degree = degreeOptional.orElseThrow().getDegreeNumber().toString(); } break; case Interface: Optional interfaceOptional = tryCastToParticularResource(Interface.class, resource); if (interfaceOptional.isPresent()) { - iface = interfaceOptional.get().getInterfaceName(); + iface = interfaceOptional.orElseThrow().getInterfaceName(); } break; case InternalLink: Optional internalLinkOptional = tryCastToParticularResource(InternalLink.class, resource); if (internalLinkOptional.isPresent()) { - internalLink = internalLinkOptional.get().getInternalLinkName(); + internalLink = internalLinkOptional.orElseThrow().getInternalLinkName(); } break; case PhysicalLink: Optional physicalLinkOptional = tryCastToParticularResource(PhysicalLink.class, resource); if (physicalLinkOptional.isPresent()) { - physicalLink = physicalLinkOptional.get().getPhysicalLinkName(); + physicalLink = physicalLinkOptional.orElseThrow().getPhysicalLinkName(); } break; case Service: Optional serviceOptional = tryCastToParticularResource(Service.class, resource); if (serviceOptional.isPresent()) { - service = serviceOptional.get().getServiceName(); + service = serviceOptional.orElseThrow().getServiceName(); } break; case Shelf: Optional shelfOptional = tryCastToParticularResource(Shelf.class, resource); if (shelfOptional.isPresent()) { - shelf = shelfOptional.get().getShelfName(); + shelf = shelfOptional.orElseThrow().getShelfName(); } break; case SharedRiskGroup: Optional sharedRiskGroupOptional = tryCastToParticularResource(Srg.class, resource); if (sharedRiskGroupOptional.isPresent()) { - sharedRiskGroup = sharedRiskGroupOptional.get().getSrgNumber().toString(); + sharedRiskGroup = sharedRiskGroupOptional.orElseThrow().getSrgNumber().toString(); } break; case Port: Optional portContainerOptional = tryCastToParticularResource(Port.class, resource); if (portContainerOptional.isPresent()) { - port = portContainerOptional.get().getPort().getPortName(); - portCircuitPack = portContainerOptional.get().getPort().getCircuitPackName(); + port = portContainerOptional.orElseThrow().getPort().getPortName(); + portCircuitPack = portContainerOptional.orElseThrow().getPort().getCircuitPackName(); } break; default: LOG.warn("Unknown resource type {}", wantedResourceType); } - StringBuilder sb = new StringBuilder(circuitPack); - sb.append(PIPE).append(connection).append(PIPE).append(degree).append(PIPE).append(iface); - sb.append(PIPE).append(internalLink).append(PIPE).append(physicalLink).append(PIPE).append(service); - sb.append(PIPE).append(shelf).append(PIPE).append(sharedRiskGroup).append(PIPE).append(port); - sb.append(PIPE).append(portCircuitPack); - return sb.toString(); + return String.join(PIPE, circuitPack, connection, degree, iface, internalLink, physicalLink, + service, shelf, sharedRiskGroup, port, portCircuitPack); } }