Search in sources :

Example 1 with SdxDatabaseRestoreResponse

use of com.sequenceiq.sdx.api.model.SdxDatabaseRestoreResponse 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 SdxDatabaseRestoreResponse

use of com.sequenceiq.sdx.api.model.SdxDatabaseRestoreResponse in project cloudbreak by hortonworks.

the class SdxRestoreController method restoreDatabaseByName.

@Override
@CheckPermissionByResourceName(action = AuthorizationResourceAction.RESTORE_DATALAKE)
public SdxDatabaseRestoreResponse restoreDatabaseByName(@ResourceName String name, String backupId, String restoreId, String backupLocation) {
    SdxCluster sdxCluster = getSdxClusterByName(name);
    try {
        sdxBackupRestoreService.getDatabaseRestoreStatus(sdxCluster, restoreId);
        SdxDatabaseRestoreResponse sdxDatabaseRestoreResponse = new SdxDatabaseRestoreResponse();
        sdxDatabaseRestoreResponse.setOperationId(restoreId);
        return sdxDatabaseRestoreResponse;
    } catch (NotFoundException notFoundException) {
        return sdxBackupRestoreService.triggerDatabaseRestore(sdxCluster, backupId, restoreId, backupLocation);
    }
}
Also used : SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) SdxDatabaseRestoreResponse(com.sequenceiq.sdx.api.model.SdxDatabaseRestoreResponse) CheckPermissionByResourceName(com.sequenceiq.authorization.annotation.CheckPermissionByResourceName)

Example 3 with SdxDatabaseRestoreResponse

use of com.sequenceiq.sdx.api.model.SdxDatabaseRestoreResponse 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 SdxDatabaseRestoreResponse

use of com.sequenceiq.sdx.api.model.SdxDatabaseRestoreResponse 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

SdxDatabaseRestoreResponse (com.sequenceiq.sdx.api.model.SdxDatabaseRestoreResponse)4 DatalakeDatabaseRestoreStartEvent (com.sequenceiq.datalake.flow.dr.restore.event.DatalakeDatabaseRestoreStartEvent)3 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)2 CheckPermissionByResourceName (com.sequenceiq.authorization.annotation.CheckPermissionByResourceName)1 NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)1 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)1 Test (org.junit.jupiter.api.Test)1