Search in sources :

Example 1 with AttachChildEnvironmentRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.attachchildenv.AttachChildEnvironmentRequest in project cloudbreak by hortonworks.

the class FreeIpaCreationHandlerTest method shouldAttachFreeIpaInCaseOfChildEnvironment.

@Test
public void shouldAttachFreeIpaInCaseOfChildEnvironment() throws Exception {
    DescribeFreeIpaResponse describeFreeIpaResponse = mock(DescribeFreeIpaResponse.class);
    EnvironmentDto environmentDto = aYarnEnvironmentDtoWithParentEnvironment();
    Environment environment = anEnvironmentWithParent();
    ArgumentCaptor<AddDnsZoneForSubnetsRequest> addDnsZoneForSubnetsRequestArgumentCaptor = ArgumentCaptor.forClass(AddDnsZoneForSubnetsRequest.class);
    when(environmentService.findEnvironmentById(ENVIRONMENT_ID)).thenReturn(Optional.of(environment));
    when(freeIpaService.describe(PARENT_ENVIRONMENT_CRN)).thenReturn(Optional.of(describeFreeIpaResponse));
    victim.accept(new Event<>(environmentDto));
    ArgumentCaptor<AttachChildEnvironmentRequest> attachChildEnvironmentRequestArgumentCaptor = ArgumentCaptor.forClass(AttachChildEnvironmentRequest.class);
    verify(dnsV1Endpoint).addDnsZoneForSubnets(addDnsZoneForSubnetsRequestArgumentCaptor.capture());
    verify(freeIpaService).attachChildEnvironment(attachChildEnvironmentRequestArgumentCaptor.capture());
    verify(eventSender).sendEvent(any(BaseNamedFlowEvent.class), any(Headers.class));
    assertEquals(PARENT_ENVIRONMENT_CRN, addDnsZoneForSubnetsRequestArgumentCaptor.getValue().getEnvironmentCrn());
    assertEquals(Collections.singletonList(YARN_NETWORK_CIDR), addDnsZoneForSubnetsRequestArgumentCaptor.getValue().getSubnets());
    assertEquals(ENVIRONMENT_CRN, attachChildEnvironmentRequestArgumentCaptor.getValue().getChildEnvironmentCrn());
    assertEquals(PARENT_ENVIRONMENT_CRN, attachChildEnvironmentRequestArgumentCaptor.getValue().getParentEnvironmentCrn());
}
Also used : BaseNamedFlowEvent(com.sequenceiq.flow.reactor.api.event.BaseNamedFlowEvent) DescribeFreeIpaResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse) AddDnsZoneForSubnetsRequest(com.sequenceiq.freeipa.api.v1.dns.model.AddDnsZoneForSubnetsRequest) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) Headers(reactor.bus.Event.Headers) Environment(com.sequenceiq.environment.environment.domain.Environment) AttachChildEnvironmentRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.attachchildenv.AttachChildEnvironmentRequest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with AttachChildEnvironmentRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.attachchildenv.AttachChildEnvironmentRequest 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 AttachChildEnvironmentRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.attachchildenv.AttachChildEnvironmentRequest in project cloudbreak by hortonworks.

the class FreeIpaV1ControllerTest method attachChildEnvironment.

@Test
void attachChildEnvironment() {
    AttachChildEnvironmentRequest attachChildEnvironmentRequest = new AttachChildEnvironmentRequest();
    when(attachChildEnvironmentRequestValidator.validate(attachChildEnvironmentRequest)).thenReturn(ValidationResult.builder().build());
    underTest.attachChildEnvironment(attachChildEnvironmentRequest);
    verify(childEnvironmentService, times(1)).attachChildEnvironment(attachChildEnvironmentRequest, ACCOUNT_ID);
}
Also used : AttachChildEnvironmentRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.attachchildenv.AttachChildEnvironmentRequest) Test(org.junit.jupiter.api.Test)

Example 4 with AttachChildEnvironmentRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.attachchildenv.AttachChildEnvironmentRequest in project cloudbreak by hortonworks.

the class FreeIpaCreationHandler method attachParentFreeIpa.

private void attachParentFreeIpa(EnvironmentDto environmentDto) throws Exception {
    if (enabledChildPlatforms.stream().anyMatch(p -> p.equalsIgnoreCase(environmentDto.getCloudPlatform()))) {
        String parentEnvironmentCrn = environmentDto.getParentEnvironmentCrn();
        Optional<DescribeFreeIpaResponse> freeIpa = freeIpaService.describe(parentEnvironmentCrn);
        if (freeIpa.isPresent()) {
            LOGGER.info("Using FreeIpa of parent environment '{}' .", parentEnvironmentCrn);
            AttachChildEnvironmentRequest attachChildEnvironmentRequest = new AttachChildEnvironmentRequest();
            attachChildEnvironmentRequest.setChildEnvironmentCrn(environmentDto.getResourceCrn());
            attachChildEnvironmentRequest.setParentEnvironmentCrn(parentEnvironmentCrn);
            freeIpaService.attachChildEnvironment(attachChildEnvironmentRequest);
            AddDnsZoneForSubnetsRequest addDnsZoneForSubnetsRequest = new AddDnsZoneForSubnetsRequest();
            addDnsZoneForSubnetsRequest.setEnvironmentCrn(parentEnvironmentCrn);
            addDnsZoneForSubnetsRequest.setSubnets(getSubnetCidrs(environmentDto));
            dnsV1Endpoint.addDnsZoneForSubnets(addDnsZoneForSubnetsRequest);
        }
    }
}
Also used : DescribeFreeIpaResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse) AddDnsZoneForSubnetsRequest(com.sequenceiq.freeipa.api.v1.dns.model.AddDnsZoneForSubnetsRequest) AttachChildEnvironmentRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.attachchildenv.AttachChildEnvironmentRequest)

Example 5 with AttachChildEnvironmentRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.attachchildenv.AttachChildEnvironmentRequest 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)

Aggregations

AttachChildEnvironmentRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.attachchildenv.AttachChildEnvironmentRequest)4 Test (org.junit.jupiter.api.Test)3 AddDnsZoneForSubnetsRequest (com.sequenceiq.freeipa.api.v1.dns.model.AddDnsZoneForSubnetsRequest)2 DescribeFreeIpaResponse (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse)2 Environment (com.sequenceiq.environment.environment.domain.Environment)1 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)1 BaseNamedFlowEvent (com.sequenceiq.flow.reactor.api.event.BaseNamedFlowEvent)1 DetachChildEnvironmentRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.detachchildenv.DetachChildEnvironmentRequest)1 ChildEnvironment (com.sequenceiq.freeipa.entity.ChildEnvironment)1 Stack (com.sequenceiq.freeipa.entity.Stack)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 Headers (reactor.bus.Event.Headers)1