Search in sources :

Example 46 with StackEvent

use of com.sequenceiq.freeipa.flow.stack.StackEvent in project cloudbreak by hortonworks.

the class StackProvisionActions method createCredentialAction.

@Bean(name = "CREATE_CREDENTIAL_STATE")
public Action<?, ?> createCredentialAction() {
    return new AbstractStackProvisionAction<>(StackEvent.class) {

        @Override
        protected void doExecute(StackContext context, StackEvent payload, Map<Object, Object> variables) {
            variables.put(START_DATE, new Date());
            stackProvisionService.startProvisioning(context);
            sendEvent(context);
        }

        @Override
        protected Selectable createRequest(StackContext context) {
            return new CreateCredentialRequest(context.getCloudContext(), context.getCloudCredential(), context.getCloudStack());
        }
    };
}
Also used : CreateCredentialRequest(com.sequenceiq.cloudbreak.cloud.event.resource.CreateCredentialRequest) StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) StackContext(com.sequenceiq.freeipa.flow.stack.StackContext) Map(java.util.Map) Date(java.util.Date) Bean(org.springframework.context.annotation.Bean)

Example 47 with StackEvent

use of com.sequenceiq.freeipa.flow.stack.StackEvent in project cloudbreak by hortonworks.

the class StackStartActions method stackStartAction.

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

        @Value("${freeipa.delayed.stop-start-sec}")
        private long delayInSec;

        @Inject
        private EntitlementService entitlementService;

        @Override
        protected void doExecute(StackStartContext context, StackEvent payload, Map<Object, Object> variables) {
            stackStartService.startStack(context.getStack());
            sendEvent(context);
        }

        @Override
        protected Selectable createRequest(StackStartContext context) {
            Stack stack = context.getStack();
            LOGGER.debug("Assembling start request for stack: {}", stack);
            List<CloudInstance> cloudInstances = stack.getNotDeletedInstanceMetaDataSet().stream().sorted(new PrimaryGatewayFirstThenSortByFqdnComparator()).map(i -> metadataConverter.convert(i)).collect(Collectors.toList());
            List<CloudResource> cloudResources = getCloudResources(stack.getId());
            if (entitlementService.isFmsDelayedStopStartEnabled(context.getStack().getAccountId())) {
                return new DelayedStartInstancesRequest(context.getCloudContext(), context.getCloudCredential(), cloudResources, cloudInstances, delayInSec);
            } else {
                return new StartInstancesRequest(context.getCloudContext(), context.getCloudCredential(), cloudResources, cloudInstances);
            }
        }
    };
}
Also used : EntitlementService(com.sequenceiq.cloudbreak.auth.altus.EntitlementService) Action(org.springframework.statemachine.action.Action) InstanceMetaDataToCloudInstanceConverter(com.sequenceiq.freeipa.converter.cloud.InstanceMetaDataToCloudInstanceConverter) EntitlementService(com.sequenceiq.cloudbreak.auth.altus.EntitlementService) LoggerFactory(org.slf4j.LoggerFactory) DelayedStartInstancesRequest(com.sequenceiq.cloudbreak.cloud.event.instance.DelayedStartInstancesRequest) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) ResourceToCloudResourceConverter(com.sequenceiq.freeipa.converter.cloud.ResourceToCloudResourceConverter) AbstractStackFailureAction(com.sequenceiq.freeipa.flow.stack.AbstractStackFailureAction) Inject(javax.inject.Inject) Value(org.springframework.beans.factory.annotation.Value) HealthCheckRequest(com.sequenceiq.freeipa.flow.stack.HealthCheckRequest) ResourceService(com.sequenceiq.freeipa.service.resource.ResourceService) Map(java.util.Map) Resource(com.sequenceiq.freeipa.entity.Resource) StartInstancesRequest(com.sequenceiq.cloudbreak.cloud.event.instance.StartInstancesRequest) StartInstancesResult(com.sequenceiq.cloudbreak.cloud.event.instance.StartInstancesResult) StackStartEvent(com.sequenceiq.freeipa.flow.stack.start.StackStartEvent) Stack(com.sequenceiq.freeipa.entity.Stack) StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) StackFailureEvent(com.sequenceiq.freeipa.flow.stack.StackFailureEvent) StackStartState(com.sequenceiq.freeipa.flow.stack.start.StackStartState) Logger(org.slf4j.Logger) CollectMetadataResult(com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataResult) StackStartService(com.sequenceiq.freeipa.flow.stack.start.StackStartService) CollectMetadataRequest(com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataRequest) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) StackStartContext(com.sequenceiq.freeipa.flow.stack.start.StackStartContext) Collectors(java.util.stream.Collectors) HealthCheckSuccess(com.sequenceiq.freeipa.flow.stack.HealthCheckSuccess) PrimaryGatewayFirstThenSortByFqdnComparator(com.sequenceiq.freeipa.service.freeipa.PrimaryGatewayFirstThenSortByFqdnComparator) Configuration(org.springframework.context.annotation.Configuration) List(java.util.List) StackToCloudStackConverter(com.sequenceiq.freeipa.converter.cloud.StackToCloudStackConverter) StackFailureContext(com.sequenceiq.freeipa.flow.stack.StackFailureContext) Bean(org.springframework.context.annotation.Bean) StackStartContext(com.sequenceiq.freeipa.flow.stack.start.StackStartContext) DelayedStartInstancesRequest(com.sequenceiq.cloudbreak.cloud.event.instance.DelayedStartInstancesRequest) StartInstancesRequest(com.sequenceiq.cloudbreak.cloud.event.instance.StartInstancesRequest) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) DelayedStartInstancesRequest(com.sequenceiq.cloudbreak.cloud.event.instance.DelayedStartInstancesRequest) PrimaryGatewayFirstThenSortByFqdnComparator(com.sequenceiq.freeipa.service.freeipa.PrimaryGatewayFirstThenSortByFqdnComparator) Stack(com.sequenceiq.freeipa.entity.Stack) StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 48 with StackEvent

