Centralize NetconfNode/InetSocketAddress conversion
[netconf.git] / netconf / netconf-topology-singleton / src / main / java / org / opendaylight / netconf / topology / singleton / impl / utils / NetconfTopologyUtils.java
index 56884d35311f132f9c3b0d5ae21c0520f58b5534..eba7cde7c7a7b98b10c1c9333451acb283bf4a25 100644 (file)
@@ -7,12 +7,8 @@
  */
 package org.opendaylight.netconf.topology.singleton.impl.utils;
 
-import java.math.BigDecimal;
-import java.net.InetSocketAddress;
 import org.opendaylight.netconf.api.DocumentedException;
 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;
 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.NodeId;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
@@ -23,7 +19,10 @@ import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.
 import org.opendaylight.yangtools.yang.binding.Identifier;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
+import org.opendaylight.yangtools.yang.common.Decimal64;
 import org.opendaylight.yangtools.yang.common.ErrorSeverity;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
+import org.opendaylight.yangtools.yang.common.ErrorType;
 
 public final class NetconfTopologyUtils {
     public static final long DEFAULT_REQUEST_TIMEOUT_MILLIS = 60000L;
@@ -34,18 +33,10 @@ public final class NetconfTopologyUtils {
     public static final int DEFAULT_MAX_CONNECTION_ATTEMPTS = 0;
     public static final int DEFAULT_BETWEEN_ATTEMPTS_TIMEOUT_MILLIS = 2000;
     public static final long DEFAULT_CONNECTION_TIMEOUT_MILLIS = 20000L;
-    public static final BigDecimal DEFAULT_SLEEP_FACTOR = new BigDecimal(1.5);
+    public static final Decimal64 DEFAULT_SLEEP_FACTOR = Decimal64.valueOf("1.5");
 
     private NetconfTopologyUtils() {
-
-    }
-
-    public static RemoteDeviceId createRemoteDeviceId(final NodeId nodeId, final NetconfNode node) {
-        final IpAddress ipAddress = node.getHost().getIpAddress();
-        final InetSocketAddress address = new InetSocketAddress(ipAddress.getIpv4Address() != null
-                ? ipAddress.getIpv4Address().getValue() : ipAddress.getIpv6Address().getValue(),
-                node.getPort().getValue().toJava());
-        return new RemoteDeviceId(nodeId.getValue(), address);
+        // Hidden on purpose
     }
 
     public static String createActorPath(final String masterMember, final String name) {
@@ -53,7 +44,7 @@ public final class NetconfTopologyUtils {
     }
 
     public static String createMasterActorName(final String name, final String masterAddress) {
-        return masterAddress.replaceAll("//", "") + "_" + name;
+        return masterAddress.replace("//", "") + "_" + name;
     }
 
     public static NodeId getNodeId(final InstanceIdentifier.PathArgument pathArgument) {
@@ -71,7 +62,8 @@ public final class NetconfTopologyUtils {
         return networkTopology.child(Topology.class, new TopologyKey(new TopologyId(topologyId)));
     }
 
-    public static InstanceIdentifier<Node> createTopologyNodeListPath(final NodeKey key, final String topologyId) {
+    public static KeyedInstanceIdentifier<Node, NodeKey> createTopologyNodeListPath(final NodeKey key,
+            final String topologyId) {
         return createTopologyListPath(topologyId)
                 .child(Node.class, new NodeKey(new NodeId(key.getNodeId().getValue())));
     }
@@ -82,7 +74,6 @@ public final class NetconfTopologyUtils {
 
     public static DocumentedException createMasterIsDownException(final RemoteDeviceId id, final Exception cause) {
         return new DocumentedException(id + ":Master is down. Please try again.", cause,
-                DocumentedException.ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_FAILED,
-                ErrorSeverity.WARNING);
+                ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, ErrorSeverity.WARNING);
     }
 }