Reduce number of parameters for pcep 78/67278/2
authorClaudio D. Gasparini <claudio.gasparini@pantheon.tech>
Thu, 18 Jan 2018 10:49:15 +0000 (11:49 +0100)
committerClaudio D. Gasparini <claudio.gasparini@pantheon.tech>
Mon, 22 Jan 2018 11:48:15 +0000 (12:48 +0100)
-improve logs

Change-Id: Ibdf63a2b7d7894600a466a07086d7b9d4d9b5cc4
Signed-off-by: Claudio D. Gasparini <claudio.gasparini@pantheon.tech>
pcep/topology/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/config/PCEPTopologyConfiguration.java
pcep/topology/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/config/PCEPTopologyDeployerImpl.java
pcep/topology/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/config/PCEPTopologyProviderUtil.java
pcep/topology/topology-provider/src/test/java/org/opendaylight/bgpcep/pcep/topology/provider/AbstractPCEPSessionTest.java

index 197fa0e5e87a95240f04214a110c43a55a4bb782..0554116f5850aaec70d678cacb9a612438348e78 100644 (file)
@@ -13,6 +13,7 @@ import java.net.InetSocketAddress;
 import javax.annotation.Nonnull;
 import org.opendaylight.protocol.concepts.KeyMapping;
 import org.opendaylight.protocol.pcep.SpeakerIdMapping;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.config.rev171025.pcep.config.SessionConfig;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
@@ -27,17 +28,14 @@ public final class PCEPTopologyConfiguration {
     private final SpeakerIdMapping speakerIds;
     private final InstanceIdentifier<Topology> topology;
 
-    public PCEPTopologyConfiguration(
-            @Nonnull final InetSocketAddress address,
-            @Nonnull final KeyMapping keys,
-            @Nonnull final SpeakerIdMapping speakerIds,
-            @Nonnull final TopologyId topologyId,
-            final short rpcTimeout) {
-        this.address = checkNotNull(address);
-        this.keys = checkNotNull(keys);
-        this.speakerIds = checkNotNull(speakerIds);
-        this.topologyId = checkNotNull(topologyId);
-        this.rpcTimeout = rpcTimeout;
+    public PCEPTopologyConfiguration(@Nonnull final SessionConfig config, @Nonnull final Topology topology) {
+        checkNotNull(topology);
+        this.address = PCEPTopologyProviderUtil
+                .getInetSocketAddress(checkNotNull(config.getListenAddress()), checkNotNull(config.getListenPort()));
+        this.keys = checkNotNull(PCEPTopologyProviderUtil.contructKeys(topology));
+        this.speakerIds = checkNotNull(PCEPTopologyProviderUtil.contructSpeakersId(topology));
+        this.topologyId = checkNotNull(topology.getTopologyId());
+        this.rpcTimeout = config.getRpcTimeout();
         this.topology = InstanceIdentifier.builder(NetworkTopology.class)
                 .child(Topology.class, new TopologyKey(this.topologyId)).build();
     }
index 7f695c53a80d0d212c2685e5663d79c1f639df9e..59967e70e8a26fb5d24bd77c645049291be3fa9d 100644 (file)
@@ -12,7 +12,6 @@ import static org.opendaylight.bgpcep.pcep.topology.provider.config.PCEPTopology
 import static org.opendaylight.bgpcep.pcep.topology.provider.config.PCEPTopologyProviderUtil.filterPcepTopologies;
 import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.CONFIGURATION;
 
-import java.net.InetSocketAddress;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
@@ -26,8 +25,6 @@ import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
 import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
-import org.opendaylight.protocol.concepts.KeyMapping;
-import org.opendaylight.protocol.pcep.SpeakerIdMapping;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.config.rev171025.pcep.config.SessionConfig;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.config.rev171025.PcepTopologyTypeConfig;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
@@ -91,6 +88,7 @@ public class PCEPTopologyDeployerImpl implements ClusteredDataTreeChangeListener
             return;
         }
         final TopologyId topologyId = topology.getTopologyId();
+        LOG.info("Updating Topology {}", topologyId);
         final PCEPTopologyProviderBean previous = this.pcepTopologyServices.remove(topology.getTopologyId());
         closeTopology(previous, topologyId);
         createTopologyProvider(topology);
@@ -105,22 +103,14 @@ public class PCEPTopologyDeployerImpl implements ClusteredDataTreeChangeListener
             LOG.warn("Topology Provider {} already exist. New instance won't be created", topologyId);
             return;
         }
+        LOG.info("Creating Topology {}", topologyId);
+        LOG.trace("Topology {}.", topology);
 
-        final PcepTopologyTypeConfig pcepTopo = topology.getAugmentation(PcepTopologyTypeConfig.class);
-
-        final SessionConfig config = pcepTopo.getSessionConfig();
-
+        final SessionConfig config = topology.getAugmentation(PcepTopologyTypeConfig.class).getSessionConfig();
         final InstructionScheduler instructionScheduler = this.instructionSchedulerFactory
-            .createInstructionScheduler(topologyId.getValue());
-
-        final InetSocketAddress inetAddress = PCEPTopologyProviderUtil
-                .getInetSocketAddress(config.getListenAddress(), config.getListenPort());
+                .createInstructionScheduler(topologyId.getValue());
 
-        final KeyMapping keys = PCEPTopologyProviderUtil.contructKeys(topology);
-        final SpeakerIdMapping speakerIds = PCEPTopologyProviderUtil.contructSpeakersId(topology);
-        final PCEPTopologyConfiguration dependencies = new PCEPTopologyConfiguration(
-                inetAddress, keys, speakerIds, topology.getTopologyId(),
-                config.getRpcTimeout());
+        final PCEPTopologyConfiguration dependencies = new PCEPTopologyConfiguration(config, topology);
 
         final PCEPTopologyProviderBean pcepTopologyProviderBean = (PCEPTopologyProviderBean) this.container
                 .getComponentInstance(PCEPTopologyProviderBean.class.getSimpleName());
