Search in sources :

Example 1 with Action

use of org.springframework.statemachine.action.Action in project cloudbreak by hortonworks.

the class StopStartUpscaleActions method cmCommissionAction.

@Bean(name = "STOPSTART_UPSCALE_HOSTS_COMMISSION_STATE")
public Action<?, ?> cmCommissionAction() {
    return new AbstractStopStartUpscaleActions<>(StopStartUpscaleStartInstancesResult.class) {

        @Override
        protected void doExecute(StopStartUpscaleContext context, StopStartUpscaleStartInstancesResult payload, Map<Object, Object> variables) throws Exception {
            // Update instance metadata for successful nodes before handling / logging info about failures.
            List<CloudVmInstanceStatus> cloudVmInstanceStatusList = payload.getAffectedInstanceStatuses();
            Set<String> cloudInstanceIdsStarted = cloudVmInstanceStatusList.stream().filter(x -> x.getStatus() == InstanceStatus.STARTED).map(x -> x.getCloudInstance().getInstanceId()).collect(Collectors.toUnmodifiableSet());
            List<InstanceMetaData> startedInstancesMetaData = cloudInstanceIdToInstanceMetaDataConverter.getNotDeletedAndNotZombieInstances(context.getStack(), context.getHostGroupName(), cloudInstanceIdsStarted);
            clusterUpscaleFlowService.instancesStarted(context.getStack().getId(), startedInstancesMetaData);
            handleInstanceUnsuccessfulStart(context, cloudVmInstanceStatusList);
            // This list is currently empty. It could be populated later in another flow-step by querying CM to get service health.
            // Meant to be a mechanism which detects cloud instances which are RUNNING, but not being utilized (likely due to previous failures)
            List<CloudInstance> instancesWithServicesNotRunning = payload.getStartInstanceRequest().getStartedInstancesWithServicesNotRunning();
            List<InstanceMetaData> metaDataWithServicesNotRunning = cloudInstanceIdToInstanceMetaDataConverter.getNotDeletedAndNotZombieInstances(context.getStack(), context.getHostGroupName(), instancesWithServicesNotRunning.stream().map(i -> i.getInstanceId()).collect(Collectors.toUnmodifiableSet()));
            LOGGER.info("StartedInstancesCount={}, StartedInstancesMetadataCount={}," + " instancesWithServicesNotRunningCount={}, instancesWithServicesNotRunningMetadataCount={}", cloudInstanceIdsStarted.size(), startedInstancesMetaData.size(), instancesWithServicesNotRunning.size(), metaDataWithServicesNotRunning.size());
            int toCommissionNodeCount = metaDataWithServicesNotRunning.size() + startedInstancesMetaData.size();
            if (toCommissionNodeCount < context.getAdjustment()) {
                LOGGER.warn("Not enough nodes found to commission. DesiredCount={}, availableCount={}", context.getAdjustment(), toCommissionNodeCount);
                clusterUpscaleFlowService.warnNotEnoughInstances(context.getStack().getId(), context.getHostGroupName(), context.getAdjustment(), toCommissionNodeCount);
            }
            clusterUpscaleFlowService.upscaleCommissioningNodes(context.getStack().getId(), context.getHostGroupName(), startedInstancesMetaData, metaDataWithServicesNotRunning);
            StopStartUpscaleCommissionViaCMRequest commissionRequest = new StopStartUpscaleCommissionViaCMRequest(context.getStack().getId(), context.getHostGroupName(), startedInstancesMetaData, metaDataWithServicesNotRunning);
            sendEvent(context, commissionRequest);
        }

        private void handleInstanceUnsuccessfulStart(StopStartUpscaleContext context, List<CloudVmInstanceStatus> cloudVmInstanceStatusList) {
            try {
                List<CloudVmInstanceStatus> instancesNotInDesiredState = cloudVmInstanceStatusList.stream().filter(i -> i.getStatus() != InstanceStatus.STARTED).collect(Collectors.toList());
                if (instancesNotInDesiredState.size() > 0) {
                    // Not updating the status of these instances in the DB. Instead letting the regular syncer threads take care of this.
                    // This is in case there is additional logic in the syncers while processing Instance state changes.
                    LOGGER.warn("Some instances could not be started: count={}, instances={}", instancesNotInDesiredState.size(), instancesNotInDesiredState);
                    clusterUpscaleFlowService.logInstancesFailedToStart(context.getStack().getId(), instancesNotInDesiredState);
                // TODO CB-15132: Eventually, we may want to take some corrective action.
                }
            } catch (Exception e) {
                LOGGER.warn("Failed while attempting to log info about instances which did not start. Ignoring, and letting flow proceed", e);
            }
        }
    };
}
Also used : Action(org.springframework.statemachine.action.Action) DetailedStackStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) AvailabilityZone.availabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone.availabilityZone) StopStartUpscaleStartInstancesRequest(com.sequenceiq.cloudbreak.cloud.event.instance.StopStartUpscaleStartInstancesRequest) LoggerFactory(org.slf4j.LoggerFactory) StackToCloudStackConverter(com.sequenceiq.cloudbreak.converter.spi.StackToCloudStackConverter) Location.location(com.sequenceiq.cloudbreak.cloud.model.Location.location) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) STOPSTART_UPSCALE_FAILURE_EVENT(com.sequenceiq.cloudbreak.core.flow2.cluster.stopstartus.StopStartUpscaleEvent.STOPSTART_UPSCALE_FAILURE_EVENT) InstanceMetaDataToCloudInstanceConverter(com.sequenceiq.cloudbreak.converter.spi.InstanceMetaDataToCloudInstanceConverter) Map(java.util.Map) Location(com.sequenceiq.cloudbreak.cloud.model.Location) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) AbstractStackAction(com.sequenceiq.cloudbreak.core.flow2.AbstractStackAction) AbstractStackFailureAction(com.sequenceiq.cloudbreak.core.flow2.stack.AbstractStackFailureAction) STOPPED(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.STOPPED) StackFailureContext(com.sequenceiq.cloudbreak.core.flow2.stack.StackFailureContext) Set(java.util.Set) FlowParameters(com.sequenceiq.flow.core.FlowParameters) StopStartUpscaleStartInstancesResult(com.sequenceiq.cloudbreak.cloud.event.instance.StopStartUpscaleStartInstancesResult) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn) StopStartUpscaleCommissionViaCMRequest(com.sequenceiq.cloudbreak.reactor.api.event.cluster.StopStartUpscaleCommissionViaCMRequest) Collectors(java.util.stream.Collectors) Configuration(org.springframework.context.annotation.Configuration) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) List(java.util.List) StackUtil(com.sequenceiq.cloudbreak.util.StackUtil) Optional(java.util.Optional) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Payload(com.sequenceiq.cloudbreak.common.event.Payload) MDCBuilder(com.sequenceiq.cloudbreak.logger.MDCBuilder) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) StackFailureEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) StopStartUpscaleCommissionViaCMResult(com.sequenceiq.cloudbreak.reactor.api.event.orchestration.StopStartUpscaleCommissionViaCMResult) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ResourceService(com.sequenceiq.cloudbreak.service.resource.ResourceService) CloudInstanceIdToInstanceMetaDataConverter(com.sequenceiq.cloudbreak.converter.CloudInstanceIdToInstanceMetaDataConverter) ClusterManagerType(com.sequenceiq.cloudbreak.common.type.ClusterManagerType) StateContext(org.springframework.statemachine.StateContext) Logger(org.slf4j.Logger) Region.region(com.sequenceiq.cloudbreak.cloud.model.Region.region) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) STOPSTART_UPSCALE_FINALIZED_EVENT(com.sequenceiq.cloudbreak.core.flow2.cluster.stopstartus.StopStartUpscaleEvent.STOPSTART_UPSCALE_FINALIZED_EVENT) InstanceStatus(com.sequenceiq.cloudbreak.cloud.model.InstanceStatus) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) Bean(org.springframework.context.annotation.Bean) VisibleForTesting(com.google.common.annotations.VisibleForTesting) StopStartUpscaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StopStartUpscaleTriggerEvent) Collections(java.util.Collections) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) StopStartUpscaleStartInstancesResult(com.sequenceiq.cloudbreak.cloud.event.instance.StopStartUpscaleStartInstancesResult) StopStartUpscaleCommissionViaCMRequest(com.sequenceiq.cloudbreak.reactor.api.event.cluster.StopStartUpscaleCommissionViaCMRequest) List(java.util.List) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 2 with Action

