Search in sources :

Example 91 with BadRequestException

use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.

the class SdxServiceTest method testSdxResizeButEnvInDeleteInProgressPhase.

@ParameterizedTest
@MethodSource("deleteInProgressParamProvider")
void testSdxResizeButEnvInDeleteInProgressPhase(EnvironmentStatus environmentStatus) {
    SdxClusterResizeRequest sdxClusterResizeRequest = new SdxClusterResizeRequest();
    sdxClusterResizeRequest.setClusterShape(MEDIUM_DUTY_HA);
    sdxClusterResizeRequest.setEnvironment("environment");
    SdxCluster sdxCluster = getSdxCluster();
    sdxCluster.setClusterShape(LIGHT_DUTY);
    sdxCluster.setDatabaseCrn(null);
    when(entitlementService.isDatalakeLightToMediumMigrationEnabled(anyString())).thenReturn(true);
    when(sdxClusterRepository.findByAccountIdAndClusterNameAndDeletedIsNullAndDetachedIsFalse(anyString(), anyString())).thenReturn(Optional.of(sdxCluster));
    when(sdxClusterRepository.findByAccountIdAndEnvCrnAndDeletedIsNullAndDetachedIsTrue(anyString(), anyString())).thenReturn(Optional.empty());
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn:cdp:freeipa:us-west-1:altus:user:__internal__actor__");
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    DetailedEnvironmentResponse detailedEnvironmentResponse = new DetailedEnvironmentResponse();
    detailedEnvironmentResponse.setName(sdxClusterResizeRequest.getEnvironment());
    detailedEnvironmentResponse.setCloudPlatform(CloudPlatform.AWS.name());
    detailedEnvironmentResponse.setCrn(getCrn());
    detailedEnvironmentResponse.setEnvironmentStatus(environmentStatus);
    when(environmentClientService.getByName(anyString())).thenReturn(detailedEnvironmentResponse);
    BadRequestException badRequestException = assertThrows(BadRequestException.class, () -> ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.resizeSdx(USER_CRN, "sdxcluster", sdxClusterResizeRequest)), "BadRequestException should thrown");
    assertEquals("The environment is in delete in progress phase. Please create a new environment first!", badRequestException.getMessage());
}
Also used : SdxClusterResizeRequest(com.sequenceiq.sdx.api.model.SdxClusterResizeRequest) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 92 with BadRequestException

use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.

the class SdxServiceTest method testDeleteSdxWhenSdxHasExternalDatabaseButCrnIsMissingShouldThrowNotFoundException.

@Test
void testDeleteSdxWhenSdxHasExternalDatabaseButCrnIsMissingShouldThrowNotFoundException() {
    SdxCluster sdxCluster = getSdxCluster();
    sdxCluster.setDatabaseAvailabilityType(SdxDatabaseAvailabilityType.HA);
    sdxCluster.setDatabaseCrn(null);
    when(sdxClusterRepository.findByAccountIdAndClusterNameAndDeletedIsNull(anyString(), anyString())).thenReturn(Optional.of(sdxCluster));
    BadRequestException badRequestException = assertThrows(BadRequestException.class, () -> underTest.deleteSdx(USER_CRN, "sdx-cluster-name", false));
    assertEquals(String.format("Can not find external database for Data Lake, but it was requested: %s. Please use force delete.", sdxCluster.getClusterName()), badRequestException.getMessage());
}
Also used : SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 93 with BadRequestException

use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.

the class SdxServiceTest method testSdxResizeClusterWithNoEntitlement.

@Test
void testSdxResizeClusterWithNoEntitlement() {
    final String runtime = "7.2.10";
    SdxClusterResizeRequest sdxClusterResizeRequest = new SdxClusterResizeRequest();
    sdxClusterResizeRequest.setClusterShape(MEDIUM_DUTY_HA);
    sdxClusterResizeRequest.setEnvironment("environment");
    SdxCluster sdxCluster = getSdxCluster();
    sdxCluster.setId(1L);
    sdxCluster.setClusterShape(LIGHT_DUTY);
    sdxCluster.setDatabaseCrn(null);
    sdxCluster.setRuntime(runtime);
    sdxCluster.setCloudStorageBaseLocation("s3a://some/dir/");
    when(sdxClusterRepository.findByAccountIdAndClusterNameAndDeletedIsNullAndDetachedIsFalse(anyString(), anyString())).thenReturn(Optional.of(sdxCluster));
    BadRequestException badRequestException = assertThrows(BadRequestException.class, () -> ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.resizeSdx(USER_CRN, "sdxcluster", sdxClusterResizeRequest)));
    assertEquals("Resizing of the data lake is not supported", badRequestException.getMessage());
}
Also used : SdxClusterResizeRequest(com.sequenceiq.sdx.api.model.SdxClusterResizeRequest) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 94 with BadRequestException

