Search in sources :

Example 31 with ControllerNode

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

the class NodeIdCompleter method complete.

@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
    // Delegate string completer
    StringsCompleter delegate = new StringsCompleter();
    // Fetch our service and feed it's offerings to the string completer
    ClusterService service = AbstractShellCommand.get(ClusterService.class);
    Iterator<ControllerNode> it = service.getNodes().iterator();
    SortedSet<String> strings = delegate.getStrings();
    while (it.hasNext()) {
        strings.add(it.next().id().toString());
    }
    // Now let the completer do the work for figuring out what to offer.
    return delegate.complete(session, commandLine, candidates);
}
Also used : ClusterService(org.onosproject.cluster.ClusterService) StringsCompleter(org.apache.karaf.shell.support.completers.StringsCompleter) ControllerNode(org.onosproject.cluster.ControllerNode)

Example 32 with ControllerNode

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

the class NodesListCommand method json.

// Produces JSON structure.
private JsonNode json(ClusterAdminService service, List<ControllerNode> nodes) {
    ObjectMapper mapper = new ObjectMapper();
    ArrayNode result = mapper.createArrayNode();
    ControllerNode self = service.getLocalNode();
    for (ControllerNode node : nodes) {
        ControllerNode.State nodeState = service.getState(node.id());
        Version nodeVersion = service.getVersion(node.id());
        IpAddress nodeIp = node.ip();
        ObjectNode newNode = mapper.createObjectNode().put("id", node.id().toString()).put("ip", nodeIp != null ? nodeIp.toString() : node.host()).put("tcpPort", node.tcpPort()).put("self", node.equals(self));
        if (nodeState != null) {
            newNode.put("state", nodeState.toString());
        }
        if (nodeVersion != null) {
            newNode.put("version", nodeVersion.toString());
        }
        result.add(newNode);
    }
    return result;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Version(org.onosproject.core.Version) ControllerNode(org.onosproject.cluster.ControllerNode) IpAddress(org.onlab.packet.IpAddress) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 33 with ControllerNode

use of org.onosproject.cluster.ControllerNode 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)

Example 34 with ControllerNode

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

the class StorageManager method eventuallyConsistentMapBuilder.

