Search in sources :

Example 1 with ClusterUpgradeSuccess

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

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

the class ClusterUpgradeActions method upgradeCluster.

@Bean(name = "CLUSTER_UPGRADE_STATE")
public Action<?, ?> upgradeCluster() {
    return new AbstractClusterUpgradeAction<>(ClusterManagerUpgradeSuccess.class) {

        @Override
        protected ClusterUpgradeContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, ClusterManagerUpgradeSuccess payload) {
            return ClusterUpgradeContext.from(flowParameters, payload);
        }

        @Override
        protected void doExecute(ClusterUpgradeContext context, ClusterManagerUpgradeSuccess payload, Map<Object, Object> variables) {
            Image currentImage = getCurrentImage(variables).getImage();
            Image targetImage = getTargetImage(variables).getImage();
            boolean clusterRuntimeUpgradeNeeded = clusterUpgradeService.upgradeCluster(context.getStackId(), currentImage, targetImage);
            Selectable event;
            if (clusterRuntimeUpgradeNeeded) {
                event = new ClusterUpgradeRequest(context.getStackId(), isPatchUpgrade(currentImage, targetImage));
            } else {
                event = new ClusterUpgradeSuccess(context.getStackId());
            }
            sendEvent(context, event.selector(), event);
        }

        @Override
        protected Object getFailurePayload(ClusterManagerUpgradeSuccess payload, Optional<ClusterUpgradeContext> flowContext, Exception ex) {
            return ClusterUpgradeFailedEvent.from(payload, ex, DetailedStackStatus.CLUSTER_UPGRADE_FAILED);
        }
    };
}
Also used : Optional(java.util.Optional) StateContext(org.springframework.statemachine.StateContext) ClusterUpgradeRequest(com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterUpgradeRequest) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) ClusterUpgradeSuccess(com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterUpgradeSuccess) FlowParameters(com.sequenceiq.flow.core.FlowParameters) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) ClusterManagerUpgradeSuccess(com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterManagerUpgradeSuccess) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 3 with ClusterUpgradeSuccess

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

the class ClusterUpgradeActions method clusterUpgradeFinished.

@Bean(name = "CLUSTER_UPGRADE_FINISHED_STATE")
public Action<?, ?> clusterUpgradeFinished() {
    return new AbstractClusterUpgradeAction<>(ClusterUpgradeSuccess.class) {

        @Inject
        private StackImageService stackImageService;

        @Override
        protected ClusterUpgradeContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, ClusterUpgradeSuccess payload) {
            return ClusterUpgradeContext.from(flowParameters, payload);
        }

        @Override
        protected void doExecute(ClusterUpgradeContext context, ClusterUpgradeSuccess payload, Map<Object, Object> variables) {
            StatedImage currentImage = getCurrentImage(variables);
            StatedImage targetImage = getTargetImage(variables);
            clusterUpgradeService.clusterUpgradeFinished(context.getStackId(), currentImage, targetImage);
            stackImageService.removeImageByComponentName(context.getStackId(), TARGET_IMAGE);
            sendEvent(context);
        }

        @Override
        protected Selectable createRequest(ClusterUpgradeContext context) {
            return new StackEvent(ClusterUpgradeEvent.CLUSTER_UPGRADE_FINALIZED_EVENT.event(), context.getStackId());
        }

        @Override
        protected Object getFailurePayload(ClusterUpgradeSuccess payload, Optional<ClusterUpgradeContext> flowContext, Exception ex) {
            return null;
        }
    };
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) Optional(java.util.Optional) StateContext(org.springframework.statemachine.StateContext) StackImageService(com.sequenceiq.cloudbreak.service.stack.StackImageService) ClusterUpgradeSuccess(com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterUpgradeSuccess) Map(java.util.Map) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) Bean(org.springframework.context.annotation.Bean)

Aggregations

ClusterUpgradeSuccess (com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterUpgradeSuccess)3 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)2 ClusterUpgradeRequest (com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterUpgradeRequest)2 StatedImage (com.sequenceiq.cloudbreak.service.image.StatedImage)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 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)1 ClusterComponent (com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterComponent)1 StackEvent (com.sequenceiq.cloudbreak.reactor.api.event.StackEvent)1 ClusterManagerUpgradeSuccess (com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterManagerUpgradeSuccess)1 ClusterUpgradeFailedEvent (com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterUpgradeFailedEvent)1 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)1 StackImageService (com.sequenceiq.cloudbreak.service.stack.StackImageService)1