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));
}
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);
}
}
}
}
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);
}
}
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);
}
}
Aggregations