Search in sources :

Example 1 with NONE

use of org.onosproject.net.MastershipRole.NONE in project onos by opennetworkinglab.

the class DeviceManager method mastershipCheck.

/**
 * Checks if all the reachable devices have a valid mastership role.
 */
private void mastershipCheck() {
    log.debug("Checking mastership");
    for (Device device : getDevices()) {
        final DeviceId deviceId = device.id();
        MastershipRole myRole = mastershipService.getLocalRole(deviceId);
        log.trace("Checking device {}. Current role is {}", deviceId, myRole);
        log.debug("Device {} local status is {}", deviceId, localStatus(deviceId));
        final boolean isGracePeriodOn = inGracePeriod(deviceId);
        final boolean isReachable = isReachable(deviceId, isGracePeriodOn);
        // Passed the grace period and it is still not reachable
        if (!isGracePeriodOn && !isReachable) {
            if (myRole != NONE) {
                // Verify if the device is fully disconnected from the cluster
                if (updateMastershipFor(deviceId) == null && myRole == MASTER && isAvailable(deviceId)) {
                    log.info("Local Role {}, Marking unreachable device {} offline", MASTER, deviceId);
                    // Following the deviceDisconnected method logic (line 734) we are marking also all the
                    // ports as disabled.
                    List<PortDescription> descs = store.getPortDescriptions(getProvider(deviceId).id(), deviceId).map(desc -> ensurePortEnabledState(desc, false)).collect(Collectors.toList());
                    store.updatePorts(getProvider(deviceId).id(), deviceId, descs);
                    post(store.markOffline(deviceId));
                }
            } else {
                // never be hit unless in a device removed phase for NONE mastership roles.
                try {
                    mastershipService.requestRoleFor(deviceId).get();
                } catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                    log.error("Interrupted waiting for Mastership", e);
                } catch (ExecutionException e) {
                    log.error("Encountered an error waiting for Mastership", e);
                }
                MastershipTerm term = termService.getMastershipTerm(deviceId);
                if (updateMastershipFor(deviceId) == null && term != null && localNodeId.equals(term.master()) && isAvailable(deviceId)) {
                    log.info("Marking unreachable device {} offline", deviceId);
                    // Following the deviceDisconnected method logic (line 734) we are marking also all the
                    // ports as disabled.
                    List<PortDescription> descs = store.getPortDescriptions(getProvider(deviceId).id(), deviceId).map(desc -> ensurePortEnabledState(desc, false)).collect(Collectors.toList());
                    store.updatePorts(getProvider(deviceId).id(), deviceId, descs);
                    post(store.markOffline(deviceId));
                }
            }
            roleToAcknowledge.remove(deviceId);
        } else if (isReachable) {
            // If this node is the master, ensure the device is marked online.
            if (myRole == MASTER && canMarkOnline(device)) {
                log.debug("Can mark online {}", deviceId);
                post(store.markOnline(deviceId));
            }
            log.debug("{} is reachable - reasserting the role", deviceId);
            // Device is still reachable. It is useful for some protocols
            // to reassert the role. Note: NONE triggers request to MastershipService
            reassertRole(deviceId, myRole);
        } else {
            // Do not proceed furthermore if the grace period is still on
            log.debug("Skipping mastership check for {}", deviceId);
        }
    }
}
Also used : NetworkConfigService(org.onosproject.net.config.NetworkConfigService) Config(org.onosproject.net.config.Config) BasicDeviceConfig(org.onosproject.net.config.basics.BasicDeviceConfig) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) DeviceStore(org.onosproject.net.device.DeviceStore) AbstractProviderService(org.onosproject.net.provider.AbstractProviderService) MASTER(org.onosproject.net.MastershipRole.MASTER) PortConfigOperator(org.onosproject.net.config.PortConfigOperator) NONE(org.onosproject.net.MastershipRole.NONE) ConnectPoint(org.onosproject.net.ConnectPoint) Executors.newSingleThreadScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor) Port(org.onosproject.net.Port) Map(java.util.Map) DeviceProvider(org.onosproject.net.device.DeviceProvider) MessageSubject(org.onosproject.store.cluster.messaging.MessageSubject) DeviceProviderService(org.onosproject.net.device.DeviceProviderService) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) MastershipService(org.onosproject.mastership.MastershipService) DeviceStoreDelegate(org.onosproject.net.device.DeviceStoreDelegate) DeviceDescription(org.onosproject.net.device.DeviceDescription) NodeId(org.onosproject.cluster.NodeId) DeviceAnnotationConfig(org.onosproject.net.config.basics.DeviceAnnotationConfig) Serializer(org.onosproject.store.service.Serializer) UpgradeService(org.onosproject.upgrade.UpgradeService) Device(org.onosproject.net.Device) Deactivate(org.osgi.service.component.annotations.Deactivate) Multimaps.newListMultimap(com.google.common.collect.Multimaps.newListMultimap) Collection(java.util.Collection) MastershipTermService(org.onosproject.mastership.MastershipTermService) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) Executors.newSingleThreadExecutor(java.util.concurrent.Executors.newSingleThreadExecutor) PortConfigOperatorRegistry(org.onosproject.net.config.PortConfigOperatorRegistry) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) AbstractListenerProviderRegistry(org.onosproject.net.provider.AbstractListenerProviderRegistry) Preconditions.checkState(com.google.common.base.Preconditions.checkState) Objects(java.util.Objects) List(java.util.List) DeviceEvent(org.onosproject.net.device.DeviceEvent) ClusterCommunicationService(org.onosproject.store.cluster.messaging.ClusterCommunicationService) Optional(java.util.Optional) ClusterService(org.onosproject.cluster.ClusterService) DeviceId(org.onosproject.net.DeviceId) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) System.currentTimeMillis(java.lang.System.currentTimeMillis) Tools(org.onlab.util.Tools) PortStatistics(org.onosproject.net.device.PortStatistics) PortDescriptionsConfig(org.onosproject.net.config.basics.PortDescriptionsConfig) NetworkConfigEvent(org.onosproject.net.config.NetworkConfigEvent) AppGuard.checkPermission(org.onosproject.security.AppGuard.checkPermission) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CompletableFuture(java.util.concurrent.CompletableFuture) DeviceProviderRegistry(org.onosproject.net.device.DeviceProviderRegistry) Multimap(com.google.common.collect.Multimap) KryoNamespace(org.onlab.util.KryoNamespace) ControllerNode(org.onosproject.cluster.ControllerNode) HashSet(java.util.HashSet) MastershipEvent(org.onosproject.mastership.MastershipEvent) Component(org.osgi.service.component.annotations.Component) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) PortDescription(org.onosproject.net.device.PortDescription) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Activate(org.osgi.service.component.annotations.Activate) Multimaps.synchronizedListMultimap(com.google.common.collect.Multimaps.synchronizedListMultimap) ExecutorService(java.util.concurrent.ExecutorService) Type(org.onosproject.net.Device.Type) STANDBY(org.onosproject.net.MastershipRole.STANDBY) DeviceListener(org.onosproject.net.device.DeviceListener) Logger(org.slf4j.Logger) MastershipRole(org.onosproject.net.MastershipRole) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) DEVICE_READ(org.onosproject.security.AppPermission.Type.DEVICE_READ) ProviderId(org.onosproject.net.provider.ProviderId) Maps(com.google.common.collect.Maps) MastershipTerm(org.onosproject.mastership.MastershipTerm) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Futures(com.google.common.util.concurrent.Futures) DefaultPortDescription(org.onosproject.net.device.DefaultPortDescription) DeviceAdminService(org.onosproject.net.device.DeviceAdminService) Provider(org.onosproject.net.provider.Provider) PortAnnotationConfig(org.onosproject.net.config.basics.PortAnnotationConfig) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) MastershipListener(org.onosproject.mastership.MastershipListener) Reference(org.osgi.service.component.annotations.Reference) MastershipAdminService(org.onosproject.mastership.MastershipAdminService) NetworkConfigListener(org.onosproject.net.config.NetworkConfigListener) MastershipTerm(org.onosproject.mastership.MastershipTerm) Device(org.onosproject.net.Device) DeviceId(org.onosproject.net.DeviceId) PortDescription(org.onosproject.net.device.PortDescription) DefaultPortDescription(org.onosproject.net.device.DefaultPortDescription) ExecutionException(java.util.concurrent.ExecutionException) MastershipRole(org.onosproject.net.MastershipRole)

Aggregations

Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 ImmutableList (com.google.common.collect.ImmutableList)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 Multimap (com.google.common.collect.Multimap)1 Multimaps.newListMultimap (com.google.common.collect.Multimaps.newListMultimap)1 Multimaps.synchronizedListMultimap (com.google.common.collect.Multimaps.synchronizedListMultimap)1 Futures (com.google.common.util.concurrent.Futures)1 System.currentTimeMillis (java.lang.System.currentTimeMillis)1 Instant (java.time.Instant)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Set (java.util.Set)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1