Merge "builder class for path creating"
authorTomas Cere <tcere@cisco.com>
Fri, 22 Apr 2016 10:19:33 +0000 (10:19 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Fri, 22 Apr 2016 10:19:33 +0000 (10:19 +0000)
netconf/abstract-topology/src/main/java/org/opendaylight/netconf/topology/util/BaseTopologyManager.java
netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/impl/NetconfNodeManagerCallback.java
netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/pipeline/ClusteredDeviceSourcesResolverImpl.java
netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/pipeline/ClusteredNetconfDevice.java
netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/pipeline/MasterSourceProviderImpl.java
netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/pipeline/TopologyMountPointFacade.java
netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/NetconfTopologyPathCreator.java [new file with mode: 0644]

index 75eb91e1c0cc3e3c4f7f6ece4dffcc22c236d352..133aa46cf3c07f12edf1fd3f22a8a3cf71049b3f 100644 (file)
@@ -54,6 +54,7 @@ import org.opendaylight.netconf.topology.TopologyManagerCallback.TopologyManager
 import org.opendaylight.netconf.topology.util.messages.CustomIdentifyMessage;
 import org.opendaylight.netconf.topology.util.messages.CustomIdentifyMessageReply;
 import org.opendaylight.netconf.topology.util.messages.NormalizedNodeMessage;
+import org.opendaylight.netconf.util.NetconfTopologyPathCreator;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
@@ -507,7 +508,8 @@ public final class BaseTopologyManager
                 return;
             }
 
-            final String path = member.address() + PATH + topologyId;
+            final NetconfTopologyPathCreator pathCreator = new NetconfTopologyPathCreator(member.address().toString(), topologyId);
+            final String path = pathCreator.build();
             LOG.debug("Actor at :{} is resolving topology actor for path {}", clusterExtension.selfAddress(), path);
 
             // first send basic identify message in case our messages have not been loaded through osgi yet to prevent crashing akka.
@@ -535,14 +537,15 @@ public final class BaseTopologyManager
             if (member.address().equals(clusterExtension.selfAddress())) {
                 return;
             }
