Search in sources :

Example 51 with FlowParameters

use of com.sequenceiq.flow.core.FlowParameters in project cloudbreak by hortonworks.

the class ClusterUpgradeActions method upgradeClusterManager.

@Bean(name = "CLUSTER_MANAGER_UPGRADE_STATE")
public Action<?, ?> upgradeClusterManager() {
    return new AbstractClusterUpgradeAction<>(ClusterUpgradeInitSuccess.class) {

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

        @Override
        protected void doExecute(ClusterUpgradeContext context, ClusterUpgradeInitSuccess payload, Map<Object, Object> variables) {
            Image currentImage = getCurrentImage(variables).getImage();
            Image targetImage = getTargetImage(variables).getImage();
            clusterUpgradeService.upgradeClusterManager(context.getStackId());
            Selectable event = new ClusterManagerUpgradeRequest(context.getStackId(), !clusterUpgradeService.isClusterRuntimeUpgradeNeeded(currentImage, targetImage));
            sendEvent(context, event.selector(), event);
        }

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

Example 52 with FlowParameters

use of com.sequenceiq.flow.core.FlowParameters 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 53 with FlowParameters

use of com.sequenceiq.flow.core.FlowParameters in project cloudbreak by hortonworks.

the class DatabaseRestoreActions method databaseRestoreFailedAction.

@Bean(name = "DATABASE_RESTORE_FAILED_STATE")
public Action<?, ?> databaseRestoreFailedAction() {
    return new AbstractBackupRestoreActions<>(DatabaseRestoreFailedEvent.class) {

        @Override
        protected BackupRestoreContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, DatabaseRestoreFailedEvent payload) {
            Flow flow = getFlow(flowParameters.getFlowId());
            flow.setFlowFailed(payload.getException());
            return BackupRestoreContext.from(flowParameters, payload, null, null, true);
        }

        @Override
        protected void doExecute(BackupRestoreContext context, DatabaseRestoreFailedEvent payload, Map<Object, Object> variables) {
            backupRestoreStatusService.handleDatabaseRestoreFailure(context.getStackId(), payload.getException().getMessage(), payload.getDetailedStatus());
            sendEvent(context, DATABASE_RESTORE_FAIL_HANDLED_EVENT.event(), payload);
        }
    };
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) DatabaseRestoreFailedEvent(com.sequenceiq.cloudbreak.reactor.api.event.cluster.dr.restore.DatabaseRestoreFailedEvent) StateContext(org.springframework.statemachine.StateContext) AbstractBackupRestoreActions(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.dr.AbstractBackupRestoreActions) Map(java.util.Map) BackupRestoreContext(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.dr.BackupRestoreContext) Flow(com.sequenceiq.flow.core.Flow) Bean(org.springframework.context.annotation.Bean)

Example 54 with FlowParameters

use of com.sequenceiq.flow.core.FlowParameters in project cloudbreak by hortonworks.

the class DatabaseBackupActions method databaseBackupFailedAction.

@Bean(name = "DATABASE_BACKUP_FAILED_STATE")
public Action<?, ?> databaseBackupFailedAction() {
    return new AbstractBackupRestoreActions<>(DatabaseBackupFailedEvent.class) {

        @Override
        protected BackupRestoreContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, DatabaseBackupFailedEvent payload) {
            Flow flow = getFlow(flowParameters.getFlowId());
            flow.setFlowFailed(payload.getException());
            return BackupRestoreContext.from(flowParameters, payload, null, null, true);
        }

        @Override
        protected void doExecute(BackupRestoreContext context, DatabaseBackupFailedEvent payload, Map<Object, Object> variables) {
            backupRestoreStatusService.handleDatabaseBackupFailure(context.getStackId(), payload.getException().getMessage(), payload.getDetailedStatus());
            sendEvent(context, DATABASE_BACKUP_FAIL_HANDLED_EVENT.event(), payload);
        }
    };
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) StateContext(org.springframework.statemachine.StateContext) AbstractBackupRestoreActions(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.dr.AbstractBackupRestoreActions) DatabaseBackupFailedEvent(com.sequenceiq.cloudbreak.reactor.api.event.cluster.dr.backup.DatabaseBackupFailedEvent) Map(java.util.Map) BackupRestoreContext(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.dr.BackupRestoreContext) Flow(com.sequenceiq.flow.core.Flow) Bean(org.springframework.context.annotation.Bean)

Example 55 with FlowParameters

use of com.sequenceiq.flow.core.FlowParameters in project cloudbreak by hortonworks.

the class AbstractInstanceTerminationAction method createFlowContext.

