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