Search in sources :

Example 1 with DatalakeDatabaseRestoreFailedEvent

use of com.sequenceiq.datalake.flow.dr.restore.event.DatalakeDatabaseRestoreFailedEvent in project cloudbreak by hortonworks.

the class DatalakeDatabaseRestoreWaitHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<DatalakeDatabaseRestoreWaitRequest> event) {
    DatalakeDatabaseRestoreWaitRequest request = event.getData();
    Long sdxId = request.getResourceId();
    String userId = request.getUserId();
    Selectable response;
    try {
        LOGGER.info("Start polling datalake database restore for id: {}", sdxId);
        PollingConfig pollingConfig = new PollingConfig(sleepTimeInSec, TimeUnit.SECONDS, durationInMinutes, TimeUnit.MINUTES);
        sdxBackupRestoreService.waitCloudbreakFlow(sdxId, pollingConfig, "Database restore");
        response = new DatalakeFullRestoreInProgressEvent(sdxId, userId, request.getOperationId());
    } catch (UserBreakException userBreakException) {
        LOGGER.info("Database restore polling exited before timeout. Cause: ", userBreakException);
        sdxBackupRestoreService.updateDatabaseStatusEntry(event.getData().getOperationId(), SdxOperationStatus.FAILED, userBreakException.getLocalizedMessage());
        response = new DatalakeDatabaseRestoreFailedEvent(sdxId, userId, userBreakException);
    } catch (PollerStoppedException pollerStoppedException) {
        LOGGER.info("Database restore poller stopped for cluster: {}", sdxId);
        sdxBackupRestoreService.updateDatabaseStatusEntry(event.getData().getOperationId(), SdxOperationStatus.FAILED, pollerStoppedException.getLocalizedMessage());
        response = new DatalakeDatabaseRestoreFailedEvent(sdxId, userId, new PollerStoppedException("Database restore timed out after " + durationInMinutes + " minutes"));
    } catch (PollerException exception) {
        LOGGER.info("Database restore polling failed for cluster: {}", sdxId);
        sdxBackupRestoreService.updateDatabaseStatusEntry(event.getData().getOperationId(), SdxOperationStatus.FAILED, exception.getLocalizedMessage());
        response = new DatalakeDatabaseRestoreFailedEvent(sdxId, userId, exception);
    }
    return response;
}
Also used : DatalakeFullRestoreInProgressEvent(com.sequenceiq.datalake.flow.dr.restore.event.DatalakeFullRestoreInProgressEvent) UserBreakException(com.dyngr.exception.UserBreakException) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) DatalakeDatabaseRestoreFailedEvent(com.sequenceiq.datalake.flow.dr.restore.event.DatalakeDatabaseRestoreFailedEvent) PollerException(com.dyngr.exception.PollerException) DatalakeDatabaseRestoreWaitRequest(com.sequenceiq.datalake.flow.dr.restore.event.DatalakeDatabaseRestoreWaitRequest) PollingConfig(com.sequenceiq.datalake.service.sdx.PollingConfig) PollerStoppedException(com.dyngr.exception.PollerStoppedException)

Example 2 with DatalakeDatabaseRestoreFailedEvent

use of com.sequenceiq.datalake.flow.dr.restore.event.DatalakeDatabaseRestoreFailedEvent in project cloudbreak by hortonworks.

the class DatalakeRestoreActions method databaseRestoreFailed.

@Bean(name = "DATALAKE_DATABASE_RESTORE_FAILED_STATE")
public Action<?, ?> databaseRestoreFailed() {
    return new AbstractSdxAction<>(DatalakeDatabaseRestoreFailedEvent.class) {

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

        @Override
        protected void doExecute(SdxContext context, DatalakeDatabaseRestoreFailedEvent payload, Map<Object, Object> variables) {
            Exception exception = payload.getException();
            LOGGER.error("Datalake database restore could not be started for datalake with id: {}", payload.getResourceId(), exception);
            String operationId = (String) variables.get(OPERATION_ID);
            sdxBackupRestoreService.updateDatabaseStatusEntry(operationId, SdxOperationStatus.FAILED, exception.getLocalizedMessage());
            Flow flow = getFlow(context.getFlowParameters().getFlowId());
            flow.setFlowFailed(payload.getException());
            sendEvent(context, DATALAKE_DATABASE_RESTORE_FAILURE_HANDLED_EVENT.event(), payload);
        }

        @Override
        protected Object getFailurePayload(DatalakeDatabaseRestoreFailedEvent payload, Optional<SdxContext> flowContext, Exception ex) {
            return DatalakeDatabaseRestoreFailedEvent.from(payload, ex);
        }
    };
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) AbstractSdxAction(com.sequenceiq.datalake.service.AbstractSdxAction) Optional(java.util.Optional) DatalakeDatabaseRestoreFailedEvent(com.sequenceiq.datalake.flow.dr.restore.event.DatalakeDatabaseRestoreFailedEvent) StateContext(org.springframework.statemachine.StateContext) Map(java.util.Map) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Flow(com.sequenceiq.flow.core.Flow) Bean(org.springframework.context.annotation.Bean)

Aggregations

DatalakeDatabaseRestoreFailedEvent (com.sequenceiq.datalake.flow.dr.restore.event.DatalakeDatabaseRestoreFailedEvent)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 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)1 SdxContext (com.sequenceiq.datalake.flow.SdxContext)1 DatalakeDatabaseRestoreWaitRequest (com.sequenceiq.datalake.flow.dr.restore.event.DatalakeDatabaseRestoreWaitRequest)1 DatalakeFullRestoreInProgressEvent (com.sequenceiq.datalake.flow.dr.restore.event.DatalakeFullRestoreInProgressEvent)1 AbstractSdxAction (com.sequenceiq.datalake.service.AbstractSdxAction)1 PollingConfig (com.sequenceiq.datalake.service.sdx.PollingConfig)1 Flow (com.sequenceiq.flow.core.Flow)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