Search in sources :

Example 11 with DnsRecord

use of com.sequenceiq.freeipa.client.model.DnsRecord in project cloudbreak by hortonworks.

the class DnsRecordServiceTest method testCnameRecordExistsDifferentValue.

@Test
public void testCnameRecordExistsDifferentValue() throws FreeIpaClientException {
    AddDnsCnameRecordRequest request = new AddDnsCnameRecordRequest();
    request.setEnvironmentCrn(ENV_CRN);
    request.setCname("Asdf");
    request.setTargetFqdn(TARGET_FQDN);
    Stack stack = createStack();
    when(stackService.getByEnvironmentCrnAndAccountId(ENV_CRN, ACCOUNT_ID)).thenReturn(stack);
    FreeIpa freeIpa = createFreeIpa();
    when(freeIpaService.findByStack(stack)).thenReturn(freeIpa);
    when(freeIpaClientFactory.getFreeIpaClientForStack(stack)).thenReturn(freeIpaClient);
    DnsRecord dnsRecord = new DnsRecord();
    dnsRecord.setCnamerecord(List.of("asdf"));
    dnsRecord.setIdnsname(request.getCname());
    when(freeIpaClient.showDnsRecord(DOMAIN, request.getCname())).thenReturn(dnsRecord);
    Assertions.assertThrows(DnsRecordConflictException.class, () -> underTest.addDnsCnameRecord(ACCOUNT_ID, request));
}
Also used : FreeIpa(com.sequenceiq.freeipa.entity.FreeIpa) AddDnsCnameRecordRequest(com.sequenceiq.freeipa.api.v1.dns.model.AddDnsCnameRecordRequest) DnsRecord(com.sequenceiq.freeipa.client.model.DnsRecord) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 12 with DnsRecord

use of com.sequenceiq.freeipa.client.model.DnsRecord in project cloudbreak by hortonworks.

the class DnsRecordService method deleteSrvRecords.

private void deleteSrvRecords(FreeIpaClient freeIpaClient, DnsZone dnsZone, Set<DnsRecord> allDnsRecordsInZone, List<String> fqdns) throws FreeIpaClientException {
    Set<DnsRecord> srvRecordsToDelete = allDnsRecordsInZone.stream().filter(record -> fqdns.stream().anyMatch(record::isHostRelatedSrvRecord)).collect(Collectors.toSet());
    for (DnsRecord dnsRecord : srvRecordsToDelete) {
        for (String fqdn : fqdns) {
            List<String> srvRecords = dnsRecord.getHostRelatedSrvRecords(fqdn);
            if (!srvRecords.isEmpty()) {
                LOGGER.info("Delete DNS SRV record [{}] for [{}] in zone [{}]", dnsRecord.getIdnsname(), fqdn, dnsZone);
                ignoreNotFoundException(() -> freeIpaClient.deleteDnsSrvRecord(dnsRecord.getIdnsname(), dnsZone.getIdnsname(), srvRecords), "DNS SRV record [{}] for [{}] not found in zone [{}]", dnsRecord.getIdnsname(), fqdn, dnsZone);
            }
        }
    }
}
Also used : FreeIpaClientExceptionUtil.ignoreNotFoundException(com.sequenceiq.freeipa.client.FreeIpaClientExceptionUtil.ignoreNotFoundException) FreeIpaClientExceptionUtil.ignoreNotFoundExceptionWithValue(com.sequenceiq.freeipa.client.FreeIpaClientExceptionUtil.ignoreNotFoundExceptionWithValue) LoggerFactory(org.slf4j.LoggerFactory) MDCBuilder(com.sequenceiq.cloudbreak.logger.MDCBuilder) Measure(com.sequenceiq.cloudbreak.aspect.Measure) StringUtils(org.apache.commons.lang3.StringUtils) AddDnsARecordRequest(com.sequenceiq.freeipa.api.v1.dns.model.AddDnsARecordRequest) Inject(javax.inject.Inject) Valid(javax.validation.Valid) FreeIpaClientExceptionUtil.ignoreEmptyModExceptionWithValue(com.sequenceiq.freeipa.client.FreeIpaClientExceptionUtil.ignoreEmptyModExceptionWithValue) DnsZone(com.sequenceiq.freeipa.client.model.DnsZone) RetryableFreeIpaClientException(com.sequenceiq.freeipa.client.RetryableFreeIpaClientException) Service(org.springframework.stereotype.Service) StackService(com.sequenceiq.freeipa.service.stack.StackService) Retryable(org.springframework.retry.annotation.Retryable) Stack(com.sequenceiq.freeipa.entity.Stack) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Logger(org.slf4j.Logger) FreeIpa(com.sequenceiq.freeipa.entity.FreeIpa) FreeIpaClientExceptionUtil(com.sequenceiq.freeipa.client.FreeIpaClientExceptionUtil) Set(java.util.Set) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) DnsRecord(com.sequenceiq.freeipa.client.model.DnsRecord) FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) Collectors(java.util.stream.Collectors) Backoff(org.springframework.retry.annotation.Backoff) List(java.util.List) FreeIpaService(com.sequenceiq.freeipa.service.freeipa.FreeIpaService) AddDnsCnameRecordRequest(com.sequenceiq.freeipa.api.v1.dns.model.AddDnsCnameRecordRequest) FreeIpaClientFactory(com.sequenceiq.freeipa.service.freeipa.FreeIpaClientFactory) Optional(java.util.Optional) DnsRecord(com.sequenceiq.freeipa.client.model.DnsRecord)

