Search in sources :

Example 86 with ApplicationId

use of org.onosproject.core.ApplicationId in project onos by opennetworkinglab.

the class IntentsWebResource method getIntentFlowsById.

/**
 * Gets all related flow entries created by a particular intent.
 * Returns all flow entries of the specified intent.
 *
 * @param appId application identifier
 * @param key   intent key
 * @return 200 OK with intent data
 * @onos.rsModel Relatedflows
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("relatedflows/{appId}/{key}")
public Response getIntentFlowsById(@PathParam("appId") String appId, @PathParam("key") String key) {
    ApplicationId applicationId = get(CoreService.class).getAppId(appId);
    nullIsNotFound(applicationId, APP_ID_NOT_FOUND);
    IntentService intentService = get(IntentService.class);
    FlowRuleService flowService = get(FlowRuleService.class);
    Intent intent = intentService.getIntent(Key.of(key, applicationId));
    if (intent == null) {
        long numericalKey = Long.decode(key);
        intent = intentService.getIntent(Key.of(numericalKey, applicationId));
    }
    nullIsNotFound(intent, INTENT_NOT_FOUND);
    ObjectNode root = mapper().createObjectNode();
    root.put(APP_ID, appId);
    root.put(ID, key);
    IntentFilter intentFilter = new IntentFilter(intentService, flowService);
    List<Intent> installables = intentService.getInstallableIntents(intent.key());
    root.put(INTENT_TYPE, intent.getClass().getSimpleName());
    ArrayNode pathsNode = root.putArray(INTENT_PATHS);
    for (List<FlowEntry> flowEntries : intentFilter.readIntentFlows(installables)) {
        ArrayNode flowNode = pathsNode.addArray();
        for (FlowEntry entry : flowEntries) {
            flowNode.add(codec(FlowEntry.class).encode(entry, this));
        }
    }
    return ok(root).build();
}
Also used : IntentService(org.onosproject.net.intent.IntentService) IntentFilter(org.onosproject.net.intent.util.IntentFilter) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) CoreService(org.onosproject.core.CoreService) Intent(org.onosproject.net.intent.Intent) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ApplicationId(org.onosproject.core.ApplicationId) FlowRuleService(org.onosproject.net.flow.FlowRuleService) FlowEntry(org.onosproject.net.flow.FlowEntry) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 87 with ApplicationId

use of org.onosproject.core.ApplicationId in project onos by opennetworkinglab.

the class IntentsResourceTest method testBadRemove.

/**
 * Tests removal of a non existent intent with DELETE.
 */
@Test
public void testBadRemove() {
    final ApplicationId appId = new DefaultApplicationId(2, "app");
    expect(mockCoreService.getAppId("app")).andReturn(appId).once();
    replay(mockCoreService);
    expect(mockIntentService.getIntent(Key.of(2, appId))).andReturn(null).once();
    expect(mockIntentService.getIntent(Key.of("0x2", appId))).andReturn(null).once();
    replay(mockIntentService);
    WebTarget wt = target();
    Response response = wt.path("intents/app/0x2").request(MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN).delete();
    assertThat(response.getStatus(), is(HttpURLConnection.HTTP_NO_CONTENT));
}
Also used : Response(javax.ws.rs.core.Response) WebTarget(javax.ws.rs.client.WebTarget) DefaultApplicationId(org.onosproject.core.DefaultApplicationId) ApplicationId(org.onosproject.core.ApplicationId) DefaultApplicationId(org.onosproject.core.DefaultApplicationId) Test(org.junit.Test)

Example 88 with ApplicationId

use of org.onosproject.core.ApplicationId in project onos by opennetworkinglab.

the class IntentsResourceTest method testPost.

/**
 * Tests creating an intent with POST.
 */
