|
@@ -131,7 +131,7 @@ public class ComponentInstance implements EventHandler<ComponentInstanceEvent>,
|
|
|
.addTransition(STARTED, INIT, STOP,
|
|
|
new ContainerStoppedTransition())
|
|
|
.addTransition(STARTED, READY, BECOME_READY,
|
|
|
- new ContainerBecomeReadyTransition())
|
|
|
+ new ContainerBecomeReadyTransition(false))
|
|
|
|
|
|
// FROM READY
|
|
|
.addTransition(READY, STARTED, BECOME_NOT_READY,
|
|
@@ -144,16 +144,20 @@ public class ComponentInstance implements EventHandler<ComponentInstanceEvent>,
|
|
|
// FROM UPGRADING
|
|
|
.addTransition(UPGRADING, EnumSet.of(READY, CANCEL_UPGRADING),
|
|
|
CANCEL_UPGRADE, new CancelUpgradeTransition())
|
|
|
- .addTransition(UPGRADING, EnumSet.of(READY), BECOME_READY,
|
|
|
- new ReadyAfterUpgradeTransition())
|
|
|
+ .addTransition(UPGRADING, EnumSet.of(REINITIALIZED), START,
|
|
|
+ new StartedAfterUpgradeTransition())
|
|
|
.addTransition(UPGRADING, UPGRADING, STOP,
|
|
|
new StoppedAfterUpgradeTransition())
|
|
|
|
|
|
// FROM CANCEL_UPGRADING
|
|
|
- .addTransition(CANCEL_UPGRADING, EnumSet.of(CANCEL_UPGRADING, READY),
|
|
|
- BECOME_READY, new ReadyAfterUpgradeTransition())
|
|
|
+ .addTransition(CANCEL_UPGRADING, EnumSet.of(CANCEL_UPGRADING,
|
|
|
+ REINITIALIZED), START, new StartedAfterUpgradeTransition())
|
|
|
.addTransition(CANCEL_UPGRADING, EnumSet.of(CANCEL_UPGRADING, INIT),
|
|
|
STOP, new StoppedAfterCancelUpgradeTransition())
|
|
|
+ .addTransition(REINITIALIZED, CANCEL_UPGRADING, CANCEL_UPGRADE,
|
|
|
+ new CancelledAfterReinitTransition())
|
|
|
+ .addTransition(REINITIALIZED, READY, BECOME_READY,
|
|
|
+ new ContainerBecomeReadyTransition(true))
|
|
|
.installTopology();
|
|
|
|
|
|
public ComponentInstance(Component component,
|
|
@@ -229,16 +233,30 @@ public class ComponentInstance implements EventHandler<ComponentInstanceEvent>,
|
|
|
}
|
|
|
|
|
|
private static class ContainerBecomeReadyTransition extends BaseTransition {
|
|
|
+ private final boolean isReinitialized;
|
|
|
+
|
|
|
+ ContainerBecomeReadyTransition(boolean isReinitialized) {
|
|
|
+ this.isReinitialized = isReinitialized;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public void transition(ComponentInstance compInstance,
|
|
|
ComponentInstanceEvent event) {
|
|
|
compInstance.setContainerState(ContainerState.READY);
|
|
|
- compInstance.component.incContainersReady(true);
|
|
|
+ if (!isReinitialized) {
|
|
|
+ compInstance.component.incContainersReady(true);
|
|
|
+ } else {
|
|
|
+ compInstance.component.incContainersReady(false);
|
|
|
+ ComponentEvent checkState = new ComponentEvent(
|
|
|
+ compInstance.component.getName(), ComponentEventType.CHECK_STABLE);
|
|
|
+ compInstance.scheduler.getDispatcher().getEventHandler().handle(
|
|
|
+ checkState);
|
|
|
+ }
|
|
|
compInstance.postContainerReady();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private static class ReadyAfterUpgradeTransition implements
|
|
|
+ private static class StartedAfterUpgradeTransition implements
|
|
|
MultipleArcTransition<ComponentInstance, ComponentInstanceEvent,
|
|
|
ComponentInstanceState> {
|
|
|
|
|
@@ -249,7 +267,7 @@ public class ComponentInstance implements EventHandler<ComponentInstanceEvent>,
|
|
|
if (instance.pendingCancelUpgrade) {
|
|
|
// cancellation of upgrade was triggered before the upgrade was
|
|
|
// finished.
|
|
|
- LOG.info("{} received ready but cancellation pending",
|
|
|
+ LOG.info("{} received started but cancellation pending",
|
|
|
event.getContainerId());
|
|
|
instance.upgradeInProgress.set(true);
|
|
|
instance.cancelUpgrade();
|
|
@@ -258,8 +276,7 @@ public class ComponentInstance implements EventHandler<ComponentInstanceEvent>,
|
|
|
}
|
|
|
|
|
|
instance.upgradeInProgress.set(false);
|
|
|
- instance.setContainerState(ContainerState.READY);
|
|
|
- instance.component.incContainersReady(false);
|
|
|
+ instance.setContainerState(ContainerState.RUNNING_BUT_UNREADY);
|
|
|
|
|
|
Component.UpgradeStatus status = instance.getState().equals(UPGRADING) ?
|
|
|
instance.component.getUpgradeStatus() :
|
|
@@ -267,12 +284,7 @@ public class ComponentInstance implements EventHandler<ComponentInstanceEvent>,
|
|
|
status.decContainersThatNeedUpgrade();
|
|
|
|
|
|
instance.serviceVersion = status.getTargetVersion();
|
|
|
- ComponentEvent checkState = new ComponentEvent(
|
|
|
- instance.component.getName(),
|
|
|
- ComponentEventType.CHECK_STABLE);
|
|
|
- instance.scheduler.getDispatcher().getEventHandler().handle(checkState);
|
|
|
- instance.postContainerReady();
|
|
|
- return ComponentInstanceState.READY;
|
|
|
+ return ComponentInstanceState.REINITIALIZED;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -570,6 +582,19 @@ public class ComponentInstance implements EventHandler<ComponentInstanceEvent>,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private static class CancelledAfterReinitTransition extends BaseTransition {
|
|
|
+ @Override
|
|
|
+ public void transition(ComponentInstance instance,
|
|
|
+ ComponentInstanceEvent event) {
|
|
|
+ if (instance.upgradeInProgress.compareAndSet(false, true)) {
|
|
|
+ instance.cancelUpgrade();
|
|
|
+ } else {
|
|
|
+ LOG.info("{} pending cancellation", event.getContainerId());
|
|
|
+ instance.pendingCancelUpgrade = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private static class CancelUpgradeTransition implements
|
|
|
MultipleArcTransition<ComponentInstance, ComponentInstanceEvent,
|
|
|
ComponentInstanceState> {
|