Committed by
Gerrit Code Review
Code clean up: Removed unused code. Fixed comments. Renamed some files.
Change-Id: I78ca1f4a973c3b5356f749680ebe0f4ccde01279 (cherry picked from commit 78be249d)
Showing
37 changed files
with
48 additions
and
1633 deletions
core/store/dist/src/main/java/org/onosproject/store/cfg/GossipComponentConfigStore.java
deleted
100644 → 0
| 1 | -/* | ||
| 2 | - * Copyright 2015-present Open Networking Laboratory | ||
| 3 | - * | ||
| 4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | - * you may not use this file except in compliance with the License. | ||
| 6 | - * You may obtain a copy of the License at | ||
| 7 | - * | ||
| 8 | - * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | - * | ||
| 10 | - * Unless required by applicable law or agreed to in writing, software | ||
| 11 | - * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | - * See the License for the specific language governing permissions and | ||
| 14 | - * limitations under the License. | ||
| 15 | - */ | ||
| 16 | -package org.onosproject.store.cfg; | ||
| 17 | - | ||
| 18 | -import org.apache.felix.scr.annotations.Activate; | ||
| 19 | -import org.apache.felix.scr.annotations.Component; | ||
| 20 | -import org.apache.felix.scr.annotations.Deactivate; | ||
| 21 | -import org.apache.felix.scr.annotations.Reference; | ||
| 22 | -import org.apache.felix.scr.annotations.ReferenceCardinality; | ||
| 23 | -import org.apache.felix.scr.annotations.Service; | ||
| 24 | -import org.onlab.util.KryoNamespace; | ||
| 25 | -import org.onosproject.cfg.ComponentConfigEvent; | ||
| 26 | -import org.onosproject.cfg.ComponentConfigStore; | ||
| 27 | -import org.onosproject.cfg.ComponentConfigStoreDelegate; | ||
| 28 | -import org.onosproject.store.AbstractStore; | ||
| 29 | -import org.onosproject.store.serializers.KryoNamespaces; | ||
| 30 | -import org.onosproject.store.service.EventuallyConsistentMap; | ||
| 31 | -import org.onosproject.store.service.EventuallyConsistentMapEvent; | ||
| 32 | -import org.onosproject.store.service.EventuallyConsistentMapListener; | ||
| 33 | -import org.onosproject.store.service.LogicalClockService; | ||
| 34 | -import org.onosproject.store.service.StorageService; | ||
| 35 | -import org.slf4j.Logger; | ||
| 36 | - | ||
| 37 | -import static org.onosproject.cfg.ComponentConfigEvent.Type.PROPERTY_SET; | ||
| 38 | -import static org.onosproject.cfg.ComponentConfigEvent.Type.PROPERTY_UNSET; | ||
| 39 | -import static org.onosproject.store.service.EventuallyConsistentMapEvent.Type.PUT; | ||
| 40 | -import static org.onosproject.store.service.EventuallyConsistentMapEvent.Type.REMOVE; | ||
| 41 | -import static org.slf4j.LoggerFactory.getLogger; | ||
| 42 | - | ||
| 43 | -/** | ||
| 44 | - * Manages inventory of component configurations in a distributed data store | ||
| 45 | - * that uses optimistic replication and gossip based anti-entropy techniques. | ||
| 46 | - */ | ||
| 47 | -@Component(immediate = true, enabled = false) | ||
| 48 | -@Service | ||
| 49 | -public class GossipComponentConfigStore | ||
| 50 | - extends AbstractStore<ComponentConfigEvent, ComponentConfigStoreDelegate> | ||
| 51 | - implements ComponentConfigStore { | ||
| 52 | - | ||
| 53 | - private static final String SEP = "#"; | ||
| 54 | - | ||
| 55 | - private final Logger log = getLogger(getClass()); | ||
| 56 | - | ||
| 57 | - private EventuallyConsistentMap<String, String> properties; | ||
| 58 | - | ||
| 59 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 60 | - protected StorageService storageService; | ||
| 61 | - | ||
| 62 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 63 | - protected LogicalClockService clockService; | ||
| 64 | - | ||
| 65 | - @Activate | ||
| 66 | - public void activate() { | ||
| 67 | - KryoNamespace.Builder serializer = KryoNamespace.newBuilder() | ||
| 68 | - .register(KryoNamespaces.API); | ||
| 69 | - | ||
| 70 | - properties = storageService.<String, String>eventuallyConsistentMapBuilder() | ||
| 71 | - .withName("cfg") | ||
| 72 | - .withSerializer(serializer) | ||
| 73 | - .withTimestampProvider((k, v) -> clockService.getTimestamp()) | ||
| 74 | - .build(); | ||
| 75 | - | ||
| 76 | - properties.addListener(new InternalPropertiesListener()); | ||
| 77 | - log.info("Started"); | ||
| 78 | - } | ||
| 79 | - | ||
| 80 | - @Deactivate | ||
| 81 | - public void deactivate() { | ||
| 82 | - properties.destroy(); | ||
| 83 | - log.info("Stopped"); | ||
| 84 | - } | ||
| 85 | - | ||
| 86 | - @Override | ||
| 87 | - public void setProperty(String componentName, String name, String value) { | ||
| 88 | - properties.put(key(componentName, name), value); | ||
| 89 | - | ||
| 90 | - } | ||
| 91 | - | ||
| 92 | - @Override | ||
| 93 | - public void unsetProperty(String componentName, String name) { | ||
| 94 | - properties.remove(key(componentName, name)); | ||
| 95 | - } | ||
| 96 | - | ||
| 97 | - /** | ||
| 98 | - * Listener to component configuration properties distributed map changes. | ||
| 99 | - */ | ||
| 100 | - private final class InternalPropertiesListener | ||
| 101 | - implements EventuallyConsistentMapListener<String, String> { | ||
| 102 | - | ||
| 103 | - @Override | ||
| 104 | - public void event(EventuallyConsistentMapEvent<String, String> event) { | ||
| 105 | - String[] keys = event.key().split(SEP); | ||
| 106 | - String value = event.value(); | ||
| 107 | - if (event.type() == PUT) { | ||
| 108 | - delegate.notify(new ComponentConfigEvent(PROPERTY_SET, keys[0], keys[1], value)); | ||
| 109 | - } else if (event.type() == REMOVE) { | ||
| 110 | - delegate.notify(new ComponentConfigEvent(PROPERTY_UNSET, keys[0], keys[1], null)); | ||
| 111 | - } | ||
| 112 | - } | ||
| 113 | - } | ||
| 114 | - | ||
| 115 | - // Generates a key from component name and property name. | ||
| 116 | - private String key(String componentName, String name) { | ||
| 117 | - return componentName + SEP + name; | ||
| 118 | - } | ||
| 119 | - | ||
| 120 | -} |
| 1 | -/* | ||
| 2 | - * Copyright 2014-present Open Networking Laboratory | ||
| 3 | - * | ||
| 4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | - * you may not use this file except in compliance with the License. | ||
| 6 | - * You may obtain a copy of the License at | ||
| 7 | - * | ||
| 8 | - * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | - * | ||
| 10 | - * Unless required by applicable law or agreed to in writing, software | ||
| 11 | - * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | - * See the License for the specific language governing permissions and | ||
| 14 | - * limitations under the License. | ||
| 15 | - */ | ||
| 16 | -package org.onosproject.store.cluster.impl; | ||
| 17 | - | ||
| 18 | -import org.onosproject.store.cluster.messaging.MessageSubject; | ||
| 19 | - | ||
| 20 | -//Not used right now | ||
| 21 | -public final class ClusterManagementMessageSubjects { | ||
| 22 | - // avoid instantiation | ||
| 23 | - private ClusterManagementMessageSubjects() {} | ||
| 24 | - | ||
| 25 | - public static final MessageSubject CLUSTER_MEMBERSHIP_EVENT = new MessageSubject("CLUSTER_MEMBERSHIP_EVENT"); | ||
| 26 | -} |
core/store/dist/src/main/java/org/onosproject/store/cluster/impl/ClusterMembershipEvent.java
deleted
100644 → 0
| 1 | -/* | ||
| 2 | - * Copyright 2014-present Open Networking Laboratory | ||
| 3 | - * | ||
| 4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | - * you may not use this file except in compliance with the License. | ||
| 6 | - * You may obtain a copy of the License at | ||
| 7 | - * | ||
| 8 | - * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | - * | ||
| 10 | - * Unless required by applicable law or agreed to in writing, software | ||
| 11 | - * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | - * See the License for the specific language governing permissions and | ||
| 14 | - * limitations under the License. | ||
| 15 | - */ | ||
| 16 | -package org.onosproject.store.cluster.impl; | ||
| 17 | - | ||
| 18 | -import org.onosproject.cluster.ControllerNode; | ||
| 19 | - | ||
| 20 | -//Not used right now | ||
| 21 | -/** | ||
| 22 | - * Contains information that will be published when a cluster membership event occurs. | ||
| 23 | - */ | ||
| 24 | -public class ClusterMembershipEvent { | ||
| 25 | - | ||
| 26 | - private final ClusterMembershipEventType type; | ||
| 27 | - private final ControllerNode node; | ||
| 28 | - | ||
| 29 | - public ClusterMembershipEvent(ClusterMembershipEventType type, ControllerNode node) { | ||
| 30 | - this.type = type; | ||
| 31 | - this.node = node; | ||
| 32 | - } | ||
| 33 | - | ||
| 34 | - public ClusterMembershipEventType type() { | ||
| 35 | - return type; | ||
| 36 | - } | ||
| 37 | - | ||
| 38 | - public ControllerNode node() { | ||
| 39 | - return node; | ||
| 40 | - } | ||
| 41 | -} |
| 1 | -/* | ||
| 2 | - * Copyright 2014-present Open Networking Laboratory | ||
| 3 | - * | ||
| 4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | - * you may not use this file except in compliance with the License. | ||
| 6 | - * You may obtain a copy of the License at | ||
| 7 | - * | ||
| 8 | - * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | - * | ||
| 10 | - * Unless required by applicable law or agreed to in writing, software | ||
| 11 | - * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | - * See the License for the specific language governing permissions and | ||
| 14 | - * limitations under the License. | ||
| 15 | - */ | ||
| 16 | -package org.onosproject.store.cluster.impl; | ||
| 17 | - | ||
| 18 | -//Not used right now | ||
| 19 | -public enum ClusterMembershipEventType { | ||
| 20 | - NEW_MEMBER, | ||
| 21 | - LEAVING_MEMBER, | ||
| 22 | - UNREACHABLE_MEMBER, | ||
| 23 | - HEART_BEAT, | ||
| 24 | -} |
core/store/dist/src/main/java/org/onosproject/store/cluster/impl/ClusterNodesDelegate.java
deleted
100644 → 0
| 1 | -/* | ||
| 2 | - * Copyright 2014-present Open Networking Laboratory | ||
| 3 | - * | ||
| 4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | - * you may not use this file except in compliance with the License. | ||
| 6 | - * You may obtain a copy of the License at | ||
| 7 | - * | ||
| 8 | - * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | - * | ||
| 10 | - * Unless required by applicable law or agreed to in writing, software | ||
| 11 | - * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | - * See the License for the specific language governing permissions and | ||
| 14 | - * limitations under the License. | ||
| 15 | - */ | ||
| 16 | -package org.onosproject.store.cluster.impl; | ||
| 17 | - | ||
| 18 | -import org.onosproject.cluster.DefaultControllerNode; | ||
| 19 | -import org.onosproject.cluster.NodeId; | ||
| 20 | -import org.onlab.packet.IpAddress; | ||
| 21 | - | ||
| 22 | -// Not used right now | ||
| 23 | -/** | ||
| 24 | - * Simple back interface through which connection manager can interact with | ||
| 25 | - * the cluster store. | ||
| 26 | - */ | ||
| 27 | -public interface ClusterNodesDelegate { | ||
| 28 | - | ||
| 29 | - /** | ||
| 30 | - * Notifies about cluster node coming online. | ||
| 31 | - * | ||
| 32 | - * @param nodeId newly detected cluster node id | ||
| 33 | - * @param ip node IP listen address | ||
| 34 | - * @param tcpPort node TCP listen port | ||
| 35 | - * @return the controller node | ||
| 36 | - */ | ||
| 37 | - DefaultControllerNode nodeDetected(NodeId nodeId, IpAddress ip, | ||
| 38 | - int tcpPort); | ||
| 39 | - | ||
| 40 | - /** | ||
| 41 | - * Notifies about cluster node going offline. | ||
| 42 | - * | ||
| 43 | - * @param nodeId identifier of the cluster node that vanished | ||
| 44 | - */ | ||
| 45 | - void nodeVanished(NodeId nodeId); | ||
| 46 | - | ||
| 47 | - /** | ||
| 48 | - * Notifies about remote request to remove node from cluster. | ||
| 49 | - * | ||
| 50 | - * @param nodeId identifier of the cluster node that was removed | ||
| 51 | - */ | ||
| 52 | - void nodeRemoved(NodeId nodeId); | ||
| 53 | - | ||
| 54 | -} |
This diff is collapsed. Click to expand it.
| 1 | -/* | ||
| 2 | - * Copyright 2016-present Open Networking Laboratory | ||
| 3 | - * | ||
| 4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | - * you may not use this file except in compliance with the License. | ||
| 6 | - * You may obtain a copy of the License at | ||
| 7 | - * | ||
| 8 | - * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | - * | ||
| 10 | - * Unless required by applicable law or agreed to in writing, software | ||
| 11 | - * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | - * See the License for the specific language governing permissions and | ||
| 14 | - * limitations under the License. | ||
| 15 | - */ | ||
| 16 | -package org.onosproject.store.cluster.impl; | ||
| 17 | - | ||
| 18 | -import static org.slf4j.LoggerFactory.getLogger; | ||
| 19 | - | ||
| 20 | -import java.util.Map; | ||
| 21 | -import java.util.Objects; | ||
| 22 | -import java.util.function.Consumer; | ||
| 23 | - | ||
| 24 | -import org.apache.felix.scr.annotations.Activate; | ||
| 25 | -import org.apache.felix.scr.annotations.Component; | ||
| 26 | -import org.apache.felix.scr.annotations.Deactivate; | ||
| 27 | -import org.apache.felix.scr.annotations.Reference; | ||
| 28 | -import org.apache.felix.scr.annotations.ReferenceCardinality; | ||
| 29 | -import org.apache.felix.scr.annotations.Service; | ||
| 30 | -import org.onosproject.cluster.ClusterService; | ||
| 31 | -import org.onosproject.cluster.Leadership; | ||
| 32 | -import org.onosproject.cluster.LeadershipEvent; | ||
| 33 | -import org.onosproject.cluster.LeadershipStore; | ||
| 34 | -import org.onosproject.cluster.LeadershipStoreDelegate; | ||
| 35 | -import org.onosproject.cluster.NodeId; | ||
| 36 | -import org.onosproject.event.Change; | ||
| 37 | -import org.onosproject.store.AbstractStore; | ||
| 38 | -import org.onosproject.store.service.LeaderElector; | ||
| 39 | -import org.onosproject.store.service.StorageService; | ||
| 40 | -import org.slf4j.Logger; | ||
| 41 | - | ||
| 42 | -/** | ||
| 43 | - * Implementation of {@code LeadershipStore} that makes use of a {@link LeaderElector} | ||
| 44 | - * primitive. | ||
| 45 | - */ | ||
| 46 | -@Service | ||
| 47 | -@Component(immediate = true, enabled = true) | ||
| 48 | -public class NewDistributedLeadershipStore | ||
| 49 | - extends AbstractStore<LeadershipEvent, LeadershipStoreDelegate> | ||
| 50 | - implements LeadershipStore { | ||
| 51 | - | ||
| 52 | - private final Logger log = getLogger(getClass()); | ||
| 53 | - | ||
| 54 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 55 | - protected ClusterService clusterService; | ||
| 56 | - | ||
| 57 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 58 | - protected StorageService storageService; | ||
| 59 | - | ||
| 60 | - private NodeId localNodeId; | ||
| 61 | - private LeaderElector leaderElector; | ||
| 62 | - | ||
| 63 | - private final Consumer<Change<Leadership>> leadershipChangeListener = | ||
| 64 | - change -> { | ||
| 65 | - Leadership oldValue = change.oldValue(); | ||
| 66 | - Leadership newValue = change.newValue(); | ||
| 67 | - boolean leaderChanged = !Objects.equals(oldValue.leader(), newValue.leader()); | ||
| 68 | - boolean candidatesChanged = !Objects.equals(oldValue.candidates(), newValue.candidates()); | ||
| 69 | - LeadershipEvent.Type eventType = null; | ||
| 70 | - if (leaderChanged && candidatesChanged) { | ||
| 71 | - eventType = LeadershipEvent.Type.LEADER_AND_CANDIDATES_CHANGED; | ||
| 72 | - } | ||
| 73 | - if (leaderChanged && !candidatesChanged) { | ||
| 74 | - eventType = LeadershipEvent.Type.LEADER_CHANGED; | ||
| 75 | - } | ||
| 76 | - if (!leaderChanged && candidatesChanged) { | ||
| 77 | - eventType = LeadershipEvent.Type.CANDIDATES_CHANGED; | ||
| 78 | - } | ||
| 79 | - notifyDelegate(new LeadershipEvent(eventType, change.newValue())); | ||
| 80 | - }; | ||
| 81 | - | ||
| 82 | - @Activate | ||
| 83 | - public void activate() { | ||
| 84 | - localNodeId = clusterService.getLocalNode().id(); | ||
| 85 | - leaderElector = storageService.leaderElectorBuilder() | ||
| 86 | - .withName("onos-leadership-elections") | ||
| 87 | - .build() | ||
| 88 | - .asLeaderElector(); | ||
| 89 | - leaderElector.addChangeListener(leadershipChangeListener); | ||
| 90 | - log.info("Started"); | ||
| 91 | - } | ||
| 92 | - | ||
| 93 | - @Deactivate | ||
| 94 | - public void deactivate() { | ||
| 95 | - leaderElector.removeChangeListener(leadershipChangeListener); | ||
| 96 | - log.info("Stopped"); | ||
| 97 | - } | ||
| 98 | - | ||
| 99 | - @Override | ||
| 100 | - public Leadership addRegistration(String topic) { | ||
| 101 | - return leaderElector.run(topic, localNodeId); | ||
| 102 | - } | ||
| 103 | - | ||
| 104 | - @Override | ||
| 105 | - public void removeRegistration(String topic) { | ||
| 106 | - leaderElector.withdraw(topic); | ||
| 107 | - } | ||
| 108 | - | ||
| 109 | - @Override | ||
| 110 | - public void removeRegistration(NodeId nodeId) { | ||
| 111 | - leaderElector.evict(nodeId); | ||
| 112 | - } | ||
| 113 | - | ||
| 114 | - @Override | ||
| 115 | - public boolean moveLeadership(String topic, NodeId toNodeId) { | ||
| 116 | - return leaderElector.anoint(topic, toNodeId); | ||
| 117 | - } | ||
| 118 | - | ||
| 119 | - @Override | ||
| 120 | - public boolean makeTopCandidate(String topic, NodeId nodeId) { | ||
| 121 | - return leaderElector.promote(topic, nodeId); | ||
| 122 | - } | ||
| 123 | - | ||
| 124 | - @Override | ||
| 125 | - public Leadership getLeadership(String topic) { | ||
| 126 | - return leaderElector.getLeadership(topic); | ||
| 127 | - } | ||
| 128 | - | ||
| 129 | - @Override | ||
| 130 | - public Map<String, Leadership> getLeaderships() { | ||
| 131 | - return leaderElector.getLeaderships(); | ||
| 132 | - } | ||
| 133 | -} |
| 1 | -/* | ||
| 2 | - * Copyright 2015-present Open Networking Laboratory | ||
| 3 | - * | ||
| 4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | - * you may not use this file except in compliance with the License. | ||
| 6 | - * You may obtain a copy of the License at | ||
| 7 | - * | ||
| 8 | - * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | - * | ||
| 10 | - * Unless required by applicable law or agreed to in writing, software | ||
| 11 | - * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | - * See the License for the specific language governing permissions and | ||
| 14 | - * limitations under the License. | ||
| 15 | - */ | ||
| 16 | -package org.onosproject.store.cluster.impl; | ||
| 17 | - | ||
| 18 | -import static com.google.common.base.MoreObjects.toStringHelper; | ||
| 19 | - | ||
| 20 | -import java.util.Objects; | ||
| 21 | - | ||
| 22 | -import org.onosproject.cluster.ControllerNode; | ||
| 23 | - | ||
| 24 | -/** | ||
| 25 | - * Node info read from configuration files during bootstrap. | ||
| 26 | - */ | ||
| 27 | -public final class NodeInfo { | ||
| 28 | - private final String id; | ||
| 29 | - private final String ip; | ||
| 30 | - private final int tcpPort; | ||
| 31 | - | ||
| 32 | - private NodeInfo(String id, String ip, int port) { | ||
| 33 | - this.id = id; | ||
| 34 | - this.ip = ip; | ||
| 35 | - this.tcpPort = port; | ||
| 36 | - } | ||
| 37 | - | ||
| 38 | - /* | ||
| 39 | - * Needed for serialization. | ||
| 40 | - */ | ||
| 41 | - private NodeInfo() { | ||
| 42 | - id = null; | ||
| 43 | - ip = null; | ||
| 44 | - tcpPort = 0; | ||
| 45 | - } | ||
| 46 | - | ||
| 47 | - /** | ||
| 48 | - * Creates a new instance. | ||
| 49 | - * @param id node id | ||
| 50 | - * @param ip node ip address | ||
| 51 | - * @param port tcp port | ||
| 52 | - * @return NodeInfo | ||
| 53 | - */ | ||
| 54 | - public static NodeInfo from(String id, String ip, int port) { | ||
| 55 | - NodeInfo node = new NodeInfo(id, ip, port); | ||
| 56 | - return node; | ||
| 57 | - } | ||
| 58 | - | ||
| 59 | - /** | ||
| 60 | - * Returns the NodeInfo for a controller node. | ||
| 61 | - * @param node controller node | ||
| 62 | - * @return NodeInfo | ||
| 63 | - */ | ||
| 64 | - public static NodeInfo of(ControllerNode node) { | ||
| 65 | - return NodeInfo.from(node.id().toString(), node.ip().toString(), node.tcpPort()); | ||
| 66 | - } | ||
| 67 | - | ||
| 68 | - /** | ||
| 69 | - * Returns node id. | ||
| 70 | - * @return node id | ||
| 71 | - */ | ||
| 72 | - public String getId() { | ||
| 73 | - return id; | ||
| 74 | - } | ||
| 75 | - | ||
| 76 | - /** | ||
| 77 | - * Returns node ip. | ||
| 78 | - * @return node ip | ||
| 79 | - */ | ||
| 80 | - public String getIp() { | ||
| 81 | - return ip; | ||
| 82 | - } | ||
| 83 | - | ||
| 84 | - /** | ||
| 85 | - * Returns node port. | ||
| 86 | - * @return port | ||
| 87 | - */ | ||
| 88 | - public int getTcpPort() { | ||
| 89 | - return tcpPort; | ||
| 90 | - } | ||
| 91 | - | ||
| 92 | - @Override | ||
| 93 | - public int hashCode() { | ||
| 94 | - return Objects.hash(id, ip, tcpPort); | ||
| 95 | - } | ||
| 96 | - | ||
| 97 | - @Override | ||
| 98 | - public boolean equals(Object o) { | ||
| 99 | - if (this == o) { | ||
| 100 | - return true; | ||
| 101 | - } | ||
| 102 | - if (o instanceof NodeInfo) { | ||
| 103 | - NodeInfo that = (NodeInfo) o; | ||
| 104 | - return Objects.equals(this.id, that.id) && | ||
| 105 | - Objects.equals(this.ip, that.ip) && | ||
| 106 | - Objects.equals(this.tcpPort, that.tcpPort); | ||
| 107 | - } | ||
| 108 | - return false; | ||
| 109 | - } | ||
| 110 | - | ||
| 111 | - @Override | ||
| 112 | - public String toString() { | ||
| 113 | - return toStringHelper(this) | ||
| 114 | - .add("id", id) | ||
| 115 | - .add("ip", ip) | ||
| 116 | - .add("tcpPort", tcpPort).toString(); | ||
| 117 | - } | ||
| 118 | -} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| ... | @@ -15,6 +15,6 @@ | ... | @@ -15,6 +15,6 @@ |
| 15 | */ | 15 | */ |
| 16 | 16 | ||
| 17 | /** | 17 | /** |
| 18 | - * Implementation of a distributed cluster node store using Hazelcast. | 18 | + * Implementation of a distributed cluster membership store and failure detector. |
| 19 | */ | 19 | */ |
| 20 | package org.onosproject.store.cluster.impl; | 20 | package org.onosproject.store.cluster.impl; | ... | ... |
| ... | @@ -15,6 +15,6 @@ | ... | @@ -15,6 +15,6 @@ |
| 15 | */ | 15 | */ |
| 16 | 16 | ||
| 17 | /** | 17 | /** |
| 18 | - * Implementation of the network configuration distributed store. | 18 | + * Implementation of the distributed network configuration store. |
| 19 | */ | 19 | */ |
| 20 | package org.onosproject.store.config.impl; | 20 | package org.onosproject.store.config.impl; |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -17,28 +17,31 @@ package org.onosproject.store.core.impl; | ... | @@ -17,28 +17,31 @@ package org.onosproject.store.core.impl; |
| 17 | 17 | ||
| 18 | import static org.slf4j.LoggerFactory.getLogger; | 18 | import static org.slf4j.LoggerFactory.getLogger; |
| 19 | 19 | ||
| 20 | + | ||
| 20 | import java.util.Map; | 21 | import java.util.Map; |
| 21 | import java.util.Set; | 22 | import java.util.Set; |
| 23 | + | ||
| 24 | + | ||
| 22 | import org.apache.felix.scr.annotations.Activate; | 25 | import org.apache.felix.scr.annotations.Activate; |
| 23 | import org.apache.felix.scr.annotations.Component; | 26 | import org.apache.felix.scr.annotations.Component; |
| 24 | import org.apache.felix.scr.annotations.Deactivate; | 27 | import org.apache.felix.scr.annotations.Deactivate; |
| 25 | import org.apache.felix.scr.annotations.Reference; | 28 | import org.apache.felix.scr.annotations.Reference; |
| 26 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 29 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 27 | import org.apache.felix.scr.annotations.Service; | 30 | import org.apache.felix.scr.annotations.Service; |
| 28 | -import org.onlab.util.KryoNamespace; | ||
| 29 | -import org.onlab.util.Tools; | ||
| 30 | import org.onosproject.core.ApplicationId; | 31 | import org.onosproject.core.ApplicationId; |
| 31 | import org.onosproject.core.ApplicationIdStore; | 32 | import org.onosproject.core.ApplicationIdStore; |
| 32 | import org.onosproject.core.DefaultApplicationId; | 33 | import org.onosproject.core.DefaultApplicationId; |
| 33 | import org.onosproject.store.serializers.KryoNamespaces; | 34 | import org.onosproject.store.serializers.KryoNamespaces; |
| 34 | import org.onosproject.store.service.AtomicCounter; | 35 | import org.onosproject.store.service.AtomicCounter; |
| 35 | import org.onosproject.store.service.ConsistentMap; | 36 | import org.onosproject.store.service.ConsistentMap; |
| 37 | +import org.onosproject.store.service.MapEvent; | ||
| 38 | +import org.onosproject.store.service.MapEventListener; | ||
| 36 | import org.onosproject.store.service.Serializer; | 39 | import org.onosproject.store.service.Serializer; |
| 37 | -import org.onosproject.store.service.StorageException; | ||
| 38 | import org.onosproject.store.service.StorageService; | 40 | import org.onosproject.store.service.StorageService; |
| 39 | import org.onosproject.store.service.Versioned; | 41 | import org.onosproject.store.service.Versioned; |
| 40 | import org.slf4j.Logger; | 42 | import org.slf4j.Logger; |
| 41 | 43 | ||
| 44 | + | ||
| 42 | import com.google.common.collect.ImmutableSet; | 45 | import com.google.common.collect.ImmutableSet; |
| 43 | import com.google.common.collect.Maps; | 46 | import com.google.common.collect.Maps; |
| 44 | 47 | ||
| ... | @@ -48,7 +51,7 @@ import com.google.common.collect.Maps; | ... | @@ -48,7 +51,7 @@ import com.google.common.collect.Maps; |
| 48 | */ | 51 | */ |
| 49 | @Component(immediate = true, enabled = true) | 52 | @Component(immediate = true, enabled = true) |
| 50 | @Service | 53 | @Service |
| 51 | -public class ConsistentApplicationIdStore implements ApplicationIdStore { | 54 | +public class DistributedApplicationIdStore implements ApplicationIdStore { |
| 52 | 55 | ||
| 53 | private final Logger log = getLogger(getClass()); | 56 | private final Logger log = getLogger(getClass()); |
| 54 | 57 | ||
| ... | @@ -57,13 +60,12 @@ public class ConsistentApplicationIdStore implements ApplicationIdStore { | ... | @@ -57,13 +60,12 @@ public class ConsistentApplicationIdStore implements ApplicationIdStore { |
| 57 | 60 | ||
| 58 | private AtomicCounter appIdCounter; | 61 | private AtomicCounter appIdCounter; |
| 59 | private ConsistentMap<String, ApplicationId> registeredIds; | 62 | private ConsistentMap<String, ApplicationId> registeredIds; |
| 60 | - private Map<String, ApplicationId> nameToAppIdCache = Maps.newConcurrentMap(); | ||
| 61 | private Map<Short, ApplicationId> idToAppIdCache = Maps.newConcurrentMap(); | 63 | private Map<Short, ApplicationId> idToAppIdCache = Maps.newConcurrentMap(); |
| 62 | - | 64 | + private MapEventListener<String, ApplicationId> mapEventListener = event -> { |
| 63 | - private static final Serializer SERIALIZER = Serializer.using(new KryoNamespace.Builder() | 65 | + if (event.type() == MapEvent.Type.INSERT) { |
| 64 | - .register(KryoNamespaces.API) | 66 | + idToAppIdCache.put(event.newValue().value().id(), event.newValue().value()); |
| 65 | - .nextId(KryoNamespaces.BEGIN_USER_CUSTOM_ID) | 67 | + } |
| 66 | - .build()); | 68 | + }; |
| 67 | 69 | ||
| 68 | @Activate | 70 | @Activate |
| 69 | public void activate() { | 71 | public void activate() { |
| ... | @@ -71,75 +73,50 @@ public class ConsistentApplicationIdStore implements ApplicationIdStore { | ... | @@ -71,75 +73,50 @@ public class ConsistentApplicationIdStore implements ApplicationIdStore { |
| 71 | 73 | ||
| 72 | registeredIds = storageService.<String, ApplicationId>consistentMapBuilder() | 74 | registeredIds = storageService.<String, ApplicationId>consistentMapBuilder() |
| 73 | .withName("onos-app-ids") | 75 | .withName("onos-app-ids") |
| 74 | - .withSerializer(SERIALIZER) | 76 | + .withSerializer(Serializer.using(KryoNamespaces.API)) |
| 77 | + .withRelaxedReadConsistency() | ||
| 75 | .build(); | 78 | .build(); |
| 76 | 79 | ||
| 77 | - primeAppIds(); | 80 | + primeIdToAppIdCache(); |
| 81 | + registeredIds.addListener(mapEventListener); | ||
| 78 | 82 | ||
| 79 | log.info("Started"); | 83 | log.info("Started"); |
| 80 | } | 84 | } |
| 81 | 85 | ||
| 82 | @Deactivate | 86 | @Deactivate |
| 83 | public void deactivate() { | 87 | public void deactivate() { |
| 88 | + registeredIds.removeListener(mapEventListener); | ||
| 84 | log.info("Stopped"); | 89 | log.info("Stopped"); |
| 85 | } | 90 | } |
| 86 | 91 | ||
| 87 | @Override | 92 | @Override |
| 88 | public Set<ApplicationId> getAppIds() { | 93 | public Set<ApplicationId> getAppIds() { |
| 89 | - // TODO: Rework this when we have notification support in ConsistentMap. | 94 | + return ImmutableSet.copyOf(registeredIds.asJavaMap().values()); |
| 90 | - primeAppIds(); | ||
| 91 | - return ImmutableSet.copyOf(nameToAppIdCache.values()); | ||
| 92 | } | 95 | } |
| 93 | 96 | ||
| 94 | @Override | 97 | @Override |
| 95 | public ApplicationId getAppId(Short id) { | 98 | public ApplicationId getAppId(Short id) { |
| 96 | if (!idToAppIdCache.containsKey(id)) { | 99 | if (!idToAppIdCache.containsKey(id)) { |
| 97 | - primeAppIds(); | 100 | + primeIdToAppIdCache(); |
| 98 | } | 101 | } |
| 99 | return idToAppIdCache.get(id); | 102 | return idToAppIdCache.get(id); |
| 100 | } | 103 | } |
| 101 | 104 | ||
| 102 | @Override | 105 | @Override |
| 103 | public ApplicationId getAppId(String name) { | 106 | public ApplicationId getAppId(String name) { |
| 104 | - ApplicationId appId = nameToAppIdCache.computeIfAbsent(name, key -> { | 107 | + return registeredIds.asJavaMap().get(name); |
| 105 | - Versioned<ApplicationId> existingAppId = registeredIds.get(key); | ||
| 106 | - return existingAppId != null ? existingAppId.value() : null; | ||
| 107 | - }); | ||
| 108 | - if (appId != null) { | ||
| 109 | - idToAppIdCache.putIfAbsent(appId.id(), appId); | ||
| 110 | - } | ||
| 111 | - return appId; | ||
| 112 | } | 108 | } |
| 113 | 109 | ||
| 114 | @Override | 110 | @Override |
| 115 | public ApplicationId registerApplication(String name) { | 111 | public ApplicationId registerApplication(String name) { |
| 116 | - ApplicationId appId = nameToAppIdCache.computeIfAbsent(name, key -> { | 112 | + return Versioned.valueOrNull(registeredIds.computeIfAbsent(name, |
| 117 | - Versioned<ApplicationId> existingAppId = registeredIds.get(name); | 113 | + key -> new DefaultApplicationId((int) appIdCounter.incrementAndGet(), name))); |
| 118 | - if (existingAppId == null) { | ||
| 119 | - int id = Tools.retryable(appIdCounter::incrementAndGet, StorageException.class, 1, 2000) | ||
| 120 | - .get() | ||
| 121 | - .intValue(); | ||
| 122 | - DefaultApplicationId newAppId = new DefaultApplicationId(id, name); | ||
| 123 | - existingAppId = registeredIds.putIfAbsent(name, newAppId); | ||
| 124 | - if (existingAppId != null) { | ||
| 125 | - return existingAppId.value(); | ||
| 126 | - } else { | ||
| 127 | - return newAppId; | ||
| 128 | - } | ||
| 129 | - } else { | ||
| 130 | - return existingAppId.value(); | ||
| 131 | - } | ||
| 132 | - }); | ||
| 133 | - idToAppIdCache.putIfAbsent(appId.id(), appId); | ||
| 134 | - return appId; | ||
| 135 | } | 114 | } |
| 136 | 115 | ||
| 137 | - private void primeAppIds() { | 116 | + private void primeIdToAppIdCache() { |
| 138 | - registeredIds.values() | 117 | + registeredIds.asJavaMap() |
| 139 | - .stream() | 118 | + .values() |
| 140 | - .map(Versioned::value) | ||
| 141 | .forEach(appId -> { | 119 | .forEach(appId -> { |
| 142 | - nameToAppIdCache.putIfAbsent(appId.name(), appId); | ||
| 143 | idToAppIdCache.putIfAbsent(appId.id(), appId); | 120 | idToAppIdCache.putIfAbsent(appId.id(), appId); |
| 144 | }); | 121 | }); |
| 145 | } | 122 | } | ... | ... |
| ... | @@ -38,7 +38,7 @@ import static org.slf4j.LoggerFactory.getLogger; | ... | @@ -38,7 +38,7 @@ import static org.slf4j.LoggerFactory.getLogger; |
| 38 | */ | 38 | */ |
| 39 | @Component(immediate = true, enabled = true) | 39 | @Component(immediate = true, enabled = true) |
| 40 | @Service | 40 | @Service |
| 41 | -public class ConsistentIdBlockStore implements IdBlockStore { | 41 | +public class DistributedIdBlockStore implements IdBlockStore { |
| 42 | 42 | ||
| 43 | private final Logger log = getLogger(getClass()); | 43 | private final Logger log = getLogger(getClass()); |
| 44 | private final Map<String, AtomicCounter> topicCounters = Maps.newConcurrentMap(); | 44 | private final Map<String, AtomicCounter> topicCounters = Maps.newConcurrentMap(); | ... | ... |
| ... | @@ -34,7 +34,7 @@ import static org.onosproject.security.AppGuard.checkPermission; | ... | @@ -34,7 +34,7 @@ import static org.onosproject.security.AppGuard.checkPermission; |
| 34 | import static org.onosproject.security.AppPermission.Type.CLOCK_WRITE; | 34 | import static org.onosproject.security.AppPermission.Type.CLOCK_WRITE; |
| 35 | 35 | ||
| 36 | /** | 36 | /** |
| 37 | - * LogicalClockService implementation based on a AtomicCounter. | 37 | + * LogicalClockService implementation based on a {@link AtomicCounter}. |
| 38 | */ | 38 | */ |
| 39 | @Component(immediate = true, enabled = true) | 39 | @Component(immediate = true, enabled = true) |
| 40 | @Service | 40 | @Service | ... | ... |
| ... | @@ -15,6 +15,6 @@ | ... | @@ -15,6 +15,6 @@ |
| 15 | */ | 15 | */ |
| 16 | 16 | ||
| 17 | /** | 17 | /** |
| 18 | - * Implementation of a distributed application ID registry store using Hazelcast. | 18 | + * Implementation of a distributed application registry. |
| 19 | */ | 19 | */ |
| 20 | package org.onosproject.store.core.impl; | 20 | package org.onosproject.store.core.impl; | ... | ... |
| ... | @@ -14,6 +14,6 @@ | ... | @@ -14,6 +14,6 @@ |
| 14 | * limitations under the License. | 14 | * limitations under the License. |
| 15 | */ | 15 | */ |
| 16 | /** | 16 | /** |
| 17 | - * Implementation of the group store. | 17 | + * Implementation of a distributed group store. |
| 18 | */ | 18 | */ |
| 19 | package org.onosproject.store.group.impl; | 19 | package org.onosproject.store.group.impl; | ... | ... |
| ... | @@ -15,6 +15,6 @@ | ... | @@ -15,6 +15,6 @@ |
| 15 | */ | 15 | */ |
| 16 | 16 | ||
| 17 | /** | 17 | /** |
| 18 | - * Implementation of the distributed host store using p2p synchronization protocol. | 18 | + * Implementation of a distributed host store. |
| 19 | */ | 19 | */ |
| 20 | package org.onosproject.store.host.impl; | 20 | package org.onosproject.store.host.impl; | ... | ... |
core/store/dist/src/main/java/org/onosproject/store/link/impl/GossipLinkStore.java
deleted
100644 → 0
This diff is collapsed. Click to expand it.
| 1 | -/* | ||
| 2 | - * Copyright 2014-present Open Networking Laboratory | ||
| 3 | - * | ||
| 4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | - * you may not use this file except in compliance with the License. | ||
| 6 | - * You may obtain a copy of the License at | ||
| 7 | - * | ||
| 8 | - * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | - * | ||
| 10 | - * Unless required by applicable law or agreed to in writing, software | ||
| 11 | - * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | - * See the License for the specific language governing permissions and | ||
| 14 | - * limitations under the License. | ||
| 15 | - */ | ||
| 16 | -package org.onosproject.store.link.impl; | ||
| 17 | - | ||
| 18 | - import org.onosproject.store.cluster.messaging.MessageSubject; | ||
| 19 | - | ||
| 20 | -/** | ||
| 21 | - * MessageSubjects used by GossipLinkStore peer-peer communication. | ||
| 22 | - */ | ||
| 23 | -public final class GossipLinkStoreMessageSubjects { | ||
| 24 | - | ||
| 25 | - private GossipLinkStoreMessageSubjects() {} | ||
| 26 | - | ||
| 27 | - public static final MessageSubject LINK_UPDATE = | ||
| 28 | - new MessageSubject("peer-link-update"); | ||
| 29 | - public static final MessageSubject LINK_REMOVED = | ||
| 30 | - new MessageSubject("peer-link-removed"); | ||
| 31 | - public static final MessageSubject LINK_ANTI_ENTROPY_ADVERTISEMENT = | ||
| 32 | - new MessageSubject("link-enti-entropy-advertisement"); | ||
| 33 | - public static final MessageSubject LINK_INJECTED = | ||
| 34 | - new MessageSubject("peer-link-injected"); | ||
| 35 | -} |
core/store/dist/src/main/java/org/onosproject/store/link/impl/InternalLinkEvent.java
deleted
100644 → 0
| 1 | -/* | ||
| 2 | - * Copyright 2014-present Open Networking Laboratory | ||
| 3 | - * | ||
| 4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | - * you may not use this file except in compliance with the License. | ||
| 6 | - * You may obtain a copy of the License at | ||
| 7 | - * | ||
| 8 | - * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | - * | ||
| 10 | - * Unless required by applicable law or agreed to in writing, software | ||
| 11 | - * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | - * See the License for the specific language governing permissions and | ||
| 14 | - * limitations under the License. | ||
| 15 | - */ | ||
| 16 | -package org.onosproject.store.link.impl; | ||
| 17 | - | ||
| 18 | -import com.google.common.base.MoreObjects; | ||
| 19 | - | ||
| 20 | -import org.onosproject.net.link.LinkDescription; | ||
| 21 | -import org.onosproject.net.provider.ProviderId; | ||
| 22 | -import org.onosproject.store.impl.Timestamped; | ||
| 23 | - | ||
| 24 | -/** | ||
| 25 | - * Information published by GossipDeviceStore to notify peers of a device | ||
| 26 | - * change event. | ||
| 27 | - */ | ||
| 28 | -public class InternalLinkEvent { | ||
| 29 | - | ||
| 30 | - private final ProviderId providerId; | ||
| 31 | - private final Timestamped<LinkDescription> linkDescription; | ||
| 32 | - | ||
| 33 | - protected InternalLinkEvent( | ||
| 34 | - ProviderId providerId, | ||
| 35 | - Timestamped<LinkDescription> linkDescription) { | ||
| 36 | - this.providerId = providerId; | ||
| 37 | - this.linkDescription = linkDescription; | ||
| 38 | - } | ||
| 39 | - | ||
| 40 | - public ProviderId providerId() { | ||
| 41 | - return providerId; | ||
| 42 | - } | ||
| 43 | - | ||
| 44 | - public Timestamped<LinkDescription> linkDescription() { | ||
| 45 | - return linkDescription; | ||
| 46 | - } | ||
| 47 | - | ||
| 48 | - @Override | ||
| 49 | - public String toString() { | ||
| 50 | - return MoreObjects.toStringHelper(getClass()) | ||
| 51 | - .add("providerId", providerId) | ||
| 52 | - .add("linkDescription", linkDescription) | ||
| 53 | - .toString(); | ||
| 54 | - } | ||
| 55 | - | ||
| 56 | - // for serializer | ||
| 57 | - protected InternalLinkEvent() { | ||
| 58 | - this.providerId = null; | ||
| 59 | - this.linkDescription = null; | ||
| 60 | - } | ||
| 61 | -} |
core/store/dist/src/main/java/org/onosproject/store/link/impl/InternalLinkRemovedEvent.java
deleted
100644 → 0
| 1 | -/* | ||
| 2 | - * Copyright 2014-present Open Networking Laboratory | ||
| 3 | - * | ||
| 4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | - * you may not use this file except in compliance with the License. | ||
| 6 | - * You may obtain a copy of the License at | ||
| 7 | - * | ||
| 8 | - * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | - * | ||
| 10 | - * Unless required by applicable law or agreed to in writing, software | ||
| 11 | - * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | - * See the License for the specific language governing permissions and | ||
| 14 | - * limitations under the License. | ||
| 15 | - */ | ||
| 16 | -package org.onosproject.store.link.impl; | ||
| 17 | - | ||
| 18 | -import org.onosproject.net.LinkKey; | ||
| 19 | -import org.onosproject.store.Timestamp; | ||
| 20 | - | ||
| 21 | -import com.google.common.base.MoreObjects; | ||
| 22 | - | ||
| 23 | -/** | ||
| 24 | - * Information published by GossipLinkStore to notify peers of a link | ||
| 25 | - * being removed. | ||
| 26 | - */ | ||
| 27 | -public class InternalLinkRemovedEvent { | ||
| 28 | - | ||
| 29 | - private final LinkKey linkKey; | ||
| 30 | - private final Timestamp timestamp; | ||
| 31 | - | ||
| 32 | - /** | ||
| 33 | - * Creates a InternalLinkRemovedEvent. | ||
| 34 | - * @param linkKey identifier of the removed link. | ||
| 35 | - * @param timestamp timestamp of when the link was removed. | ||
| 36 | - */ | ||
| 37 | - public InternalLinkRemovedEvent(LinkKey linkKey, Timestamp timestamp) { | ||
| 38 | - this.linkKey = linkKey; | ||
| 39 | - this.timestamp = timestamp; | ||
| 40 | - } | ||
| 41 | - | ||
| 42 | - public LinkKey linkKey() { | ||
| 43 | - return linkKey; | ||
| 44 | - } | ||
| 45 | - | ||
| 46 | - public Timestamp timestamp() { | ||
| 47 | - return timestamp; | ||
| 48 | - } | ||
| 49 | - | ||
| 50 | - @Override | ||
| 51 | - public String toString() { | ||
| 52 | - return MoreObjects.toStringHelper(getClass()) | ||
| 53 | - .add("linkKey", linkKey) | ||
| 54 | - .add("timestamp", timestamp) | ||
| 55 | - .toString(); | ||
| 56 | - } | ||
| 57 | - | ||
| 58 | - // for serializer | ||
| 59 | - @SuppressWarnings("unused") | ||
| 60 | - private InternalLinkRemovedEvent() { | ||
| 61 | - linkKey = null; | ||
| 62 | - timestamp = null; | ||
| 63 | - } | ||
| 64 | -} |
| 1 | -/* | ||
| 2 | - * Copyright 2014-present Open Networking Laboratory | ||
| 3 | - * | ||
| 4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | - * you may not use this file except in compliance with the License. | ||
| 6 | - * You may obtain a copy of the License at | ||
| 7 | - * | ||
| 8 | - * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | - * | ||
| 10 | - * Unless required by applicable law or agreed to in writing, software | ||
| 11 | - * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | - * See the License for the specific language governing permissions and | ||
| 14 | - * limitations under the License. | ||
| 15 | - */ | ||
| 16 | -package org.onosproject.store.link.impl; | ||
| 17 | - | ||
| 18 | -import static com.google.common.base.Preconditions.checkNotNull; | ||
| 19 | - | ||
| 20 | -import java.util.Map; | ||
| 21 | - | ||
| 22 | -import org.onosproject.cluster.NodeId; | ||
| 23 | -import org.onosproject.net.LinkKey; | ||
| 24 | -import org.onosproject.store.Timestamp; | ||
| 25 | - | ||
| 26 | -/** | ||
| 27 | - * Link AE Advertisement message. | ||
| 28 | - */ | ||
| 29 | -public class LinkAntiEntropyAdvertisement { | ||
| 30 | - | ||
| 31 | - private final NodeId sender; | ||
| 32 | - private final Map<LinkFragmentId, Timestamp> linkTimestamps; | ||
| 33 | - private final Map<LinkKey, Timestamp> linkTombstones; | ||
| 34 | - | ||
| 35 | - | ||
| 36 | - public LinkAntiEntropyAdvertisement(NodeId sender, | ||
| 37 | - Map<LinkFragmentId, Timestamp> linkTimestamps, | ||
| 38 | - Map<LinkKey, Timestamp> linkTombstones) { | ||
| 39 | - this.sender = checkNotNull(sender); | ||
| 40 | - this.linkTimestamps = checkNotNull(linkTimestamps); | ||
| 41 | - this.linkTombstones = checkNotNull(linkTombstones); | ||
| 42 | - } | ||
| 43 | - | ||
| 44 | - public NodeId sender() { | ||
| 45 | - return sender; | ||
| 46 | - } | ||
| 47 | - | ||
| 48 | - public Map<LinkFragmentId, Timestamp> linkTimestamps() { | ||
| 49 | - return linkTimestamps; | ||
| 50 | - } | ||
| 51 | - | ||
| 52 | - public Map<LinkKey, Timestamp> linkTombstones() { | ||
| 53 | - return linkTombstones; | ||
| 54 | - } | ||
| 55 | - | ||
| 56 | - // For serializer | ||
| 57 | - @SuppressWarnings("unused") | ||
| 58 | - private LinkAntiEntropyAdvertisement() { | ||
| 59 | - this.sender = null; | ||
| 60 | - this.linkTimestamps = null; | ||
| 61 | - this.linkTombstones = null; | ||
| 62 | - } | ||
| 63 | -} |
core/store/dist/src/main/java/org/onosproject/store/link/impl/LinkFragmentId.java
deleted
100644 → 0
| 1 | -/* | ||
| 2 | - * Copyright 2014-present Open Networking Laboratory | ||
| 3 | - * | ||
| 4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | - * you may not use this file except in compliance with the License. | ||
| 6 | - * You may obtain a copy of the License at | ||
| 7 | - * | ||
| 8 | - * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | - * | ||
| 10 | - * Unless required by applicable law or agreed to in writing, software | ||
| 11 | - * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | - * See the License for the specific language governing permissions and | ||
| 14 | - * limitations under the License. | ||
| 15 | - */ | ||
| 16 | -package org.onosproject.store.link.impl; | ||
| 17 | - | ||
| 18 | -import java.util.Objects; | ||
| 19 | - | ||
| 20 | -import org.onosproject.net.LinkKey; | ||
| 21 | -import org.onosproject.net.provider.ProviderId; | ||
| 22 | - | ||
| 23 | -import com.google.common.base.MoreObjects; | ||
| 24 | - | ||
| 25 | -/** | ||
| 26 | - * Identifier for LinkDescription from a Provider. | ||
| 27 | - */ | ||
| 28 | -public final class LinkFragmentId { | ||
| 29 | - public final ProviderId providerId; | ||
| 30 | - public final LinkKey linkKey; | ||
| 31 | - | ||
| 32 | - public LinkFragmentId(LinkKey linkKey, ProviderId providerId) { | ||
| 33 | - this.providerId = providerId; | ||
| 34 | - this.linkKey = linkKey; | ||
| 35 | - } | ||
| 36 | - | ||
| 37 | - public LinkKey linkKey() { | ||
| 38 | - return linkKey; | ||
| 39 | - } | ||
| 40 | - | ||
| 41 | - public ProviderId providerId() { | ||
| 42 | - return providerId; | ||
| 43 | - } | ||
| 44 | - | ||
| 45 | - @Override | ||
| 46 | - public int hashCode() { | ||
| 47 | - return Objects.hash(providerId, linkKey); | ||
| 48 | - } | ||
| 49 | - | ||
| 50 | - @Override | ||
| 51 | - public boolean equals(Object obj) { | ||
| 52 | - if (this == obj) { | ||
| 53 | - return true; | ||
| 54 | - } | ||
| 55 | - if (!(obj instanceof LinkFragmentId)) { | ||
| 56 | - return false; | ||
| 57 | - } | ||
| 58 | - LinkFragmentId that = (LinkFragmentId) obj; | ||
| 59 | - return Objects.equals(this.linkKey, that.linkKey) && | ||
| 60 | - Objects.equals(this.providerId, that.providerId); | ||
| 61 | - } | ||
| 62 | - | ||
| 63 | - @Override | ||
| 64 | - public String toString() { | ||
| 65 | - return MoreObjects.toStringHelper(getClass()) | ||
| 66 | - .add("providerId", providerId) | ||
| 67 | - .add("linkKey", linkKey) | ||
| 68 | - .toString(); | ||
| 69 | - } | ||
| 70 | - | ||
| 71 | - // for serializer | ||
| 72 | - @SuppressWarnings("unused") | ||
| 73 | - private LinkFragmentId() { | ||
| 74 | - this.providerId = null; | ||
| 75 | - this.linkKey = null; | ||
| 76 | - } | ||
| 77 | -} |
core/store/dist/src/main/java/org/onosproject/store/link/impl/LinkInjectedEvent.java
deleted
100644 → 0
| 1 | -/* | ||
| 2 | - * Copyright 2015-present Open Networking Laboratory | ||
| 3 | - * | ||
| 4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | - * you may not use this file except in compliance with the License. | ||
| 6 | - * You may obtain a copy of the License at | ||
| 7 | - * | ||
| 8 | - * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | - * | ||
| 10 | - * Unless required by applicable law or agreed to in writing, software | ||
| 11 | - * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | - * See the License for the specific language governing permissions and | ||
| 14 | - * limitations under the License. | ||
| 15 | - */ | ||
| 16 | -package org.onosproject.store.link.impl; | ||
| 17 | - | ||
| 18 | -import com.google.common.base.MoreObjects; | ||
| 19 | -import org.onosproject.net.link.LinkDescription; | ||
| 20 | -import org.onosproject.net.provider.ProviderId; | ||
| 21 | - | ||
| 22 | -public class LinkInjectedEvent { | ||
| 23 | - | ||
| 24 | - ProviderId providerId; | ||
| 25 | - LinkDescription linkDescription; | ||
| 26 | - | ||
| 27 | - public LinkInjectedEvent(ProviderId providerId, LinkDescription linkDescription) { | ||
| 28 | - this.providerId = providerId; | ||
| 29 | - this.linkDescription = linkDescription; | ||
| 30 | - } | ||
| 31 | - | ||
| 32 | - public ProviderId providerId() { | ||
| 33 | - return providerId; | ||
| 34 | - } | ||
| 35 | - | ||
| 36 | - public LinkDescription linkDescription() { | ||
| 37 | - return linkDescription; | ||
| 38 | - } | ||
| 39 | - | ||
| 40 | - @Override | ||
| 41 | - public String toString() { | ||
| 42 | - return MoreObjects.toStringHelper(getClass()) | ||
| 43 | - .add("providerId", providerId) | ||
| 44 | - .add("linkDescription", linkDescription) | ||
| 45 | - .toString(); | ||
| 46 | - } | ||
| 47 | - | ||
| 48 | - // for serializer | ||
| 49 | - protected LinkInjectedEvent() { | ||
| 50 | - this.providerId = null; | ||
| 51 | - this.linkDescription = null; | ||
| 52 | - } | ||
| 53 | -} |
| ... | @@ -15,6 +15,6 @@ | ... | @@ -15,6 +15,6 @@ |
| 15 | */ | 15 | */ |
| 16 | 16 | ||
| 17 | /** | 17 | /** |
| 18 | - * Implementation of distributed link store using p2p synchronization protocol. | 18 | + * Implementation of distributed link store using eventually consistent map primitive. |
| 19 | */ | 19 | */ |
| 20 | package org.onosproject.store.link.impl; | 20 | package org.onosproject.store.link.impl; | ... | ... |
core/store/dist/src/main/java/org/onosproject/store/mastership/impl/RoleValue.java
deleted
100644 → 0
| 1 | -/* | ||
| 2 | - * Copyright 2014-present Open Networking Laboratory | ||
| 3 | - * | ||
| 4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | - * you may not use this file except in compliance with the License. | ||
| 6 | - * You may obtain a copy of the License at | ||
| 7 | - * | ||
| 8 | - * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | - * | ||
| 10 | - * Unless required by applicable law or agreed to in writing, software | ||
| 11 | - * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | - * See the License for the specific language governing permissions and | ||
| 14 | - * limitations under the License. | ||
| 15 | - */ | ||
| 16 | -package org.onosproject.store.mastership.impl; | ||
| 17 | - | ||
| 18 | -import static org.onosproject.net.MastershipRole.MASTER; | ||
| 19 | -import static org.onosproject.net.MastershipRole.NONE; | ||
| 20 | -import static org.onosproject.net.MastershipRole.STANDBY; | ||
| 21 | - | ||
| 22 | -import java.util.Collections; | ||
| 23 | -import java.util.EnumMap; | ||
| 24 | -import java.util.LinkedList; | ||
| 25 | -import java.util.List; | ||
| 26 | -import java.util.Map; | ||
| 27 | - | ||
| 28 | -import org.onosproject.cluster.NodeId; | ||
| 29 | -import org.onosproject.cluster.RoleInfo; | ||
| 30 | -import org.onosproject.net.MastershipRole; | ||
| 31 | - | ||
| 32 | -import com.google.common.base.MoreObjects; | ||
| 33 | -import com.google.common.base.MoreObjects.ToStringHelper; | ||
| 34 | -import com.google.common.collect.Lists; | ||
| 35 | - | ||
| 36 | -/** | ||
| 37 | - * A structure that holds node mastership roles associated with a | ||
| 38 | - * {@link org.onosproject.net.DeviceId}. This structure needs to be locked through IMap. | ||
| 39 | - */ | ||
| 40 | -final class RoleValue { | ||
| 41 | - | ||
| 42 | - protected final Map<MastershipRole, List<NodeId>> value = new EnumMap<>(MastershipRole.class); | ||
| 43 | - | ||
| 44 | - /** | ||
| 45 | - * Constructs empty RoleValue. | ||
| 46 | - */ | ||
| 47 | - public RoleValue() { | ||
| 48 | - value.put(MastershipRole.MASTER, new LinkedList<>()); | ||
| 49 | - value.put(MastershipRole.STANDBY, new LinkedList<>()); | ||
| 50 | - value.put(MastershipRole.NONE, new LinkedList<>()); | ||
| 51 | - } | ||
| 52 | - | ||
| 53 | - /** | ||
| 54 | - * Constructs copy of specified RoleValue. | ||
| 55 | - * | ||
| 56 | - * @param original original to create copy from | ||
| 57 | - */ | ||
| 58 | - public RoleValue(final RoleValue original) { | ||
| 59 | - value.put(MASTER, Lists.newLinkedList(original.value.get(MASTER))); | ||
| 60 | - value.put(STANDBY, Lists.newLinkedList(original.value.get(STANDBY))); | ||
| 61 | - value.put(NONE, Lists.newLinkedList(original.value.get(NONE))); | ||
| 62 | - } | ||
| 63 | - | ||
| 64 | - // exposing internals for serialization purpose only | ||
| 65 | - Map<MastershipRole, List<NodeId>> value() { | ||
| 66 | - return Collections.unmodifiableMap(value); | ||
| 67 | - } | ||
| 68 | - | ||
| 69 | - public List<NodeId> nodesOfRole(MastershipRole type) { | ||
| 70 | - return value.get(type); | ||
| 71 | - } | ||
| 72 | - | ||
| 73 | - /** | ||
| 74 | - * Returns the first node to match the MastershipRole, or if there | ||
| 75 | - * are none, null. | ||
| 76 | - * | ||
| 77 | - * @param type the role | ||
| 78 | - * @return a node ID or null | ||
| 79 | - */ | ||
| 80 | - public NodeId get(MastershipRole type) { | ||
| 81 | - return value.get(type).isEmpty() ? null : value.get(type).get(0); | ||
| 82 | - } | ||
| 83 | - | ||
| 84 | - public boolean contains(MastershipRole type, NodeId nodeId) { | ||
| 85 | - return value.get(type).contains(nodeId); | ||
| 86 | - } | ||
| 87 | - | ||
| 88 | - public MastershipRole getRole(NodeId nodeId) { | ||
| 89 | - if (contains(MASTER, nodeId)) { | ||
| 90 | - return MASTER; | ||
| 91 | - } | ||
| 92 | - if (contains(STANDBY, nodeId)) { | ||
| 93 | - return STANDBY; | ||
| 94 | - } | ||
| 95 | - return NONE; | ||
| 96 | - } | ||
| 97 | - | ||
| 98 | - /** | ||
| 99 | - * Associates a node to a certain role. | ||
| 100 | - * | ||
| 101 | - * @param type the role | ||
| 102 | - * @param nodeId the node ID of the node to associate | ||
| 103 | - * @return true if modified | ||
| 104 | - */ | ||
| 105 | - public boolean add(MastershipRole type, NodeId nodeId) { | ||
| 106 | - List<NodeId> nodes = value.get(type); | ||
| 107 | - | ||
| 108 | - if (!nodes.contains(nodeId)) { | ||
| 109 | - return nodes.add(nodeId); | ||
| 110 | - } | ||
| 111 | - return false; | ||
| 112 | - } | ||
| 113 | - | ||
| 114 | - /** | ||
| 115 | - * Removes a node from a certain role. | ||
| 116 | - * | ||
| 117 | - * @param type the role | ||
| 118 | - * @param nodeId the ID of the node to remove | ||
| 119 | - * @return true if modified | ||
| 120 | - */ | ||
| 121 | - public boolean remove(MastershipRole type, NodeId nodeId) { | ||
| 122 | - List<NodeId> nodes = value.get(type); | ||
| 123 | - if (!nodes.isEmpty()) { | ||
| 124 | - return nodes.remove(nodeId); | ||
| 125 | - } else { | ||
| 126 | - return false; | ||
| 127 | - } | ||
| 128 | - } | ||
| 129 | - | ||
| 130 | - /** | ||
| 131 | - * Reassigns a node from one role to another. If the node was not of the | ||
| 132 | - * old role, it will still be assigned the new role. | ||
| 133 | - * | ||
| 134 | - * @param nodeId the Node ID of node changing roles | ||
| 135 | - * @param from the old role | ||
| 136 | - * @param to the new role | ||
| 137 | - * @return true if modified | ||
| 138 | - */ | ||
| 139 | - public boolean reassign(NodeId nodeId, MastershipRole from, MastershipRole to) { | ||
| 140 | - boolean modified = remove(from, nodeId); | ||
| 141 | - modified |= add(to, nodeId); | ||
| 142 | - return modified; | ||
| 143 | - } | ||
| 144 | - | ||
| 145 | - /** | ||
| 146 | - * Replaces a node in one role with another node. Even if there is no node to | ||
| 147 | - * replace, the new node is associated to the role. | ||
| 148 | - * | ||
| 149 | - * @param from the old NodeId to replace | ||
| 150 | - * @param to the new NodeId | ||
| 151 | - * @param type the role associated with the old NodeId | ||
| 152 | - * @return true if modified | ||
| 153 | - */ | ||
| 154 | - public boolean replace(NodeId from, NodeId to, MastershipRole type) { | ||
| 155 | - boolean modified = remove(type, from); | ||
| 156 | - modified |= add(type, to); | ||
| 157 | - return modified; | ||
| 158 | - } | ||
| 159 | - | ||
| 160 | - /** | ||
| 161 | - * Summarizes this RoleValue as a RoleInfo. Note that master and/or backups | ||
| 162 | - * may be empty, so the values should be checked for safety. | ||
| 163 | - * | ||
| 164 | - * @return the RoleInfo. | ||
| 165 | - */ | ||
| 166 | - public RoleInfo roleInfo() { | ||
| 167 | - return new RoleInfo( | ||
| 168 | - get(MastershipRole.MASTER), nodesOfRole(MastershipRole.STANDBY)); | ||
| 169 | - } | ||
| 170 | - | ||
| 171 | - @Override | ||
| 172 | - public String toString() { | ||
| 173 | - ToStringHelper helper = MoreObjects.toStringHelper(this.getClass()); | ||
| 174 | - for (Map.Entry<MastershipRole, List<NodeId>> el : value.entrySet()) { | ||
| 175 | - helper.add(el.getKey().toString(), el.getValue()); | ||
| 176 | - } | ||
| 177 | - return helper.toString(); | ||
| 178 | - } | ||
| 179 | -} |
core/store/dist/src/main/java/org/onosproject/store/mastership/impl/RoleValueSerializer.java
deleted
100644 → 0
| 1 | -/* | ||
| 2 | - * Copyright 2014-present Open Networking Laboratory | ||
| 3 | - * | ||
| 4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | - * you may not use this file except in compliance with the License. | ||
| 6 | - * You may obtain a copy of the License at | ||
| 7 | - * | ||
| 8 | - * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | - * | ||
| 10 | - * Unless required by applicable law or agreed to in writing, software | ||
| 11 | - * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | - * See the License for the specific language governing permissions and | ||
| 14 | - * limitations under the License. | ||
| 15 | - */ | ||
| 16 | -package org.onosproject.store.mastership.impl; | ||
| 17 | - | ||
| 18 | -import java.util.List; | ||
| 19 | -import java.util.Map; | ||
| 20 | - | ||
| 21 | -import org.onosproject.cluster.NodeId; | ||
| 22 | -import org.onosproject.net.MastershipRole; | ||
| 23 | - | ||
| 24 | -import com.esotericsoftware.kryo.Kryo; | ||
| 25 | -import com.esotericsoftware.kryo.Serializer; | ||
| 26 | -import com.esotericsoftware.kryo.io.Input; | ||
| 27 | -import com.esotericsoftware.kryo.io.Output; | ||
| 28 | - | ||
| 29 | -/** | ||
| 30 | - * Serializer for RoleValues used by {@link org.onosproject.mastership.MastershipStore}. | ||
| 31 | - */ | ||
| 32 | -public class RoleValueSerializer extends Serializer<RoleValue> { | ||
| 33 | - | ||
| 34 | - //RoleValues are assumed to hold a Map of MastershipRoles (an enum) | ||
| 35 | - //to a List of NodeIds. | ||
| 36 | - | ||
| 37 | - @Override | ||
| 38 | - public RoleValue read(Kryo kryo, Input input, Class<RoleValue> type) { | ||
| 39 | - RoleValue rv = new RoleValue(); | ||
| 40 | - int size = input.readInt(); | ||
| 41 | - for (int i = 0; i < size; i++) { | ||
| 42 | - MastershipRole role = MastershipRole.values()[input.readInt()]; | ||
| 43 | - int s = input.readInt(); | ||
| 44 | - for (int j = 0; j < s; j++) { | ||
| 45 | - rv.add(role, new NodeId(input.readString())); | ||
| 46 | - } | ||
| 47 | - } | ||
| 48 | - return rv; | ||
| 49 | - } | ||
| 50 | - | ||
| 51 | - @Override | ||
| 52 | - public void write(Kryo kryo, Output output, RoleValue type) { | ||
| 53 | - final Map<MastershipRole, List<NodeId>> map = type.value(); | ||
| 54 | - output.writeInt(map.size()); | ||
| 55 | - | ||
| 56 | - for (Map.Entry<MastershipRole, List<NodeId>> el : map.entrySet()) { | ||
| 57 | - output.writeInt(el.getKey().ordinal()); | ||
| 58 | - | ||
| 59 | - List<NodeId> nodes = el.getValue(); | ||
| 60 | - output.writeInt(nodes.size()); | ||
| 61 | - for (NodeId n : nodes) { | ||
| 62 | - output.writeString(n.toString()); | ||
| 63 | - } | ||
| 64 | - } | ||
| 65 | - } | ||
| 66 | - | ||
| 67 | -} |
| ... | @@ -15,6 +15,6 @@ | ... | @@ -15,6 +15,6 @@ |
| 15 | */ | 15 | */ |
| 16 | 16 | ||
| 17 | /** | 17 | /** |
| 18 | - * Implementation of a distributed mastership store using Hazelcast. | 18 | + * Implementation of a distributed mastership store. |
| 19 | */ | 19 | */ |
| 20 | package org.onosproject.store.mastership.impl; | 20 | package org.onosproject.store.mastership.impl; | ... | ... |
| 1 | -/* | ||
| 2 | - * Copyright 2015-present Open Networking Laboratory | ||
| 3 | - * | ||
| 4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | - * you may not use this file except in compliance with the License. | ||
| 6 | - * You may obtain a copy of the License at | ||
| 7 | - * | ||
| 8 | - * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | - * | ||
| 10 | - * Unless required by applicable law or agreed to in writing, software | ||
| 11 | - * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | - * See the License for the specific language governing permissions and | ||
| 14 | - * limitations under the License. | ||
| 15 | - */ | ||
| 16 | -package org.onosproject.store.serializers.custom; | ||
| 17 | - | ||
| 18 | -import org.onosproject.cluster.NodeId; | ||
| 19 | -import org.onosproject.store.cluster.messaging.ClusterMessage; | ||
| 20 | -import org.onosproject.store.cluster.messaging.MessageSubject; | ||
| 21 | -import com.esotericsoftware.kryo.Kryo; | ||
| 22 | -import com.esotericsoftware.kryo.Serializer; | ||
| 23 | -import com.esotericsoftware.kryo.io.Input; | ||
| 24 | -import com.esotericsoftware.kryo.io.Output; | ||
| 25 | - | ||
| 26 | -public final class ClusterMessageSerializer extends Serializer<ClusterMessage> { | ||
| 27 | - | ||
| 28 | - /** | ||
| 29 | - * Creates a serializer for {@link ClusterMessage}. | ||
| 30 | - */ | ||
| 31 | - public ClusterMessageSerializer() { | ||
| 32 | - // does not accept null | ||
| 33 | - super(false); | ||
| 34 | - } | ||
| 35 | - | ||
| 36 | - @Override | ||
| 37 | - public void write(Kryo kryo, Output output, ClusterMessage message) { | ||
| 38 | - kryo.writeClassAndObject(output, message.sender()); | ||
| 39 | - kryo.writeClassAndObject(output, message.subject()); | ||
| 40 | - output.writeInt(message.payload().length); | ||
| 41 | - output.writeBytes(message.payload()); | ||
| 42 | - } | ||
| 43 | - | ||
| 44 | - @Override | ||
| 45 | - public ClusterMessage read(Kryo kryo, Input input, | ||
| 46 | - Class<ClusterMessage> type) { | ||
| 47 | - NodeId sender = (NodeId) kryo.readClassAndObject(input); | ||
| 48 | - MessageSubject subject = (MessageSubject) kryo.readClassAndObject(input); | ||
| 49 | - int payloadSize = input.readInt(); | ||
| 50 | - byte[] payload = input.readBytes(payloadSize); | ||
| 51 | - return new ClusterMessage(sender, subject, payload); | ||
| 52 | - } | ||
| 53 | -} |
| 1 | -/* | ||
| 2 | - * Copyright 2015-present Open Networking Laboratory | ||
| 3 | - * | ||
| 4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | - * you may not use this file except in compliance with the License. | ||
| 6 | - * You may obtain a copy of the License at | ||
| 7 | - * | ||
| 8 | - * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | - * | ||
| 10 | - * Unless required by applicable law or agreed to in writing, software | ||
| 11 | - * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | - * See the License for the specific language governing permissions and | ||
| 14 | - * limitations under the License. | ||
| 15 | - */ | ||
| 16 | -package org.onosproject.store.serializers.custom; | ||
| 17 | - | ||
| 18 | -import org.onosproject.store.cluster.messaging.MessageSubject; | ||
| 19 | - | ||
| 20 | -import com.esotericsoftware.kryo.Kryo; | ||
| 21 | -import com.esotericsoftware.kryo.Serializer; | ||
| 22 | -import com.esotericsoftware.kryo.io.Input; | ||
| 23 | -import com.esotericsoftware.kryo.io.Output; | ||
| 24 | - | ||
| 25 | -public final class MessageSubjectSerializer extends Serializer<MessageSubject> { | ||
| 26 | - | ||
| 27 | - /** | ||
| 28 | - * Creates a serializer for {@link MessageSubject}. | ||
| 29 | - */ | ||
| 30 | - public MessageSubjectSerializer() { | ||
| 31 | - // non-null, immutable | ||
| 32 | - super(false, true); | ||
| 33 | - } | ||
| 34 | - | ||
| 35 | - | ||
| 36 | - @Override | ||
| 37 | - public void write(Kryo kryo, Output output, MessageSubject object) { | ||
| 38 | - output.writeString(object.value()); | ||
| 39 | - } | ||
| 40 | - | ||
| 41 | - @Override | ||
| 42 | - public MessageSubject read(Kryo kryo, Input input, | ||
| 43 | - Class<MessageSubject> type) { | ||
| 44 | - return new MessageSubject(input.readString()); | ||
| 45 | - } | ||
| 46 | -} |
| ... | @@ -15,8 +15,6 @@ | ... | @@ -15,8 +15,6 @@ |
| 15 | */ | 15 | */ |
| 16 | 16 | ||
| 17 | /** | 17 | /** |
| 18 | - * Cluster messaging and distributed store serializers. | 18 | + * Distributed store serializers. |
| 19 | */ | 19 | */ |
| 20 | -//FIXME what is the right name for this package? | ||
| 21 | -//FIXME can this be moved to onos-core-serializers? | ||
| 22 | package org.onosproject.store.serializers.custom; | 20 | package org.onosproject.store.serializers.custom; | ... | ... |
| ... | @@ -17,6 +17,7 @@ | ... | @@ -17,6 +17,7 @@ |
| 17 | package org.onosproject.store.statistic.impl; | 17 | package org.onosproject.store.statistic.impl; |
| 18 | 18 | ||
| 19 | import com.google.common.base.Objects; | 19 | import com.google.common.base.Objects; |
| 20 | + | ||
| 20 | import org.apache.felix.scr.annotations.Activate; | 21 | import org.apache.felix.scr.annotations.Activate; |
| 21 | import org.apache.felix.scr.annotations.Component; | 22 | import org.apache.felix.scr.annotations.Component; |
| 22 | import org.apache.felix.scr.annotations.Deactivate; | 23 | import org.apache.felix.scr.annotations.Deactivate; |
| ... | @@ -38,6 +39,7 @@ import org.onosproject.net.flow.instructions.Instruction; | ... | @@ -38,6 +39,7 @@ import org.onosproject.net.flow.instructions.Instruction; |
| 38 | import org.onosproject.net.flow.instructions.Instructions; | 39 | import org.onosproject.net.flow.instructions.Instructions; |
| 39 | import org.onosproject.net.statistic.FlowStatisticStore; | 40 | import org.onosproject.net.statistic.FlowStatisticStore; |
| 40 | import org.onosproject.store.cluster.messaging.ClusterCommunicationService; | 41 | import org.onosproject.store.cluster.messaging.ClusterCommunicationService; |
| 42 | +import org.onosproject.store.cluster.messaging.MessageSubject; | ||
| 41 | import org.onosproject.store.serializers.KryoNamespaces; | 43 | import org.onosproject.store.serializers.KryoNamespaces; |
| 42 | import org.onosproject.store.serializers.StoreSerializer; | 44 | import org.onosproject.store.serializers.StoreSerializer; |
| 43 | import org.osgi.service.component.ComponentContext; | 45 | import org.osgi.service.component.ComponentContext; |
| ... | @@ -59,8 +61,6 @@ import static com.google.common.base.Preconditions.checkArgument; | ... | @@ -59,8 +61,6 @@ import static com.google.common.base.Preconditions.checkArgument; |
| 59 | import static com.google.common.base.Strings.isNullOrEmpty; | 61 | import static com.google.common.base.Strings.isNullOrEmpty; |
| 60 | import static org.onlab.util.Tools.get; | 62 | import static org.onlab.util.Tools.get; |
| 61 | import static org.onlab.util.Tools.groupedThreads; | 63 | import static org.onlab.util.Tools.groupedThreads; |
| 62 | -import static org.onosproject.store.statistic.impl.StatisticStoreMessageSubjects.GET_CURRENT; | ||
| 63 | -import static org.onosproject.store.statistic.impl.StatisticStoreMessageSubjects.GET_PREVIOUS; | ||
| 64 | import static org.slf4j.LoggerFactory.getLogger; | 64 | import static org.slf4j.LoggerFactory.getLogger; |
| 65 | 65 | ||
| 66 | /** | 66 | /** |
| ... | @@ -89,6 +89,9 @@ public class DistributedFlowStatisticStore implements FlowStatisticStore { | ... | @@ -89,6 +89,9 @@ public class DistributedFlowStatisticStore implements FlowStatisticStore { |
| 89 | private Map<ConnectPoint, Set<FlowEntry>> current = | 89 | private Map<ConnectPoint, Set<FlowEntry>> current = |
| 90 | new ConcurrentHashMap<>(); | 90 | new ConcurrentHashMap<>(); |
| 91 | 91 | ||
| 92 | + public static final MessageSubject GET_CURRENT = new MessageSubject("peer-return-current"); | ||
| 93 | + public static final MessageSubject GET_PREVIOUS = new MessageSubject("peer-return-previous"); | ||
| 94 | + | ||
| 92 | protected static final StoreSerializer SERIALIZER = StoreSerializer.using(KryoNamespaces.API); | 95 | protected static final StoreSerializer SERIALIZER = StoreSerializer.using(KryoNamespaces.API); |
| 93 | 96 | ||
| 94 | private NodeId local; | 97 | private NodeId local; | ... | ... |
| ... | @@ -38,6 +38,7 @@ import org.onosproject.net.flow.instructions.Instruction; | ... | @@ -38,6 +38,7 @@ import org.onosproject.net.flow.instructions.Instruction; |
| 38 | import org.onosproject.net.flow.instructions.Instructions; | 38 | import org.onosproject.net.flow.instructions.Instructions; |
| 39 | import org.onosproject.net.statistic.StatisticStore; | 39 | import org.onosproject.net.statistic.StatisticStore; |
| 40 | import org.onosproject.store.cluster.messaging.ClusterCommunicationService; | 40 | import org.onosproject.store.cluster.messaging.ClusterCommunicationService; |
| 41 | +import org.onosproject.store.cluster.messaging.MessageSubject; | ||
| 41 | import org.onosproject.store.serializers.KryoNamespaces; | 42 | import org.onosproject.store.serializers.KryoNamespaces; |
| 42 | import org.onosproject.store.serializers.StoreSerializer; | 43 | import org.onosproject.store.serializers.StoreSerializer; |
| 43 | import org.osgi.service.component.ComponentContext; | 44 | import org.osgi.service.component.ComponentContext; |
| ... | @@ -59,8 +60,6 @@ import static com.google.common.base.Preconditions.checkArgument; | ... | @@ -59,8 +60,6 @@ import static com.google.common.base.Preconditions.checkArgument; |
| 59 | import static com.google.common.base.Strings.isNullOrEmpty; | 60 | import static com.google.common.base.Strings.isNullOrEmpty; |
| 60 | import static org.onlab.util.Tools.get; | 61 | import static org.onlab.util.Tools.get; |
| 61 | import static org.onlab.util.Tools.groupedThreads; | 62 | import static org.onlab.util.Tools.groupedThreads; |
| 62 | -import static org.onosproject.store.statistic.impl.StatisticStoreMessageSubjects.GET_CURRENT; | ||
| 63 | -import static org.onosproject.store.statistic.impl.StatisticStoreMessageSubjects.GET_PREVIOUS; | ||
| 64 | import static org.slf4j.LoggerFactory.getLogger; | 63 | import static org.slf4j.LoggerFactory.getLogger; |
| 65 | 64 | ||
| 66 | 65 | ||
| ... | @@ -85,6 +84,9 @@ public class DistributedStatisticStore implements StatisticStore { | ... | @@ -85,6 +84,9 @@ public class DistributedStatisticStore implements StatisticStore { |
| 85 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 84 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 86 | protected ClusterService clusterService; | 85 | protected ClusterService clusterService; |
| 87 | 86 | ||
| 87 | + public static final MessageSubject GET_CURRENT = new MessageSubject("peer-return-current"); | ||
| 88 | + public static final MessageSubject GET_PREVIOUS = new MessageSubject("peer-return-previous"); | ||
| 89 | + | ||
| 88 | private Map<ConnectPoint, InternalStatisticRepresentation> representations = | 90 | private Map<ConnectPoint, InternalStatisticRepresentation> representations = |
| 89 | new ConcurrentHashMap<>(); | 91 | new ConcurrentHashMap<>(); |
| 90 | 92 | ... | ... |
| 1 | -/* | ||
| 2 | - * Copyright 2014-present Open Networking Laboratory | ||
| 3 | - * | ||
| 4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | - * you may not use this file except in compliance with the License. | ||
| 6 | - * You may obtain a copy of the License at | ||
| 7 | - * | ||
| 8 | - * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | - * | ||
| 10 | - * Unless required by applicable law or agreed to in writing, software | ||
| 11 | - * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | - * See the License for the specific language governing permissions and | ||
| 14 | - * limitations under the License. | ||
| 15 | - */ | ||
| 16 | -package org.onosproject.store.statistic.impl; | ||
| 17 | - | ||
| 18 | -import org.onosproject.store.cluster.messaging.MessageSubject; | ||
| 19 | - | ||
| 20 | -/** | ||
| 21 | - * MessageSubjects used by DistributedStatisticStore peer-peer communication. | ||
| 22 | - */ | ||
| 23 | -public final class StatisticStoreMessageSubjects { | ||
| 24 | - private StatisticStoreMessageSubjects() {} | ||
| 25 | - public static final MessageSubject GET_CURRENT = | ||
| 26 | - new MessageSubject("peer-return-current"); | ||
| 27 | - public static final MessageSubject GET_PREVIOUS = | ||
| 28 | - new MessageSubject("peer-return-previous"); | ||
| 29 | - | ||
| 30 | -} |
| 1 | -/* | ||
| 2 | - * Copyright 2014-present Open Networking Laboratory | ||
| 3 | - * | ||
| 4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | - * you may not use this file except in compliance with the License. | ||
| 6 | - * You may obtain a copy of the License at | ||
| 7 | - * | ||
| 8 | - * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | - * | ||
| 10 | - * Unless required by applicable law or agreed to in writing, software | ||
| 11 | - * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | - * See the License for the specific language governing permissions and | ||
| 14 | - * limitations under the License. | ||
| 15 | - */ | ||
| 16 | -package org.onosproject.store.cluster.messaging.impl; | ||
| 17 | - | ||
| 18 | -import org.junit.After; | ||
| 19 | -import org.junit.Before; | ||
| 20 | -import org.junit.Ignore; | ||
| 21 | -import org.junit.Test; | ||
| 22 | -import org.onosproject.cluster.DefaultControllerNode; | ||
| 23 | -import org.onosproject.cluster.NodeId; | ||
| 24 | -import org.onosproject.store.cluster.impl.ClusterNodesDelegate; | ||
| 25 | -import org.onlab.packet.IpAddress; | ||
| 26 | - | ||
| 27 | -import java.util.concurrent.CountDownLatch; | ||
| 28 | -import java.util.concurrent.TimeUnit; | ||
| 29 | - | ||
| 30 | -import static org.junit.Assert.assertEquals; | ||
| 31 | -import static org.junit.Assert.assertTrue; | ||
| 32 | - | ||
| 33 | -/** | ||
| 34 | - * Tests of the cluster communication manager. | ||
| 35 | - */ | ||
| 36 | -public class ClusterCommunicationManagerTest { | ||
| 37 | - | ||
| 38 | - private static final NodeId N1 = new NodeId("n1"); | ||
| 39 | - private static final NodeId N2 = new NodeId("n2"); | ||
| 40 | - | ||
| 41 | - private static final int P1 = 9881; | ||
| 42 | - private static final int P2 = 9882; | ||
| 43 | - | ||
| 44 | - private static final IpAddress IP = IpAddress.valueOf("127.0.0.1"); | ||
| 45 | - | ||
| 46 | - private ClusterCommunicationManager ccm1; | ||
| 47 | - private ClusterCommunicationManager ccm2; | ||
| 48 | - | ||
| 49 | - private TestDelegate cnd1 = new TestDelegate(); | ||
| 50 | - private TestDelegate cnd2 = new TestDelegate(); | ||
| 51 | - | ||
| 52 | - private DefaultControllerNode node1 = new DefaultControllerNode(N1, IP, P1); | ||
| 53 | - private DefaultControllerNode node2 = new DefaultControllerNode(N2, IP, P2); | ||
| 54 | - | ||
| 55 | - @Before | ||
| 56 | - public void setUp() throws Exception { | ||
| 57 | - | ||
| 58 | - NettyMessagingManager messagingService = new NettyMessagingManager(); | ||
| 59 | - messagingService.activate(); | ||
| 60 | - | ||
| 61 | - ccm1 = new ClusterCommunicationManager(); | ||
| 62 | - ccm1.activate(); | ||
| 63 | - | ||
| 64 | - ccm2 = new ClusterCommunicationManager(); | ||
| 65 | - ccm2.activate(); | ||
| 66 | - | ||
| 67 | -// ccm1.initialize(node1, cnd1); | ||
| 68 | -// ccm2.initialize(node2, cnd2); | ||
| 69 | - } | ||
| 70 | - | ||
| 71 | - @After | ||
| 72 | - public void tearDown() { | ||
| 73 | - ccm1.deactivate(); | ||
| 74 | - ccm2.deactivate(); | ||
| 75 | - } | ||
| 76 | - | ||
| 77 | - @Ignore("FIXME: failing randomly?") | ||
| 78 | - @Test | ||
| 79 | - public void connect() throws Exception { | ||
| 80 | - cnd1.latch = new CountDownLatch(1); | ||
| 81 | - cnd2.latch = new CountDownLatch(1); | ||
| 82 | - | ||
| 83 | -// ccm1.addNode(node2); | ||
| 84 | - validateDelegateEvent(cnd1, Op.DETECTED, node2.id()); | ||
| 85 | - validateDelegateEvent(cnd2, Op.DETECTED, node1.id()); | ||
| 86 | - } | ||
| 87 | - | ||
| 88 | - @Test | ||
| 89 | - @Ignore | ||
| 90 | - public void disconnect() throws Exception { | ||
| 91 | - cnd1.latch = new CountDownLatch(1); | ||
| 92 | - cnd2.latch = new CountDownLatch(1); | ||
| 93 | - | ||
| 94 | -// ccm1.addNode(node2); | ||
| 95 | - validateDelegateEvent(cnd1, Op.DETECTED, node2.id()); | ||
| 96 | - validateDelegateEvent(cnd2, Op.DETECTED, node1.id()); | ||
| 97 | - | ||
| 98 | - cnd1.latch = new CountDownLatch(1); | ||
| 99 | - cnd2.latch = new CountDownLatch(1); | ||
| 100 | - ccm1.deactivate(); | ||
| 101 | -// | ||
| 102 | -// validateDelegateEvent(cnd2, Op.VANISHED, node1.id()); | ||
| 103 | - } | ||
| 104 | - | ||
| 105 | - private void validateDelegateEvent(TestDelegate delegate, Op op, NodeId nodeId) | ||
| 106 | - throws InterruptedException { | ||
| 107 | - assertTrue("did not connect in time", delegate.latch.await(2500, TimeUnit.MILLISECONDS)); | ||
| 108 | - assertEquals("incorrect event", op, delegate.op); | ||
| 109 | - assertEquals("incorrect event node", nodeId, delegate.nodeId); | ||
| 110 | - } | ||
| 111 | - | ||
| 112 | - enum Op { DETECTED, VANISHED, REMOVED } | ||
| 113 | - | ||
| 114 | - private class TestDelegate implements ClusterNodesDelegate { | ||
| 115 | - | ||
| 116 | - Op op; | ||
| 117 | - CountDownLatch latch; | ||
| 118 | - NodeId nodeId; | ||
| 119 | - | ||
| 120 | - @Override | ||
| 121 | - public DefaultControllerNode nodeDetected(NodeId nodeId, IpAddress ip, int tcpPort) { | ||
| 122 | - latch(nodeId, Op.DETECTED); | ||
| 123 | - return new DefaultControllerNode(nodeId, ip, tcpPort); | ||
| 124 | - } | ||
| 125 | - | ||
| 126 | - @Override | ||
| 127 | - public void nodeVanished(NodeId nodeId) { | ||
| 128 | - latch(nodeId, Op.VANISHED); | ||
| 129 | - } | ||
| 130 | - | ||
| 131 | - @Override | ||
| 132 | - public void nodeRemoved(NodeId nodeId) { | ||
| 133 | - latch(nodeId, Op.REMOVED); | ||
| 134 | - } | ||
| 135 | - | ||
| 136 | - private void latch(NodeId nodeId, Op op) { | ||
| 137 | - this.op = op; | ||
| 138 | - this.nodeId = nodeId; | ||
| 139 | - latch.countDown(); | ||
| 140 | - } | ||
| 141 | - } | ||
| 142 | -} |
| ... | @@ -17,7 +17,6 @@ package org.onosproject.store.link.impl; | ... | @@ -17,7 +17,6 @@ package org.onosproject.store.link.impl; |
| 17 | 17 | ||
| 18 | import com.google.common.collect.Iterables; | 18 | import com.google.common.collect.Iterables; |
| 19 | 19 | ||
| 20 | -import org.easymock.Capture; | ||
| 21 | import org.junit.After; | 20 | import org.junit.After; |
| 22 | import org.junit.AfterClass; | 21 | import org.junit.AfterClass; |
| 23 | import org.junit.Before; | 22 | import org.junit.Before; |
| ... | @@ -59,8 +58,6 @@ import java.util.concurrent.CountDownLatch; | ... | @@ -59,8 +58,6 @@ import java.util.concurrent.CountDownLatch; |
| 59 | import java.util.concurrent.ExecutorService; | 58 | import java.util.concurrent.ExecutorService; |
| 60 | import java.util.concurrent.TimeUnit; | 59 | import java.util.concurrent.TimeUnit; |
| 61 | import java.util.concurrent.atomic.AtomicLong; | 60 | import java.util.concurrent.atomic.AtomicLong; |
| 62 | -import java.util.function.Function; | ||
| 63 | - | ||
| 64 | import static org.easymock.EasyMock.*; | 61 | import static org.easymock.EasyMock.*; |
| 65 | import static org.junit.Assert.*; | 62 | import static org.junit.Assert.*; |
| 66 | import static org.onosproject.cluster.ControllerNode.State.ACTIVE; | 63 | import static org.onosproject.cluster.ControllerNode.State.ACTIVE; |
| ... | @@ -76,7 +73,8 @@ import static org.onosproject.net.link.LinkEvent.Type.LINK_UPDATED; | ... | @@ -76,7 +73,8 @@ import static org.onosproject.net.link.LinkEvent.Type.LINK_UPDATED; |
| 76 | /** | 73 | /** |
| 77 | * Test of the GossipLinkStoreTest implementation. | 74 | * Test of the GossipLinkStoreTest implementation. |
| 78 | */ | 75 | */ |
| 79 | -public class GossipLinkStoreTest { | 76 | +@Ignore |
| 77 | +public class ECLinkStoreTest { | ||
| 80 | 78 | ||
| 81 | private static final ProviderId PID = new ProviderId("of", "foo"); | 79 | private static final ProviderId PID = new ProviderId("of", "foo"); |
| 82 | private static final ProviderId PIDA = new ProviderId("of", "bar", true); | 80 | private static final ProviderId PIDA = new ProviderId("of", "bar", true); |
| ... | @@ -114,10 +112,9 @@ public class GossipLinkStoreTest { | ... | @@ -114,10 +112,9 @@ public class GossipLinkStoreTest { |
| 114 | private static final ControllerNode ONOS2 = | 112 | private static final ControllerNode ONOS2 = |
| 115 | new DefaultControllerNode(NID2, IpAddress.valueOf("127.0.0.2")); | 113 | new DefaultControllerNode(NID2, IpAddress.valueOf("127.0.0.2")); |
| 116 | 114 | ||
| 117 | - private GossipLinkStore linkStoreImpl; | 115 | + private ECLinkStore linkStoreImpl; |
| 118 | private LinkStore linkStore; | 116 | private LinkStore linkStore; |
| 119 | 117 | ||
| 120 | - private final AtomicLong ticker = new AtomicLong(); | ||
| 121 | private DeviceClockService deviceClockService; | 118 | private DeviceClockService deviceClockService; |
| 122 | private ClusterCommunicationService clusterCommunicator; | 119 | private ClusterCommunicationService clusterCommunicator; |
| 123 | 120 | ||
| ... | @@ -139,7 +136,7 @@ public class GossipLinkStoreTest { | ... | @@ -139,7 +136,7 @@ public class GossipLinkStoreTest { |
| 139 | expectLastCall().anyTimes(); | 136 | expectLastCall().anyTimes(); |
| 140 | replay(clusterCommunicator); | 137 | replay(clusterCommunicator); |
| 141 | 138 | ||
| 142 | - linkStoreImpl = new GossipLinkStore(); | 139 | + linkStoreImpl = new ECLinkStore(); |
| 143 | linkStoreImpl.deviceClockService = deviceClockService; | 140 | linkStoreImpl.deviceClockService = deviceClockService; |
| 144 | linkStoreImpl.clusterCommunicator = clusterCommunicator; | 141 | linkStoreImpl.clusterCommunicator = clusterCommunicator; |
| 145 | linkStoreImpl.clusterService = new TestClusterService(); | 142 | linkStoreImpl.clusterService = new TestClusterService(); |
| ... | @@ -163,28 +160,10 @@ public class GossipLinkStoreTest { | ... | @@ -163,28 +160,10 @@ public class GossipLinkStoreTest { |
| 163 | SparseAnnotations... annotations) { | 160 | SparseAnnotations... annotations) { |
| 164 | ConnectPoint src = new ConnectPoint(srcId, srcNum); | 161 | ConnectPoint src = new ConnectPoint(srcId, srcNum); |
| 165 | ConnectPoint dst = new ConnectPoint(dstId, dstNum); | 162 | ConnectPoint dst = new ConnectPoint(dstId, dstNum); |
| 166 | - reset(clusterCommunicator); | ||
| 167 | - clusterCommunicator.<InternalLinkEvent>broadcast( | ||
| 168 | - anyObject(InternalLinkEvent.class), anyObject(MessageSubject.class), anyObject(Function.class)); | ||
| 169 | - expectLastCall().anyTimes(); | ||
| 170 | - replay(clusterCommunicator); | ||
| 171 | linkStore.createOrUpdateLink(PID, new DefaultLinkDescription(src, dst, type, annotations)); | 163 | linkStore.createOrUpdateLink(PID, new DefaultLinkDescription(src, dst, type, annotations)); |
| 172 | verify(clusterCommunicator); | 164 | verify(clusterCommunicator); |
| 173 | } | 165 | } |
| 174 | 166 | ||
| 175 | - private <T> void resetCommunicatorExpectingSingleBroadcast( | ||
| 176 | - Capture<T> message, | ||
| 177 | - Capture<MessageSubject> subject, | ||
| 178 | - Capture<Function<T, byte[]>> encoder) { | ||
| 179 | - message.reset(); | ||
| 180 | - subject.reset(); | ||
| 181 | - encoder.reset(); | ||
| 182 | - reset(clusterCommunicator); | ||
| 183 | - clusterCommunicator.broadcast(capture(message), capture(subject), capture(encoder)); | ||
| 184 | - expectLastCall().once(); | ||
| 185 | - replay(clusterCommunicator); | ||
| 186 | - } | ||
| 187 | - | ||
| 188 | private void putLink(LinkKey key, Type type, SparseAnnotations... annotations) { | 167 | private void putLink(LinkKey key, Type type, SparseAnnotations... annotations) { |
| 189 | putLink(key.src().deviceId(), key.src().port(), | 168 | putLink(key.src().deviceId(), key.src().port(), |
| 190 | key.dst().deviceId(), key.dst().port(), | 169 | key.dst().deviceId(), key.dst().port(), |
| ... | @@ -358,57 +337,26 @@ public class GossipLinkStoreTest { | ... | @@ -358,57 +337,26 @@ public class GossipLinkStoreTest { |
| 358 | ConnectPoint src = new ConnectPoint(DID1, P1); | 337 | ConnectPoint src = new ConnectPoint(DID1, P1); |
| 359 | ConnectPoint dst = new ConnectPoint(DID2, P2); | 338 | ConnectPoint dst = new ConnectPoint(DID2, P2); |
| 360 | 339 | ||
| 361 | - Capture<InternalLinkEvent> message = new Capture<>(); | ||
| 362 | - Capture<MessageSubject> subject = new Capture<>(); | ||
| 363 | - Capture<Function<InternalLinkEvent, byte[]>> encoder = new Capture<>(); | ||
| 364 | - | ||
| 365 | - // add link | ||
| 366 | - resetCommunicatorExpectingSingleBroadcast(message, subject, encoder); | ||
| 367 | final DefaultLinkDescription linkDescription = new DefaultLinkDescription(src, dst, INDIRECT); | 340 | final DefaultLinkDescription linkDescription = new DefaultLinkDescription(src, dst, INDIRECT); |
| 368 | LinkEvent event = linkStore.createOrUpdateLink(PID, | 341 | LinkEvent event = linkStore.createOrUpdateLink(PID, |
| 369 | linkDescription); | 342 | linkDescription); |
| 370 | - verifyLinkBroadcastMessage(PID, NID1, src, dst, INDIRECT, message, subject, encoder); | ||
| 371 | 343 | ||
| 372 | assertLink(DID1, P1, DID2, P2, INDIRECT, event.subject()); | 344 | assertLink(DID1, P1, DID2, P2, INDIRECT, event.subject()); |
| 373 | assertEquals(LINK_ADDED, event.type()); | 345 | assertEquals(LINK_ADDED, event.type()); |
| 374 | 346 | ||
| 375 | - // update link type | ||
| 376 | - resetCommunicatorExpectingSingleBroadcast(message, subject, encoder); | ||
| 377 | LinkEvent event2 = linkStore.createOrUpdateLink(PID, | 347 | LinkEvent event2 = linkStore.createOrUpdateLink(PID, |
| 378 | new DefaultLinkDescription(src, dst, DIRECT)); | 348 | new DefaultLinkDescription(src, dst, DIRECT)); |
| 379 | - verifyLinkBroadcastMessage(PID, NID1, src, dst, DIRECT, message, subject, encoder); | ||
| 380 | 349 | ||
| 381 | assertLink(DID1, P1, DID2, P2, DIRECT, event2.subject()); | 350 | assertLink(DID1, P1, DID2, P2, DIRECT, event2.subject()); |
| 382 | assertEquals(LINK_UPDATED, event2.type()); | 351 | assertEquals(LINK_UPDATED, event2.type()); |
| 383 | 352 | ||
| 384 | // no change | 353 | // no change |
| 385 | - resetCommunicatorExpectingSingleBroadcast(message, subject, encoder); | ||
| 386 | LinkEvent event3 = linkStore.createOrUpdateLink(PID, | 354 | LinkEvent event3 = linkStore.createOrUpdateLink(PID, |
| 387 | new DefaultLinkDescription(src, dst, DIRECT)); | 355 | new DefaultLinkDescription(src, dst, DIRECT)); |
| 388 | - verifyNoBroadcastMessage(message); | ||
| 389 | 356 | ||
| 390 | assertNull("No change event expected", event3); | 357 | assertNull("No change event expected", event3); |
| 391 | } | 358 | } |
| 392 | 359 | ||
| 393 | - private <T> void verifyNoBroadcastMessage(Capture<T> message) { | ||
| 394 | - assertFalse("No broadcast expected", message.hasCaptured()); | ||
| 395 | - } | ||
| 396 | - | ||
| 397 | - private void verifyLinkBroadcastMessage(ProviderId providerId, | ||
| 398 | - NodeId sender, | ||
| 399 | - ConnectPoint src, | ||
| 400 | - ConnectPoint dst, | ||
| 401 | - Type type, | ||
| 402 | - Capture<InternalLinkEvent> actualLinkEvent, | ||
| 403 | - Capture<MessageSubject> actualSubject, | ||
| 404 | - Capture<Function<InternalLinkEvent, byte[]>> actualEncoder) { | ||
| 405 | - verify(clusterCommunicator); | ||
| 406 | - assertTrue(actualLinkEvent.hasCaptured()); | ||
| 407 | - assertEquals(GossipLinkStoreMessageSubjects.LINK_UPDATE, actualSubject.getValue()); | ||
| 408 | - assertEquals(providerId, actualLinkEvent.getValue().providerId()); | ||
| 409 | - assertLinkDescriptionEquals(src, dst, type, actualLinkEvent.getValue().linkDescription().value()); | ||
| 410 | - } | ||
| 411 | - | ||
| 412 | private static void assertLinkDescriptionEquals(ConnectPoint src, | 360 | private static void assertLinkDescriptionEquals(ConnectPoint src, |
| 413 | ConnectPoint dst, | 361 | ConnectPoint dst, |
| 414 | Type type, | 362 | Type type, |
| ... | @@ -424,33 +372,23 @@ public class GossipLinkStoreTest { | ... | @@ -424,33 +372,23 @@ public class GossipLinkStoreTest { |
| 424 | ConnectPoint src = new ConnectPoint(DID1, P1); | 372 | ConnectPoint src = new ConnectPoint(DID1, P1); |
| 425 | ConnectPoint dst = new ConnectPoint(DID2, P2); | 373 | ConnectPoint dst = new ConnectPoint(DID2, P2); |
| 426 | 374 | ||
| 427 | - Capture<InternalLinkEvent> message = new Capture<>(); | ||
| 428 | - Capture<MessageSubject> subject = new Capture<>(); | ||
| 429 | - Capture<Function<InternalLinkEvent, byte[]>> encoder = new Capture<>(); | ||
| 430 | - | ||
| 431 | // add Ancillary link | 375 | // add Ancillary link |
| 432 | - resetCommunicatorExpectingSingleBroadcast(message, subject, encoder); | ||
| 433 | LinkEvent event = linkStore.createOrUpdateLink(PIDA, | 376 | LinkEvent event = linkStore.createOrUpdateLink(PIDA, |
| 434 | new DefaultLinkDescription(src, dst, INDIRECT, A1)); | 377 | new DefaultLinkDescription(src, dst, INDIRECT, A1)); |
| 435 | - verifyLinkBroadcastMessage(PIDA, NID1, src, dst, INDIRECT, message, subject, encoder); | ||
| 436 | 378 | ||
| 437 | assertNotNull("Ancillary only link is ignored", event); | 379 | assertNotNull("Ancillary only link is ignored", event); |
| 438 | 380 | ||
| 439 | // add Primary link | 381 | // add Primary link |
| 440 | - resetCommunicatorExpectingSingleBroadcast(message, subject, encoder); | ||
| 441 | LinkEvent event2 = linkStore.createOrUpdateLink(PID, | 382 | LinkEvent event2 = linkStore.createOrUpdateLink(PID, |
| 442 | new DefaultLinkDescription(src, dst, INDIRECT, A2)); | 383 | new DefaultLinkDescription(src, dst, INDIRECT, A2)); |
| 443 | - verifyLinkBroadcastMessage(PID, NID1, src, dst, INDIRECT, message, subject, encoder); | ||
| 444 | 384 | ||
| 445 | assertLink(DID1, P1, DID2, P2, INDIRECT, event2.subject()); | 385 | assertLink(DID1, P1, DID2, P2, INDIRECT, event2.subject()); |
| 446 | assertAnnotationsEquals(event2.subject().annotations(), A2, A1); | 386 | assertAnnotationsEquals(event2.subject().annotations(), A2, A1); |
| 447 | assertEquals(LINK_UPDATED, event2.type()); | 387 | assertEquals(LINK_UPDATED, event2.type()); |
| 448 | 388 | ||
| 449 | // update link type | 389 | // update link type |
| 450 | - resetCommunicatorExpectingSingleBroadcast(message, subject, encoder); | ||
| 451 | LinkEvent event3 = linkStore.createOrUpdateLink(PID, | 390 | LinkEvent event3 = linkStore.createOrUpdateLink(PID, |
| 452 | new DefaultLinkDescription(src, dst, DIRECT, A2)); | 391 | new DefaultLinkDescription(src, dst, DIRECT, A2)); |
| 453 | - verifyLinkBroadcastMessage(PID, NID1, src, dst, DIRECT, message, subject, encoder); | ||
| 454 | 392 | ||
| 455 | assertLink(DID1, P1, DID2, P2, DIRECT, event3.subject()); | 393 | assertLink(DID1, P1, DID2, P2, DIRECT, event3.subject()); |
| 456 | assertAnnotationsEquals(event3.subject().annotations(), A2, A1); | 394 | assertAnnotationsEquals(event3.subject().annotations(), A2, A1); |
| ... | @@ -458,38 +396,30 @@ public class GossipLinkStoreTest { | ... | @@ -458,38 +396,30 @@ public class GossipLinkStoreTest { |
| 458 | 396 | ||
| 459 | 397 | ||
| 460 | // no change | 398 | // no change |
| 461 | - resetCommunicatorExpectingSingleBroadcast(message, subject, encoder); | ||
| 462 | LinkEvent event4 = linkStore.createOrUpdateLink(PID, | 399 | LinkEvent event4 = linkStore.createOrUpdateLink(PID, |
| 463 | new DefaultLinkDescription(src, dst, DIRECT)); | 400 | new DefaultLinkDescription(src, dst, DIRECT)); |
| 464 | - verifyNoBroadcastMessage(message); | ||
| 465 | 401 | ||
| 466 | assertNull("No change event expected", event4); | 402 | assertNull("No change event expected", event4); |
| 467 | 403 | ||
| 468 | // update link annotation (Primary) | 404 | // update link annotation (Primary) |
| 469 | - resetCommunicatorExpectingSingleBroadcast(message, subject, encoder); | ||
| 470 | LinkEvent event5 = linkStore.createOrUpdateLink(PID, | 405 | LinkEvent event5 = linkStore.createOrUpdateLink(PID, |
| 471 | new DefaultLinkDescription(src, dst, DIRECT, A2_2)); | 406 | new DefaultLinkDescription(src, dst, DIRECT, A2_2)); |
| 472 | - verifyLinkBroadcastMessage(PID, NID1, src, dst, DIRECT, message, subject, encoder); | ||
| 473 | 407 | ||
| 474 | assertLink(DID1, P1, DID2, P2, DIRECT, event5.subject()); | 408 | assertLink(DID1, P1, DID2, P2, DIRECT, event5.subject()); |
| 475 | assertAnnotationsEquals(event5.subject().annotations(), A2, A2_2, A1); | 409 | assertAnnotationsEquals(event5.subject().annotations(), A2, A2_2, A1); |
| 476 | assertEquals(LINK_UPDATED, event5.type()); | 410 | assertEquals(LINK_UPDATED, event5.type()); |
| 477 | 411 | ||
| 478 | // update link annotation (Ancillary) | 412 | // update link annotation (Ancillary) |
| 479 | - resetCommunicatorExpectingSingleBroadcast(message, subject, encoder); | ||
| 480 | LinkEvent event6 = linkStore.createOrUpdateLink(PIDA, | 413 | LinkEvent event6 = linkStore.createOrUpdateLink(PIDA, |
| 481 | new DefaultLinkDescription(src, dst, DIRECT, A1_2)); | 414 | new DefaultLinkDescription(src, dst, DIRECT, A1_2)); |
| 482 | - verifyLinkBroadcastMessage(PIDA, NID1, src, dst, DIRECT, message, subject, encoder); | ||
| 483 | 415 | ||
| 484 | assertLink(DID1, P1, DID2, P2, DIRECT, event6.subject()); | 416 | assertLink(DID1, P1, DID2, P2, DIRECT, event6.subject()); |
| 485 | assertAnnotationsEquals(event6.subject().annotations(), A2, A2_2, A1, A1_2); | 417 | assertAnnotationsEquals(event6.subject().annotations(), A2, A2_2, A1, A1_2); |
| 486 | assertEquals(LINK_UPDATED, event6.type()); | 418 | assertEquals(LINK_UPDATED, event6.type()); |
| 487 | 419 | ||
| 488 | // update link type (Ancillary) : ignored | 420 | // update link type (Ancillary) : ignored |
| 489 | - resetCommunicatorExpectingSingleBroadcast(message, subject, encoder); | ||
| 490 | LinkEvent event7 = linkStore.createOrUpdateLink(PIDA, | 421 | LinkEvent event7 = linkStore.createOrUpdateLink(PIDA, |
| 491 | new DefaultLinkDescription(src, dst, EDGE)); | 422 | new DefaultLinkDescription(src, dst, EDGE)); |
| 492 | - verifyNoBroadcastMessage(message); | ||
| 493 | assertNull("Ancillary change other than annotation is ignored", event7); | 423 | assertNull("Ancillary change other than annotation is ignored", event7); |
| 494 | } | 424 | } |
| 495 | 425 | ... | ... |
core/store/dist/src/test/java/org/onosproject/store/link/impl/LinkFragmentIdTest.java
deleted
100644 → 0
| 1 | -/* | ||
| 2 | - * Copyright 2014-present Open Networking Laboratory | ||
| 3 | - * | ||
| 4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | - * you may not use this file except in compliance with the License. | ||
| 6 | - * You may obtain a copy of the License at | ||
| 7 | - * | ||
| 8 | - * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | - * | ||
| 10 | - * Unless required by applicable law or agreed to in writing, software | ||
| 11 | - * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | - * See the License for the specific language governing permissions and | ||
| 14 | - * limitations under the License. | ||
| 15 | - */ | ||
| 16 | -package org.onosproject.store.link.impl; | ||
| 17 | - | ||
| 18 | -import static org.onosproject.net.DeviceId.deviceId; | ||
| 19 | - | ||
| 20 | -import org.junit.Test; | ||
| 21 | -import org.onosproject.net.ConnectPoint; | ||
| 22 | -import org.onosproject.net.DeviceId; | ||
| 23 | -import org.onosproject.net.LinkKey; | ||
| 24 | -import org.onosproject.net.PortNumber; | ||
| 25 | -import org.onosproject.net.provider.ProviderId; | ||
| 26 | -import com.google.common.testing.EqualsTester; | ||
| 27 | - | ||
| 28 | -public class LinkFragmentIdTest { | ||
| 29 | - | ||
| 30 | - private static final ProviderId PID = new ProviderId("of", "foo"); | ||
| 31 | - private static final ProviderId PIDA = new ProviderId("of", "bar", true); | ||
| 32 | - | ||
| 33 | - private static final DeviceId DID1 = deviceId("of:foo"); | ||
| 34 | - private static final DeviceId DID2 = deviceId("of:bar"); | ||
| 35 | - | ||
| 36 | - private static final PortNumber P1 = PortNumber.portNumber(1); | ||
| 37 | - private static final PortNumber P2 = PortNumber.portNumber(2); | ||
| 38 | - private static final PortNumber P3 = PortNumber.portNumber(3); | ||
| 39 | - | ||
| 40 | - private static final ConnectPoint CP1 = new ConnectPoint(DID1, P1); | ||
| 41 | - private static final ConnectPoint CP2 = new ConnectPoint(DID2, P2); | ||
| 42 | - | ||
| 43 | - private static final ConnectPoint CP3 = new ConnectPoint(DID1, P2); | ||
| 44 | - private static final ConnectPoint CP4 = new ConnectPoint(DID2, P3); | ||
| 45 | - | ||
| 46 | - private static final LinkKey L1 = LinkKey.linkKey(CP1, CP2); | ||
| 47 | - private static final LinkKey L2 = LinkKey.linkKey(CP3, CP4); | ||
| 48 | - | ||
| 49 | - @Test | ||
| 50 | - public void testEquals() { | ||
| 51 | - new EqualsTester() | ||
| 52 | - .addEqualityGroup(new LinkFragmentId(L1, PID), | ||
| 53 | - new LinkFragmentId(L1, PID)) | ||
| 54 | - .addEqualityGroup(new LinkFragmentId(L2, PID), | ||
| 55 | - new LinkFragmentId(L2, PID)) | ||
| 56 | - .addEqualityGroup(new LinkFragmentId(L1, PIDA), | ||
| 57 | - new LinkFragmentId(L1, PIDA)) | ||
| 58 | - .addEqualityGroup(new LinkFragmentId(L2, PIDA), | ||
| 59 | - new LinkFragmentId(L2, PIDA)) | ||
| 60 | - .testEquals(); | ||
| 61 | - } | ||
| 62 | - | ||
| 63 | -} |
core/store/dist/src/test/java/org/onosproject/store/mastership/impl/RoleValueTest.java
deleted
100644 → 0
| 1 | -/* | ||
| 2 | - * Copyright 2014-present Open Networking Laboratory | ||
| 3 | - * | ||
| 4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | - * you may not use this file except in compliance with the License. | ||
| 6 | - * You may obtain a copy of the License at | ||
| 7 | - * | ||
| 8 | - * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | - * | ||
| 10 | - * Unless required by applicable law or agreed to in writing, software | ||
| 11 | - * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | - * See the License for the specific language governing permissions and | ||
| 14 | - * limitations under the License. | ||
| 15 | - */ | ||
| 16 | -package org.onosproject.store.mastership.impl; | ||
| 17 | - | ||
| 18 | -import static org.junit.Assert.assertEquals; | ||
| 19 | -import static org.junit.Assert.assertTrue; | ||
| 20 | -import static org.onosproject.net.MastershipRole.*; | ||
| 21 | - | ||
| 22 | -import org.junit.Test; | ||
| 23 | -import org.onosproject.cluster.NodeId; | ||
| 24 | - | ||
| 25 | -import com.google.common.collect.Sets; | ||
| 26 | - | ||
| 27 | -public class RoleValueTest { | ||
| 28 | - | ||
| 29 | - private static final RoleValue RV = new RoleValue(); | ||
| 30 | - | ||
| 31 | - private static final NodeId NID1 = new NodeId("node1"); | ||
| 32 | - private static final NodeId NID2 = new NodeId("node2"); | ||
| 33 | - private static final NodeId NID3 = new NodeId("node3"); | ||
| 34 | - | ||
| 35 | - @Test | ||
| 36 | - public void add() { | ||
| 37 | - assertEquals("faulty initialization: ", 3, RV.value.size()); | ||
| 38 | - RV.add(MASTER, NID1); | ||
| 39 | - RV.add(STANDBY, NID2); | ||
| 40 | - RV.add(STANDBY, NID3); | ||
| 41 | - | ||
| 42 | - assertEquals("wrong nodeID: ", NID1, RV.get(MASTER)); | ||
| 43 | - assertTrue("wrong nodeIDs: ", | ||
| 44 | - Sets.newHashSet(NID3, NID2).containsAll(RV.nodesOfRole(STANDBY))); | ||
| 45 | - } | ||
| 46 | -} |
-
Please register or login to post a comment