use of org.springframework.statemachine.action.Action in project cloudbreak by hortonworks.

the class ClusterUpgradeValidationActions method clusterUpgradeCheckCloudProviderUpdate.

@Bean(name = "CLUSTER_UPGRADE_CLOUDPROVIDER_CHECK_UPDATE_STATE")
public Action<?, ?> clusterUpgradeCheckCloudProviderUpdate() {
    return new AbstractClusterUpgradeValidationAction<>(ClusterUpgradeDiskSpaceValidationFinishedEvent.class) {

        @Override
        protected void doExecute(StackContext context, ClusterUpgradeDiskSpaceValidationFinishedEvent payload, Map<Object, Object> variables) {
            Collection<Resource> resources = resourceService.getAllByStackId(context.getStack().getId());
            List<CloudResource> cloudResources = resources.stream().map(resource -> resourceToCloudResourceConverter.convert(resource)).collect(Collectors.toList());
            ClusterUpgradeUpdateCheckRequest clusterUpgradeUpdateCheckRequest = new ClusterUpgradeUpdateCheckRequest(payload.getResourceId(), context.getCloudStack(), context.getCloudCredential(), context.getCloudContext(), cloudResources);
            sendEvent(context, VALIDATE_CLOUDPROVIDER_UPDATE.selector(), clusterUpgradeUpdateCheckRequest);
        }

        @Override
        protected Object getFailurePayload(ClusterUpgradeDiskSpaceValidationFinishedEvent payload, Optional<StackContext> flowContext, Exception ex) {
            return new ClusterUpgradeValidationFailureEvent(payload.getResourceId(), ex);
        }
    };
}
Also used : StackView(com.sequenceiq.cloudbreak.domain.view.StackView) Action(org.springframework.statemachine.action.Action) DetailedStackStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus) Resource(com.sequenceiq.cloudbreak.domain.Resource) AVAILABLE(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.AVAILABLE) LoggerFactory(org.slf4j.LoggerFactory) ClusterUpgradeFreeIpaStatusValidationEvent(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.event.ClusterUpgradeFreeIpaStatusValidationEvent) UpgradeImageInfoFactory(com.sequenceiq.cloudbreak.service.upgrade.UpgradeImageInfoFactory) ClusterUpgradeDiskSpaceValidationEvent(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.event.ClusterUpgradeDiskSpaceValidationEvent) ClusterUpgradeDiskSpaceValidationFinishedEvent(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.event.ClusterUpgradeDiskSpaceValidationFinishedEvent) CloudbreakMessagesService(com.sequenceiq.cloudbreak.message.CloudbreakMessagesService) CloudbreakEventService(com.sequenceiq.cloudbreak.structuredevent.event.CloudbreakEventService) START_CLUSTER_UPGRADE_IMAGE_VALIDATION_EVENT(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.event.ClusterUpgradeValidationStateSelectors.START_CLUSTER_UPGRADE_IMAGE_VALIDATION_EVENT) Map(java.util.Map) ClusterUpgradeValidationTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.event.ClusterUpgradeValidationTriggerEvent) StackUpdater(com.sequenceiq.cloudbreak.service.StackUpdater) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException) VALIDATE_DISK_SPACE_EVENT(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.event.ClusterUpgradeValidationHandlerSelectors.VALIDATE_DISK_SPACE_EVENT) ClusterUpgradeContext(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.ClusterUpgradeContext) UPDATE_FAILED(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.UPDATE_FAILED) PayloadConverter(com.sequenceiq.flow.core.PayloadConverter) VALIDATE_CLOUDPROVIDER_UPDATE(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.event.ClusterUpgradeValidationHandlerSelectors.VALIDATE_CLOUDPROVIDER_UPDATE) Collection(java.util.Collection) ClusterUpgradeExistingUpgradeCommandValidationEvent(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.event.ClusterUpgradeExistingUpgradeCommandValidationEvent) FlowParameters(com.sequenceiq.flow.core.FlowParameters) ClusterUpgradeExistingUpgradeCommandValidationFinishedEvent(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.event.ClusterUpgradeExistingUpgradeCommandValidationFinishedEvent) Collectors(java.util.stream.Collectors) UpgradeImageInfo(com.sequenceiq.cloudbreak.service.upgrade.UpgradeImageInfo) Configuration(org.springframework.context.annotation.Configuration) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) ClusterUpgradeValidationEvent(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.event.ClusterUpgradeValidationEvent) List(java.util.List) ClusterUpgradeValidationFailureEvent(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.event.ClusterUpgradeValidationFailureEvent) ClusterUpgradeUpdateCheckFinishedEvent(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.event.ClusterUpgradeUpdateCheckFinishedEvent) Optional(java.util.Optional) Flow(com.sequenceiq.flow.core.Flow) StackContext(com.sequenceiq.cloudbreak.core.flow2.stack.StackContext) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) ClusterUpgradeUpdateCheckFailedToClusterUpgradeValidationFailureEvent(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.config.ClusterUpgradeUpdateCheckFailedToClusterUpgradeValidationFailureEvent) MDCBuilder(com.sequenceiq.cloudbreak.logger.MDCBuilder) Image(com.sequenceiq.cloudbreak.cloud.model.Image) ClusterUpgradeValidationEventToClusterUpgradeDiskSpaceValidationEventConverter(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.config.ClusterUpgradeValidationEventToClusterUpgradeDiskSpaceValidationEventConverter) AbstractAction(com.sequenceiq.flow.core.AbstractAction) Inject(javax.inject.Inject) ResourceToCloudResourceConverter(com.sequenceiq.cloudbreak.converter.spi.ResourceToCloudResourceConverter) ResourceService(com.sequenceiq.cloudbreak.service.resource.ResourceService) ClusterUpgradeUpdateCheckRequest(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.event.ClusterUpgradeUpdateCheckRequest) ClusterUpgradeValidationStateSelectors(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.event.ClusterUpgradeValidationStateSelectors) UPDATE_IN_PROGRESS(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.UPDATE_IN_PROGRESS) StateContext(org.springframework.statemachine.StateContext) Logger(org.slf4j.Logger) StackImageService(com.sequenceiq.cloudbreak.service.stack.StackImageService) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) ClusterUpgradeServiceValidationEvent(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.event.ClusterUpgradeServiceValidationEvent) ClusterUpgradeValidationFinalizeEvent(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.event.ClusterUpgradeValidationFinalizeEvent) ClusterUpgradeValidationFinishedEvent(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.event.ClusterUpgradeValidationFinishedEvent) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) HANDLED_FAILED_CLUSTER_UPGRADE_VALIDATION_EVENT(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.event.ClusterUpgradeValidationStateSelectors.HANDLED_FAILED_CLUSTER_UPGRADE_VALIDATION_EVENT) Bean(org.springframework.context.annotation.Bean) Collections(java.util.Collections) ClusterUpgradeFreeIpaStatusValidationFinishedEvent(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.event.ClusterUpgradeFreeIpaStatusValidationFinishedEvent) Optional(java.util.Optional) Resource(com.sequenceiq.cloudbreak.domain.Resource) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) StackContext(com.sequenceiq.cloudbreak.core.flow2.stack.StackContext) ClusterUpgradeDiskSpaceValidationFinishedEvent(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.event.ClusterUpgradeDiskSpaceValidationFinishedEvent) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) ClusterUpgradeUpdateCheckRequest(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.event.ClusterUpgradeUpdateCheckRequest) Map(java.util.Map) 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 3 with Action

