Search in sources :

Example 36 with ControllerNode

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

the class AtomixClusterStore method removeNode.

@Override
public void removeNode(NodeId nodeId) {
    checkNotNull(nodeId, INSTANCE_ID_NULL);
    ControllerNode node = nodes.remove(nodeId);
    if (node != null) {
        states.remove(nodeId);
        notifyDelegate(clusterEvent(ClusterEvent.Type.INSTANCE_REMOVED, membershipService.getMember(node.id().id()), node));
    }
}
Also used : ControllerNode(org.onosproject.cluster.ControllerNode) DefaultControllerNode(org.onosproject.cluster.DefaultControllerNode)

Example 37 with ControllerNode

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

the class NetconfControllerImpl method activate.

@Activate
public void activate(ComponentContext context) {
    cfgService.registerProperties(getClass());
    modified(context);
    Security.addProvider(new BouncyCastleProvider());
    clusterCommunicator.<NetconfProxyMessage>addSubscriber(SEND_REQUEST_SUBJECT_STRING, SERIALIZER::decode, this::handleProxyMessage, remoteRequestExecutor);
    clusterCommunicator.<NetconfProxyMessage>addSubscriber(SEND_REQUEST_SUBJECT_SET_STRING, SERIALIZER::decode, this::handleProxyMessage, remoteRequestExecutor);
    clusterCommunicator.<NetconfProxyMessage>addSubscriber(SEND_REPLY_SUBJECT_STRING, SERIALIZER::decode, this::handleProxyReplyMessage, remoteRequestExecutor);
    clusterCommunicator.<NetconfProxyMessage>addSubscriber(SEND_REPLY_SUBJECT_SET_STRING, SERIALIZER::decode, this::handleProxyReplyMessage, remoteRequestExecutor);
    localNodeId = Optional.ofNullable(clusterService.getLocalNode()).map(ControllerNode::id).orElseGet(() -> new NodeId("nullNodeId"));
    log.info("Started");
}
Also used : NodeId(org.onosproject.cluster.NodeId) ControllerNode(org.onosproject.cluster.ControllerNode) NetconfProxyMessage(org.onosproject.netconf.NetconfProxyMessage) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider) Activate(org.osgi.service.component.annotations.Activate)

Example 38 with ControllerNode

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

the class ClusterMetadataManager method getLocalNode.

@Override
public ControllerNode getLocalNode() {
    checkPermission(CLUSTER_READ);
    if (localNode == null) {
        ClusterMetadata metadata = getProvider().getClusterMetadata().value();
        ControllerNode localNode = metadata.getLocalNode();
        try {
            if (localNode != null) {
                this.localNode = new DefaultControllerNode(localNode.id(), localNode.ip() != null ? localNode.ip() : findLocalIp(), localNode.tcpPort());
            } else {
                IpAddress ip = findLocalIp();
                localNode = metadata.getControllerNodes().stream().filter(node -> node.ip().equals(ip)).findFirst().orElse(null);
                if (localNode != null) {
                    this.localNode = localNode;
                } else {
                    this.localNode = new DefaultControllerNode(NodeId.nodeId(ip.toString()), ip);
                }
            }
        } catch (SocketException e) {
            throw new IllegalStateException(e);
        }
    }
    return localNode;
}
Also used : ClusterMetadata(org.onosproject.cluster.ClusterMetadata) CLUSTER_READ(org.onosproject.security.AppPermission.Type.CLUSTER_READ) Enumeration(java.util.Enumeration) URL(java.net.URL) AppGuard.checkPermission(org.onosproject.security.AppGuard.checkPermission) AbstractProviderService(org.onosproject.net.provider.AbstractProviderService) ClusterMetadataProvider(org.onosproject.cluster.ClusterMetadataProvider) ControllerNode(org.onosproject.cluster.ControllerNode) DefaultControllerNode(org.onosproject.cluster.DefaultControllerNode) InetAddress(java.net.InetAddress) Component(org.osgi.service.component.annotations.Component) SocketException(java.net.SocketException) ImmutableList(com.google.common.collect.ImmutableList) ClusterMetadataProviderRegistry(org.onosproject.cluster.ClusterMetadataProviderRegistry) ClusterMetadataProviderService(org.onosproject.cluster.ClusterMetadataProviderService) ClusterMetadata(org.onosproject.cluster.ClusterMetadata) Activate(org.osgi.service.component.annotations.Activate) IpAddress(org.onlab.packet.IpAddress) NodeId(org.onosproject.cluster.NodeId) Logger(org.slf4j.Logger) ClusterActivator(org.onosproject.store.atomix.ClusterActivator) MalformedURLException(java.net.MalformedURLException) Deactivate(org.osgi.service.component.annotations.Deactivate) ClusterMetadataEventListener(org.onosproject.cluster.ClusterMetadataEventListener) NetworkInterface(java.net.NetworkInterface) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Set(java.util.Set) ProviderId(org.onosproject.net.provider.ProviderId) Inet4Address(java.net.Inet4Address) UnknownHostException(java.net.UnknownHostException) Collectors(java.util.stream.Collectors) AbstractListenerProviderRegistry(org.onosproject.net.provider.AbstractListenerProviderRegistry) ClusterMetadataService(org.onosproject.cluster.ClusterMetadataService) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) Versioned(org.onosproject.store.service.Versioned) List(java.util.List) ClusterMetadataAdminService(org.onosproject.cluster.ClusterMetadataAdminService) ClusterMetadataEvent(org.onosproject.cluster.ClusterMetadataEvent) PartitionId(org.onosproject.cluster.PartitionId) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Reference(org.osgi.service.component.annotations.Reference) SocketException(java.net.SocketException) ControllerNode(org.onosproject.cluster.ControllerNode) DefaultControllerNode(org.onosproject.cluster.DefaultControllerNode) IpAddress(org.onlab.packet.IpAddress) DefaultControllerNode(org.onosproject.cluster.DefaultControllerNode)

