Search in sources :

Example 1 with DatalakeRestoreFailedEvent

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

the class DatalakeFullRestoreWaitHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<DatalakeFullRestoreWaitRequest> event) {
    DatalakeFullRestoreWaitRequest request = event.getData();
    Long sdxId = request.getResourceId();
    String userId = request.getUserId();
    Selectable response;
    try {
        LOGGER.info("Start polling datalake full restore status for id: {}", sdxId);
        PollingConfig pollingConfig = new PollingConfig(sleepTimeInSec, TimeUnit.SECONDS, durationInMinutes, TimeUnit.MINUTES);
        sdxBackupRestoreService.waitForDatalakeDrRestoreToComplete(sdxId, request.getOperationId(), request.getUserId(), pollingConfig, "Full restore");
        response = new DatalakeRestoreSuccessEvent(sdxId, userId, request.getOperationId());
    } catch (UserBreakException userBreakException) {
        LOGGER.info("Full restore polling exited before timeout. Cause: ", userBreakException);
        response = new DatalakeRestoreFailedEvent(sdxId, userId, userBreakException);
    } catch (PollerStoppedException pollerStoppedException) {
        LOGGER.info("Full restore poller stopped for cluster: {}", sdxId);
        response = new DatalakeRestoreFailedEvent(sdxId, userId, new PollerStoppedException("Data lake restore timed out after " + durationInMinutes + " minutes"));
    } catch (PollerException exception) {
        LOGGER.info("Full restore polling failed for cluster: {}", sdxId);
        response = new DatalakeRestoreFailedEvent(sdxId, userId, exception);
    } catch (CloudbreakApiException exception) {
        LOGGER.info("Datalake restore failed. Reason: " + exception.getMessage());
        response = new DatalakeRestoreFailedEvent(sdxId, userId, exception);
    }
    return response;
}
Also used : DatalakeRestoreSuccessEvent(com.sequenceiq.datalake.flow.dr.restore.event.DatalakeRestoreSuccessEvent) UserBreakException(com.dyngr.exception.UserBreakException) DatalakeRestoreFailedEvent(com.sequenceiq.datalake.flow.dr.restore.event.DatalakeRestoreFailedEvent) DatalakeFullRestoreWaitRequest(com.sequenceiq.datalake.flow.dr.restore.event.DatalakeFullRestoreWaitRequest) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) PollerException(com.dyngr.exception.PollerException) PollingConfig(com.sequenceiq.datalake.service.sdx.PollingConfig) CloudbreakApiException(com.sequenceiq.cloudbreak.exception.CloudbreakApiException) PollerStoppedException(com.dyngr.exception.PollerStoppedException)

Example 2 with DatalakeRestoreFailedEvent

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

the class DatalakeRestoreActions method restoreFailed.

@Bean(name = "DATALAKE_RESTORE_FAILED_STATE")
public Action<?, ?> restoreFailed() {
    return new AbstractSdxAction<>(DatalakeRestoreFailedEvent.class) {

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

        @Override
        protected void doExecute(SdxContext context, DatalakeRestoreFailedEvent 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);
            SdxCluster sdxCluster = sdxStatusService.setStatusForDatalakeAndNotify(DatalakeStatusEnum.RUNNING, ResourceEvent.DATALAKE_RESTORE_FINISHED, "Datalake is running, Datalake restore failed", payload.getResourceId());
            eventSenderService.sendEventAndNotification(sdxCluster, context.getFlowTriggerUserCrn(), ResourceEvent.DATALAKE_RESTORE_FAILED, List.of(exception.getMessage()));
            Flow flow = getFlow(context.getFlowParameters().getFlowId());
            flow.setFlowFailed(payload.getException());
            metricService.incrementMetricCounter(MetricType.SDX_RESTORE_FAILED, sdxCluster);
            sendEvent(context, DATALAKE_RESTORE_FAILURE_HANDLED_EVENT.event(), payload);
        }

        @Override
        protected Object getFailurePayload(DatalakeRestoreFailedEvent payload, Optional<SdxContext> flowContext, Exception ex) {
            return null;
        }
    };
}
Also used : DatalakeRestoreFailedEvent(com.sequenceiq.datalake.flow.dr.restore.event.DatalakeRestoreFailedEvent) 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) 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

DatalakeRestoreFailedEvent (com.sequenceiq.datalake.flow.dr.restore.event.DatalakeRestoreFailedEvent)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 CloudbreakApiException (com.sequenceiq.cloudbreak.exception.CloudbreakApiException)1 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)1 SdxContext (com.sequenceiq.datalake.flow.SdxContext)1 DatalakeFullRestoreWaitRequest (com.sequenceiq.datalake.flow.dr.restore.event.DatalakeFullRestoreWaitRequest)1 DatalakeRestoreSuccessEvent (com.sequenceiq.datalake.flow.dr.restore.event.DatalakeRestoreSuccessEvent)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