From 59bab9bde44fc64d114a2296152d7d54fa72fa59 Mon Sep 17 00:00:00 2001 From: Klaus Ma Date: Sun, 1 May 2016 21:05:13 +0800 Subject: [PATCH] Corrected cassandra example's indent. --- .../k8s/cassandra/KubernetesSeedProvider.java | 71 +++++++------------ 1 file changed, 25 insertions(+), 46 deletions(-) diff --git a/examples/cassandra/java/src/main/java/io/k8s/cassandra/KubernetesSeedProvider.java b/examples/cassandra/java/src/main/java/io/k8s/cassandra/KubernetesSeedProvider.java index e2111f26d5695..df50084282222 100644 --- a/examples/cassandra/java/src/main/java/io/k8s/cassandra/KubernetesSeedProvider.java +++ b/examples/cassandra/java/src/main/java/io/k8s/cassandra/KubernetesSeedProvider.java @@ -65,12 +65,10 @@ public class KubernetesSeedProvider implements SeedProvider { */ private List defaultSeeds; - private TrustManager[] trustAll; private HostnameVerifier trustAllHosts; - /** * Create new Seeds * @param params @@ -80,22 +78,21 @@ public KubernetesSeedProvider(Map params) { // Create default seeds defaultSeeds = createDefaultSeeds(); - // TODO: Load the CA cert when it is available on all platforms. - trustAll = new TrustManager[] { - new X509TrustManager() { - public void checkServerTrusted(X509Certificate[] certs, String authType) {} - public void checkClientTrusted(X509Certificate[] certs, String authType) {} - public X509Certificate[] getAcceptedIssuers() { return null; } - } - }; - - trustAllHosts = new HostnameVerifier() { - public boolean verify(String hostname, SSLSession session) { - return true; - } - }; - } + // TODO: Load the CA cert when it is available on all platforms. + trustAll = new TrustManager[] { + new X509TrustManager() { + public void checkServerTrusted(X509Certificate[] certs, String authType) {} + public void checkClientTrusted(X509Certificate[] certs, String authType) {} + public X509Certificate[] getAcceptedIssuers() { return null; } + } + }; + trustAllHosts = new HostnameVerifier() { + public boolean verify(String hostname, SSLSession session) { + return true; + } + }; + } /** * Call kubernetes API to collect a list of seed providers @@ -133,14 +130,10 @@ public List getSeeds() { Endpoints endpoints = mapper.readValue(conn.getInputStream(), Endpoints.class); if (endpoints != null) { - // Here is a problem point, endpoints.subsets can be null in first node cases. - if (endpoints.subsets != null && !endpoints.subsets.isEmpty()){ - for (Subset subset : endpoints.subsets) { if (subset.addresses != null && !subset.addresses.isEmpty()) { - for (Address address : subset.addresses) { seeds.add(InetAddress.getByName(address.ip)); @@ -151,29 +144,22 @@ public List getSeeds() { } } } - } - - logger.info("Available num endpoints: " + seeds.size()); - + logger.info("Available num endpoints: " + seeds.size()); } else { - - logger.warn("Endpoints are not available using default seeds in cassandra.yaml"); + logger.warn("Endpoints are not available using default seeds in cassandra.yaml"); return Collections.unmodifiableList(defaultSeeds); - - } + } } catch (IOException | NoSuchAlgorithmException | KeyManagementException ex) { - logger.warn("Request to kubernetes apiserver failed, using default seeds in cassandra.yaml", ex); + logger.warn("Request to kubernetes apiserver failed, using default seeds in cassandra.yaml", ex); return Collections.unmodifiableList(defaultSeeds); } if (seeds.size() == 0) { - - // If we got nothing, we might be the first instance, in that case - // fall back on the seeds that were passed in cassandra.yaml. + // If we got nothing, we might be the first instance, in that case + // fall back on the seeds that were passed in cassandra.yaml. logger.warn("Seeds are not available using default seeds in cassandra.yaml"); return Collections.unmodifiableList(defaultSeeds); - } return Collections.unmodifiableList(seeds); @@ -187,24 +173,19 @@ public List getSeeds() { protected List createDefaultSeeds() { Config conf; - try - { + try { conf = loadConfig(); } - catch (Exception e) - { + catch (Exception e) { throw new AssertionError(e); } String[] hosts = conf.seed_provider.parameters.get("seeds").split(",", -1); List seeds = new ArrayList(); - for (String host : hosts) - { - try - { + for (String host : hosts) { + try { seeds.add(InetAddress.getByName(host.trim())); } - catch (UnknownHostException ex) - { + catch (UnknownHostException ex) { // not fatal... DD will bark if there end up being zero seeds. logger.warn("Seed provider couldn't lookup host {}", host); } @@ -269,6 +250,4 @@ static class Subset { static class Endpoints { public List subsets; } - - }