use of com.sequenceiq.freeipa.flow.stack.StackEvent in project cloudbreak by hortonworks.

the class UpgradeCcmActions method failed.

@Bean(name = UPGRADE_CCM_FAILED_STATE_NAME)
public Action<?, ?> failed() {
    return new AbstractUpgradeCcmAction<>(UpgradeCcmFailureEvent.class) {

        @Override
        protected UpgradeCcmContext createFlowContext(FlowParameters flowParameters, StateContext<UpgradeCcmState, UpgradeCcmStateSelector> stateContext, UpgradeCcmFailureEvent payload) {
            Flow flow = getFlow(flowParameters.getFlowId());
            flow.setFlowFailed(payload.getException());
            return super.createFlowContext(flowParameters, stateContext, payload);
        }

        @Override
        protected void doExecute(UpgradeCcmContext context, UpgradeCcmFailureEvent payload, Map<Object, Object> variables) {
            LOGGER.info("FreeIPA CCM upgrade failed {}", payload);
            upgradeCcmService.failedState(context, payload);
            failOperation(context.getStack().getAccountId(), payload.getException().getMessage(), variables);
            sendEvent(context, UPGRADE_CCM_FAILURE_HANDLED_EVENT.event(), new StackEvent(context.getStack().getId()));
        }
    };
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) StateContext(org.springframework.statemachine.StateContext) Map(java.util.Map) UpgradeCcmFailureEvent(com.sequenceiq.freeipa.flow.stack.upgrade.ccm.event.UpgradeCcmFailureEvent) Flow(com.sequenceiq.flow.core.Flow) Bean(org.springframework.context.annotation.Bean)

Example 49 with StackEvent

use of com.sequenceiq.freeipa.flow.stack.StackEvent in project cloudbreak by hortonworks.

the class UserDataUpdateFailureHandlerAction method doExecute.

@Override
protected void doExecute(StackFailureContext context, StackFailureEvent payload, Map<Object, Object> variables) throws Exception {
    LOGGER.error("UserData change failed", payload.getException());
    if (isOperationIdSet(variables)) {
        operationService.failOperation(context.getStack().getAccountId(), getOperationId(variables), payload.getException().getMessage());
    }
    sendEvent(context, new StackEvent(UPDATE_USERDATA_FAILURE_HANDLED_EVENT.event(), context.getStack().getId()));
}
Also used : StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent)

Example 50 with StackEvent

use of com.sequenceiq.freeipa.flow.stack.StackEvent in project cloudbreak by hortonworks.

the class ImageChangeFailureHandlerAction method doExecute.

@Override
protected void doExecute(StackFailureContext context, StackFailureEvent payload, Map<Object, Object> variables) throws Exception {
    LOGGER.error("Image change failed", payload.getException());
    if (variables.containsKey(ImageChangeActions.ORIGINAL_IMAGE_REVISION) && variables.containsKey(ImageChangeActions.IMAGE_CHANGED_IN_DB)) {
        LOGGER.info("Reverting to original image using revision [{}]", variables.get(ImageChangeActions.ORIGINAL_IMAGE_REVISION));
        imageService.revertImageToRevision((Long) variables.get(ImageChangeActions.IMAGE_ENTITY_ID), (Number) variables.get(ImageChangeActions.ORIGINAL_IMAGE_REVISION));
    } else if (variables.containsKey(ImageChangeActions.ORIGINAL_IMAGE) && variables.containsKey(ImageChangeActions.IMAGE_CHANGED_IN_DB)) {
        LOGGER.info("Reverting to original image using entity stored in variables");
        ImageEntity originalImage = (ImageEntity) variables.get(ImageChangeActions.ORIGINAL_IMAGE);
        imageService.save(originalImage);
    }
    if (isOperationIdSet(variables)) {
        operationService.failOperation(context.getStack().getAccountId(), getOperationId(variables), payload.getException().getMessage());
    }
    sendEvent(context, new StackEvent(IMAGE_CHANGE_FAILURE_HANDLED_EVENT.event(), context.getStack().getId()));
}
Also used : StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) ImageEntity(com.sequenceiq.freeipa.entity.ImageEntity)

Aggregations

StackEvent (com.sequenceiq.freeipa.flow.stack.StackEvent)54 Map (java.util.Map)40 Bean (org.springframework.context.annotation.Bean)40 Stack (com.sequenceiq.freeipa.entity.Stack)38 StackContext (com.sequenceiq.freeipa.flow.stack.StackContext)28 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)17 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)12 InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)11 OperationService (com.sequenceiq.freeipa.service.operation.OperationService)11 SuccessDetails (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails)10 ClientErrorException (javax.ws.rs.ClientErrorException)10 EnvironmentEndpoint (com.sequenceiq.environment.api.v1.environment.endpoint.EnvironmentEndpoint)9 Flow (com.sequenceiq.flow.core.Flow)9 FlowParameters (com.sequenceiq.flow.core.FlowParameters)8 List (java.util.List)8 Collectors (java.util.stream.Collectors)8 Inject (javax.inject.Inject)8 Logger (org.slf4j.Logger)8 LoggerFactory (org.slf4j.LoggerFactory)8 Configuration (org.springframework.context.annotation.Configuration)8