Search in sources :

Example 1 with ValidateCloudConfigRequest

use of com.sequenceiq.cloudbreak.core.flow2.validate.cloud.event.ValidateCloudConfigRequest in project cloudbreak by hortonworks.

the class ValidateCloudConfigHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<ValidateCloudConfigRequest> event) {
    ValidateCloudConfigRequest data = event.getData();
    Stack stack = stackService.getByIdWithLists(data.getResourceId());
    String name = stack.getName();
    DetailedEnvironmentResponse environment = environmentClientService.getByCrn(stack.getEnvironmentCrn());
    Credential credential = credentialConverter.convert(environment.getCredential());
    CloudCredential cloudCredential = credentialToCloudCredentialConverter.convert(credential);
    ValidationResult.ValidationResultBuilder validationBuilder = ValidationResult.builder();
    stackValidator.validate(stack, validationBuilder);
    Set<InstanceGroup> instanceGroups = stack.getInstanceGroups();
    measure(() -> {
        for (InstanceGroup instanceGroup : instanceGroups) {
            LOGGER.info("Validate template for {} name with {} instanceGroup.", name, instanceGroup.toString());
            StackType type = stack.getType();
            templateValidator.validate(credential, instanceGroup, stack, fromStackType(type == null ? null : type.name()), Optional.of(stack.getCreator()), validationBuilder);
        }
    }, LOGGER, "Stack's instance templates have been validated in {} ms for stack {}", name);
    multiAzValidator.validateMultiAzForStack(stack.getPlatformVariant(), instanceGroups, validationBuilder);
    ParametersValidationRequest parametersValidationRequest = parametersValidator.validate(stack.getCloudPlatform(), cloudCredential, stack.getParameters(), stack.getWorkspace().getId());
    parametersValidator.waitResult(parametersValidationRequest, validationBuilder);
    if (!StackType.LEGACY.equals(stack.getType())) {
        dataLakeValidator.validate(stack, validationBuilder);
    }
    environmentValidator.validate(stack, environment, stack.getType().equals(StackType.WORKLOAD), validationBuilder);
    ValidationResult validationResult = validationBuilder.build();
    if (validationResult.getState() == ValidationResult.State.ERROR || validationResult.hasError()) {
        LOGGER.debug("Stack request has validation error(s): {}.", validationResult.getFormattedErrors());
        throw new IllegalStateException(validationResult.getFormattedErrors());
    } else {
        LOGGER.debug("Stack validation has been finished without any error.");
        return new StackEvent(CloudConfigValidationEvent.VALIDATE_CLOUD_CONFIG_FINISHED_EVENT.selector(), data.getResourceId());
    }
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Credential(com.sequenceiq.cloudbreak.dto.credential.Credential) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) ParametersValidationRequest(com.sequenceiq.cloudbreak.cloud.event.validation.ParametersValidationRequest) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) StackType(com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType) CdpResourceType.fromStackType(com.sequenceiq.common.api.type.CdpResourceType.fromStackType) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) ValidateCloudConfigRequest(com.sequenceiq.cloudbreak.core.flow2.validate.cloud.event.ValidateCloudConfigRequest) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)

Example 2 with ValidateCloudConfigRequest

use of com.sequenceiq.cloudbreak.core.flow2.validate.cloud.event.ValidateCloudConfigRequest in project cloudbreak by hortonworks.

the class CloudConfigValidationActions method cloudConfigValidationAction.

@Bean(name = "VALIDATE_CLOUD_CONFIG_STATE")
public Action<?, ?> cloudConfigValidationAction() {
    return new AbstractStackCreationAction<>(StackEvent.class) {

        @Override
        protected void doExecute(StackCreationContext context, StackEvent payload, Map<Object, Object> variables) throws Exception {
            ValidateCloudConfigRequest request = new ValidateCloudConfigRequest(payload.getResourceId());
            sendEvent(context, request.selector(), request);
        }

        @Override
        protected Object getFailurePayload(StackEvent payload, Optional<StackCreationContext> flowContext, Exception ex) {
            return new StackFailureEvent(CloudConfigValidationEvent.VALIDATE_CLOUD_CONFIG_FAILED_EVENT.selector(), payload.getResourceId(), ex);
        }
    };
}
Also used : StackCreationContext(com.sequenceiq.cloudbreak.core.flow2.stack.start.StackCreationContext) AbstractStackCreationAction(com.sequenceiq.cloudbreak.core.flow2.stack.provision.action.AbstractStackCreationAction) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) Optional(java.util.Optional) ValidateCloudConfigRequest(com.sequenceiq.cloudbreak.core.flow2.validate.cloud.event.ValidateCloudConfigRequest) StackFailureEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Aggregations

ValidateCloudConfigRequest (com.sequenceiq.cloudbreak.core.flow2.validate.cloud.event.ValidateCloudConfigRequest)2 StackEvent (com.sequenceiq.cloudbreak.reactor.api.event.StackEvent)2 StackType (com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType)1 ParametersValidationRequest (com.sequenceiq.cloudbreak.cloud.event.validation.ParametersValidationRequest)1 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)1 AbstractStackCreationAction (com.sequenceiq.cloudbreak.core.flow2.stack.provision.action.AbstractStackCreationAction)1 StackCreationContext (com.sequenceiq.cloudbreak.core.flow2.stack.start.StackCreationContext)1 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)1 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)1 Credential (com.sequenceiq.cloudbreak.dto.credential.Credential)1 StackFailureEvent (com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent)1 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)1 CdpResourceType.fromStackType (com.sequenceiq.common.api.type.CdpResourceType.fromStackType)1 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Bean (org.springframework.context.annotation.Bean)1