use of com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.ClusterUpgradeContext in project cloudbreak by hortonworks.
the class ClusterUpgradeValidationActions method clusterUpgradeValidationFailed.
@Bean(name = "CLUSTER_UPGRADE_VALIDATION_FAILED_STATE")
public Action<?, ?> clusterUpgradeValidationFailed() {
return new AbstractAction<ClusterUpgradeValidationState, ClusterUpgradeValidationStateSelectors, ClusterUpgradeContext, ClusterUpgradeValidationFailureEvent>(ClusterUpgradeValidationFailureEvent.class) {
@Inject
private CloudbreakMessagesService messagesService;
@Inject
private StackUpdater stackUpdater;
@Override
protected ClusterUpgradeContext createFlowContext(FlowParameters flowParameters, StateContext<ClusterUpgradeValidationState, ClusterUpgradeValidationStateSelectors> stateContext, ClusterUpgradeValidationFailureEvent payload) {
StackView stackView = stackService.getViewByIdWithoutAuth(payload.getResourceId());
MDCBuilder.buildMdcContext(stackView);
Flow flow = getFlow(flowParameters.getFlowId());
flow.setFlowFailed(payload.getException());
return ClusterUpgradeContext.from(flowParameters, payload);
}
@Override
protected void doExecute(ClusterUpgradeContext context, ClusterUpgradeValidationFailureEvent payload, Map<Object, Object> variables) {
String errorMessage = payload.getException().getMessage();
Long resourceId = payload.getResourceId();
LOGGER.debug("Cluster upgrade validation failed with validation error: {}", errorMessage);
ResourceEvent validationFailedResourceEvent = ResourceEvent.CLUSTER_UPGRADE_VALIDATION_FAILED;
cloudbreakEventService.fireCloudbreakEvent(resourceId, UPDATE_FAILED.name(), validationFailedResourceEvent, List.of(errorMessage));
String reason = messagesService.getMessage(validationFailedResourceEvent.getMessage(), List.of(errorMessage));
stackUpdater.updateStackStatus(resourceId, DetailedStackStatus.AVAILABLE, reason);
sendEvent(context, HANDLED_FAILED_CLUSTER_UPGRADE_VALIDATION_EVENT.event(), payload);
}
@Override
protected Object getFailurePayload(ClusterUpgradeValidationFailureEvent payload, Optional<ClusterUpgradeContext> flowContext, Exception ex) {
LOGGER.warn("No failure payload in case of CLUSTER_UPGRADE_VALIDATION_FAILED_STATE. This should not happen.", ex);
return null;
}
@Override
protected void initPayloadConverterMap(List<PayloadConverter<ClusterUpgradeValidationFailureEvent>> payloadConverters) {
payloadConverters.add(new ClusterUpgradeUpdateCheckFailedToClusterUpgradeValidationFailureEvent());
}
};
}
use of com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.ClusterUpgradeContext in project cloudbreak by hortonworks.
the class ClusterUpgradeActions method initClusterUpgrade.
@Bean(name = "CLUSTER_UPGRADE_INIT_STATE")
public Action<?, ?> initClusterUpgrade() {
return new AbstractClusterUpgradeAction<>(ClusterUpgradeTriggerEvent.class) {
@Inject
private ImageComponentUpdaterService imageComponentUpdaterService;
@Inject
private ClusterUpgradeTargetImageService clusterUpgradeTargetImageService;
@Override
protected void doExecute(ClusterUpgradeContext context, ClusterUpgradeTriggerEvent payload, Map<Object, Object> variables) {
try {
UpgradeImageInfo images = imageComponentUpdaterService.updateForUpgrade(payload.getImageId(), payload.getResourceId());
variables.put(CURRENT_IMAGE, images.getCurrentStatedImage());
variables.put(TARGET_IMAGE, images.getTargetStatedImage());
clusterUpgradeTargetImageService.saveImage(context.getStackId(), images.getTargetStatedImage());
clusterUpgradeService.initUpgradeCluster(context.getStackId(), getTargetImage(variables));
Selectable event = new ClusterUpgradeInitRequest(context.getStackId(), isPatchUpgrade(images.getCurrentStatedImage().getImage(), images.getTargetStatedImage().getImage()));
sendEvent(context, event.selector(), event);
} catch (Exception e) {
LOGGER.error("Error during updating cluster components with image id: [{}]", payload.getImageId(), e);
ClusterUpgradeFailedEvent upgradeFailedEvent = new ClusterUpgradeFailedEvent(payload.getResourceId(), e, DetailedStackStatus.CLUSTER_MANAGER_UPGRADE_FAILED);
sendEvent(context, upgradeFailedEvent);
}
}
@Override
protected Object getFailurePayload(ClusterUpgradeTriggerEvent payload, Optional<ClusterUpgradeContext> flowContext, Exception ex) {
return ClusterUpgradeFailedEvent.from(payload, ex, DetailedStackStatus.CLUSTER_MANAGER_UPGRADE_FAILED);
}
@Override
protected ClusterUpgradeContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, ClusterUpgradeTriggerEvent payload) {
return ClusterUpgradeContext.from(flowParameters, payload);
}
};
}
Aggregations