Search in sources :

Example 26 with EnvironmentDeletionDto

use of com.sequenceiq.environment.environment.dto.EnvironmentDeletionDto in project cloudbreak by hortonworks.

the class ResourceEncryptionDeleteHandlerTest method setUp.

@BeforeEach
void setUp() {
    EnvironmentDto eventDto = EnvironmentDto.builder().withId(ENVIRONMENT_ID).withResourceCrn(ENVIRONMENT_CRN).withName(ENVIRONMENT_NAME).withCloudPlatform("AZURE").withParameters(ParametersDto.builder().withAzureParameters(AzureParametersDto.builder().withEncryptionParameters(AzureResourceEncryptionParametersDto.builder().withDiskEncryptionSetId("/subscriptions/dummySubscriptionId/resourceGroups/dummyResourceGroup/" + "providers/Microsoft.Compute/diskEncryptionSets/dummyDesId").withEncryptionKeyUrl("https://dummyVault.vault.azure.net/keys/dummyKey/dummyKeyVersion").build()).build()).build()).build();
    EnvironmentDeletionDto environmentDeletionDto = EnvironmentDeletionDto.builder().withId(ENVIRONMENT_ID).withForceDelete(false).withEnvironmentDto(eventDto).build();
    lenient().when(environmentDtoEvent.getData()).thenReturn(environmentDeletionDto);
    lenient().when(environmentDtoEvent.getHeaders()).thenReturn(headers);
    lenient().doAnswer(i -> null).when(eventSender).sendEvent(baseNamedFlowEventCaptor.capture(), any(Headers.class));
}
Also used : EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) Headers(reactor.bus.Event.Headers) EnvironmentDeletionDto(com.sequenceiq.environment.environment.dto.EnvironmentDeletionDto) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 27 with EnvironmentDeletionDto

use of com.sequenceiq.environment.environment.dto.EnvironmentDeletionDto in project cloudbreak by hortonworks.

the class DataHubClusterDeletionHandler method accept.

