Search in sources :

Example 1 with ControllerNode

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

the class ControlMetricsResourceTest method setUpTest.

/**
 * Sets up the global values for all the tests.
 */
@Before
public void setUpTest() {
    final CodecManager codecService = new CodecManager();
    codecService.activate();
    codecService.registerCodec(ControlLoadSnapshot.class, new ControlLoadSnapshotCodec());
    ServiceDirectory testDirectory = new TestServiceDirectory().add(ControlPlaneMonitorService.class, mockControlPlaneMonitorService).add(ClusterService.class, mockClusterService).add(CodecService.class, codecService);
    setServiceDirectory(testDirectory);
    nodeId = new NodeId("1");
    mockControlLoad = new MockControlLoad();
    ControllerNode mockControllerNode = new MockControllerNode(nodeId);
    expect(mockClusterService.getLocalNode()).andReturn(mockControllerNode).anyTimes();
    replay(mockClusterService);
}
Also used : ClusterService(org.onosproject.cluster.ClusterService) ControlLoadSnapshotCodec(org.onosproject.cpman.codec.ControlLoadSnapshotCodec) ServiceDirectory(org.onlab.osgi.ServiceDirectory) TestServiceDirectory(org.onlab.osgi.TestServiceDirectory) TestServiceDirectory(org.onlab.osgi.TestServiceDirectory) NodeId(org.onosproject.cluster.NodeId) ControllerNode(org.onosproject.cluster.ControllerNode) CodecManager(org.onosproject.codec.impl.CodecManager) Before(org.junit.Before)

Example 2 with ControllerNode

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

the class PrimitivePerfApp method startTestRun.

private void startTestRun() {
    if (running) {
        return;
    }
    sampleCollector.clearSamples();
    startTime = System.currentTimeMillis();
    currentStartTime = startTime;
    currentCounter = new AtomicLong();
    overallCounter = new AtomicLong();
    reporterTask = new ReporterTask();
    reportTimer.scheduleAtFixedRate(reporterTask, REPORT_PERIOD - currentTimeMillis() % REPORT_PERIOD, REPORT_PERIOD);
    running = true;
    Map<String, ControllerNode> nodes = new TreeMap<>();
    for (ControllerNode node : clusterService.getNodes()) {
        nodes.put(node.id().id(), node);
    }
    // Compute the index of the local node in a sorted list of nodes.
    List<String> sortedNodes = Lists.newArrayList(nodes.keySet());
    int nodeCount = nodes.size();
    int index = sortedNodes.indexOf(nodeId.id());
    // Count the number of workers assigned to this node.
    int workerCount = 0;
    for (int i = 1; i <= numClients; i++) {
        if (i % nodeCount == index) {
            workerCount++;
        }
    }
    // Create a worker pool and start the workers for this node.
    if (workerCount > 0) {
        String[] keys = createStrings(keyLength, numKeys);
        String[] values = createStrings(valueLength, numValues);
        workers = Executors.newFixedThreadPool(workerCount, groupedThreads("onos/primitive-perf", "worker-%d"));
        for (int i = 0; i < workerCount; i++) {
            if (deterministic) {
                workers.submit(new DeterministicRunner(keys, values));
            } else {
                workers.submit(new NonDeterministicRunner(keys, values));
            }
        }
    }
    log.info("Started test run");
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) ControllerNode(org.onosproject.cluster.ControllerNode) TreeMap(java.util.TreeMap)

Example 3 with ControllerNode

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

the class VirtualNetworkMastershipManager method balanceRoles.