Example 39 with ControllerNode

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

the class MastershipManager method findBucket.

/**
 * Finds node with the minimum/maximum devices from a list of nodes.
 *
 * @param min               true: minimum, false: maximum
 * @param controllerDevices controller nodes to devices map
 * @return controller node with minimum/maximum devices
 */
private ControllerNode findBucket(boolean min, Map<ControllerNode, Set<DeviceId>> controllerDevices) {
    int xSize = min ? Integer.MAX_VALUE : -1;
    ControllerNode xNode = null;
    for (ControllerNode node : controllerDevices.keySet()) {
        int size = controllerDevices.get(node).size();
        if ((min && size < xSize) || (!min && size > xSize)) {
            xSize = size;
            xNode = node;
        }
    }
    return xNode;
}
Also used : ControllerNode(org.onosproject.cluster.ControllerNode)

Example 40 with ControllerNode

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

the class MastershipManager method balanceControllerNodes.

/**
 * Balances the nodes specified in controllerDevices.
 *
 * @param controllerDevices controller nodes to devices map
 * @param deviceCount       number of devices mastered by controller nodes
 * @param futures           list of setRole futures for "moved" devices
 */
private void balanceControllerNodes(Map<ControllerNode, Set<DeviceId>> controllerDevices, int deviceCount, List<CompletableFuture<Void>> futures) {
    // Now re-balance the buckets until they are roughly even.
    int rounds = controllerDevices.keySet().size();
    for (int i = 0; i < rounds; i++) {
        // Iterate over the buckets and find the smallest and the largest.
        ControllerNode smallest = findBucket(true, controllerDevices);
        ControllerNode largest = findBucket(false, controllerDevices);
        futures.add(balanceBuckets(smallest, largest, controllerDevices, deviceCount));
    }
}
Also used : ControllerNode(org.onosproject.cluster.ControllerNode)

Aggregations

ControllerNode (org.onosproject.cluster.ControllerNode)42 NodeId (org.onosproject.cluster.NodeId)17 ClusterService (org.onosproject.cluster.ClusterService)14 Activate (org.osgi.service.component.annotations.Activate)11 Set (java.util.Set)10 DefaultControllerNode (org.onosproject.cluster.DefaultControllerNode)10 List (java.util.List)8 Collectors (java.util.stream.Collectors)8 Logger (org.slf4j.Logger)8 LoggerFactory.getLogger (org.slf4j.LoggerFactory.getLogger)8 DeviceId (org.onosproject.net.DeviceId)7 IpAddress (org.onlab.packet.IpAddress)6 Version (org.onosproject.core.Version)6 Component (org.osgi.service.component.annotations.Component)5 Deactivate (org.osgi.service.component.annotations.Deactivate)5 Reference (org.osgi.service.component.annotations.Reference)5 ReferenceCardinality (org.osgi.service.component.annotations.ReferenceCardinality)5 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)4 Collection (java.util.Collection)4 HashSet (java.util.HashSet)4