Search in sources :

Example 1 with EnvClusterDeleteFailedEvent

use of com.sequenceiq.environment.environment.flow.deletion.event.EnvClusterDeleteFailedEvent in project cloudbreak by hortonworks.

the class ExperienceDeletionHandlerTest method testAcceptWhenDeleteActionThrowsExceptionThenEventSenderShouldAcceptEnvDeleteFailedEvent.

@Test
void testAcceptWhenDeleteActionThrowsExceptionThenEventSenderShouldAcceptEnvDeleteFailedEvent() {
    Environment env = new Environment();
    when(mockEntitlementService.isExperienceDeletionEnabled(TEST_ACCOUNT_ID)).thenReturn(true);
    when(mockEnvironmentService.findEnvironmentById(TEST_ENV_ID)).thenReturn(Optional.of(env));
    doThrow(new RuntimeException()).when(mockEnvironmentExperienceDeletionAction).execute(any(Environment.class), anyBoolean());
    underTest.accept(mockEnvironmentDeletionDtoEvent);
    verify(mockEnvironmentExperienceDeletionAction, times(ONCE)).execute(any(), anyBoolean());
    verify(mockEnvironmentExperienceDeletionAction, times(ONCE)).execute(env, true);
    verify(mockEventSender, times(ONCE)).sendEvent(any(EnvClusterDeleteFailedEvent.class), eq(mockEventHeaders));
    verify(mockEventSender, never()).sendEvent(any(EnvDeleteEvent.class), any());
    EnvClusterDeleteFailedEvent capturedDeleteEvent = (EnvClusterDeleteFailedEvent) baseNamedFlowEvent.getValue();
    assertThat(capturedDeleteEvent.getResourceName()).isEqualTo(TEST_ENV_NAME);
    assertThat(capturedDeleteEvent.getResourceId()).isEqualTo(TEST_ENV_ID);
    assertThat(capturedDeleteEvent.getResourceCrn()).isEqualTo(TEST_ENV_CRN);
    assertThat(capturedDeleteEvent.selector()).isEqualTo("FAILED_ENV_CLUSTERS_DELETE_EVENT");
}
Also used : EnvDeleteEvent(com.sequenceiq.environment.environment.flow.deletion.event.EnvDeleteEvent) Environment(com.sequenceiq.environment.environment.domain.Environment) EnvClusterDeleteFailedEvent(com.sequenceiq.environment.environment.flow.deletion.event.EnvClusterDeleteFailedEvent) Test(org.junit.jupiter.api.Test)

Example 2 with EnvClusterDeleteFailedEvent

use of com.sequenceiq.environment.environment.flow.deletion.event.EnvClusterDeleteFailedEvent in project cloudbreak by hortonworks.

the class DataLakeClustersDeleteHandlerTest method acceptFail.

@Test
void acceptFail() {
    IllegalStateException error = new IllegalStateException("error");
    when(environmentViewService.getById(ENV_ID)).thenThrow(error);
    underTest.accept(environmentDtoEvent);
    verify(sdxDeleteService, never()).deleteSdxClustersForEnvironment(any(), any(), anyBoolean());
    verify(eventSender).sendEvent(any(EnvClusterDeleteFailedEvent.class), eq(headers));
    verify(eventSender, never()).sendEvent(any(EnvDeleteEvent.class), any());
    EnvClusterDeleteFailedEvent capturedDeleteFailedEvent = (EnvClusterDeleteFailedEvent) baseNamedFlowEvent.getValue();
    assertThat(capturedDeleteFailedEvent.getResourceName()).isEqualTo(ENV_NAME);
    assertThat(capturedDeleteFailedEvent.getResourceId()).isEqualTo(ENV_ID);
    assertThat(capturedDeleteFailedEvent.getResourceCrn()).isEqualTo(RESOURCE_CRN);
    assertThat(capturedDeleteFailedEvent.selector()).isEqualTo("FAILED_ENV_CLUSTERS_DELETE_EVENT");
    assertThat(capturedDeleteFailedEvent.getException()).isEqualTo(error);
}
Also used : EnvDeleteEvent(com.sequenceiq.environment.environment.flow.deletion.event.EnvDeleteEvent) EnvClusterDeleteFailedEvent(com.sequenceiq.environment.environment.flow.deletion.event.EnvClusterDeleteFailedEvent) Test(org.junit.jupiter.api.Test)

