Search in sources :

Example 16 with EnvironmentView

use of com.sequenceiq.environment.environment.domain.EnvironmentView in project cloudbreak by hortonworks.

the class EnvironmentDeletionService method deleteByNameAndAccountId.

public EnvironmentViewDto deleteByNameAndAccountId(String environmentName, String accountId, String actualUserCrn, boolean cascading, boolean forced) {
    EnvironmentView environment = environmentViewService.getByNameAndAccountId(environmentName, accountId);
    MDCBuilder.buildMdcContext(environment);
    LOGGER.debug(String.format("Deleting environment [name: %s]", environment.getName()));
    delete(environment, actualUserCrn, cascading, forced);
    return environmentDtoConverter.environmentViewToViewDto(environment);
}
Also used : EnvironmentView(com.sequenceiq.environment.environment.domain.EnvironmentView)

Example 17 with EnvironmentView

use of com.sequenceiq.environment.environment.domain.EnvironmentView in project cloudbreak by hortonworks.

the class DataLakeClustersDeleteHandler method accept.

@Override
public void accept(Event<EnvironmentDeletionDto> environmentDtoEvent) {
    LOGGER.debug("Accepting DataLakeClustersDelete event");
    EnvironmentDeletionDto environmentDeletionDto = environmentDtoEvent.getData();
    EnvironmentDto environmentDto = environmentDeletionDto.getEnvironmentDto();
    EnvDeleteEvent envDeleteEvent = getEnvDeleteEvent(environmentDeletionDto);
    try {
        PollingConfig pollingConfig = getPollingConfig();
        EnvironmentView environment = environmentViewService.getById(environmentDto.getId());
        sdxDeleteService.deleteSdxClustersForEnvironment(pollingConfig, environment, environmentDeletionDto.isForceDelete());
        eventSender().sendEvent(envDeleteEvent, environmentDtoEvent.getHeaders());
    } catch (ClientErrorException e) {
        String message;
        try {
            message = e.getResponse().readEntity(ExceptionResponse.class).getMessage();
        } catch (Exception exception) {
            message = null;
        }
        EnvClusterDeleteFailedEvent failedEvent = EnvClusterDeleteFailedEvent.builder().withEnvironmentID(environmentDto.getId()).withException(new BadRequestException(message)).withResourceCrn(environmentDto.getResourceCrn()).withResourceName(environmentDto.getName()).withMessage(message).build();
        eventSender().sendEvent(failedEvent, environmentDtoEvent.getHeaders());
    } catch (Exception e) {
        EnvClusterDeleteFailedEvent failedEvent = EnvClusterDeleteFailedEvent.builder().withEnvironmentID(environmentDto.getId()).withException(e).withResourceCrn(environmentDto.getResourceCrn()).withResourceName(environmentDto.getName()).build();
        eventSender().sendEvent(failedEvent, environmentDtoEvent.getHeaders());
    }
}
Also used : ExceptionResponse(com.sequenceiq.cloudbreak.common.exception.ExceptionResponse) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) EnvDeleteEvent(com.sequenceiq.environment.environment.flow.deletion.event.EnvDeleteEvent) EnvironmentView(com.sequenceiq.environment.environment.domain.EnvironmentView) ClientErrorException(javax.ws.rs.ClientErrorException) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) EnvClusterDeleteFailedEvent(com.sequenceiq.environment.environment.flow.deletion.event.EnvClusterDeleteFailedEvent) PollingConfig(com.sequenceiq.environment.util.PollingConfig) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) ClientErrorException(javax.ws.rs.ClientErrorException) EnvironmentDeletionDto(com.sequenceiq.environment.environment.dto.EnvironmentDeletionDto)

Example 18 with EnvironmentView

use of com.sequenceiq.environment.environment.domain.EnvironmentView in project cloudbreak by hortonworks.

the class AwsEnvironmentParametersConverterTest method convertToDtoTest.