use of org.springframework.statemachine.action.Action in project cloudbreak by hortonworks.

the class StackStartActions method stackStartAction.

@Bean(name = "START_STATE")
public Action<?, ?> stackStartAction() {
    return new AbstractStackStartAction<>(StackEvent.class) {

        @Override
        protected void doExecute(StackStartStopContext context, StackEvent payload, Map<Object, Object> variables) {
            stackStartStopService.startStackStart(context);
            sendEvent(context);
        }

        @Override
        protected Selectable createRequest(StackStartStopContext context) {
            Stack stack = context.getStack();
            LOGGER.debug("Assembling start request for stack: {}", stack);
            List<CloudInstance> cloudInstances = instanceMetaDataToCloudInstanceConverter.convert(stack.getNotDeletedAndNotZombieInstanceMetaDataList(), stack.getEnvironmentCrn(), stack.getStackAuthentication());
            List<CloudResource> resources = stack.getResources().stream().map(s -> resourceToCloudResourceConverter.convert(s)).collect(Collectors.toList());
            cloudInstances.forEach(instance -> context.getStack().getParameters().forEach(instance::putParameter));
            return new StartInstancesRequest(context.getCloudContext(), context.getCloudCredential(), resources, cloudInstances);
        }
    };
}
Also used : Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Action(org.springframework.statemachine.action.Action) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) Payload(com.sequenceiq.cloudbreak.common.event.Payload) AvailabilityZone.availabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone.availabilityZone) LoggerFactory(org.slf4j.LoggerFactory) 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) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) StackFailureEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) 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) Map(java.util.Map) Location(com.sequenceiq.cloudbreak.cloud.model.Location) StartInstancesRequest(com.sequenceiq.cloudbreak.cloud.event.instance.StartInstancesRequest) InstanceMetaDataService(com.sequenceiq.cloudbreak.service.stack.InstanceMetaDataService) StartInstancesResult(com.sequenceiq.cloudbreak.cloud.event.instance.StartInstancesResult) AbstractStackAction(com.sequenceiq.cloudbreak.core.flow2.AbstractStackAction) AbstractStackFailureAction(com.sequenceiq.cloudbreak.core.flow2.stack.AbstractStackFailureAction) Logger(org.slf4j.Logger) CollectMetadataResult(com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataResult) CollectMetadataRequest(com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataRequest) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) StackFailureContext(com.sequenceiq.cloudbreak.core.flow2.stack.StackFailureContext) Region.region(com.sequenceiq.cloudbreak.cloud.model.Region.region) FlowParameters(com.sequenceiq.flow.core.FlowParameters) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Collectors(java.util.stream.Collectors) Configuration(org.springframework.context.annotation.Configuration) List(java.util.List) StackUtil(com.sequenceiq.cloudbreak.util.StackUtil) MetricType(com.sequenceiq.cloudbreak.service.metrics.MetricType) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) Optional(java.util.Optional) Bean(org.springframework.context.annotation.Bean) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) StartInstancesRequest(com.sequenceiq.cloudbreak.cloud.event.instance.StartInstancesRequest) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Map(java.util.Map) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Bean(org.springframework.context.annotation.Bean)

