Search in sources :

Example 1 with WITHDRAWN

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

the class WipeOutCommand method wipeOutIntents.

private void wipeOutIntents() {
    print("Wiping intents");
    IntentService intentService = get(IntentService.class);
    Set<Key> keysToWithdrawn = Sets.newConcurrentHashSet();
    Set<Intent> intentsToWithdrawn = Tools.stream(intentService.getIntents()).filter(intent -> intentService.getIntentState(intent.key()) != WITHDRAWN).collect(Collectors.toSet());
    intentsToWithdrawn.stream().map(Intent::key).forEach(keysToWithdrawn::add);
    CompletableFuture<Void> completableFuture = new CompletableFuture<>();
    IntentListener listener = e -> {
        if (e.type() == IntentEvent.Type.WITHDRAWN) {
            keysToWithdrawn.remove(e.subject().key());
        }
        if (keysToWithdrawn.isEmpty()) {
            completableFuture.complete(null);
        }
    };
    intentService.addListener(listener);
    intentsToWithdrawn.forEach(intentService::withdraw);
    try {
        if (!intentsToWithdrawn.isEmpty()) {
            // Wait 1.5 seconds for each Intent
            completableFuture.get(intentsToWithdrawn.size() * 1500L, TimeUnit.MILLISECONDS);
        }
    } catch (InterruptedException | ExecutionException | TimeoutException e) {
        print("Encountered exception while withdrawing intents: " + e.toString());
    } finally {
        intentService.removeListener(listener);
    }
    intentsToWithdrawn.forEach(intentService::purge);
}
Also used : NetworkConfigService(org.onosproject.net.config.NetworkConfigService) LinkAdminService(org.onosproject.net.link.LinkAdminService) Tools(org.onlab.util.Tools) Host(org.onosproject.net.Host) IntentEvent(org.onosproject.net.intent.IntentEvent) UiExtensionService(org.onosproject.ui.UiExtensionService) TimeoutException(java.util.concurrent.TimeoutException) CompletableFuture(java.util.concurrent.CompletableFuture) Link(org.onosproject.net.Link) Command(org.apache.karaf.shell.api.action.Command) PacketRequest(org.onosproject.net.packet.PacketRequest) FlowRuleService(org.onosproject.net.flow.FlowRuleService) IntentService(org.onosproject.net.intent.IntentService) MeterService(org.onosproject.net.meter.MeterService) UiTopoLayoutService(org.onosproject.ui.UiTopoLayoutService) Intent(org.onosproject.net.intent.Intent) Device(org.onosproject.net.Device) GroupService(org.onosproject.net.group.GroupService) Set(java.util.Set) Argument(org.apache.karaf.shell.api.action.Argument) HostAdminService(org.onosproject.net.host.HostAdminService) PacketService(org.onosproject.net.packet.PacketService) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) DeviceAdminService(org.onosproject.net.device.DeviceAdminService) Key(org.onosproject.net.intent.Key) WITHDRAWN(org.onosproject.net.intent.IntentState.WITHDRAWN) IntentListener(org.onosproject.net.intent.IntentListener) Service(org.apache.karaf.shell.api.action.lifecycle.Service) RegionAdminService(org.onosproject.net.region.RegionAdminService) IntentService(org.onosproject.net.intent.IntentService) Intent(org.onosproject.net.intent.Intent) CompletableFuture(java.util.concurrent.CompletableFuture) IntentListener(org.onosproject.net.intent.IntentListener) ExecutionException(java.util.concurrent.ExecutionException) Key(org.onosproject.net.intent.Key) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

Sets (com.google.common.collect.Sets)1 Set (java.util.Set)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeUnit (java.util.concurrent.TimeUnit)1 TimeoutException (java.util.concurrent.TimeoutException)1 Collectors (java.util.stream.Collectors)1 Argument (org.apache.karaf.shell.api.action.Argument)1 Command (org.apache.karaf.shell.api.action.Command)1 Service (org.apache.karaf.shell.api.action.lifecycle.Service)1 Tools (org.onlab.util.Tools)1 AbstractShellCommand (org.onosproject.cli.AbstractShellCommand)1 Device (org.onosproject.net.Device)1 Host (org.onosproject.net.Host)1 Link (org.onosproject.net.Link)1 NetworkConfigService (org.onosproject.net.config.NetworkConfigService)1 DeviceAdminService (org.onosproject.net.device.DeviceAdminService)1 FlowRuleService (org.onosproject.net.flow.FlowRuleService)1 GroupService (org.onosproject.net.group.GroupService)1 HostAdminService (org.onosproject.net.host.HostAdminService)1