Search in sources :

Example 1 with StackDeletionWaitRequest

use of com.sequenceiq.datalake.flow.delete.event.StackDeletionWaitRequest in project cloudbreak by hortonworks.

the class StackDeletionHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<StackDeletionWaitRequest> event) {
    StackDeletionWaitRequest stackDeletionWaitRequest = event.getData();
    Long sdxId = stackDeletionWaitRequest.getResourceId();
    String userId = stackDeletionWaitRequest.getUserId();
    Selectable response;
    try {
        LOGGER.debug("Start polling stack deletion process for id: {}", sdxId);
        PollingConfig pollingConfig = new PollingConfig(sleepTimeInSec, TimeUnit.SECONDS, durationInMinutes, TimeUnit.MINUTES);
        provisionerService.waitCloudbreakClusterDeletion(sdxId, pollingConfig);
        response = new StackDeletionSuccessEvent(sdxId, userId, stackDeletionWaitRequest.isForced());
    } catch (UserBreakException userBreakException) {
        LOGGER.error("Deletion polling exited before timeout. Cause: ", userBreakException);
        response = new SdxDeletionFailedEvent(sdxId, userId, userBreakException, stackDeletionWaitRequest.isForced());
    } catch (PollerStoppedException pollerStoppedException) {
        LOGGER.error("Deletion poller stopped for stack: {}", sdxId);
        response = new SdxDeletionFailedEvent(sdxId, userId, new PollerStoppedException("Datalake stack deletion timed out after " + durationInMinutes + " minutes"), stackDeletionWaitRequest.isForced());
    } catch (PollerException exception) {
        LOGGER.error("Deletion polling failed for stack: {}", sdxId);
        response = new SdxDeletionFailedEvent(sdxId, userId, exception, stackDeletionWaitRequest.isForced());
    }
    return response;
}
Also used : UserBreakException(com.dyngr.exception.UserBreakException) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) PollerException(com.dyngr.exception.PollerException) SdxDeletionFailedEvent(com.sequenceiq.datalake.flow.delete.event.SdxDeletionFailedEvent) StackDeletionWaitRequest(com.sequenceiq.datalake.flow.delete.event.StackDeletionWaitRequest) PollingConfig(com.sequenceiq.datalake.service.sdx.PollingConfig) PollerStoppedException(com.dyngr.exception.PollerStoppedException) StackDeletionSuccessEvent(com.sequenceiq.datalake.flow.delete.event.StackDeletionSuccessEvent)

Example 2 with StackDeletionWaitRequest

use of com.sequenceiq.datalake.flow.delete.event.StackDeletionWaitRequest in project cloudbreak by hortonworks.

the class StackDeletionHandlerTest method acceptTestStackDeletionFailed.

@Test
void acceptTestStackDeletionFailed() {
    long id = 2L;
    StackDeletionWaitRequest stackCreationWaitRequest = new StackDeletionWaitRequest(id, userId, true);
    Event receivedEvent = new Event<>(stackCreationWaitRequest);
    doThrow(new UserBreakException("stack deletion failed")).when(provisionerService).waitCloudbreakClusterDeletion(eq(id), any(PollingConfig.class));
    stackDeletionHandler.accept(receivedEvent);
    verify(provisionerService, times(1)).waitCloudbreakClusterDeletion(eq(id), any(PollingConfig.class));
    final ArgumentCaptor<String> eventSelector = ArgumentCaptor.forClass(String.class);
    final ArgumentCaptor<Event> sentEvent = ArgumentCaptor.forClass(Event.class);
    verify(eventBus, times(1)).notify(eventSelector.capture(), sentEvent.capture());
    String eventNotified = eventSelector.getValue();
    Event event = sentEvent.getValue();
    Assertions.assertEquals("SdxDeletionFailedEvent", eventNotified);
    Assertions.assertEquals(SdxDeletionFailedEvent.class, event.getData().getClass());
    Assertions.assertEquals(id, ((SdxDeletionFailedEvent) event.getData()).getResourceId());
}
Also used : UserBreakException(com.dyngr.exception.UserBreakException) Event(reactor.bus.Event) SdxDeletionFailedEvent(com.sequenceiq.datalake.flow.delete.event.SdxDeletionFailedEvent) StackDeletionSuccessEvent(com.sequenceiq.datalake.flow.delete.event.StackDeletionSuccessEvent) StackDeletionWaitRequest(com.sequenceiq.datalake.flow.delete.event.StackDeletionWaitRequest) PollingConfig(com.sequenceiq.datalake.service.sdx.PollingConfig) Test(org.junit.jupiter.api.Test)

