use of com.sequenceiq.freeipa.client.model.DnsZone 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;
}
use of com.sequenceiq.freeipa.client.model.DnsZone in project cloudbreak by hortonworks.
the class CleanupServiceTest method testRemoveDnsEntries.
@Test
public void testRemoveDnsEntries() throws FreeIpaClientException {
FreeIpaClient client = mock(FreeIpaClient.class);
when(freeIpaClientFactory.getFreeIpaClientForStackId(STACK_ID)).thenReturn(client);
DnsZone dnsZone = new DnsZone();
String domain = "test.com";
dnsZone.setIdnsname(domain);
DnsZone reverseZone = new DnsZone();
reverseZone.setIdnsname("0.10.in-addr.arpa.");
DnsZone disappearingZone = new DnsZone();
disappearingZone.setIdnsname("disappear");
when(client.findAllDnsZone()).thenReturn(Set.of(dnsZone, reverseZone, disappearingZone));
DnsRecord deleteMe = new DnsRecord();
deleteMe.setIdnsname("deleteMe");
deleteMe.setArecord(List.of("ignored"));
DnsRecord notFound = new DnsRecord();
notFound.setIdnsname("notfound");
notFound.setArecord(List.of("ignored"));
DnsRecord failed = new DnsRecord();
failed.setIdnsname("failed");
failed.setArecord(List.of("ignored"));
DnsRecord ptrRecord = new DnsRecord();
ptrRecord.setIdnsname("1.0");
ptrRecord.setPtrrecord(List.of("ptrRecord"));
when(client.findAllDnsRecordInZone(dnsZone.getIdnsname())).thenReturn(Set.of(deleteMe, notFound, failed));
when(client.deleteDnsRecord(failed.getIdnsname(), domain)).thenThrow(new FreeIpaClientException("delete failed"));
when(client.deleteDnsRecord(notFound.getIdnsname(), domain)).thenThrow(new FreeIpaClientException("Not found", new JsonRpcClientException(FreeIpaErrorCodes.NOT_FOUND.getValue(), "Not found", null)));
when(client.findAllDnsRecordInZone(reverseZone.getIdnsname())).thenReturn(Set.of(ptrRecord));
when(client.findAllDnsRecordInZone(disappearingZone.getIdnsname())).thenThrow(new FreeIpaClientException("Not found zone", new JsonRpcClientException(FreeIpaErrorCodes.NOT_FOUND.getValue(), "Not found", null)));
Pair<Set<String>, Map<String, String>> result = cleanupService.removeDnsEntries(STACK_ID, Set.of(deleteMe.getIdnsname(), notFound.getIdnsname(), failed.getIdnsname(), "ptrRecord"), Set.of("10.0.0.1", "10.1.0.1"), domain);
verify(client).deleteDnsRecord(deleteMe.getIdnsname(), domain);
assertTrue(result.getFirst().containsAll(Set.of(deleteMe.getIdnsname(), notFound.getIdnsname(), "10.0.0.1")));
assertTrue(result.getSecond().containsKey(failed.getIdnsname()));
assertEquals("delete failed", result.getSecond().get(failed.getIdnsname()));
assertEquals(1, result.getSecond().size());
assertEquals(3, result.getFirst().size());
}
use of com.sequenceiq.freeipa.client.model.DnsZone in project cloudbreak by hortonworks.
the class UpdateDnsSoaRecordsHandlerTest method testResultContainsServerFqdns.
@Test
void testResultContainsServerFqdns() throws Exception {
String zoneName = "example.com.";
String fqdn1 = "foo1.example.com";
String fqdn2 = "foo2.example.com";
FreeIpaClient mockIpaClient = mock(FreeIpaClient.class);
IpaServer mockIpaServer1 = mock(IpaServer.class);
IpaServer mockIpaServer2 = mock(IpaServer.class);
DnsZone dnsZone = mock(DnsZone.class);
when(freeIpaClientFactory.getFreeIpaClientForStackId(any())).thenReturn(mockIpaClient);
when(mockIpaClient.findAllServers()).thenReturn(Set.of(mockIpaServer1, mockIpaServer2));
Mockito.lenient().when(mockIpaServer1.getFqdn()).thenReturn(fqdn1);
when(mockIpaServer2.getFqdn()).thenReturn(fqdn2);
when(mockIpaClient.findAllDnsZone()).thenReturn(Set.of(dnsZone));
when(dnsZone.getIdnssoamname()).thenReturn(fqdn1 + ".");
when(dnsZone.getIdnsname()).thenReturn(zoneName);
CleanupEvent cleanupEvent = new CleanupEvent(1L, Set.of(), Set.of(fqdn1), Set.of(), Set.of(), Set.of(), "", "", "", "");
UpdateDnsSoaRecordsRequest request = new UpdateDnsSoaRecordsRequest(cleanupEvent);
underTest.accept(new Event<>(request));
verify(eventBus).notify(eq("UPDATEDNSSOARECORDSRESPONSE"), any(Event.class));
verify(mockIpaClient).setDnsZoneAuthoritativeNameserver(eq(zoneName), eq(fqdn2 + "."));
}
use of com.sequenceiq.freeipa.client.model.DnsZone 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.DnsZone 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);
}
}
Aggregations