Search in sources :

Example 1 with SdxDeletionFailedEvent

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

the class RdsDeletionHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<RdsDeletionWaitRequest> event) {
    RdsDeletionWaitRequest rdsWaitRequest = event.getData();
    Long sdxId = rdsWaitRequest.getResourceId();
    String userId = rdsWaitRequest.getUserId();
    Selectable response;
    try {
        sdxClusterRepository.findById(sdxId).ifPresent(sdxCluster -> {
            if (sdxCluster.hasExternalDatabase() && StringUtils.isNotEmpty(sdxCluster.getDatabaseCrn())) {
                LOGGER.debug("start polling database termination for sdx: {}", sdxId);
                databaseService.terminate(sdxCluster, rdsWaitRequest.isForced());
            } else {
                LOGGER.debug("skipping deletion of database for sdx: {}", sdxId);
            }
            setDeletedStatus(sdxCluster);
        });
        response = new RdsDeletionSuccessEvent(sdxId, userId);
    } catch (UserBreakException userBreakException) {
        LOGGER.error("Database polling exited before timeout. Cause: ", userBreakException);
        response = new SdxDeletionFailedEvent(sdxId, userId, userBreakException, rdsWaitRequest.isForced());
    } catch (PollerStoppedException pollerStoppedException) {
        LOGGER.error("Database poller stopped for sdx: {}", sdxId, pollerStoppedException);
        response = new SdxDeletionFailedEvent(sdxId, userId, new PollerStoppedException("Database deletion timed out after " + durationInMinutes + " minutes"), rdsWaitRequest.isForced());
    } catch (PollerException exception) {
        LOGGER.error("Database polling failed for sdx: {}", sdxId, exception);
        response = new SdxDeletionFailedEvent(sdxId, userId, exception, rdsWaitRequest.isForced());
    } catch (Exception anotherException) {
        LOGGER.error("Something wrong happened in sdx database deletion wait phase", anotherException);
        response = new SdxDeletionFailedEvent(sdxId, userId, anotherException, rdsWaitRequest.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) RdsDeletionSuccessEvent(com.sequenceiq.datalake.flow.delete.event.RdsDeletionSuccessEvent) RdsDeletionWaitRequest(com.sequenceiq.datalake.flow.delete.event.RdsDeletionWaitRequest) PollerStoppedException(com.dyngr.exception.PollerStoppedException) UserBreakException(com.dyngr.exception.UserBreakException) PollerException(com.dyngr.exception.PollerException) PollerStoppedException(com.dyngr.exception.PollerStoppedException) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException)

Example 2 with SdxDeletionFailedEvent

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

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

the class SdxDeleteActions method failedAction.

@Bean(name = "SDX_DELETION_FAILED_STATE")
public Action<?, ?> failedAction() {
    return new AbstractSdxAction<>(SdxDeletionFailedEvent.class) {

        @Override
        protected SdxContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, SdxDeletionFailedEvent payload) {
            return SdxContext.from(flowParameters, payload);
        }

        @Override
        protected void doExecute(SdxContext context, SdxDeletionFailedEvent payload, Map<Object, Object> variables) throws Exception {
            Exception exception = payload.getException();
            String statusReason = "Datalake deletion failed";
            String errorMessage = webApplicationExceptionMessageExtractor.getErrorMessage(exception);
            if (StringUtils.hasText(errorMessage)) {
                statusReason = statusReason + ". " + errorMessage;
            } else if (exception.getMessage() != null) {
                statusReason = statusReason + ". " + exception.getMessage();
            }
            LOGGER.error(statusReason, exception);
            try {
                SdxCluster sdxCluster = sdxStatusService.setStatusForDatalakeAndNotify(DatalakeStatusEnum.DELETE_FAILED, statusReason, payload.getResourceId());
                metricService.incrementMetricCounter(MetricType.SDX_DELETION_FAILED, sdxCluster);
                if (sdxCluster.isDetached()) {
                    eventSenderService.sendEventAndNotification(sdxCluster, context.getFlowTriggerUserCrn(), ResourceEvent.SDX_DETACHED_CLUSTER_DELETION_FAILED, List.of(sdxCluster.getClusterName()));
                } else {
                    eventSenderService.notifyEvent(context, ResourceEvent.SDX_CLUSTER_DELETION_FAILED);
                }
            } catch (NotFoundException notFoundException) {
                LOGGER.info("Can not set status to SDX_DELETION_FAILED because data lake was not found");
            }
            sendEvent(context, SDX_DELETE_FAILED_HANDLED_EVENT.event(), payload);
        }

        @Override
        protected Object getFailurePayload(SdxDeletionFailedEvent payload, Optional<SdxContext> flowContext, Exception ex) {
            return null;
        }
    };
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) AbstractSdxAction(com.sequenceiq.datalake.service.AbstractSdxAction) Optional(java.util.Optional) StateContext(org.springframework.statemachine.StateContext) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) SdxDeletionFailedEvent(com.sequenceiq.datalake.flow.delete.event.SdxDeletionFailedEvent) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) Map(java.util.Map) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Bean(org.springframework.context.annotation.Bean)

Example 4 with SdxDeletionFailedEvent

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

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

Aggregations

SdxDeletionFailedEvent (com.sequenceiq.datalake.flow.delete.event.SdxDeletionFailedEvent)6 StackDeletionSuccessEvent (com.sequenceiq.datalake.flow.delete.event.StackDeletionSuccessEvent)4 StackDeletionWaitRequest (com.sequenceiq.datalake.flow.delete.event.StackDeletionWaitRequest)4 PollingConfig (com.sequenceiq.datalake.service.sdx.PollingConfig)4 PollerException (com.dyngr.exception.PollerException)3 PollerStoppedException (com.dyngr.exception.PollerStoppedException)3 UserBreakException (com.dyngr.exception.UserBreakException)3 Test (org.junit.jupiter.api.Test)3 Event (reactor.bus.Event)3 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)2 NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)2 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)1 SdxContext (com.sequenceiq.datalake.flow.SdxContext)1 RdsDeletionSuccessEvent (com.sequenceiq.datalake.flow.delete.event.RdsDeletionSuccessEvent)1 RdsDeletionWaitRequest (com.sequenceiq.datalake.flow.delete.event.RdsDeletionWaitRequest)1 AbstractSdxAction (com.sequenceiq.datalake.service.AbstractSdxAction)1 FlowParameters (com.sequenceiq.flow.core.FlowParameters)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Bean (org.springframework.context.annotation.Bean)1