@Test
void convertToDtoTest() {
    EnvironmentView environmentView = ENVIRONMENT_VIEW;
    AwsParameters parameters = new AwsParameters();
    parameters.setAccountId(ACCOUNT_ID);
    parameters.setEnvironment(environmentView);
    parameters.setId(ID);
    parameters.setName(ENV_NAME);
    parameters.setS3guardTableName(TABLE_NAME);
    parameters.setS3guardTableCreation(S3GuardTableCreation.CREATE_NEW);
    parameters.setFreeIpaSpotPercentage(null);
    parameters.setFreeIpaSpotMaxPrice(0.9);
    parameters.setEncryptionKeyArn(ENCRYPTION_KEY_ARN);
    ParametersDto result = underTest.convertToDto(parameters);
    assertEquals(ACCOUNT_ID, result.getAccountId());
    assertEquals(ID, result.getId());
    assertEquals(ENV_NAME, result.getName());
    assertEquals(TABLE_NAME, result.getAwsParametersDto().getS3GuardTableName());
    assertEquals(S3GuardTableCreation.CREATE_NEW, result.getAwsParametersDto().getDynamoDbTableCreation());
    assertEquals(0, result.getAwsParametersDto().getFreeIpaSpotPercentage());
    assertEquals(0.9, result.getAwsParametersDto().getFreeIpaSpotMaxPrice());
    assertEquals(ENCRYPTION_KEY_ARN, result.getAwsParametersDto().getAwsDiskEncryptionParametersDto().getEncryptionKeyArn());
}
Also used : EnvironmentView(com.sequenceiq.environment.environment.domain.EnvironmentView) AwsParameters(com.sequenceiq.environment.parameters.dao.domain.AwsParameters) AwsDiskEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.AwsDiskEncryptionParametersDto) ParametersDto(com.sequenceiq.environment.parameter.dto.ParametersDto) AwsParametersDto(com.sequenceiq.environment.parameter.dto.AwsParametersDto) Test(org.junit.jupiter.api.Test)

Example 19 with EnvironmentView

use of com.sequenceiq.environment.environment.domain.EnvironmentView in project cloudbreak by hortonworks.

the class AzureEnvironmentParametersConverterTest method convertToDtoTest.

@Test
void convertToDtoTest() {
    EnvironmentView environmentView = ENVIRONMENT_VIEW;
    AzureParameters parameters = new AzureParameters();
    parameters.setAccountId(ACCOUNT_ID);
    parameters.setEnvironment(environmentView);
    parameters.setId(ID);
    parameters.setName(ENV_NAME);
    parameters.setEncryptionKeyUrl(KEY_URL);
    parameters.setDiskEncryptionSetId("DummyDesId");
    parameters.setEncryptionKeyResourceGroupName(KEY_RESOURCE_GROUP_NAME);
    ParametersDto result = underTest.convertToDto(parameters);
    assertEquals(ACCOUNT_ID, result.getAccountId());
    assertEquals(ID, result.getId());
    assertEquals(ENV_NAME, result.getName());
    assertEquals(KEY_URL, result.getAzureParametersDto().getAzureResourceEncryptionParametersDto().getEncryptionKeyUrl());
    assertEquals("DummyDesId", result.getAzureParametersDto().getAzureResourceEncryptionParametersDto().getDiskEncryptionSetId());
    assertEquals(KEY_RESOURCE_GROUP_NAME, result.getAzureParametersDto().getAzureResourceEncryptionParametersDto().getEncryptionKeyResourceGroupName());
}
Also used : AzureParameters(com.sequenceiq.environment.parameters.dao.domain.AzureParameters) EnvironmentView(com.sequenceiq.environment.environment.domain.EnvironmentView) ParametersDto(com.sequenceiq.environment.parameter.dto.ParametersDto) AzureParametersDto(com.sequenceiq.environment.parameter.dto.AzureParametersDto) AzureResourceEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.AzureResourceEncryptionParametersDto) Test(org.junit.jupiter.api.Test)

Aggregations

EnvironmentView (com.sequenceiq.environment.environment.domain.EnvironmentView)19 Test (org.junit.jupiter.api.Test)12 PollingConfig (com.sequenceiq.environment.util.PollingConfig)6 ParametersDto (com.sequenceiq.environment.parameter.dto.ParametersDto)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 EnvClusterDeleteFailedEvent (com.sequenceiq.environment.environment.flow.deletion.event.EnvClusterDeleteFailedEvent)2 EnvDeleteEvent (com.sequenceiq.environment.environment.flow.deletion.event.EnvDeleteEvent)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 UserBreakException (com.dyngr.exception.UserBreakException)1 StackViewV4Responses (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Responses)1 Network (com.sequenceiq.cloudbreak.cloud.model.Network)1 CreatedCloudNetwork (com.sequenceiq.cloudbreak.cloud.model.network.CreatedCloudNetwork)1 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)1 ExceptionResponse (com.sequenceiq.cloudbreak.common.exception.ExceptionResponse)1 Environment (com.sequenceiq.environment.environment.domain.Environment)1 EnvironmentDeletionDto (com.sequenceiq.environment.environment.dto.EnvironmentDeletionDto)1 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)1 EnvironmentViewDto (com.sequenceiq.environment.environment.dto.EnvironmentViewDto)1 EnvironmentTestData.newTestEnvironment (com.sequenceiq.environment.environment.service.EnvironmentTestData.newTestEnvironment)1