Search in sources :

Example 1 with UpgradeImageInfo

use of com.sequenceiq.cloudbreak.service.upgrade.UpgradeImageInfo in project cloudbreak by hortonworks.

the class ClusterUpgradeValidationActions method clusterUpgradeImageValidation.

@Bean(name = "CLUSTER_UPGRADE_IMAGE_VALIDATION_STATE")
public Action<?, ?> clusterUpgradeImageValidation() {
    return new AbstractClusterUpgradeValidationAction<>(ClusterUpgradeValidationEvent.class) {

        @Override
        protected void doExecute(StackContext context, ClusterUpgradeValidationEvent payload, Map<Object, Object> variables) throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
            LOGGER.info("Starting cluster upgrade image validation.");
            UpgradeImageInfo upgradeImageInfo = upgradeImageInfoFactory.create(payload.getImageId(), payload.getResourceId());
            Image targetImage = stackImageService.getImageModelFromStatedImage(context.getStack(), upgradeImageInfo.getCurrentImage(), upgradeImageInfo.getTargetStatedImage());
            variables.put(TARGET_IMAGE, targetImage);
            CloudStack cloudStack = context.getCloudStack().replaceImage(targetImage);
            ClusterUpgradeImageValidationEvent event = new ClusterUpgradeImageValidationEvent(payload.getResourceId(), payload.getImageId(), cloudStack, context.getCloudCredential(), context.getCloudContext(), upgradeImageInfo.getTargetStatedImage().getImage());
            sendEvent(context, event.selector(), event);
        }

        @Override
        protected Object getFailurePayload(ClusterUpgradeValidationEvent payload, Optional<StackContext> flowContext, Exception ex) {
            return new ClusterUpgradeValidationFailureEvent(payload.getResourceId(), ex);
        }
    };
}
Also used : ClusterUpgradeValidationEvent(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.event.ClusterUpgradeValidationEvent) Optional(java.util.Optional) StackContext(com.sequenceiq.cloudbreak.core.flow2.stack.StackContext) UpgradeImageInfo(com.sequenceiq.cloudbreak.service.upgrade.UpgradeImageInfo) Image(com.sequenceiq.cloudbreak.cloud.model.Image) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Map(java.util.Map) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) ClusterUpgradeValidationFailureEvent(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.event.ClusterUpgradeValidationFailureEvent) ClusterUpgradeUpdateCheckFailedToClusterUpgradeValidationFailureEvent(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.config.ClusterUpgradeUpdateCheckFailedToClusterUpgradeValidationFailureEvent) Bean(org.springframework.context.annotation.Bean)

Example 2 with UpgradeImageInfo

use of com.sequenceiq.cloudbreak.service.upgrade.UpgradeImageInfo 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)

Aggregations

UpgradeImageInfo (com.sequenceiq.cloudbreak.service.upgrade.UpgradeImageInfo)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Bean (org.springframework.context.annotation.Bean)2 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)1 Image (com.sequenceiq.cloudbreak.cloud.model.Image)1 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)1 CloudbreakImageCatalogException (com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException)1 CloudbreakImageNotFoundException (com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException)1 ClusterUpgradeUpdateCheckFailedToClusterUpgradeValidationFailureEvent (com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.config.ClusterUpgradeUpdateCheckFailedToClusterUpgradeValidationFailureEvent)1 ClusterUpgradeValidationEvent (com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.event.ClusterUpgradeValidationEvent)1 ClusterUpgradeValidationFailureEvent (com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.event.ClusterUpgradeValidationFailureEvent)1 ClusterUpgradeTriggerEvent (com.sequenceiq.cloudbreak.core.flow2.event.ClusterUpgradeTriggerEvent)1 StackContext (com.sequenceiq.cloudbreak.core.flow2.stack.StackContext)1 ClusterUpgradeFailedEvent (com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterUpgradeFailedEvent)1 ClusterUpgradeInitRequest (com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterUpgradeInitRequest)1 ClusterUpgradeTargetImageService (com.sequenceiq.cloudbreak.service.image.ClusterUpgradeTargetImageService)1 ImageComponentUpdaterService (com.sequenceiq.cloudbreak.service.upgrade.ImageComponentUpdaterService)1 FlowParameters (com.sequenceiq.flow.core.FlowParameters)1 StateContext (org.springframework.statemachine.StateContext)1