Search in sources :

Example 1 with LabelResourceRequest

use of org.onosproject.incubator.net.resource.label.LabelResourceRequest 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 2 with LabelResourceRequest

use of org.onosproject.incubator.net.resource.label.LabelResourceRequest 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 3 with LabelResourceRequest

use of org.onosproject.incubator.net.resource.label.LabelResourceRequest in project onos by opennetworkinglab.

the class DistributedLabelResourceStore method releaseToGlobalPool.

@Override
public boolean releaseToGlobalPool(Set<LabelResourceId> release) {
    Set<LabelResource> set = new HashSet<>();
    DefaultLabelResource resource = null;
    for (LabelResourceId labelResource : release) {
        resource = new DefaultLabelResource(DeviceId.deviceId(GLOBAL_RESOURCE_POOL_DEVICE_ID), labelResource);
        set.add(resource);
    }
    LabelResourceRequest request = new LabelResourceRequest(DeviceId.deviceId(GLOBAL_RESOURCE_POOL_DEVICE_ID), LabelResourceRequest.Type.RELEASE, 0, ImmutableSet.copyOf(set));
    return this.internalRelease(request);
}
Also used : DefaultLabelResource(org.onosproject.incubator.net.resource.label.DefaultLabelResource) LabelResource(org.onosproject.incubator.net.resource.label.LabelResource) LabelResourceRequest(org.onosproject.incubator.net.resource.label.LabelResourceRequest) DefaultLabelResource(org.onosproject.incubator.net.resource.label.DefaultLabelResource) LabelResourceId(org.onosproject.incubator.net.resource.label.LabelResourceId) HashSet(java.util.HashSet)

Aggregations

LabelResourceRequest (org.onosproject.incubator.net.resource.label.LabelResourceRequest)3 NodeId (org.onosproject.cluster.NodeId)2 DefaultLabelResource (org.onosproject.incubator.net.resource.label.DefaultLabelResource)2 LabelResource (org.onosproject.incubator.net.resource.label.LabelResource)2 Device (org.onosproject.net.Device)2 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 LabelResourceId (org.onosproject.incubator.net.resource.label.LabelResourceId)1 DeviceId (org.onosproject.net.DeviceId)1