Search in sources :

Example 1 with SdxDatabaseBackupStatusResponse

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

the class DatalakeBackupActions method datalakeFullBackupInProgress.

@Bean(name = "DATALAKE_FULL_BACKUP_IN_PROGRESS_STATE")
public Action<?, ?> datalakeFullBackupInProgress() {
    return new AbstractSdxAction<>(SdxEvent.class) {

        @Override
        protected SdxContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, SdxEvent payload) {
            return SdxContext.from(flowParameters, payload);
        }

        @Override
        protected void doExecute(SdxContext context, SdxEvent payload, Map<Object, Object> variables) {
            LOGGER.info("Full datalake backup is in progress for {} ", payload.getResourceId());
            String operationId = (String) variables.get(OPERATION_ID);
            String backupId = (String) variables.get(BACKUP_ID);
            SdxCluster sdxCluster = sdxService.getById(payload.getResourceId());
            eventSenderService.sendEventAndNotification(sdxCluster, ThreadBasedUserCrnProvider.getUserCrn(), DATALAKE_DATABASE_BACKUP_FINISHED);
            SdxDatabaseBackupStatusResponse backupStatusResponse = sdxBackupRestoreService.getDatabaseBackupStatus(sdxCluster, operationId);
            if (backupStatusResponse.getStatus().equals(DatalakeDatabaseDrStatus.INPROGRESS)) {
                sdxBackupRestoreService.updateDatabaseStatusEntry(operationId, SdxOperationStatus.SUCCEEDED, null);
            }
            sendEvent(context, DatalakeFullBackupWaitRequest.from(context, backupId));
        }

        @Override
        protected Object getFailurePayload(SdxEvent payload, Optional<SdxContext> flowContext, Exception ex) {
            return DatalakeBackupFailedEvent.from(payload, ex);
        }
    };
}
Also used : SdxDatabaseBackupStatusResponse(com.sequenceiq.sdx.api.model.SdxDatabaseBackupStatusResponse) FlowParameters(com.sequenceiq.flow.core.FlowParameters) AbstractSdxAction(com.sequenceiq.datalake.service.AbstractSdxAction) Optional(java.util.Optional) StateContext(org.springframework.statemachine.StateContext) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) SdxEvent(com.sequenceiq.datalake.flow.SdxEvent) Map(java.util.Map) PollerStoppedException(com.dyngr.exception.PollerStoppedException) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Bean(org.springframework.context.annotation.Bean)

Example 2 with SdxDatabaseBackupStatusResponse

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

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

the class SdxBackupRestoreService method getDatabaseBackupStatus.

public SdxDatabaseBackupStatusResponse getDatabaseBackupStatus(SdxCluster sdxCluster, String operationId) {
    MDCBuilder.buildMdcContext(sdxCluster);
    SdxOperation drStatus = getDatabaseDrStatus(sdxCluster, operationId, SdxOperationType.BACKUP);
    return new SdxDatabaseBackupStatusResponse(convertSdxDatabaseDrStatus(drStatus.getStatus()), drStatus.getStatusReason());
}
Also used : SdxDatabaseBackupStatusResponse(com.sequenceiq.sdx.api.model.SdxDatabaseBackupStatusResponse) SdxOperation(com.sequenceiq.datalake.entity.operation.SdxOperation)

Example 4 with SdxDatabaseBackupStatusResponse

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

Example 5 with SdxDatabaseBackupStatusResponse

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

the class SdxBackupControllerTest method testBackupDatabaseByName.

@Test
public void testBackupDatabaseByName() {
    SdxCluster sdxCluster = getValidSdxCluster();
    when(sdxService.getByNameInAccount(any(), anyString())).thenReturn(sdxCluster);
    String backupId = UUID.randomUUID().toString();
    when(sdxBackupRestoreService.getDatabaseBackupStatus(sdxCluster, backupId)).thenThrow(new NotFoundException("Status entry not found"));
    sdxBackupController.backupDatabaseByName(sdxCluster.getClusterName(), backupId, "");
    verify(sdxBackupRestoreService, times(1)).triggerDatabaseBackup(any(), any());
    reset(sdxBackupRestoreService);
    when(sdxBackupRestoreService.getDatabaseBackupStatus(sdxCluster, backupId)).thenReturn(new SdxDatabaseBackupStatusResponse(DatalakeDatabaseDrStatus.SUCCEEDED, null));
    sdxBackupController.backupDatabaseByName(sdxCluster.getClusterName(), backupId, "");
    verify(sdxBackupRestoreService, times(0)).triggerDatabaseBackup(any(), any());
}
Also used : SdxDatabaseBackupStatusResponse(com.sequenceiq.sdx.api.model.SdxDatabaseBackupStatusResponse) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Aggregations

SdxDatabaseBackupStatusResponse (com.sequenceiq.sdx.api.model.SdxDatabaseBackupStatusResponse)5 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)4 NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)3 CheckPermissionByResourceName (com.sequenceiq.authorization.annotation.CheckPermissionByResourceName)2 SdxDatabaseBackupResponse (com.sequenceiq.sdx.api.model.SdxDatabaseBackupResponse)2 PollerStoppedException (com.dyngr.exception.PollerStoppedException)1 SdxOperation (com.sequenceiq.datalake.entity.operation.SdxOperation)1 SdxContext (com.sequenceiq.datalake.flow.SdxContext)1 SdxEvent (com.sequenceiq.datalake.flow.SdxEvent)1 AbstractSdxAction (com.sequenceiq.datalake.service.AbstractSdxAction)1 FlowParameters (com.sequenceiq.flow.core.FlowParameters)1 SdxDatabaseBackupRequest (com.sequenceiq.sdx.api.model.SdxDatabaseBackupRequest)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Test (org.junit.jupiter.api.Test)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 Bean (org.springframework.context.annotation.Bean)1 StateContext (org.springframework.statemachine.StateContext)1