Search in sources :

Example 91 with NodeId

use of org.onosproject.cluster.NodeId 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 92 with NodeId

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

the class ECLinkStore method createOrUpdateLink.

@Override
public LinkEvent createOrUpdateLink(ProviderId providerId, LinkDescription linkDescription) {
    final DeviceId dstDeviceId = linkDescription.dst().deviceId();
    final NodeId dstNodeId = mastershipService.getMasterFor(dstDeviceId);
    // otherwise signal the actual master.
    if (clusterService.getLocalNode().id().equals(dstNodeId)) {
        LinkKey linkKey = linkKey(linkDescription.src(), linkDescription.dst());
        Provided<LinkKey> internalLinkKey = getProvided(linkKey, providerId);
        if (internalLinkKey == null) {
            return null;
        }
        linkDescriptions.compute(internalLinkKey, (k, v) -> createOrUpdateLinkInternal(v, linkDescription));
        return refreshLinkCache(linkKey);
    } else {
        // Forwarding was added as a workaround for ONOS-490
        if (!"cfg".equals(providerId.scheme()) && !"null".equals(providerId.scheme())) {
            return null;
        }
        // Proper fix is to implement forwarding to master on ConfigProvider
        if (dstNodeId == null) {
            return null;
        }
        return Futures.getUnchecked(clusterCommunicator.sendAndReceive(new Provided<>(linkDescription, providerId), LINK_INJECT_MESSAGE, SERIALIZER::encode, SERIALIZER::decode, dstNodeId));
    }
}
Also used : LinkKey(org.onosproject.net.LinkKey) DeviceId(org.onosproject.net.DeviceId) NodeId(org.onosproject.cluster.NodeId)

Example 93 with NodeId

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

the class DistributedPacketStore method emit.

@Override
public void emit(OutboundPacket packet) {
    NodeId myId = clusterService.getLocalNode().id();
    NodeId master = mastershipService.getMasterFor(packet.sendThrough());
    if (master == null) {
        return;
    }
    if (myId.equals(master)) {
        notifyDelegate(new PacketEvent(Type.EMIT, packet));
        return;
    }
    communicationService.unicast(packet, PACKET_OUT_SUBJECT, SERIALIZER::encode, master).whenComplete((r, error) -> {
        if (error != null) {
            log.warn("Failed to send packet-out to {}", master, error);
        }
    });
}
Also used : NodeId(org.onosproject.cluster.NodeId) PacketEvent(org.onosproject.net.packet.PacketEvent)

Example 94 with NodeId

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

the class ControlPlaneMonitorTest method setup.

/**
 * Sets up the services required by control plane monitor.
 */
@Before
public void setup() {
    monitor = new ControlPlaneMonitor();
    mockCommunicationService = new ClusterCommunicationServiceAdapter();
    monitor.communicationService = mockCommunicationService;
    nodeId = new NodeId("1");
    mockControllerNode = new MockControllerNode(nodeId);
    mockClusterService = createMock(ClusterService.class);
    monitor.clusterService = mockClusterService;
    expect(mockClusterService.getNode(anyObject())).andReturn(mockControllerNode).anyTimes();
    expect(mockClusterService.getLocalNode()).andReturn(mockControllerNode).anyTimes();
    replay(mockClusterService);
    monitor.activate();
}
Also used : ClusterService(org.onosproject.cluster.ClusterService) NodeId(org.onosproject.cluster.NodeId) ClusterCommunicationServiceAdapter(org.onosproject.store.cluster.messaging.ClusterCommunicationServiceAdapter) Before(org.junit.Before)

Example 95 with NodeId

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

the class ControlPlaneMonitorTest method testNetworkMetric.

/**
 * Tests network metric update and load function.
 */
@Test
public void testNetworkMetric() {
    MetricValue mv = new MetricValue.Builder().load(10).add();
    Set<String> set = ImmutableSet.of("eth0", "eth1");
    set.forEach(network -> NETWORK_METRICS.forEach(cmt -> testUpdateMetricWithResource(cmt, mv, network)));
    set.forEach(network -> NETWORK_METRICS.forEach(cmt -> testLoadMetricWithResource(nodeId, cmt, mv, network)));
}
Also used : CONTROL_MESSAGE_METRICS(org.onosproject.cpman.ControlResource.CONTROL_MESSAGE_METRICS) ControllerNode(org.onosproject.cluster.ControllerNode) Assert.assertThat(org.junit.Assert.assertThat) ControlMetric(org.onosproject.cpman.ControlMetric) ClusterCommunicationServiceAdapter(org.onosproject.store.cluster.messaging.ClusterCommunicationServiceAdapter) MEMORY_METRICS(org.onosproject.cpman.ControlResource.MEMORY_METRICS) Type(org.onosproject.cpman.ControlResource.Type) EasyMock.replay(org.easymock.EasyMock.replay) EasyMock.createMock(org.easymock.EasyMock.createMock) MetricValue(org.onosproject.cpman.MetricValue) Before(org.junit.Before) IpAddress(org.onlab.packet.IpAddress) CPU_METRICS(org.onosproject.cpman.ControlResource.CPU_METRICS) NodeId(org.onosproject.cluster.NodeId) EasyMock.anyObject(org.easymock.EasyMock.anyObject) ImmutableSet(com.google.common.collect.ImmutableSet) ControlMetricType(org.onosproject.cpman.ControlMetricType) NETWORK_METRICS(org.onosproject.cpman.ControlResource.NETWORK_METRICS) Set(java.util.Set) Test(org.junit.Test) EasyMock.expect(org.easymock.EasyMock.expect) ExecutionException(java.util.concurrent.ExecutionException) ClusterCommunicationService(org.onosproject.store.cluster.messaging.ClusterCommunicationService) Optional(java.util.Optional) DISK_METRICS(org.onosproject.cpman.ControlResource.DISK_METRICS) ClusterService(org.onosproject.cluster.ClusterService) Matchers.is(org.hamcrest.Matchers.is) DeviceId(org.onosproject.net.DeviceId) MetricValue(org.onosproject.cpman.MetricValue) Test(org.junit.Test)

Aggregations

NodeId (org.onosproject.cluster.NodeId)145 ClusterService (org.onosproject.cluster.ClusterService)36 DeviceId (org.onosproject.net.DeviceId)36 Set (java.util.Set)26 MastershipRole (org.onosproject.net.MastershipRole)23 ControllerNode (org.onosproject.cluster.ControllerNode)22 Test (org.junit.Test)18 Activate (org.osgi.service.component.annotations.Activate)18 List (java.util.List)16 MastershipService (org.onosproject.mastership.MastershipService)15 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)13 Map (java.util.Map)12 ImmutableSet (com.google.common.collect.ImmutableSet)11 ArrayList (java.util.ArrayList)11 Collectors (java.util.stream.Collectors)11 HashSet (java.util.HashSet)10 Optional (java.util.Optional)10 ClusterCommunicationService (org.onosproject.store.cluster.messaging.ClusterCommunicationService)10 Component (org.osgi.service.component.annotations.Component)9 Deactivate (org.osgi.service.component.annotations.Deactivate)9