Search in sources :

Example 1 with ParametersValidationRequest

use of com.sequenceiq.cloudbreak.cloud.event.validation.ParametersValidationRequest 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 ParametersValidationRequest

use of com.sequenceiq.cloudbreak.cloud.event.validation.ParametersValidationRequest in project cloudbreak by hortonworks.

the class ParametersValidationHandler method accept.

@Override
public void accept(Event<ParametersValidationRequest> requestEvent) {
    LOGGER.debug("Received event: {}", requestEvent);
    ParametersValidationRequest request = requestEvent.getData();
    try {
        CloudConnector<Object> connector = cloudPlatformConnectors.get(request.getCloudContext().getPlatformVariant());
        AuthenticatedContext auth = connector.authentication().authenticate(request.getCloudContext(), request.getCloudCredential());
        connector.setup().validateParameters(auth, request.getParameters());
        request.getResult().onNext(new ParametersValidationResult(request.getResourceId()));
    } catch (Exception e) {
        request.getResult().onNext(new ParametersValidationResult(e.getMessage(), e, request.getResourceId()));
    }
}
Also used : ParametersValidationRequest(com.sequenceiq.cloudbreak.cloud.event.validation.ParametersValidationRequest) ParametersValidationResult(com.sequenceiq.cloudbreak.cloud.event.validation.ParametersValidationResult) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)

Example 3 with ParametersValidationRequest

use of com.sequenceiq.cloudbreak.cloud.event.validation.ParametersValidationRequest in project cloudbreak by hortonworks.

the class ParametersValidator method validate.

public ParametersValidationRequest validate(String platform, CloudCredential cloudCredential, Map<String, String> parameters, Long workspaceId) {
    if (parameters == null || parameters.isEmpty()) {
        return null;
    }
    LOGGER.info("Validate the parameters: {}", parameters);
    CloudContext cloudContext = CloudContext.Builder.builder().withPlatform(platform).withWorkspaceId(workspaceId).build();
    ParametersValidationRequest request = new ParametersValidationRequest(cloudCredential, cloudContext, parameters);
    eventBus.notify(request.selector(), eventFactory.createEvent(request));
    return request;
}
Also used : ParametersValidationRequest(com.sequenceiq.cloudbreak.cloud.event.validation.ParametersValidationRequest) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext)

Aggregations

ParametersValidationRequest (com.sequenceiq.cloudbreak.cloud.event.validation.ParametersValidationRequest)3 StackType (com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType)1 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)1 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)1 ParametersValidationResult (com.sequenceiq.cloudbreak.cloud.event.validation.ParametersValidationResult)1 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)1 ValidateCloudConfigRequest (com.sequenceiq.cloudbreak.core.flow2.validate.cloud.event.ValidateCloudConfigRequest)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 StackEvent (com.sequenceiq.cloudbreak.reactor.api.event.StackEvent)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