use of org.xbill.DNS.Update in project opennms by OpenNMS.
the class ReverseDnsProvisioningAdapter method doUpdate.
private void doUpdate(AdapterOperation op) {
LOG.debug("doUpdate: operation: {}", op.getType().name());
for (ReverseDnsRecord record : m_reverseDnsProvisioningAdapterService.get(op.getNodeId())) {
LOG.debug("doUpdate: ReverseDnsRecord: hostname: {} zone: {} ip address: {}", record.getIp().getHostAddress(), record.getHostname(), record.getZone());
try {
Update update = new Update(Name.fromString(record.getZone()));
Name ptrRecord = ReverseMap.fromAddress(record.getIp());
update.replace(ptrRecord, Type.PTR, 3600, record.getHostname());
m_resolver.send(update);
m_reverseDnsProvisioningAdapterService.update(op.getNodeId(), record);
} catch (Exception e) {
LOG.error("updateNode: Error handling updated event.", e);
sendAndThrow(op.getNodeId(), e);
}
}
}
use of org.xbill.DNS.Update in project opennms by OpenNMS.
the class DnsProvisioningAdapter method doUpdate.
private void doUpdate(AdapterOperation op) {
OnmsNode node = null;
LOG.debug("doUpdate: operation: {}", op.getType().name());
try {
node = m_nodeDao.get(op.getNodeId());
if (node == null) {
doDelete(op);
return;
}
DnsRecord record = new DnsRecord(node, m_level);
LOG.debug("doUpdate: DnsRecord: hostname: {} zone: {} ip address {}", record.getIp().getHostAddress(), record.getHostname(), record.getZone());
DnsRecord oldRecord = m_nodeDnsRecordMap.get(Integer.valueOf(node.getId()));
Update update = new Update(Name.fromString(record.getZone()));
if (oldRecord != null && oldRecord.getHostname() != record.getHostname()) {
update.delete(Name.fromString(oldRecord.getHostname()), Type.A);
}
update.replace(Name.fromString(record.getHostname()), Type.A, 3600, record.getIp().getHostAddress());
m_resolver.send(update);
m_nodeDnsRecordMap.put(Integer.valueOf(op.getNodeId()), record);
} catch (Throwable e) {
LOG.error("addNode: Error handling node added event.", e);
sendAndThrow(op.getNodeId(), e);
}
}
use of org.xbill.DNS.Update in project ecf by eclipse.
the class DnsSdDiscoveryAdvertiser method sendToServer.
protected void sendToServer(final IServiceInfo serviceInfo, final boolean mode) {
Assert.isNotNull(serviceInfo);
Assert.isLegal(serviceInfo.getServiceID() instanceof DnsSdServiceID);
final DnsSdServiceID serviceID = (DnsSdServiceID) serviceInfo.getServiceID();
try {
// TYPE.SRV
final Record srvRecord = serviceID.toSRVRecord();
// TYPE.TXT
final Record[] txtRecords = serviceID.toTXTRecords(srvRecord);
final Name name = serviceID.getDnsName();
final String[] registrationDomains = getRegistrationDomains(serviceID.getServiceTypeID());
for (int i = 0; i < registrationDomains.length; i++) {
final Name zone = new Name(registrationDomains[i]);
// $NON-NLS-1$
final Name fqdn = new Name(name.toString() + "." + zone.toString());
final Update update = new Update(zone);
// TYPE.SRV
if (mode == ADD) {
// TODO add absent/present condition checks
update.replace(srvRecord.withName(fqdn));
} else {
update.delete(srvRecord.withName(fqdn));
}
// TYPE.TXT
for (int j = 0; j < txtRecords.length; j++) {
if (mode == ADD) {
update.add(txtRecords[j].withName(fqdn));
} else {
update.delete(txtRecords[j].withName(fqdn));
}
}
// set up a the resolver for the given domain (a scope might use different domains)
final Collection dnsServers = getUpdateDomain(zone);
if (dnsServers.size() == 0) {
throw new DnsSdDiscoveryException(Messages.DnsSdDiscoveryAdvertiser_No_DynDns_Servers_Found);
}
for (final Iterator iterator = dnsServers.iterator(); iterator.hasNext(); ) {
final SRVRecord dnsServer = (SRVRecord) iterator.next();
// try to send msg and fail gracefully if more dns servers are available
final Name target = dnsServer.getTarget();
final Message response;
final InetAddress byName;
try {
byName = InetAddress.getByName(target.toString());
((SimpleResolver) resolver).setAddress(byName);
((SimpleResolver) resolver).setPort(dnsServer.getPort());
response = resolver.send(update);
} catch (UnknownHostException uhe) {
if (iterator.hasNext()) {
continue;
} else {
throw new DnsSdDiscoveryException(uhe);
}
} catch (EOFException eof) {
if (iterator.hasNext()) {
continue;
} else {
throw new DnsSdDiscoveryException(eof);
}
}
// catch some errors and fall back to the next dnsServer
if (response.getRcode() != Rcode.NOERROR) {
if (iterator.hasNext()) {
continue;
} else {
throw DnsSdDiscoveryException.getException(response.getRcode());
}
}
}
}
} catch (Exception e) {
throw new DnsSdDiscoveryException(e);
}
}
use of org.xbill.DNS.Update in project ecf by eclipse.
the class DnsSdAdvertiserServiceTest method setUp.
/* (non-Javadoc)
* @see org.eclipse.ecf.tests.discovery.AbstractDiscoveryTest#setUp()
*/
protected void setUp() throws Exception {
super.setUp();
// purge all SRV records from the test domain
ZoneTransferIn xfr = ZoneTransferIn.newAXFR(new Name(DnsSdTestHelper.REG_DOMAIN), DnsSdTestHelper.DNS_SERVER, null);
List records = xfr.run();
for (Iterator itr = records.iterator(); itr.hasNext(); ) {
Record record = (Record) itr.next();
String name = record.getName().toString();
if (name.startsWith("_" + DnsSdTestHelper.REG_SCHEME + "._" + DnsSdTestHelper.PROTO)) {
Update update = new Update(Name.fromString(DnsSdTestHelper.REG_DOMAIN + "."));
update.delete(record);
SimpleResolver resolver = new SimpleResolver(DnsSdTestHelper.DNS_SERVER);
resolver.setTCP(true);
resolver.setTSIGKey(new TSIG(DnsSdTestHelper.TSIG_KEY_NAME, DnsSdTestHelper.TSIG_KEY));
Message response = resolver.send(update);
int rcode = response.getRcode();
assertTrue("", rcode == 0);
}
}
}
use of org.xbill.DNS.Update in project ecf by eclipse.
the class DnsSdAdvertiserServiceTest method createTXTRecords.
private void createTXTRecords() throws TextParseException, IOException, UnknownHostException {
final Name zone = Name.fromString(DnsSdTestHelper.REG_DOMAIN + ".");
final Name name = Name.fromString("_" + DnsSdTestHelper.REG_SCHEME + "._" + DnsSdTestHelper.PROTO, zone);
Update update = null;
final IServiceProperties properties = serviceInfo.getServiceProperties();
final Enumeration enumeration = properties.getPropertyNames();
while (enumeration.hasMoreElements()) {
final Object property = enumeration.nextElement();
final String key = property.toString();
final String value = (String) properties.getProperty(key).toString();
final Record record = Record.fromString(name, Type.TXT, DClass.IN, serviceInfo.getTTL(), key + "=" + value, zone);
update = new Update(zone);
update.add(record);
}
final SimpleResolver resolver = new SimpleResolver(DnsSdTestHelper.DNS_SERVER);
resolver.setTCP(true);
resolver.setTSIGKey(new TSIG(DnsSdTestHelper.TSIG_KEY_NAME, DnsSdTestHelper.TSIG_KEY));
final Message response = resolver.send(update);
final int rcode = response.getRcode();
assertTrue("", rcode == 0);
}
Aggregations