use of org.onosproject.net.intent.Key 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);
}
use of org.onosproject.net.intent.Key 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();
}
use of org.onosproject.net.intent.Key in project onos by opennetworkinglab.
the class VplsIntentTest method generateVplsBrc.
/**
* Generates a list of the expected sp2mp intents for a VPLS.
*
* @param fcPoints the filtered connect point
* @param name the name of the VPLS
* @param encap the encapsulation type
* @return the list of expected sp2mp intents for the given VPLS
*/
private List<SinglePointToMultiPointIntent> generateVplsBrc(Set<FilteredConnectPoint> fcPoints, String name, EncapsulationType encap) {
List<SinglePointToMultiPointIntent> intents = Lists.newArrayList();
fcPoints.forEach(point -> {
Set<FilteredConnectPoint> otherPoints = fcPoints.stream().filter(fcp -> !fcp.equals(point)).collect(Collectors.toSet());
Key brckey = buildKey(VplsIntentUtility.PREFIX_BROADCAST, point.connectPoint(), name, MacAddress.BROADCAST);
intents.add(buildBrcIntent(brckey, point, otherPoints, encap));
});
return intents;
}
use of org.onosproject.net.intent.Key in project onos by opennetworkinglab.
the class PacketLinkRealizedByOpticalTest method testCreate.
/**
* Checks the construction of PacketLinkRealizedByOptical object with all parameters specified.
*/
@Test
public void testCreate() {
ConnectPoint cp1 = new ConnectPoint(DeviceId.deviceId("of:0000000000000001"), PortNumber.portNumber(1L));
ConnectPoint cp2 = new ConnectPoint(DeviceId.deviceId("of:0000000000000002"), PortNumber.portNumber(2L));
Key key = Key.of(10L, appId);
Bandwidth bandwidth = Bandwidth.bps(100L);
PacketLinkRealizedByOptical plink = new PacketLinkRealizedByOptical(cp1, cp2, key, bandwidth);
assertNotNull(plink);
assertEquals(plink.src(), cp1);
assertEquals(plink.dst(), cp2);
assertEquals((long) plink.bandwidth().bps(), 100L);
}
use of org.onosproject.net.intent.Key in project onos by opennetworkinglab.
the class ServiceApplicationComponent method processTapiEvent.
/**
* Process TAPI Event from NBI.
*
* @param config TAPI Connectivity config for the event
*/
public void processTapiEvent(TapiConnectivityConfig config) {
checkNotNull(config, "Config can't be null");
Key key = Key.of(config.uuid(), appId);
// Setup the Intent
if (config.isSetup()) {
log.debug("TAPI config: {} to setup intent", config);
Intent intent = createOpticalIntent(config.leftCp(), config.rightCp(), key, appId);
intentService.submit(intent);
} else {
// Release the intent
Intent intent = intentService.getIntent(key);
if (intent == null) {
log.error("Intent for uuid {} does not exist", config.uuid());
return;
}
log.debug("TAPI config: {} to purge intent {}", config, intent);
CountDownLatch latch = new CountDownLatch(1);
IntentListener listener = new DeleteListener(key, latch);
intentService.addListener(listener);
try {
/*
* RCAS: Note, withdraw is asynchronous. We cannot call purge
* directly, because at this point it remains in the "INSTALLED"
* state.
*/
intentService.withdraw(intent);
/*
* org.onosproject.onos-core-net - 2.1.0.SNAPSHOT |
* Purge for intent 0x0 is rejected because intent state is INSTALLED
* intentService.purge(intent);
*/
try {
latch.await(WITHDRAW_EVENT_TIMEOUT_SECONDS, TimeUnit.SECONDS);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
// double check the state
IntentState state = intentService.getIntentState(key);
if (state == WITHDRAWN || state == FAILED) {
intentService.purge(intent);
}
} finally {
intentService.removeListener(listener);
}
}
}
Aggregations