Search in sources :

Example 1 with SdxDatabaseBackupResponse

use of com.sequenceiq.sdx.api.model.SdxDatabaseBackupResponse 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);
}
Also used : DatalakeDatabaseBackupStartEvent(com.sequenceiq.datalake.flow.dr.backup.event.DatalakeDatabaseBackupStartEvent) SdxDatabaseBackupResponse(com.sequenceiq.sdx.api.model.SdxDatabaseBackupResponse) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier)

Example 2 with SdxDatabaseBackupResponse

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

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

the class SdxBackupController method backupDatabaseByNameInternal.

@Override
@CheckPermissionByResourceName(action = AuthorizationResourceAction.BACKUP_DATALAKE)
public SdxDatabaseBackupResponse backupDatabaseByNameInternal(@ResourceName String name, SdxDatabaseBackupRequest backupRequest) {
    SdxCluster sdxCluster = getSdxClusterByName(name);
    String backupId = backupRequest.getBackupId();
    try {
        SdxDatabaseBackupStatusResponse response = sdxBackupRestoreService.getDatabaseBackupStatus(sdxCluster, backupId);
        SdxDatabaseBackupResponse sdxDatabaseBackupResponse = new SdxDatabaseBackupResponse();
        sdxDatabaseBackupResponse.setOperationId(backupId);
        return sdxDatabaseBackupResponse;
    } catch (NotFoundException notFoundException) {
        return sdxBackupRestoreService.triggerDatabaseBackup(sdxCluster, backupRequest);
    }
}
Also used : SdxDatabaseBackupStatusResponse(com.sequenceiq.sdx.api.model.SdxDatabaseBackupStatusResponse) 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)

Example 4 with SdxDatabaseBackupResponse

use of com.sequenceiq.sdx.api.model.SdxDatabaseBackupResponse 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);
}
Also used : DatalakeDatabaseBackupStartEvent(com.sequenceiq.datalake.flow.dr.backup.event.DatalakeDatabaseBackupStartEvent) SdxDatabaseBackupResponse(com.sequenceiq.sdx.api.model.SdxDatabaseBackupResponse) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier)

Example 5 with SdxDatabaseBackupResponse

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

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