Search in sources :

Example 6 with SdxClusterResizeRequest

use of com.sequenceiq.sdx.api.model.SdxClusterResizeRequest in project cloudbreak by hortonworks.

the class SdxServiceTest method testSdxResizeButEnvInFailedPhase.

@ParameterizedTest
@MethodSource("failedParamProvider")
void testSdxResizeButEnvInFailedPhase(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 failed phase. Please fix the environment or create a new one 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 7 with SdxClusterResizeRequest

use of com.sequenceiq.sdx.api.model.SdxClusterResizeRequest in project cloudbreak by hortonworks.

the class SdxServiceTest method testSdxResizeByAccountIdAndNameWhenSdxOnGcp.

@Test
void testSdxResizeByAccountIdAndNameWhenSdxOnGcp() {
    SdxClusterResizeRequest sdxClusterResizeRequest = new SdxClusterResizeRequest();
    sdxClusterResizeRequest.setClusterShape(MEDIUM_DUTY_HA);
    sdxClusterResizeRequest.setEnvironment("environment");
    SdxCluster sdxCluster = getSdxCluster();
    sdxCluster.setClusterShape(LIGHT_DUTY);
    sdxCluster.setCloudStorageFileSystemType(FileSystemType.GCS);
    sdxCluster.setDatabaseCrn(null);
    when(entitlementService.isDatalakeLightToMediumMigrationEnabled(anyString())).thenReturn(true);
    when(sdxClusterRepository.findByAccountIdAndClusterNameAndDeletedIsNullAndDetachedIsFalse(anyString(), anyString())).thenReturn(Optional.of(sdxCluster));
    BadRequestException badRequestException = assertThrows(BadRequestException.class, () -> underTest.resizeSdx(USER_CRN, "sdxcluster", sdxClusterResizeRequest));
    assertTrue(badRequestException.getMessage().startsWith("Unsupported cloud provider GCP"));
}
Also used : SdxClusterResizeRequest(com.sequenceiq.sdx.api.model.SdxClusterResizeRequest) 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 8 with SdxClusterResizeRequest

use of com.sequenceiq.sdx.api.model.SdxClusterResizeRequest in project cloudbreak by hortonworks.

the class SdxServiceTest method testSdxResizeByAccountIdAndNameWhenSdxWithSameShape.

@Test
void testSdxResizeByAccountIdAndNameWhenSdxWithSameShape() {
    SdxClusterResizeRequest sdxClusterResizeRequest = new SdxClusterResizeRequest();
    sdxClusterResizeRequest.setClusterShape(MEDIUM_DUTY_HA);
    sdxClusterResizeRequest.setEnvironment("environment");
    SdxCluster sdxCluster = getSdxCluster();
    sdxCluster.setClusterShape(MEDIUM_DUTY_HA);
    sdxCluster.setDatabaseCrn(null);
    when(entitlementService.isDatalakeLightToMediumMigrationEnabled(anyString())).thenReturn(true);
    when(sdxClusterRepository.findByAccountIdAndClusterNameAndDeletedIsNullAndDetachedIsFalse(anyString(), anyString())).thenReturn(Optional.of(sdxCluster));
    BadRequestException badRequestException = assertThrows(BadRequestException.class, () -> underTest.resizeSdx(USER_CRN, "sdxcluster", sdxClusterResizeRequest));
    assertEquals("SDX cluster already is of requested shape", badRequestException.getMessage());
}
Also used : SdxClusterResizeRequest(com.sequenceiq.sdx.api.model.SdxClusterResizeRequest) 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 9 with SdxClusterResizeRequest

use of com.sequenceiq.sdx.api.model.SdxClusterResizeRequest in project cloudbreak by hortonworks.

the class SdxServiceTest method testSdxResizeClusterSuccess.

@Test
void testSdxResizeClusterSuccess() throws Exception {
    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(entitlementService.isDatalakeLightToMediumMigrationEnabled(anyString())).thenReturn(true);
    when(sdxClusterRepository.findByAccountIdAndClusterNameAndDeletedIsNullAndDetachedIsFalse(anyString(), anyString())).thenReturn(Optional.of(sdxCluster));
    when(sdxClusterRepository.findByAccountIdAndEnvCrnAndDeletedIsNullAndDetachedIsTrue(anyString(), anyString())).thenReturn(Optional.empty());
    mockEnvironmentCall(sdxClusterResizeRequest, CloudPlatform.AWS);
    when(sdxReactorFlowManager.triggerSdxResize(anyLong(), any(SdxCluster.class))).thenReturn(new FlowIdentifier(FlowType.FLOW, "FLOW_ID"));
    String mediumDutyJson = FileReaderUtils.readFileFromClasspath("/duties/7.2.10/aws/medium_duty_ha.json");
    when(cdpConfigService.getConfigForKey(any())).thenReturn(JsonUtil.readValue(mediumDutyJson, StackV4Request.class));
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn:cdp:freeipa:us-west-1:altus:user:__internal__actor__");
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    StackV4Response stackV4Response = new StackV4Response();
    stackV4Response.setStatus(Status.STOPPED);
    when(stackV4Endpoint.get(anyLong(), anyString(), anySet(), anyString())).thenReturn(stackV4Response);
    Pair<SdxCluster, FlowIdentifier> result = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.resizeSdx(USER_CRN, sdxCluster.getClusterName(), sdxClusterResizeRequest));
    SdxCluster createdSdxCluster = result.getLeft();
    assertEquals(sdxCluster.getClusterName(), createdSdxCluster.getClusterName());
    assertEquals(runtime, createdSdxCluster.getRuntime());
    assertEquals("s3a://some/dir/", createdSdxCluster.getCloudStorageBaseLocation());
    assertEquals("envir", createdSdxCluster.getEnvName());
}
Also used : StackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) SdxClusterResizeRequest(com.sequenceiq.sdx.api.model.SdxClusterResizeRequest) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 10 with SdxClusterResizeRequest

use of com.sequenceiq.sdx.api.model.SdxClusterResizeRequest in project cloudbreak by hortonworks.

the class SdxServiceTest method testSdxResizeByAccountIdAndNameWhenSdxDoesNotExist.

@Test
void testSdxResizeByAccountIdAndNameWhenSdxDoesNotExist() {
    SdxClusterResizeRequest sdxClusterResizeRequest = new SdxClusterResizeRequest();
    sdxClusterResizeRequest.setClusterShape(MEDIUM_DUTY_HA);
    sdxClusterResizeRequest.setEnvironment("environment");
    when(sdxClusterRepository.findByAccountIdAndClusterNameAndDeletedIsNullAndDetachedIsFalse(anyString(), anyString())).thenReturn(Optional.empty());
    NotFoundException notFoundException = assertThrows(NotFoundException.class, () -> underTest.resizeSdx(USER_CRN, "sdxcluster", sdxClusterResizeRequest));
    assertEquals("SDX cluster 'sdxcluster' not found.", notFoundException.getMessage());
}
Also used : SdxClusterResizeRequest(com.sequenceiq.sdx.api.model.SdxClusterResizeRequest) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Aggregations

SdxClusterResizeRequest (com.sequenceiq.sdx.api.model.SdxClusterResizeRequest)13 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)11 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)10 Test (org.junit.jupiter.api.Test)9 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)3 MethodSource (org.junit.jupiter.params.provider.MethodSource)3 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)1 StackV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response)1 NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)1 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)1 SdxClusterDetailResponse (com.sequenceiq.sdx.api.model.SdxClusterDetailResponse)1 SdxClusterResponse (com.sequenceiq.sdx.api.model.SdxClusterResponse)1