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);
}
};
}
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);
}
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()));
}
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);
}
Aggregations