use of org.onosproject.net.intent.IntentData in project onos by opennetworkinglab.
the class GossipIntentStoreTest method testAddAndWithdrawIntent.
/**
* Tests adding and withdrawing an Intent.
*/
@Test
public void testAddAndWithdrawIntent() {
// build and install one intent
Intent intent = builder1.build();
IntentData installed = new IntentData(intent, IntentState.INSTALLED, new IntentTestsMocks.MockTimestamp(12));
intentStore.write(installed);
// check that the intent count includes the new one
assertThat(intentStore.getIntentCount(), is(1L));
// check that the getIntents() API returns the new intent
intentStore.getIntents().forEach(item -> assertThat(item, is(intent)));
// check that the getInstallableIntents() API returns the new intent
intentStore.getInstallableIntents(intent.key()).forEach(item -> assertThat(item, is(intent)));
// check that the getIntent() API can find the new intent
Intent queried = intentStore.getIntent(intent.key());
assertThat(queried, is(intent));
// check that the state of the new intent is correct
IntentState state = intentStore.getIntentState(intent.key());
assertThat(state, is(IntentState.INSTALLED));
// check that the getIntentData() API returns the proper value for the
// new intent
IntentData dataByQuery = intentStore.getIntentData(intent.key());
assertThat(dataByQuery, is(installed));
// check that the getIntentData() API returns the new intent when given
// a time stamp to look for
Iterable<IntentData> dataIteratorByTime = intentStore.getIntentData(true, 10L);
assertThat(dataIteratorByTime.iterator().hasNext(), is(true));
dataIteratorByTime.forEach(data -> assertThat(data, is(installed)));
// check that the getIntentData() API returns the new intent when asked to
// find all intents
Iterable<IntentData> dataIteratorAll = intentStore.getIntentData(false, 0L);
assertThat(dataIteratorAll.iterator().hasNext(), is(true));
dataIteratorAll.forEach(data -> assertThat(data, is(installed)));
// now purge the intent that was created
IntentData purgeAssigned = IntentData.assign(IntentData.purge(intent), new IntentTestsMocks.MockTimestamp(12), new NodeId("node-id"));
intentStore.write(purgeAssigned);
// check that no intents are left
assertThat(intentStore.getIntentCount(), is(0L));
// check that a getIntent() operation on the key of the purged intent
// returns null
Intent queriedAfterWithdrawal = intentStore.getIntent(intent.key());
assertThat(queriedAfterWithdrawal, nullValue());
}
use of org.onosproject.net.intent.IntentData in project onos by opennetworkinglab.
the class ObjectiveTracker method trackIntent.
@Override
public void trackIntent(IntentData intentData) {
// NOTE: This will be called for intents that are being added to the store
// locally (i.e. every intent update)
Key key = intentData.key();
Intent intent = intentData.intent();
boolean isLocal = intentService.isLocal(key);
boolean isInstalled = intentData.state() == INSTALLING || intentData.state() == INSTALLED;
List<Intent> installables = intentData.installables();
if (log.isTraceEnabled()) {
log.trace("intent {}, old: {}, new: {}, installableCount: {}, resourceCount: {}", key, intentsByDevice.values().contains(key), isLocal && isInstalled, installables.size(), intent.resources().size() + installables.stream().mapToLong(i -> i.resources().size()).sum());
}
if (isNullOrEmpty(installables) && intentData.state() == INSTALLED) {
log.warn("Intent {} is INSTALLED with no installables", key);
}
// then when installing and when installed)
if (isLocal && isInstalled) {
addTrackedResources(key, intent.resources());
for (Intent installable : installables) {
addTrackedResources(key, installable.resources());
}
// FIXME check all resources against current topo service(s); recompile if necessary
} else {
removeTrackedResources(key, intent.resources());
for (Intent installable : installables) {
removeTrackedResources(key, installable.resources());
}
}
}
use of org.onosproject.net.intent.IntentData in project onos by opennetworkinglab.
the class FlowObjectiveIntentInstaller method apply.
@Override
public void apply(IntentOperationContext<FlowObjectiveIntent> intentOperationContext) {
Objects.requireNonNull(intentOperationContext);
Optional<IntentData> toUninstall = intentOperationContext.toUninstall();
Optional<IntentData> toInstall = intentOperationContext.toInstall();
List<FlowObjectiveIntent> uninstallIntents = intentOperationContext.intentsToUninstall();
List<FlowObjectiveIntent> installIntents = intentOperationContext.intentsToInstall();
if (!toInstall.isPresent() && !toUninstall.isPresent()) {
intentInstallCoordinator.intentInstallSuccess(intentOperationContext);
return;
}
if (toUninstall.isPresent()) {
IntentData intentData = toUninstall.get();
trackerService.removeTrackedResources(intentData.key(), intentData.intent().resources());
uninstallIntents.forEach(installable -> trackerService.removeTrackedResources(intentData.intent().key(), installable.resources()));
}
if (toInstall.isPresent()) {
IntentData intentData = toInstall.get();
trackerService.addTrackedResources(intentData.key(), intentData.intent().resources());
installIntents.forEach(installable -> trackerService.addTrackedResources(intentData.key(), installable.resources()));
}
FlowObjectiveIntentInstallationContext intentInstallationContext = new FlowObjectiveIntentInstallationContext(intentOperationContext);
uninstallIntents.stream().map(intent -> buildObjectiveContexts(intent, REMOVE)).flatMap(Collection::stream).forEach(context -> {
context.intentInstallationContext(intentInstallationContext);
intentInstallationContext.addContext(context);
intentInstallationContext.addPendingContext(context);
});
installIntents.stream().map(intent -> buildObjectiveContexts(intent, ADD)).flatMap(Collection::stream).forEach(context -> {
context.intentInstallationContext(intentInstallationContext);
intentInstallationContext.addContext(context);
intentInstallationContext.addNextPendingContext(context);
});
intentInstallationContext.apply();
}
use of org.onosproject.net.intent.IntentData in project onos by opennetworkinglab.
the class ProtectionEndpointIntentInstaller method apply.
@Override
public void apply(IntentOperationContext<ProtectionEndpointIntent> context) {
Optional<IntentData> toUninstall = context.toUninstall();
Optional<IntentData> toInstall = context.toInstall();
List<ProtectionEndpointIntent> uninstallIntents = context.intentsToUninstall();
List<ProtectionEndpointIntent> installIntents = context.intentsToInstall();
if (!toInstall.isPresent() && !toUninstall.isPresent()) {
intentInstallCoordinator.intentInstallSuccess(context);
return;
}
if (toUninstall.isPresent()) {
IntentData intentData = toUninstall.get();
trackerService.removeTrackedResources(intentData.key(), intentData.intent().resources());
uninstallIntents.forEach(installable -> trackerService.removeTrackedResources(intentData.intent().key(), installable.resources()));
}
if (toInstall.isPresent()) {
IntentData intentData = toInstall.get();
trackerService.addTrackedResources(intentData.key(), intentData.intent().resources());
installIntents.forEach(installable -> trackerService.addTrackedResources(intentData.key(), installable.resources()));
}
List<Stage> stages = new ArrayList<>();
stages.add(new Stage(uninstallIntents.stream().map(i -> Pair.of(i, REMOVE)).collect(Collectors.toList())));
stages.add(new Stage(installIntents.stream().map(i -> Pair.of(i, ADD)).collect(Collectors.toList())));
for (Stage stage : stages) {
log.debug("applying Stage {}", stage);
try {
// wait for stage completion
stage.apply();
stage.listeners().forEach(networkConfigService::removeListener);
} catch (IntentException e) {
log.error("Stage {} failed, reason: {}", stage, e.toString());
intentInstallCoordinator.intentInstallFailed(context);
return;
}
}
// All stage success
intentInstallCoordinator.intentInstallSuccess(context);
}
Aggregations