Search in sources :

Example 16 with ClusterService

use of org.onosproject.cluster.ClusterService 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 17 with ClusterService

use of org.onosproject.cluster.ClusterService 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 18 with ClusterService

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

the class FpmConnectionsList method print.

private void print(FpmPeerInfo info) {
    ClusterService clusterService = get(ClusterService.class);
    info.connections().forEach(cinfo -> print(FORMAT, cinfo.peer().address(), cinfo.peer().port(), cinfo.connectedTo(), Tools.timeAgo(cinfo.connectTime()), cinfo.connectedTo().equals(clusterService.getLocalNode().id()) ? "*" : "", info.routes(), cinfo.isAcceptRoutes()));
}
Also used : ClusterService(org.onosproject.cluster.ClusterService)

Example 19 with ClusterService

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

the class LeaderElectorTestCommand method doExecute.

@Override
protected void doExecute() {
    ClusterService clusterService = get(ClusterService.class);
    DistributedPrimitivesTest test = get(DistributedPrimitivesTest.class);
    leaderElector = test.getLeaderElector(name);
    NodeId localNodeId = clusterService.getLocalNode().id();
    if ("run".equals(operation)) {
        print(leaderElector.run(topic, localNodeId));
    } else if ("withdraw".equals(operation)) {
        leaderElector.withdraw(topic);
    } else if ("show".equals(operation)) {
        print(leaderElector.getLeadership(topic));
    }
}
Also used : ClusterService(org.onosproject.cluster.ClusterService) NodeId(org.onosproject.cluster.NodeId) DistributedPrimitivesTest(org.onosproject.distributedprimitives.DistributedPrimitivesTest)

Example 20 with ClusterService

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

the class SimpleVirtualMastershipStore method createFakeClusterService.

/**
 * Returns a fake cluster service for a test purpose only.
 *
 * @return a fake cluster service
 */
private ClusterService createFakeClusterService() {
    // just for ease of unit test
    final ControllerNode instance = new DefaultControllerNode(new NodeId("local"), IpAddress.valueOf("127.0.0.1"));
    ClusterService faceClusterService = new ClusterService() {

        private final Instant creationTime = Instant.now();

        @Override
        public ControllerNode getLocalNode() {
            return instance;
        }

        @Override
        public Set<ControllerNode> getNodes() {
            return ImmutableSet.of(instance);
        }

        @Override
        public Set<Node> getConsensusNodes() {
            return ImmutableSet.of();
        }

        @Override
        public ControllerNode getNode(NodeId nodeId) {
            if (instance.id().equals(nodeId)) {
                return instance;
            }
            return null;
        }

        @Override
        public ControllerNode.State getState(NodeId nodeId) {
            if (instance.id().equals(nodeId)) {
                return ControllerNode.State.ACTIVE;
            } else {
                return ControllerNode.State.INACTIVE;
            }
        }

        @Override
        public Version getVersion(NodeId nodeId) {
            if (instance.id().equals(nodeId)) {
                return versionService.version();
            }
            return null;
        }

        @Override
        public Instant getLastUpdatedInstant(NodeId nodeId) {
            return creationTime;
        }

        @Override
        public void addListener(ClusterEventListener listener) {
        }

        @Override
        public void removeListener(ClusterEventListener listener) {
        }
    };
    return faceClusterService;
}
Also used : ClusterService(org.onosproject.cluster.ClusterService) Instant(java.time.Instant) ControllerNode(org.onosproject.cluster.ControllerNode) DefaultControllerNode(org.onosproject.cluster.DefaultControllerNode) Node(org.onosproject.cluster.Node) NodeId(org.onosproject.cluster.NodeId) ControllerNode(org.onosproject.cluster.ControllerNode) DefaultControllerNode(org.onosproject.cluster.DefaultControllerNode) DefaultControllerNode(org.onosproject.cluster.DefaultControllerNode) ClusterEventListener(org.onosproject.cluster.ClusterEventListener)

Aggregations

ClusterService (org.onosproject.cluster.ClusterService)25 NodeId (org.onosproject.cluster.NodeId)17 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)8 ControllerNode (org.onosproject.cluster.ControllerNode)8 GET (javax.ws.rs.GET)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 ControlPlaneMonitorService (org.onosproject.cpman.ControlPlaneMonitorService)6 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)5 Set (java.util.Set)4 ExecutorService (java.util.concurrent.ExecutorService)3 Collectors (java.util.stream.Collectors)3 Command (org.apache.karaf.shell.api.action.Command)3 Option (org.apache.karaf.shell.api.action.Option)3 Before (org.junit.Before)3 IpAddress (org.onlab.packet.IpAddress)3 Sets (com.google.common.collect.Sets)2 Instant (java.time.Instant)2 Collection (java.util.Collection)2 Executors.newSingleThreadScheduledExecutor (java.util.concurrent.Executors.newSingleThreadScheduledExecutor)2