use of org.onosproject.cluster.NodeId in project onos by opennetworkinglab.
the class SimpleVirtualMastershipStore method setMaster.
@Override
public synchronized CompletableFuture<MastershipEvent> setMaster(NetworkId networkId, NodeId nodeId, DeviceId deviceId) {
Map<DeviceId, NodeId> masterMap = getMasterMap(networkId);
MastershipRole role = getRole(networkId, nodeId, deviceId);
switch(role) {
case MASTER:
// no-op
return CompletableFuture.completedFuture(null);
case STANDBY:
case NONE:
NodeId prevMaster = masterMap.put(deviceId, nodeId);
incrementTerm(networkId, deviceId);
removeFromBackups(networkId, deviceId, nodeId);
addToBackup(networkId, deviceId, prevMaster);
break;
default:
log.warn("unknown Mastership Role {}", role);
return null;
}
return CompletableFuture.completedFuture(new MastershipEvent(MASTER_CHANGED, deviceId, getMastership(networkId, deviceId)));
}
use of org.onosproject.cluster.NodeId in project onos by opennetworkinglab.
the class SimpleVirtualMastershipStore method setStandby.
@Override
public CompletableFuture<MastershipEvent> setStandby(NetworkId networkId, NodeId nodeId, DeviceId deviceId) {
Map<DeviceId, NodeId> masterMap = getMasterMap(networkId);
MastershipRole role = getRole(networkId, nodeId, deviceId);
switch(role) {
case MASTER:
NodeId backup = reelect(networkId, deviceId, nodeId);
if (backup == null) {
// no master alternative
masterMap.remove(deviceId);
// TODO: Should there be new event type for no MASTER?
return CompletableFuture.completedFuture(new MastershipEvent(MASTER_CHANGED, deviceId, getMastership(networkId, deviceId)));
} else {
NodeId prevMaster = masterMap.put(deviceId, backup);
incrementTerm(networkId, deviceId);
addToBackup(networkId, deviceId, prevMaster);
return CompletableFuture.completedFuture(new MastershipEvent(MASTER_CHANGED, deviceId, getMastership(networkId, deviceId)));
}
case STANDBY:
case NONE:
boolean modified = addToBackup(networkId, deviceId, nodeId);
if (modified) {
return CompletableFuture.completedFuture(new MastershipEvent(BACKUPS_CHANGED, deviceId, getMastership(networkId, deviceId)));
}
break;
default:
log.warn("unknown Mastership Role {}", role);
}
return null;
}
use of org.onosproject.cluster.NodeId in project onos by opennetworkinglab.
the class IntentsListCommand method fullFormat.
/*
* Prints information about the intent state, given an intent.
*/
private StringBuilder fullFormat(Intent intent, IntentState state) {
StringBuilder builder = new StringBuilder();
NodeId nodeId = workPartitionService.getLeader(intent.key(), Key::hash);
builder.append(format(ID, intent.id()));
if (state != null) {
builder.append('\n').append(format(STATE, state));
}
builder.append('\n').append(format(KEY, intent.key()));
builder.append('\n').append(format(TYPE, intent.getClass().getSimpleName()));
builder.append('\n').append(format(APP_ID, intent.appId().name()));
builder.append('\n').append(nodeId == null ? NONE : format(LEADER_ID, nodeId.id()));
return builder;
}
use of org.onosproject.cluster.NodeId 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.NodeId in project onos by opennetworkinglab.
the class DefaultInfluxDbMetricsRetriever method metricsByName.
@Override
public Map<NodeId, List<InfluxMetric>> metricsByName(String metricName, int period, TimeUnit unit) {
Map<NodeId, List<InfluxMetric>> map = Maps.newHashMap();
List<InfluxMetric> metrics = Lists.newArrayList();
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(" WHERE time > now() - ").append(period).append(unitString(unit)).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) {
results.get(0).getSeries().get(0).getValues().forEach(value -> metrics.add(new DefaultInfluxMetric.Builder().time((String) value.get(0)).oneMinRate((Double) value.get(1)).build()));
map.putIfAbsent(nodeId, metrics);
}
});
return map;
}
Aggregations