Declare SuppressFBWarnings in imports
[transportpce.git] / renderer / src / main / java / org / opendaylight / transportpce / renderer / provisiondevice / DeviceRendererServiceImpl.java
index 39be93c61ee928291fc2fde5d4a7ab1096b397ee..032c474105c5aa03209474da72db2a803eef137c 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.transportpce.renderer.provisiondevice;
 
 import com.google.common.collect.Sets;
 import com.google.common.util.concurrent.FluentFuture;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
@@ -41,6 +42,7 @@ import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
 import org.opendaylight.transportpce.common.fixedflex.GridConstant;
 import org.opendaylight.transportpce.common.fixedflex.GridUtils;
 import org.opendaylight.transportpce.common.fixedflex.SpectrumInformation;
+import org.opendaylight.transportpce.common.mapping.MappingUtils;
 import org.opendaylight.transportpce.common.mapping.PortMapping;
 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaceException;
 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
@@ -78,10 +80,13 @@ import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev220926
 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev220926.node.interfaces.NodeInterfaceKey;
 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev220926.optical.renderer.nodes.Nodes;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-
+@Component
 public class DeviceRendererServiceImpl implements DeviceRendererService {
     private static final String IS_NOT_MOUNTED_ON_THE_CONTROLLER = " is not mounted on the controller";
     private static final Logger LOG = LoggerFactory.getLogger(DeviceRendererServiceImpl.class);
@@ -93,15 +98,19 @@ public class DeviceRendererServiceImpl implements DeviceRendererService {
     private final CrossConnect crossConnect;
     private final PortMapping portMapping;
 
-    public DeviceRendererServiceImpl(DataBroker dataBroker, DeviceTransactionManager deviceTransactionManager,
-            OpenRoadmInterfaceFactory openRoadmInterfaceFactory, OpenRoadmInterfaces openRoadmInterfaces,
-            CrossConnect crossConnect, PortMapping portMapping) {
+    @Activate
+    public DeviceRendererServiceImpl(@Reference DataBroker dataBroker,
+            @Reference DeviceTransactionManager deviceTransactionManager,
+            @Reference OpenRoadmInterfaces openRoadmInterfaces,
+            @Reference CrossConnect crossConnect,
+            @Reference MappingUtils mappingUtils,
+            @Reference PortMapping portMapping) {
         this.dataBroker = dataBroker;
         this.deviceTransactionManager = deviceTransactionManager;
-        this.openRoadmInterfaceFactory = openRoadmInterfaceFactory;
         this.openRoadmInterfaces = openRoadmInterfaces;
         this.crossConnect = crossConnect;
         this.portMapping = portMapping;
+        this.openRoadmInterfaceFactory = new OpenRoadmInterfaceFactory(mappingUtils, portMapping, openRoadmInterfaces);
     }
 
     @SuppressWarnings("rawtypes")
@@ -158,14 +167,25 @@ public class DeviceRendererServiceImpl implements DeviceRendererService {
                         // Split the string based on # pass the last element as the supported Interface
                         // This is needed for 7.1 device models with B100G, we have OTSI, OTSI-group combined as OCH
                         String[] listOfSuppOchInf = supportingOchInterface.split("#");
-                        createdOchInterfaces = Set.of(listOfSuppOchInf);
+                        List<String> createdOchInf = Arrays.asList(listOfSuppOchInf);
+                        createdOchInterfaces.addAll(createdOchInf);
+                        LOG.info("DEST all otsi interfaces {}", createdOchInterfaces);
                         // Taking the last element
-                        supportingOchInterface = listOfSuppOchInf[createdOchInterfaces.size() - 1];
-                        String supportingOtuInterface = this.openRoadmInterfaceFactory.createOpenRoadmOtu4Interface(
-                                nodeId, destTp, supportingOchInterface, apiInfoA, apiInfoZ);
+                        supportingOchInterface = listOfSuppOchInf[createdOchInf.size() - 1];
+                        String supportingOtuInterface = this.openRoadmInterfaceFactory
+                                .createOpenRoadmOtu4Interface(nodeId, destTp, supportingOchInterface, apiInfoA,
+                                        apiInfoZ);
                         createdOtuInterfaces.add(supportingOtuInterface);
+                        LOG.info("all dest otu interfaces {}", createdOtuInterfaces);
                         if (srcTp == null) {
                             otnLinkTps.add(new LinkTpBuilder().setNodeId(nodeId).setTpId(destTp).build());
+                        } else if (srcTp.contains(StringConstants.NETWORK_TOKEN)) {
+                            // If src and dest tp contains the network token, then it is regenerator
+                            LOG.info("Create the ODUCn for regen on the dest-tp");
+                            // Here we first create ODUCn interface for the Regen
+                            createdOduInterfaces.add(this.openRoadmInterfaceFactory
+                                    .createOpenRoadmOducn(nodeId, destTp));
+                            LOG.info("all dest odu interfaces {}", createdOduInterfaces);
                         } else {
                             // This is needed for 7.1 device models for 400GE, since we have ODUC4 and ODUflex
                             // are combined
@@ -188,7 +208,7 @@ public class DeviceRendererServiceImpl implements DeviceRendererService {
                         // create OpenRoadm Xponder Line Interfaces
                         String supportingOchInterface = this.openRoadmInterfaceFactory.createOpenRoadmOchInterface(
                                 nodeId, srcTp, spectrumInformation);
-                        createdOchInterfaces.add(supportingOchInterface);
+                        // createdOchInterfaces.add(supportingOchInterface);
                         // Split the string based on # pass the last element as the supported Interface
                         // This is needed for 7.1 device models with B100G, we have OTSI, OTSI-group combined as OCH
                         String[] listOfSuppOchInf = supportingOchInterface.split("#");
@@ -201,6 +221,13 @@ public class DeviceRendererServiceImpl implements DeviceRendererService {
                         createdOtuInterfaces.add(supportingOtuInterface);
                         if (destTp == null) {
                             otnLinkTps.add(new LinkTpBuilder().setNodeId(nodeId).setTpId(srcTp).build());
+                        } else if (destTp.contains(StringConstants.NETWORK_TOKEN)) {
+                            // If the src and dest tp have network-token, then it is a regen
+                            LOG.info("Create the regen-interfaces on the src-tp");
+                            // Here we first create ODUCn interface for the Regen
+                            createdOduInterfaces.add(this.openRoadmInterfaceFactory.createOpenRoadmOducn(nodeId,
+                                    srcTp));
+                            LOG.info("all src odu interfaces {}", createdOduInterfaces);
                         } else {
                             createdOduInterfaces.add(this.openRoadmInterfaceFactory.createOpenRoadmOdu4HOInterface(
                                     nodeId, srcTp, false, apiInfoA, apiInfoZ, PT_07));
@@ -234,7 +261,7 @@ public class DeviceRendererServiceImpl implements DeviceRendererService {
                                 this.crossConnect.postCrossConnect(nodeId, srcTp, destTp, spectrumInformation);
                         if (connectionNameOpt.isPresent()) {
                             nodesProvisioned.add(nodeId);
-                            createdConnections.add(connectionNameOpt.get());
+                            createdConnections.add(connectionNameOpt.orElseThrow());
                         } else {
                             processErrorMessage("Unable to post Roadm-connection for node " + nodeId, forkJoinPool,
                                     results);
@@ -277,7 +304,7 @@ public class DeviceRendererServiceImpl implements DeviceRendererService {
             LOG.warn("Failed to write topologies for service {}.", input.getServiceName(), e);
         }
         if (!alarmSuppressionNodeRemoval(input.getServiceName())) {
-            LOG.error("Alarm suppresion node removal failed!!!!");
+            LOG.error("Alarm suppression node removal failed!!!!");
         }
         return new ServicePathOutputBuilder()
                 .setNodeInterface(nodeInterfaces)
@@ -421,57 +448,57 @@ public class DeviceRendererServiceImpl implements DeviceRendererService {
         // common GridConstant that states NAME_PARAMETERS_SEPARATOR = "-"
 
         if (destTp.contains(StringConstants.NETWORK_TOKEN)) {
-            try {
-                for (String suffix : suffixListMap.get("ODU")) {
-                    if (this.openRoadmInterfaces.getInterface(
-                            nodeId, String.join(GridConstant.NAME_PARAMETERS_SEPARATOR, destTp, suffix)).isPresent()) {
-                        interfacesToDelete.add(String.join(GridConstant.NAME_PARAMETERS_SEPARATOR, destTp, suffix));
-                    }
-                }
-            }
-            catch (OpenRoadmInterfaceException e) {
-                LOG.error("impossible to get one of the interfaces {}",
-                    destTp + GridConstant.NAME_PARAMETERS_SEPARATOR + String.join(
-                        " or " + destTp + GridConstant.NAME_PARAMETERS_SEPARATOR,
-                        suffixListMap.get("ODU")),
-                    e);
-            }
-            try {
-                for (String suffix : suffixListMap.get("other")) {
-                    if (this.openRoadmInterfaces.getInterface(
-                        nodeId, String.join(GridConstant.NAME_PARAMETERS_SEPARATOR, destTp, suffix)).isPresent()) {
-                        LOG.info("Deleting the interface {}",
-                            String.join(GridConstant.NAME_PARAMETERS_SEPARATOR, destTp, suffix));
-                        interfacesToDelete.add(String.join(GridConstant.NAME_PARAMETERS_SEPARATOR, destTp, suffix));
-                    }
-                }
-            }
-            catch (OpenRoadmInterfaceException e) {
-                LOG.error("impossible to get one of the interfaces {}",
-                    destTp + GridConstant.NAME_PARAMETERS_SEPARATOR + String.join(
-                        " or " + destTp + GridConstant.NAME_PARAMETERS_SEPARATOR,
-                        suffixListMap.get("ODU")),
-                    e);
-            }
+            interfacesToDelete.addAll(inf2Del(destTp, suffixListMap, nodeId));
         }
         if (srcTp.contains(StringConstants.NETWORK_TOKEN)) {
-            interfacesToDelete.add(
-                    String.join(GridConstant.NAME_PARAMETERS_SEPARATOR, srcTp, suffixListMap.get("ODU").get(0)));
-            for (String suffix : suffixListMap.get("other")) {
-                interfacesToDelete.add(String.join(GridConstant.NAME_PARAMETERS_SEPARATOR, srcTp, suffix));
-            }
+            // For a regen case, the srcTp can also contain the network-token
+            interfacesToDelete.addAll(inf2Del(srcTp, suffixListMap, nodeId));
         }
-
         if (srcTp.contains(StringConstants.CLIENT_TOKEN)) {
             interfacesToDelete.add(String.join(GridConstant.NAME_PARAMETERS_SEPARATOR, srcTp, "ETHERNET"));
         }
         if (destTp.contains(StringConstants.CLIENT_TOKEN)) {
-
             interfacesToDelete.add(String.join(GridConstant.NAME_PARAMETERS_SEPARATOR, destTp, "ETHERNET"));
         }
         return interfacesToDelete;
     }
 
+    private List<String> inf2Del(String termPoint, Map<String, List<String>> suffixListMap, String nodeId) {
+        List<String> inf2Del = new LinkedList<>();
+        try {
+            for (String suffix : suffixListMap.get("ODU")) {
+                if (this.openRoadmInterfaces.getInterface(
+                        nodeId, String.join(GridConstant.NAME_PARAMETERS_SEPARATOR, termPoint, suffix)).isPresent()) {
+                    inf2Del.add(String.join(GridConstant.NAME_PARAMETERS_SEPARATOR, termPoint, suffix));
+                }
+            }
+        }
+        catch (OpenRoadmInterfaceException e) {
+            LOG.error("impossible to get one of the interfaces {}",
+                    termPoint + GridConstant.NAME_PARAMETERS_SEPARATOR + String.join(
+                            " or " + termPoint + GridConstant.NAME_PARAMETERS_SEPARATOR,
+                            suffixListMap.get("ODU")),
+                    e);
+        }
+        try {
+            for (String suffix : suffixListMap.get("other")) {
+                if (this.openRoadmInterfaces.getInterface(
+                        nodeId, String.join(GridConstant.NAME_PARAMETERS_SEPARATOR, termPoint, suffix)).isPresent()) {
+                    LOG.info("Deleting the interface {}",
+                            String.join(GridConstant.NAME_PARAMETERS_SEPARATOR, termPoint, suffix));
+                    inf2Del.add(String.join(GridConstant.NAME_PARAMETERS_SEPARATOR, termPoint, suffix));
+                }
+            }
+        }
+        catch (OpenRoadmInterfaceException e) {
+            LOG.error("impossible to get one of the interfaces {}",
+                    termPoint + GridConstant.NAME_PARAMETERS_SEPARATOR + String.join(
+                            " or " + termPoint + GridConstant.NAME_PARAMETERS_SEPARATOR,
+                            suffixListMap.get("ODU")),
+                    e);
+        }
+        return inf2Del;
+    }
 
 
     @Override
@@ -605,7 +632,7 @@ public class DeviceRendererServiceImpl implements DeviceRendererService {
         }
         if (services.isPresent()) {
             LOG.info("service {} already exists", name);
-            servicesBuilder = new ServicesBuilder(services.get()).setTopology(topo);
+            servicesBuilder = new ServicesBuilder(services.orElseThrow()).setTopology(topo);
             WriteTransaction writeTx = this.dataBroker.newWriteOnlyTransaction();
             writeTx.merge(LogicalDatastoreType.OPERATIONAL, iid, servicesBuilder.build());
             writeTx.commit().get(Timeouts.DATASTORE_WRITE, TimeUnit.MILLISECONDS);
@@ -614,7 +641,7 @@ public class DeviceRendererServiceImpl implements DeviceRendererService {
         }
     }
 
-    @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
+    @SuppressFBWarnings(
         value = "SLF4J_FORMAT_SHOULD_BE_CONST",
         justification = "Log messages content needs to be formatted before"
             + "since they are used in the returned object")