use of com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder in project cloudbreak by hortonworks.
the class SdxService method validateBaseLocation.
ValidationResult validateBaseLocation(String baseLocation) {
ValidationResultBuilder resultBuilder = new ValidationResultBuilder();
if (baseLocation != null) {
Pattern pattern = Pattern.compile("\\s");
Matcher matcher = pattern.matcher(baseLocation.trim());
if (matcher.find()) {
resultBuilder.error("You have added some whitespace to the base location: " + baseLocation);
}
} else {
LOGGER.debug("Cannot validate the base location, because it's null");
}
return resultBuilder.build();
}
use of com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder in project cloudbreak by hortonworks.
the class StackRequestManifester method validateCloudStorageLocation.
private void validateCloudStorageLocation(SdxCluster sdxCluster, DetailedEnvironmentResponse environment) {
if (FileSystemType.S3.equals(sdxCluster.getCloudStorageFileSystemType()) && !Strings.isNullOrEmpty(sdxCluster.getCloudStorageBaseLocation())) {
ValidationResultBuilder validationBuilder = new ValidationResultBuilder();
cloudStorageLocationValidator.validate(sdxCluster.getCloudStorageBaseLocation(), FileSystemType.S3, environment, validationBuilder);
ValidationResult validationResult = validationBuilder.build();
if (validationResult.hasError()) {
throw new BadRequestException(validationResult.getFormattedErrors());
}
}
}
use of com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder in project cloudbreak by hortonworks.
the class StackRequestManifester method validateCloudStorageAndHandleTimeout.
private void validateCloudStorageAndHandleTimeout(SdxCluster sdxCluster, DetailedEnvironmentResponse environment, StackV4Request stackRequest) {
ValidationResultBuilder validationResultBuilder = new ValidationResultBuilder();
try {
cloudStorageValidator.validate(stackRequest.getCluster().getCloudStorage(), environment, validationResultBuilder);
} catch (Exception e) {
String message = String.format("Error occured during object storage validation, validation skipped. Error: %s", e.getMessage());
LOGGER.warn(message);
sdxNotificationService.send(ResourceEvent.SDX_VALIDATION_FAILED_AND_SKIPPED, Set.of(e.getMessage()), sdxCluster);
}
ValidationResult validationResult = validationResultBuilder.build();
if (validationResult.hasError()) {
throw new BadRequestException(validationResult.getFormattedErrors());
}
if (validationResult.hasWarning()) {
LOGGER.info(validationResult.getFormattedWarnings());
eventSenderService.sendEventAndNotification(sdxCluster, sdxCluster.getInitiatorUserCrn(), ResourceEvent.SDX_VALIDATION_FAILED_AND_SKIPPED, Set.of(validationResult.getFormattedWarnings()));
sdxNotificationService.send(ResourceEvent.SDX_VALIDATION_FAILED_AND_SKIPPED, Set.of(validationResult.getFormattedWarnings()), sdxCluster);
}
}
use of com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder in project cloudbreak by hortonworks.
the class AwsIamServiceTest method missingInstanceProfile.
@Test
public void missingInstanceProfile() {
when(iam.getInstanceProfile(any(GetInstanceProfileRequest.class))).thenThrow(NoSuchEntityException.class);
String instanceProfileArn = "account/missingInstanceProfile";
ValidationResultBuilder validationRequestBuilder = new ValidationResultBuilder();
InstanceProfile instanceProfile = awsIamService.getInstanceProfile(iam, instanceProfileArn, CloudIdentityType.ID_BROKER, validationRequestBuilder);
assertThat(instanceProfile).isNull();
ValidationResult validationResult = validationRequestBuilder.build();
assertThat(validationResult.hasError()).isTrue();
assertThat(validationResult.getErrors()).isEqualTo(Collections.singletonList(String.format("Instance profile (%s) doesn't exists on AWS side. " + "Please check if you've used the correct Instance profile when setting up Data Access.", instanceProfileArn)));
}
use of com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder in project cloudbreak by hortonworks.
the class AwsIamServiceTest method validRole.
@Test
public void validRole() {
String roleArn = "account/validRole";
Role expectedRole = new Role().withArn(roleArn);
GetRoleResult getRoleResult = mock(GetRoleResult.class);
when(getRoleResult.getRole()).thenReturn(expectedRole);
when(iam.getRole(any(GetRoleRequest.class))).thenReturn(getRoleResult);
ValidationResultBuilder validationRequestBuilder = new ValidationResultBuilder();
Role role = awsIamService.getRole(iam, roleArn, validationRequestBuilder);
assertThat(role.getArn()).isEqualTo(roleArn);
assertThat(validationRequestBuilder.build().hasError()).isFalse();
}
Aggregations