Search in sources :

Example 1 with DatalakeDatabaseRestoreStartEvent

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()));
}
Also used : DatalakeDatabaseRestoreStartEvent(com.sequenceiq.datalake.flow.dr.restore.event.DatalakeDatabaseRestoreStartEvent) SdxDatabaseRestoreResponse(com.sequenceiq.sdx.api.model.SdxDatabaseRestoreResponse) Test(org.junit.jupiter.api.Test)

Example 2 with DatalakeDatabaseRestoreStartEvent

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());
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) DatalakeTriggerRestoreEvent(com.sequenceiq.datalake.flow.dr.restore.event.DatalakeTriggerRestoreEvent) HashMap(java.util.HashMap) AbstractActionTestSupport(com.sequenceiq.flow.core.AbstractActionTestSupport) DatalakeDatabaseRestoreStartEvent(com.sequenceiq.datalake.flow.dr.restore.event.DatalakeDatabaseRestoreStartEvent) AbstractAction(com.sequenceiq.flow.core.AbstractAction) DatalakeRestoreStatusResponse(com.sequenceiq.cloudbreak.datalakedr.model.DatalakeRestoreStatusResponse) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Test(org.junit.jupiter.api.Test)

Example 3 with DatalakeDatabaseRestoreStartEvent

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);
}
Also used : DatalakeDatabaseRestoreStartEvent(com.sequenceiq.datalake.flow.dr.restore.event.DatalakeDatabaseRestoreStartEvent) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) SdxDatabaseRestoreResponse(com.sequenceiq.sdx.api.model.SdxDatabaseRestoreResponse)

Example 4 with DatalakeDatabaseRestoreStartEvent

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());
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) DatalakeTriggerRestoreEvent(com.sequenceiq.datalake.flow.dr.restore.event.DatalakeTriggerRestoreEvent) HashMap(java.util.HashMap) AbstractActionTestSupport(com.sequenceiq.flow.core.AbstractActionTestSupport) DatalakeDatabaseRestoreStartEvent(com.sequenceiq.datalake.flow.dr.restore.event.DatalakeDatabaseRestoreStartEvent) AbstractAction(com.sequenceiq.flow.core.AbstractAction) DatalakeRestoreStatusResponse(com.sequenceiq.cloudbreak.datalakedr.model.DatalakeRestoreStatusResponse) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Test(org.junit.jupiter.api.Test)

Example 5 with DatalakeDatabaseRestoreStartEvent

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);
}
Also used : DatalakeDatabaseRestoreStartEvent(com.sequenceiq.datalake.flow.dr.restore.event.DatalakeDatabaseRestoreStartEvent) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) SdxDatabaseRestoreResponse(com.sequenceiq.sdx.api.model.SdxDatabaseRestoreResponse)

Aggregations

DatalakeDatabaseRestoreStartEvent (com.sequenceiq.datalake.flow.dr.restore.event.DatalakeDatabaseRestoreStartEvent)5 SdxDatabaseRestoreResponse (com.sequenceiq.sdx.api.model.SdxDatabaseRestoreResponse)3 Test (org.junit.jupiter.api.Test)3 DatalakeRestoreStatusResponse (com.sequenceiq.cloudbreak.datalakedr.model.DatalakeRestoreStatusResponse)2 SdxContext (com.sequenceiq.datalake.flow.SdxContext)2 DatalakeTriggerRestoreEvent (com.sequenceiq.datalake.flow.dr.restore.event.DatalakeTriggerRestoreEvent)2 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)2 AbstractAction (com.sequenceiq.flow.core.AbstractAction)2 AbstractActionTestSupport (com.sequenceiq.flow.core.AbstractActionTestSupport)2 FlowParameters (com.sequenceiq.flow.core.FlowParameters)2 HashMap (java.util.HashMap)2