Search in sources :

Example 71 with NotFoundException

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

the class StackServiceTest method getStackByIdNotFound.

@Test
void getStackByIdNotFound() {
    when(stackRepository.findById(STACK_ID)).thenReturn(Optional.empty());
    NotFoundException notFoundException = assertThrows(NotFoundException.class, () -> underTest.getStackById(STACK_ID));
    assertEquals("FreeIPA stack [" + STACK_ID + "] not found", notFoundException.getMessage());
}
Also used : NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) Test(org.junit.jupiter.api.Test)

Example 72 with NotFoundException

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

the class StackServiceTest method getByCrnAndAccountIdEvenIfTerminatedThrowsWhenNotPresent.

@Test
void getByCrnAndAccountIdEvenIfTerminatedThrowsWhenNotPresent() {
    when(stackRepository.findByAccountIdEnvironmentCrnAndCrnWithListsEvenIfTerminated(ENVIRONMENT_CRN, ACCOUNT_ID, FREEIPA_CRN)).thenReturn(Optional.empty());
    when(childEnvironmentService.findParentStackByChildEnvironmentCrnAndCrnWithListsEvenIfTerminated(ENVIRONMENT_CRN, ACCOUNT_ID, FREEIPA_CRN)).thenReturn(Optional.empty());
    NotFoundException notFoundException = assertThrows(NotFoundException.class, () -> underTest.getByCrnAndAccountIdEvenIfTerminated(ENVIRONMENT_CRN, ACCOUNT_ID, FREEIPA_CRN));
    assertEquals("FreeIPA stack by environment [" + ENVIRONMENT_CRN + "] with CRN [" + FREEIPA_CRN + "] not found", notFoundException.getMessage());
}
Also used : NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) Test(org.junit.jupiter.api.Test)

Example 73 with NotFoundException

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

the class ChildEnvironmentService method detachChildEnvironment.

public void detachChildEnvironment(DetachChildEnvironmentRequest request, String accountId) {
    ChildEnvironment childEnvironment = repository.findByParentAndChildEnvironmentCrns(request.getParentEnvironmentCrn(), request.getChildEnvironmentCrn(), accountId).orElseThrow(() -> new NotFoundException(String.format("ChildEnvironment by parent environment crn [%s] and child environment crn [%s] not found", request.getParentEnvironmentCrn(), request.getChildEnvironmentCrn())));
    MDCBuilder.buildMdcContext(childEnvironment.getStack());
    LOGGER.info("Detaching child env: {}", childEnvironment);
    try {
        repository.delete(childEnvironment);
    } catch (ObjectOptimisticLockingFailureException e) {
        LOGGER.info("Child env {} is already detached", childEnvironment, e);
        throw new NotFoundException(String.format("Child env %s is already detached", childEnvironment.getEnvironmentCrn()));
    }
}
Also used : ChildEnvironment(com.sequenceiq.freeipa.entity.ChildEnvironment) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) ObjectOptimisticLockingFailureException(org.springframework.orm.ObjectOptimisticLockingFailureException)

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