Search in sources :

Example 61 with NotFoundException

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());
}
Also used : NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Example 62 with NotFoundException

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());
}
Also used : NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Example 63 with NotFoundException

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());
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) Mock(org.mockito.Mock) TestUtil(com.sequenceiq.cloudbreak.TestUtil) ComponentConfigProviderService(com.sequenceiq.cloudbreak.service.ComponentConfigProviderService) ImageCatalogPlatform.imageCatalogPlatform(com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogPlatform.imageCatalogPlatform) MockitoAnnotations(org.mockito.MockitoAnnotations) StackMatrixService(com.sequenceiq.cloudbreak.service.StackMatrixService) ClusterComponentConfigProvider(com.sequenceiq.cloudbreak.cluster.service.ClusterComponentConfigProvider) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) PLATFORM(com.sequenceiq.cloudbreak.service.image.ImageTestUtil.PLATFORM) MethodSource(org.junit.jupiter.params.provider.MethodSource) InjectMocks(org.mockito.InjectMocks) ImageSettingsV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.image.ImageSettingsV4Request) Mockito.when(org.mockito.Mockito.when) Arguments(org.junit.jupiter.params.provider.Arguments) ImageCatalog(com.sequenceiq.cloudbreak.domain.ImageCatalog) CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) Workspace(com.sequenceiq.cloudbreak.workspace.model.Workspace) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Stream(java.util.stream.Stream) CloudPlatformConnectors(com.sequenceiq.cloudbreak.cloud.init.CloudPlatformConnectors) Assert.assertFalse(org.junit.Assert.assertFalse) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) BlueprintUtils(com.sequenceiq.cloudbreak.cmtemplate.utils.BlueprintUtils) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ImageSettingsV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.image.ImageSettingsV4Request) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 64 with NotFoundException

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());
    }
}
Also used : VmTypeResponse(com.sequenceiq.sdx.api.model.VmTypeResponse) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) List(java.util.List) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException)

Example 65 with NotFoundException

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());
    }
}
Also used : NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) VmTypeResponse(com.sequenceiq.sdx.api.model.VmTypeResponse) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) SdxRecommendationResponse(com.sequenceiq.sdx.api.model.SdxRecommendationResponse) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) List(java.util.List)

Aggregations

NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)73 Test (org.junit.jupiter.api.Test)33 CloudbreakImageNotFoundException (com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException)11 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)10 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)10 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)10 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)9 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)8 Map (java.util.Map)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 NameOrCrn (com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn)6 List (java.util.List)6 TransactionExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException)5 TransactionRuntimeExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException)5 Workspace (com.sequenceiq.cloudbreak.workspace.model.Workspace)5 Optional (java.util.Optional)5 CloudbreakImageCatalogException (com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException)4 Set (java.util.Set)4 CheckPermissionByResourceName (com.sequenceiq.authorization.annotation.CheckPermissionByResourceName)3 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)3