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();
}
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));
}
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/"));
}
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();
}
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);
}
Aggregations