@Test
public void testPost() {
    ApplicationId testId = new DefaultApplicationId(2, "myApp");
    expect(mockCoreService.getAppId("myApp")).andReturn(testId);
    replay(mockCoreService);
    mockIntentService.submit(anyObject());
    expectLastCall();
    replay(mockIntentService);
    InputStream jsonStream = IntentsResourceTest.class.getResourceAsStream("post-intent.json");
    WebTarget wt = target();
    Response response = wt.path("intents").request(MediaType.APPLICATION_JSON_TYPE).post(Entity.json(jsonStream));
    assertThat(response.getStatus(), is(HttpURLConnection.HTTP_CREATED));
    String location = response.getLocation().getPath();
    assertThat(location, Matchers.startsWith("/intents/myApp/"));
}
Also used : Response(javax.ws.rs.core.Response) InputStream(java.io.InputStream) WebTarget(javax.ws.rs.client.WebTarget) DefaultApplicationId(org.onosproject.core.DefaultApplicationId) ApplicationId(org.onosproject.core.ApplicationId) DefaultApplicationId(org.onosproject.core.DefaultApplicationId) Test(org.junit.Test)

Example 89 with ApplicationId

use of org.onosproject.core.ApplicationId in project onos by opennetworkinglab.

the class ApplicationsWebResource method health.

/**
 * Get application health.
 *
 * @param name application name
 * @return 200 OK with app health in the body; 404 if app is not found
 */
@GET
@Path("{name}/health")
public Response health(@PathParam("name") String name) {
    ApplicationAdminService service = get(ApplicationAdminService.class);
    ApplicationId appId = service.getId(name);
    nullIsNotFound(appId, APP_ID_NOT_FOUND + ": " + name);
    Application app = service.getApplication(appId);
    nullIsNotFound(app, APP_NOT_FOUND + ": " + appId);
    ComponentsMonitorService componentsMonitorService = get(ComponentsMonitorService.class);
    boolean ready = componentsMonitorService.isFullyStarted(app.features());
    return Response.ok(mapper().createObjectNode().put("message", ready ? APP_READY : APP_PENDING)).build();
}
Also used : ComponentsMonitorService(org.onosproject.cluster.ComponentsMonitorService) ApplicationId(org.onosproject.core.ApplicationId) Application(org.onosproject.core.Application) ApplicationAdminService(org.onosproject.app.ApplicationAdminService) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 90 with ApplicationId

use of org.onosproject.core.ApplicationId in project onos by opennetworkinglab.

the class ApplicationsWebResource method getAppIdByName.

/**
 * Gets applicationId entry by either id or name.
 *
 * @param id   id of application
 * @param name name of application
 * @return 200 OK; 404; 401
 * @onos.rsModel ApplicationId
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("ids/entry")
public Response getAppIdByName(@QueryParam("id") String id, @QueryParam("name") String name) {
    CoreService service = get(CoreService.class);
    ApplicationId appId = null;
    if (id != null) {
        appId = service.getAppId(Short.valueOf(id));
    } else if (name != null) {
        appId = service.getAppId(name);
    }
    return response(appId);
}
Also used : CoreService(org.onosproject.core.CoreService) ApplicationId(org.onosproject.core.ApplicationId) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

ApplicationId (org.onosproject.core.ApplicationId)138 CoreService (org.onosproject.core.CoreService)36 Activate (org.osgi.service.component.annotations.Activate)36 DefaultApplicationId (org.onosproject.core.DefaultApplicationId)25 Path (javax.ws.rs.Path)21 Produces (javax.ws.rs.Produces)16 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)15 GET (javax.ws.rs.GET)14 Test (org.junit.Test)13 ApplicationAdminService (org.onosproject.app.ApplicationAdminService)11 FlowRuleService (org.onosproject.net.flow.FlowRuleService)11 TrafficSelector (org.onosproject.net.flow.TrafficSelector)11 Intent (org.onosproject.net.intent.Intent)11 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)10 JsonNode (com.fasterxml.jackson.databind.JsonNode)9 InputStream (java.io.InputStream)9 DeviceId (org.onosproject.net.DeviceId)9 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)9 IntentService (org.onosproject.net.intent.IntentService)9 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)8