Example 3 with StackDeletionWaitRequest

use of com.sequenceiq.datalake.flow.delete.event.StackDeletionWaitRequest in project cloudbreak by hortonworks.

the class StackDeletionHandlerTest method acceptTestPollerStackTimeout.

@Test
void acceptTestPollerStackTimeout() {
    long id = 2L;
    StackDeletionWaitRequest stackCreationWaitRequest = new StackDeletionWaitRequest(id, userId, true);
    Event receivedEvent = new Event<>(stackCreationWaitRequest);
    doThrow(new PollerStoppedException("stack deletion timeout")).when(provisionerService).waitCloudbreakClusterDeletion(eq(id), any(PollingConfig.class));
    stackDeletionHandler.accept(receivedEvent);
    verify(provisionerService, times(1)).waitCloudbreakClusterDeletion(eq(id), any(PollingConfig.class));
    final ArgumentCaptor<String> eventSelector = ArgumentCaptor.forClass(String.class);
    final ArgumentCaptor<Event> sentEvent = ArgumentCaptor.forClass(Event.class);
    verify(eventBus, times(1)).notify(eventSelector.capture(), sentEvent.capture());
    String eventNotified = eventSelector.getValue();
    Event event = sentEvent.getValue();
    Assertions.assertEquals("SdxDeletionFailedEvent", eventNotified);
    Assertions.assertEquals(SdxDeletionFailedEvent.class, event.getData().getClass());
    Assertions.assertEquals(id, ((SdxDeletionFailedEvent) event.getData()).getResourceId());
}
Also used : Event(reactor.bus.Event) SdxDeletionFailedEvent(com.sequenceiq.datalake.flow.delete.event.SdxDeletionFailedEvent) StackDeletionSuccessEvent(com.sequenceiq.datalake.flow.delete.event.StackDeletionSuccessEvent) StackDeletionWaitRequest(com.sequenceiq.datalake.flow.delete.event.StackDeletionWaitRequest) PollingConfig(com.sequenceiq.datalake.service.sdx.PollingConfig) PollerStoppedException(com.dyngr.exception.PollerStoppedException) Test(org.junit.jupiter.api.Test)

Example 4 with StackDeletionWaitRequest

use of com.sequenceiq.datalake.flow.delete.event.StackDeletionWaitRequest in project cloudbreak by hortonworks.

the class StackDeletionHandlerTest method acceptTestPollerStackOtherError.