@Override
public <K, V> EventuallyConsistentMapBuilder<K, V> eventuallyConsistentMapBuilder() {
    checkPermission(STORAGE_WRITE);
    // Note: NPE in the usage of ClusterService/MembershipService prevents rebooting the Karaf container.
    // We need to reference these services outside the following peer suppliers.
    final MembershipService membershipService = this.membershipService;
    final ClusterService clusterService = this.clusterService;
    final NodeId localNodeId = clusterService.getLocalNode().id();
    // Use the MembershipService to provide peers for the map that are isolated within the current version.
    Supplier<List<NodeId>> peersSupplier = () -> membershipService.getMembers().stream().map(Member::nodeId).filter(nodeId -> !nodeId.equals(localNodeId)).filter(id -> clusterService.getState(id).isActive()).collect(Collectors.toList());
    // If this is the first node in its version, bootstrap from the previous version. Otherwise, bootstrap the
    // map from members isolated within the current version.
    Supplier<List<NodeId>> bootstrapPeersSupplier = () -> {
        if (membershipService.getMembers().size() == 1) {
            return clusterService.getNodes().stream().map(ControllerNode::id).filter(id -> !localNodeId.equals(id)).filter(id -> clusterService.getState(id).isActive()).collect(Collectors.toList());
        } else {
            return membershipService.getMembers().stream().map(Member::nodeId).filter(id -> !localNodeId.equals(id)).filter(id -> clusterService.getState(id).isActive()).collect(Collectors.toList());
        }
    };
    return new EventuallyConsistentMapBuilderImpl<>(localNodeId, clusterCommunicator, persistenceService, peersSupplier, bootstrapPeersSupplier);
}
Also used : StorageAdminService(org.onosproject.store.service.StorageAdminService) STORAGE_WRITE(org.onosproject.security.AppPermission.Type.STORAGE_WRITE) PersistenceService(org.onosproject.persistence.PersistenceService) Member(org.onosproject.cluster.Member) EventuallyConsistentMapBuilder(org.onosproject.store.service.EventuallyConsistentMapBuilder) Atomix(io.atomix.core.Atomix) AtomicCounterMapBuilder(org.onosproject.store.service.AtomicCounterMapBuilder) StorageService(org.onosproject.store.service.StorageService) MapInfo(org.onosproject.store.service.MapInfo) WorkQueueStats(org.onosproject.store.service.WorkQueueStats) Map(java.util.Map) ConsistentMultimapBuilder(org.onosproject.store.service.ConsistentMultimapBuilder) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) AtomicCounterBuilder(org.onosproject.store.service.AtomicCounterBuilder) NodeId(org.onosproject.cluster.NodeId) Serializer(org.onosproject.store.service.Serializer) LeaderElectorBuilder(org.onosproject.store.service.LeaderElectorBuilder) DocumentTreeBuilder(org.onosproject.store.service.DocumentTreeBuilder) Deactivate(org.osgi.service.component.annotations.Deactivate) Collection(java.util.Collection) TransactionId(org.onosproject.store.primitives.TransactionId) PartitionGroup(io.atomix.primitive.partition.PartitionGroup) Collectors(java.util.stream.Collectors) ConsistentTreeMapBuilder(org.onosproject.store.service.ConsistentTreeMapBuilder) List(java.util.List) AtomicCounter(io.atomix.core.counter.AtomicCounter) AsyncConsistentTreeMap(org.onosproject.store.service.AsyncConsistentTreeMap) ClusterCommunicationService(org.onosproject.store.cluster.messaging.ClusterCommunicationService) ClusterService(org.onosproject.cluster.ClusterService) DistributedSetBuilder(org.onosproject.store.service.DistributedSetBuilder) AtomicMapType(io.atomix.core.map.AtomicMapType) DistributedLockBuilder(org.onosproject.store.service.DistributedLockBuilder) AtomicCounterType(io.atomix.core.counter.AtomicCounterType) AtomicIdGeneratorBuilder(org.onosproject.store.service.AtomicIdGeneratorBuilder) WorkQueue(org.onosproject.store.service.WorkQueue) TopicBuilder(org.onosproject.store.service.TopicBuilder) AppGuard.checkPermission(org.onosproject.security.AppGuard.checkPermission) MultiRaftProtocol(io.atomix.protocols.raft.MultiRaftProtocol) AtomixManager(org.onosproject.store.atomix.impl.AtomixManager) Supplier(java.util.function.Supplier) ControllerNode(org.onosproject.cluster.ControllerNode) Component(org.osgi.service.component.annotations.Component) AtomicValueBuilder(org.onosproject.store.service.AtomicValueBuilder) Activate(org.osgi.service.component.annotations.Activate) WorkQueueType(io.atomix.core.workqueue.WorkQueueType) AsyncDocumentTree(org.onosproject.store.service.AsyncDocumentTree) WorkQueueBuilder(org.onosproject.store.service.WorkQueueBuilder) Logger(org.slf4j.Logger) Topic(org.onosproject.store.service.Topic) PartitionAdminService(org.onosproject.store.primitives.PartitionAdminService) AsyncConsistentMultimap(org.onosproject.store.service.AsyncConsistentMultimap) ConsistentMapBuilder(org.onosproject.store.service.ConsistentMapBuilder) Maps(com.google.common.collect.Maps) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) TransactionContextBuilder(org.onosproject.store.service.TransactionContextBuilder) MembershipService(org.onosproject.cluster.MembershipService) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Reference(org.osgi.service.component.annotations.Reference) ClusterService(org.onosproject.cluster.ClusterService) MembershipService(org.onosproject.cluster.MembershipService) NodeId(org.onosproject.cluster.NodeId) ControllerNode(org.onosproject.cluster.ControllerNode) List(java.util.List) Member(org.onosproject.cluster.Member)

Example 35 with ControllerNode

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

the class AtomixClusterStore method activate.

@Activate
public void activate() {
    membershipService = atomixManager.getAtomix().getMembershipService();
    membershipService.addListener(membershipEventListener);
    membershipService.getMembers().forEach(member -> {
        ControllerNode node = toControllerNode(member);
        nodes.put(node.id(), node);
        updateState(node, member);
        updateVersion(node, member);
    });
    membershipService.getLocalMember().properties().put(STATE_KEY, ControllerNode.State.ACTIVE.name());
    membershipService.getLocalMember().properties().put(VERSION_KEY, versionService.version().toString());
    localNode = toControllerNode(membershipService.getLocalMember());
    states.put(localNode.id(), ControllerNode.State.ACTIVE);
    versions.put(localNode.id(), versionService.version());
    log.info("Started");
}
Also used : ControllerNode(org.onosproject.cluster.ControllerNode) DefaultControllerNode(org.onosproject.cluster.DefaultControllerNode) Activate(org.osgi.service.component.annotations.Activate)

Aggregations

ControllerNode (org.onosproject.cluster.ControllerNode)42 NodeId (org.onosproject.cluster.NodeId)17 ClusterService (org.onosproject.cluster.ClusterService)14 Activate (org.osgi.service.component.annotations.Activate)11 Set (java.util.Set)10 DefaultControllerNode (org.onosproject.cluster.DefaultControllerNode)10 List (java.util.List)8 Collectors (java.util.stream.Collectors)8 Logger (org.slf4j.Logger)8 LoggerFactory.getLogger (org.slf4j.LoggerFactory.getLogger)8 DeviceId (org.onosproject.net.DeviceId)7 IpAddress (org.onlab.packet.IpAddress)6 Version (org.onosproject.core.Version)6 Component (org.osgi.service.component.annotations.Component)5 Deactivate (org.osgi.service.component.annotations.Deactivate)5 Reference (org.osgi.service.component.annotations.Reference)5 ReferenceCardinality (org.osgi.service.component.annotations.ReferenceCardinality)5 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)4 Collection (java.util.Collection)4 HashSet (java.util.HashSet)4