Search in sources :

Example 1 with AddDnsZoneForSubnetsRequest

use of com.sequenceiq.freeipa.api.v1.dns.model.AddDnsZoneForSubnetsRequest in project cloudbreak by hortonworks.

the class FreeIpaUpgradeTests method addListDeleteDnsZonesBySubnet.

private void addListDeleteDnsZonesBySubnet(com.sequenceiq.freeipa.api.client.FreeIpaClient ipaClient, String environmentCrn) {
    try {
        AddDnsZoneForSubnetsRequest request = new AddDnsZoneForSubnetsRequest();
        request.setSubnets(List.of("10.0.1.0/24", "192.168.1.0/24"));
        request.setEnvironmentCrn(environmentCrn);
        ipaClient.getDnsV1Endpoint().addDnsZoneForSubnets(request);
        /*          Until CB-15454 is fixed
            Set<String> dnsZones = ipaClient.getDnsV1Endpoint().listDnsZones(environmentCrn);
            Assertions.assertTrue(dnsZones.stream().anyMatch(dnsZone -> dnsZone.startsWith("1.0.10")));
            Assertions.assertTrue(dnsZones.stream().anyMatch(dnsZone -> dnsZone.startsWith("1.168.192")));*/
        ipaClient.getDnsV1Endpoint().deleteDnsZoneBySubnet(environmentCrn, "192.168.1.0/24");
        ipaClient.getDnsV1Endpoint().deleteDnsZoneBySubnet(environmentCrn, "10.0.1.0/24");
    /*            dnsZones = ipaClient.getDnsV1Endpoint().listDnsZones(environmentCrn);
            Assertions.assertFalse(dnsZones.stream().anyMatch(dnsZone -> dnsZone.startsWith("1.0.10")));
            Assertions.assertFalse(dnsZones.stream().anyMatch(dnsZone -> dnsZone.startsWith("1.168.192")));*/
    } catch (Exception e) {
        logger.error("DNS ZONE test failed during upgrade", e);
        throw new TestFailException("DNS ZONE test failed during upgrade with: " + e.getMessage(), e);
    }
}
Also used : AddDnsZoneForSubnetsRequest(com.sequenceiq.freeipa.api.v1.dns.model.AddDnsZoneForSubnetsRequest) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) WebApplicationException(javax.ws.rs.WebApplicationException) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException)

Example 2 with AddDnsZoneForSubnetsRequest

use of com.sequenceiq.freeipa.api.v1.dns.model.AddDnsZoneForSubnetsRequest 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 3 with AddDnsZoneForSubnetsRequest

use of com.sequenceiq.freeipa.api.v1.dns.model.AddDnsZoneForSubnetsRequest 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 4 with AddDnsZoneForSubnetsRequest

use of com.sequenceiq.freeipa.api.v1.dns.model.AddDnsZoneForSubnetsRequest in project cloudbreak by hortonworks.

the class DnsZoneService method addDnsZonesForSubnets.

@Retryable(value = RetryableFreeIpaClientException.class, maxAttemptsExpression = RetryableFreeIpaClientException.MAX_RETRIES_EXPRESSION, backoff = @Backoff(delayExpression = RetryableFreeIpaClientException.DELAY_EXPRESSION, multiplierExpression = RetryableFreeIpaClientException.MULTIPLIER_EXPRESSION))
public AddDnsZoneForSubnetsResponse addDnsZonesForSubnets(AddDnsZoneForSubnetsRequest request, String accountId) throws FreeIpaClientException {
    FreeIpaClient client = getFreeIpaClient(request.getEnvironmentCrn(), accountId);
    AddDnsZoneForSubnetsResponse response = new AddDnsZoneForSubnetsResponse();
    for (String subnet : request.getSubnets()) {
        try {
            LOGGER.info("Add subnet's [{}] reverse DNS zone", subnet);
            client.addReverseDnsZone(subnet);
            response.getSuccess().add(subnet);
            LOGGER.debug("Subnet [{}] added", subnet);
        } catch (RetryableFreeIpaClientException e) {
            throw e;
        } catch (FreeIpaClientException e) {
            LOGGER.warn("Can't add subnet's [{}] reverse DNS zone", subnet, e);
            response.getFailed().put(subnet, e.getMessage());
        }
    }
    return response;
}
Also used : RetryableFreeIpaClientException(com.sequenceiq.freeipa.client.RetryableFreeIpaClientException) AddDnsZoneForSubnetsResponse(com.sequenceiq.freeipa.api.v1.dns.model.AddDnsZoneForSubnetsResponse) FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) RetryableFreeIpaClientException(com.sequenceiq.freeipa.client.RetryableFreeIpaClientException) Retryable(org.springframework.retry.annotation.Retryable)

Aggregations

AddDnsZoneForSubnetsRequest (com.sequenceiq.freeipa.api.v1.dns.model.AddDnsZoneForSubnetsRequest)3 AttachChildEnvironmentRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.attachchildenv.AttachChildEnvironmentRequest)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 AddDnsZoneForSubnetsResponse (com.sequenceiq.freeipa.api.v1.dns.model.AddDnsZoneForSubnetsResponse)1 FreeIpaClient (com.sequenceiq.freeipa.client.FreeIpaClient)1 FreeIpaClientException (com.sequenceiq.freeipa.client.FreeIpaClientException)1 RetryableFreeIpaClientException (com.sequenceiq.freeipa.client.RetryableFreeIpaClientException)1 TestFailException (com.sequenceiq.it.cloudbreak.exception.TestFailException)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 Test (org.junit.jupiter.api.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 Retryable (org.springframework.retry.annotation.Retryable)1 Headers (reactor.bus.Event.Headers)1