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));
}
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;
}
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));
}
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);
}
}
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("-------------------------------------------------------------------");
}
}
}
Aggregations