Search in sources :

Example 1 with IntentOperationContext

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);
        }
    }
}
Also used : IntentData(org.onosproject.net.intent.IntentData) IntentOperationContext(org.onosproject.net.intent.IntentOperationContext)

Example 2 with IntentOperationContext

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);
    });
}
Also used : IntentInstaller(org.onosproject.net.intent.IntentInstaller) IntentInstallationContext(org.onosproject.net.intent.IntentInstallationContext) Intent(org.onosproject.net.intent.Intent) IntentOperationContext(org.onosproject.net.intent.IntentOperationContext)

Example 3 with IntentOperationContext

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));
        }
    }
}
Also used : IntentData(org.onosproject.net.intent.IntentData) IntentOperationContext(org.onosproject.net.intent.IntentOperationContext)

Example 4 with IntentOperationContext

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);
}
Also used : WallClockTimestamp(org.onosproject.store.service.WallClockTimestamp) IntentData(org.onosproject.net.intent.IntentData) IntentInstallationContext(org.onosproject.net.intent.IntentInstallationContext) FlowObjectiveIntent(org.onosproject.net.intent.FlowObjectiveIntent) Intent(org.onosproject.net.intent.Intent) FlowObjectiveIntent(org.onosproject.net.intent.FlowObjectiveIntent) IntentOperationContext(org.onosproject.net.intent.IntentOperationContext) Test(org.junit.Test)

Example 5 with IntentOperationContext

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);
}
Also used : IntentData(org.onosproject.net.intent.IntentData) IntentInstallationContext(org.onosproject.net.intent.IntentInstallationContext) FlowObjectiveIntent(org.onosproject.net.intent.FlowObjectiveIntent) IntentOperationContext(org.onosproject.net.intent.IntentOperationContext) Test(org.junit.Test)

Aggregations

IntentOperationContext (org.onosproject.net.intent.IntentOperationContext)35 IntentData (org.onosproject.net.intent.IntentData)33 IntentInstallationContext (org.onosproject.net.intent.IntentInstallationContext)32 Test (org.junit.Test)28 Intent (org.onosproject.net.intent.Intent)28 WallClockTimestamp (org.onosproject.store.service.WallClockTimestamp)26 FlowRuleIntent (org.onosproject.net.intent.FlowRuleIntent)14 PathIntent (org.onosproject.net.intent.PathIntent)13 ProtectionEndpointIntent (org.onosproject.net.intent.ProtectionEndpointIntent)6 Collection (java.util.Collection)5 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)5 FlowRule (org.onosproject.net.flow.FlowRule)5 Sets (com.google.common.collect.Sets)4 List (java.util.List)4 Set (java.util.Set)4 Collectors (java.util.stream.Collectors)4 DeviceId (org.onosproject.net.DeviceId)4 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)4 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)4 TrafficSelector (org.onosproject.net.flow.TrafficSelector)4