Search in sources :

Example 1 with SdxDatabaseBackupRequest

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

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

the class SdxBackupController method backupDatabaseByName.

@Override
@CheckPermissionByResourceName(action = AuthorizationResourceAction.BACKUP_DATALAKE)
public SdxDatabaseBackupResponse backupDatabaseByName(@ResourceName String name, String backupId, String backupLocation) {
    SdxCluster sdxCluster = getSdxClusterByName(name);
    try {
        SdxDatabaseBackupStatusResponse response = sdxBackupRestoreService.getDatabaseBackupStatus(sdxCluster, backupId);
        SdxDatabaseBackupResponse sdxDatabaseBackupResponse = new SdxDatabaseBackupResponse();
        sdxDatabaseBackupResponse.setOperationId(backupId);
        return sdxDatabaseBackupResponse;
    } catch (NotFoundException notFoundException) {
        SdxDatabaseBackupRequest backupRequest = new SdxDatabaseBackupRequest();
        backupRequest.setBackupId(backupId);
        backupRequest.setBackupLocation(backupLocation);
        backupRequest.setCloseConnections(true);
        return sdxBackupRestoreService.triggerDatabaseBackup(sdxCluster, backupRequest);
    }
}
Also used : SdxDatabaseBackupStatusResponse(com.sequenceiq.sdx.api.model.SdxDatabaseBackupStatusResponse) SdxDatabaseBackupRequest(com.sequenceiq.sdx.api.model.SdxDatabaseBackupRequest) SdxDatabaseBackupResponse(com.sequenceiq.sdx.api.model.SdxDatabaseBackupResponse) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) CheckPermissionByResourceName(com.sequenceiq.authorization.annotation.CheckPermissionByResourceName)

Aggregations

SdxDatabaseBackupRequest (com.sequenceiq.sdx.api.model.SdxDatabaseBackupRequest)2 SdxDatabaseBackupResponse (com.sequenceiq.sdx.api.model.SdxDatabaseBackupResponse)2 CheckPermissionByResourceName (com.sequenceiq.authorization.annotation.CheckPermissionByResourceName)1 NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)1 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)1 DatalakeDatabaseBackupStartEvent (com.sequenceiq.datalake.flow.dr.backup.event.DatalakeDatabaseBackupStartEvent)1 SdxDatabaseBackupStatusResponse (com.sequenceiq.sdx.api.model.SdxDatabaseBackupStatusResponse)1 Test (org.junit.jupiter.api.Test)1