use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.

the class SdxServiceTest method testSdxResizeMediumDutySdxEnabled720Runtime.

@Test
void testSdxResizeMediumDutySdxEnabled720Runtime() {
    final String invalidRuntime = "7.2.0";
    SdxClusterResizeRequest sdxClusterResizeRequest = new SdxClusterResizeRequest();
    sdxClusterResizeRequest.setClusterShape(MEDIUM_DUTY_HA);
    sdxClusterResizeRequest.setEnvironment("environment");
    SdxCluster sdxCluster = getSdxCluster();
    sdxCluster.setClusterShape(LIGHT_DUTY);
    sdxCluster.setDatabaseCrn(null);
    sdxCluster.setRuntime(invalidRuntime);
    when(entitlementService.isDatalakeLightToMediumMigrationEnabled(anyString())).thenReturn(true);
    when(sdxClusterRepository.findByAccountIdAndClusterNameAndDeletedIsNullAndDetachedIsFalse(anyString(), anyString())).thenReturn(Optional.of(sdxCluster));
    when(sdxClusterRepository.findByAccountIdAndEnvCrnAndDeletedIsNullAndDetachedIsTrue(anyString(), anyString())).thenReturn(Optional.empty());
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn:cdp:freeipa:us-west-1:altus:user:__internal__actor__");
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    mockEnvironmentCall(sdxClusterResizeRequest, CloudPlatform.AWS);
    BadRequestException badRequestException = assertThrows(BadRequestException.class, () -> ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.resizeSdx(USER_CRN, "sdxcluster", sdxClusterResizeRequest)));
    assertEquals("Provisioning a Medium Duty SDX shape is only valid for CM version greater than or equal to " + MEDIUM_DUTY_REQUIRED_VERSION + " and not " + invalidRuntime, badRequestException.getMessage());
}
Also used : SdxClusterResizeRequest(com.sequenceiq.sdx.api.model.SdxClusterResizeRequest) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 95 with BadRequestException

use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.

the class SdxServiceTest method testCreateSdxClusterWhenClusterWithSpecifiedNameAlreadyExistShouldThrowClusterAlreadyExistBadRequestException.

@Test
void testCreateSdxClusterWhenClusterWithSpecifiedNameAlreadyExistShouldThrowClusterAlreadyExistBadRequestException() {
    SdxClusterRequest sdxClusterRequest = createSdxClusterRequest(null, MEDIUM_DUTY_HA);
    SdxCluster existing = new SdxCluster();
    existing.setEnvName("envir");
    when(sdxClusterRepository.findByAccountIdAndEnvNameAndDeletedIsNullAndDetachedIsFalse(anyString(), anyString())).thenReturn(Collections.singletonList(existing));
    BadRequestException badRequestException = assertThrows(BadRequestException.class, () -> ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.createSdx(USER_CRN, CLUSTER_NAME, sdxClusterRequest, null)));
    assertEquals("SDX cluster exists for environment name: envir", badRequestException.getMessage());
}
Also used : SdxClusterRequest(com.sequenceiq.sdx.api.model.SdxClusterRequest) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Aggregations

BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)298 Test (org.junit.jupiter.api.Test)134 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)45 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)34 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)26 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)23 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)22 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)21 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)21 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)19 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)19 Stack (com.sequenceiq.freeipa.entity.Stack)18 BaseDiagnosticsCollectionRequest (com.sequenceiq.common.api.diagnostics.BaseDiagnosticsCollectionRequest)14 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)14 SdxClusterRequest (com.sequenceiq.sdx.api.model.SdxClusterRequest)14 Set (java.util.Set)14 NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)13 NameOrCrn (com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn)12 Json (com.sequenceiq.cloudbreak.common.json.Json)12 TransactionExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException)12