Search in sources :

Example 1 with AddDnsZoneForSubnetsResponse

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

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

AddDnsZoneForSubnetsResponse (com.sequenceiq.freeipa.api.v1.dns.model.AddDnsZoneForSubnetsResponse)2 FreeIpaClient (com.sequenceiq.freeipa.client.FreeIpaClient)2 FreeIpaClientException (com.sequenceiq.freeipa.client.FreeIpaClientException)2 RetryableFreeIpaClientException (com.sequenceiq.freeipa.client.RetryableFreeIpaClientException)2 Retryable (org.springframework.retry.annotation.Retryable)2 DnsZone (com.sequenceiq.freeipa.client.model.DnsZone)1 Stack (com.sequenceiq.freeipa.entity.Stack)1