use of org.onosproject.upgrade.Upgrade in project onos by opennetworkinglab.
the class UpgradeManager method handleClusterEvent.
/**
* Handles a cluster event.
*
* @param event the cluster event
*/
protected void handleClusterEvent(ClusterEvent event) {
checkPermission(CLUSTER_EVENT);
// If an instance was deactivated, check whether we need to roll back the upgrade.
if (event.type() == ClusterEvent.Type.INSTANCE_DEACTIVATED) {
Upgrade upgrade = getState();
if (upgrade.status().upgraded()) {
// Get the upgraded subset of the cluster and check whether the down node is a member
// of the upgraded subset. If so, roll back the upgrade to tolerate the failure.
Set<NodeId> upgradedNodes = clusterService.getNodes().stream().map(ControllerNode::id).filter(id -> clusterService.getVersion(id).equals(upgrade.target())).collect(Collectors.toSet());
if (upgradedNodes.contains(event.subject().id())) {
log.warn("Upgrade failure detected: rolling back upgrade");
rollback();
}
}
}
}
use of org.onosproject.upgrade.Upgrade in project onos by opennetworkinglab.
the class UpgradeManager method upgrade.
@Override
public void upgrade() {
Upgrade initialized = getState();
// If the current upgrade status is not INITIALIZED, throw an exception.
if (initialized.status() != Upgrade.Status.INITIALIZED) {
throw new IllegalStateException("Upgrade not initialized");
}
// Set the upgrade status to UPGRADING.
Upgrade upgrading = new Upgrade(initialized.source(), initialized.target(), Upgrade.Status.UPGRADING);
changeState(initialized, upgrading);
// Set the upgrade status to UPGRADED.
Upgrade upgraded = new Upgrade(upgrading.source(), upgrading.target(), Upgrade.Status.UPGRADED);
changeState(upgrading, upgraded);
}
use of org.onosproject.upgrade.Upgrade in project onos by opennetworkinglab.
the class UpgradeManagerTest method testFailedCommit.
@Test
public void testFailedCommit() throws Exception {
UpgradeManager upgradeManager = createUpgradeManager(Version.version("1.0.0"), new Upgrade(Version.version("1.0.0"), Version.version("1.0.0"), Upgrade.Status.INACTIVE), Arrays.asList(Version.version("1.0.0"), Version.version("1.0.0"), Version.version("1.0.1")));
assertEquals(Upgrade.Status.INACTIVE, upgradeManager.getState().status());
assertTrue(upgradeManager.isLocalActive());
assertFalse(upgradeManager.isLocalUpgraded());
upgradeManager.initialize();
assertEquals(Upgrade.Status.INITIALIZED, upgradeManager.getState().status());
assertEquals(Version.version("1.0.0"), upgradeManager.getState().source());
assertEquals(Version.version("1.0.0"), upgradeManager.getState().target());
assertEquals(Version.version("1.0.0"), upgradeManager.getVersion());
assertTrue(upgradeManager.isLocalActive());
assertFalse(upgradeManager.isLocalUpgraded());
upgradeManager.upgrade();
assertEquals(Upgrade.Status.UPGRADED, upgradeManager.getState().status());
try {
upgradeManager.commit();
fail();
} catch (IllegalStateException e) {
}
}
use of org.onosproject.upgrade.Upgrade in project onos by opennetworkinglab.
the class UpgradeManagerTest method testCrashRollback.
@Test
public void testCrashRollback() throws Exception {
UpgradeManager upgradeManager = createUpgradeManager(Version.version("1.0.0"), new Upgrade(Version.version("1.0.0"), Version.version("1.0.1"), Upgrade.Status.UPGRADED), Arrays.asList(Version.version("1.0.0"), Version.version("1.0.0"), Version.version("1.0.1")));
assertFalse(upgradeManager.isLocalActive());
upgradeManager.handleClusterEvent(new ClusterEvent(ClusterEvent.Type.INSTANCE_DEACTIVATED, upgradeManager.clusterService.getNode(NodeId.nodeId("2"))));
assertEquals(Upgrade.Status.ROLLED_BACK, upgradeManager.getState().status());
assertTrue(upgradeManager.isLocalActive());
assertFalse(upgradeManager.isLocalUpgraded());
}
Aggregations