Search in sources :

Example 1 with DatalakeDatabaseBackupStartEvent

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

the class DatalakeBackupActions method datalakeBackup.

@Bean(name = "DATALAKE_DATABASE_BACKUP_START_STATE")
public Action<?, ?> datalakeBackup() {
    return new AbstractSdxAction<>(DatalakeDatabaseBackupStartEvent.class) {

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

        @Override
        protected void prepareExecution(DatalakeDatabaseBackupStartEvent payload, Map<Object, Object> variables) {
            super.prepareExecution(payload, variables);
            if (!variables.containsKey(OPERATION_ID)) {
                variables.put(OPERATION_ID, payload.getDrStatus().getOperationId());
            }
            if (!variables.containsKey(BACKUP_ID)) {
                variables.put(BACKUP_ID, payload.getBackupRequest().getBackupId());
            }
        }

        @Override
        protected void doExecute(SdxContext context, DatalakeDatabaseBackupStartEvent payload, Map<Object, Object> variables) {
            LOGGER.info("Datalake database backup has been started for {}", payload.getResourceId());
            SdxCluster sdxCluster = sdxService.getById(payload.getResourceId());
            eventSenderService.sendEventAndNotification(sdxCluster, context.getFlowTriggerUserCrn(), ResourceEvent.DATALAKE_DATABASE_BACKUP);
            sdxBackupRestoreService.databaseBackup(payload.getDrStatus(), payload.getResourceId(), payload.getBackupRequest());
            sendEvent(context, DATALAKE_DATABASE_BACKUP_IN_PROGRESS_EVENT.event(), payload);
        }

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

Example 2 with DatalakeDatabaseBackupStartEvent

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

the class SdxBackupRestoreService method triggerDatalakeDatabaseBackupFlow.

private SdxDatabaseBackupResponse triggerDatalakeDatabaseBackupFlow(Long clusterId, SdxDatabaseBackupRequest backupRequest) {
    String selector = DATALAKE_DATABASE_BACKUP_EVENT.event();
    String userId = ThreadBasedUserCrnProvider.getUserCrn();
    DatalakeDatabaseBackupStartEvent startEvent = new DatalakeDatabaseBackupStartEvent(selector, clusterId, userId, backupRequest);
    FlowIdentifier flowIdentifier = sdxReactorFlowManager.triggerDatalakeDatabaseBackupFlow(startEvent);
    return new SdxDatabaseBackupResponse(startEvent.getDrStatus().getOperationId(), flowIdentifier);
}
Also used : DatalakeDatabaseBackupStartEvent(com.sequenceiq.datalake.flow.dr.backup.event.DatalakeDatabaseBackupStartEvent) SdxDatabaseBackupResponse(com.sequenceiq.sdx.api.model.SdxDatabaseBackupResponse) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier)

Example 3 with DatalakeDatabaseBackupStartEvent

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

the class SdxBackupRestoreServiceTest method triggerDatabaseBackupSuccess.

@Test
public void triggerDatabaseBackupSuccess() {
    when(sdxReactorFlowManager.triggerDatalakeDatabaseBackupFlow(any(DatalakeDatabaseBackupStartEvent.class), anyString())).thenReturn(FLOW_IDENTIFIER);
    SdxDatabaseBackupRequest backupRequest = new SdxDatabaseBackupRequest();
    backupRequest.setBackupId(BACKUP_ID);
    backupRequest.setBackupLocation(BACKUP_LOCATION);
    backupRequest.setCloseConnections(true);
    SdxDatabaseBackupResponse backupResponse = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> sdxBackupRestoreService.triggerDatabaseBackup(sdxCluster, backupRequest));
    assertEquals(FLOW_IDENTIFIER, backupResponse.getFlowIdentifier());
    ArgumentCaptor<DatalakeDatabaseBackupStartEvent> eventArgumentCaptor = ArgumentCaptor.forClass(DatalakeDatabaseBackupStartEvent.class);
    verify(sdxReactorFlowManager, times(1)).triggerDatalakeDatabaseBackupFlow(eventArgumentCaptor.capture(), anyString());
    assertEquals(BACKUP_ID, eventArgumentCaptor.getValue().getBackupRequest().getBackupId());
    assertEquals(BACKUP_LOCATION, eventArgumentCaptor.getValue().getBackupRequest().getBackupLocation());
    assertEquals(USER_CRN, eventArgumentCaptor.getValue().getUserId());
    assertEquals(sdxCluster.getId(), eventArgumentCaptor.getValue().getResourceId());
    assertTrue(isUUID(eventArgumentCaptor.getValue().getDrStatus().getOperationId()));
}
Also used : SdxDatabaseBackupRequest(com.sequenceiq.sdx.api.model.SdxDatabaseBackupRequest) DatalakeDatabaseBackupStartEvent(com.sequenceiq.datalake.flow.dr.backup.event.DatalakeDatabaseBackupStartEvent) SdxDatabaseBackupResponse(com.sequenceiq.sdx.api.model.SdxDatabaseBackupResponse) Test(org.junit.jupiter.api.Test)

Example 4 with DatalakeDatabaseBackupStartEvent

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

the class SdxBackupRestoreService method triggerDatalakeDatabaseBackupFlow.

private SdxDatabaseBackupResponse triggerDatalakeDatabaseBackupFlow(SdxCluster cluster, SdxDatabaseBackupRequest backupRequest) {
    String selector = DATALAKE_DATABASE_BACKUP_EVENT.event();
    String userId = ThreadBasedUserCrnProvider.getUserCrn();
    DatalakeDatabaseBackupStartEvent startEvent = new DatalakeDatabaseBackupStartEvent(selector, cluster.getId(), userId, backupRequest);
    FlowIdentifier flowIdentifier = sdxReactorFlowManager.triggerDatalakeDatabaseBackupFlow(startEvent, cluster.getClusterName());
    return new SdxDatabaseBackupResponse(startEvent.getDrStatus().getOperationId(), flowIdentifier);
}
Also used : DatalakeDatabaseBackupStartEvent(com.sequenceiq.datalake.flow.dr.backup.event.DatalakeDatabaseBackupStartEvent) SdxDatabaseBackupResponse(com.sequenceiq.sdx.api.model.SdxDatabaseBackupResponse) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier)

Aggregations

DatalakeDatabaseBackupStartEvent (com.sequenceiq.datalake.flow.dr.backup.event.DatalakeDatabaseBackupStartEvent)4 SdxDatabaseBackupResponse (com.sequenceiq.sdx.api.model.SdxDatabaseBackupResponse)3 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)2 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)1 SdxContext (com.sequenceiq.datalake.flow.SdxContext)1 AbstractSdxAction (com.sequenceiq.datalake.service.AbstractSdxAction)1 FlowParameters (com.sequenceiq.flow.core.FlowParameters)1 SdxDatabaseBackupRequest (com.sequenceiq.sdx.api.model.SdxDatabaseBackupRequest)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Test (org.junit.jupiter.api.Test)1 Bean (org.springframework.context.annotation.Bean)1 StateContext (org.springframework.statemachine.StateContext)1