Search in sources :

Example 26 with IntentService

use of org.onosproject.net.intent.IntentService in project onos by opennetworkinglab.

the class IntentCodecTest method setUpIntentService.

@Before
public void setUpIntentService() {
    final IntentService mockIntentService = new IntentServiceAdapter();
    context.registerService(IntentService.class, mockIntentService);
    context.registerService(CoreService.class, mockCoreService);
    expect(mockCoreService.getAppId(appId.name())).andReturn(appId);
    replay(mockCoreService);
}
Also used : IntentServiceAdapter(org.onosproject.net.intent.IntentServiceAdapter) IntentService(org.onosproject.net.intent.IntentService) Before(org.junit.Before)

Example 27 with IntentService

use of org.onosproject.net.intent.IntentService in project onos by opennetworkinglab.

the class MultiPointToSinglePointIntentCodecTest method setUpIntentService.

@Before
public void setUpIntentService() {
    final IntentService mockIntentService = new IntentServiceAdapter();
    context.registerService(IntentService.class, mockIntentService);
    context.registerService(CoreService.class, mockCoreService);
    expect(mockCoreService.getAppId(APPID.name())).andReturn(APPID);
    replay(mockCoreService);
}
Also used : IntentServiceAdapter(org.onosproject.net.intent.IntentServiceAdapter) IntentService(org.onosproject.net.intent.IntentService) Before(org.junit.Before)

Example 28 with IntentService

use of org.onosproject.net.intent.IntentService 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 29 with IntentService

use of org.onosproject.net.intent.IntentService 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 30 with IntentService

use of org.onosproject.net.intent.IntentService 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

IntentService (org.onosproject.net.intent.IntentService)36 Intent (org.onosproject.net.intent.Intent)19 ApplicationId (org.onosproject.core.ApplicationId)8 ConnectPoint (org.onosproject.net.ConnectPoint)8 CoreService (org.onosproject.core.CoreService)7 Key (org.onosproject.net.intent.Key)7 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)6 FlowRuleIntent (org.onosproject.net.intent.FlowRuleIntent)6 Path (javax.ws.rs.Path)5 Produces (javax.ws.rs.Produces)5 StringsCompleter (org.apache.karaf.shell.support.completers.StringsCompleter)5 Link (org.onosproject.net.Link)5 TrafficSelector (org.onosproject.net.flow.TrafficSelector)5 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)5 Constraint (org.onosproject.net.intent.Constraint)5 OpticalConnectivityIntent (org.onosproject.net.intent.OpticalConnectivityIntent)5 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)3 IOException (java.io.IOException)3 HashSet (java.util.HashSet)3 Consumes (javax.ws.rs.Consumes)3