Example 13 with DnsRecord

use of com.sequenceiq.freeipa.client.model.DnsRecord in project cloudbreak by hortonworks.

the class DnsRecordService method deleteDnsRecordByFqdn.

@Retryable(value = RetryableFreeIpaClientException.class, maxAttemptsExpression = RetryableFreeIpaClientException.MAX_RETRIES_EXPRESSION, backoff = @Backoff(delayExpression = RetryableFreeIpaClientException.DELAY_EXPRESSION, multiplierExpression = RetryableFreeIpaClientException.MULTIPLIER_EXPRESSION))
@Measure(DnsRecordService.class)
public void deleteDnsRecordByFqdn(String environmentCrn, String accountId, List<String> fqdns) throws FreeIpaClientException {
    FreeIpaAndClient freeIpaAndClient = createFreeIpaAndClient(environmentCrn, accountId);
    for (DnsZone dnsZone : freeIpaAndClient.getClient().findAllDnsZone()) {
        LOGGER.debug("Looking for records in zone [{}]", dnsZone.getIdnsname());
        Set<DnsRecord> allDnsRecordsInZone = freeIpaAndClient.getClient().findAllDnsRecordInZone(dnsZone.getIdnsname());
        deleteRegularRecords(freeIpaAndClient.getClient(), dnsZone, allDnsRecordsInZone, fqdns, freeIpaAndClient.getFreeIpa().getDomain());
        deleteSrvRecords(freeIpaAndClient.getClient(), dnsZone, allDnsRecordsInZone, fqdns);
    }
}
Also used : DnsRecord(com.sequenceiq.freeipa.client.model.DnsRecord) DnsZone(com.sequenceiq.freeipa.client.model.DnsZone) Retryable(org.springframework.retry.annotation.Retryable) Measure(com.sequenceiq.cloudbreak.aspect.Measure)

Example 14 with DnsRecord

use of com.sequenceiq.freeipa.client.model.DnsRecord in project cloudbreak by hortonworks.

the class DnsRecordService method deleteRegularRecords.

