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());
}
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());
}
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);
}
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);
}
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();
}
}
Aggregations