Search in sources :

Example 1 with ClusterUpgradeFailedEvent

use of com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterUpgradeFailedEvent 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 ClusterUpgradeFailedEvent

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

the class ClusterManagerUpgradeHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<ClusterManagerUpgradeRequest> event) {
    LOGGER.debug("Accepting Cluster Manager upgrade event..");
    ClusterManagerUpgradeRequest request = event.getData();
    Selectable result;
    try {
        clusterManagerUpgradeService.upgradeClusterManager(request.getResourceId(), request.isRuntimeServicesStartNeeded());
        result = new ClusterManagerUpgradeSuccess(request.getResourceId());
    } catch (Exception e) {
        LOGGER.info("Cluster Manager upgrade event failed", e);
        result = new ClusterUpgradeFailedEvent(request.getResourceId(), e, DetailedStackStatus.CLUSTER_MANAGER_UPGRADE_FAILED);
    }
    return result;
}
Also used : Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) ClusterManagerUpgradeRequest(com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterManagerUpgradeRequest) ClusterUpgradeFailedEvent(com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterUpgradeFailedEvent) ClusterManagerUpgradeSuccess(com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterManagerUpgradeSuccess)

Example 3 with ClusterUpgradeFailedEvent

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

the class ClusterUpgradeHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<ClusterUpgradeRequest> event) {
    LOGGER.debug("Accepting Cluster upgrade event..");
    ClusterUpgradeRequest request = event.getData();
    Long stackId = request.getResourceId();
    Selectable result;
    try {
        Stack stack = stackService.getByIdWithClusterInTransaction(stackId);
        Optional<String> remoteDataContext = getRemoteDataContext(stack);
        ClusterApi connector = clusterApiConnectors.getConnector(stack);
        Set<ClusterComponent> components = parcelService.getParcelComponentsByBlueprint(stack);
        connector.upgradeClusterRuntime(components, request.isPatchUpgrade(), remoteDataContext);
        ParcelOperationStatus parcelOperationStatus = parcelService.removeUnusedParcelComponents(stack, components);
        if (parcelOperationStatus.getFailed().isEmpty()) {
            result = new ClusterUpgradeSuccess(request.getResourceId());
        } else {
            LOGGER.info("There are failed parcel removals: {}", parcelOperationStatus);
            CloudbreakException exception = new CloudbreakException(format("Failed to remove the following parcels: %s", parcelOperationStatus.getFailed()));
            result = new ClusterUpgradeFailedEvent(request.getResourceId(), exception, DetailedStackStatus.CLUSTER_UPGRADE_FAILED);
        }
    } catch (Exception e) {
        LOGGER.error("Cluster upgrade event failed", e);
        result = new ClusterUpgradeFailedEvent(request.getResourceId(), e, DetailedStackStatus.CLUSTER_UPGRADE_FAILED);
    }
    return result;
}
Also used : ClusterApi(com.sequenceiq.cloudbreak.cluster.api.ClusterApi) ClusterComponent(com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterComponent) ClusterUpgradeRequest(com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterUpgradeRequest) ClusterUpgradeFailedEvent(com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterUpgradeFailedEvent) ClusterUpgradeSuccess(com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterUpgradeSuccess) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) ParcelOperationStatus(com.sequenceiq.cloudbreak.cluster.model.ParcelOperationStatus) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException)

Example 4 with ClusterUpgradeFailedEvent

use of com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterUpgradeFailedEvent 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);
        }
    };
}
Also used : Optional(java.util.Optional) ClusterUpgradeTargetImageService(com.sequenceiq.cloudbreak.service.image.ClusterUpgradeTargetImageService) StateContext(org.springframework.statemachine.StateContext) ClusterUpgradeFailedEvent(com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterUpgradeFailedEvent) ImageComponentUpdaterService(com.sequenceiq.cloudbreak.service.upgrade.ImageComponentUpdaterService) ClusterUpgradeInitRequest(com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterUpgradeInitRequest) FlowParameters(com.sequenceiq.flow.core.FlowParameters) ClusterUpgradeTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.ClusterUpgradeTriggerEvent) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) UpgradeImageInfo(com.sequenceiq.cloudbreak.service.upgrade.UpgradeImageInfo) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 5 with ClusterUpgradeFailedEvent

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

the class ClusterUpgradeInitHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<ClusterUpgradeInitRequest> event) {
    LOGGER.debug("Accepting Cluster Manager parcel deactivation event..");
    Stack stack = stackService.getByIdWithClusterInTransaction(event.getData().getResourceId());
    ClusterUpgradeInitRequest request = event.getData();
    Selectable result;
    try {
        Set<ClusterComponent> componentsByBlueprint = parcelService.getParcelComponentsByBlueprint(stack);
        parcelService.removeUnusedParcelComponents(stack, componentsByBlueprint);
        clusterApiConnectors.getConnector(stack).downloadAndDistributeParcels(componentsByBlueprint, request.isPatchUpgrade());
        result = new ClusterUpgradeInitSuccess(request.getResourceId());
    } catch (Exception e) {
        LOGGER.error("Cluster Manager parcel deactivation failed", e);
        result = new ClusterUpgradeFailedEvent(request.getResourceId(), e, DetailedStackStatus.CLUSTER_UPGRADE_INIT_FAILED);
    }
    return result;
}
Also used : ClusterUpgradeInitRequest(com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterUpgradeInitRequest) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) ClusterComponent(com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterComponent) ClusterUpgradeInitSuccess(com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterUpgradeInitSuccess) ClusterUpgradeFailedEvent(com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterUpgradeFailedEvent) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Aggregations

ClusterUpgradeFailedEvent (com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterUpgradeFailedEvent)5 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)4 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)3 ClusterComponent (com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterComponent)2 ClusterUpgradeInitRequest (com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterUpgradeInitRequest)2 FlowParameters (com.sequenceiq.flow.core.FlowParameters)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Bean (org.springframework.context.annotation.Bean)2 StateContext (org.springframework.statemachine.StateContext)2 Image (com.sequenceiq.cloudbreak.cloud.model.catalog.Image)1 ClusterApi (com.sequenceiq.cloudbreak.cluster.api.ClusterApi)1 ParcelOperationStatus (com.sequenceiq.cloudbreak.cluster.model.ParcelOperationStatus)1 ClusterUpgradeTriggerEvent (com.sequenceiq.cloudbreak.core.flow2.event.ClusterUpgradeTriggerEvent)1 ClusterManagerUpgradeRequest (com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterManagerUpgradeRequest)1 ClusterManagerUpgradeSuccess (com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterManagerUpgradeSuccess)1 ClusterUpgradeFailHandledRequest (com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterUpgradeFailHandledRequest)1 ClusterUpgradeFailedCmSyncRequest (com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterUpgradeFailedCmSyncRequest)1 ClusterUpgradeInitSuccess (com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterUpgradeInitSuccess)1 ClusterUpgradeRequest (com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterUpgradeRequest)1