private void deleteRegularRecords(FreeIpaClient freeIpaClient, DnsZone dnsZone, Set<DnsRecord> allDnsRecordsInZone, List<String> fqdns, String domain) throws FreeIpaClientException {
    Set<DnsRecord> recordsToDelete = allDnsRecordsInZone.stream().filter(record -> fqdns.stream().anyMatch(fqdn -> record.isHostRelatedRecord(fqdn, domain))).collect(Collectors.toSet());
    for (DnsRecord dnsRecord : recordsToDelete) {
        LOGGER.info("Delete DNS record [{}] in zone [{}]", dnsRecord, dnsZone);
        ignoreNotFoundException(() -> freeIpaClient.deleteDnsRecord(dnsRecord.getIdnsname(), dnsZone.getIdnsname()), "DNS record [{}] not found in zone [{}]", dnsRecord, dnsZone);
    }
}
Also used : FreeIpaClientExceptionUtil.ignoreNotFoundException(com.sequenceiq.freeipa.client.FreeIpaClientExceptionUtil.ignoreNotFoundException) FreeIpaClientExceptionUtil.ignoreNotFoundExceptionWithValue(com.sequenceiq.freeipa.client.FreeIpaClientExceptionUtil.ignoreNotFoundExceptionWithValue) LoggerFactory(org.slf4j.LoggerFactory) MDCBuilder(com.sequenceiq.cloudbreak.logger.MDCBuilder) Measure(com.sequenceiq.cloudbreak.aspect.Measure) StringUtils(org.apache.commons.lang3.StringUtils) AddDnsARecordRequest(com.sequenceiq.freeipa.api.v1.dns.model.AddDnsARecordRequest) Inject(javax.inject.Inject) Valid(javax.validation.Valid) FreeIpaClientExceptionUtil.ignoreEmptyModExceptionWithValue(com.sequenceiq.freeipa.client.FreeIpaClientExceptionUtil.ignoreEmptyModExceptionWithValue) DnsZone(com.sequenceiq.freeipa.client.model.DnsZone) RetryableFreeIpaClientException(com.sequenceiq.freeipa.client.RetryableFreeIpaClientException) Service(org.springframework.stereotype.Service) StackService(com.sequenceiq.freeipa.service.stack.StackService) Retryable(org.springframework.retry.annotation.Retryable) Stack(com.sequenceiq.freeipa.entity.Stack) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Logger(org.slf4j.Logger) FreeIpa(com.sequenceiq.freeipa.entity.FreeIpa) FreeIpaClientExceptionUtil(com.sequenceiq.freeipa.client.FreeIpaClientExceptionUtil) Set(java.util.Set) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) DnsRecord(com.sequenceiq.freeipa.client.model.DnsRecord) FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) Collectors(java.util.stream.Collectors) Backoff(org.springframework.retry.annotation.Backoff) List(java.util.List) FreeIpaService(com.sequenceiq.freeipa.service.freeipa.FreeIpaService) AddDnsCnameRecordRequest(com.sequenceiq.freeipa.api.v1.dns.model.AddDnsCnameRecordRequest) FreeIpaClientFactory(com.sequenceiq.freeipa.service.freeipa.FreeIpaClientFactory) Optional(java.util.Optional) DnsRecord(com.sequenceiq.freeipa.client.model.DnsRecord)

Aggregations

DnsRecord (com.sequenceiq.freeipa.client.model.DnsRecord)14 FreeIpa (com.sequenceiq.freeipa.entity.FreeIpa)8 Stack (com.sequenceiq.freeipa.entity.Stack)8 Test (org.junit.jupiter.api.Test)6 AddDnsARecordRequest (com.sequenceiq.freeipa.api.v1.dns.model.AddDnsARecordRequest)5 AddDnsCnameRecordRequest (com.sequenceiq.freeipa.api.v1.dns.model.AddDnsCnameRecordRequest)5 DnsZone (com.sequenceiq.freeipa.client.model.DnsZone)4 Measure (com.sequenceiq.cloudbreak.aspect.Measure)3 FreeIpaClient (com.sequenceiq.freeipa.client.FreeIpaClient)3 FreeIpaClientException (com.sequenceiq.freeipa.client.FreeIpaClientException)3 Set (java.util.Set)3 Retryable (org.springframework.retry.annotation.Retryable)3 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)2 MDCBuilder (com.sequenceiq.cloudbreak.logger.MDCBuilder)2 FreeIpaClientExceptionUtil (com.sequenceiq.freeipa.client.FreeIpaClientExceptionUtil)2 FreeIpaClientExceptionUtil.ignoreEmptyModExceptionWithValue (com.sequenceiq.freeipa.client.FreeIpaClientExceptionUtil.ignoreEmptyModExceptionWithValue)2 FreeIpaClientExceptionUtil.ignoreNotFoundException (com.sequenceiq.freeipa.client.FreeIpaClientExceptionUtil.ignoreNotFoundException)2 FreeIpaClientExceptionUtil.ignoreNotFoundExceptionWithValue (com.sequenceiq.freeipa.client.FreeIpaClientExceptionUtil.ignoreNotFoundExceptionWithValue)2 RetryableFreeIpaClientException (com.sequenceiq.freeipa.client.RetryableFreeIpaClientException)2 FreeIpaClientFactory (com.sequenceiq.freeipa.service.freeipa.FreeIpaClientFactory)2