Yuta HIGUCHI

moved Hazelcast based Mastership+Cluster store to onos-code-dist bundle

Change-Id: I304f916f3a400eaf050a5351825634349790e1bf
Showing 29 changed files with 27 additions and 309 deletions
...@@ -58,6 +58,10 @@ ...@@ -58,6 +58,10 @@
58 <classifier>tests</classifier> 58 <classifier>tests</classifier>
59 <scope>test</scope> 59 <scope>test</scope>
60 </dependency> 60 </dependency>
61 + <dependency>
62 + <groupId>com.hazelcast</groupId>
63 + <artifactId>hazelcast</artifactId>
64 + </dependency>
61 </dependencies> 65 </dependencies>
62 66
63 </project> 67 </project>
......
...@@ -16,6 +16,7 @@ import java.util.HashSet; ...@@ -16,6 +16,7 @@ import java.util.HashSet;
16 import java.util.Iterator; 16 import java.util.Iterator;
17 import java.util.Set; 17 import java.util.Set;
18 18
19 +//Not used right now
19 /** 20 /**
20 * Allows for reading and writing cluster definition as a JSON file. 21 * Allows for reading and writing cluster definition as a JSON file.
21 */ 22 */
......
...@@ -2,6 +2,7 @@ package org.onlab.onos.store.cluster.impl; ...@@ -2,6 +2,7 @@ package org.onlab.onos.store.cluster.impl;
2 2
3 import org.onlab.onos.store.cluster.messaging.MessageSubject; 3 import org.onlab.onos.store.cluster.messaging.MessageSubject;
4 4
5 +//Not used right now
5 public final class ClusterManagementMessageSubjects { 6 public final class ClusterManagementMessageSubjects {
6 // avoid instantiation 7 // avoid instantiation
7 private ClusterManagementMessageSubjects() {} 8 private ClusterManagementMessageSubjects() {}
......
...@@ -2,6 +2,7 @@ package org.onlab.onos.store.cluster.impl; ...@@ -2,6 +2,7 @@ package org.onlab.onos.store.cluster.impl;
2 2
3 import org.onlab.onos.cluster.ControllerNode; 3 import org.onlab.onos.cluster.ControllerNode;
4 4
5 +//Not used right now
5 /** 6 /**
6 * Contains information that will be published when a cluster membership event occurs. 7 * Contains information that will be published when a cluster membership event occurs.
7 */ 8 */
......
1 package org.onlab.onos.store.cluster.impl; 1 package org.onlab.onos.store.cluster.impl;
2 2
3 +//Not used right now
3 public enum ClusterMembershipEventType { 4 public enum ClusterMembershipEventType {
4 NEW_MEMBER, 5 NEW_MEMBER,
5 LEAVING_MEMBER, 6 LEAVING_MEMBER,
......
...@@ -4,6 +4,7 @@ import org.onlab.onos.cluster.DefaultControllerNode; ...@@ -4,6 +4,7 @@ import org.onlab.onos.cluster.DefaultControllerNode;
4 import org.onlab.onos.cluster.NodeId; 4 import org.onlab.onos.cluster.NodeId;
5 import org.onlab.packet.IpPrefix; 5 import org.onlab.packet.IpPrefix;
6 6
7 +// Not used right now
7 /** 8 /**
8 * Simple back interface through which connection manager can interact with 9 * Simple back interface through which connection manager can interact with
9 * the cluster store. 10 * the cluster store.
......
...@@ -19,9 +19,9 @@ import org.onlab.onos.cluster.ClusterStoreDelegate; ...@@ -19,9 +19,9 @@ import org.onlab.onos.cluster.ClusterStoreDelegate;
19 import org.onlab.onos.cluster.ControllerNode; 19 import org.onlab.onos.cluster.ControllerNode;
20 import org.onlab.onos.cluster.DefaultControllerNode; 20 import org.onlab.onos.cluster.DefaultControllerNode;
21 import org.onlab.onos.cluster.NodeId; 21 import org.onlab.onos.cluster.NodeId;
22 -import org.onlab.onos.store.common.AbsentInvalidatingLoadingCache; 22 +import org.onlab.onos.store.hz.AbsentInvalidatingLoadingCache;
23 -import org.onlab.onos.store.common.AbstractHazelcastStore; 23 +import org.onlab.onos.store.hz.AbstractHazelcastStore;
24 -import org.onlab.onos.store.common.OptionalCacheLoader; 24 +import org.onlab.onos.store.hz.OptionalCacheLoader;
25 import org.onlab.packet.IpPrefix; 25 import org.onlab.packet.IpPrefix;
26 26
27 import java.util.Map; 27 import java.util.Map;
......
1 -package org.onlab.onos.store.cluster.impl;
2 -
3 -import com.google.common.cache.Cache;
4 -import com.google.common.cache.CacheBuilder;
5 -import com.google.common.cache.RemovalListener;
6 -import com.google.common.cache.RemovalNotification;
7 -import com.google.common.collect.ImmutableSet;
8 -
9 -import org.apache.felix.scr.annotations.Activate;
10 -import org.apache.felix.scr.annotations.Deactivate;
11 -import org.apache.felix.scr.annotations.Reference;
12 -import org.apache.felix.scr.annotations.ReferenceCardinality;
13 -import org.onlab.onos.cluster.ClusterEvent;
14 -import org.onlab.onos.cluster.ClusterStore;
15 -import org.onlab.onos.cluster.ClusterStoreDelegate;
16 -import org.onlab.onos.cluster.ControllerNode;
17 -import org.onlab.onos.cluster.DefaultControllerNode;
18 -import org.onlab.onos.cluster.NodeId;
19 -import org.onlab.onos.store.AbstractStore;
20 -import org.onlab.onos.store.cluster.messaging.ClusterCommunicationAdminService;
21 -import org.onlab.packet.IpPrefix;
22 -import org.slf4j.Logger;
23 -import org.slf4j.LoggerFactory;
24 -
25 -import java.io.IOException;
26 -import java.util.Map;
27 -import java.util.Set;
28 -import java.util.concurrent.ConcurrentHashMap;
29 -import java.util.concurrent.TimeUnit;
30 -
31 -import static org.onlab.onos.cluster.ControllerNode.State;
32 -import static org.onlab.packet.IpPrefix.valueOf;
33 -
34 -/**
35 - * Distributed implementation of the cluster nodes store.
36 - */
37 -//@Component(immediate = true)
38 -//@Service
39 -public class DistributedClusterStore
40 - extends AbstractStore<ClusterEvent, ClusterStoreDelegate>
41 - implements ClusterStore {
42 -
43 - private final Logger log = LoggerFactory.getLogger(getClass());
44 -
45 - private DefaultControllerNode localNode;
46 - private final Map<NodeId, DefaultControllerNode> nodes = new ConcurrentHashMap<>();
47 - private final Map<NodeId, State> states = new ConcurrentHashMap<>();
48 - private final Cache<NodeId, ControllerNode> livenessCache = CacheBuilder.newBuilder()
49 - .maximumSize(1000)
50 - .expireAfterWrite(/*ClusterCommunicationManager.HEART_BEAT_INTERVAL_MILLIS * */3, TimeUnit.MILLISECONDS)
51 - .removalListener(new LivenessCacheRemovalListener()).build();
52 -
53 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
54 - private ClusterCommunicationAdminService clusterCommunicationAdminService;
55 -
56 - private final ClusterNodesDelegate nodesDelegate = new InternalNodesDelegate();
57 -
58 - @Activate
59 - public void activate() throws IOException {
60 - loadClusterDefinition();
61 - establishSelfIdentity();
62 -
63 - // Start-up the comm service and prime it with the loaded nodes.
64 - clusterCommunicationAdminService.initialize(localNode, nodesDelegate);
65 - for (DefaultControllerNode node : nodes.values()) {
66 - clusterCommunicationAdminService.addNode(node);
67 - }
68 - log.info("Started");
69 - }
70 -
71 - @Deactivate
72 - public void deactivate() {
73 - log.info("Stopped");
74 - }
75 -
76 - /**
77 - * Loads the cluster definition file.
78 - */
79 - private void loadClusterDefinition() {
80 - ClusterDefinitionStore cds = new ClusterDefinitionStore("../config/cluster.json");
81 - try {
82 - Set<DefaultControllerNode> storedNodes = cds.read();
83 - for (DefaultControllerNode node : storedNodes) {
84 - nodes.put(node.id(), node);
85 - }
86 - } catch (IOException e) {
87 - log.error("Unable to read cluster definitions", e);
88 - }
89 - }
90 -
91 - /**
92 - * Determines who the local controller node is.
93 - */
94 - private void establishSelfIdentity() {
95 - // Establishes the controller's own identity.
96 - IpPrefix ip = valueOf(System.getProperty("onos.ip", "127.0.1.1"));
97 - localNode = nodes.get(new NodeId(ip.toString()));
98 -
99 - // As a fall-back, let's make sure we at least know who we are.
100 - if (localNode == null) {
101 - localNode = new DefaultControllerNode(new NodeId(ip.toString()), ip);
102 - nodes.put(localNode.id(), localNode);
103 - }
104 - states.put(localNode.id(), State.ACTIVE);
105 - }
106 -
107 - @Override
108 - public ControllerNode getLocalNode() {
109 - return localNode;
110 - }
111 -
112 - @Override
113 - public Set<ControllerNode> getNodes() {
114 - ImmutableSet.Builder<ControllerNode> builder = ImmutableSet.builder();
115 - return builder.addAll(nodes.values()).build();
116 - }
117 -
118 - @Override
119 - public ControllerNode getNode(NodeId nodeId) {
120 - return nodes.get(nodeId);
121 - }
122 -
123 - @Override
124 - public State getState(NodeId nodeId) {
125 - State state = states.get(nodeId);
126 - return state == null ? State.INACTIVE : state;
127 - }
128 -
129 - @Override
130 - public ControllerNode addNode(NodeId nodeId, IpPrefix ip, int tcpPort) {
131 - DefaultControllerNode node = new DefaultControllerNode(nodeId, ip, tcpPort);
132 - nodes.put(nodeId, node);
133 - clusterCommunicationAdminService.addNode(node);
134 - return node;
135 - }
136 -
137 - @Override
138 - public void removeNode(NodeId nodeId) {
139 - if (nodeId.equals(localNode.id())) {
140 - nodes.clear();
141 - nodes.put(localNode.id(), localNode);
142 -
143 - } else {
144 - // Remove the other node.
145 - DefaultControllerNode node = nodes.remove(nodeId);
146 - if (node != null) {
147 - clusterCommunicationAdminService.removeNode(node);
148 - }
149 - }
150 - }
151 -
152 - // Entity to handle back calls from the connection manager.
153 - private class InternalNodesDelegate implements ClusterNodesDelegate {
154 - @Override
155 - public DefaultControllerNode nodeDetected(NodeId nodeId, IpPrefix ip, int tcpPort) {
156 - DefaultControllerNode node = nodes.get(nodeId);
157 - if (node == null) {
158 - node = (DefaultControllerNode) addNode(nodeId, ip, tcpPort);
159 - }
160 - states.put(nodeId, State.ACTIVE);
161 - livenessCache.put(nodeId, node);
162 - return node;
163 - }
164 -
165 - @Override
166 - public void nodeVanished(NodeId nodeId) {
167 - states.put(nodeId, State.INACTIVE);
168 - }
169 -
170 - @Override
171 - public void nodeRemoved(NodeId nodeId) {
172 - removeNode(nodeId);
173 - }
174 - }
175 -
176 - private class LivenessCacheRemovalListener implements RemovalListener<NodeId, ControllerNode> {
177 -
178 - @Override
179 - public void onRemoval(RemovalNotification<NodeId, ControllerNode> entry) {
180 - NodeId nodeId = entry.getKey();
181 - log.warn("Failed to receive heartbeats from controller: " + nodeId);
182 - nodesDelegate.nodeVanished(nodeId);
183 - }
184 - }
185 -}
1 /** 1 /**
2 - * Distributed cluster store and messaging subsystem implementation. 2 + * Implementation of a distributed cluster node store using Hazelcast.
3 */ 3 */
4 package org.onlab.onos.store.cluster.impl; 4 package org.onlab.onos.store.cluster.impl;
......
1 -package org.onlab.onos.store.common; 1 +package org.onlab.onos.store.hz;
2 2
3 import java.util.concurrent.Callable; 3 import java.util.concurrent.Callable;
4 import java.util.concurrent.ExecutionException; 4 import java.util.concurrent.ExecutionException;
......
1 -package org.onlab.onos.store.common; 1 +package org.onlab.onos.store.hz;
2 2
3 import com.google.common.base.Optional; 3 import com.google.common.base.Optional;
4 import com.google.common.cache.LoadingCache; 4 import com.google.common.cache.LoadingCache;
......
1 -package org.onlab.onos.store.common; 1 +package org.onlab.onos.store.hz;
2 2
3 import static com.google.common.base.Preconditions.checkNotNull; 3 import static com.google.common.base.Preconditions.checkNotNull;
4 4
......
1 -package org.onlab.onos.store.common; 1 +package org.onlab.onos.store.hz;
2 2
3 import static com.google.common.base.Preconditions.checkNotNull; 3 import static com.google.common.base.Preconditions.checkNotNull;
4 4
......
1 -package org.onlab.onos.store.common; 1 +package org.onlab.onos.store.hz;
2 2
3 import com.hazelcast.config.Config; 3 import com.hazelcast.config.Config;
4 import com.hazelcast.config.FileSystemXmlConfig; 4 import com.hazelcast.config.FileSystemXmlConfig;
......
1 -package org.onlab.onos.store.common; 1 +package org.onlab.onos.store.hz;
2 2
3 import com.hazelcast.core.HazelcastInstance; 3 import com.hazelcast.core.HazelcastInstance;
4 4
......
...@@ -2,4 +2,4 @@ ...@@ -2,4 +2,4 @@
2 * Common abstractions and facilities for implementing distributed store 2 * Common abstractions and facilities for implementing distributed store
3 * using Hazelcast. 3 * using Hazelcast.
4 */ 4 */
5 -package org.onlab.onos.store.common; 5 +package org.onlab.onos.store.hz;
......
...@@ -20,8 +20,8 @@ import org.onlab.onos.mastership.MastershipStoreDelegate; ...@@ -20,8 +20,8 @@ import org.onlab.onos.mastership.MastershipStoreDelegate;
20 import org.onlab.onos.mastership.MastershipTerm; 20 import org.onlab.onos.mastership.MastershipTerm;
21 import org.onlab.onos.net.DeviceId; 21 import org.onlab.onos.net.DeviceId;
22 import org.onlab.onos.net.MastershipRole; 22 import org.onlab.onos.net.MastershipRole;
23 -import org.onlab.onos.store.common.AbstractHazelcastStore; 23 +import org.onlab.onos.store.hz.AbstractHazelcastStore;
24 -import org.onlab.onos.store.common.SMap; 24 +import org.onlab.onos.store.hz.SMap;
25 import org.onlab.onos.store.serializers.KryoNamespaces; 25 import org.onlab.onos.store.serializers.KryoNamespaces;
26 import org.onlab.onos.store.serializers.KryoSerializer; 26 import org.onlab.onos.store.serializers.KryoSerializer;
27 import org.onlab.util.KryoNamespace; 27 import org.onlab.util.KryoNamespace;
...@@ -31,6 +31,7 @@ import com.hazelcast.core.EntryEvent; ...@@ -31,6 +31,7 @@ import com.hazelcast.core.EntryEvent;
31 import com.hazelcast.core.EntryListener; 31 import com.hazelcast.core.EntryListener;
32 import com.hazelcast.core.IAtomicLong; 32 import com.hazelcast.core.IAtomicLong;
33 import com.hazelcast.core.MapEvent; 33 import com.hazelcast.core.MapEvent;
34 +
34 import static org.onlab.onos.net.MastershipRole.*; 35 import static org.onlab.onos.net.MastershipRole.*;
35 36
36 /** 37 /**
......
1 -package org.onlab.onos.store.common; 1 +package org.onlab.onos.store.hz;
2 2
3 import java.io.FileNotFoundException; 3 import java.io.FileNotFoundException;
4 import java.util.UUID; 4 import java.util.UUID;
......
...@@ -28,9 +28,9 @@ import org.onlab.onos.mastership.MastershipTerm; ...@@ -28,9 +28,9 @@ import org.onlab.onos.mastership.MastershipTerm;
28 import org.onlab.onos.mastership.MastershipEvent.Type; 28 import org.onlab.onos.mastership.MastershipEvent.Type;
29 import org.onlab.onos.net.DeviceId; 29 import org.onlab.onos.net.DeviceId;
30 import org.onlab.onos.net.MastershipRole; 30 import org.onlab.onos.net.MastershipRole;
31 -import org.onlab.onos.store.common.StoreManager; 31 +import org.onlab.onos.store.hz.StoreManager;
32 -import org.onlab.onos.store.common.StoreService; 32 +import org.onlab.onos.store.hz.StoreService;
33 -import org.onlab.onos.store.common.TestStoreManager; 33 +import org.onlab.onos.store.hz.TestStoreManager;
34 import org.onlab.onos.store.serializers.KryoSerializer; 34 import org.onlab.onos.store.serializers.KryoSerializer;
35 import org.onlab.packet.IpPrefix; 35 import org.onlab.packet.IpPrefix;
36 36
......
1 -<?xml version="1.0" encoding="UTF-8"?>
2 -<project xmlns="http://maven.apache.org/POM/4.0.0"
3 - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4 - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
5 - <modelVersion>4.0.0</modelVersion>
6 -
7 - <parent>
8 - <groupId>org.onlab.onos</groupId>
9 - <artifactId>onos-core-hz</artifactId>
10 - <version>1.0.0-SNAPSHOT</version>
11 - <relativePath>../pom.xml</relativePath>
12 - </parent>
13 -
14 - <artifactId>onos-core-hz-cluster</artifactId>
15 - <packaging>bundle</packaging>
16 -
17 - <description>ONOS Hazelcast based distributed store subsystems</description>
18 -
19 - <dependencies>
20 - <dependency>
21 - <groupId>org.onlab.onos</groupId>
22 - <artifactId>onos-core-serializers</artifactId>
23 - <version>${project.version}</version>
24 - </dependency>
25 - <dependency>
26 - <groupId>org.onlab.onos</groupId>
27 - <artifactId>onos-core-hz-common</artifactId>
28 - <version>${project.version}</version>
29 - </dependency>
30 - <dependency>
31 - <groupId>org.onlab.onos</groupId>
32 - <artifactId>onos-core-hz-common</artifactId>
33 - <classifier>tests</classifier>
34 - <scope>test</scope>
35 - <version>${project.version}</version>
36 - </dependency>
37 - </dependencies>
38 -
39 -</project>
1 -/**
2 - * Implementation of a distributed cluster node store using Hazelcast.
3 - */
4 -package org.onlab.onos.store.cluster.impl;
1 -<?xml version="1.0" encoding="UTF-8"?>
2 -<project xmlns="http://maven.apache.org/POM/4.0.0"
3 - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4 - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
5 - <modelVersion>4.0.0</modelVersion>
6 -
7 - <parent>
8 - <groupId>org.onlab.onos</groupId>
9 - <artifactId>onos-core-hz</artifactId>
10 - <version>1.0.0-SNAPSHOT</version>
11 - <relativePath>../pom.xml</relativePath>
12 - </parent>
13 -
14 - <artifactId>onos-core-hz-common</artifactId>
15 - <packaging>bundle</packaging>
16 -
17 - <description>ONOS Hazelcast based distributed store subsystems</description>
18 -
19 - <dependencies>
20 - <dependency>
21 - <groupId>org.onlab.onos</groupId>
22 - <artifactId>onos-core-serializers</artifactId>
23 - <version>${project.version}</version>
24 - </dependency>
25 - <dependency>
26 - <groupId>org.apache.commons</groupId>
27 - <artifactId>commons-lang3</artifactId>
28 - </dependency>
29 - </dependencies>
30 -
31 -</project>
1 -<?xml version="1.0" encoding="UTF-8"?>
2 -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3 - <modelVersion>4.0.0</modelVersion>
4 -
5 - <parent>
6 - <groupId>org.onlab.onos</groupId>
7 - <artifactId>onos-core-store</artifactId>
8 - <version>1.0.0-SNAPSHOT</version>
9 - <relativePath>../pom.xml</relativePath>
10 - </parent>
11 -
12 - <artifactId>onos-core-hz</artifactId>
13 - <packaging>pom</packaging>
14 -
15 - <description>ONOS Core Hazelcast Store subsystem</description>
16 -
17 - <modules>
18 - <module>common</module>
19 - <module>cluster</module>
20 - </modules>
21 -
22 - <dependencies>
23 - <dependency>
24 - <groupId>com.hazelcast</groupId>
25 - <artifactId>hazelcast</artifactId>
26 - </dependency>
27 - </dependencies>
28 -
29 -</project>
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
19 <modules> 19 <modules>
20 <module>trivial</module> 20 <module>trivial</module>
21 <module>dist</module> 21 <module>dist</module>
22 - <module>hz</module>
23 <module>serializers</module> 22 <module>serializers</module>
24 </modules> 23 </modules>
25 24
......
...@@ -87,9 +87,6 @@ ...@@ -87,9 +87,6 @@
87 <bundle>mvn:org.onlab.onos/onos-core-dist/1.0.0-SNAPSHOT</bundle> 87 <bundle>mvn:org.onlab.onos/onos-core-dist/1.0.0-SNAPSHOT</bundle>
88 <bundle>mvn:org.onlab.onos/onos-core-serializers/1.0.0-SNAPSHOT</bundle> 88 <bundle>mvn:org.onlab.onos/onos-core-serializers/1.0.0-SNAPSHOT</bundle>
89 <bundle>mvn:org.onlab.onos/onlab-netty/1.0.0-SNAPSHOT</bundle> 89 <bundle>mvn:org.onlab.onos/onlab-netty/1.0.0-SNAPSHOT</bundle>
90 -
91 - <bundle>mvn:org.onlab.onos/onos-core-hz-common/1.0.0-SNAPSHOT</bundle>
92 - <bundle>mvn:org.onlab.onos/onos-core-hz-cluster/1.0.0-SNAPSHOT</bundle>
93 </feature> 90 </feature>
94 91
95 <feature name="onos-core-trivial" version="1.0.0" 92 <feature name="onos-core-trivial" version="1.0.0"
......