Search in sources :

Example 76 with NodeId

use of org.onosproject.cluster.NodeId in project onos by opennetworkinglab.

the class DefaultInfluxDbMetricsRetriever method metricsByName.

@Override
public Map<NodeId, InfluxMetric> metricsByName(String metricName) {
    Map<NodeId, InfluxMetric> map = Maps.newHashMap();
    String queryPrefix = new StringBuilder().append("SELECT m1_rate FROM").append(database).append(METRIC_DELIMITER).append(quote(DEFAULT_POLICY)).append(METRIC_DELIMITER).toString();
    String querySuffix = new StringBuilder().append(" LIMIT 1").toString();
    allMetricNames().keySet().forEach(nodeId -> {
        String queryString = new StringBuilder().append(queryPrefix).append(quote(nodeId + METRIC_DELIMITER + metricName)).append(querySuffix).toString();
        Query query = new Query(queryString, database);
        List<QueryResult.Result> results = influxDB.query(query).getResults();
        if (results != null && results.get(0) != null && results.get(0).getSeries() != null) {
            InfluxMetric metric = new DefaultInfluxMetric.Builder().time((String) results.get(0).getSeries().get(0).getValues().get(0).get(0)).oneMinRate((Double) results.get(0).getSeries().get(0).getValues().get(0).get(1)).build();
            map.putIfAbsent(nodeId, metric);
        }
    });
    return map;
}
Also used : Query(org.influxdb.dto.Query) NodeId(org.onosproject.cluster.NodeId) QueryResult(org.influxdb.dto.QueryResult)

Example 77 with NodeId

use of org.onosproject.cluster.NodeId in project onos by opennetworkinglab.

the class DefaultInfluxDbMetricsRetriever method allMetricNames.

/**
 * Returns all metric names that bound with node identification.
 *
 * @return all metric names
 */
protected Map<NodeId, Set<String>> allMetricNames() {
    Map<NodeId, Set<String>> metricNameMap = Maps.newHashMap();
    Query query = new Query("SHOW MEASUREMENTS", database);
    List<QueryResult.Result> results = influxDB.query(query).getResults();
    List<List<Object>> rawMetricNames = results.get(0).getSeries().get(0).getValues();
    rawMetricNames.forEach(rawMetricName -> {
        String nodeIdStr = getNodeId(strip(rawMetricName.toString()));
        if (nodeIdStr != null) {
            NodeId nodeId = NodeId.nodeId(nodeIdStr);
            String metricName = getMetricName(strip(rawMetricName.toString()));
            if (!metricNameMap.containsKey(nodeId)) {
                metricNameMap.putIfAbsent(nodeId, Sets.newHashSet());
            }
            if (metricName != null) {
                metricNameMap.get(nodeId).add(metricName);
            }
        }
    });
    return metricNameMap;
}
Also used : Set(java.util.Set) Query(org.influxdb.dto.Query) NodeId(org.onosproject.cluster.NodeId) List(java.util.List) QueryResult(org.influxdb.dto.QueryResult)

Example 78 with NodeId

use of org.onosproject.cluster.NodeId in project onos by opennetworkinglab.

the class RegionUpdateCommand method doExecute.

@Override
protected void doExecute() {
    RegionService regionService = get(RegionService.class);
    RegionAdminService regionAdminService = get(RegionAdminService.class);
    RegionId regionId = RegionId.regionId(id);
    if (regionService.getRegion(regionId) == null) {
        print("The region with id %s does not exist.", regionId);
        return;
    }
    List<Set<NodeId>> masters = Lists.newArrayList();
    Set<NodeId> nodeIds = Sets.newHashSet();
    for (String masterArg : masterArgs) {
        if ("/".equals(masterArg)) {
            masters.add(nodeIds);
            nodeIds = Sets.newHashSet();
        } else {
            nodeIds.add(NodeId.nodeId(masterArg));
        }
    }
    masters.add(nodeIds);
    regionAdminService.updateRegion(regionId, name, REGION_TYPE_MAP.get(type), masters);
    print("Region with id %s is successfully updated.", regionId);
}
Also used : RegionAdminService(org.onosproject.net.region.RegionAdminService) Set(java.util.Set) NodeId(org.onosproject.cluster.NodeId) RegionService(org.onosproject.net.region.RegionService) RegionId(org.onosproject.net.region.RegionId)

Example 79 with NodeId

use of org.onosproject.cluster.NodeId in project onos by opennetworkinglab.

the class SimpleMastershipStore method getMastership.

@Override
public MastershipInfo getMastership(DeviceId deviceId) {
    ImmutableMap.Builder<NodeId, MastershipRole> roleBuilder = ImmutableMap.builder();
    NodeId master = masterMap.get(deviceId);
    if (master != null) {
        roleBuilder.put(master, MastershipRole.MASTER);
    }
    backups.getOrDefault(deviceId, Collections.emptyList()).forEach(nodeId -> roleBuilder.put(nodeId, MastershipRole.STANDBY));
    return new MastershipInfo(termMap.getOrDefault(deviceId, new AtomicInteger(NOTHING)).get(), Optional.ofNullable(master), roleBuilder.build());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NodeId(org.onosproject.cluster.NodeId) MastershipInfo(org.onosproject.mastership.MastershipInfo) MastershipRole(org.onosproject.net.MastershipRole) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 80 with NodeId

use of org.onosproject.cluster.NodeId in project onos by opennetworkinglab.

the class SimpleMastershipStore method relinquishRole.

@Override
public synchronized CompletableFuture<MastershipEvent> relinquishRole(NodeId nodeId, DeviceId deviceId) {
    MastershipRole role = getRole(nodeId, deviceId);
    switch(role) {
        case MASTER:
            NodeId backup = reelect(deviceId, nodeId);
            masterMap.put(deviceId, backup);
            incrementTerm(deviceId);
            return CompletableFuture.completedFuture(new MastershipEvent(MASTER_CHANGED, deviceId, getMastership(deviceId)));
        case STANDBY:
            if (removeFromBackups(deviceId, nodeId)) {
                return CompletableFuture.completedFuture(new MastershipEvent(BACKUPS_CHANGED, deviceId, getMastership(deviceId)));
            }
            break;
        case NONE:
            break;
        default:
            log.warn("unknown Mastership Role {}", role);
    }
    return CompletableFuture.completedFuture(null);
}
Also used : MastershipEvent(org.onosproject.mastership.MastershipEvent) NodeId(org.onosproject.cluster.NodeId) MastershipRole(org.onosproject.net.MastershipRole)

Aggregations

NodeId (org.onosproject.cluster.NodeId)145 ClusterService (org.onosproject.cluster.ClusterService)36 DeviceId (org.onosproject.net.DeviceId)36 Set (java.util.Set)26 MastershipRole (org.onosproject.net.MastershipRole)23 ControllerNode (org.onosproject.cluster.ControllerNode)22 Test (org.junit.Test)18 Activate (org.osgi.service.component.annotations.Activate)18 List (java.util.List)16 MastershipService (org.onosproject.mastership.MastershipService)15 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)13 Map (java.util.Map)12 ImmutableSet (com.google.common.collect.ImmutableSet)11 ArrayList (java.util.ArrayList)11 Collectors (java.util.stream.Collectors)11 HashSet (java.util.HashSet)10 Optional (java.util.Optional)10 ClusterCommunicationService (org.onosproject.store.cluster.messaging.ClusterCommunicationService)10 Component (org.osgi.service.component.annotations.Component)9 Deactivate (org.osgi.service.component.annotations.Deactivate)9