Search in sources :

Example 6 with ClusterService

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();
}
Also used : ClusterService(org.onosproject.cluster.ClusterService) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ControlPlaneMonitorService(org.onosproject.cpman.ControlPlaneMonitorService) NodeId(org.onosproject.cluster.NodeId) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 7 with ClusterService

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);
            }
        }
    }
}
Also used : ClusterService(org.onosproject.cluster.ClusterService) DeviceId(org.onosproject.net.DeviceId) DeviceService(org.onosproject.net.device.DeviceService) ControllerNode(org.onosproject.cluster.ControllerNode) MastershipService(org.onosproject.mastership.MastershipService)

Example 8 with ClusterService

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;
}
Also used : NodeId(org.onosproject.cluster.NodeId) PartitionAdminService(org.onosproject.store.primitives.PartitionAdminService) PartitionClientInfo(org.onosproject.store.service.PartitionClientInfo) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ControllerNode(org.onosproject.cluster.ControllerNode) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Command(org.apache.karaf.shell.api.action.Command) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) List(java.util.List) Ordering(com.google.common.collect.Ordering) Service(org.apache.karaf.shell.api.action.lifecycle.Service) PartitionInfo(org.onosproject.store.service.PartitionInfo) ClusterService(org.onosproject.cluster.ClusterService) JsonNode(com.fasterxml.jackson.databind.JsonNode) Option(org.apache.karaf.shell.api.action.Option) ClusterService(org.onosproject.cluster.ClusterService) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 9 with ClusterService

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("-------------------------------------------------------------------");
        }
    }
}
Also used : ClusterService(org.onosproject.cluster.ClusterService) NodeId(org.onosproject.cluster.NodeId) ControllerNode(org.onosproject.cluster.ControllerNode) PartitionClientInfo(org.onosproject.store.service.PartitionClientInfo)

Example 10 with ClusterService

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");
}
Also used : ClusterService(org.onosproject.cluster.ClusterService) HashSet(java.util.HashSet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) Version(org.onosproject.core.Version) State(org.onosproject.cluster.ControllerNode.State) Instant(java.time.Instant) NodeId(org.onosproject.cluster.NodeId) ControllerNode(org.onosproject.cluster.ControllerNode) DefaultControllerNode(org.onosproject.cluster.DefaultControllerNode) DefaultControllerNode(org.onosproject.cluster.DefaultControllerNode) ClusterEventListener(org.onosproject.cluster.ClusterEventListener) Activate(org.osgi.service.component.annotations.Activate)

Aggregations

ClusterService (org.onosproject.cluster.ClusterService)25 NodeId (org.onosproject.cluster.NodeId)17 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)8 ControllerNode (org.onosproject.cluster.ControllerNode)8 GET (javax.ws.rs.GET)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 ControlPlaneMonitorService (org.onosproject.cpman.ControlPlaneMonitorService)6 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)5 Set (java.util.Set)4 ExecutorService (java.util.concurrent.ExecutorService)3 Collectors (java.util.stream.Collectors)3 Command (org.apache.karaf.shell.api.action.Command)3 Option (org.apache.karaf.shell.api.action.Option)3 Before (org.junit.Before)3 IpAddress (org.onlab.packet.IpAddress)3 Sets (com.google.common.collect.Sets)2 Instant (java.time.Instant)2 Collection (java.util.Collection)2 Executors.newSingleThreadScheduledExecutor (java.util.concurrent.Executors.newSingleThreadScheduledExecutor)2