@Override
public void accept(Event<EnvironmentDeletionDto> environmentDtoEvent) {
    LOGGER.debug("Accepting DataHubClustersDelete event");
    EnvironmentDeletionDto environmentDeletionDto = environmentDtoEvent.getData();
    EnvironmentDto environmentDto = environmentDeletionDto.getEnvironmentDto();
    EnvDeleteEvent envDeleteEvent = getEnvDeleteEvent(environmentDeletionDto);
    try {
        PollingConfig pollingConfig = getPollingConfig();
        environmentService.findEnvironmentById(environmentDto.getId()).ifPresent(environment -> datahubDeletionService.deleteDatahubClustersForEnvironment(pollingConfig, environment, environmentDeletionDto.isForceDelete()));
        eventSender().sendEvent(envDeleteEvent, 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 : EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) EnvDeleteEvent(com.sequenceiq.environment.environment.flow.deletion.event.EnvDeleteEvent) EnvClusterDeleteFailedEvent(com.sequenceiq.environment.environment.flow.deletion.event.EnvClusterDeleteFailedEvent) PollingConfig(com.sequenceiq.environment.util.PollingConfig) EnvironmentDeletionDto(com.sequenceiq.environment.environment.dto.EnvironmentDeletionDto)

Example 28 with EnvironmentDeletionDto

use of com.sequenceiq.environment.environment.dto.EnvironmentDeletionDto in project cloudbreak by hortonworks.

the class ExperienceDeletionHandler method accept.

@Override
public void accept(Event<EnvironmentDeletionDto> environmentDeletionDtoEvent) {
    LOGGER.debug("Accepting XP Delete event");
    EnvironmentDeletionDto environmentDeletionDto = environmentDeletionDtoEvent.getData();
    EnvironmentDto envDto = environmentDeletionDtoEvent.getData().getEnvironmentDto();
    try {
        if (experienceDeletionEnabled) {
            if (entitlementService.isExperienceDeletionEnabled(envDto.getAccountId())) {
                environmentService.findEnvironmentById(envDto.getId()).ifPresent(environment -> environmentExperienceDeletionAction.execute(environment, environmentDeletionDto.isForceDelete()));
            } else {
                LOGGER.debug("Experience deletion is disabled by entitlement.");
            }
        } else {
            LOGGER.debug("Experience deletion is disabled by Spring config.");
        }
        EnvDeleteEvent envDeleteEvent = getEnvDeleteEvent(environmentDeletionDto);
        eventSender().sendEvent(envDeleteEvent, environmentDeletionDtoEvent.getHeaders());
    } catch (Exception e) {
        LOGGER.debug("Experience deletion failed with exception", e);
        EnvClusterDeleteFailedEvent failedEvent = EnvClusterDeleteFailedEvent.builder().withEnvironmentID(envDto.getId()).withException(e).withResourceCrn(envDto.getResourceCrn()).withResourceName(envDto.getName()).build();
        eventSender().sendEvent(failedEvent, environmentDeletionDtoEvent.getHeaders());
    }
}
Also used : EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) EnvDeleteEvent(com.sequenceiq.environment.environment.flow.deletion.event.EnvDeleteEvent) EnvClusterDeleteFailedEvent(com.sequenceiq.environment.environment.flow.deletion.event.EnvClusterDeleteFailedEvent) EnvironmentDeletionDto(com.sequenceiq.environment.environment.dto.EnvironmentDeletionDto)

Example 29 with EnvironmentDeletionDto

use of com.sequenceiq.environment.environment.dto.EnvironmentDeletionDto 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 30 with EnvironmentDeletionDto

use of com.sequenceiq.environment.environment.dto.EnvironmentDeletionDto in project cloudbreak by hortonworks.

the class EnvClustersDeleteActions method datalakeClustersDeleteAction.

@Bean(name = "DATALAKE_CLUSTERS_DELETE_STARTED_STATE")
public Action<?, ?> datalakeClustersDeleteAction() {
    return new AbstractEnvClustersDeleteAction<>(EnvDeleteEvent.class) {

        @Override
        protected void doExecute(CommonContext context, EnvDeleteEvent payload, Map<Object, Object> variables) {
            EnvironmentStatus environmentStatus = EnvironmentStatus.DATALAKE_CLUSTERS_DELETE_IN_PROGRESS;
            ResourceEvent resourceEvent = ResourceEvent.ENVIRONMENT_DATALAKE_CLUSTERS_DELETION_STARTED;
            EnvClustersDeleteState envClustersDeleteState = EnvClustersDeleteState.DATALAKE_CLUSTERS_DELETE_STARTED_STATE;
            String logDeleteState = "Data Lake clusters";
            EnvironmentDeletionDto envDto = commonUpdateEnvironmentAndNotify(context, payload, environmentStatus, resourceEvent, envClustersDeleteState, logDeleteState);
            sendEvent(context, DELETE_DATALAKE_CLUSTERS_EVENT.selector(), envDto);
        }
    };
}
Also used : EnvironmentStatus(com.sequenceiq.environment.environment.EnvironmentStatus) EnvDeleteEvent(com.sequenceiq.environment.environment.flow.deletion.event.EnvDeleteEvent) CommonContext(com.sequenceiq.flow.core.CommonContext) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) Map(java.util.Map) EnvironmentDeletionDto(com.sequenceiq.environment.environment.dto.EnvironmentDeletionDto) Bean(org.springframework.context.annotation.Bean)

Aggregations

EnvironmentDeletionDto (com.sequenceiq.environment.environment.dto.EnvironmentDeletionDto)38 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)34 EnvDeleteEvent (com.sequenceiq.environment.environment.flow.deletion.event.EnvDeleteEvent)23 CommonContext (com.sequenceiq.flow.core.CommonContext)12 Map (java.util.Map)12 Bean (org.springframework.context.annotation.Bean)12 BeforeEach (org.junit.jupiter.api.BeforeEach)8 BaseNamedFlowEvent (com.sequenceiq.flow.reactor.api.event.BaseNamedFlowEvent)4 Test (org.junit.jupiter.api.Test)4 Environment (com.sequenceiq.environment.environment.domain.Environment)3 EnvClusterDeleteFailedEvent (com.sequenceiq.environment.environment.flow.deletion.event.EnvClusterDeleteFailedEvent)3 DescribeFreeIpaResponse (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse)3 ResourceEvent (com.sequenceiq.cloudbreak.event.ResourceEvent)2 EnvironmentStatus (com.sequenceiq.environment.environment.EnvironmentStatus)2 PollingConfig (com.sequenceiq.environment.util.PollingConfig)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Headers (reactor.bus.Event.Headers)2 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)1 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)1 ExceptionResponse (com.sequenceiq.cloudbreak.common.exception.ExceptionResponse)1