Search in sources :

Example 11 with NodeId

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

the class DistributedLabelResourceStore method destroyDevicePool.

@Override
public boolean destroyDevicePool(DeviceId deviceId) {
    Device device = deviceService.getDevice(deviceId);
    if (device == null) {
        return false;
    }
    NodeId master = mastershipService.getMasterFor(deviceId);
    if (master == null) {
        log.warn("Failed to destroyDevicePool. No master for {}", deviceId);
        return false;
    }
    if (master.equals(clusterService.getLocalNode().id())) {
        return internalDestroy(deviceId);
    }
    log.trace("Forwarding request to {}, which is the primary (master) for device {}", master, deviceId);
    return complete(clusterCommunicator.sendAndReceive(deviceId, LabelResourceMessageSubjects.LABEL_POOL_DESTROYED, SERIALIZER::encode, SERIALIZER::decode, master));
}
Also used : Device(org.onosproject.net.Device) NodeId(org.onosproject.cluster.NodeId)

Example 12 with NodeId

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

the class DistributedLabelResourceStore method releaseToDevicePool.

@Override
public boolean releaseToDevicePool(Multimap<DeviceId, LabelResource> release) {
    Map<DeviceId, Collection<LabelResource>> maps = release.asMap();
    Set<DeviceId> deviceIdSet = maps.keySet();
    LabelResourceRequest request = null;
    for (Iterator<DeviceId> it = deviceIdSet.iterator(); it.hasNext(); ) {
        DeviceId deviceId = it.next();
        Device device = deviceService.getDevice(deviceId);
        if (device == null) {
            continue;
        }
        ImmutableSet<LabelResource> collection = ImmutableSet.copyOf(maps.get(deviceId));
        request = new LabelResourceRequest(deviceId, LabelResourceRequest.Type.RELEASE, 0, collection);
        NodeId master = mastershipService.getMasterFor(deviceId);
        if (master == null) {
            log.warn("Failed to releaseToDevicePool: No master for {}", deviceId);
            return false;
        }
        if (master.equals(clusterService.getLocalNode().id())) {
            return internalRelease(request);
        }
        log.trace("Forwarding request to {}, which is the primary (master) for device {}", master, deviceId);
        return complete(clusterCommunicator.sendAndReceive(request, LabelResourceMessageSubjects.LABEL_POOL_RELEASE, SERIALIZER::encode, SERIALIZER::decode, master));
    }
    return false;
}
Also used : DefaultLabelResource(org.onosproject.incubator.net.resource.label.DefaultLabelResource) LabelResource(org.onosproject.incubator.net.resource.label.LabelResource) DeviceId(org.onosproject.net.DeviceId) LabelResourceRequest(org.onosproject.incubator.net.resource.label.LabelResourceRequest) Device(org.onosproject.net.Device) NodeId(org.onosproject.cluster.NodeId) Collection(java.util.Collection)

Example 13 with NodeId

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

the class DistributedLabelResourceStore method applyFromDevicePool.

@Override
public Collection<LabelResource> applyFromDevicePool(DeviceId deviceId, long applyNum) {
    Device device = deviceService.getDevice(deviceId);
    if (device == null) {
        return Collections.emptyList();
    }
    LabelResourceRequest request = new LabelResourceRequest(deviceId, LabelResourceRequest.Type.APPLY, applyNum, null);
    NodeId master = mastershipService.getMasterFor(deviceId);
    if (master == null) {
        log.warn("Failed to applyFromDevicePool: No master for {}", deviceId);
        return Collections.emptyList();
    }
    if (master.equals(clusterService.getLocalNode().id())) {
        return internalApply(request);
    }
    log.trace("Forwarding request to {}, which is the primary (master) for device {}", master, deviceId);
    return complete(clusterCommunicator.sendAndReceive(request, LabelResourceMessageSubjects.LABEL_POOL_APPLY, SERIALIZER::encode, SERIALIZER::decode, master));
}
Also used : Device(org.onosproject.net.Device) LabelResourceRequest(org.onosproject.incubator.net.resource.label.LabelResourceRequest) NodeId(org.onosproject.cluster.NodeId)

Example 14 with NodeId

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

the class ProxyTestCommand method doExecute.

@Override
protected void doExecute() {
    ProxyTest proxyTest = get(ProxyTest.class);
    TestProxy proxy;
    if ("node".equals(type)) {
        NodeId nodeId = NodeId.nodeId(arg1);
        proxy = proxyTest.getProxyFor(nodeId);
    } else if ("master".equals(type)) {
        DeviceId deviceId = DeviceId.deviceId(arg1);
        proxy = proxyTest.getProxyFor(deviceId);
    } else {
        throw new IllegalArgumentException("Unknown operation type " + type);
    }
    if ("sync".equals(operation)) {
        print("%s", proxy.testSync(arg2));
    } else if ("async".equals(operation)) {
        try {
            print("%s", proxy.testAsync(arg2).get(10, TimeUnit.SECONDS));
        } catch (InterruptedException | ExecutionException | TimeoutException e) {
            throw new IllegalStateException(e);
        }
    } else {
        throw new IllegalArgumentException("Unknown operation " + operation);
    }
}
Also used : DeviceId(org.onosproject.net.DeviceId) NodeId(org.onosproject.cluster.NodeId)

Example 15 with NodeId

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

the class PartitionsListCommand method displayPartitionClients.

/**
 * Displays partition client info as text.
 *
 * @param partitionClientInfo partition client information
 */
private void displayPartitionClients(List<PartitionClientInfo> partitionClientInfo) {
    if (partitionClientInfo.isEmpty()) {
        return;
    }
    ClusterService clusterService = get(ClusterService.class);
    print("-------------------------------------------------------------------");
    print(CLIENT_FMT, "Name", "Servers");
    print("-------------------------------------------------------------------");
    for (PartitionClientInfo info : partitionClientInfo) {
        boolean first = true;
        for (NodeId serverId : Ordering.natural().sortedCopy(info.servers())) {
            ControllerNode server = clusterService.getNode(serverId);
            String serverString = String.format("%s:%d", server.id(), server.tcpPort());
            if (first) {
                print(CLIENT_FMT, info.partitionId(), serverString);
                first = false;
            } else {
                print(CLIENT_FMT, "", serverString);
            }
        }
        if (!first) {
            print("-------------------------------------------------------------------");
        }
    }
}
Also used : ClusterService(org.onosproject.cluster.ClusterService) NodeId(org.onosproject.cluster.NodeId) ControllerNode(org.onosproject.cluster.ControllerNode) PartitionClientInfo(org.onosproject.store.service.PartitionClientInfo)

Aggregations

NodeId (org.onosproject.cluster.NodeId)150 DeviceId (org.onosproject.net.DeviceId)38 ClusterService (org.onosproject.cluster.ClusterService)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