Search in sources :

Example 1 with EnvironmentStatus

use of com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentStatus in project cloudbreak by hortonworks.

the class DistroXV1RequestToStackV4RequestConverterTest method testStackV4RequestToDistroXV1RequestRegardlessOfTheStateOfTheEnvironment.

@ParameterizedTest
@EnumSource(EnvironmentStatus.class)
void testStackV4RequestToDistroXV1RequestRegardlessOfTheStateOfTheEnvironment(EnvironmentStatus status) {
    StackV4Request source = new StackV4Request();
    source.setName("SomeStack");
    source.setEnvironmentCrn("SomeEnvCrn");
    DetailedEnvironmentResponse env = createAwsEnvironment();
    env.setCrn(source.getEnvironmentCrn());
    env.setEnvironmentStatus(status);
    when(environmentClientService.getByCrn(source.getEnvironmentCrn())).thenReturn(env);
    DistroXV1Request result = assertDoesNotThrow(() -> underTest.convert(source));
    verify(environmentClientService, times(1)).getByCrn(any());
    verify(environmentClientService, times(1)).getByCrn(source.getEnvironmentCrn());
    Assertions.assertEquals(env.getName(), result.getEnvironmentName());
}
Also used : StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) DistroXV1Request(com.sequenceiq.distrox.api.v1.distrox.model.DistroXV1Request) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with EnvironmentStatus

use of com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentStatus in project cloudbreak by hortonworks.

the class CleanupWaitUtil method checkEnvironmentDeleteFailedStatus.

/**
 * Checking the environment is in DELETE_FAILED state.
 *
 * Returns with:
 * TRUE:   DELETE_FAILED state is available.
 * FALSE:  DELETE_FAILED state is not available.
 *
 * @param environmentClient  com.sequenceiq.environment.client.EnvironmentClient
 * @param environmentName    Provided environment name
 * @return                   TRUE or FALSE based on existing DELETE_FAILED status
 */
private boolean checkEnvironmentDeleteFailedStatus(EnvironmentClient environmentClient, String environmentName) {
    try {
        EnvironmentStatus environmentStatus = environmentClient.environmentV1Endpoint().list().getResponses().stream().filter(response -> response.getName().equalsIgnoreCase(environmentName)).findFirst().map(EnvironmentBaseResponse::getEnvironmentStatus).orElse(EnvironmentStatus.ARCHIVED);
        LOG.info("{} environment actual state is: {}", environmentName, environmentStatus);
        return environmentStatus.equals(EnvironmentStatus.DELETE_FAILED);
    } catch (Exception e) {
        LOG.warn("Exception has been occurred while checking {} environment's DELETE_FAILED state: {}", environmentName, e.getMessage(), e);
        return false;
    }
}
Also used : Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) Status(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status) CloudbreakClient(com.sequenceiq.cloudbreak.client.CloudbreakClient) Collectors(java.util.stream.Collectors) StackViewV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Response) EnvironmentBaseResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentBaseResponse) WaitResult(com.sequenceiq.it.cloudbreak.util.WaitResult) Value(org.springframework.beans.factory.annotation.Value) SdxClient(com.sequenceiq.sdx.client.SdxClient) Component(org.springframework.stereotype.Component) SdxClusterResponse(com.sequenceiq.sdx.api.model.SdxClusterResponse) EnvironmentClient(com.sequenceiq.environment.client.EnvironmentClient) Map(java.util.Map) EnvironmentStatus(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentStatus) SdxClusterStatusResponse(com.sequenceiq.sdx.api.model.SdxClusterStatusResponse) Collections(java.util.Collections) EnvironmentStatus(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentStatus)

Example 3 with EnvironmentStatus

use of com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentStatus 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 4 with EnvironmentStatus

use of com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentStatus in project cloudbreak by hortonworks.

the class SdxServiceTest method testSdxResizeButEnvInStoppedStatus.

@ParameterizedTest
@MethodSource("startParamProvider")
void testSdxResizeButEnvInStoppedStatus(EnvironmentStatus environmentStatus, String exceptionMessage) {
    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(exceptionMessage, 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 5 with EnvironmentStatus

use of com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentStatus 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)

Aggregations

DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)11 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)6 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 MethodSource (org.junit.jupiter.params.provider.MethodSource)6 EnvironmentStatus (com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentStatus)3 SdxClusterRequest (com.sequenceiq.sdx.api.model.SdxClusterRequest)3 SdxClusterResizeRequest (com.sequenceiq.sdx.api.model.SdxClusterResizeRequest)3 Test (org.junit.jupiter.api.Test)2 Status (com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status)1 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)1 StackViewV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Response)1 CloudbreakClient (com.sequenceiq.cloudbreak.client.CloudbreakClient)1 DistroXV1Request (com.sequenceiq.distrox.api.v1.distrox.model.DistroXV1Request)1 EnvironmentBaseResponse (com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentBaseResponse)1 EnvironmentClient (com.sequenceiq.environment.client.EnvironmentClient)1 WaitResult (com.sequenceiq.it.cloudbreak.util.WaitResult)1 SdxClusterResponse (com.sequenceiq.sdx.api.model.SdxClusterResponse)1 SdxClusterStatusResponse (com.sequenceiq.sdx.api.model.SdxClusterStatusResponse)1 SdxClient (com.sequenceiq.sdx.client.SdxClient)1