Search in sources :

Example 86 with NodeId

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

the class NodeMetricsManager method activate.

@Activate
public void activate(ComponentContext context) {
    appId = coreService.registerApplication("org.onosproject.nodemetrics");
    cfgService.registerProperties(getClass());
    metricsExecutor = Executors.newSingleThreadScheduledExecutor(Tools.groupedThreads("nodemetrics/pollingStatics", "statistics-executor-%d", log));
    localNodeId = clusterService.getLocalNode().id();
    KryoNamespace.Builder serializer = KryoNamespace.newBuilder().register(KryoNamespaces.API).register(NodeMemoryUsage.class).register(NodeDiskUsage.class).register(NodeCpuUsage.class).register(Units.class);
    memoryStore = storageService.<NodeId, NodeMemoryUsage>eventuallyConsistentMapBuilder().withSerializer(serializer).withTimestampProvider((nodeId, memory) -> clockService.getTimestamp()).withName("nodemetrics-memory").build();
    diskStore = storageService.<NodeId, NodeDiskUsage>eventuallyConsistentMapBuilder().withSerializer(serializer).withTimestampProvider((nodeId, disk) -> clockService.getTimestamp()).withName("nodemetrics-disk").build();
    cpuStore = storageService.<NodeId, NodeCpuUsage>eventuallyConsistentMapBuilder().withSerializer(serializer).withTimestampProvider((nodeId, cpu) -> clockService.getTimestamp()).withName("nodemetrics-cpu").build();
    modified(context);
    sigar = new Sigar();
    pollMetrics();
}
Also used : METRIC_POLL_FREQUENCY_SECONDS(org.onosproject.nodemetrics.impl.OsgiPropertyConstants.METRIC_POLL_FREQUENCY_SECONDS) ScheduledFuture(java.util.concurrent.ScheduledFuture) Tools(org.onlab.util.Tools) Mem(org.hyperic.sigar.Mem) CoreService(org.onosproject.core.CoreService) ComponentContext(org.osgi.service.component.ComponentContext) LoggerFactory(org.slf4j.LoggerFactory) Tools.getIntegerProperty(org.onlab.util.Tools.getIntegerProperty) KryoNamespace(org.onlab.util.KryoNamespace) METRIC_POLL_FREQUENCY_SECONDS_DEFAULT(org.onosproject.nodemetrics.impl.OsgiPropertyConstants.METRIC_POLL_FREQUENCY_SECONDS_DEFAULT) CpuPerc(org.hyperic.sigar.CpuPerc) NodeCpuUsage(org.onosproject.nodemetrics.NodeCpuUsage) Component(org.osgi.service.component.annotations.Component) StorageService(org.onosproject.store.service.StorageService) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) NodeDiskUsage(org.onosproject.nodemetrics.NodeDiskUsage) Activate(org.osgi.service.component.annotations.Activate) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) EventuallyConsistentMap(org.onosproject.store.service.EventuallyConsistentMap) ComponentConfigService(org.onosproject.cfg.ComponentConfigService) NodeId(org.onosproject.cluster.NodeId) SigarException(org.hyperic.sigar.SigarException) NodeMemoryUsage(org.onosproject.nodemetrics.NodeMemoryUsage) Logger(org.slf4j.Logger) FileSystemUsage(org.hyperic.sigar.FileSystemUsage) NodeMetricsService(org.onosproject.nodemetrics.NodeMetricsService) Deactivate(org.osgi.service.component.annotations.Deactivate) LogicalClockService(org.onosproject.store.service.LogicalClockService) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) Modified(org.osgi.service.component.annotations.Modified) ClusterService(org.onosproject.cluster.ClusterService) Units(org.onosproject.nodemetrics.Units) Reference(org.osgi.service.component.annotations.Reference) Sigar(org.hyperic.sigar.Sigar) Dictionary(java.util.Dictionary) Sigar(org.hyperic.sigar.Sigar) NodeCpuUsage(org.onosproject.nodemetrics.NodeCpuUsage) NodeMemoryUsage(org.onosproject.nodemetrics.NodeMemoryUsage) KryoNamespace(org.onlab.util.KryoNamespace) Activate(org.osgi.service.component.annotations.Activate)

