Search in sources :

Example 1 with ClusterUpgradeFailHandledRequest

use of com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterUpgradeFailHandledRequest in project cloudbreak by hortonworks.

the class ClusterUpgradeActions method clusterUpgradeFailedAction.

@Bean(name = "CLUSTER_UPGRADE_FAILED_STATE")
public Action<?, ?> clusterUpgradeFailedAction() {
    return new AbstractClusterUpgradeAction<>(ClusterUpgradeFailedEvent.class) {

        @Value("${cb.upgrade.failure.sync.sdx.enabled}")
        private boolean syncAfterFailureEnabled;

        @Override
        protected ClusterUpgradeContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, ClusterUpgradeFailedEvent payload) {
            Flow flow = getFlow(flowParameters.getFlowId());
            Stack stack = stackService.getById(payload.getResourceId());
            MDCBuilder.buildMdcContext(stack);
            flow.setFlowFailed(payload.getException());
            return ClusterUpgradeContext.from(flowParameters, payload);
        }

        @Override
        protected void doExecute(ClusterUpgradeContext context, ClusterUpgradeFailedEvent payload, Map<Object, Object> variables) {
            clusterUpgradeService.handleUpgradeClusterFailure(context.getStackId(), payload.getException().getMessage(), payload.getDetailedStatus());
            if (syncAfterFailureEnabled) {
                LOGGER.debug("Starting syncing parcel and CM version from CM to DB.");
                try {
                    Set<Image> candidateImages = new HashSet<>();
                    Optional.ofNullable(getCurrentImage(variables)).ifPresent(si -> candidateImages.add(si.getImage()));
                    Optional.ofNullable(getTargetImage(variables)).ifPresent(si -> candidateImages.add(si.getImage()));
                    ClusterUpgradeFailedCmSyncRequest cmSyncRequest = new ClusterUpgradeFailedCmSyncRequest(payload.getResourceId(), payload.getException(), payload.getDetailedStatus(), candidateImages);
                    sendEvent(context, cmSyncRequest);
                } catch (Exception e) {
                    LOGGER.warn("Error starting syncing CM version to DB, syncing skipped: ", e);
                    sendEvent(context, new ClusterUpgradeFailHandledRequest(payload.getResourceId(), payload.getException(), payload.getDetailedStatus()));
                }
            } else {
                LOGGER.debug("Syncing from CM to DB is not enabled.");
                sendEvent(context, new ClusterUpgradeFailHandledRequest(payload.getResourceId(), payload.getException(), payload.getDetailedStatus()));
            }
        }

        @Override
        protected Object getFailurePayload(ClusterUpgradeFailedEvent payload, Optional<ClusterUpgradeContext> flowContext, Exception ex) {
            return null;
        }
    };
}
Also used : Optional(java.util.Optional) StateContext(org.springframework.statemachine.StateContext) ClusterUpgradeFailedEvent(com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterUpgradeFailedEvent) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) ClusterUpgradeFailedCmSyncRequest(com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterUpgradeFailedCmSyncRequest) Flow(com.sequenceiq.flow.core.Flow) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) FlowParameters(com.sequenceiq.flow.core.FlowParameters) ClusterUpgradeFailHandledRequest(com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterUpgradeFailHandledRequest) Map(java.util.Map) HashSet(java.util.HashSet) Bean(org.springframework.context.annotation.Bean)

Example 2 with ClusterUpgradeFailHandledRequest

use of com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterUpgradeFailHandledRequest in project cloudbreak by hortonworks.

the class ClusterUpgradeFailedCmSyncHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<ClusterUpgradeFailedCmSyncRequest> event) {
    ClusterUpgradeFailedCmSyncRequest request = event.getData();
    try {
        Stack stack = stackService.getByIdWithListsInTransaction(request.getResourceId());
        cmSyncerService.syncFromCmToDb(stack, request.getCandidateImages());
    } catch (Exception e) {
        LOGGER.warn("Error during syncing CM version to DB, syncing skipped.", e);
    }
    return new ClusterUpgradeFailHandledRequest(request.getResourceId(), request.getException(), request.getDetailedStatus());
}
Also used : ClusterUpgradeFailHandledRequest(com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterUpgradeFailHandledRequest) ClusterUpgradeFailedCmSyncRequest(com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterUpgradeFailedCmSyncRequest) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Aggregations

Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)2 ClusterUpgradeFailHandledRequest (com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterUpgradeFailHandledRequest)2 ClusterUpgradeFailedCmSyncRequest (com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterUpgradeFailedCmSyncRequest)2 Image (com.sequenceiq.cloudbreak.cloud.model.catalog.Image)1 ClusterUpgradeFailedEvent (com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterUpgradeFailedEvent)1 StatedImage (com.sequenceiq.cloudbreak.service.image.StatedImage)1 Flow (com.sequenceiq.flow.core.Flow)1 FlowParameters (com.sequenceiq.flow.core.FlowParameters)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Bean (org.springframework.context.annotation.Bean)1 StateContext (org.springframework.statemachine.StateContext)1