use of com.sequenceiq.datalake.flow.dr.restore.event.DatalakeDatabaseRestoreStartEvent in project cloudbreak by hortonworks.
the class SdxBackupRestoreServiceTest method triggerDatabaseRestoreSuccess.
@Test
public void triggerDatabaseRestoreSuccess() {
when(sdxReactorFlowManager.triggerDatalakeDatabaseRestoreFlow(any(DatalakeDatabaseRestoreStartEvent.class), anyString())).thenReturn(FLOW_IDENTIFIER);
SdxDatabaseRestoreResponse restoreResponse = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> sdxBackupRestoreService.triggerDatabaseRestore(sdxCluster, BACKUP_ID, RESTORE_ID, BACKUP_LOCATION));
assertEquals(FLOW_IDENTIFIER, restoreResponse.getFlowIdentifier());
ArgumentCaptor<DatalakeDatabaseRestoreStartEvent> eventArgumentCaptor = ArgumentCaptor.forClass(DatalakeDatabaseRestoreStartEvent.class);
verify(sdxReactorFlowManager, times(1)).triggerDatalakeDatabaseRestoreFlow(eventArgumentCaptor.capture(), anyString());
assertEquals(BACKUP_ID, eventArgumentCaptor.getValue().getBackupId());
assertEquals(RESTORE_ID, eventArgumentCaptor.getValue().getRestoreId());
assertEquals(BACKUP_LOCATION, eventArgumentCaptor.getValue().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.restore.event.DatalakeDatabaseRestoreStartEvent in project cloudbreak by hortonworks.
the class DatalakeRestoreActionsTest method testGetNewSdxIdForResizeDoExecute.
@Test
public void testGetNewSdxIdForResizeDoExecute() throws Exception {
when(sdxBackupRestoreService.triggerDatalakeRestore(eq(NEW_SDX_ID), any(), any(), eq(USER_CRN))).thenReturn(new DatalakeRestoreStatusResponse(BACKUP_ID, RESTORE_ID, State.STARTED, Optional.empty()));
DatalakeTriggerRestoreEvent event = new DatalakeTriggerRestoreEvent(DATALAKE_TRIGGER_RESTORE_EVENT.event(), NEW_SDX_ID, DATALAKE_NAME, USER_CRN, null, BACKUP_LOCATION, null, DatalakeRestoreFailureReason.RESTORE_ON_RESIZE);
AbstractAction action = (AbstractAction) underTest.triggerDatalakeRestore();
initActionPrivateFields(action);
AbstractActionTestSupport testSupport = new AbstractActionTestSupport(action);
SdxContext context = SdxContext.from(new FlowParameters(FLOW_ID, FLOW_ID, null), event);
testSupport.doExecute(context, event, new HashMap());
ArgumentCaptor<DatalakeDatabaseRestoreStartEvent> captor = ArgumentCaptor.forClass(DatalakeDatabaseRestoreStartEvent.class);
verify(reactorEventFactory, times(1)).createEvent(any(), captor.capture());
DatalakeDatabaseRestoreStartEvent captorValue = captor.getValue();
Assertions.assertEquals(NEW_SDX_ID, captorValue.getResourceId());
}
use of com.sequenceiq.datalake.flow.dr.restore.event.DatalakeDatabaseRestoreStartEvent in project cloudbreak by hortonworks.
the class SdxBackupRestoreService method triggerDatalakeDatabaseRestoreFlow.
private SdxDatabaseRestoreResponse triggerDatalakeDatabaseRestoreFlow(SdxCluster cluster, String backupId, String restoreId, String backupLocation) {
String selector = DATALAKE_DATABASE_RESTORE_EVENT.event();
String userId = ThreadBasedUserCrnProvider.getUserCrn();
DatalakeDatabaseRestoreStartEvent startEvent = new DatalakeDatabaseRestoreStartEvent(selector, cluster.getId(), userId, backupId, restoreId, backupLocation);
FlowIdentifier flowIdentifier = sdxReactorFlowManager.triggerDatalakeDatabaseRestoreFlow(startEvent, cluster.getClusterName());
return new SdxDatabaseRestoreResponse(startEvent.getDrStatus().getOperationId(), flowIdentifier);
}
use of com.sequenceiq.datalake.flow.dr.restore.event.DatalakeDatabaseRestoreStartEvent in project cloudbreak by hortonworks.
the class DatalakeRestoreActionsTest method testRestoreWithNoFlowChain.
@Test
public void testRestoreWithNoFlowChain() throws Exception {
when(sdxBackupRestoreService.triggerDatalakeRestore(eq(OLD_SDX_ID), any(), any(), eq(USER_CRN))).thenReturn(new DatalakeRestoreStatusResponse(BACKUP_ID, RESTORE_ID, State.STARTED, Optional.empty()));
DatalakeTriggerRestoreEvent event = new DatalakeTriggerRestoreEvent(DATALAKE_TRIGGER_RESTORE_EVENT.event(), OLD_SDX_ID, DATALAKE_NAME, USER_CRN, null, BACKUP_LOCATION, null, DatalakeRestoreFailureReason.RESTORE_ON_RESIZE);
AbstractAction action = (AbstractAction) underTest.triggerDatalakeRestore();
initActionPrivateFields(action);
AbstractActionTestSupport testSupport = new AbstractActionTestSupport(action);
SdxContext context = SdxContext.from(new FlowParameters(FLOW_ID, FLOW_ID, null), event);
testSupport.doExecute(context, event, new HashMap());
ArgumentCaptor<DatalakeDatabaseRestoreStartEvent> captor = ArgumentCaptor.forClass(DatalakeDatabaseRestoreStartEvent.class);
verify(reactorEventFactory, times(1)).createEvent(any(), captor.capture());
DatalakeDatabaseRestoreStartEvent captorValue = captor.getValue();
Assertions.assertEquals(OLD_SDX_ID, captorValue.getResourceId());
}
use of com.sequenceiq.datalake.flow.dr.restore.event.DatalakeDatabaseRestoreStartEvent in project cloudbreak by hortonworks.
the class SdxBackupRestoreService method triggerDatalakeDatabaseRestoreFlow.
private SdxDatabaseRestoreResponse triggerDatalakeDatabaseRestoreFlow(Long clusterId, String backupId, String restoreId, String backupLocation) {
String selector = DATALAKE_DATABASE_RESTORE_EVENT.event();
String userId = ThreadBasedUserCrnProvider.getUserCrn();
DatalakeDatabaseRestoreStartEvent startEvent = new DatalakeDatabaseRestoreStartEvent(selector, clusterId, userId, backupId, restoreId, backupLocation);
FlowIdentifier flowIdentifier = sdxReactorFlowManager.triggerDatalakeDatabaseRestoreFlow(startEvent);
return new SdxDatabaseRestoreResponse(startEvent.getDrStatus().getOperationId(), flowIdentifier);
}
Aggregations