Search in sources :

Example 1 with StackDeletionSuccessEvent

use of com.sequenceiq.datalake.flow.delete.event.StackDeletionSuccessEvent 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 StackDeletionSuccessEvent

use of com.sequenceiq.datalake.flow.delete.event.StackDeletionSuccessEvent 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)2 StackDeletionSuccessEvent (com.sequenceiq.datalake.flow.delete.event.StackDeletionSuccessEvent)2 StackDeletionWaitRequest (com.sequenceiq.datalake.flow.delete.event.StackDeletionWaitRequest)2 PollingConfig (com.sequenceiq.datalake.service.sdx.PollingConfig)2 PollerException (com.dyngr.exception.PollerException)1 PollerStoppedException (com.dyngr.exception.PollerStoppedException)1 UserBreakException (com.dyngr.exception.UserBreakException)1 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)1 Test (org.junit.jupiter.api.Test)1 Event (reactor.bus.Event)1