Java Code Examples for org.onosproject.net.intent.IntentService#withdraw()

The following examples show how to use org.onosproject.net.intent.IntentService#withdraw() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OpticalIntentsWebResource.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Delete the specified optical intent.
 *
 * @param appId application identifier
 * @param keyString   intent key
 * @return 204 NO CONTENT
 */
@DELETE
@Consumes(MediaType.APPLICATION_JSON)
@Path("{appId}/{key}")
public Response deleteIntent(@PathParam("appId") String appId,
                             @PathParam("key") String keyString) {

    final ApplicationId app = get(CoreService.class).getAppId(appId);
    nullIsNotFound(app, "Application Id not found");

    IntentService intentService = get(IntentService.class);
    Intent intent = intentService.getIntent(Key.of(keyString, app));
    if (intent == null) {
        intent = intentService.getIntent(Key.of(Long.decode(keyString), app));
    }
    nullIsNotFound(intent, "Intent Id is not found");

    if ((intent instanceof OpticalConnectivityIntent) || (intent instanceof OpticalCircuitIntent)) {
        intentService.withdraw(intent);
    } else {
        throw new IllegalArgumentException("Specified intent is not of type OpticalConnectivityIntent");
    }

    return Response.noContent().build();
}
 
Example 2
Source File: IntentsWebResource.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * 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) {
        // No such intent.  REST standards recommend a positive status code
        // 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();
}