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());
}
}
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);
}
};
}
Aggregations