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