public ConsulAgent attachAgent(String nodeName) { return ConsulCluster.attach(nodeName); }
public ConsulDatacenter dc() { return ConsulCluster.dc(); }
public void detachAgent(ConsulAgent agent) { ConsulCluster.detach(agent); } }
public void start() { masterClient = creator.apply(config(ConsulCluster.dc().getMasterToken(), false)); writeClient = creator.apply(writeClientOptions = config(ConsulCluster.writeToken(), false)); readClient = creator.apply(readClientOptions = config(ConsulCluster.readToken(), false)); }
private static ConsulAgentOptions sslOptions() { ConsulAgentOptions opts = new ConsulAgentOptions() .setKeyFile(copyFileFromResources("server-key.pem", "server-key")) .setCertFile(copyFileFromResources("server-cert.pem", "server-cert")) .setCaFile(copyFileFromResources("server-cert-ca-chain.pem", "server-cert-ca-chain")); String v = getVersion(); if (v != null) { opts.setConsulVersion(v); } return opts; }
private static ConsulClientOptions config(String token, boolean secure) { return new ConsulClientOptions() .setAclToken(token) .setDc(ConsulCluster.dc().getName()) .setHost("localhost") .setPort(secure ? ConsulCluster.getDefaultAgent().getHttpsPort() : ConsulCluster.getDefaultAgent().getHttpPort()) .setSsl(secure); }
static ConsulAgent attach(String nodeName) { return dc.attachAgent(sslOptions().setNodeName(nodeName)); }
public String consulVersion() { return ConsulCluster.getDefaultAgent().getConsulVersion(); }
@BeforeClass public static void startConsul() throws Exception { ConsulCluster.start(); }
public ConsulClient createSecureClient(boolean trustAll, PemTrustOptions trustOptions) { ConsulClientOptions options = config(ConsulCluster.writeToken(), true) .setTrustAll(trustAll) .setPemTrustOptions(trustOptions); return creator.apply(options); }
public static void start() { if (started.compareAndSet(false, true)) { ConsulAgentOptions options = sslOptions(); defaultAgent = dc.attachAgent(options); try { writeToken = defaultAgent.createAclToken(Utils.readResource("write_rules.hcl")); readToken = defaultAgent.createAclToken(Utils.readResource("read_rules.hcl")); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } Runtime.getRuntime().addShutdownHook(new Thread(dc::stop)); } }
public String nodeName() { return ConsulCluster.getDefaultAgent().getName(); }