Example 4 with Action

use of org.springframework.statemachine.action.Action in project cloudbreak by hortonworks.

the class StackStopActions method stackStopAction.

@Bean(name = "STOP_STATE")
public Action<?, ?> stackStopAction() {
    return new AbstractStackStopAction<>(StackEvent.class) {

        @Override
        protected void doExecute(StackStartStopContext context, StackEvent payload, Map<Object, Object> variables) {
            stackStartStopService.startStackStop(context);
            sendEvent(context);
        }

        @Override
        protected Selectable createRequest(StackStartStopContext context) {
            Stack stack = context.getStack();
            List<CloudInstance> cloudInstances = instanceMetaDataToCloudInstanceConverter.convert(context.getInstanceMetaData(), stack.getEnvironmentCrn(), stack.getStackAuthentication());
            List<CloudResource> cloudResources = stack.getResources().stream().map(s -> resourceToCloudResourceConverter.convert(s)).collect(Collectors.toList());
            cloudInstances.forEach(instance -> stack.getParameters().forEach(instance::putParameter));
            return new StopInstancesRequest(context.getCloudContext(), context.getCloudCredential(), cloudResources, cloudInstances);
        }
    };
}
Also used : Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Action(org.springframework.statemachine.action.Action) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) Payload(com.sequenceiq.cloudbreak.common.event.Payload) AvailabilityZone.availabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone.availabilityZone) LoggerFactory(org.slf4j.LoggerFactory) Location.location(com.sequenceiq.cloudbreak.cloud.model.Location.location) MDCBuilder(com.sequenceiq.cloudbreak.logger.MDCBuilder) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) StackFailureEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent) StopInstancesRequest(com.sequenceiq.cloudbreak.cloud.event.instance.StopInstancesRequest) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) 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) Map(java.util.Map) Location(com.sequenceiq.cloudbreak.cloud.model.Location) InstanceMetaDataService(com.sequenceiq.cloudbreak.service.stack.InstanceMetaDataService) AbstractStackAction(com.sequenceiq.cloudbreak.core.flow2.AbstractStackAction) AbstractStackFailureAction(com.sequenceiq.cloudbreak.core.flow2.stack.AbstractStackFailureAction) Logger(org.slf4j.Logger) StackStartStopContext(com.sequenceiq.cloudbreak.core.flow2.stack.start.StackStartStopContext) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) StackStartStopService(com.sequenceiq.cloudbreak.core.flow2.stack.start.StackStartStopService) StackFailureContext(com.sequenceiq.cloudbreak.core.flow2.stack.StackFailureContext) Region.region(com.sequenceiq.cloudbreak.cloud.model.Region.region) FlowParameters(com.sequenceiq.flow.core.FlowParameters) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Collectors(java.util.stream.Collectors) Configuration(org.springframework.context.annotation.Configuration) List(java.util.List) StackUtil(com.sequenceiq.cloudbreak.util.StackUtil) MetricType(com.sequenceiq.cloudbreak.service.metrics.MetricType) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) StopInstancesResult(com.sequenceiq.cloudbreak.cloud.event.instance.StopInstancesResult) Optional(java.util.Optional) Bean(org.springframework.context.annotation.Bean) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) StackStartStopContext(com.sequenceiq.cloudbreak.core.flow2.stack.start.StackStartStopContext) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) StopInstancesRequest(com.sequenceiq.cloudbreak.cloud.event.instance.StopInstancesRequest) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Map(java.util.Map) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Bean(org.springframework.context.annotation.Bean)