Example 87 with NodeId

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

the class OpenstackEastWestProbeCommand method doExecute.

@Override
protected void doExecute() {
    OpenstackTroubleshootService tsService = get(OpenstackTroubleshootService.class);
    InstancePortService instPortService = get(InstancePortService.class);
    MastershipService mastershipService = get(MastershipService.class);
    ClusterService clusterService = get(ClusterService.class);
    OpenstackNodeService osNodeService = get(OpenstackNodeService.class);
    if (tsService == null) {
        error("Failed to troubleshoot openstack networking.");
        return;
    }
    if ((!isAll && vmIps == null) || (isAll && vmIps != null)) {
        print("Please specify one of VM IP address or -a option.");
        return;
    }
    NodeId localNodeId = clusterService.getLocalNode().id();
    for (OpenstackNode node : osNodeService.completeNodes(COMPUTE)) {
        if (!localNodeId.equals(mastershipService.getMasterFor(node.intgBridge()))) {
            error("Current node is not the master for all compute nodes. " + "Please enforce mastership first using openstack-reset-mastership -c !");
            return;
        }
    }
    if (isAll) {
        printHeader();
        // send ICMP PACKET_OUT to all connect VMs whose instance port state is ACTIVE
        Set<InstancePort> activePorts = instPortService.instancePorts().stream().filter(p -> p.state() == ACTIVE).collect(Collectors.toSet());
        activePorts.forEach(srcPort -> activePorts.forEach(dstPort -> printReachability(tsService.probeEastWest(srcPort, dstPort))));
    } else {
        if (vmIps.length > 2) {
            print("Too many VM IPs. The number of IP should be limited to 2.");
            return;
        }
        IpAddress srcIp = getIpAddress(vmIps[0]);
        if (srcIp == null) {
            return;
        }
        InstancePort srcPort = instPort(instPortService, srcIp);
        if (srcPort == null) {
            print("Specified source IP is not existing.");
            return;
        }
        final Set<IpAddress> dstIps = Sets.newConcurrentHashSet();
        if (vmIps.length == 2) {
            IpAddress dstIp = getIpAddress(vmIps[1]);
            if (dstIp == null) {
                return;
            }
            dstIps.add(dstIp);
        }
        if (vmIps.length == 1) {
            dstIps.addAll(instPortService.instancePorts().stream().filter(p -> !p.ipAddress().equals(srcIp)).filter(p -> p.state().equals(InstancePort.State.ACTIVE)).map(InstancePort::ipAddress).collect(Collectors.toSet()));
        }
        printHeader();
        dstIps.stream().filter(ip -> instPort(instPortService, ip) != null).map(ip -> instPort(instPortService, ip)).forEach(port -> probeExecutor.execute(() -> printReachability(tsService.probeEastWest(srcPort, port))));
    }
}
Also used : OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) COMPUTE(org.onosproject.openstacknode.api.OpenstackNode.NodeType.COMPUTE) InstancePort(org.onosproject.openstacknetworking.api.InstancePort) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) Command(org.apache.karaf.shell.api.action.Command) OpenstackTroubleshootService(org.onosproject.openstacktroubleshoot.api.OpenstackTroubleshootService) Executors.newSingleThreadScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor) MastershipService(org.onosproject.mastership.MastershipService) ExecutorService(java.util.concurrent.ExecutorService) IpAddress(org.onlab.packet.IpAddress) NodeId(org.onosproject.cluster.NodeId) OpenstackNodeService(org.onosproject.openstacknode.api.OpenstackNodeService) ACTIVE(org.onosproject.openstacknetworking.api.InstancePort.State.ACTIVE) Set(java.util.Set) Argument(org.apache.karaf.shell.api.action.Argument) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) Reachability(org.onosproject.openstacktroubleshoot.api.Reachability) Service(org.apache.karaf.shell.api.action.lifecycle.Service) Optional(java.util.Optional) Completion(org.apache.karaf.shell.api.action.Completion) ClusterService(org.onosproject.cluster.ClusterService) Option(org.apache.karaf.shell.api.action.Option) InstancePortService(org.onosproject.openstacknetworking.api.InstancePortService) OpenstackNodeService(org.onosproject.openstacknode.api.OpenstackNodeService) ClusterService(org.onosproject.cluster.ClusterService) OpenstackTroubleshootService(org.onosproject.openstacktroubleshoot.api.OpenstackTroubleshootService) InstancePortService(org.onosproject.openstacknetworking.api.InstancePortService) InstancePort(org.onosproject.openstacknetworking.api.InstancePort) NodeId(org.onosproject.cluster.NodeId) MastershipService(org.onosproject.mastership.MastershipService) IpAddress(org.onlab.packet.IpAddress) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode)