@Override
protected InstanceTerminationContext createFlowContext(FlowParameters flowParameters, StateContext<InstanceTerminationState, InstanceTerminationEvent> stateContext, P payload) {
    Stack stack = stackService.getByIdWithListsInTransaction(payload.getResourceId());
    stack.setResources(new HashSet<>(resourceService.getAllByStackId(payload.getResourceId())));
    MDCBuilder.buildMdcContext(stack);
    Location location = location(region(stack.getRegion()), availabilityZone(stack.getAvailabilityZone()));
    CloudContext cloudContext = CloudContext.Builder.builder().withId(stack.getId()).withName(stack.getName()).withCrn(stack.getResourceCrn()).withPlatform(stack.getCloudPlatform()).withVariant(stack.getPlatformVariant()).withLocation(location).withWorkspaceId(stack.getWorkspace().getId()).withAccountId(Crn.safeFromString(stack.getResourceCrn()).getAccountId()).withTenantId(stack.getTenant().getId()).build();
    CloudCredential cloudCredential = stackUtil.getCloudCredential(stack);
    Set<String> instanceIds = payload.getInstanceIds();
    CloudStack cloudStack = cloudStackConverter.convert(stack, instanceIds);
    List<CloudResource> cloudResources = stack.getResources().stream().map(r -> cloudResourceConverter.convert(r)).collect(Collectors.toList());
    List<InstanceMetaData> instanceMetaDataList = new ArrayList<>();
    List<CloudInstance> cloudInstances = new ArrayList<>();
    DetailedEnvironmentResponse environment = environmentClientService.getByCrnAsInternal(stack.getEnvironmentCrn());
    for (String instanceId : instanceIds) {
        InstanceMetaData instanceMetaData = instanceMetaDataService.findByStackIdAndInstanceId(stack.getId(), instanceId).orElseThrow(NotFoundException.notFound("instanceMetadata", instanceId));
        CloudInstance cloudInstance = metadataConverter.convert(instanceMetaData, environment, stack.getStackAuthentication());
        instanceMetaDataList.add(instanceMetaData);
        cloudInstances.add(cloudInstance);
    }
    return new InstanceTerminationContext(flowParameters, stack, cloudContext, cloudCredential, cloudStack, cloudResources, cloudInstances, instanceMetaDataList);
}
Also used : Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) AvailabilityZone.availabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone.availabilityZone) StackToCloudStackConverter(com.sequenceiq.cloudbreak.converter.spi.StackToCloudStackConverter) Location.location(com.sequenceiq.cloudbreak.cloud.model.Location.location) MDCBuilder(com.sequenceiq.cloudbreak.logger.MDCBuilder) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) StackFailureEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ResourceToCloudResourceConverter(com.sequenceiq.cloudbreak.converter.spi.ResourceToCloudResourceConverter) ResourceService(com.sequenceiq.cloudbreak.service.resource.ResourceService) InstanceMetaDataToCloudInstanceConverter(com.sequenceiq.cloudbreak.converter.spi.InstanceMetaDataToCloudInstanceConverter) StateContext(org.springframework.statemachine.StateContext) InstancePayload(com.sequenceiq.cloudbreak.cloud.event.InstancePayload) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) Location(com.sequenceiq.cloudbreak.cloud.model.Location) InstanceMetaDataService(com.sequenceiq.cloudbreak.service.stack.InstanceMetaDataService) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) AbstractStackAction(com.sequenceiq.cloudbreak.core.flow2.AbstractStackAction) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Region.region(com.sequenceiq.cloudbreak.cloud.model.Region.region) Set(java.util.Set) FlowParameters(com.sequenceiq.flow.core.FlowParameters) EnvironmentClientService(com.sequenceiq.cloudbreak.service.environment.EnvironmentClientService) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Collectors(java.util.stream.Collectors) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) List(java.util.List) StackUtil(com.sequenceiq.cloudbreak.util.StackUtil) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) Optional(java.util.Optional) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Location(com.sequenceiq.cloudbreak.cloud.model.Location)

Aggregations

FlowParameters (com.sequenceiq.flow.core.FlowParameters)103 Map (java.util.Map)84 StateContext (org.springframework.statemachine.StateContext)84 Bean (org.springframework.context.annotation.Bean)81 Optional (java.util.Optional)67 SdxContext (com.sequenceiq.datalake.flow.SdxContext)56 AbstractSdxAction (com.sequenceiq.datalake.service.AbstractSdxAction)52 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)31 Flow (com.sequenceiq.flow.core.Flow)28 SdxEvent (com.sequenceiq.datalake.flow.SdxEvent)16 Stack (com.sequenceiq.freeipa.entity.Stack)12 List (java.util.List)11 StackEvent (com.sequenceiq.cloudbreak.reactor.api.event.StackEvent)10 BeforeEach (org.junit.jupiter.api.BeforeEach)9 Test (org.junit.jupiter.api.Test)9 HashMap (java.util.HashMap)8 PollerStoppedException (com.dyngr.exception.PollerStoppedException)7 NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)7 FailureDetails (com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails)7 SuccessDetails (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails)7