Example 5 with Action

use of org.springframework.statemachine.action.Action in project cloudbreak by hortonworks.

the class StackUpscaleActions method addInstances.

@Bean(name = "ADD_INSTANCES_STATE")
public Action<?, ?> addInstances() {
    return new AbstractStackUpscaleAction<>(UpscaleStackValidationResult.class) {

        @Override
        protected void doExecute(StackScalingFlowContext context, UpscaleStackValidationResult payload, Map<Object, Object> variables) {
            sendEvent(context);
        }

        @Override
        protected Selectable createRequest(StackScalingFlowContext context) {
            Map<String, Integer> hostGroupWithInstanceCountToCreate = getHostGroupsWithInstanceCountToCreate(context);
            Stack updatedStack = instanceMetaDataService.saveInstanceAndGetUpdatedStack(context.getStack(), hostGroupWithInstanceCountToCreate, context.getHostgroupWithHostnames(), true, context.isRepair(), context.getStackNetworkScaleDetails());
            List<CloudResource> resources = context.getStack().getResources().stream().map(r -> cloudResourceConverter.convert(r)).collect(Collectors.toList());
            CloudStack updatedCloudStack = cloudStackConverter.convert(updatedStack);
            AdjustmentTypeWithThreshold adjustmentTypeWithThreshold = context.getAdjustmentTypeWithThreshold();
            if (adjustmentTypeWithThreshold == null) {
                Integer exactNumber = hostGroupWithInstanceCountToCreate.values().stream().reduce(0, Integer::sum);
                adjustmentTypeWithThreshold = new AdjustmentTypeWithThreshold(AdjustmentType.EXACT, exactNumber.longValue());
            }
            LOGGER.info("Adjustment type with threshold for upscale request: {}", adjustmentTypeWithThreshold);
            return new UpscaleStackRequest<UpscaleStackResult>(context.getCloudContext(), context.getCloudCredential(), updatedCloudStack, resources, adjustmentTypeWithThreshold);
        }
    };
}
Also used : Action(org.springframework.statemachine.action.Action) StackScaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackScaleTriggerEvent) LoggerFactory(org.slf4j.LoggerFactory) StackToCloudStackConverter(com.sequenceiq.cloudbreak.converter.spi.StackToCloudStackConverter) EventSelectorUtil(com.sequenceiq.flow.event.EventSelectorUtil) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) InstanceGroupService(com.sequenceiq.cloudbreak.service.stack.InstanceGroupService) InstanceMetaDataToCloudInstanceConverter(com.sequenceiq.cloudbreak.converter.spi.InstanceMetaDataToCloudInstanceConverter) Map(java.util.Map) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) StackScalingFlowContext(com.sequenceiq.cloudbreak.core.flow2.stack.downscale.StackScalingFlowContext) BootstrapNewNodesResult(com.sequenceiq.cloudbreak.reactor.api.event.resource.BootstrapNewNodesResult) UpscaleStackRequest(com.sequenceiq.cloudbreak.reactor.api.event.stack.UpscaleStackRequest) AbstractStackFailureAction(com.sequenceiq.cloudbreak.core.flow2.stack.AbstractStackFailureAction) UpscaleStackValidationRequest(com.sequenceiq.cloudbreak.cloud.event.resource.UpscaleStackValidationRequest) Collection(java.util.Collection) StackFailureContext(com.sequenceiq.cloudbreak.core.flow2.stack.StackFailureContext) Set(java.util.Set) HOST_GROUP_WITH_HOSTNAMES(com.sequenceiq.cloudbreak.core.flow2.stack.upscale.AbstractStackUpscaleAction.HOST_GROUP_WITH_HOSTNAMES) Collectors(java.util.stream.Collectors) UpscaleStackValidationResult(com.sequenceiq.cloudbreak.cloud.event.resource.UpscaleStackValidationResult) Configuration(org.springframework.context.annotation.Configuration) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) AdjustmentType(com.sequenceiq.common.api.type.AdjustmentType) List(java.util.List) UpdateDomainDnsResolverResult(com.sequenceiq.cloudbreak.reactor.api.event.stack.UpdateDomainDnsResolverResult) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) ExtendHostMetadataRequest(com.sequenceiq.cloudbreak.reactor.api.event.resource.ExtendHostMetadataRequest) Optional(java.util.Optional) StackCreationEvent(com.sequenceiq.cloudbreak.core.flow2.stack.provision.StackCreationEvent) BootstrapNewNodesRequest(com.sequenceiq.cloudbreak.reactor.api.event.resource.BootstrapNewNodesRequest) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) HashMap(java.util.HashMap) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) StackFailureEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent) ClusterPublicEndpointManagementService(com.sequenceiq.cloudbreak.service.publicendpoint.ClusterPublicEndpointManagementService) HOST_GROUP_WITH_ADJUSTMENT(com.sequenceiq.cloudbreak.core.flow2.stack.upscale.AbstractStackUpscaleAction.HOST_GROUP_WITH_ADJUSTMENT) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) CleanupFreeIpaEvent(com.sequenceiq.cloudbreak.reactor.api.event.stack.CleanupFreeIpaEvent) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ResourceToCloudResourceConverter(com.sequenceiq.cloudbreak.converter.spi.ResourceToCloudResourceConverter) ExtendHostMetadataResult(com.sequenceiq.cloudbreak.reactor.api.event.resource.ExtendHostMetadataResult) UpscaleStackResult(com.sequenceiq.cloudbreak.reactor.api.event.stack.UpscaleStackResult) InstanceMetaDataService(com.sequenceiq.cloudbreak.service.stack.InstanceMetaDataService) GetSSHFingerprintsResult(com.sequenceiq.cloudbreak.cloud.event.instance.GetSSHFingerprintsResult) UpdateDomainDnsResolverRequest(com.sequenceiq.cloudbreak.reactor.api.event.stack.UpdateDomainDnsResolverRequest) Logger(org.slf4j.Logger) GetSSHFingerprintsRequest(com.sequenceiq.cloudbreak.cloud.event.instance.GetSSHFingerprintsRequest) CollectMetadataResult(com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataResult) CollectMetadataRequest(com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataRequest) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) AdjustmentTypeWithThreshold(com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold) EnvironmentClientService(com.sequenceiq.cloudbreak.service.environment.EnvironmentClientService) ClusterProxyEnablementService(com.sequenceiq.cloudbreak.clusterproxy.ClusterProxyEnablementService) ClusterProxyReRegistrationRequest(com.sequenceiq.cloudbreak.reactor.api.event.orchestration.ClusterProxyReRegistrationRequest) InstanceGroupType(com.sequenceiq.common.api.type.InstanceGroupType) InstanceStatus(com.sequenceiq.cloudbreak.cloud.model.InstanceStatus) MetricType(com.sequenceiq.cloudbreak.service.metrics.MetricType) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) Bean(org.springframework.context.annotation.Bean) AdjustmentTypeWithThreshold(com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) StackScalingFlowContext(com.sequenceiq.cloudbreak.core.flow2.stack.downscale.StackScalingFlowContext) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) UpscaleStackRequest(com.sequenceiq.cloudbreak.reactor.api.event.stack.UpscaleStackRequest) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) UpscaleStackValidationResult(com.sequenceiq.cloudbreak.cloud.event.resource.UpscaleStackValidationResult) Map(java.util.Map) HashMap(java.util.HashMap) Bean(org.springframework.context.annotation.Bean)

Aggregations

List (java.util.List)25 Collectors (java.util.stream.Collectors)25 Action (org.springframework.statemachine.action.Action)25 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)23 Map (java.util.Map)23 Inject (javax.inject.Inject)23 Bean (org.springframework.context.annotation.Bean)23 Configuration (org.springframework.context.annotation.Configuration)23 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)20 Logger (org.slf4j.Logger)20 LoggerFactory (org.slf4j.LoggerFactory)20 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)19 FlowParameters (com.sequenceiq.flow.core.FlowParameters)18 StateContext (org.springframework.statemachine.StateContext)16 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)15 Set (java.util.Set)15 Collections (java.util.Collections)14 Optional (java.util.Optional)14 InstanceMetaDataToCloudInstanceConverter (com.sequenceiq.cloudbreak.converter.spi.InstanceMetaDataToCloudInstanceConverter)13 AbstractStackFailureAction (com.sequenceiq.cloudbreak.core.flow2.stack.AbstractStackFailureAction)13