@Override
public void balanceRoles() {
    // FIXME: More advanced logic for balancing virtual network roles.
    List<ControllerNode> nodes = clusterService.getNodes().stream().filter(n -> clusterService.getState(n.id()).equals(ControllerNode.State.ACTIVE)).collect(Collectors.toList());
    nodes.sort(Comparator.comparing(ControllerNode::id));
    // Pick a node using network Id,
    NodeId masterNode = nodes.get((int) ((networkId.id() - 1) % nodes.size())).id();
    List<CompletableFuture<Void>> setRoleFutures = Lists.newLinkedList();
    for (VirtualDevice device : manager.getVirtualDevices(networkId)) {
        setRoleFutures.add(setRole(masterNode, device.id(), MastershipRole.MASTER));
    }
    CompletableFuture<Void> balanceRolesFuture = CompletableFuture.allOf(setRoleFutures.toArray(new CompletableFuture[setRoleFutures.size()]));
    Futures.getUnchecked(balanceRolesFuture);
}
Also used : MetricsUtil.stopTimer(org.onlab.metrics.MetricsUtil.stopTimer) MetricsService(org.onlab.metrics.MetricsService) CompletableFuture(java.util.concurrent.CompletableFuture) ControllerNode(org.onosproject.cluster.ControllerNode) MetricsHelper(org.onosproject.core.MetricsHelper) MastershipEvent(org.onosproject.mastership.MastershipEvent) Lists(com.google.common.collect.Lists) VirtualNetworkService(org.onosproject.incubator.net.virtual.VirtualNetworkService) NetworkId(org.onosproject.incubator.net.virtual.NetworkId) MastershipService(org.onosproject.mastership.MastershipService) NodeId(org.onosproject.cluster.NodeId) Logger(org.slf4j.Logger) MetricsUtil.startTimer(org.onlab.metrics.MetricsUtil.startTimer) MastershipRole(org.onosproject.net.MastershipRole) VirtualNetworkMastershipStore(org.onosproject.incubator.net.virtual.VirtualNetworkMastershipStore) MastershipTermService(org.onosproject.mastership.MastershipTermService) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) MastershipInfo(org.onosproject.mastership.MastershipInfo) Set(java.util.Set) Collectors(java.util.stream.Collectors) MastershipTerm(org.onosproject.mastership.MastershipTerm) Futures(com.google.common.util.concurrent.Futures) VirtualDevice(org.onosproject.incubator.net.virtual.VirtualDevice) List(java.util.List) AbstractVirtualListenerManager(org.onosproject.incubator.net.virtual.event.AbstractVirtualListenerManager) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Timer(com.codahale.metrics.Timer) ClusterService(org.onosproject.cluster.ClusterService) RoleInfo(org.onosproject.cluster.RoleInfo) MastershipListener(org.onosproject.mastership.MastershipListener) DeviceId(org.onosproject.net.DeviceId) Comparator(java.util.Comparator) MastershipAdminService(org.onosproject.mastership.MastershipAdminService) MastershipStoreDelegate(org.onosproject.mastership.MastershipStoreDelegate) CompletableFuture(java.util.concurrent.CompletableFuture) NodeId(org.onosproject.cluster.NodeId) VirtualDevice(org.onosproject.incubator.net.virtual.VirtualDevice) ControllerNode(org.onosproject.cluster.ControllerNode)

Example 4 with ControllerNode

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

the class MastersListCommand method json.

// Produces JSON structure.
private JsonNode json(ClusterService service, MastershipService mastershipService, List<ControllerNode> nodes) {
    ObjectMapper mapper = new ObjectMapper();
    ArrayNode result = mapper.createArrayNode();
    for (ControllerNode node : nodes) {
        List<DeviceId> ids = Lists.newArrayList(mastershipService.getDevicesOf(node.id()));
        result.add(mapper.createObjectNode().put("id", node.id().toString()).put("size", ids.size()).set("devices", json(mapper, ids)));
    }
    return result;
}
Also used : DeviceId(org.onosproject.net.DeviceId) ControllerNode(org.onosproject.cluster.ControllerNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 5 with ControllerNode

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

the class MastersListCommand method doExecute.

@Override
protected void doExecute() {
    ClusterService service = get(ClusterService.class);
    MastershipService mastershipService = get(MastershipService.class);
    DeviceService deviceService = get(DeviceService.class);
    List<ControllerNode> nodes = newArrayList(service.getNodes());
    Collections.sort(nodes, Comparators.NODE_COMPARATOR);
    if (outputJson()) {
        print("%s", json(service, mastershipService, nodes));
    } else {
        for (ControllerNode node : nodes) {
            List<DeviceId> ids = Lists.newArrayList(mastershipService.getDevicesOf(node.id()));
            ids.removeIf(did -> deviceService.getDevice(did) == null);
            Collections.sort(ids, Comparators.ELEMENT_ID_COMPARATOR);
            print("%s: %d devices", node.id(), ids.size());
            for (DeviceId deviceId : ids) {
                print("  %s", deviceId);
            }
        }
    }
}
Also used : ClusterService(org.onosproject.cluster.ClusterService) DeviceId(org.onosproject.net.DeviceId) DeviceService(org.onosproject.net.device.DeviceService) ControllerNode(org.onosproject.cluster.ControllerNode) MastershipService(org.onosproject.mastership.MastershipService)

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