use of com.sequenceiq.freeipa.entity.ChildEnvironment in project cloudbreak by hortonworks.
the class ChildEnvironmentServiceTest method detachChildEnvironmentOptimisticLockingFailure.
@Test
void detachChildEnvironmentOptimisticLockingFailure() {
ChildEnvironment childEnvironment = new ChildEnvironment();
childEnvironment.setEnvironmentCrn(CHILD_ENVIRONMENT_CRN);
when(repository.findByParentAndChildEnvironmentCrns(ENVIRONMENT_CRN, CHILD_ENVIRONMENT_CRN, ACCOUNT_ID)).thenReturn(Optional.of(childEnvironment));
doThrow(ObjectOptimisticLockingFailureException.class).when(repository).delete(childEnvironment);
DetachChildEnvironmentRequest request = new DetachChildEnvironmentRequest();
request.setParentEnvironmentCrn(ENVIRONMENT_CRN);
request.setChildEnvironmentCrn(CHILD_ENVIRONMENT_CRN);
Assertions.assertThatThrownBy(() -> underTest.detachChildEnvironment(request, ACCOUNT_ID)).isInstanceOf(NotFoundException.class).hasMessage("Child env %s is already detached", CHILD_ENVIRONMENT_CRN);
}
use of com.sequenceiq.freeipa.entity.ChildEnvironment in project cloudbreak by hortonworks.
the class ChildEnvironmentService method attachChildEnvironment.
public void attachChildEnvironment(AttachChildEnvironmentRequest request, String accountId) {
Stack stack = stackService.getByOwnEnvironmentCrnAndAccountIdWithLists(request.getParentEnvironmentCrn(), accountId);
MDCBuilder.buildMdcContext(stack);
LOGGER.info("Attaching child [{}] environment to parent env [{}]", request.getChildEnvironmentCrn(), request.getParentEnvironmentCrn());
ChildEnvironment childEnvironment = new ChildEnvironment();
childEnvironment.setEnvironmentCrn(request.getChildEnvironmentCrn());
childEnvironment.setStack(stack);
repository.save(childEnvironment);
}
use of com.sequenceiq.freeipa.entity.ChildEnvironment in project cloudbreak by hortonworks.
the class ChildEnvironmentServiceTest method attachChildEnvironment.
@Test
void attachChildEnvironment() {
AttachChildEnvironmentRequest request = new AttachChildEnvironmentRequest();
request.setParentEnvironmentCrn(ENVIRONMENT_CRN);
request.setChildEnvironmentCrn(CHILD_ENVIRONMENT_CRN);
Stack stack = new Stack();
when(stackService.getByOwnEnvironmentCrnAndAccountIdWithLists(ENVIRONMENT_CRN, ACCOUNT_ID)).thenReturn(stack);
underTest.attachChildEnvironment(request, ACCOUNT_ID);
ArgumentCaptor<ChildEnvironment> childEnvironmentArgumentCaptor = ArgumentCaptor.forClass(ChildEnvironment.class);
verify(repository).save(childEnvironmentArgumentCaptor.capture());
ChildEnvironment childEnvironment = childEnvironmentArgumentCaptor.getValue();
Assertions.assertThat(childEnvironment).returns(CHILD_ENVIRONMENT_CRN, ChildEnvironment::getEnvironmentCrn).returns(stack, ChildEnvironment::getStack);
}
use of com.sequenceiq.freeipa.entity.ChildEnvironment in project cloudbreak by hortonworks.
the class ChildEnvironmentServiceTest method detachChildEnvironmentSuccess.
@Test
void detachChildEnvironmentSuccess() {
ChildEnvironment childEnvironment = new ChildEnvironment();
when(repository.findByParentAndChildEnvironmentCrns(ENVIRONMENT_CRN, CHILD_ENVIRONMENT_CRN, ACCOUNT_ID)).thenReturn(Optional.of(childEnvironment));
DetachChildEnvironmentRequest request = new DetachChildEnvironmentRequest();
request.setParentEnvironmentCrn(ENVIRONMENT_CRN);
request.setChildEnvironmentCrn(CHILD_ENVIRONMENT_CRN);
underTest.detachChildEnvironment(request, ACCOUNT_ID);
verify(repository).delete(childEnvironment);
}
use of com.sequenceiq.freeipa.entity.ChildEnvironment 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