use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.
the class StackToCreateFreeIpaRequestConverter method getBackupLocation.
String getBackupLocation(Stack stack, String location) {
String originalLocation = getLocation(location, CLUSTER_BACKUP_PREFIX);
// Example: convert https://storage1.dfs.core.windows.net/logs-fs into abfs://logs-fs@storage1.dfs.core.windows.net
try {
if (CloudPlatform.AZURE.equalsIgnoreCase(stack.getCloudPlatform()) && originalLocation != null) {
URI uri = new URI(originalLocation);
if (AZURE_BLOB_STORAGE_SCHEMA.equals(uri.getScheme())) {
String uriPath = uri.getPath();
int firstSeparator = uriPath.indexOf(PATH_DELIMETER);
if (firstSeparator != -1) {
int secondSeparator = uriPath.indexOf(PATH_DELIMETER, firstSeparator + 1);
String bucketName;
String bucketPath = "";
if (secondSeparator == -1) {
bucketName = uriPath.substring(firstSeparator + 1);
} else {
bucketName = uriPath.substring(firstSeparator + 1, secondSeparator);
bucketPath = uriPath.substring(secondSeparator);
}
originalLocation = String.format("%s%s@%s%s", ORIGINAL_AZURE_BLOB_STORAGE_SCHEMA, bucketName, uri.getHost(), bucketPath);
}
}
}
} catch (URISyntaxException e) {
String error = String.format("Unable to parse URI for backup location %s", originalLocation);
LOGGER.error(error);
throw new BadRequestException(error, e);
}
LOGGER.debug("Created backup location {} location {}", originalLocation, location);
return originalLocation;
}
use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.
the class CreateFreeIpaRequestToStackConverter method getRegion.
private String getRegion(CreateFreeIpaRequest source, String cloudPlatform) {
if (source.getPlacement() == null) {
return null;
}
if (isEmpty(source.getPlacement().getRegion())) {
Map<Platform, Region> regions = Maps.newHashMap();
if (isNotEmpty(defaultRegions)) {
for (String entry : defaultRegions.split(",")) {
String[] keyValue = entry.split(":");
regions.put(platform(keyValue[0]), Region.region(keyValue[1]));
}
Region platformRegion = regions.get(platform(cloudPlatform));
if (platformRegion == null || isEmpty(platformRegion.value())) {
throw new BadRequestException(String.format("No default region specified for: %s. Region cannot be empty.", cloudPlatform));
}
return platformRegion.value();
} else {
throw new BadRequestException("No default region is specified. Region cannot be empty.");
}
}
return source.getPlacement().getRegion();
}
use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.
the class FreeIpaV1Controller method create.
@Override
@CheckPermissionByRequestProperty(path = "environmentCrn", type = CRN, action = EDIT_ENVIRONMENT)
public DescribeFreeIpaResponse create(@RequestObject @Valid CreateFreeIpaRequest request) {
ValidationResult validationResult = createFreeIpaRequestValidator.validate(request);
if (validationResult.getState() == State.ERROR) {
LOGGER.debug("FreeIPA request has validation error(s): {}.", validationResult.getFormattedErrors());
throw new BadRequestException(validationResult.getFormattedErrors());
}
String accountId = crnService.getCurrentAccountId();
return freeIpaCreationService.launchFreeIpa(request, accountId);
}
use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.
the class StackV4RequestToStackConverterTest method testWhenRegionIsEmptyButDefaultRegionsAreEmptyThenBadRequestExceptionComes.
@Test
public void testWhenRegionIsEmptyButDefaultRegionsAreEmptyThenBadRequestExceptionComes() {
setDefaultRegions(null);
StackV4Request request = getRequest("stack.json");
request.setCloudPlatform(MOCK);
request.getPlacement().setRegion(null);
BadRequestException resultException = assertThrows(BadRequestException.class, () -> underTest.convert(request));
assertEquals("No default region is specified. Region cannot be empty.", resultException.getMessage());
}
use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.
the class StackCreatorServiceRecipeValidationTest method testIfMultipleRecipesDoesNotExistsWhichHasGivenInOneOfTheHostgroupsThenBadRequestExceptionShouldCome.
@Test
void testIfMultipleRecipesDoesNotExistsWhichHasGivenInOneOfTheHostgroupsThenBadRequestExceptionShouldCome() {
String notExistingRecipeName = "someNotExistingRecipe";
String someOtherNotExistingRecipeName = "someOtherNotExistingRecipe";
StackV4Request request = new StackV4Request();
request.setInstanceGroups(List.of(getInstanceGroupWithRecipe(INSTANCE_GROUP_MASTER, Set.of(notExistingRecipeName, someOtherNotExistingRecipeName))));
when(recipeService.get(any(NameOrCrn.class), eq(WORKSPACE_ID))).thenThrow(new NotFoundException("Recipe not found"));
BadRequestException exception = Assertions.assertThrows(BadRequestException.class, () -> underTest.createStack(user, workspace, request, false));
Assert.assertNotNull(exception);
Assertions.assertTrue(exception.getMessage().matches(String.format("The given recipes does not exists for the instance group \"%s\": (\\w+), (\\w+)", INSTANCE_GROUP_MASTER)));
verify(recipeService, times(2)).get(any(NameOrCrn.class), anyLong());
}
Aggregations