From 63c0e53ca23ac9f0b1e19dd134af79b6e63bf05c Mon Sep 17 00:00:00 2001 From: "miroslav.kovac" Date: Thu, 10 Mar 2016 15:30:10 +0100 Subject: [PATCH] builder class for path creating Paths can be created with new path creator class instead of using constant strings. Change-Id: Icae8b65fc43f2a12f044f075279fd3ccb009074e Signed-off-by: miroslav.kovac --- .../topology/util/BaseTopologyManager.java | 11 +++-- .../impl/NetconfNodeManagerCallback.java | 6 ++- .../ClusteredDeviceSourcesResolverImpl.java | 4 +- .../pipeline/ClusteredNetconfDevice.java | 6 +-- .../pipeline/MasterSourceProviderImpl.java | 4 +- .../pipeline/TopologyMountPointFacade.java | 8 +++- .../util/NetconfTopologyPathCreator.java | 42 +++++++++++++++++++ 7 files changed, 68 insertions(+), 13 deletions(-) create mode 100644 netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/NetconfTopologyPathCreator.java diff --git a/netconf/abstract-topology/src/main/java/org/opendaylight/netconf/topology/util/BaseTopologyManager.java b/netconf/abstract-topology/src/main/java/org/opendaylight/netconf/topology/util/BaseTopologyManager.java index 75eb91e1c0..133aa46cf3 100644 --- a/netconf/abstract-topology/src/main/java/org/opendaylight/netconf/topology/util/BaseTopologyManager.java +++ b/netconf/abstract-topology/src/main/java/org/opendaylight/netconf/topology/util/BaseTopologyManager.java @@ -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(); diff --git a/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/impl/NetconfNodeManagerCallback.java b/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/impl/NetconfNodeManagerCallback.java index c4eaae9ad7..89e1dfa15b 100644 --- a/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/impl/NetconfNodeManagerCallback.java +++ b/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/impl/NetconfNodeManagerCallback.java @@ -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 topologyRefFuture = actorSystem.actorSelection("/user/" + topologyId).resolveOne(FiniteDuration.create(10L, TimeUnit.SECONDS)); + final NetconfTopologyPathCreator pathCreator = new NetconfTopologyPathCreator(topologyId); + final Future topologyRefFuture = actorSystem.actorSelection(pathCreator.build()).resolveOne(FiniteDuration.create(10L, TimeUnit.SECONDS)); topologyRefFuture.onComplete(new OnComplete() { @Override public void onComplete(Throwable throwable, ActorRef actorRef) throws Throwable { @@ -140,7 +142,7 @@ public class NetconfNodeManagerCallback implements NodeManagerCallback, NetconfC } }, actorSystem.dispatcher()); - final Future nodeRefFuture = actorSystem.actorSelection("/user/" + topologyId + "/" + nodeId).resolveOne(FiniteDuration.create(10L, TimeUnit.SECONDS)); + final Future nodeRefFuture = actorSystem.actorSelection(pathCreator.withSuffix(nodeId).build()).resolveOne(FiniteDuration.create(10L, TimeUnit.SECONDS)); nodeRefFuture.onComplete(new OnComplete() { @Override public void onComplete(Throwable throwable, ActorRef actorRef) throws Throwable { diff --git a/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/pipeline/ClusteredDeviceSourcesResolverImpl.java b/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/pipeline/ClusteredDeviceSourcesResolverImpl.java index 3a74e40b01..8ea8d3d0c3 100644 --- a/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/pipeline/ClusteredDeviceSourcesResolverImpl.java +++ b/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/pipeline/ClusteredDeviceSourcesResolverImpl.java @@ -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()); } } diff --git a/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/pipeline/ClusteredNetconfDevice.java b/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/pipeline/ClusteredNetconfDevice.java index 3a838ace21..058204b9f5 100644 --- a/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/pipeline/ClusteredNetconfDevice.java +++ b/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/pipeline/ClusteredNetconfDevice.java @@ -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 schemaContextFuture = new FutureCallback() { @Override diff --git a/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/pipeline/MasterSourceProviderImpl.java b/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/pipeline/MasterSourceProviderImpl.java index 42375dc613..618de81ea6 100644 --- a/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/pipeline/MasterSourceProviderImpl.java +++ b/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/pipeline/MasterSourceProviderImpl.java @@ -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()); diff --git a/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/pipeline/TopologyMountPointFacade.java b/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/pipeline/TopologyMountPointFacade.java index 269db6907b..271910d430 100644 --- a/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/pipeline/TopologyMountPointFacade.java +++ b/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/pipeline/TopologyMountPointFacade.java @@ -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; @@ -134,7 +135,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); } } @@ -166,7 +168,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 index 0000000000..1a16eca924 --- /dev/null +++ b/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/NetconfTopologyPathCreator.java @@ -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; + } + +} -- 2.36.6