Example 3 with EnvClusterDeleteFailedEvent

use of com.sequenceiq.environment.environment.flow.deletion.event.EnvClusterDeleteFailedEvent in project cloudbreak by hortonworks.

the class DataHubClusterDeletionHandlerTest method acceptFail.

@Test
void acceptFail() {
    IllegalStateException error = new IllegalStateException("error");
    when(environmentService.findEnvironmentById(ENV_ID)).thenThrow(error);
    underTest.accept(environmentDtoEvent);
    verify(datahubDeletionService, never()).deleteDatahubClustersForEnvironment(any(), any(), anyBoolean());
    verify(eventSender).sendEvent(any(EnvClusterDeleteFailedEvent.class), eq(headers));
    verify(eventSender, never()).sendEvent(any(EnvDeleteEvent.class), any());
    EnvClusterDeleteFailedEvent capturedDeleteFailedEvent = (EnvClusterDeleteFailedEvent) baseNamedFlowEvent.getValue();
    assertThat(capturedDeleteFailedEvent.getResourceName()).isEqualTo(ENV_NAME);
    assertThat(capturedDeleteFailedEvent.getResourceId()).isEqualTo(ENV_ID);
    assertThat(capturedDeleteFailedEvent.getResourceCrn()).isEqualTo(RESOURCE_CRN);
    assertThat(capturedDeleteFailedEvent.selector()).isEqualTo("FAILED_ENV_CLUSTERS_DELETE_EVENT");
    assertThat(capturedDeleteFailedEvent.getException()).isEqualTo(error);
}
Also used : EnvDeleteEvent(com.sequenceiq.environment.environment.flow.deletion.event.EnvDeleteEvent) EnvClusterDeleteFailedEvent(com.sequenceiq.environment.environment.flow.deletion.event.EnvClusterDeleteFailedEvent) Test(org.junit.jupiter.api.Test)

Example 4 with EnvClusterDeleteFailedEvent

use of com.sequenceiq.environment.environment.flow.deletion.event.EnvClusterDeleteFailedEvent 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 5 with EnvClusterDeleteFailedEvent

use of com.sequenceiq.environment.environment.flow.deletion.event.EnvClusterDeleteFailedEvent 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)

Aggregations

EnvClusterDeleteFailedEvent (com.sequenceiq.environment.environment.flow.deletion.event.EnvClusterDeleteFailedEvent)7 EnvDeleteEvent (com.sequenceiq.environment.environment.flow.deletion.event.EnvDeleteEvent)6 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)4 EnvironmentDeletionDto (com.sequenceiq.environment.environment.dto.EnvironmentDeletionDto)3 Test (org.junit.jupiter.api.Test)3 Environment (com.sequenceiq.environment.environment.domain.Environment)2 PollingConfig (com.sequenceiq.environment.util.PollingConfig)2 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)1 ExceptionResponse (com.sequenceiq.cloudbreak.common.exception.ExceptionResponse)1 EnvironmentView (com.sequenceiq.environment.environment.domain.EnvironmentView)1 CommonContext (com.sequenceiq.flow.core.CommonContext)1 Flow (com.sequenceiq.flow.core.Flow)1 FlowParameters (com.sequenceiq.flow.core.FlowParameters)1 Map (java.util.Map)1 ClientErrorException (javax.ws.rs.ClientErrorException)1 Bean (org.springframework.context.annotation.Bean)1 StateContext (org.springframework.statemachine.StateContext)1