Search in sources :

Example 1 with ClusterUpgradeInitRequest

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

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

Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)2 ClusterUpgradeFailedEvent (com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterUpgradeFailedEvent)2 ClusterUpgradeInitRequest (com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterUpgradeInitRequest)2 ClusterUpgradeTriggerEvent (com.sequenceiq.cloudbreak.core.flow2.event.ClusterUpgradeTriggerEvent)1 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)1 ClusterComponent (com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterComponent)1 ClusterUpgradeInitSuccess (com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterUpgradeInitSuccess)1 ClusterUpgradeTargetImageService (com.sequenceiq.cloudbreak.service.image.ClusterUpgradeTargetImageService)1 ImageComponentUpdaterService (com.sequenceiq.cloudbreak.service.upgrade.ImageComponentUpdaterService)1 UpgradeImageInfo (com.sequenceiq.cloudbreak.service.upgrade.UpgradeImageInfo)1 FlowParameters (com.sequenceiq.flow.core.FlowParameters)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Bean (org.springframework.context.annotation.Bean)1 StateContext (org.springframework.statemachine.StateContext)1