Example 88 with NodeId

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

the class OpenstackNorthSouthProbeCommand method doExecute.

@Override
protected void doExecute() {
    OpenstackTroubleshootService tsService = get(OpenstackTroubleshootService.class);
    InstancePortService instPortService = get(InstancePortService.class);
    OpenstackNodeService osNodeService = get(OpenstackNodeService.class);
    MastershipService mastershipService = get(MastershipService.class);
    ClusterService clusterService = get(ClusterService.class);
    if (tsService == null || osNodeService == null || instPortService == null || mastershipService == null) {
        error("Failed to troubleshoot openstack networking.");
        return;
    }
    if ((!isAll && vmIps == null) || (isAll && vmIps != null)) {
        print("Please specify one of VM IP address or -a option.");
        return;
    }
    NodeId localNodeId = clusterService.getLocalNode().id();
    for (OpenstackNode gw : osNodeService.completeNodes(GATEWAY)) {
        if (!localNodeId.equals(mastershipService.getMasterFor(gw.intgBridge()))) {
            error("Current node is not the master for all gateway nodes. " + "Please enforce mastership first using openstack-reset-mastership -c !");
            return;
        }
    }
    if (isAll) {
        printHeader();
        // send ICMP PACKET_OUT to all connect VMs whose instance port state is ACTIVE
        instPortService.instancePorts().stream().filter(p -> p.state() == ACTIVE).filter(p -> instPortService.floatingIp(p.portId()) != null).forEach(port -> printReachability(tsService.probeNorthSouth(port)));
    } else {
        final Set<InstancePort> ports = Sets.newConcurrentHashSet();
        for (String ip : vmIps) {
            instPortService.instancePorts().stream().filter(p -> p.state().equals(InstancePort.State.ACTIVE)).filter(p -> instPortService.floatingIp(p.portId()) != null).filter(p -> ip.equals(instPortService.floatingIp(p.portId()).toString())).forEach(ports::add);
        }
        printHeader();
        ports.forEach(port -> probeExecutor.execute(() -> printReachability(tsService.probeNorthSouth(port))));
    }
}
Also used : NodeId(org.onosproject.cluster.NodeId) GATEWAY(org.onosproject.openstacknode.api.OpenstackNode.NodeType.GATEWAY) OpenstackNodeService(org.onosproject.openstacknode.api.OpenstackNodeService) ACTIVE(org.onosproject.openstacknetworking.api.InstancePort.State.ACTIVE) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) InstancePort(org.onosproject.openstacknetworking.api.InstancePort) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) Set(java.util.Set) Argument(org.apache.karaf.shell.api.action.Argument) Sets(com.google.common.collect.Sets) Command(org.apache.karaf.shell.api.action.Command) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) OpenstackTroubleshootService(org.onosproject.openstacktroubleshoot.api.OpenstackTroubleshootService) Executors.newSingleThreadScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor) Reachability(org.onosproject.openstacktroubleshoot.api.Reachability) Service(org.apache.karaf.shell.api.action.lifecycle.Service) Completion(org.apache.karaf.shell.api.action.Completion) ClusterService(org.onosproject.cluster.ClusterService) Option(org.apache.karaf.shell.api.action.Option) MastershipService(org.onosproject.mastership.MastershipService) ExecutorService(java.util.concurrent.ExecutorService) InstancePortService(org.onosproject.openstacknetworking.api.InstancePortService) OpenstackNodeService(org.onosproject.openstacknode.api.OpenstackNodeService) ClusterService(org.onosproject.cluster.ClusterService) OpenstackTroubleshootService(org.onosproject.openstacktroubleshoot.api.OpenstackTroubleshootService) InstancePortService(org.onosproject.openstacknetworking.api.InstancePortService) InstancePort(org.onosproject.openstacknetworking.api.InstancePort) NodeId(org.onosproject.cluster.NodeId) MastershipService(org.onosproject.mastership.MastershipService) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode)

