Search in sources :

Example 21 with ControllerNode

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

the class Topo2Jsonifier method jsonCommon.

private ObjectNode jsonCommon(UiClusterMember member) {
    ControllerNode.State state = clusterService.getState(member.id());
    ControllerNode node = member.backingNode();
    if (node != null) {
        IpAddress nodeIp = member.backingNode().ip();
        return objectNode().put("id", member.idAsString()).put("ip", nodeIp != null ? nodeIp.toString() : node.host()).put("online", state.isActive()).put("ready", state.isReady());
    }
    return objectNode().put("id", member.idAsString()).put("ip", "NONE").put("online", false).put("ready", false);
}
Also used : ControllerNode(org.onosproject.cluster.ControllerNode) IpAddress(org.onlab.packet.IpAddress)

Example 22 with ControllerNode

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

the class TopologyViewMessageHandler method sendAllInstances.

// Sends all controller nodes to the client as node-added messages.
private void sendAllInstances(String messageType) {
    List<ControllerNode> nodes = new ArrayList<>(services.cluster().getNodes());
    nodes.sort(NODE_COMPARATOR);
    for (ControllerNode node : nodes) {
        sendMessage(instanceMessage(new ClusterEvent(INSTANCE_ADDED, node), messageType));
    }
}
Also used : ClusterEvent(org.onosproject.cluster.ClusterEvent) ArrayList(java.util.ArrayList) ControllerNode(org.onosproject.cluster.ControllerNode)

Example 23 with ControllerNode

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

the class DistributedApplicationStore method fetchBits.

/**
 * Fetches the bits from the cluster peers.
 */
