Search in sources :

Example 1 with DatalakeTriggerBackupEvent

use of com.sequenceiq.datalake.flow.dr.backup.event.DatalakeTriggerBackupEvent in project cloudbreak by hortonworks.

the class SdxBackupRestoreService method triggerDatalakeBackupFlow.

private SdxBackupResponse triggerDatalakeBackupFlow(Long clusterId, String backupLocation, String backupName) {
    String selector = DATALAKE_TRIGGER_BACKUP_EVENT.event();
    String userId = ThreadBasedUserCrnProvider.getUserCrn();
    DatalakeTriggerBackupEvent startEvent = new DatalakeTriggerBackupEvent(selector, clusterId, userId, backupLocation, backupName, DatalakeBackupFailureReason.USER_TRIGGERED);
    FlowIdentifier flowIdentifier = sdxReactorFlowManager.triggerDatalakeBackupFlow(startEvent);
    return new SdxBackupResponse(startEvent.getDrStatus().getOperationId(), flowIdentifier);
}
Also used : FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) SdxBackupResponse(com.sequenceiq.sdx.api.model.SdxBackupResponse) DatalakeTriggerBackupEvent(com.sequenceiq.datalake.flow.dr.backup.event.DatalakeTriggerBackupEvent)

Example 2 with DatalakeTriggerBackupEvent

use of com.sequenceiq.datalake.flow.dr.backup.event.DatalakeTriggerBackupEvent in project cloudbreak by hortonworks.

the class DatalakeResizeFlowEventChainFactory method createFlowTriggerEventQueue.

@Override
public FlowTriggerEventQueue createFlowTriggerEventQueue(DatalakeResizeFlowChainStartEvent event) {
    Queue<Selectable> chain = new ConcurrentLinkedQueue<>();
    if (event.shouldTakeBackup()) {
        // Take a backup
        chain.add(new DatalakeTriggerBackupEvent(DATALAKE_TRIGGER_BACKUP_EVENT.event(), event.getResourceId(), event.getUserId(), event.getBackupLocation(), "resize" + System.currentTimeMillis(), DatalakeBackupFailureReason.BACKUP_ON_RESIZE, event.accepted()));
        // Stop datalake
        chain.add(new SdxStartStopEvent(SDX_STOP_EVENT.event(), event.getResourceId(), event.getUserId(), STOP_DATAHUBS));
    } else {
        chain.add(new SdxStartStopEvent(SDX_STOP_EVENT.event(), event.getResourceId(), event.getUserId(), STOP_DATAHUBS, event.accepted()));
    }
    // Detach sdx from environment
    chain.add(new SdxStartDetachEvent(SDX_DETACH_EVENT.event(), event.getResourceId(), event.getSdxCluster(), event.getUserId()));
    // Create new
    chain.add(new SdxEvent(SDX_VALIDATION_EVENT.event(), event.getResourceId(), event.getSdxCluster().getClusterName(), event.getUserId()));
    if (event.shouldPerformRestore()) {
        // restore the new cluster
        chain.add(new DatalakeTriggerRestoreEvent(DATALAKE_TRIGGER_RESTORE_EVENT.event(), event.getResourceId(), event.getSdxCluster().getClusterName(), event.getUserId(), null, event.getBackupLocation(), null, DatalakeRestoreFailureReason.RESTORE_ON_RESIZE));
    }
    // Delete the detached Sdx
    chain.add(new SdxDeleteStartEvent(SDX_DELETE_EVENT.event(), event.getResourceId(), event.getUserId(), true));
    chain.add(new DatahubRefreshStartEvent(event.getResourceId(), event.getSdxCluster().getClusterName(), event.getUserId()));
    return new FlowTriggerEventQueue(getName(), event, chain);
}
Also used : DatalakeTriggerRestoreEvent(com.sequenceiq.datalake.flow.dr.restore.event.DatalakeTriggerRestoreEvent) FlowTriggerEventQueue(com.sequenceiq.flow.core.chain.config.FlowTriggerEventQueue) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) SdxStartStopEvent(com.sequenceiq.datalake.flow.stop.event.SdxStartStopEvent) SdxStartDetachEvent(com.sequenceiq.datalake.flow.detach.event.SdxStartDetachEvent) SdxEvent(com.sequenceiq.datalake.flow.SdxEvent) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) SdxDeleteStartEvent(com.sequenceiq.datalake.flow.delete.event.SdxDeleteStartEvent) DatahubRefreshStartEvent(com.sequenceiq.datalake.flow.refresh.event.DatahubRefreshStartEvent) DatalakeTriggerBackupEvent(com.sequenceiq.datalake.flow.dr.backup.event.DatalakeTriggerBackupEvent)