Example 89 with NodeId

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

the class ResetMastershipCommand method doExecute.

@Override
protected void doExecute() {
    MastershipAdminService mastershipService = get(MastershipAdminService.class);
    ClusterService clusterService = get(ClusterService.class);
    DeviceService deviceService = get(DeviceService.class);
    if ((isConcentrate && isBalance) || (!isConcentrate && !isBalance)) {
        print("Please specify either -b or -c option only");
        return;
    }
    NodeId localId = clusterService.getLocalNode().id();
    if (isConcentrate) {
        deviceService.getAvailableDevices(Device.Type.SWITCH).forEach(d -> mastershipService.setRole(localId, d.id(), MastershipRole.MASTER));
    }
    if (isBalance) {
        mastershipService.balanceRoles();
    }
}
Also used : ClusterService(org.onosproject.cluster.ClusterService) MastershipAdminService(org.onosproject.mastership.MastershipAdminService) DeviceService(org.onosproject.net.device.DeviceService) NodeId(org.onosproject.cluster.NodeId)

Example 90 with NodeId

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

the class FpmManager method updateAcceptRouteFlag.

@Override
public void updateAcceptRouteFlag(Collection<FpmPeerAcceptRoutes> modifiedPeers) {
    modifiedPeers.forEach(modifiedPeer -> {
        log.debug("FPM connection to {} is disabled", modifiedPeer);
        NodeId localNode = clusterService.getLocalNode().id();
        log.debug("Peer Flag {}", modifiedPeer.isAcceptRoutes());
        peers.compute(modifiedPeer.peer(), (p, infos) -> {
            if (infos == null) {
                return null;
            }
            Iterator<FpmConnectionInfo> iterator = infos.iterator();
            if (iterator.hasNext()) {
                FpmConnectionInfo connectionInfo = iterator.next();
                if (connectionInfo.isAcceptRoutes() == modifiedPeer.isAcceptRoutes()) {
                    return null;
                }
                localPeers.remove(modifiedPeer.peer());
                infos.remove(connectionInfo);
                infos.add(new FpmConnectionInfo(localNode, modifiedPeer.peer(), System.currentTimeMillis(), modifiedPeer.isAcceptRoutes()));
                localPeers.put(modifiedPeer.peer(), infos);
            }
            Map<IpPrefix, Route> routes = fpmRoutes.get(modifiedPeer.peer());
            if (routes != null && !modifiedPeer.isAcceptRoutes()) {
                updateRouteStore(Lists.newArrayList(), routes.values());
            } else {
                updateRouteStore(routes.values(), Lists.newArrayList());
            }
            return infos;
        });
    });
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) NodeId(org.onosproject.cluster.NodeId) Route(org.onosproject.routeservice.Route)

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