Search in sources :

Example 71 with NodeId

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)));
}
Also used : DeviceId(org.onosproject.net.DeviceId) MastershipEvent(org.onosproject.mastership.MastershipEvent) NodeId(org.onosproject.cluster.NodeId) MastershipRole(org.onosproject.net.MastershipRole)

Example 72 with NodeId

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;
}
Also used : DeviceId(org.onosproject.net.DeviceId) MastershipEvent(org.onosproject.mastership.MastershipEvent) NodeId(org.onosproject.cluster.NodeId) MastershipRole(org.onosproject.net.MastershipRole)

Example 73 with NodeId

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;
}
Also used : NodeId(org.onosproject.cluster.NodeId) Key(org.onosproject.net.intent.Key)

Example 74 with NodeId

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

Example 75 with NodeId

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;
}
Also used : Query(org.influxdb.dto.Query) QueryResult(org.influxdb.dto.QueryResult) NodeId(org.onosproject.cluster.NodeId) List(java.util.List)

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