Search in sources :

Example 31 with NotFoundException

use of com.sequenceiq.cloudbreak.common.exception.NotFoundException in project cloudbreak by hortonworks.

the class KerberosConfigServiceTest method testDeleteNotFound.

@Test
public void testDeleteNotFound() {
    // GIVEN
    Mockito.when(crnService.getCurrentAccountId()).thenReturn(ACCOUNT_ID);
    NotFoundException ex = Assertions.assertThrows(NotFoundException.class, () -> {
        // WHEN
        underTest.delete(ENVIRONMENT_ID);
    });
    assertEquals("KerberosConfig for environment 'environmentId' not found.", ex.getMessage());
}
Also used : NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) Test(org.junit.jupiter.api.Test)

Example 32 with NotFoundException

use of com.sequenceiq.cloudbreak.common.exception.NotFoundException in project cloudbreak by hortonworks.

the class SdxCreateActions method failedAction.

@Bean(name = "SDX_CREATION_FAILED_STATE")
public Action<?, ?> failedAction() {
    return new AbstractSdxAction<>(SdxCreateFailedEvent.class) {

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

        @Override
        protected void doExecute(SdxContext context, SdxCreateFailedEvent payload, Map<Object, Object> variables) throws Exception {
            Exception exception = payload.getException();
            String statusReason = "Datalake creation failed";
            String errorMessage = webApplicationExceptionMessageExtractor.getErrorMessage(exception);
            if (StringUtils.hasText(errorMessage)) {
                statusReason = statusReason + ". " + errorMessage;
            } else if (exception.getMessage() != null) {
                statusReason = statusReason + ". " + exception.getMessage();
            }
            LOGGER.error(statusReason, exception);
            try {
                SdxCluster sdxCluster = sdxStatusService.setStatusForDatalakeAndNotify(DatalakeStatusEnum.PROVISIONING_FAILED, statusReason, payload.getResourceId());
                metricService.incrementMetricCounter(MetricType.SDX_CREATION_FAILED, sdxCluster);
                eventSenderService.notifyEvent(context, ResourceEvent.SDX_CLUSTER_CREATION_FAILED);
            } catch (NotFoundException notFoundException) {
                LOGGER.info("Can not set status to SDX_CREATION_FAILED because data lake was not found");
            } catch (DatalakeStatusUpdateException datalakeStatusUpdateException) {
                LOGGER.info("Status update for data lake failed (possible reason: ongoing parallel deletion flow): {}", exception.getMessage());
            }
            Flow flow = getFlow(context.getFlowParameters().getFlowId());
            flow.setFlowFailed(payload.getException());
            sendEvent(context, SDX_CREATE_FAILED_HANDLED_EVENT.event(), payload);
        }

        @Override
        protected Object getFailurePayload(SdxCreateFailedEvent payload, Optional<SdxContext> flowContext, Exception ex) {
            return null;
        }
    };
}
Also used : Optional(java.util.Optional) StateContext(org.springframework.statemachine.StateContext) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) DatalakeStatusUpdateException(com.sequenceiq.datalake.service.sdx.status.DatalakeStatusUpdateException) DatalakeStatusUpdateException(com.sequenceiq.datalake.service.sdx.status.DatalakeStatusUpdateException) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Flow(com.sequenceiq.flow.core.Flow) FlowParameters(com.sequenceiq.flow.core.FlowParameters) AbstractSdxAction(com.sequenceiq.datalake.service.AbstractSdxAction) SdxCreateFailedEvent(com.sequenceiq.datalake.flow.create.event.SdxCreateFailedEvent) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 33 with NotFoundException

use of com.sequenceiq.cloudbreak.common.exception.NotFoundException 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 34 with NotFoundException

use of com.sequenceiq.cloudbreak.common.exception.NotFoundException 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 35 with NotFoundException

use of com.sequenceiq.cloudbreak.common.exception.NotFoundException in project cloudbreak by hortonworks.

the class ProgressService method getFlowProgressListByResourceCrn.

public SdxProgressListResponse getFlowProgressListByResourceCrn(String resourceCrn) {
    SdxProgressListResponse response = new SdxProgressListResponse();
    response.setRecentFlowOperations(flowService.getFlowProgressListByResourceCrn(resourceCrn));
    try {
        response.setRecentInternalFlowOperations(progressV4Endpoint.getFlowLogsProgressByResourceCrn(resourceCrn));
    } catch (NotFoundException notFoundException) {
        LOGGER.debug("Stack for datalake '{}' has not found yet. It is acceptable for progress response.", resourceCrn);
    }
    return response;
}
Also used : NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) SdxProgressListResponse(com.sequenceiq.sdx.api.model.SdxProgressListResponse)

Aggregations

NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)73 Test (org.junit.jupiter.api.Test)33 CloudbreakImageNotFoundException (com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException)11 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)10 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)10 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)10 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)9 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)8 Map (java.util.Map)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 NameOrCrn (com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn)6 List (java.util.List)6 TransactionExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException)5 TransactionRuntimeExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException)5 Workspace (com.sequenceiq.cloudbreak.workspace.model.Workspace)5 Optional (java.util.Optional)5 CloudbreakImageCatalogException (com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException)4 Set (java.util.Set)4 CheckPermissionByResourceName (com.sequenceiq.authorization.annotation.CheckPermissionByResourceName)3 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)3