+ @Override
+ public void updateTapiTopology(String nodeId, Mapping mapping) {
+ List<Uuid> uuids = getChangedNodeUuids(nodeId, mapping);
+
+ List<Uuid> changedOneps = updateNeps(mapping, uuids);
+ updateLinks(changedOneps, mapping);
+ sendNotification(changedOneps, mapping);
+
+ LOG.info("Updated TAPI topology successfully.");
+ }
+
+ @SuppressWarnings("rawtypes")
+ private void sendNotification(List<Uuid> changedOneps, Mapping mapping) {
+ Notification notification = new NotificationBuilder()
+ .setNotificationType(NotificationType.ATTRIBUTEVALUECHANGE)
+ .setTargetObjectType(ObjectType.NODEEDGEPOINT)
+ .setChangedAttributes(getChangedAttributes(changedOneps, mapping))
+ .setUuid(tapiTopoUuid)
+ .build();
+ try {
+ notificationPublishService.putNotification(notification);
+ } catch (InterruptedException e) {
+ LOG.error("Could not send notification");
+ }
+ }
+
+ private Map<ChangedAttributesKey, ChangedAttributes> getChangedAttributes(List<Uuid> changedOneps,
+ Mapping mapping) {
+ Map<ChangedAttributesKey, ChangedAttributes> changedAttributes = new HashMap<>();
+ for (Uuid nep : changedOneps) {
+ changedAttributes.put(new ChangedAttributesKey(nep.getValue()),
+ new ChangedAttributesBuilder().setValueName(nep.getValue())
+ .setOldValue(mapping.getPortOperState().equals("InService") ? "OutOfService" : "InService")
+ .setNewValue(mapping.getPortOperState())
+ .build());
+ }
+ return changedAttributes;
+ }
+
+ private void updateLinks(List<Uuid> changedOneps, Mapping mapping) {
+ try {
+ InstanceIdentifier<Topology> topoIID = InstanceIdentifier.builder(Context.class)
+ .augmentation(Context1.class).child(TopologyContext.class)
+ .child(Topology.class, new TopologyKey(tapiTopoUuid))
+ .build();
+ Optional<Topology> optTopology = this.networkTransactionService
+ .read(LogicalDatastoreType.OPERATIONAL, topoIID).get();
+ if (optTopology.isEmpty()) {
+ LOG.error("Could not update TAPI links");
+ return;
+ }
+ for (Link link : optTopology.get().nonnullLink().values()) {
+ List<Uuid> linkNeps = Objects.requireNonNull(link.getNodeEdgePoint()).values().stream()
+ .map(NodeEdgePointRef::getNodeEdgePointUuid).collect(Collectors.toList());
+ if (!Collections.disjoint(changedOneps, linkNeps)) {
+ InstanceIdentifier<Link> linkIID = InstanceIdentifier.builder(Context.class)
+ .augmentation(Context1.class).child(TopologyContext.class)
+ .child(Topology.class, new TopologyKey(tapiTopoUuid))
+ .child(Link.class, new LinkKey(link.getUuid())).build();
+ Link linkblr = new LinkBuilder().setUuid(link.getUuid())
+ .setAdministrativeState(transformAdminState(mapping.getPortAdminState()))
+ .setOperationalState(transformOperState(mapping.getPortOperState())).build();
+ this.networkTransactionService.merge(LogicalDatastoreType.OPERATIONAL, linkIID, linkblr);
+ }
+ }
+ this.networkTransactionService.commit().get();
+ } catch (InterruptedException | ExecutionException e) {
+ LOG.error("Could not update TAPI links");
+ }
+ }
+
+ private List<Uuid> updateNeps(Mapping mapping, List<Uuid> uuids) {
+ List<Uuid> changedOneps = new ArrayList<>();
+ for (Uuid nodeUuid : uuids) {
+ try {
+ InstanceIdentifier<Node> nodeIID = InstanceIdentifier.builder(Context.class)
+ .augmentation(Context1.class).child(TopologyContext.class)
+ .child(Topology.class, new TopologyKey(tapiTopoUuid)).child(Node.class, new NodeKey(nodeUuid))
+ .build();
+ Optional<Node> optionalNode = this.networkTransactionService.read(
+ LogicalDatastoreType.OPERATIONAL, nodeIID).get();
+ if (optionalNode.isPresent()) {
+ Node node = optionalNode.get();
+ List<OwnedNodeEdgePoint> oneps = node.getOwnedNodeEdgePoint().values().stream()
+ .filter(onep -> ((Name) onep.getName().values().toArray()[0]).getValue()
+ .contains(mapping.getLogicalConnectionPoint())).collect(Collectors.toList());
+ for (OwnedNodeEdgePoint onep : oneps) {
+ changedOneps.add(onep.getUuid());
+ updateSips(mapping, onep);
+ CepList cepList = getUpdatedCeps(mapping, onep);
+ InstanceIdentifier<OwnedNodeEdgePoint> onepIID = InstanceIdentifier.builder(Context.class)
+ .augmentation(Context1.class).child(TopologyContext.class)
+ .child(Topology.class, new TopologyKey(tapiTopoUuid))
+ .child(Node.class, new NodeKey(nodeUuid))
+ .child(OwnedNodeEdgePoint.class, new OwnedNodeEdgePointKey(onep.getUuid()))
+ .build();
+ OwnedNodeEdgePoint onepblr = new OwnedNodeEdgePointBuilder().setUuid(onep.getUuid())
+ .addAugmentation(new OwnedNodeEdgePoint1Builder().setCepList(cepList).build())
+ .setAdministrativeState(transformAdminState(mapping.getPortAdminState()))
+ .setOperationalState(transformOperState(mapping.getPortOperState())).build();
+ this.networkTransactionService.merge(LogicalDatastoreType.OPERATIONAL, onepIID, onepblr);
+ }
+ this.networkTransactionService.commit().get();
+ }
+ } catch (InterruptedException | ExecutionException e) {
+ LOG.error("Could not update TAPI NEP");
+ }
+ }
+ return changedOneps;
+ }
+
+ private CepList getUpdatedCeps(Mapping mapping, OwnedNodeEdgePoint onep) {
+ OwnedNodeEdgePoint1 onep1 = onep.augmentation(OwnedNodeEdgePoint1.class);
+ Map<ConnectionEndPointKey, ConnectionEndPoint> cepMap = new HashMap<>();
+ if (onep1 != null && onep1.getCepList() != null && onep1.getCepList().getConnectionEndPoint() != null) {
+ for (Map.Entry<ConnectionEndPointKey, ConnectionEndPoint> entry : onep1.getCepList().getConnectionEndPoint()
+ .entrySet()) {
+ ConnectionEndPoint cep = new ConnectionEndPointBuilder(entry.getValue())
+ .setOperationalState(transformOperState(mapping.getPortOperState())).build();
+ cepMap.put(entry.getKey(), cep);
+ }
+ }
+ return new CepListBuilder().setConnectionEndPoint(cepMap).build();
+ }
+
+ private List<Uuid> getChangedNodeUuids(String nodeId, Mapping mapping) {
+ List<Uuid> uuids = new ArrayList<>();
+ if (nodeId.contains("ROADM")) {
+ uuids.add(new Uuid(UUID.nameUUIDFromBytes((String.join("+", nodeId, TapiStringConstants.PHTNC_MEDIA))
+ .getBytes(StandardCharsets.UTF_8)).toString()));
+ } else if (nodeId.contains("PDR") && mapping.getLogicalConnectionPoint().contains("CLIENT")) {
+ int xpdrNb = Integer.parseInt(mapping.getLogicalConnectionPoint().split("XPDR")[1].split("-")[0]);
+ String xpdrNodeId = nodeId + TapiStringConstants.XPDR + xpdrNb;
+ uuids.add(new Uuid(UUID.nameUUIDFromBytes((String.join("+", xpdrNodeId, TapiStringConstants.DSR))
+ .getBytes(StandardCharsets.UTF_8)).toString()));
+ } else if (nodeId.contains("PDR") && mapping.getLogicalConnectionPoint().contains("NETWORK")) {
+ int xpdrNb = Integer.parseInt(mapping.getLogicalConnectionPoint().split("XPDR")[1].split("-")[0]);
+ String xpdrNodeId = nodeId + TapiStringConstants.XPDR + xpdrNb;
+ uuids.add(new Uuid(UUID.nameUUIDFromBytes((String.join("+", xpdrNodeId, TapiStringConstants.DSR))
+ .getBytes(StandardCharsets.UTF_8)).toString()));
+ uuids.add(new Uuid(UUID.nameUUIDFromBytes((String.join("+", xpdrNodeId, TapiStringConstants.OTSI))
+ .getBytes(StandardCharsets.UTF_8)).toString()));
+ } else {
+ LOG.error("Updating this device is currently not supported");
+ return uuids;
+ }
+ return uuids;
+ }
+
+ private void updateSips(Mapping mapping, OwnedNodeEdgePoint onep) {
+ if (onep.getMappedServiceInterfacePoint() == null
+ || onep.getMappedServiceInterfacePoint().size() == 0) {
+ return;
+ }
+ for (MappedServiceInterfacePoint msip : onep.getMappedServiceInterfacePoint().values()) {
+ InstanceIdentifier<ServiceInterfacePoint> sipIID = InstanceIdentifier
+ .builder(Context.class)
+ .child(ServiceInterfacePoint.class,
+ new ServiceInterfacePointKey(msip.getServiceInterfacePointUuid()))
+ .build();
+ ServiceInterfacePoint sipblr = new ServiceInterfacePointBuilder()
+ .setUuid(msip.getServiceInterfacePointUuid())
+ .setAdministrativeState(transformAdminState(mapping.getPortAdminState()))
+ .setOperationalState(transformOperState(mapping.getPortOperState())).build();
+ this.networkTransactionService.merge(LogicalDatastoreType.OPERATIONAL, sipIID, sipblr);
+ }
+
+ }
+