private void fetchBits(Application app, boolean delegateInstallation) {
    ControllerNode localNode = clusterService.getLocalNode();
    CountDownLatch latch = new CountDownLatch(1);
    // FIXME: send message with name & version to make sure we don't get served old bits
    log.info("Downloading bits for application {} for version : {}", app.id().name(), app.version());
    for (ControllerNode node : clusterService.getNodes()) {
        if (latch.getCount() == 0) {
            break;
        }
        if (node.equals(localNode)) {
            continue;
        }
        clusterCommunicator.sendAndReceive(app.id().name(), APP_BITS_REQUEST, s -> s.getBytes(Charsets.UTF_8), Function.identity(), node.id()).whenCompleteAsync((bits, error) -> {
            if (error == null && latch.getCount() > 0) {
                saveApplication(new ByteArrayInputStream(bits));
                log.info("Downloaded bits for application {} from node {}", app.id().name(), node.id());
                latch.countDown();
                if (delegateInstallation) {
                    if (log.isTraceEnabled()) {
                        log.trace("Delegate installation for {}", app.id());
                    }
                    notifyDelegate(new ApplicationEvent(APP_INSTALLED, app));
                }
            } else if (error != null) {
                log.warn("Unable to fetch bits for application {} from node {}", app.id().name(), node.id());
            }
        }, messageHandlingExecutor);
    }
    try {
        if (!latch.await(FETCH_TIMEOUT_MS, MILLISECONDS)) {
            log.warn("Unable to fetch bits for application {}", app.id().name());
        }
    } catch (InterruptedException e) {
        log.warn("Interrupted while fetching bits for application {}", app.id().name());
        Thread.currentThread().interrupt();
    }
}
Also used : ConsistentMap(org.onosproject.store.service.ConsistentMap) CoreService(org.onosproject.core.CoreService) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) Executors.newSingleThreadScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor) ApplicationIdStore(org.onosproject.app.ApplicationIdStore) StorageService(org.onosproject.store.service.StorageService) ByteArrayInputStream(java.io.ByteArrayInputStream) ApplicationEvent(org.onosproject.app.ApplicationEvent) ApplicationId(org.onosproject.core.ApplicationId) MessageSubject(org.onosproject.store.cluster.messaging.MessageSubject) Version(org.onosproject.core.Version) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) ApplicationException(org.onosproject.app.ApplicationException) Serializer(org.onosproject.store.service.Serializer) ImmutableSet(com.google.common.collect.ImmutableSet) Deactivate(org.osgi.service.component.annotations.Deactivate) Set(java.util.Set) Executors.newSingleThreadExecutor(java.util.concurrent.Executors.newSingleThreadExecutor) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Versioned(org.onosproject.store.service.Versioned) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) APP_ACTIVATED(org.onosproject.app.ApplicationEvent.Type.APP_ACTIVATED) APP_UNINSTALLED(org.onosproject.app.ApplicationEvent.Type.APP_UNINSTALLED) ClusterCommunicationService(org.onosproject.store.cluster.messaging.ClusterCommunicationService) Optional(java.util.Optional) ClusterService(org.onosproject.cluster.ClusterService) RevisionType(org.onosproject.store.service.RevisionType) DEACTIVATED(org.onosproject.store.app.DistributedApplicationStore.InternalState.DEACTIVATED) ApplicationState(org.onosproject.app.ApplicationState) StorageException(org.onosproject.store.service.StorageException) APP_PERMISSIONS_CHANGED(org.onosproject.app.ApplicationEvent.Type.APP_PERMISSIONS_CHANGED) INSTALLED(org.onosproject.store.app.DistributedApplicationStore.InternalState.INSTALLED) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Multimap(com.google.common.collect.Multimap) Tools.randomDelay(org.onlab.util.Tools.randomDelay) Function(java.util.function.Function) ControllerNode(org.onosproject.cluster.ControllerNode) MapEventListener(org.onosproject.store.service.MapEventListener) Permission(org.onosproject.security.Permission) Component(org.osgi.service.component.annotations.Component) APP_DEACTIVATED(org.onosproject.app.ApplicationEvent.Type.APP_DEACTIVATED) Lists(com.google.common.collect.Lists) APP_INSTALLED(org.onosproject.app.ApplicationEvent.Type.APP_INSTALLED) ACTIVATED(org.onosproject.store.app.DistributedApplicationStore.InternalState.ACTIVATED) Multimaps.newSetMultimap(com.google.common.collect.Multimaps.newSetMultimap) VersionService(org.onosproject.core.VersionService) ApplicationDescription(org.onosproject.app.ApplicationDescription) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Activate(org.osgi.service.component.annotations.Activate) ExecutorService(java.util.concurrent.ExecutorService) Multimaps.synchronizedSetMultimap(com.google.common.collect.Multimaps.synchronizedSetMultimap) Application(org.onosproject.core.Application) DefaultApplication(org.onosproject.core.DefaultApplication) Charsets(com.google.common.base.Charsets) Logger(org.slf4j.Logger) Topic(org.onosproject.store.service.Topic) MoreObjects(com.google.common.base.MoreObjects) Throwables(com.google.common.base.Throwables) IOException(java.io.IOException) ApplicationStoreDelegate(org.onosproject.app.ApplicationStoreDelegate) Maps(com.google.common.collect.Maps) Status(org.onosproject.store.service.DistributedPrimitive.Status) ApplicationArchive(org.onosproject.common.app.ApplicationArchive) ByteStreams.toByteArray(com.google.common.io.ByteStreams.toByteArray) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) ApplicationStore(org.onosproject.app.ApplicationStore) MapEvent(org.onosproject.store.service.MapEvent) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Preconditions(com.google.common.base.Preconditions) Reference(org.osgi.service.component.annotations.Reference) InputStream(java.io.InputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ApplicationEvent(org.onosproject.app.ApplicationEvent) ControllerNode(org.onosproject.cluster.ControllerNode) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 24 with ControllerNode

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

the class GossipIntentStore method getRandomNode.

private List<NodeId> getRandomNode() {
    NodeId me = clusterService.getLocalNode().id();
    List<NodeId> nodes = clusterService.getNodes().stream().map(ControllerNode::id).filter(node -> !Objects.equals(node, me)).collect(Collectors.toList());
    if (nodes.isEmpty()) {
        return ImmutableList.of();
    }
    return ImmutableList.of(nodes.get(RandomUtils.nextInt(nodes.size())));
}
Also used : IntentState(org.onosproject.net.intent.IntentState) EventuallyConsistentMapBuilder(org.onosproject.store.service.EventuallyConsistentMapBuilder) Backtrace(org.onlab.util.Backtrace) RandomUtils(org.apache.commons.lang.math.RandomUtils) StorageService(org.onosproject.store.service.StorageService) PURGE_REQ(org.onosproject.net.intent.IntentState.PURGE_REQ) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) WorkPartitionService(org.onosproject.net.intent.WorkPartitionService) NodeId(org.onosproject.cluster.NodeId) Tools.get(org.onlab.util.Tools.get) EventuallyConsistentMapEvent(org.onosproject.store.service.EventuallyConsistentMapEvent) Deactivate(org.osgi.service.component.annotations.Deactivate) Collection(java.util.Collection) WallClockTimestamp(org.onosproject.store.service.WallClockTimestamp) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) Key(org.onosproject.net.intent.Key) List(java.util.List) GIS_PERSISTENCE_ENABLED_DEFAULT(org.onosproject.store.OsgiPropertyConstants.GIS_PERSISTENCE_ENABLED_DEFAULT) Optional(java.util.Optional) ClusterService(org.onosproject.cluster.ClusterService) GIS_PERSISTENCE_ENABLED(org.onosproject.store.OsgiPropertyConstants.GIS_PERSISTENCE_ENABLED) Dictionary(java.util.Dictionary) IntentEvent(org.onosproject.net.intent.IntentEvent) ComponentContext(org.osgi.service.component.ComponentContext) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) KryoNamespace(org.onlab.util.KryoNamespace) IntentData(org.onosproject.net.intent.IntentData) ControllerNode(org.onosproject.cluster.ControllerNode) Component(org.osgi.service.component.annotations.Component) ImmutableList(com.google.common.collect.ImmutableList) Intent(org.onosproject.net.intent.Intent) Timestamp(org.onosproject.store.Timestamp) Activate(org.osgi.service.component.annotations.Activate) EventuallyConsistentMap(org.onosproject.store.service.EventuallyConsistentMap) EventuallyConsistentMapListener(org.onosproject.store.service.EventuallyConsistentMapListener) ComponentConfigService(org.onosproject.cfg.ComponentConfigService) Logger(org.slf4j.Logger) Properties(java.util.Properties) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) AtomicLong(java.util.concurrent.atomic.AtomicLong) IntentStoreDelegate(org.onosproject.net.intent.IntentStoreDelegate) MultiValuedTimestamp(org.onosproject.store.service.MultiValuedTimestamp) IntentStore(org.onosproject.net.intent.IntentStore) AbstractStore(org.onosproject.store.AbstractStore) Modified(org.osgi.service.component.annotations.Modified) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Reference(org.osgi.service.component.annotations.Reference) NodeId(org.onosproject.cluster.NodeId) ControllerNode(org.onosproject.cluster.ControllerNode)

Example 25 with ControllerNode

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

the class ClusterCommunicationManager method doUnicast.

private CompletableFuture<Void> doUnicast(MessageSubject subject, byte[] payload, NodeId toNodeId) {
    ControllerNode node = clusterService.getNode(toNodeId);
    checkArgument(node != null, "Unknown nodeId: %s", toNodeId);
    Endpoint nodeEp = new Endpoint(node.ip(), node.tcpPort());
    MeteringAgent.Context context = subjectMeteringAgent.startTimer(subject.toString() + ONE_WAY_SUFFIX);
    return messagingService.sendAsync(nodeEp, subject.toString(), payload).whenComplete((r, e) -> context.stop(e));
}
Also used : Endpoint(org.onosproject.store.cluster.messaging.Endpoint) ControllerNode(org.onosproject.cluster.ControllerNode) MeteringAgent(org.onosproject.utils.MeteringAgent)

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