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