Search in sources :

Example 1 with ChildEnvironment

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);
}
Also used : ChildEnvironment(com.sequenceiq.freeipa.entity.ChildEnvironment) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) DetachChildEnvironmentRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.detachchildenv.DetachChildEnvironmentRequest) Test(org.junit.jupiter.api.Test)

Example 2 with ChildEnvironment

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);
}
Also used : ChildEnvironment(com.sequenceiq.freeipa.entity.ChildEnvironment) Stack(com.sequenceiq.freeipa.entity.Stack)

Example 3 with 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);
}
Also used : ChildEnvironment(com.sequenceiq.freeipa.entity.ChildEnvironment) AttachChildEnvironmentRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.attachchildenv.AttachChildEnvironmentRequest) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 4 with ChildEnvironment

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);
}
Also used : ChildEnvironment(com.sequenceiq.freeipa.entity.ChildEnvironment) DetachChildEnvironmentRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.detachchildenv.DetachChildEnvironmentRequest) Test(org.junit.jupiter.api.Test)

Example 5 with 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()));
    }
}
Also used : ChildEnvironment(com.sequenceiq.freeipa.entity.ChildEnvironment) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) ObjectOptimisticLockingFailureException(org.springframework.orm.ObjectOptimisticLockingFailureException)

Aggregations

ChildEnvironment (com.sequenceiq.freeipa.entity.ChildEnvironment)5 Test (org.junit.jupiter.api.Test)3 NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)2 DetachChildEnvironmentRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.detachchildenv.DetachChildEnvironmentRequest)2 Stack (com.sequenceiq.freeipa.entity.Stack)2 AttachChildEnvironmentRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.attachchildenv.AttachChildEnvironmentRequest)1 ObjectOptimisticLockingFailureException (org.springframework.orm.ObjectOptimisticLockingFailureException)1