Move ControllerToNodeId Function to api bundle
Change-Id: I80eac83cc72f9a92b594fef46d83376b42843746
Showing
3 changed files
with
49 additions
and
5 deletions
1 | -package org.onlab.onos.store.common.impl; | 1 | +package org.onlab.onos.cluster; |
2 | - | ||
3 | -import org.onlab.onos.cluster.ControllerNode; | ||
4 | -import org.onlab.onos.cluster.NodeId; | ||
5 | 2 | ||
6 | import com.google.common.base.Function; | 3 | import com.google.common.base.Function; |
7 | 4 | ||
... | @@ -18,6 +15,11 @@ public final class ControllerNodeToNodeId | ... | @@ -18,6 +15,11 @@ public final class ControllerNodeToNodeId |
18 | return input.id(); | 15 | return input.id(); |
19 | } | 16 | } |
20 | 17 | ||
18 | + /** | ||
19 | + * Returns a Function to convert ControllerNode to NodeId. | ||
20 | + * | ||
21 | + * @return ControllerNodeToNodeId instance. | ||
22 | + */ | ||
21 | public static ControllerNodeToNodeId toNodeId() { | 23 | public static ControllerNodeToNodeId toNodeId() { |
22 | return INSTANCE; | 24 | return INSTANCE; |
23 | } | 25 | } | ... | ... |
1 | +package org.onlab.onos.cluster; | ||
2 | + | ||
3 | +import static org.junit.Assert.*; | ||
4 | +import static org.onlab.onos.cluster.ControllerNodeToNodeId.toNodeId; | ||
5 | + | ||
6 | +import java.util.Arrays; | ||
7 | +import java.util.List; | ||
8 | + | ||
9 | +import org.junit.Test; | ||
10 | +import org.onlab.packet.IpPrefix; | ||
11 | + | ||
12 | +import com.google.common.collect.FluentIterable; | ||
13 | + | ||
14 | + | ||
15 | +public class ControllerNodeToNodeIdTest { | ||
16 | + | ||
17 | + private static final NodeId NID1 = new NodeId("foo"); | ||
18 | + private static final NodeId NID2 = new NodeId("bar"); | ||
19 | + private static final NodeId NID3 = new NodeId("buz"); | ||
20 | + | ||
21 | + private static final IpPrefix IP1 = IpPrefix.valueOf("127.0.0.1"); | ||
22 | + private static final IpPrefix IP2 = IpPrefix.valueOf("127.0.0.2"); | ||
23 | + private static final IpPrefix IP3 = IpPrefix.valueOf("127.0.0.3"); | ||
24 | + | ||
25 | + private static final ControllerNode CN1 = new DefaultControllerNode(NID1, IP1); | ||
26 | + private static final ControllerNode CN2 = new DefaultControllerNode(NID2, IP2); | ||
27 | + private static final ControllerNode CN3 = new DefaultControllerNode(NID3, IP3); | ||
28 | + | ||
29 | + | ||
30 | + @Test | ||
31 | + public final void testToNodeId() { | ||
32 | + | ||
33 | + final Iterable<ControllerNode> nodes = Arrays.asList(CN1, CN2, CN3); | ||
34 | + final List<NodeId> nodeIds = Arrays.asList(NID1, NID2, NID3); | ||
35 | + | ||
36 | + assertEquals(nodeIds, | ||
37 | + FluentIterable.from(nodes) | ||
38 | + .transform(toNodeId()) | ||
39 | + .toList()); | ||
40 | + } | ||
41 | + | ||
42 | +} |
... | @@ -65,6 +65,7 @@ import java.util.concurrent.TimeUnit; | ... | @@ -65,6 +65,7 @@ import java.util.concurrent.TimeUnit; |
65 | 65 | ||
66 | import static com.google.common.base.Preconditions.checkArgument; | 66 | import static com.google.common.base.Preconditions.checkArgument; |
67 | import static com.google.common.base.Predicates.notNull; | 67 | import static com.google.common.base.Predicates.notNull; |
68 | +import static org.onlab.onos.cluster.ControllerNodeToNodeId.toNodeId; | ||
68 | import static org.onlab.onos.net.device.DeviceEvent.Type.*; | 69 | import static org.onlab.onos.net.device.DeviceEvent.Type.*; |
69 | import static org.slf4j.LoggerFactory.getLogger; | 70 | import static org.slf4j.LoggerFactory.getLogger; |
70 | import static org.apache.commons.lang3.concurrent.ConcurrentUtils.createIfAbsentUnchecked; | 71 | import static org.apache.commons.lang3.concurrent.ConcurrentUtils.createIfAbsentUnchecked; |
... | @@ -73,7 +74,6 @@ import static com.google.common.base.Verify.verify; | ... | @@ -73,7 +74,6 @@ import static com.google.common.base.Verify.verify; |
73 | import static org.onlab.util.Tools.namedThreads; | 74 | import static org.onlab.util.Tools.namedThreads; |
74 | import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor; | 75 | import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor; |
75 | import static org.onlab.onos.store.device.impl.GossipDeviceStoreMessageSubjects.DEVICE_ADVERTISE; | 76 | import static org.onlab.onos.store.device.impl.GossipDeviceStoreMessageSubjects.DEVICE_ADVERTISE; |
76 | -import static org.onlab.onos.store.common.impl.ControllerNodeToNodeId.toNodeId; | ||
77 | 77 | ||
78 | // TODO: give me a better name | 78 | // TODO: give me a better name |
79 | /** | 79 | /** | ... | ... |
-
Please register or login to post a comment