use of org.onosproject.net.intent.IntentOperationContext in project onos by opennetworkinglab.
the class VirtualIntentInstallCoordinator method finish.
/**
* Completed the installation context and update the Intent store.
*
* @param intentInstallationContext the installation context
*/
private void finish(IntentInstallationContext intentInstallationContext) {
Set<IntentOperationContext> errCtxs = intentInstallationContext.errorContexts();
Optional<IntentData> toUninstall = intentInstallationContext.toUninstall();
Optional<IntentData> toInstall = intentInstallationContext.toInstall();
// Intent install success
if (errCtxs == null || errCtxs.isEmpty()) {
if (toInstall.isPresent()) {
IntentData installData = toInstall.get();
log.debug("Completed installing: {}", installData.key());
installData = IntentData.compiled(installData, installData.installables());
installData.setState(INSTALLED);
intentStore.write(networkId, installData);
} else if (toUninstall.isPresent()) {
IntentData uninstallData = toUninstall.get();
uninstallData = IntentData.compiled(uninstallData, Collections.emptyList());
log.debug("Completed withdrawing: {}", uninstallData.key());
switch(uninstallData.request()) {
case INSTALL_REQ:
log.warn("{} was requested to withdraw during installation?", uninstallData.intent());
uninstallData.setState(FAILED);
break;
case WITHDRAW_REQ:
default:
// TODO "default" case should not happen
uninstallData.setState(WITHDRAWN);
break;
}
// Intent has been withdrawn; we can clear the installables
intentStore.write(networkId, uninstallData);
}
} else {
// if toInstall was cause of error, then recompile (manage/increment counter, when exceeded -> CORRUPT)
if (toInstall.isPresent()) {
IntentData installData = toInstall.get();
installData.setState(CORRUPT);
installData.incrementErrorCount();
intentStore.write(networkId, installData);
}
// if toUninstall was cause of error, then CORRUPT (another job will clean this up)
if (toUninstall.isPresent()) {
IntentData uninstallData = toUninstall.get();
uninstallData.setState(CORRUPT);
uninstallData.incrementErrorCount();
intentStore.write(networkId, uninstallData);
}
}
}
use of org.onosproject.net.intent.IntentOperationContext in project onos by opennetworkinglab.
the class VirtualIntentInstallCoordinator method installIntents.
/**
* Applies Intent data to be uninstalled and to be installed.
*
* @param toUninstall Intent data to be uninstalled
* @param toInstall Intent data to be installed
*/
public void installIntents(Optional<IntentData> toUninstall, Optional<IntentData> toInstall) {
// If no any Intents to be uninstalled or installed, ignore it.
if (!toUninstall.isPresent() && !toInstall.isPresent()) {
return;
}
// Classify installable Intents to different installers.
ArrayListMultimap<IntentInstaller, Intent> uninstallInstallers;
ArrayListMultimap<IntentInstaller, Intent> installInstallers;
Set<IntentInstaller> allInstallers = Sets.newHashSet();
if (toUninstall.isPresent()) {
uninstallInstallers = getInstallers(toUninstall.get());
allInstallers.addAll(uninstallInstallers.keySet());
} else {
uninstallInstallers = ArrayListMultimap.create();
}
if (toInstall.isPresent()) {
installInstallers = getInstallers(toInstall.get());
allInstallers.addAll(installInstallers.keySet());
} else {
installInstallers = ArrayListMultimap.create();
}
// Generates an installation context for the high level Intent.
IntentInstallationContext installationContext = new IntentInstallationContext(toUninstall.orElse(null), toInstall.orElse(null));
// Generates different operation context for different installable Intents.
Map<IntentInstaller, IntentOperationContext> contexts = Maps.newHashMap();
allInstallers.forEach(installer -> {
List<Intent> intentsToUninstall = uninstallInstallers.get(installer);
List<Intent> intentsToInstall = installInstallers.get(installer);
// Connect context to high level installation context
IntentOperationContext context = new IntentOperationContext(intentsToUninstall, intentsToInstall, installationContext);
installationContext.addPendingContext(context);
contexts.put(installer, context);
});
// Apply contexts to installers
contexts.forEach((installer, context) -> {
installer.apply(context);
});
}
use of org.onosproject.net.intent.IntentOperationContext in project onos by opennetworkinglab.
the class InstallCoordinator method finish.
/**
* Completed the installation context and update the Intent store.
*
* @param intentInstallationContext the installation context
*/
private void finish(IntentInstallationContext intentInstallationContext) {
Set<IntentOperationContext> errCtxs = intentInstallationContext.errorContexts();
Optional<IntentData> toUninstall = intentInstallationContext.toUninstall();
Optional<IntentData> toInstall = intentInstallationContext.toInstall();
// Intent install success
if (errCtxs == null || errCtxs.isEmpty()) {
if (toInstall.isPresent()) {
IntentData installData = toInstall.get();
log.debug("Completed installing: {}:{}", installData.key(), installData.intent().id());
installData = IntentData.compiled(installData, installData.installables());
installData.setState(INSTALLED);
intentStore.write(installData);
} else if (toUninstall.isPresent()) {
IntentData uninstallData = toUninstall.get();
uninstallData = IntentData.compiled(uninstallData, Collections.emptyList());
log.debug("Completed withdrawing: {}:{}", uninstallData.key(), uninstallData.intent().id());
switch(uninstallData.request()) {
case INSTALL_REQ:
// INSTALLED intent was damaged & clean up is now complete
uninstallData.setState(FAILED);
break;
case WITHDRAW_REQ:
default:
// TODO "default" case should not happen
uninstallData.setState(WITHDRAWN);
break;
}
// Intent has been withdrawn; we can clear the installables
intentStore.write(uninstallData);
}
} else {
// if toInstall was cause of error, then recompile (manage/increment counter, when exceeded -> CORRUPT)
if (toInstall.isPresent()) {
IntentData installData = toInstall.get();
intentStore.write(IntentData.corrupt(installData));
}
// if toUninstall was cause of error, then CORRUPT (another job will clean this up)
if (toUninstall.isPresent()) {
IntentData uninstallData = toUninstall.get();
intentStore.write(IntentData.corrupt(uninstallData));
}
}
}
use of org.onosproject.net.intent.IntentOperationContext in project onos by opennetworkinglab.
the class FlowObjectiveIntentInstallerTest method testUninstallAndInstallIntent.
/**
* Do both uninstall and install flow objective Intents.
*/
@Test
public void testUninstallAndInstallIntent() {
List<Intent> intentsToUninstall = createFlowObjectiveIntents();
List<Intent> intentsToInstall = createAnotherFlowObjectiveIntents();
IntentData toInstall = new IntentData(createP2PIntent(), IntentState.INSTALLING, new WallClockTimestamp());
toInstall = IntentData.compiled(toInstall, intentsToInstall);
IntentData toUninstall = new IntentData(createP2PIntent(), IntentState.INSTALLED, new WallClockTimestamp());
toUninstall = IntentData.compiled(toUninstall, intentsToUninstall);
IntentOperationContext<FlowObjectiveIntent> operationContext;
IntentInstallationContext context = new IntentInstallationContext(toUninstall, toInstall);
operationContext = new IntentOperationContext(intentsToUninstall, intentsToInstall, context);
installer.apply(operationContext);
IntentOperationContext successContext = intentInstallCoordinator.successContext;
assertEquals(successContext, operationContext);
}
use of org.onosproject.net.intent.IntentOperationContext in project onos by opennetworkinglab.
the class FlowObjectiveIntentInstallerTest method testNoAnyIntentToApply.
/**
* Nothing to uninstall or install.
*/
@Test
public void testNoAnyIntentToApply() {
IntentData toInstall = null;
IntentData toUninstall = null;
IntentOperationContext<FlowObjectiveIntent> operationContext;
IntentInstallationContext context = new IntentInstallationContext(toUninstall, toInstall);
operationContext = new IntentOperationContext<>(ImmutableList.of(), ImmutableList.of(), context);
installer.apply(operationContext);
IntentOperationContext successContext = intentInstallCoordinator.successContext;
assertEquals(successContext, operationContext);
}
Aggregations