-
-            final String path = member.address() + PATH + topologyId;
+            final NetconfTopologyPathCreator pathCreator = new NetconfTopologyPathCreator(member.address().toString(), topologyId);
+            final String path = pathCreator.build();
             LOG.debug("Actor at :{} is resolving topology actor for path {}", clusterExtension.selfAddress(), path);
 
             clusterExtension.system().actorSelection(path).tell(new Identify(member.address()), TypedActor.context().self());
         } else if (message instanceof ActorIdentity) {
             LOG.debug("Received ActorIdentity message", message);
-            final String path = ((ActorIdentity) message).correlationId() + PATH + topologyId;
+            final NetconfTopologyPathCreator pathCreator = new NetconfTopologyPathCreator(((ActorIdentity) message).correlationId().toString(), topologyId);
+            final String path = pathCreator.build();
             if (((ActorIdentity) message).getRef() == null) {
                 LOG.debug("ActorIdentity has null actor ref, retrying..", message);
                 final ActorRef self = TypedActor.context().self();
index c4eaae9ad77c3e8c67ee66c7f3378b263052e172..89e1dfa15b3349b192a4e4fa1c66adb9948ee288 100644 (file)
@@ -47,6 +47,7 @@ import org.opendaylight.netconf.topology.util.BaseNodeManager;
 import org.opendaylight.netconf.topology.util.BaseTopologyManager;
 import org.opendaylight.netconf.topology.util.messages.AnnounceMasterMountPoint;
 import org.opendaylight.netconf.topology.util.messages.AnnounceMasterMountPointDown;
+import org.opendaylight.netconf.util.NetconfTopologyPathCreator;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeConnectionStatus.ConnectionStatus;
@@ -126,7 +127,8 @@ public class NetconfNodeManagerCallback implements NodeManagerCallback, NetconfC
         this.topologyDispatcher = (ClusteredNetconfTopology) topologyDispatcher;
         this.roleChangeStrategy = roleChangeStrategy;
 
-        final Future<ActorRef> topologyRefFuture = actorSystem.actorSelection("/user/" + topologyId).resolveOne(FiniteDuration.create(10L, TimeUnit.SECONDS));
+        final NetconfTopologyPathCreator pathCreator = new NetconfTopologyPathCreator(topologyId);
+        final Future<ActorRef> topologyRefFuture = actorSystem.actorSelection(pathCreator.build()).resolveOne(FiniteDuration.create(10L, TimeUnit.SECONDS));
         topologyRefFuture.onComplete(new OnComplete<ActorRef>() {
             @Override
             public void onComplete(Throwable throwable, ActorRef actorRef) throws Throwable {
@@ -140,7 +142,7 @@ public class NetconfNodeManagerCallback implements NodeManagerCallback, NetconfC
             }
         }, actorSystem.dispatcher());
 
-        final Future<ActorRef> nodeRefFuture = actorSystem.actorSelection("/user/" + topologyId + "/" + nodeId).resolveOne(FiniteDuration.create(10L, TimeUnit.SECONDS));
+        final Future<ActorRef> nodeRefFuture = actorSystem.actorSelection(pathCreator.withSuffix(nodeId).build()).resolveOne(FiniteDuration.create(10L, TimeUnit.SECONDS));
         nodeRefFuture.onComplete(new OnComplete<ActorRef>() {
             @Override
             public void onComplete(Throwable throwable, ActorRef actorRef) throws Throwable {
index 3a74e40b019a080bc88f4dc5d036474b55329b9c..8ea8d3d0c388b1b56ee8c55f0a5de12aab575269 100644 (file)
@@ -30,6 +30,7 @@ import org.opendaylight.controller.cluster.schema.provider.impl.RemoteSchemaProv
 import org.opendaylight.netconf.topology.pipeline.messages.AnnounceClusteredDeviceSourcesResolverUp;
 import org.opendaylight.netconf.topology.pipeline.messages.AnnounceMasterOnSameNodeUp;
 import org.opendaylight.netconf.topology.pipeline.messages.AnnounceMasterSourceProviderUp;
+import org.opendaylight.netconf.util.NetconfTopologyPathCreator;
 import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
@@ -71,7 +72,8 @@ public class ClusteredDeviceSourcesResolverImpl implements ClusteredDeviceSource
         Cluster cluster = Cluster.get(actorSystem);
         for(Member node : cluster.state().getMembers()) {
             if(!node.address().equals(cluster.selfAddress())) {
-                final String path = node.address() + "/user/" + topologyId + "/" + nodeId + "/masterSourceProvider";
+                final NetconfTopologyPathCreator pathCreator = new NetconfTopologyPathCreator(node.address().toString(), topologyId);
+                final String path = pathCreator.withSuffix(nodeId).withSuffix(NetconfTopologyPathCreator.MASTER_SOURCE_PROVIDER).build();
                 actorSystem.actorSelection(path).tell(new AnnounceClusteredDeviceSourcesResolverUp(), TypedActor.context().self());
             }
         }
index 3a838ace21ac154c13f2de85f550e60f8f23ea4e..058204b9f5d390677e8612105d8400dd5edc87b3 100644 (file)
@@ -33,6 +33,7 @@ import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPrefe
 import org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceRpc;
 import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.NetconfMessageTransformer;
 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
+import org.opendaylight.netconf.util.NetconfTopologyPathCreator;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
 import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
@@ -97,7 +98,7 @@ public class ClusteredNetconfDevice extends NetconfDevice implements EntityOwner
                             public MasterSourceProviderImpl create() throws Exception {
                                 return new MasterSourceProviderImpl(schemaRepo, sourceIds, actorSystem, topologyId, nodeId);
                             }
-                        }), "masterSourceProvider");
+                        }), NetconfTopologyPathCreator.MASTER_SOURCE_PROVIDER);
     }
 
     @Override
@@ -126,8 +127,7 @@ public class ClusteredNetconfDevice extends NetconfDevice implements EntityOwner
                             public ClusteredDeviceSourcesResolverImpl create() throws Exception {
                                 return new ClusteredDeviceSourcesResolverImpl(topologyId, nodeId, actorSystem, schemaRegistry, sourceRegistrations);
                             }
