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());
}
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());
}
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()));
}
}
Aggregations