Search in sources :

Example 6 with EnvironmentStatus

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

the class SdxServiceTest method testCreateButEnvInStoppedStatus.

@MethodSource("startParamProvider")
void testCreateButEnvInStoppedStatus(EnvironmentStatus environmentStatus, String exceptionMessage) {
    SdxClusterRequest sdxClusterRequest = createSdxClusterRequest(null, MEDIUM_DUTY_HA);
    DetailedEnvironmentResponse detailedEnvironmentResponse = new DetailedEnvironmentResponse();
    detailedEnvironmentResponse.setName(sdxClusterRequest.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.createSdx(USER_CRN, CLUSTER_NAME, sdxClusterRequest, null)), "BadRequestException should thrown");
    assertEquals(exceptionMessage, badRequestException.getMessage());
}
Also used : SdxClusterRequest(com.sequenceiq.sdx.api.model.SdxClusterRequest) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 7 with EnvironmentStatus

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

the class SdxServiceTest method testCreateButEnvInDeleteInProgressPhase.

@ParameterizedTest
@MethodSource("deleteInProgressParamProvider")
void testCreateButEnvInDeleteInProgressPhase(EnvironmentStatus environmentStatus) {
    SdxClusterRequest sdxClusterRequest = createSdxClusterRequest(null, MEDIUM_DUTY_HA);
    DetailedEnvironmentResponse detailedEnvironmentResponse = new DetailedEnvironmentResponse();
    detailedEnvironmentResponse.setName(sdxClusterRequest.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.createSdx(USER_CRN, CLUSTER_NAME, sdxClusterRequest, null)), "BadRequestException should thrown");
    assertEquals("The environment is in delete in progress phase. Please create a new environment first!", badRequestException.getMessage());
}
Also used : SdxClusterRequest(com.sequenceiq.sdx.api.model.SdxClusterRequest) 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 8 with EnvironmentStatus

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

the class EnvironmentServiceTest method testWaitEnvironmentAvailable.

@Test
public void testWaitEnvironmentAvailable() {
    Long sdxId = 42L;
    SdxCluster sdxCluster = new SdxCluster();
    sdxCluster.setId(sdxId);
    sdxCluster.setClusterShape(SdxClusterShape.LIGHT_DUTY);
    sdxCluster.setEnvName("env");
    sdxCluster.setEnvCrn("crn");
    sdxCluster.setClusterName("cluster");
    Optional<SdxCluster> sdxClusterOptional = Optional.of(sdxCluster);
    when(sdxClusterRepository.findById(sdxId)).thenReturn(sdxClusterOptional);
    when(environmentClientService.getByCrn("crn")).thenReturn(getDetailedEnvironmentResponseWithStatus(EnvironmentStatus.ENVIRONMENT_VALIDATION_IN_PROGRESS)).thenReturn(getDetailedEnvironmentResponseWithStatus(EnvironmentStatus.NETWORK_CREATION_IN_PROGRESS)).thenReturn(getDetailedEnvironmentResponseWithStatus(EnvironmentStatus.PUBLICKEY_CREATE_IN_PROGRESS)).thenReturn(getDetailedEnvironmentResponseWithStatus(EnvironmentStatus.FREEIPA_CREATION_IN_PROGRESS)).thenReturn(getDetailedEnvironmentResponseWithStatus(EnvironmentStatus.AVAILABLE));
    PollingConfig pollingConfig = new PollingConfig(100, TimeUnit.MILLISECONDS, 10, TimeUnit.SECONDS);
    DetailedEnvironmentResponse environment = underTest.waitAndGetEnvironment(sdxId, pollingConfig, EnvironmentStatus::isAvailable);
    assertThat(environment.getEnvironmentStatus(), is(EnvironmentStatus.AVAILABLE));
    verifyZeroInteractions(sdxClusterRepository);
    verifyZeroInteractions(environmentClientService);
}
Also used : EnvironmentStatus(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentStatus) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) Test(org.junit.jupiter.api.Test)

Example 9 with EnvironmentStatus

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

the class EnvironmentServiceTest method testWaitEnvironmentNetworkCreationFinished.

