use of org.onosproject.core.ApplicationId in project onos by opennetworkinglab.
the class SimpleApplicationStore method create.
@Override
public Application create(InputStream appDescStream) {
ApplicationDescription appDesc = saveApplication(appDescStream);
ApplicationId appId = idStore.registerApplication(appDesc.name());
DefaultApplication app = DefaultApplication.builder(appDesc).withAppId(appId).build();
apps.put(appId, app);
states.put(appId, INSTALLED);
delegate.notify(new ApplicationEvent(APP_INSTALLED, app));
return app;
}
use of org.onosproject.core.ApplicationId in project onos by opennetworkinglab.
the class CoreManager method registerApplication.
@Override
public ApplicationId registerApplication(String name, Runnable preDeactivate) {
checkPermission(APP_WRITE);
ApplicationId id = registerApplication(name);
appService.registerDeactivateHook(id, preDeactivate);
return id;
}
use of org.onosproject.core.ApplicationId in project onos by opennetworkinglab.
the class IntentsResourceTest method testRemove.
/**
* Tests removing an intent with DELETE.
*/
@Test
public void testRemove() {
final HashSet<NetworkResource> resources = new HashSet<>();
resources.add(new MockResource(1));
resources.add(new MockResource(2));
resources.add(new MockResource(3));
final Intent intent = new MockIntent(3L, resources);
final ApplicationId appId = new DefaultApplicationId(2, "app");
IntentService fakeManager = new FakeIntentManager();
expect(mockCoreService.getAppId("app")).andReturn(appId).once();
replay(mockCoreService);
mockIntentService.withdraw(anyObject());
expectLastCall().andDelegateTo(fakeManager).once();
expect(mockIntentService.getIntent(Key.of(2, appId))).andReturn(intent).once();
expect(mockIntentService.getIntent(Key.of("0x2", appId))).andReturn(null).once();
mockIntentService.addListener(anyObject());
expectLastCall().andDelegateTo(fakeManager).once();
mockIntentService.removeListener(anyObject());
expectLastCall().andDelegateTo(fakeManager).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 IntentsWebResource method getIntentWithInstallable.
/**
* Gets intent installables by application ID and key.
* @param appId application identifier
* @param key intent key
*
* @return 200 OK with array of the intent installables
* @onos.rsModel Intents
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("installables/{appId}/{key}")
public Response getIntentWithInstallable(@PathParam("appId") String appId, @PathParam("key") String key) {
final IntentService intentService = get(IntentService.class);
final ApplicationId app = get(CoreService.class).getAppId(appId);
nullIsNotFound(app, APP_ID_NOT_FOUND);
Intent intent = intentService.getIntent(Key.of(key, app));
if (intent == null) {
long numericalKey = Long.decode(key);
intent = intentService.getIntent(Key.of(numericalKey, app));
}
nullIsNotFound(intent, INTENT_NOT_FOUND);
final Iterable<Intent> installables = intentService.getInstallableIntents(intent.key());
final ObjectNode root = encodeArray(Intent.class, "installables", installables);
return ok(root).build();
}
use of org.onosproject.core.ApplicationId in project onos by opennetworkinglab.
the class IntentsWebResource method deleteIntentById.
/**
* Withdraws intent.
* Withdraws the specified intent from the system.
*
* @param appId application identifier
* @param key intent key
* @return 204 NO CONTENT
*/
@DELETE
@Path("{appId}/{key}")
public Response deleteIntentById(@PathParam("appId") String appId, @PathParam("key") String key) {
final ApplicationId app = get(CoreService.class).getAppId(appId);
nullIsNotFound(app, APP_ID_NOT_FOUND);
Intent intent = get(IntentService.class).getIntent(Key.of(key, app));
IntentService service = get(IntentService.class);
if (intent == null) {
intent = service.getIntent(Key.of(Long.decode(key), app));
}
if (intent == null) {
// in this case.
return Response.noContent().build();
}
Key k = intent.key();
// set up latch and listener to track uninstall progress
CountDownLatch latch = new CountDownLatch(1);
IntentListener listener = new DeleteListener(k, latch);
service.addListener(listener);
try {
// request the withdraw
service.withdraw(intent);
try {
latch.await(WITHDRAW_EVENT_TIMEOUT_SECONDS, TimeUnit.SECONDS);
} catch (InterruptedException e) {
log.info("REST Delete operation timed out waiting for intent {}", k);
Thread.currentThread().interrupt();
}
// double check the state
IntentState state = service.getIntentState(k);
if (state == WITHDRAWN || state == FAILED) {
service.purge(intent);
}
} finally {
// clean up the listener
service.removeListener(listener);
}
return Response.noContent().build();
}
Aggregations