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);
}
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");
}
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);
}
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);
}
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);
}
Aggregations