Search in sources :

Example 6 with Upgrade

use of org.onosproject.upgrade.Upgrade in project onos by opennetworkinglab.

the class UpgradeManager method reset.

@Override
public void reset() {
    Upgrade upgraded = getState();
    // If the current upgrade status is not INITIALIZED or ROLLED_BACK, throw an exception.
    if (upgraded.status() != Upgrade.Status.INITIALIZED && upgraded.status() != Upgrade.Status.ROLLED_BACK) {
        throw new IllegalStateException("Upgrade not rolled back");
    }
    // Determine whether any nodes are still running the target version.
    boolean rollbackComplete = membershipService.getGroups().size() == 1 && membershipService.getLocalGroup().version().equals(upgraded.source());
    // If some nodes have not yet been downgraded, throw an exception.
    if (!rollbackComplete) {
        throw new IllegalStateException("Some nodes have not yet been downgraded to version " + upgraded.source());
    }
    // Set the upgrade status to RESETTING.
    Upgrade resetting = new Upgrade(upgraded.source(), upgraded.target(), Upgrade.Status.RESETTING);
    changeState(upgraded, resetting);
    // Set the upgrade status to RESET.
    Upgrade reset = new Upgrade(resetting.source(), resetting.target(), Upgrade.Status.RESET);
    changeState(resetting, reset);
    // Set the upgrade status to INACTIVE.
    Upgrade inactive = new Upgrade(localVersion, localVersion, Upgrade.Status.INACTIVE);
    changeState(reset, inactive);
}
Also used : Upgrade(org.onosproject.upgrade.Upgrade)

Example 7 with Upgrade

use of org.onosproject.upgrade.Upgrade in project onos by opennetworkinglab.

the class UpgradeManager method activate.

@Activate
public void activate() {
    eventDispatcher.addSink(UpgradeEvent.class, listenerRegistry);
    state = coordinationService.<Upgrade>atomicValueBuilder().withName("onos-upgrade-state").withSerializer(Serializer.using(KryoNamespaces.API)).build().asAtomicValue();
    localVersion = versionService.version();
    currentState.set(state.get());
    if (getState() == null) {
        initializeState(new Upgrade(localVersion, localVersion, Upgrade.Status.INACTIVE));
    }
    Upgrade upgrade = getState();
    // If the upgrade state is initialized then check the node version.
    if (upgrade.status() == Upgrade.Status.INITIALIZED) {
        // If the source version equals the target version, attempt to update the target version.
        if (Objects.equals(upgrade.source(), upgrade.target()) && !Objects.equals(upgrade.target(), localVersion)) {
            checkPermission(UPGRADE_WRITE);
            upgrade = new Upgrade(upgrade.source(), localVersion, upgrade.status());
            initializeState(upgrade);
        }
    }
    // If the upgrade status is active, verify that the local version matches the upgrade version.
    if (upgrade.status().active() && !Objects.equals(upgrade.source(), upgrade.target())) {
        // the source or target version.
        if (!Objects.equals(localVersion, upgrade.source()) && !Objects.equals(localVersion, upgrade.target())) {
            log.error("Cannot upgrade node to version {}; Upgrade to {} already in progress", localVersion, upgrade.target());
            throw new IllegalStateException("Cannot upgrade node to version " + localVersion + "; Upgrade to " + upgrade.target() + " already in progress");
        }
    }
    state.addListener(stateListener);
    clusterService.addListener(clusterListener);
    log.info("Started");
}
Also used : Upgrade(org.onosproject.upgrade.Upgrade) Activate(org.osgi.service.component.annotations.Activate)

Example 8 with Upgrade

use of org.onosproject.upgrade.Upgrade in project onos by opennetworkinglab.

the class UpgradeManager method rollback.

@Override
public void rollback() {
    Upgrade upgraded = getState();
    // If the current upgrade status is not UPGRADED, throw an exception.
    if (upgraded.status() != Upgrade.Status.UPGRADED) {
        throw new IllegalStateException("Upgrade not performed");
    }
    // Set the upgrade status to ROLLING_BACK.
    Upgrade rollingBack = new Upgrade(upgraded.source(), upgraded.target(), Upgrade.Status.ROLLING_BACK);
    changeState(upgraded, rollingBack);
    // Set the upgrade status to ROLLED_BACK.
    Upgrade rolledBack = new Upgrade(rollingBack.source(), rollingBack.target(), Upgrade.Status.ROLLED_BACK);
    changeState(rollingBack, rolledBack);
}
Also used : Upgrade(org.onosproject.upgrade.Upgrade)

Example 9 with Upgrade

use of org.onosproject.upgrade.Upgrade in project onos by opennetworkinglab.

the class UpgradeManager method initialize.

@Override
public void initialize() {
    Upgrade inactive = getState();
    // If the current upgrade status is active, fail initialization.
    if (inactive.status().active()) {
        throw new IllegalStateException("Upgrade already active");
    }
    // Set the upgrade status to INITIALIZING.
    Upgrade initializing = new Upgrade(localVersion, localVersion, Upgrade.Status.INITIALIZING);
    changeState(inactive, initializing);
    // Set the upgrade status to INITIALIZED.
    Upgrade initialized = new Upgrade(initializing.source(), initializing.target(), Upgrade.Status.INITIALIZED);
    changeState(initializing, initialized);
}
Also used : Upgrade(org.onosproject.upgrade.Upgrade)

Example 10 with Upgrade

use of org.onosproject.upgrade.Upgrade in project onos by opennetworkinglab.

the class UpgradeManager method commit.

@Override
public void commit() {
    Upgrade upgraded = getState();
    // If the current upgrade status is not UPGRADED, throw an exception.
    if (upgraded.status() != Upgrade.Status.UPGRADED) {
        throw new IllegalStateException("Upgrade not performed");
    }
    // Determine whether any nodes have not been upgraded to the target version.
    boolean upgradeComplete = membershipService.getGroups().size() == 1 && membershipService.getLocalGroup().version().equals(upgraded.target());
    // If some nodes have not yet been upgraded, throw an exception.
    if (!upgradeComplete) {
        throw new IllegalStateException("Some nodes have not yet been upgraded to version " + upgraded.target());
    }
    // Set the upgrade status to COMMITTING.
    Upgrade committing = new Upgrade(upgraded.source(), upgraded.target(), Upgrade.Status.COMMITTING);
    changeState(upgraded, committing);
    // Set the upgrade status to COMMITTED.
    Upgrade committed = new Upgrade(committing.source(), committing.target(), Upgrade.Status.COMMITTED);
    changeState(committing, committed);
    // Set the upgrade status to INACTIVE.
    Upgrade inactive = new Upgrade(localVersion, localVersion, Upgrade.Status.INACTIVE);
    changeState(committed, inactive);
}
Also used : Upgrade(org.onosproject.upgrade.Upgrade)

Aggregations

Upgrade (org.onosproject.upgrade.Upgrade)14 Test (org.junit.Test)7 ClusterEvent (org.onosproject.cluster.ClusterEvent)3 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 ControllerNode (org.onosproject.cluster.ControllerNode)2 NodeId (org.onosproject.cluster.NodeId)2 Version (org.onosproject.core.Version)2 AtomicValue (org.onosproject.store.service.AtomicValue)2 Activate (org.osgi.service.component.annotations.Activate)2 Maps (com.google.common.collect.Maps)1 Sets (com.google.common.collect.Sets)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Assert.assertEquals (org.junit.Assert.assertEquals)1