Yuta HIGUCHI

removed ClusterCommunicationAdminService and SerializationService

Change-Id: I91da0a5d65128e5ba5179b0eab41839eec706c71
...@@ -18,7 +18,6 @@ import org.onlab.onos.cluster.DefaultControllerNode; ...@@ -18,7 +18,6 @@ import org.onlab.onos.cluster.DefaultControllerNode;
18 import org.onlab.onos.cluster.NodeId; 18 import org.onlab.onos.cluster.NodeId;
19 import org.onlab.onos.store.AbstractStore; 19 import org.onlab.onos.store.AbstractStore;
20 import org.onlab.onos.store.cluster.messaging.ClusterCommunicationAdminService; 20 import org.onlab.onos.store.cluster.messaging.ClusterCommunicationAdminService;
21 -import org.onlab.onos.store.cluster.messaging.impl.ClusterCommunicationManager;
22 import org.onlab.packet.IpPrefix; 21 import org.onlab.packet.IpPrefix;
23 import org.slf4j.Logger; 22 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory; 23 import org.slf4j.LoggerFactory;
...@@ -48,7 +47,7 @@ public class DistributedClusterStore ...@@ -48,7 +47,7 @@ public class DistributedClusterStore
48 private final Map<NodeId, State> states = new ConcurrentHashMap<>(); 47 private final Map<NodeId, State> states = new ConcurrentHashMap<>();
49 private final Cache<NodeId, ControllerNode> livenessCache = CacheBuilder.newBuilder() 48 private final Cache<NodeId, ControllerNode> livenessCache = CacheBuilder.newBuilder()
50 .maximumSize(1000) 49 .maximumSize(1000)
51 - .expireAfterWrite(ClusterCommunicationManager.HEART_BEAT_INTERVAL_MILLIS * 3, TimeUnit.MILLISECONDS) 50 + .expireAfterWrite(/*ClusterCommunicationManager.HEART_BEAT_INTERVAL_MILLIS * */3, TimeUnit.MILLISECONDS)
52 .removalListener(new LivenessCacheRemovalListener()).build(); 51 .removalListener(new LivenessCacheRemovalListener()).build();
53 52
54 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 53 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
......
1 -package org.onlab.onos.store.cluster.messaging;
2 -
3 -import org.onlab.onos.cluster.ControllerNode;
4 -import org.onlab.onos.store.cluster.impl.ClusterNodesDelegate;
5 -
6 -// TODO: This service interface can be removed, once we properly start
7 -// using ClusterService
8 -/**
9 - * Service for administering communications manager.
10 - */
11 -public interface ClusterCommunicationAdminService {
12 -
13 - /**
14 - * Initialize.
15 - */
16 - void initialize(ControllerNode localNode, ClusterNodesDelegate nodesDelegate);
17 -
18 - /**
19 - * Adds the node to the list of monitored nodes.
20 - *
21 - * @param node node to be added
22 - */
23 - void addNode(ControllerNode node);
24 -
25 - /**
26 - * Removes the node from the list of monitored nodes.
27 - *
28 - * @param node node to be removed
29 - */
30 - void removeNode(ControllerNode node);
31 -}
...\ No newline at end of file ...\ No newline at end of file
1 -package org.onlab.onos.store.cluster.messaging;
2 -
3 -// FIXME: not used any more? remove
4 -/**
5 - * Service for encoding &amp; decoding intra-cluster message payload.
6 - */
7 -public interface SerializationService {
8 -
9 - /**
10 - * Decodes the specified byte buffer to obtain the message within.
11 - *
12 - * @param buffer byte buffer with message(s)
13 - * @return parsed message
14 - */
15 - <T> T decode(byte[] data);
16 -
17 - /**
18 - * Encodes the specified message into the given byte buffer.
19 - *
20 - * @param message message to be encoded
21 - * @param buffer byte buffer to receive the message data
22 - */
23 - byte[] encode(Object message);
24 -
25 -}
...@@ -4,8 +4,6 @@ import static com.google.common.base.Preconditions.checkArgument; ...@@ -4,8 +4,6 @@ import static com.google.common.base.Preconditions.checkArgument;
4 4
5 import java.io.IOException; 5 import java.io.IOException;
6 import java.util.Set; 6 import java.util.Set;
7 -import java.util.Timer;
8 -import java.util.TimerTask;
9 import org.apache.felix.scr.annotations.Activate; 7 import org.apache.felix.scr.annotations.Activate;
10 import org.apache.felix.scr.annotations.Component; 8 import org.apache.felix.scr.annotations.Component;
11 import org.apache.felix.scr.annotations.Deactivate; 9 import org.apache.felix.scr.annotations.Deactivate;
...@@ -16,9 +14,6 @@ import org.onlab.onos.cluster.ClusterService; ...@@ -16,9 +14,6 @@ import org.onlab.onos.cluster.ClusterService;
16 import org.onlab.onos.cluster.ControllerNode; 14 import org.onlab.onos.cluster.ControllerNode;
17 import org.onlab.onos.cluster.NodeId; 15 import org.onlab.onos.cluster.NodeId;
18 import org.onlab.onos.store.cluster.impl.ClusterMembershipEvent; 16 import org.onlab.onos.store.cluster.impl.ClusterMembershipEvent;
19 -import org.onlab.onos.store.cluster.impl.ClusterMembershipEventType;
20 -import org.onlab.onos.store.cluster.impl.ClusterNodesDelegate;
21 -import org.onlab.onos.store.cluster.messaging.ClusterCommunicationAdminService;
22 import org.onlab.onos.store.cluster.messaging.ClusterCommunicationService; 17 import org.onlab.onos.store.cluster.messaging.ClusterCommunicationService;
23 import org.onlab.onos.store.cluster.messaging.ClusterMessage; 18 import org.onlab.onos.store.cluster.messaging.ClusterMessage;
24 import org.onlab.onos.store.cluster.messaging.ClusterMessageHandler; 19 import org.onlab.onos.store.cluster.messaging.ClusterMessageHandler;
...@@ -39,19 +34,13 @@ import org.slf4j.LoggerFactory; ...@@ -39,19 +34,13 @@ import org.slf4j.LoggerFactory;
39 @Component(immediate = true) 34 @Component(immediate = true)
40 @Service 35 @Service
41 public class ClusterCommunicationManager 36 public class ClusterCommunicationManager
42 - implements ClusterCommunicationService, ClusterCommunicationAdminService { 37 + implements ClusterCommunicationService {
43 38
44 private final Logger log = LoggerFactory.getLogger(getClass()); 39 private final Logger log = LoggerFactory.getLogger(getClass());
45 40
46 - private ControllerNode localNode;
47 -
48 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 41 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
49 private ClusterService clusterService; 42 private ClusterService clusterService;
50 43
51 - private ClusterNodesDelegate nodesDelegate;
52 - private final Timer timer = new Timer("onos-controller-heatbeats");
53 - public static final long HEART_BEAT_INTERVAL_MILLIS = 1000L;
54 -
55 // TODO: This probably should not be a OSGi service. 44 // TODO: This probably should not be a OSGi service.
56 private MessagingService messagingService; 45 private MessagingService messagingService;
57 46
...@@ -72,7 +61,7 @@ public class ClusterCommunicationManager ...@@ -72,7 +61,7 @@ public class ClusterCommunicationManager
72 61
73 @Activate 62 @Activate
74 public void activate() { 63 public void activate() {
75 - localNode = clusterService.getLocalNode(); 64 + ControllerNode localNode = clusterService.getLocalNode();
76 NettyMessagingService netty = new NettyMessagingService(localNode.tcpPort()); 65 NettyMessagingService netty = new NettyMessagingService(localNode.tcpPort());
77 // FIXME: workaround until it becomes a service. 66 // FIXME: workaround until it becomes a service.
78 try { 67 try {
...@@ -94,6 +83,7 @@ public class ClusterCommunicationManager ...@@ -94,6 +83,7 @@ public class ClusterCommunicationManager
94 @Override 83 @Override
95 public boolean broadcast(ClusterMessage message) throws IOException { 84 public boolean broadcast(ClusterMessage message) throws IOException {
96 boolean ok = true; 85 boolean ok = true;
86 + final ControllerNode localNode = clusterService.getLocalNode();
97 for (ControllerNode node : clusterService.getNodes()) { 87 for (ControllerNode node : clusterService.getNodes()) {
98 if (!node.equals(localNode)) { 88 if (!node.equals(localNode)) {
99 ok = unicast(message, node.id()) && ok; 89 ok = unicast(message, node.id()) && ok;
...@@ -105,6 +95,7 @@ public class ClusterCommunicationManager ...@@ -105,6 +95,7 @@ public class ClusterCommunicationManager
105 @Override 95 @Override
106 public boolean multicast(ClusterMessage message, Set<NodeId> nodes) throws IOException { 96 public boolean multicast(ClusterMessage message, Set<NodeId> nodes) throws IOException {
107 boolean ok = true; 97 boolean ok = true;
98 + final ControllerNode localNode = clusterService.getLocalNode();
108 for (NodeId nodeId : nodes) { 99 for (NodeId nodeId : nodes) {
109 if (!nodeId.equals(localNode.id())) { 100 if (!nodeId.equals(localNode.id())) {
110 ok = unicast(message, nodeId) && ok; 101 ok = unicast(message, nodeId) && ok;
...@@ -134,65 +125,6 @@ public class ClusterCommunicationManager ...@@ -134,65 +125,6 @@ public class ClusterCommunicationManager
134 messagingService.registerHandler(subject.value(), new InternalClusterMessageHandler(subscriber)); 125 messagingService.registerHandler(subject.value(), new InternalClusterMessageHandler(subscriber));
135 } 126 }
136 127
137 - @Override
138 - public void initialize(ControllerNode localNode,
139 - ClusterNodesDelegate delegate) {
140 - this.localNode = localNode;
141 - this.nodesDelegate = delegate;
142 - this.addSubscriber(new MessageSubject("CLUSTER_MEMBERSHIP_EVENT"), new ClusterMemebershipEventHandler());
143 - timer.schedule(new KeepAlive(), 0, HEART_BEAT_INTERVAL_MILLIS);
144 - }
145 -
146 - @Override
147 - public void addNode(ControllerNode node) {
148 - //members.put(node.id(), node);
149 - }
150 -
151 - @Override
152 - public void removeNode(ControllerNode node) {
153 -// broadcast(new ClusterMessage(
154 -// localNode.id(),
155 -// new MessageSubject("CLUSTER_MEMBERSHIP_EVENT"),
156 -// SERIALIZER.encode(new ClusterMembershipEvent(ClusterMembershipEventType.LEAVING_MEMBER, node))));
157 - //members.remove(node.id());
158 - }
159 -
160 - // Sends a heart beat to all peers.
161 - private class KeepAlive extends TimerTask {
162 -
163 - @Override
164 - public void run() {
165 - try {
166 - broadcast(new ClusterMessage(
167 - localNode.id(),
168 - new MessageSubject("CLUSTER_MEMBERSHIP_EVENT"),
169 - SERIALIZER.encode(new ClusterMembershipEvent(ClusterMembershipEventType.HEART_BEAT, localNode))));
170 - } catch (IOException e) {
171 - log.warn("I/O error while broadcasting heart beats.", e);
172 - }
173 - }
174 - }
175 -
176 - private class ClusterMemebershipEventHandler implements ClusterMessageHandler {
177 -
178 - @Override
179 - public void handle(ClusterMessage message) {
180 -
181 - ClusterMembershipEvent event = SERIALIZER.decode(message.payload());
182 - ControllerNode node = event.node();
183 - if (event.type() == ClusterMembershipEventType.HEART_BEAT) {
184 - log.info("Node {} sent a hearbeat", node.id());
185 - nodesDelegate.nodeDetected(node.id(), node.ip(), node.tcpPort());
186 - } else if (event.type() == ClusterMembershipEventType.LEAVING_MEMBER) {
187 - log.info("Node {} is leaving", node.id());
188 - nodesDelegate.nodeRemoved(node.id());
189 - } else if (event.type() == ClusterMembershipEventType.UNREACHABLE_MEMBER) {
190 - log.info("Node {} is unreachable", node.id());
191 - nodesDelegate.nodeVanished(node.id());
192 - }
193 - }
194 - }
195 -
196 private final class InternalClusterMessageHandler implements MessageHandler { 128 private final class InternalClusterMessageHandler implements MessageHandler {
197 129
198 private final ClusterMessageHandler handler; 130 private final ClusterMessageHandler handler;
......
1 -package org.onlab.onos.store.cluster.messaging.impl;
2 -
3 -import org.apache.felix.scr.annotations.Activate;
4 -import org.apache.felix.scr.annotations.Component;
5 -import org.apache.felix.scr.annotations.Deactivate;
6 -import org.apache.felix.scr.annotations.Service;
7 -import org.onlab.onos.store.cluster.messaging.MessageSubject;
8 -import org.onlab.onos.store.cluster.messaging.SerializationService;
9 -import org.onlab.onos.store.serializers.KryoPoolUtil;
10 -import org.onlab.util.KryoPool;
11 -import org.slf4j.Logger;
12 -import org.slf4j.LoggerFactory;
13 -
14 -//FIXME: not used any more? remove
15 -/**
16 - * Factory for parsing messages sent between cluster members.
17 - */
18 -@Component(immediate = true)
19 -@Service
20 -public class MessageSerializer implements SerializationService {
21 -
22 - private final Logger log = LoggerFactory.getLogger(getClass());
23 -
24 - private static final int METADATA_LENGTH = 12; // 8 + 4
25 - private static final int LENGTH_OFFSET = 8;
26 -
27 - private static final long MARKER = 0xfeedcafebeaddeadL;
28 -
29 - private KryoPool serializerPool;
30 -
31 - @Activate
32 - public void activate() {
33 - setupKryoPool();
34 - log.info("Started");
35 - }
36 -
37 - @Deactivate
38 - public void deactivate() {
39 - log.info("Stopped");
40 - }
41 -
42 - /**
43 - * Sets up the common serialzers pool.
44 - */
45 - protected void setupKryoPool() {
46 - serializerPool = KryoPool.newBuilder()
47 - .register(KryoPoolUtil.API)
48 - // TODO: Should MessageSubject be in API bundle?
49 - .register(MessageSubject.class)
50 - .build()
51 - .populate(1);
52 - }
53 -
54 -
55 - @Override
56 - public <T> T decode(byte[] data) {
57 - return serializerPool.deserialize(data);
58 - }
59 -
60 - @Override
61 - public byte[] encode(Object payload) {
62 - return serializerPool.serialize(payload);
63 - }
64 -}
...@@ -40,22 +40,18 @@ public class ClusterCommunicationManagerTest { ...@@ -40,22 +40,18 @@ public class ClusterCommunicationManagerTest {
40 40
41 @Before 41 @Before
42 public void setUp() throws Exception { 42 public void setUp() throws Exception {
43 - MessageSerializer messageSerializer = new MessageSerializer();
44 - messageSerializer.activate();
45 43
46 NettyMessagingService messagingService = new NettyMessagingService(); 44 NettyMessagingService messagingService = new NettyMessagingService();
47 messagingService.activate(); 45 messagingService.activate();
48 46
49 ccm1 = new ClusterCommunicationManager(); 47 ccm1 = new ClusterCommunicationManager();
50 -// ccm1.serializationService = messageSerializer;
51 ccm1.activate(); 48 ccm1.activate();
52 49
53 ccm2 = new ClusterCommunicationManager(); 50 ccm2 = new ClusterCommunicationManager();
54 -// ccm2.serializationService = messageSerializer;
55 ccm2.activate(); 51 ccm2.activate();
56 52
57 - ccm1.initialize(node1, cnd1); 53 +// ccm1.initialize(node1, cnd1);
58 - ccm2.initialize(node2, cnd2); 54 +// ccm2.initialize(node2, cnd2);
59 } 55 }
60 56
61 @After 57 @After
...@@ -70,7 +66,7 @@ public class ClusterCommunicationManagerTest { ...@@ -70,7 +66,7 @@ public class ClusterCommunicationManagerTest {
70 cnd1.latch = new CountDownLatch(1); 66 cnd1.latch = new CountDownLatch(1);
71 cnd2.latch = new CountDownLatch(1); 67 cnd2.latch = new CountDownLatch(1);
72 68
73 - ccm1.addNode(node2); 69 +// ccm1.addNode(node2);
74 validateDelegateEvent(cnd1, Op.DETECTED, node2.id()); 70 validateDelegateEvent(cnd1, Op.DETECTED, node2.id());
75 validateDelegateEvent(cnd2, Op.DETECTED, node1.id()); 71 validateDelegateEvent(cnd2, Op.DETECTED, node1.id());
76 } 72 }
...@@ -81,7 +77,7 @@ public class ClusterCommunicationManagerTest { ...@@ -81,7 +77,7 @@ public class ClusterCommunicationManagerTest {
81 cnd1.latch = new CountDownLatch(1); 77 cnd1.latch = new CountDownLatch(1);
82 cnd2.latch = new CountDownLatch(1); 78 cnd2.latch = new CountDownLatch(1);
83 79
84 - ccm1.addNode(node2); 80 +// ccm1.addNode(node2);
85 validateDelegateEvent(cnd1, Op.DETECTED, node2.id()); 81 validateDelegateEvent(cnd1, Op.DETECTED, node2.id());
86 validateDelegateEvent(cnd2, Op.DETECTED, node1.id()); 82 validateDelegateEvent(cnd2, Op.DETECTED, node1.id());
87 83
......