-                        }), "clusteredDeviceSourcesResolver");
-
+                        }), NetconfTopologyPathCreator.CLUSTERED_DEVICE_SOURCES_RESOLVER);
 
         final FutureCallback<SchemaContext> schemaContextFuture = new FutureCallback<SchemaContext>() {
             @Override
index 42375dc61308b4264597fa9396c8a60666f22cd3..618de81ea661233e9903ce00806d4752018be389 100644 (file)
@@ -18,6 +18,7 @@ import org.opendaylight.controller.cluster.schema.provider.impl.RemoteYangTextSo
 import org.opendaylight.netconf.topology.pipeline.messages.AnnounceClusteredDeviceSourcesResolverUp;
 import org.opendaylight.netconf.topology.pipeline.messages.AnnounceMasterOnSameNodeUp;
 import org.opendaylight.netconf.topology.pipeline.messages.AnnounceMasterSourceProviderUp;
+import org.opendaylight.netconf.util.NetconfTopologyPathCreator;
 import org.opendaylight.yangtools.yang.model.repo.api.SchemaRepository;
 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
 import org.slf4j.Logger;
@@ -53,7 +54,8 @@ public class MasterSourceProviderImpl extends RemoteYangTextSourceProviderImpl
         cluster.join(cluster.selfAddress());
         LOG.debug("Notifying members master schema source provider is up.");
         for(Member node : cluster.state().getMembers()) {
-            final String path = node.address() + "/user/" + topologyId + "/" + nodeId + "/clusteredDeviceSourcesResolver";
+            final NetconfTopologyPathCreator pathCreator = new NetconfTopologyPathCreator(node.address().toString(),topologyId);
+            final String path = pathCreator.withSuffix(nodeId).withSuffix(NetconfTopologyPathCreator.CLUSTERED_DEVICE_SOURCES_RESOLVER).build();
             if(node.address().equals(cluster.selfAddress())) {
                 actorSystem.actorSelection(path).tell(new AnnounceMasterOnSameNodeUp(), TypedActor.context().self());
                 actorSystem.actorSelection(path).tell(PoisonPill.getInstance(), TypedActor.context().self());
index c79627be5a86ceb86d74dd5fb75e222b82c349f6..a44bf47a19a24cfff37d86e7937acd3ad7fa0bce 100644 (file)
@@ -29,6 +29,7 @@ import org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceNotificatio
 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
 import org.opendaylight.netconf.topology.util.messages.AnnounceMasterMountPoint;
 import org.opendaylight.netconf.topology.util.messages.AnnounceMasterMountPointDown;
+import org.opendaylight.netconf.util.NetconfTopologyPathCreator;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -131,7 +132,8 @@ public class TopologyMountPointFacade implements AutoCloseable, RemoteDeviceHand
         final ActorRef deviceDataBrokerRef = TypedActor.get(actorSystem).getActorRefFor(deviceDataBroker);
         for (final Member member : members) {
             if (!member.address().equals(cluster.selfAddress())) {
-                final String path = member.address() + "/user/" + topologyId + "/" + id.getName();
+                final NetconfTopologyPathCreator pathCreator = new NetconfTopologyPathCreator(member.address().toString(),topologyId);
+                final String path = pathCreator.withSuffix(id.getName()).build();
                 actorSystem.actorSelection(path).tell(new AnnounceMasterMountPoint(), deviceDataBrokerRef);
             }
         }
@@ -163,7 +165,9 @@ public class TopologyMountPointFacade implements AutoCloseable, RemoteDeviceHand
                 if (member.address().equals(Cluster.get(actorSystem).selfAddress())) {
                     continue;
                 }
-                actorSystem.actorSelection(member.address() + "/user/" + topologyId + "/" + id.getName()).tell(new AnnounceMasterMountPointDown(), null);
+                final NetconfTopologyPathCreator pathCreator = new NetconfTopologyPathCreator(member.address().toString(), topologyId);
+                final String path = pathCreator.withSuffix(id.getName()).build();
+                actorSystem.actorSelection(path).tell(new AnnounceMasterMountPointDown(), null);
             }
             TypedActor.get(actorSystem).stop(deviceDataBroker);
             deviceDataBroker = null;
diff --git a/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/NetconfTopologyPathCreator.java b/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/NetconfTopologyPathCreator.java
new file mode 100644 (file)
index 0000000..1a16eca
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.netconf.util;
+
+public class NetconfTopologyPathCreator {
+
+    public static final String CLUSTERED_DEVICE_SOURCES_RESOLVER = "clusteredDeviceSourcesResolver";
+    public static final String MASTER_SOURCE_PROVIDER
+            = "masterSourceProvider";
+
+    private static final String USER = "/user/";
+
+    private String mainPath;
+
+    public NetconfTopologyPathCreator(final String topologyId) {
+        mainPath = createMainPath("", topologyId);
+    }
+
+    public NetconfTopologyPathCreator(final String memberAddress, final String topologyId) {
+        mainPath = createMainPath(memberAddress, topologyId);
+    }
+
+    private String createMainPath(final String memberAddress, final String topologyId) {
+        return memberAddress + USER + topologyId;
+    }
+
+    public NetconfTopologyPathCreator withSuffix(final String suffix) {
+        mainPath += "/"+suffix;
+        return this;
+    }
+
+    public String build(){
+        return mainPath;
+    }
+
+}