use of com.sequenceiq.cloudbreak.common.exception.NotFoundException in project cloudbreak by hortonworks.
the class DatabaseServiceTest method testGetDatabaseServerWhenNoClusterShouldThrowNotFoundException.
@Test
public void testGetDatabaseServerWhenNoClusterShouldThrowNotFoundException() {
when(stackOperations.getStackByCrn(CLUSTER_CRN)).thenReturn(new Stack());
NotFoundException exception = assertThrows(NotFoundException.class, () -> underTest.getDatabaseServer(CLUSTER_CRN));
assertThat(exception.getMessage()).isEqualTo("Data Hub with crn: 'clusterCrn' not found.");
verify(databaseServerV4Endpoint, never()).getByCrn(anyString());
}
use of com.sequenceiq.cloudbreak.common.exception.NotFoundException in project cloudbreak by hortonworks.
the class DatabaseServiceTest method testGetDatabaseServerWhenNoDatabaseCrnShouldThrowNotFoundException.
@Test
public void testGetDatabaseServerWhenNoDatabaseCrnShouldThrowNotFoundException() {
Stack stack = createStack();
stack.getCluster().setDatabaseServerCrn(null);
when(stackOperations.getStackByCrn(CLUSTER_CRN)).thenReturn(stack);
NotFoundException exception = assertThrows(NotFoundException.class, () -> underTest.getDatabaseServer(CLUSTER_CRN));
assertThat(exception.getMessage()).isEqualTo("Database for Data Hub with Data Hub crn: 'clusterCrn' not found.");
verify(databaseServerV4Endpoint, never()).getByCrn(anyString());
}
use of com.sequenceiq.cloudbreak.common.exception.NotFoundException in project cloudbreak by hortonworks.
the class ImageServiceTest method testDetermineImageFromCatalogWithNonExistingCatalogName.
@Test
public void testDetermineImageFromCatalogWithNonExistingCatalogName() {
when(imageCatalogService.getImageCatalogByName(WORKSPACE_ID, "aCatalog")).thenThrow(new NotFoundException("Image catalog not found with name: aCatalog"));
ImageSettingsV4Request imageRequest = new ImageSettingsV4Request();
imageRequest.setCatalog("aCatalog");
imageRequest.setOs(OS);
CloudbreakImageCatalogException exception = assertThrows(CloudbreakImageCatalogException.class, () -> underTest.determineImageFromCatalog(WORKSPACE_ID, imageRequest, PLATFORM, PLATFORM, TestUtil.blueprint(), true, true, TestUtil.user(USER_ID, USER_ID_STRING), image -> true));
assertEquals("Image catalog not found with name: aCatalog", exception.getMessage());
}
use of com.sequenceiq.cloudbreak.common.exception.NotFoundException in project cloudbreak by hortonworks.
the class SdxRecommendationService method validateVmTypeOverride.
public void validateVmTypeOverride(DetailedEnvironmentResponse environment, SdxCluster sdxCluster) {
try {
LOGGER.debug("Validate vm type override for sdx cluster: {}", sdxCluster.getCrn());
String cloudPlatform = environment.getCloudPlatform();
if (shouldValidateVmTypes(sdxCluster, cloudPlatform)) {
StackV4Request stackV4Request = JsonUtil.readValue(sdxCluster.getStackRequest(), StackV4Request.class);
StackV4Request defaultTemplate = getDefaultTemplate(sdxCluster.getClusterShape(), sdxCluster.getRuntime(), cloudPlatform);
String region = environment.getRegions().getNames().stream().findFirst().orElse(null);
List<VmTypeResponse> availableVmTypes = getAvailableVmTypes(environment.getCredential().getCrn(), cloudPlatform, region, null);
Map<String, VmTypeResponse> defaultVmTypesByInstanceGroup = getDefaultVmTypesByInstanceGroup(availableVmTypes, defaultTemplate);
Map<String, List<String>> availableVmTypeNamesByInstanceGroup = filterAvailableVmTypeNamesBasedOnDefault(availableVmTypes, defaultVmTypesByInstanceGroup);
stackV4Request.getInstanceGroups().forEach(instanceGroup -> {
if (!defaultVmTypesByInstanceGroup.containsKey(instanceGroup.getName())) {
String message = "Instance group is missing from default template: " + instanceGroup.getName();
LOGGER.warn(message);
throw new BadRequestException(message);
}
VmTypeResponse defaultTemplateVmType = defaultVmTypesByInstanceGroup.get(instanceGroup.getName());
if (isCustomInstanceTypeProvided(instanceGroup, defaultTemplateVmType.getValue()) && !isProvidedInstanceTypeIsAvailable(availableVmTypeNamesByInstanceGroup, instanceGroup)) {
String message = String.format("Invalid custom instance type for instance group: %s - %s", instanceGroup.getName(), instanceGroup.getTemplate().getInstanceType());
LOGGER.warn(message);
throw new BadRequestException(message);
}
});
}
} catch (NotFoundException | BadRequestException e) {
throw e;
} catch (Exception e) {
LOGGER.warn("Validate VM type override failed!", e);
throw new RuntimeException("Validate VM type override failed: " + e.getMessage());
}
}
use of com.sequenceiq.cloudbreak.common.exception.NotFoundException in project cloudbreak by hortonworks.
the class SdxRecommendationService method getRecommendation.
public SdxRecommendationResponse getRecommendation(String credentialCrn, SdxClusterShape clusterShape, String runtimeVersion, String cloudPlatform, String region, String availabilityZone) {
try {
StackV4Request defaultTemplate = getDefaultTemplate(clusterShape, runtimeVersion, cloudPlatform);
List<VmTypeResponse> availableVmTypes = getAvailableVmTypes(credentialCrn, cloudPlatform, region, availabilityZone);
Map<String, VmTypeResponse> defaultVmTypesByInstanceGroup = getDefaultVmTypesByInstanceGroup(availableVmTypes, defaultTemplate);
Map<String, List<VmTypeResponse>> availableVmTypesByInstanceGroup = filterAvailableVmTypesBasedOnDefault(availableVmTypes, defaultVmTypesByInstanceGroup);
LOGGER.debug("Return default template and available vm types for clusterShape: {}, " + "runtimeVersion: {}, cloudPlatform: {}, region: {}, availabilityZone: {}", clusterShape, runtimeVersion, cloudPlatform, region, availabilityZone);
return new SdxRecommendationResponse(defaultTemplate, availableVmTypesByInstanceGroup);
} catch (NotFoundException | BadRequestException e) {
throw e;
} catch (Exception e) {
LOGGER.warn("Getting recommendation failed!", e);
throw new RuntimeException("Getting recommendation failed: " + e.getMessage());
}
}
Aggregations