Search in sources :

Example 1 with AddDnsZoneForSubnetIdsRequest

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

the class FreeIpaCreationHandler method createFreeIpa.

private void createFreeIpa(Event<EnvironmentDto> environmentDtoEvent, EnvironmentDto environmentDto) throws Exception {
    Optional<DescribeFreeIpaResponse> freeIpa = freeIpaService.describe(environmentDto.getResourceCrn());
    if (freeIpa.isEmpty()) {
        LOGGER.info("FreeIpa for environmentCrn '{}' was not found, creating a new one.", environmentDto.getResourceCrn());
        CreateFreeIpaRequest createFreeIpaRequest = createFreeIpaRequest(environmentDto);
        freeIpaService.create(createFreeIpaRequest);
        awaitFreeIpaCreation(environmentDtoEvent, environmentDto);
        AddDnsZoneForSubnetIdsRequest addDnsZoneForSubnetIdsRequest = addDnsZoneForSubnetIdsRequest(environmentDto);
        if (shouldSendSubnetIdsToFreeIpa(addDnsZoneForSubnetIdsRequest)) {
            dnsV1Endpoint.addDnsZoneForSubnetIds(addDnsZoneForSubnetIdsRequest);
        }
    } else {
        LOGGER.info("FreeIpa for environmentCrn '{}' already exists. Using this one.", environmentDto.getResourceCrn());
        if (CREATE_IN_PROGRESS == freeIpa.get().getStatus()) {
            awaitFreeIpaCreation(environmentDtoEvent, environmentDto);
        }
    }
}
Also used : DescribeFreeIpaResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse) CreateFreeIpaRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.CreateFreeIpaRequest) AddDnsZoneForSubnetIdsRequest(com.sequenceiq.freeipa.api.v1.dns.model.AddDnsZoneForSubnetIdsRequest)

Example 2 with AddDnsZoneForSubnetIdsRequest

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

the class DnsZoneService method addDnsZonesForSubnetIds.

@Retryable(value = RetryableFreeIpaClientException.class, maxAttemptsExpression = RetryableFreeIpaClientException.MAX_RETRIES_EXPRESSION, backoff = @Backoff(delayExpression = RetryableFreeIpaClientException.DELAY_EXPRESSION, multiplierExpression = RetryableFreeIpaClientException.MULTIPLIER_EXPRESSION))
public AddDnsZoneForSubnetsResponse addDnsZonesForSubnetIds(AddDnsZoneForSubnetIdsRequest request, String accountId) throws FreeIpaClientException {
    Stack stack = stackService.getByEnvironmentCrnAndAccountId(request.getEnvironmentCrn(), accountId);
    MDCBuilder.buildMdcContext(stack);
    Multimap<String, String> subnetWithCidr = networkService.getFilteredSubnetWithCidr(request.getEnvironmentCrn(), stack, request.getAddDnsZoneNetwork().getNetworkId(), request.getAddDnsZoneNetwork().getSubnetIds());
    FreeIpaClient client = freeIpaClientFactory.getFreeIpaClientForStack(stack);
    AddDnsZoneForSubnetsResponse response = new AddDnsZoneForSubnetsResponse();
    for (Entry<String, String> subnet : subnetWithCidr.entries()) {
        try {
            LOGGER.info("Add subnet's [{}] reverse DNS zone", subnet);
            String subnetCidr = subnet.getValue();
            Set<DnsZone> dnsZones = client.findDnsZone(subnetCidr);
            if (dnsZones.isEmpty()) {
                LOGGER.debug("Subnet reverse DNS zone does not exists [{}], add it now", subnet);
                client.addReverseDnsZone(subnetCidr);
                response.getSuccess().add(subnet.getKey());
                LOGGER.debug("Subnet [{}] added", subnet);
            }
        } catch (RetryableFreeIpaClientException e) {
            throw e;
        } catch (FreeIpaClientException e) {
            LOGGER.warn("Can't add subnet's [{}] reverse DNS zone with cidr [{}]", subnet, subnet.getValue(), e);
            response.getFailed().putIfAbsent(subnet.getKey(), 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) DnsZone(com.sequenceiq.freeipa.client.model.DnsZone) Stack(com.sequenceiq.freeipa.entity.Stack) Retryable(org.springframework.retry.annotation.Retryable)

Example 3 with AddDnsZoneForSubnetIdsRequest

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

the class FreeIpaCreationHandler method addDnsZoneForSubnetIdsRequest.

private AddDnsZoneForSubnetIdsRequest addDnsZoneForSubnetIdsRequest(EnvironmentDto environmentDto) {
    AddDnsZoneForSubnetIdsRequest addDnsZoneForSubnetIdsRequest = new AddDnsZoneForSubnetIdsRequest();
    addDnsZoneForSubnetIdsRequest.setEnvironmentCrn(environmentDto.getResourceCrn());
    AddDnsZoneNetwork addDnsZoneNetwork = new AddDnsZoneNetwork();
    addDnsZoneNetwork.setNetworkId(environmentDto.getNetwork().getNetworkId());
    addDnsZoneNetwork.setSubnetIds(environmentDto.getNetwork().getSubnetIds());
    addDnsZoneForSubnetIdsRequest.setAddDnsZoneNetwork(addDnsZoneNetwork);
    return addDnsZoneForSubnetIdsRequest;
}
Also used : AddDnsZoneForSubnetIdsRequest(com.sequenceiq.freeipa.api.v1.dns.model.AddDnsZoneForSubnetIdsRequest) AddDnsZoneNetwork(com.sequenceiq.freeipa.api.v1.dns.model.AddDnsZoneNetwork)

Aggregations

AddDnsZoneForSubnetIdsRequest (com.sequenceiq.freeipa.api.v1.dns.model.AddDnsZoneForSubnetIdsRequest)2 AddDnsZoneForSubnetsResponse (com.sequenceiq.freeipa.api.v1.dns.model.AddDnsZoneForSubnetsResponse)1 AddDnsZoneNetwork (com.sequenceiq.freeipa.api.v1.dns.model.AddDnsZoneNetwork)1 CreateFreeIpaRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.CreateFreeIpaRequest)1 DescribeFreeIpaResponse (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse)1 FreeIpaClient (com.sequenceiq.freeipa.client.FreeIpaClient)1 FreeIpaClientException (com.sequenceiq.freeipa.client.FreeIpaClientException)1 RetryableFreeIpaClientException (com.sequenceiq.freeipa.client.RetryableFreeIpaClientException)1 DnsZone (com.sequenceiq.freeipa.client.model.DnsZone)1 Stack (com.sequenceiq.freeipa.entity.Stack)1 Retryable (org.springframework.retry.annotation.Retryable)1