Example 3 with DatalakeTriggerBackupEvent

use of com.sequenceiq.datalake.flow.dr.backup.event.DatalakeTriggerBackupEvent in project cloudbreak by hortonworks.

the class DatalakeUpgradeFlowEventChainFactory method createFlowTriggerEventQueue.

@Override
public FlowTriggerEventQueue createFlowTriggerEventQueue(DatalakeUpgradeFlowChainStartEvent event) {
    Queue<Selectable> chain = new ConcurrentLinkedQueue<>();
    chain.add(new DatalakeTriggerBackupEvent(DATALAKE_TRIGGER_BACKUP_EVENT.event(), event.getResourceId(), event.getUserId(), event.getBackupLocation(), "", DatalakeBackupFailureReason.BACKUP_ON_UPGRADE, event.accepted()));
    chain.add(new DatalakeUpgradeStartEvent(DATALAKE_UPGRADE_EVENT.event(), event.getResourceId(), event.getUserId(), event.getImageId(), event.getReplaceVms()));
    return new FlowTriggerEventQueue(getName(), event, chain);
}
Also used : FlowTriggerEventQueue(com.sequenceiq.flow.core.chain.config.FlowTriggerEventQueue) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) DatalakeUpgradeStartEvent(com.sequenceiq.datalake.flow.datalake.upgrade.event.DatalakeUpgradeStartEvent) DatalakeTriggerBackupEvent(com.sequenceiq.datalake.flow.dr.backup.event.DatalakeTriggerBackupEvent)

Example 4 with DatalakeTriggerBackupEvent

use of com.sequenceiq.datalake.flow.dr.backup.event.DatalakeTriggerBackupEvent in project cloudbreak by hortonworks.

the class SdxBackupRestoreService method triggerDatalakeBackupFlow.

private SdxBackupResponse triggerDatalakeBackupFlow(SdxCluster cluster, String backupLocation, String backupName) {
    String selector = DATALAKE_TRIGGER_BACKUP_EVENT.event();
    String userId = ThreadBasedUserCrnProvider.getUserCrn();
    DatalakeTriggerBackupEvent startEvent = new DatalakeTriggerBackupEvent(selector, cluster.getId(), userId, backupLocation, backupName, DatalakeBackupFailureReason.USER_TRIGGERED);
    FlowIdentifier flowIdentifier = sdxReactorFlowManager.triggerDatalakeBackupFlow(startEvent, cluster.getClusterName());
    return new SdxBackupResponse(startEvent.getDrStatus().getOperationId(), flowIdentifier);
}
Also used : FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) SdxBackupResponse(com.sequenceiq.sdx.api.model.SdxBackupResponse) DatalakeTriggerBackupEvent(com.sequenceiq.datalake.flow.dr.backup.event.DatalakeTriggerBackupEvent)

Example 5 with DatalakeTriggerBackupEvent

use of com.sequenceiq.datalake.flow.dr.backup.event.DatalakeTriggerBackupEvent in project cloudbreak by hortonworks.

the class DatalakeBackupActions method triggerDatalakeBackup.