@@ -128,13 +118,12 @@ public class PCEPTopologyDeployerImpl implements ClusteredDataTreeChangeListener
         pcepTopologyProviderBean.start(dependencies, instructionScheduler);
     }
 
-    private synchronized void removeTopologyProvider(final Topology topo) {
-        if (!filterPcepTopologies(topo.getTopologyTypes())) {
+    private synchronized void removeTopologyProvider(final Topology topology) {
+        if (!filterPcepTopologies(topology.getTopologyTypes())) {
             return;
         }
-        final TopologyId topologyId = topo.getTopologyId();
-        final PCEPTopologyProviderBean topology = this.pcepTopologyServices.remove(topologyId);
-        closeTopology(topology, topologyId);
+        final TopologyId topologyId = topology.getTopologyId();
+        closeTopology(this.pcepTopologyServices.remove(topologyId), topologyId);
     }
 
     @Override
index c0121b6ed58e0a6bf5538e431eb51e2bb40b5055..b3198f253c4e38d97ce9e0b21be3ee433344125b 100644 (file)
@@ -75,13 +75,15 @@ final class PCEPTopologyProviderUtil {
 
     @SuppressWarnings("checkstyle:IllegalCatch")
     static void closeTopology(@Nullable final PCEPTopologyProviderBean topology, @Nonnull final TopologyId topologyId) {
-        if (topology != null) {
-            try {
-                topology.closeServiceInstance().get(TIMEOUT_NS, TimeUnit.NANOSECONDS);
-                topology.close();
-            } catch (final Exception e) {
-                LOG.error("Topology {} instance failed to close service instance", topologyId, e);
-            }
+        if (topology == null) {
+            return;
+        }
+        LOG.info("Removing Topology {}", topologyId);
+        try {
+            topology.closeServiceInstance().get(TIMEOUT_NS, TimeUnit.NANOSECONDS);
+            topology.close();
+        } catch (final Exception e) {
+            LOG.error("Topology {} instance failed to close service instance", topologyId, e);
         }
     }
 
index 522f07d3b0e1bb200f53488e040c564a30924855..c666d195048c325ce6581997b3388699032be10d 100644 (file)
@@ -26,6 +26,7 @@ import io.netty.util.concurrent.Promise;
 import java.lang.reflect.ParameterizedType;
 import java.net.InetSocketAddress;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import java.util.concurrent.TimeUnit;
 import org.junit.After;
@@ -36,16 +37,17 @@ import org.mockito.MockitoAnnotations;
 import org.opendaylight.bgpcep.pcep.topology.provider.config.PCEPTopologyConfiguration;
 import org.opendaylight.bgpcep.pcep.topology.provider.config.PCEPTopologyProviderDependencies;
 import org.opendaylight.bgpcep.pcep.topology.spi.stats.TopologySessionStatsRegistry;
-import org.opendaylight.bgpcep.programming.spi.InstructionScheduler;
 import org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest;
-import org.opendaylight.protocol.concepts.KeyMapping;
 import org.opendaylight.protocol.pcep.PCEPSessionListener;
-import org.opendaylight.protocol.pcep.SpeakerIdMapping;
 import org.opendaylight.protocol.pcep.impl.DefaultPCEPSessionNegotiator;
 import org.opendaylight.protocol.pcep.impl.PCEPSessionImpl;
 import org.opendaylight.protocol.util.InetSocketAddressUtil;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.config.rev171025.pcep.config.SessionConfig;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.Ero;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.EroBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.Subobject;
@@ -105,7 +107,9 @@ public abstract class AbstractPCEPSessionTest<T extends TopologySessionListenerF
     @Mock
     private PCEPTopologyProviderDependencies topologyDependencies;
     @Mock
-    private InstructionScheduler scheduler;
+    private SessionConfig sessionConfig;
+    @Mock
+    private Topology topology;
     @Mock
     private Promise<PCEPSessionImpl> promise;
     private DefaultPCEPSessionNegotiator neg;
@@ -142,9 +146,13 @@ public abstract class AbstractPCEPSessionTest<T extends TopologySessionListenerF
 
         @SuppressWarnings("unchecked") final T listenerFactory = (T) ((Class) ((ParameterizedType) this.getClass()
                 .getGenericSuperclass()).getActualTypeArguments()[0]).newInstance();
+        doReturn(new IpAddress(new Ipv4Address(this.testAddress))).when(this.sessionConfig).getListenAddress();
+        doReturn(new PortNumber(4189)).when(this.sessionConfig).getListenPort();
+        doReturn(RPC_TIMEOUT).when(this.sessionConfig).getRpcTimeout();
+        doReturn(TEST_TOPOLOGY_ID).when(this.topology).getTopologyId();
+        doReturn(Collections.emptyList()).when(this.topology).getNode();
 
-        final PCEPTopologyConfiguration configDep = new PCEPTopologyConfiguration(ra, KeyMapping.getKeyMapping(),
-                SpeakerIdMapping.getSpeakerIdMap(), TEST_TOPOLOGY_ID, RPC_TIMEOUT);
+        final PCEPTopologyConfiguration configDep = new PCEPTopologyConfiguration(this.sessionConfig, this.topology);
         this.manager = new ServerSessionManager(this.topologyDependencies, listenerFactory, configDep);
         startSessionManager();
         this.neg = new DefaultPCEPSessionNegotiator(this.promise, this.clientListener,