Search in sources :

Example 11 with ClusterService

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

the class GossipDeviceStoreTest method setUp.

@Before
public void setUp() throws Exception {
    clusterCommunicator = createNiceMock(ClusterCommunicationService.class);
    replay(clusterCommunicator);
    ClusterService clusterService = new TestClusterService();
    testGossipDeviceStore = new TestGossipDeviceStore(deviceClockService, clusterService, clusterCommunicator);
    testGossipDeviceStore.mastershipService = new TestMastershipService();
    ecMapBuilder = createNiceMock(EventuallyConsistentMapBuilder.class);
    expect(ecMapBuilder.withName(anyObject(String.class))).andReturn(ecMapBuilder).anyTimes();
    expect(ecMapBuilder.withSerializer(anyObject(KryoNamespace.Builder.class))).andReturn(ecMapBuilder).anyTimes();
    expect(ecMapBuilder.withAntiEntropyPeriod(5, TimeUnit.SECONDS)).andReturn(ecMapBuilder).anyTimes();
    expect(ecMapBuilder.withTimestampProvider(anyObject(BiFunction.class))).andReturn(ecMapBuilder).anyTimes();
    expect(ecMapBuilder.withTombstonesDisabled()).andReturn(ecMapBuilder).anyTimes();
    ecMap = createNiceMock(EventuallyConsistentMap.class);
    expect(ecMapBuilder.build()).andReturn(ecMap).anyTimes();
    testStorageService = createNiceMock(StorageService.class);
    expect(testStorageService.eventuallyConsistentMapBuilder()).andReturn(ecMapBuilder).anyTimes();
    replay(testStorageService, ecMapBuilder, ecMap);
    testGossipDeviceStore.storageService = testStorageService;
    testGossipDeviceStore.deviceClockService = deviceClockService;
    gossipDeviceStore = testGossipDeviceStore;
    gossipDeviceStore.activate();
    deviceStore = gossipDeviceStore;
    verify(clusterCommunicator);
    reset(clusterCommunicator);
}
Also used : ClusterService(org.onosproject.cluster.ClusterService) StaticClusterService(org.onosproject.store.cluster.StaticClusterService) ClusterCommunicationService(org.onosproject.store.cluster.messaging.ClusterCommunicationService) EventuallyConsistentMapBuilder(org.onosproject.store.service.EventuallyConsistentMapBuilder) EventuallyConsistentMap(org.onosproject.store.service.EventuallyConsistentMap) KryoNamespace(org.onlab.util.KryoNamespace) StorageService(org.onosproject.store.service.StorageService) Before(org.junit.Before)

Example 12 with ClusterService

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

the class DistributedGroupStoreTest method setUp.

@Before
public void setUp() throws Exception {
    groupStoreImpl = new DistributedGroupStore();
    groupStoreImpl.storageService = new TestStorageService();
    groupStoreImpl.clusterCommunicator = new ClusterCommunicationServiceAdapter();
    groupStoreImpl.mastershipService = new MasterOfAll();
    groupStoreImpl.cfgService = new ComponentConfigAdapter();
    groupStoreImpl.deviceService = new InternalDeviceServiceImpl();
    ClusterService mockClusterService = createMock(ClusterService.class);
    NodeId nodeId = new NodeId(NODE_ID);
    MockControllerNode mockControllerNode = new MockControllerNode(nodeId);
    expect(mockClusterService.getLocalNode()).andReturn(mockControllerNode).anyTimes();
    replay(mockClusterService);
    groupStoreImpl.clusterService = mockClusterService;
    groupStoreImpl.activate(null);
    groupStore = groupStoreImpl;
    auditPendingReqQueue = TestUtils.getField(groupStoreImpl, "auditPendingReqQueue");
}
Also used : ComponentConfigAdapter(org.onosproject.cfg.ComponentConfigAdapter) ClusterService(org.onosproject.cluster.ClusterService) TestStorageService(org.onosproject.store.service.TestStorageService) NodeId(org.onosproject.cluster.NodeId) ClusterCommunicationServiceAdapter(org.onosproject.store.cluster.messaging.ClusterCommunicationServiceAdapter) Before(org.junit.Before)

Example 13 with ClusterService

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

the class ControlMetricsWebResource method controlMessageMetrics.

/**
 * Returns control message metrics of a given device.
 *
 * @param deviceId device identification
 * @return control message metrics of a given device
 * @onos.rsModel ControlMessageMetric
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("messages/{deviceId}")
public Response controlMessageMetrics(@PathParam("deviceId") String deviceId) {
    ObjectNode root = mapper().createObjectNode();
    ControlPlaneMonitorService monitorService = get(ControlPlaneMonitorService.class);
    ClusterService clusterService = get(ClusterService.class);
    NodeId localNodeId = clusterService.getLocalNode().id();
    metricsStats(monitorService, localNodeId, CONTROL_MESSAGE_METRICS, DeviceId.deviceId(deviceId), root);
    return ok(root).build();
}
Also used : ClusterService(org.onosproject.cluster.ClusterService) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ControlPlaneMonitorService(org.onosproject.cpman.ControlPlaneMonitorService) NodeId(org.onosproject.cluster.NodeId) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 14 with ClusterService

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

the class ControlMetricsWebResource method controlMessageMetrics.

/**
 * Returns control message metrics of all devices.
 *
 * @return array of all control message metrics
 * @onos.rsModel ControlMessageMetrics
 */
@GET
@Path("messages")
@Produces(MediaType.APPLICATION_JSON)
public Response controlMessageMetrics() {
    ObjectNode root = mapper().createObjectNode();
    ControlPlaneMonitorService monitorService = get(ControlPlaneMonitorService.class);
    ClusterService clusterService = get(ClusterService.class);
    NodeId localNodeId = clusterService.getLocalNode().id();
    ArrayNode deviceNodes = root.putArray("devices");
    monitorService.availableResourcesSync(localNodeId, CONTROL_MESSAGE).forEach(name -> {
        ObjectNode deviceNode = mapper().createObjectNode();
        ObjectNode valueNode = mapper().createObjectNode();
        metricsStats(monitorService, localNodeId, CONTROL_MESSAGE_METRICS, DeviceId.deviceId(name), valueNode);
        deviceNode.put("name", name);
        deviceNode.set("value", valueNode);
        deviceNodes.add(deviceNode);
    });
    return ok(root).build();
}
Also used : ClusterService(org.onosproject.cluster.ClusterService) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ControlPlaneMonitorService(org.onosproject.cpman.ControlPlaneMonitorService) NodeId(org.onosproject.cluster.NodeId) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 15 with ClusterService

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

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