@Test
public void testWaitEnvironmentNetworkCreationFinished() {
    Long sdxId = 42L;
    SdxCluster sdxCluster = new SdxCluster();
    sdxCluster.setId(sdxId);
    sdxCluster.setClusterShape(SdxClusterShape.LIGHT_DUTY);
    sdxCluster.setEnvName("env");
    sdxCluster.setEnvCrn("crn");
    sdxCluster.setClusterName("cluster");
    Optional<SdxCluster> sdxClusterOptional = Optional.of(sdxCluster);
    when(sdxClusterRepository.findById(sdxId)).thenReturn(sdxClusterOptional);
    when(environmentClientService.getByCrn("crn")).thenReturn(getDetailedEnvironmentResponseWithStatus(EnvironmentStatus.ENVIRONMENT_VALIDATION_IN_PROGRESS)).thenReturn(getDetailedEnvironmentResponseWithStatus(EnvironmentStatus.NETWORK_CREATION_IN_PROGRESS)).thenReturn(getDetailedEnvironmentResponseWithStatus(EnvironmentStatus.PUBLICKEY_CREATE_IN_PROGRESS));
    PollingConfig pollingConfig = new PollingConfig(100, TimeUnit.MILLISECONDS, 10, TimeUnit.SECONDS);
    DetailedEnvironmentResponse environment = underTest.waitAndGetEnvironment(sdxId, pollingConfig, EnvironmentStatus::isNetworkCreationFinished);
    assertThat(environment.getEnvironmentStatus(), is(EnvironmentStatus.PUBLICKEY_CREATE_IN_PROGRESS));
    verifyZeroInteractions(sdxClusterRepository);
    verifyZeroInteractions(environmentClientService);
}
Also used : EnvironmentStatus(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentStatus) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) Test(org.junit.jupiter.api.Test)

Example 10 with EnvironmentStatus

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

the class EnvironmentService method waitAndGetEnvironment.

public DetailedEnvironmentResponse waitAndGetEnvironment(Long sdxId, PollingConfig pollingConfig, Function<EnvironmentStatus, Boolean> statusCheck) {
    Optional<SdxCluster> sdxClusterOptional = sdxClusterRepository.findById(sdxId);
    if (sdxClusterOptional.isPresent()) {
        SdxCluster sdxCluster = sdxClusterOptional.get();
        sdxStatusService.setStatusForDatalakeAndNotify(DatalakeStatusEnum.WAIT_FOR_ENVIRONMENT, "Waiting for environment creation", sdxCluster);
        DetailedEnvironmentResponse environmentResponse = Polling.waitPeriodly(pollingConfig.getSleepTime(), pollingConfig.getSleepTimeUnit()).stopIfException(pollingConfig.getStopPollingIfExceptionOccurred()).stopAfterDelay(pollingConfig.getDuration(), pollingConfig.getDurationTimeUnit()).run(() -> {
            if (PollGroup.CANCELLED.equals(DatalakeInMemoryStateStore.get(sdxCluster.getId()))) {
                LOGGER.info("Environment wait polling cancelled in inmemory store, id: " + sdxCluster.getId());
                return AttemptResults.breakFor("Environment wait polling cancelled in inmemory store, id: " + sdxCluster.getId());
            }
            LOGGER.info("Creation polling environment for environment status: '{}' in '{}' env", sdxCluster.getClusterName(), sdxCluster.getEnvName());
            DetailedEnvironmentResponse environment = getDetailedEnvironmentResponse(sdxCluster.getEnvCrn());
            LOGGER.info("Response from environment: {}", JsonUtil.writeValueAsString(environment));
            if (statusCheck.apply(environment.getEnvironmentStatus())) {
                return AttemptResults.finishWith(environment);
            } else {
                if (environment.getEnvironmentStatus().isFailed()) {
                    return AttemptResults.breakFor("Environment creation failed: " + sdxCluster.getEnvName());
                } else if (environment.getEnvironmentStatus().isStopInProgressOrStopped()) {
                    return AttemptResults.breakFor("Environment is in stopped status: " + sdxCluster.getEnvName());
                } else if (environment.getEnvironmentStatus().isStartInProgress()) {
                    return AttemptResults.breakFor("The environment is starting. Please wait until finished: " + sdxCluster.getEnvName());
                } else {
                    return AttemptResults.justContinue();
                }
            }
        });
        return environmentResponse;
    } else {
        throw notFound("SDX cluster", sdxId).get();
    }
}
Also used : SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)

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