@Bean(name = "DATALAKE_TRIGGERING_BACKUP_STATE")
public Action<?, ?> triggerDatalakeBackup() {
    return new AbstractSdxAction<>(DatalakeTriggerBackupEvent.class) {

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

        @Override
        protected void prepareExecution(DatalakeTriggerBackupEvent payload, Map<Object, Object> variables) {
            variables.put(OPERATION_ID, payload.getDrStatus().getOperationId());
            variables.put(REASON, payload.getReason().name());
            super.prepareExecution(payload, variables);
        }

        @Override
        protected void doExecute(SdxContext context, DatalakeTriggerBackupEvent payload, Map<Object, Object> variables) {
            LOGGER.info("Triggering data lake backup for {}", payload.getResourceId());
            SdxCluster sdxCluster = sdxService.getById(payload.getResourceId());
            eventSenderService.sendEventAndNotification(sdxCluster, context.getFlowTriggerUserCrn(), ResourceEvent.DATALAKE_BACKUP_IN_PROGRESS);
            DatalakeBackupStatusResponse backupStatusResponse = sdxBackupRestoreService.triggerDatalakeBackup(payload.getResourceId(), payload.getBackupLocation(), payload.getBackupName(), payload.getUserId());
            variables.put(BACKUP_ID, backupStatusResponse.getBackupId());
            variables.put(OPERATION_ID, backupStatusResponse.getBackupId());
            payload.getDrStatus().setOperationId(backupStatusResponse.getBackupId());
            if (!backupStatusResponse.failed()) {
                sendEvent(context, DatalakeDatabaseBackupStartEvent.from(payload, backupStatusResponse.getBackupId()));
            } else {
                sendEvent(context, DATALAKE_BACKUP_FAILED_EVENT.event(), payload);
            }
        }

        @Override
        protected Object getFailurePayload(DatalakeTriggerBackupEvent payload, Optional<SdxContext> flowContext, Exception ex) {
            return DatalakeBackupFailedEvent.from(payload, ex);
        }
    };
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) AbstractSdxAction(com.sequenceiq.datalake.service.AbstractSdxAction) Optional(java.util.Optional) DatalakeBackupStatusResponse(com.sequenceiq.cloudbreak.datalakedr.model.DatalakeBackupStatusResponse) StateContext(org.springframework.statemachine.StateContext) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) Map(java.util.Map) PollerStoppedException(com.dyngr.exception.PollerStoppedException) DatalakeTriggerBackupEvent(com.sequenceiq.datalake.flow.dr.backup.event.DatalakeTriggerBackupEvent) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Bean(org.springframework.context.annotation.Bean)

Aggregations

DatalakeTriggerBackupEvent (com.sequenceiq.datalake.flow.dr.backup.event.DatalakeTriggerBackupEvent)6 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)3 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)2 FlowTriggerEventQueue (com.sequenceiq.flow.core.chain.config.FlowTriggerEventQueue)2 SdxBackupResponse (com.sequenceiq.sdx.api.model.SdxBackupResponse)2 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)2 PollerStoppedException (com.dyngr.exception.PollerStoppedException)1 DatalakeBackupStatusResponse (com.sequenceiq.cloudbreak.datalakedr.model.DatalakeBackupStatusResponse)1 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)1 SdxContext (com.sequenceiq.datalake.flow.SdxContext)1 SdxEvent (com.sequenceiq.datalake.flow.SdxEvent)1 DatalakeUpgradeStartEvent (com.sequenceiq.datalake.flow.datalake.upgrade.event.DatalakeUpgradeStartEvent)1 SdxDeleteStartEvent (com.sequenceiq.datalake.flow.delete.event.SdxDeleteStartEvent)1 SdxStartDetachEvent (com.sequenceiq.datalake.flow.detach.event.SdxStartDetachEvent)1 DatalakeTriggerRestoreEvent (com.sequenceiq.datalake.flow.dr.restore.event.DatalakeTriggerRestoreEvent)1 DatahubRefreshStartEvent (com.sequenceiq.datalake.flow.refresh.event.DatahubRefreshStartEvent)1 SdxStartStopEvent (com.sequenceiq.datalake.flow.stop.event.SdxStartStopEvent)1 AbstractSdxAction (com.sequenceiq.datalake.service.AbstractSdxAction)1 FlowParameters (com.sequenceiq.flow.core.FlowParameters)1 Map (java.util.Map)1