@Test
void acceptTestPollerStackOtherError() {
    long id = 2L;
    StackDeletionWaitRequest stackCreationWaitRequest = new StackDeletionWaitRequest(id, userId, true);
    Event receivedEvent = new Event<>(stackCreationWaitRequest);
    doThrow(new PollerException("stack deletion error")).when(provisionerService).waitCloudbreakClusterDeletion(eq(id), any(PollingConfig.class));
    stackDeletionHandler.accept(receivedEvent);
    verify(provisionerService, times(1)).waitCloudbreakClusterDeletion(eq(id), any(PollingConfig.class));
    final ArgumentCaptor<String> eventSelector = ArgumentCaptor.forClass(String.class);
    final ArgumentCaptor<Event> sentEvent = ArgumentCaptor.forClass(Event.class);
    verify(eventBus, times(1)).notify(eventSelector.capture(), sentEvent.capture());
    String eventNotified = eventSelector.getValue();
    Event event = sentEvent.getValue();
    Assertions.assertEquals("SdxDeletionFailedEvent", eventNotified);
    Assertions.assertEquals(SdxDeletionFailedEvent.class, event.getData().getClass());
    Assertions.assertEquals(id, ((SdxDeletionFailedEvent) event.getData()).getResourceId());
}
Also used : PollerException(com.dyngr.exception.PollerException) Event(reactor.bus.Event) SdxDeletionFailedEvent(com.sequenceiq.datalake.flow.delete.event.SdxDeletionFailedEvent) StackDeletionSuccessEvent(com.sequenceiq.datalake.flow.delete.event.StackDeletionSuccessEvent) StackDeletionWaitRequest(com.sequenceiq.datalake.flow.delete.event.StackDeletionWaitRequest) PollingConfig(com.sequenceiq.datalake.service.sdx.PollingConfig) Test(org.junit.jupiter.api.Test)

Example 5 with StackDeletionWaitRequest

use of com.sequenceiq.datalake.flow.delete.event.StackDeletionWaitRequest in project cloudbreak by hortonworks.

the class StackDeletionHandlerTest method acceptTestStackDeletionSuccess.

@Test
void acceptTestStackDeletionSuccess() {
    long id = 2L;
    StackDeletionWaitRequest stackCreationWaitRequest = new StackDeletionWaitRequest(id, userId, true);
    Event receivedEvent = new Event<>(stackCreationWaitRequest);
    doNothing().when(provisionerService).waitCloudbreakClusterDeletion(eq(id), any(PollingConfig.class));
    stackDeletionHandler.accept(receivedEvent);
    verify(provisionerService, times(1)).waitCloudbreakClusterDeletion(eq(id), any(PollingConfig.class));
    final ArgumentCaptor<String> eventSelector = ArgumentCaptor.forClass(String.class);
    final ArgumentCaptor<Event> sentEvent = ArgumentCaptor.forClass(Event.class);
    verify(eventBus, times(1)).notify(eventSelector.capture(), sentEvent.capture());
    String eventNotified = eventSelector.getValue();
    Event event = sentEvent.getValue();
    Assertions.assertEquals("StackDeletionSuccessEvent", eventNotified);
    Assertions.assertEquals(StackDeletionSuccessEvent.class, event.getData().getClass());
    Assertions.assertEquals(id, ((StackDeletionSuccessEvent) event.getData()).getResourceId());
}
Also used : Event(reactor.bus.Event) SdxDeletionFailedEvent(com.sequenceiq.datalake.flow.delete.event.SdxDeletionFailedEvent) StackDeletionSuccessEvent(com.sequenceiq.datalake.flow.delete.event.StackDeletionSuccessEvent) StackDeletionWaitRequest(com.sequenceiq.datalake.flow.delete.event.StackDeletionWaitRequest) PollingConfig(com.sequenceiq.datalake.service.sdx.PollingConfig) Test(org.junit.jupiter.api.Test)

Aggregations

SdxDeletionFailedEvent (com.sequenceiq.datalake.flow.delete.event.SdxDeletionFailedEvent)5 StackDeletionSuccessEvent (com.sequenceiq.datalake.flow.delete.event.StackDeletionSuccessEvent)5 StackDeletionWaitRequest (com.sequenceiq.datalake.flow.delete.event.StackDeletionWaitRequest)5 PollingConfig (com.sequenceiq.datalake.service.sdx.PollingConfig)5 Test (org.junit.jupiter.api.Test)4 Event (reactor.bus.Event)4 PollerException (com.dyngr.exception.PollerException)2 PollerStoppedException (com.dyngr.exception.PollerStoppedException)2 UserBreakException (com.dyngr.exception.UserBreakException)2 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)1