Move ControllerToNodeId Function to api bundle
Change-Id: I80eac83cc72f9a92b594fef46d83376b42843746
diff --git a/core/store/dist/src/main/java/org/onlab/onos/store/common/impl/ControllerNodeToNodeId.java b/core/api/src/main/java/org/onlab/onos/cluster/ControllerNodeToNodeId.java
similarity index 73%
rename from core/store/dist/src/main/java/org/onlab/onos/store/common/impl/ControllerNodeToNodeId.java
rename to core/api/src/main/java/org/onlab/onos/cluster/ControllerNodeToNodeId.java
index 73187ee..0891494 100644
--- a/core/store/dist/src/main/java/org/onlab/onos/store/common/impl/ControllerNodeToNodeId.java
+++ b/core/api/src/main/java/org/onlab/onos/cluster/ControllerNodeToNodeId.java
@@ -1,7 +1,4 @@
-package org.onlab.onos.store.common.impl;
-
-import org.onlab.onos.cluster.ControllerNode;
-import org.onlab.onos.cluster.NodeId;
+package org.onlab.onos.cluster;
import com.google.common.base.Function;
@@ -18,6 +15,11 @@
return input.id();
}
+ /**
+ * Returns a Function to convert ControllerNode to NodeId.
+ *
+ * @return ControllerNodeToNodeId instance.
+ */
public static ControllerNodeToNodeId toNodeId() {
return INSTANCE;
}
diff --git a/core/api/src/test/java/org/onlab/onos/cluster/ControllerNodeToNodeIdTest.java b/core/api/src/test/java/org/onlab/onos/cluster/ControllerNodeToNodeIdTest.java
new file mode 100644
index 0000000..44261e8
--- /dev/null
+++ b/core/api/src/test/java/org/onlab/onos/cluster/ControllerNodeToNodeIdTest.java
@@ -0,0 +1,42 @@
+package org.onlab.onos.cluster;
+
+import static org.junit.Assert.*;
+import static org.onlab.onos.cluster.ControllerNodeToNodeId.toNodeId;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.Test;
+import org.onlab.packet.IpPrefix;
+
+import com.google.common.collect.FluentIterable;
+
+
+public class ControllerNodeToNodeIdTest {
+
+ private static final NodeId NID1 = new NodeId("foo");
+ private static final NodeId NID2 = new NodeId("bar");
+ private static final NodeId NID3 = new NodeId("buz");
+
+ private static final IpPrefix IP1 = IpPrefix.valueOf("127.0.0.1");
+ private static final IpPrefix IP2 = IpPrefix.valueOf("127.0.0.2");
+ private static final IpPrefix IP3 = IpPrefix.valueOf("127.0.0.3");
+
+ private static final ControllerNode CN1 = new DefaultControllerNode(NID1, IP1);
+ private static final ControllerNode CN2 = new DefaultControllerNode(NID2, IP2);
+ private static final ControllerNode CN3 = new DefaultControllerNode(NID3, IP3);
+
+
+ @Test
+ public final void testToNodeId() {
+
+ final Iterable<ControllerNode> nodes = Arrays.asList(CN1, CN2, CN3);
+ final List<NodeId> nodeIds = Arrays.asList(NID1, NID2, NID3);
+
+ assertEquals(nodeIds,
+ FluentIterable.from(nodes)
+ .transform(toNodeId())
+ .toList());
+ }
+
+}
diff --git a/core/store/dist/src/main/java/org/onlab/onos/store/device/impl/GossipDeviceStore.java b/core/store/dist/src/main/java/org/onlab/onos/store/device/impl/GossipDeviceStore.java
index 782bc6c..6ab529a 100644
--- a/core/store/dist/src/main/java/org/onlab/onos/store/device/impl/GossipDeviceStore.java
+++ b/core/store/dist/src/main/java/org/onlab/onos/store/device/impl/GossipDeviceStore.java
@@ -65,6 +65,7 @@
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Predicates.notNull;
+import static org.onlab.onos.cluster.ControllerNodeToNodeId.toNodeId;
import static org.onlab.onos.net.device.DeviceEvent.Type.*;
import static org.slf4j.LoggerFactory.getLogger;
import static org.apache.commons.lang3.concurrent.ConcurrentUtils.createIfAbsentUnchecked;
@@ -73,7 +74,6 @@
import static org.onlab.util.Tools.namedThreads;
import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor;
import static org.onlab.onos.store.device.impl.GossipDeviceStoreMessageSubjects.DEVICE_ADVERTISE;
-import static org.onlab.onos.store.common.impl.ControllerNodeToNodeId.toNodeId;
// TODO: give me a better name
/**