Search in sources :

Example 81 with ApplicationId

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;
}
Also used : ApplicationEvent(org.onosproject.app.ApplicationEvent) DefaultApplication(org.onosproject.core.DefaultApplication) ApplicationId(org.onosproject.core.ApplicationId) ApplicationDescription(org.onosproject.app.ApplicationDescription)

Example 82 with ApplicationId

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;
}
Also used : ApplicationId(org.onosproject.core.ApplicationId)

Example 83 with ApplicationId

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));
}
Also used : NetworkResource(org.onosproject.net.NetworkResource) Response(javax.ws.rs.core.Response) IntentService(org.onosproject.net.intent.IntentService) FakeIntentManager(org.onosproject.net.intent.FakeIntentManager) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) ConnectivityIntent(org.onosproject.net.intent.ConnectivityIntent) Intent(org.onosproject.net.intent.Intent) PathIntent(org.onosproject.net.intent.PathIntent) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) MockIntent(org.onosproject.net.intent.IntentTestsMocks.MockIntent) WebTarget(javax.ws.rs.client.WebTarget) DefaultApplicationId(org.onosproject.core.DefaultApplicationId) ApplicationId(org.onosproject.core.ApplicationId) MockIntent(org.onosproject.net.intent.IntentTestsMocks.MockIntent) DefaultApplicationId(org.onosproject.core.DefaultApplicationId) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 84 with ApplicationId

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();
}
Also used : IntentService(org.onosproject.net.intent.IntentService) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) CoreService(org.onosproject.core.CoreService) Intent(org.onosproject.net.intent.Intent) ApplicationId(org.onosproject.core.ApplicationId) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 85 with ApplicationId

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();
}
Also used : IntentService(org.onosproject.net.intent.IntentService) IntentState(org.onosproject.net.intent.IntentState) CoreService(org.onosproject.core.CoreService) Intent(org.onosproject.net.intent.Intent) ApplicationId(org.onosproject.core.ApplicationId) CountDownLatch(java.util.concurrent.CountDownLatch) IntentListener(org.onosproject.net.intent.IntentListener) Key(org.onosproject.net.intent.Key) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

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