Search in sources :

Example 1 with ClusterEventListener

use of org.onosproject.cluster.ClusterEventListener in project onos by opennetworkinglab.

the class SimpleMastershipStore method activate.

@Activate
public void activate() {
    if (clusterService == null) {
        // just for ease of unit test
        final ControllerNode instance = new DefaultControllerNode(new NodeId("local"), IpAddress.valueOf("127.0.0.1"));
        clusterService = new ClusterService() {

            private final Instant creationTime = Instant.now();

            @Override
            public ControllerNode getLocalNode() {
                return instance;
            }

            @Override
            public Set<ControllerNode> getNodes() {
                return ImmutableSet.of(instance);
            }

            @Override
            public Set<Node> getConsensusNodes() {
                return ImmutableSet.of();
            }

            @Override
            public ControllerNode getNode(NodeId nodeId) {
                if (instance.id().equals(nodeId)) {
                    return instance;
                }
                return null;
            }

            @Override
            public State getState(NodeId nodeId) {
                if (instance.id().equals(nodeId)) {
                    return State.ACTIVE;
                } else {
                    return State.INACTIVE;
                }
            }

            @Override
            public Version getVersion(NodeId nodeId) {
                if (instance.id().equals(nodeId)) {
                    return versionService.version();
                }
                return null;
            }

            @Override
            public Instant getLastUpdatedInstant(NodeId nodeId) {
                return creationTime;
            }

            @Override
            public void addListener(ClusterEventListener listener) {
            }

            @Override
            public void removeListener(ClusterEventListener listener) {
            }
        };
    }
    log.info("Started");
}
Also used : ClusterService(org.onosproject.cluster.ClusterService) HashSet(java.util.HashSet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) Version(org.onosproject.core.Version) State(org.onosproject.cluster.ControllerNode.State) Instant(java.time.Instant) NodeId(org.onosproject.cluster.NodeId) ControllerNode(org.onosproject.cluster.ControllerNode) DefaultControllerNode(org.onosproject.cluster.DefaultControllerNode) DefaultControllerNode(org.onosproject.cluster.DefaultControllerNode) ClusterEventListener(org.onosproject.cluster.ClusterEventListener) Activate(org.osgi.service.component.annotations.Activate)

Example 2 with ClusterEventListener

use of org.onosproject.cluster.ClusterEventListener in project onos by opennetworkinglab.

the class SimpleVirtualMastershipStore method createFakeClusterService.

/**
 * Returns a fake cluster service for a test purpose only.
 *
 * @return a fake cluster service
 */
private ClusterService createFakeClusterService() {
    // just for ease of unit test
    final ControllerNode instance = new DefaultControllerNode(new NodeId("local"), IpAddress.valueOf("127.0.0.1"));
    ClusterService faceClusterService = new ClusterService() {

        private final Instant creationTime = Instant.now();

        @Override
        public ControllerNode getLocalNode() {
            return instance;
        }

        @Override
        public Set<ControllerNode> getNodes() {
            return ImmutableSet.of(instance);
        }

        @Override
        public Set<Node> getConsensusNodes() {
            return ImmutableSet.of();
        }

        @Override
        public ControllerNode getNode(NodeId nodeId) {
            if (instance.id().equals(nodeId)) {
                return instance;
            }
            return null;
        }

        @Override
        public ControllerNode.State getState(NodeId nodeId) {
            if (instance.id().equals(nodeId)) {
                return ControllerNode.State.ACTIVE;
            } else {
                return ControllerNode.State.INACTIVE;
            }
        }

        @Override
        public Version getVersion(NodeId nodeId) {
            if (instance.id().equals(nodeId)) {
                return versionService.version();
            }
            return null;
        }

        @Override
        public Instant getLastUpdatedInstant(NodeId nodeId) {
            return creationTime;
        }

        @Override
        public void addListener(ClusterEventListener listener) {
        }

        @Override
        public void removeListener(ClusterEventListener listener) {
        }
    };
    return faceClusterService;
}
Also used : ClusterService(org.onosproject.cluster.ClusterService) Instant(java.time.Instant) ControllerNode(org.onosproject.cluster.ControllerNode) DefaultControllerNode(org.onosproject.cluster.DefaultControllerNode) Node(org.onosproject.cluster.Node) NodeId(org.onosproject.cluster.NodeId) ControllerNode(org.onosproject.cluster.ControllerNode) DefaultControllerNode(org.onosproject.cluster.DefaultControllerNode) DefaultControllerNode(org.onosproject.cluster.DefaultControllerNode) ClusterEventListener(org.onosproject.cluster.ClusterEventListener)

Aggregations

Instant (java.time.Instant)2 ClusterEventListener (org.onosproject.cluster.ClusterEventListener)2 ClusterService (org.onosproject.cluster.ClusterService)2 ControllerNode (org.onosproject.cluster.ControllerNode)2 DefaultControllerNode (org.onosproject.cluster.DefaultControllerNode)2 NodeId (org.onosproject.cluster.NodeId)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 State (org.onosproject.cluster.ControllerNode.State)1 Node (org.onosproject.cluster.Node)1 Version (org.onosproject.core.Version)1 Activate (org.osgi.service.component.annotations.Activate)1