Search in sources :

Example 11 with MastershipService

use of org.onosproject.mastership.MastershipService in project onos by opennetworkinglab.

the class MastershipWebResource method getDeviceOf.

/**
 * Returns the devices for which a controller is master.
 *
 * @param nodeId controller identifier
 * @return 200 OK with a set of device identifiers
 * @onos.rsModel DeviceIds
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{nodeId}/device")
public Response getDeviceOf(@PathParam("nodeId") String nodeId) {
    MastershipService mastershipService = get(MastershipService.class);
    ObjectNode root = mapper().createObjectNode();
    ArrayNode devicesNode = root.putArray(DEVICE_IDS);
    Set<DeviceId> devices = mastershipService.getDevicesOf(NodeId.nodeId(nodeId));
    if (devices != null) {
        devices.forEach(id -> devicesNode.add(id.toString()));
    }
    return ok(root).build();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DeviceId(org.onosproject.net.DeviceId) MastershipService(org.onosproject.mastership.MastershipService) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 12 with MastershipService

use of org.onosproject.mastership.MastershipService in project onos by opennetworkinglab.

the class MastershipWebResource method getLocalRole.

/**
 * Returns the role of the local node for the specified device.
 *
 * @param deviceId device identifier
 * @return 200 OK with role of the current node
 * @onos.rsModel MastershipRole
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{deviceId}/local")
public Response getLocalRole(@PathParam("deviceId") String deviceId) {
    MastershipService mastershipService = get(MastershipService.class);
    MastershipRole role = mastershipService.getLocalRole(DeviceId.deviceId(deviceId));
    ObjectNode root = codec(MastershipRole.class).encode(role, this);
    return ok(root).build();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) MastershipService(org.onosproject.mastership.MastershipService) MastershipRole(org.onosproject.net.MastershipRole) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 13 with MastershipService

use of org.onosproject.mastership.MastershipService in project onos by opennetworkinglab.

the class MastershipWebResource method getNodesFor.

/**
 * Returns controllers connected to a given device, in order of
 * preference. The first entry in the list is the current master.
 *
 * @param deviceId device identifier
 * @return 200 OK with a list of controller identifiers
 * @onos.rsModel RoleInfo
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{deviceId}/role")
public Response getNodesFor(@PathParam("deviceId") String deviceId) {
    MastershipService mastershipService = get(MastershipService.class);
    RoleInfo info = nullIsNotFound(mastershipService.getNodesFor(DeviceId.deviceId(deviceId)), ROLE_INFO_NOT_FOUND);
    ObjectNode root = codec(RoleInfo.class).encode(info, this);
    return ok(root).build();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) RoleInfo(org.onosproject.cluster.RoleInfo) MastershipService(org.onosproject.mastership.MastershipService) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 14 with MastershipService

use of org.onosproject.mastership.MastershipService in project onos by opennetworkinglab.

the class MastershipWebResource method requestRoleFor.

/**
 * Returns the mastership status of the local controller for a given
 * device forcing master selection if necessary.
 *
 * @param deviceId device identifier
 * @return 200 OK with the role of this controller instance
 * @onos.rsModel MastershipRole
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{deviceId}/request")
public Response requestRoleFor(@PathParam("deviceId") String deviceId) {
    MastershipService mastershipService = get(MastershipService.class);
    DeviceService deviceService = get(DeviceService.class);
    DeviceId id = DeviceId.deviceId(deviceId);
    nullIsNotFound(deviceService.getDevice(id), DEVICE_ID_NOT_FOUND);
    MastershipRole role = nullIsNotFound(mastershipService.requestRoleForSync(id), MASTERSHIP_ROLE_NOT_FOUND);
    ObjectNode root = codec(MastershipRole.class).encode(role, this);
    return ok(root).build();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DeviceId(org.onosproject.net.DeviceId) DeviceService(org.onosproject.net.device.DeviceService) MastershipService(org.onosproject.mastership.MastershipService) MastershipRole(org.onosproject.net.MastershipRole) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 15 with MastershipService

use of org.onosproject.mastership.MastershipService in project onos by opennetworkinglab.

the class TestCodecService method setup.

@Before
public void setup() throws IOException {
    storageService = new TestStorageService();
    mastershipService = createNiceMock(MastershipService.class);
    coreService = createNiceMock(CoreService.class);
    hostService = createNiceMock(HostService.class);
    deviceService = createNiceMock(DeviceService.class);
    expect(deviceService.getDevices()).andReturn(ImmutableList.of()).anyTimes();
    networkConfigRegistry = createNiceMock(NetworkConfigRegistry.class);
    networkConfigService = createNiceMock(NetworkConfigService.class);
    manager = new SimpleIntManager();
    manager.coreService = coreService;
    manager.deviceService = deviceService;
    manager.storageService = storageService;
    manager.mastershipService = mastershipService;
    manager.hostService = hostService;
    manager.netcfgService = networkConfigService;
    manager.netcfgRegistry = networkConfigRegistry;
    manager.eventExecutor = MoreExecutors.newDirectExecutorService();
    manager.codecService = codecService;
    expect(coreService.registerApplication(APP_NAME)).andReturn(APP_ID).anyTimes();
    networkConfigRegistry.registerConfigFactory(anyObject());
    expectLastCall().once();
    Capture<NetworkConfigListener> capture = newCapture();
    networkConfigService.addListener(EasyMock.capture(capture));
    expectLastCall().once();
    IntReportConfig config = getIntReportConfig("/report-config.json");
    expect(networkConfigService.getConfig(APP_ID, IntReportConfig.class)).andReturn(config).anyTimes();
    replay(mastershipService, deviceService, coreService, hostService, networkConfigRegistry, networkConfigService);
    manager.activate();
    networkConfigListener = capture.getValue();
}
Also used : HostService(org.onosproject.net.host.HostService) NetworkConfigRegistry(org.onosproject.net.config.NetworkConfigRegistry) NetworkConfigService(org.onosproject.net.config.NetworkConfigService) TestStorageService(org.onosproject.store.service.TestStorageService) DeviceService(org.onosproject.net.device.DeviceService) CoreService(org.onosproject.core.CoreService) MastershipService(org.onosproject.mastership.MastershipService) IntReportConfig(org.onosproject.net.behaviour.inbandtelemetry.IntReportConfig) NetworkConfigListener(org.onosproject.net.config.NetworkConfigListener) Before(org.junit.Before)

Aggregations

MastershipService (org.onosproject.mastership.MastershipService)41 DeviceId (org.onosproject.net.DeviceId)29 DriverHandler (org.onosproject.net.driver.DriverHandler)20 NetconfController (org.onosproject.netconf.NetconfController)20 NetconfException (org.onosproject.netconf.NetconfException)20 NodeId (org.onosproject.cluster.NodeId)9 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 GET (javax.ws.rs.GET)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 ControllerInfo (org.onosproject.net.behaviour.ControllerInfo)5 ArrayList (java.util.ArrayList)4 DeviceService (org.onosproject.net.device.DeviceService)4 ClusterService (org.onosproject.cluster.ClusterService)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Sets (com.google.common.collect.Sets)2 Set (java.util.Set)2 ExecutorService (java.util.concurrent.ExecutorService)2 Executors.newSingleThreadScheduledExecutor (java.util.concurrent.Executors.newSingleThreadScheduledExecutor)2