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