Search in sources :

Example 1 with RdsDeletionSuccessEvent

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

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

the class SdxDeleteActions method finishedAction.

@Bean(name = "SDX_DELETION_FINISHED_STATE")
public Action<?, ?> finishedAction() {
    return new AbstractSdxAction<>(RdsDeletionSuccessEvent.class) {

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

        @Override
        protected void doExecute(SdxContext context, RdsDeletionSuccessEvent payload, Map<Object, Object> variables) throws Exception {
            Long datalakeId = payload.getResourceId();
            LOGGER.info("Datalake delete finalized: {}", datalakeId);
            SdxCluster sdxCluster = sdxService.getById(datalakeId);
            if (sdxCluster != null) {
                metricService.incrementMetricCounter(MetricType.SDX_DELETION_FINISHED, sdxCluster);
            }
            eventSenderService.notifyEvent(context, ResourceEvent.SDX_CLUSTER_DELETION_FINISHED);
            sendEvent(context, SDX_DELETE_FINALIZED_EVENT.event(), payload);
        }

        @Override
        protected Object getFailurePayload(RdsDeletionSuccessEvent 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) RdsDeletionSuccessEvent(com.sequenceiq.datalake.flow.delete.event.RdsDeletionSuccessEvent) Map(java.util.Map) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Bean(org.springframework.context.annotation.Bean)

Aggregations

NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)2 RdsDeletionSuccessEvent (com.sequenceiq.datalake.flow.delete.event.RdsDeletionSuccessEvent)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 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)1 SdxContext (com.sequenceiq.datalake.flow.SdxContext)1 RdsDeletionWaitRequest (com.sequenceiq.datalake.flow.delete.event.RdsDeletionWaitRequest)1 SdxDeletionFailedEvent (com.sequenceiq.datalake.flow.delete.event.SdxDeletionFailedEvent)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 StateContext (org.springframework.statemachine.StateContext)1