use of org.onosproject.cluster.ClusterService in project onos by opennetworkinglab.
the class ControlMetricsWebResource method memoryMetrics.
/**
* Returns memory metrics.
*
* @return memory metrics
* @onos.rsModel MemoryMetrics
*/
@GET
@Path("memory_metrics")
@Produces(MediaType.APPLICATION_JSON)
public Response memoryMetrics() {
ObjectNode root = mapper().createObjectNode();
ControlPlaneMonitorService monitorService = get(ControlPlaneMonitorService.class);
ClusterService clusterService = get(ClusterService.class);
NodeId localNodeId = clusterService.getLocalNode().id();
metricsStats(monitorService, localNodeId, MEMORY_METRICS, root);
return ok(root).build();
}
use of org.onosproject.cluster.ClusterService 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);
}
}
}
}
use of org.onosproject.cluster.ClusterService in project onos by opennetworkinglab.
the class PartitionsListCommand method jsonForClientInfo.
/**
* Converts partition client info into a JSON object.
*
* @param partitionClientInfo partition client descriptions
*/
private JsonNode jsonForClientInfo(List<PartitionClientInfo> partitionClientInfo) {
ObjectMapper mapper = new ObjectMapper();
ArrayNode partitions = mapper.createArrayNode();
ClusterService clusterService = get(ClusterService.class);
// Create a JSON node for each partition client
partitionClientInfo.forEach(info -> {
ObjectNode partition = mapper.createObjectNode();
// Add each member to the "servers" array for this partition
ArrayNode servers = partition.putArray("servers");
info.servers().stream().map(clusterService::getNode).map(node -> String.format("%s:%d", node.ip(), node.tcpPort())).forEach(servers::add);
// Complete the partition attributes and add it to the array
partition.put("partitionId", info.partitionId().toString());
partitions.add(partition);
});
return partitions;
}
use of org.onosproject.cluster.ClusterService 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("-------------------------------------------------------------------");
}
}
}
use of org.onosproject.cluster.ClusterService in project onos by opennetworkinglab.
the class SimpleMastershipStore method activate.
@Activate
public void activate() {
if (clusterService == null) {
// just for ease of unit test
final ControllerNode instance = new DefaultControllerNode(new NodeId("local"), IpAddress.valueOf("127.0.0.1"));
clusterService = new ClusterService() {
private final Instant creationTime = Instant.now();
@Override
public ControllerNode getLocalNode() {
return instance;
}
@Override
public Set<ControllerNode> getNodes() {
return ImmutableSet.of(instance);
}
@Override
public Set<Node> getConsensusNodes() {
return ImmutableSet.of();
}
@Override
public ControllerNode getNode(NodeId nodeId) {
if (instance.id().equals(nodeId)) {
return instance;
}
return null;
}
@Override
public State getState(NodeId nodeId) {
if (instance.id().equals(nodeId)) {
return State.ACTIVE;
} else {
return State.INACTIVE;
}
}
@Override
public Version getVersion(NodeId nodeId) {
if (instance.id().equals(nodeId)) {
return versionService.version();
}
return null;
}
@Override
public Instant getLastUpdatedInstant(NodeId nodeId) {
return creationTime;
}
@Override
public void addListener(ClusterEventListener listener) {
}
@Override
public void removeListener(ClusterEventListener listener) {
}
};
}
log.info("Started");
}
Aggregations