Search in sources :

Example 1 with DetachChildEnvironmentRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.detachchildenv.DetachChildEnvironmentRequest in project cloudbreak by hortonworks.

the class FreeIpaDeletionHandlerTest method shouldDetachChildEnvironmentIfParentExists.

@Test
public void shouldDetachChildEnvironmentIfParentExists() throws Exception {
    EnvironmentDto environmentDto = new EnvironmentDto();
    environmentDto.setId(CHILD_ENVIRONMENT_ID);
    EnvironmentDeletionDto environmentDeletionDto = EnvironmentDeletionDto.builder().withEnvironmentDto(environmentDto).withForceDelete(true).withId(CHILD_ENVIRONMENT_ID).build();
    when(environmentService.findEnvironmentById(CHILD_ENVIRONMENT_ID)).thenReturn(of(anEnvironmentWithParent(CHILD_ENVIRONMENT_ID)));
    when(freeIpaService.describe(ENVIRONMENT_CRN)).thenReturn(of(new DescribeFreeIpaResponse()));
    victim.accept(new Event<>(environmentDeletionDto));
    ArgumentCaptor<DetachChildEnvironmentRequest> detachChildEnvironmentRequestArgumentCaptor = ArgumentCaptor.forClass(DetachChildEnvironmentRequest.class);
    verify(freeIpaService).detachChildEnvironment(detachChildEnvironmentRequestArgumentCaptor.capture());
    verifyNoMoreInteractions(freeIpaService);
    verify(eventSender).sendEvent(any(BaseNamedFlowEvent.class), any(Event.Headers.class));
    verify(dnsV1Endpoint).deleteDnsZoneBySubnet(eq(PARENT_ENVIRONMENT_CRN), any());
    assertEquals(PARENT_ENVIRONMENT_CRN, detachChildEnvironmentRequestArgumentCaptor.getValue().getParentEnvironmentCrn());
    assertEquals(ENVIRONMENT_CRN, detachChildEnvironmentRequestArgumentCaptor.getValue().getChildEnvironmentCrn());
}
Also used : BaseNamedFlowEvent(com.sequenceiq.flow.reactor.api.event.BaseNamedFlowEvent) DescribeFreeIpaResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) DetachChildEnvironmentRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.detachchildenv.DetachChildEnvironmentRequest) EnvironmentDeletionDto(com.sequenceiq.environment.environment.dto.EnvironmentDeletionDto) Test(org.junit.jupiter.api.Test)

Example 2 with DetachChildEnvironmentRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.detachchildenv.DetachChildEnvironmentRequest in project cloudbreak by hortonworks.

the class FreeIpaDetachChildEnvironmentAction method convertRequest.

private DetachChildEnvironmentRequest convertRequest(AttachChildEnvironmentRequest attachChildEnvironmentRequest) {
    DetachChildEnvironmentRequest detachChildEnvironmentRequest = new DetachChildEnvironmentRequest();
    detachChildEnvironmentRequest.setParentEnvironmentCrn(attachChildEnvironmentRequest.getParentEnvironmentCrn());
    detachChildEnvironmentRequest.setChildEnvironmentCrn(attachChildEnvironmentRequest.getChildEnvironmentCrn());
    return detachChildEnvironmentRequest;
}
Also used : DetachChildEnvironmentRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.detachchildenv.DetachChildEnvironmentRequest)

Example 3 with DetachChildEnvironmentRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.detachchildenv.DetachChildEnvironmentRequest in project cloudbreak by hortonworks.

the class ChildEnvironmentServiceTest method detachChildEnvironmentFailure.

@Test
void detachChildEnvironmentFailure() {
    when(repository.findByParentAndChildEnvironmentCrns(ENVIRONMENT_CRN, CHILD_ENVIRONMENT_CRN, ACCOUNT_ID)).thenReturn(Optional.empty());
    DetachChildEnvironmentRequest request = new DetachChildEnvironmentRequest();
    request.setParentEnvironmentCrn(ENVIRONMENT_CRN);
    request.setChildEnvironmentCrn(CHILD_ENVIRONMENT_CRN);
    Assertions.assertThatThrownBy(() -> underTest.detachChildEnvironment(request, ACCOUNT_ID)).isInstanceOf(NotFoundException.class);
}
Also used : DetachChildEnvironmentRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.detachchildenv.DetachChildEnvironmentRequest) Test(org.junit.jupiter.api.Test)

Example 4 with DetachChildEnvironmentRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.detachchildenv.DetachChildEnvironmentRequest 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 5 with DetachChildEnvironmentRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.detachchildenv.DetachChildEnvironmentRequest in project cloudbreak by hortonworks.

the class FreeIpaDeletionHandler method detachChildEnvironmentFromFreeIpa.

private void detachChildEnvironmentFromFreeIpa(Environment environment) {
    try {
        DetachChildEnvironmentRequest detachChildEnvironmentRequest = new DetachChildEnvironmentRequest();
        detachChildEnvironmentRequest.setParentEnvironmentCrn(environment.getParentEnvironment().getResourceCrn());
        detachChildEnvironmentRequest.setChildEnvironmentCrn(environment.getResourceCrn());
        freeIpaService.detachChildEnvironment(detachChildEnvironmentRequest);
        if (lastChildEnvironmentInNetworkIsGettingDeleted(environment)) {
            try {
                dnsV1Endpoint.deleteDnsZoneBySubnet(environment.getParentEnvironment().getResourceCrn(), environment.getNetwork().getNetworkCidr());
            } catch (Exception e) {
                LOGGER.warn("Failed to delete dns zone of child environment.", e);
            }
        }
    } catch (FreeIpaOperationFailedException e) {
        if (e.getCause() instanceof NotFoundException) {
            LOGGER.warn("Child FreeIpa is already detached.", e);
        } else {
            throw e;
        }
    }
}
Also used : FreeIpaOperationFailedException(com.sequenceiq.environment.exception.FreeIpaOperationFailedException) NotFoundException(javax.ws.rs.NotFoundException) DetachChildEnvironmentRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.detachchildenv.DetachChildEnvironmentRequest) FreeIpaOperationFailedException(com.sequenceiq.environment.exception.FreeIpaOperationFailedException) NotFoundException(javax.ws.rs.NotFoundException)

Aggregations

DetachChildEnvironmentRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.detachchildenv.DetachChildEnvironmentRequest)8 Test (org.junit.jupiter.api.Test)5 ChildEnvironment (com.sequenceiq.freeipa.entity.ChildEnvironment)2 NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)1 EnvironmentDeletionDto (com.sequenceiq.environment.environment.dto.EnvironmentDeletionDto)1 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)1 FreeIpaOperationFailedException (com.sequenceiq.environment.exception.FreeIpaOperationFailedException)1 BaseNamedFlowEvent (com.sequenceiq.flow.reactor.api.event.BaseNamedFlowEvent)1 DescribeFreeIpaResponse (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse)1 NotFoundException (javax.ws.rs.NotFoundException)1