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

The following examples show how to use org.onosproject.net.intent.IntentService#purge() . 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: TopologyViewMessageHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void process(ObjectNode payload) {
    IntentService intentService = get(IntentService.class);
    for (Intent intent : intentService.getIntents()) {
        if (intentService.getIntentState(intent.key()) == IntentState.WITHDRAWN) {
            intentService.purge(intent);
        }
    }

}
 
Example 2
Source File: IntentPurgeCommand.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
protected void doExecute() {
    IntentService intentService = get(IntentService.class);
    for (Intent intent: intentService.getIntents()) {
        if (intentService.getIntentState(intent.key()) == WITHDRAWN) {
            intentService.purge(intent);
        }
    }
}
 
Example 3
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();
}