Search in sources :

Example 41 with NotFoundException

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

the class DatalakeRecoverySetupNewInstancesHandlerTest method testDoAcceptWhenExceptionThenFailure.

@Test
void testDoAcceptWhenExceptionThenFailure() {
    when(stackService.getByIdWithClusterInTransaction(STACK_ID)).thenThrow(new NotFoundException(EXCEPTION_MESSAGE));
    Selectable nextFlowStepSelector = underTest.doAccept(getHandlerEvent());
    assertEquals(EventSelectorUtil.selector(DatalakeRecoverySetupNewInstancesFailedEvent.class), nextFlowStepSelector.selector());
    DatalakeRecoverySetupNewInstancesFailedEvent failureEvent = (DatalakeRecoverySetupNewInstancesFailedEvent) nextFlowStepSelector;
    assertEquals(EXCEPTION_MESSAGE, failureEvent.getException().getMessage());
}
Also used : DatalakeRecoverySetupNewInstancesFailedEvent(com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.recovery.bringup.DatalakeRecoverySetupNewInstancesFailedEvent) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) Test(org.junit.jupiter.api.Test)

Example 42 with NotFoundException

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

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

the class SdxServiceTest method testSdxResizeByAccountIdAndNameWhenSdxDoesNotExist.

@Test
void testSdxResizeByAccountIdAndNameWhenSdxDoesNotExist() {
    SdxClusterResizeRequest sdxClusterResizeRequest = new SdxClusterResizeRequest();
    sdxClusterResizeRequest.setClusterShape(MEDIUM_DUTY_HA);
    sdxClusterResizeRequest.setEnvironment("environment");
    when(sdxClusterRepository.findByAccountIdAndClusterNameAndDeletedIsNullAndDetachedIsFalse(anyString(), anyString())).thenReturn(Optional.empty());
    NotFoundException notFoundException = assertThrows(NotFoundException.class, () -> underTest.resizeSdx(USER_CRN, "sdxcluster", sdxClusterResizeRequest));
    assertEquals("SDX cluster 'sdxcluster' not found.", notFoundException.getMessage());
}
Also used : SdxClusterResizeRequest(com.sequenceiq.sdx.api.model.SdxClusterResizeRequest) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 44 with NotFoundException

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

the class DatabaseServiceTest method testGetDatabaseServerWhenNoDatabaseCrnShouldThrowNotFoundException.

@Test
public void testGetDatabaseServerWhenNoDatabaseCrnShouldThrowNotFoundException() {
    when(sdxService.getByCrn(USER_CRN, CLUSTER_CRN)).thenReturn(new SdxCluster());
    NotFoundException exception = assertThrows(NotFoundException.class, () -> underTest.getDatabaseServer(USER_CRN, CLUSTER_CRN));
    assertThat(exception.getMessage()).isEqualTo("Database for Data Lake with Data Lake crn: 'cluster crn' not found.");
    verify(databaseServerV4Endpoint, never()).getByCrn(anyString());
}
Also used : SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 45 with NotFoundException

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

the class SdxBackupRestoreServiceTest method testgetDatabaseBackupStatus.

@Test
public void testgetDatabaseBackupStatus() {
    when(sdxOperationRepository.findSdxOperationByOperationId(Mockito.anyString())).thenReturn(null);
    try {
        sdxBackupRestoreService.getDatabaseBackupStatus(sdxCluster, BACKUP_ID);
        fail("Exception should have been thrown");
    } catch (NotFoundException notFoundException) {
        String exceptedMessage = String.format("Status with id: [%s] not found", BACKUP_ID);
        assertEquals(exceptedMessage, notFoundException.getLocalizedMessage());
    }
    reset(sdxOperationRepository);
    SdxOperation sdxOperation = new SdxOperation();
    sdxOperation.setOperationType(SdxOperationType.RESTORE);
    sdxOperation.setSdxClusterId(sdxCluster.getId());
    sdxOperation.setOperationId(BACKUP_ID);
    when(sdxOperationRepository.findSdxOperationByOperationId(Mockito.anyString())).thenReturn(sdxOperation);
    try {
        sdxBackupRestoreService.getDatabaseBackupStatus(sdxCluster, BACKUP_ID);
        fail("Exception should have been thrown");
    } catch (CloudbreakApiException cloudbreakApiException) {
        String exceptedMessage = String.format("Invalid operation-id: [%s]. provided", BACKUP_ID);
        assertEquals(exceptedMessage, cloudbreakApiException.getLocalizedMessage());
    }
}
Also used : SdxOperation(com.sequenceiq.datalake.entity.operation.SdxOperation) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CloudbreakApiException(com.sequenceiq.cloudbreak.exception.CloudbreakApiException) Test(org.junit.jupiter.api.Test)

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