Search in sources :

Example 11 with Upgrade

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();
            }
        }
    }
}
Also used : AtomicValueEvent(org.onosproject.store.service.AtomicValueEvent) AppGuard.checkPermission(org.onosproject.security.AppGuard.checkPermission) CLUSTER_EVENT(org.onosproject.security.AppPermission.Type.CLUSTER_EVENT) CoordinationService(org.onosproject.store.service.CoordinationService) AtomicReference(java.util.concurrent.atomic.AtomicReference) ControllerNode(org.onosproject.cluster.ControllerNode) AtomicValue(org.onosproject.store.service.AtomicValue) Component(org.osgi.service.component.annotations.Component) Upgrade(org.onosproject.upgrade.Upgrade) VersionService(org.onosproject.core.VersionService) Version(org.onosproject.core.Version) Activate(org.osgi.service.component.annotations.Activate) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) NodeId(org.onosproject.cluster.NodeId) UpgradeEventListener(org.onosproject.upgrade.UpgradeEventListener) Serializer(org.onosproject.store.service.Serializer) ClusterEventListener(org.onosproject.cluster.ClusterEventListener) UpgradeService(org.onosproject.upgrade.UpgradeService) Logger(org.slf4j.Logger) UPGRADE_EVENT(org.onosproject.security.AppPermission.Type.UPGRADE_EVENT) UPGRADE_READ(org.onosproject.security.AppPermission.Type.UPGRADE_READ) ClusterEvent(org.onosproject.cluster.ClusterEvent) AbstractListenerManager(org.onosproject.event.AbstractListenerManager) Deactivate(org.osgi.service.component.annotations.Deactivate) Set(java.util.Set) Collectors(java.util.stream.Collectors) AtomicValueEventListener(org.onosproject.store.service.AtomicValueEventListener) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) Objects(java.util.Objects) UpgradeEvent(org.onosproject.upgrade.UpgradeEvent) UpgradeAdminService(org.onosproject.upgrade.UpgradeAdminService) MembershipService(org.onosproject.cluster.MembershipService) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) ClusterService(org.onosproject.cluster.ClusterService) UPGRADE_WRITE(org.onosproject.security.AppPermission.Type.UPGRADE_WRITE) Reference(org.osgi.service.component.annotations.Reference) NodeId(org.onosproject.cluster.NodeId) ControllerNode(org.onosproject.cluster.ControllerNode) Upgrade(org.onosproject.upgrade.Upgrade)

Example 12 with Upgrade

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);
}
Also used : Upgrade(org.onosproject.upgrade.Upgrade)

Example 13 with Upgrade

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) {
    }
}
Also used : Upgrade(org.onosproject.upgrade.Upgrade) Test(org.junit.Test)

Example 14 with Upgrade

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());
}
Also used : ClusterEvent(org.onosproject.cluster.ClusterEvent) Upgrade(org.onosproject.upgrade.Upgrade) Test(org.junit.Test)

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