Giter Site home page Giter Site logo

powerdns-java-sdk's Introduction

PowerDNS client (Java)

How to install

Later, when it will be deployd on Maven Central:

<dependency>
	<group>com.itranga</group>
	<artifact>powerdns-client</artifact>
</depenency>

but now - you have to clone the project and compile it with maven.

How to patch multiple records in a zone

Here is an example in the imperative style, although the functional one would be more appropriate:

import java.net.MalformedURLException;
import java.util.Collection;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;


public class App {	
	private static final org.slf4j.Logger LOG = org.slf4j.LoggerFactory.getLogger(App.class);
	
	public static void main(String[] args) throws InterruptedException, ExecutionException, TimeoutException, MalformedURLException{
		// vertx to use slf4j as logger
		System.setProperty("vertx.logger-delegate-factory-class-name", "io.vertx.core.logging.SLF4JLogDelegateFactory");
		
		PowerDnsClient dnsClient = new PowerDnsClientBuilder()
			.setApiKey("yourApiKey")
			.setApiUrl("https://ns1api.exmple.net/api")
			.setDefaultNS("ns1.example.net", "ns2.example.net")
			.setImplicitRecordTtl(180)
			.build();
		
		String deploymentId = dnsClient.init().join();
		LOG.info("Init dns client: {} - Vertx deploymentId", deploymentId);		
		
		CompletableFuture<Collection<String>> wwwResult = dnsClient
			.addRecordToBatch("www.example.com", "127.0.0.1")
			.exceptionally( t -> {
				if(LOG.isTraceEnabled()){
					LOG.error("Failed to add record to batch", t);
				}else{
					LOG.error("Failed to add record to bacth : {}", t.getMessage());
				}					
				return null;
			});
		
		//RUN batch asyncronously
		Thread t = new Thread ( () -> {
			try {
				Thread.sleep(3000);
				dnsClient.doBatchJob();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		});
		t.setDaemon(true);
		t.start();
		
		wwwResult.thenAccept( ns -> {
				LOG.debug("Namserver: "+ns);			
			}).get(10,  TimeUnit.SECONDS);

		dnsClient.close().join();
	}
}

Under the hood

PowerDNS client is using Vert.x web-client and it is actually a Verticle itself—an actor, as defined in Actor Model.

If you are unaware how to deploy verticles to Vert.x, then just call powerDnsClient.init().join() method and when done—powerDnsClient.close().join().

Plans

  • Add OSGi support
  • Better support for errors
  • integration tests
  • deploy to Maven Central

powerdns-java-sdk's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.