Search in sources :

Example 1 with TerminationType

use of com.sequenceiq.cloudbreak.reactor.api.event.stack.TerminationType in project cloudbreak by hortonworks.

the class StackTerminationFailureAction method doExecute.

@Override
protected void doExecute(StackFailureContext context, StackFailureEvent payload, Map<Object, Object> variables) {
    TerminationType terminationType = (TerminationType) variables.getOrDefault(TERMINATION_TYPE, TerminationType.REGULAR);
    boolean forced = terminationType.isForced();
    boolean recovery = terminationType.isRecovery();
    Exception payloadException = payload.getException();
    StackView stackView = context.getStackView();
    try {
        if (recovery) {
            recoveryTeardownService.handleRecoveryTeardownError(stackView, payloadException);
        } else {
            stackTerminationService.handleStackTerminationError(stackView, payloadException, forced);
        }
    } catch (Exception e) {
        LOGGER.error("Exception occurred while Cloudbreak tried to handle stack {} termination.", terminationType.name(), e);
    }
    sendEvent(context);
}
Also used : TerminationType(com.sequenceiq.cloudbreak.reactor.api.event.stack.TerminationType) StackView(com.sequenceiq.cloudbreak.domain.view.StackView)

Example 2 with TerminationType

use of com.sequenceiq.cloudbreak.reactor.api.event.stack.TerminationType in project cloudbreak by hortonworks.

the class AbstractStackTerminationAction method createFlowContext.

@Override
protected StackTerminationContext createFlowContext(FlowParameters flowParameters, StateContext<StackTerminationState, StackTerminationEvent> stateContext, P payload) {
    Map<Object, Object> variables = stateContext.getExtendedState().getVariables();
    TerminationType terminationType = (TerminationType) variables.getOrDefault(TERMINATION_TYPE, TerminationType.REGULAR);
    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()).withOriginalName(stack.getOriginalName()).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);
    CloudStack cloudStack = cloudStackConverter.convert(stack);
    List<CloudResource> resources = stack.getResources().stream().map(r -> cloudResourceConverter.convert(r)).collect(Collectors.toList());
    return createStackTerminationContext(flowParameters, stack, cloudContext, cloudCredential, cloudStack, resources, terminationType);
}
Also used : Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) Payload(com.sequenceiq.cloudbreak.common.event.Payload) 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) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ResourceToCloudResourceConverter(com.sequenceiq.cloudbreak.converter.spi.ResourceToCloudResourceConverter) ResourceService(com.sequenceiq.cloudbreak.service.resource.ResourceService) StateContext(org.springframework.statemachine.StateContext) Map(java.util.Map) Location(com.sequenceiq.cloudbreak.cloud.model.Location) AbstractStackAction(com.sequenceiq.cloudbreak.core.flow2.AbstractStackAction) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) 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) TerminationType(com.sequenceiq.cloudbreak.reactor.api.event.stack.TerminationType) Collectors(java.util.stream.Collectors) 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) TerminationType(com.sequenceiq.cloudbreak.reactor.api.event.stack.TerminationType) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Location(com.sequenceiq.cloudbreak.cloud.model.Location)

Aggregations

TerminationType (com.sequenceiq.cloudbreak.reactor.api.event.stack.TerminationType)2 Crn (com.sequenceiq.cloudbreak.auth.crn.Crn)1 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)1 AvailabilityZone.availabilityZone (com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone.availabilityZone)1 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)1 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)1 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)1 Location (com.sequenceiq.cloudbreak.cloud.model.Location)1 Location.location (com.sequenceiq.cloudbreak.cloud.model.Location.location)1 Region.region (com.sequenceiq.cloudbreak.cloud.model.Region.region)1 Payload (com.sequenceiq.cloudbreak.common.event.Payload)1 ResourceToCloudResourceConverter (com.sequenceiq.cloudbreak.converter.spi.ResourceToCloudResourceConverter)1 StackToCloudStackConverter (com.sequenceiq.cloudbreak.converter.spi.StackToCloudStackConverter)1 AbstractStackAction (com.sequenceiq.cloudbreak.core.flow2.AbstractStackAction)1 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)1 StackView (com.sequenceiq.cloudbreak.domain.view.StackView)1 MDCBuilder (com.sequenceiq.cloudbreak.logger.MDCBuilder)1 ResourceService (com.sequenceiq.cloudbreak.service.resource.ResourceService)1 StackService (com.sequenceiq.cloudbreak.service.stack.StackService)1 StackUtil (com.sequenceiq.cloudbreak.util.StackUtil)1