Search in sources :

Example 1 with CLUSTER_READ

use of org.onosproject.security.AppPermission.Type.CLUSTER_READ 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)

Aggregations

Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 ImmutableList (com.google.common.collect.ImmutableList)1 Inet4Address (java.net.Inet4Address)1 InetAddress (java.net.InetAddress)1 MalformedURLException (java.net.MalformedURLException)1 NetworkInterface (java.net.NetworkInterface)1 SocketException (java.net.SocketException)1 URL (java.net.URL)1 UnknownHostException (java.net.UnknownHostException)1 Enumeration (java.util.Enumeration)1 List (java.util.List)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 IpAddress (org.onlab.packet.IpAddress)1 ClusterMetadata (org.onosproject.cluster.ClusterMetadata)1 ClusterMetadataAdminService (org.onosproject.cluster.ClusterMetadataAdminService)1 ClusterMetadataEvent (org.onosproject.cluster.ClusterMetadataEvent)1 ClusterMetadataEventListener (org.onosproject.cluster.ClusterMetadataEventListener)1 ClusterMetadataProvider (org.onosproject.cluster.ClusterMetadataProvider)1 ClusterMetadataProviderRegistry (org.onosproject.cluster.ClusterMetadataProviderRegistry)1