Search in sources :

Example 81 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 82 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 83 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)

Example 84 with NodeId

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

the class SimpleMastershipStore method setMaster.

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

Example 85 with NodeId

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

the class UpgradeManager method handleClusterEvent.

/**
 * Handles a cluster event.
 *
 * @param event the cluster event
 */
protected void handleClusterEvent(ClusterEvent event) {
    checkPermission(CLUSTER_EVENT);
    // If an instance was deactivated, check whether we need to roll back the upgrade.
    if (event.type() == ClusterEvent.Type.INSTANCE_DEACTIVATED) {
        Upgrade upgrade = getState();
        if (upgrade.status().upgraded()) {
            // Get the upgraded subset of the cluster and check whether the down node is a member
            // of the upgraded subset. If so, roll back the upgrade to tolerate the failure.
            Set<NodeId> upgradedNodes = clusterService.getNodes().stream().map(ControllerNode::id).filter(id -> clusterService.getVersion(id).equals(upgrade.target())).collect(Collectors.toSet());
            if (upgradedNodes.contains(event.subject().id())) {
                log.warn("Upgrade failure detected: rolling back upgrade");
                rollback();
            }
        }
    }
}
Also used : AtomicValueEvent(org.onosproject.store.service.AtomicValueEvent) AppGuard.checkPermission(org.onosproject.security.AppGuard.checkPermission) CLUSTER_EVENT(org.onosproject.security.AppPermission.Type.CLUSTER_EVENT) CoordinationService(org.onosproject.store.service.CoordinationService) AtomicReference(java.util.concurrent.atomic.AtomicReference) ControllerNode(org.onosproject.cluster.ControllerNode) AtomicValue(org.onosproject.store.service.AtomicValue) Component(org.osgi.service.component.annotations.Component) Upgrade(org.onosproject.upgrade.Upgrade) VersionService(org.onosproject.core.VersionService) Version(org.onosproject.core.Version) Activate(org.osgi.service.component.annotations.Activate) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) NodeId(org.onosproject.cluster.NodeId) UpgradeEventListener(org.onosproject.upgrade.UpgradeEventListener) Serializer(org.onosproject.store.service.Serializer) ClusterEventListener(org.onosproject.cluster.ClusterEventListener) UpgradeService(org.onosproject.upgrade.UpgradeService) Logger(org.slf4j.Logger) UPGRADE_EVENT(org.onosproject.security.AppPermission.Type.UPGRADE_EVENT) UPGRADE_READ(org.onosproject.security.AppPermission.Type.UPGRADE_READ) ClusterEvent(org.onosproject.cluster.ClusterEvent) AbstractListenerManager(org.onosproject.event.AbstractListenerManager) Deactivate(org.osgi.service.component.annotations.Deactivate) Set(java.util.Set) Collectors(java.util.stream.Collectors) AtomicValueEventListener(org.onosproject.store.service.AtomicValueEventListener) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) Objects(java.util.Objects) UpgradeEvent(org.onosproject.upgrade.UpgradeEvent) UpgradeAdminService(org.onosproject.upgrade.UpgradeAdminService) MembershipService(org.onosproject.cluster.MembershipService) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) ClusterService(org.onosproject.cluster.ClusterService) UPGRADE_WRITE(org.onosproject.security.AppPermission.Type.UPGRADE_WRITE) Reference(org.osgi.service.component.annotations.Reference) NodeId(org.onosproject.cluster.NodeId) ControllerNode(org.onosproject.cluster.ControllerNode) Upgrade(org.onosproject.upgrade.Upgrade)

Aggregations

NodeId (org.onosproject.cluster.NodeId)150 DeviceId (org.onosproject.net.DeviceId)38 ClusterService (org.onosproject.cluster.ClusterService)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