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