Corrected cassandra example's indent.

This commit is contained in:
Klaus Ma 2016-05-01 21:05:13 +08:00
parent b930d58fcb
commit 59bab9bde4

View File

@ -65,12 +65,10 @@ public class KubernetesSeedProvider implements SeedProvider {
*/ */
private List<InetAddress> defaultSeeds; private List<InetAddress> defaultSeeds;
private TrustManager[] trustAll; private TrustManager[] trustAll;
private HostnameVerifier trustAllHosts; private HostnameVerifier trustAllHosts;
/** /**
* Create new Seeds * Create new Seeds
* @param params * @param params
@ -80,23 +78,22 @@ public class KubernetesSeedProvider implements SeedProvider {
// Create default seeds // Create default seeds
defaultSeeds = createDefaultSeeds(); defaultSeeds = createDefaultSeeds();
// TODO: Load the CA cert when it is available on all platforms. // TODO: Load the CA cert when it is available on all platforms.
trustAll = new TrustManager[] { trustAll = new TrustManager[] {
new X509TrustManager() { new X509TrustManager() {
public void checkServerTrusted(X509Certificate[] certs, String authType) {} public void checkServerTrusted(X509Certificate[] certs, String authType) {}
public void checkClientTrusted(X509Certificate[] certs, String authType) {} public void checkClientTrusted(X509Certificate[] certs, String authType) {}
public X509Certificate[] getAcceptedIssuers() { return null; } public X509Certificate[] getAcceptedIssuers() { return null; }
} }
}; };
trustAllHosts = new HostnameVerifier() { trustAllHosts = new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) { public boolean verify(String hostname, SSLSession session) {
return true; return true;
} }
}; };
} }
/** /**
* Call kubernetes API to collect a list of seed providers * Call kubernetes API to collect a list of seed providers
* @return list of seed providers * @return list of seed providers
@ -133,14 +130,10 @@ public class KubernetesSeedProvider implements SeedProvider {
Endpoints endpoints = mapper.readValue(conn.getInputStream(), Endpoints.class); Endpoints endpoints = mapper.readValue(conn.getInputStream(), Endpoints.class);
if (endpoints != null) { if (endpoints != null) {
// Here is a problem point, endpoints.subsets can be null in first node cases. // Here is a problem point, endpoints.subsets can be null in first node cases.
if (endpoints.subsets != null && !endpoints.subsets.isEmpty()){ if (endpoints.subsets != null && !endpoints.subsets.isEmpty()){
for (Subset subset : endpoints.subsets) { for (Subset subset : endpoints.subsets) {
if (subset.addresses != null && !subset.addresses.isEmpty()) { if (subset.addresses != null && !subset.addresses.isEmpty()) {
for (Address address : subset.addresses) { for (Address address : subset.addresses) {
seeds.add(InetAddress.getByName(address.ip)); seeds.add(InetAddress.getByName(address.ip));
@ -151,29 +144,22 @@ public class KubernetesSeedProvider implements SeedProvider {
} }
} }
} }
} }
logger.info("Available num endpoints: " + seeds.size());
logger.info("Available num endpoints: " + seeds.size());
} else { } 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); return Collections.unmodifiableList(defaultSeeds);
}
}
} catch (IOException | NoSuchAlgorithmException | KeyManagementException ex) { } 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); return Collections.unmodifiableList(defaultSeeds);
} }
if (seeds.size() == 0) { if (seeds.size() == 0) {
// If we got nothing, we might be the first instance, in that case
// If we got nothing, we might be the first instance, in that case // fall back on the seeds that were passed in cassandra.yaml.
// fall back on the seeds that were passed in cassandra.yaml.
logger.warn("Seeds are not available using default seeds in cassandra.yaml"); logger.warn("Seeds are not available using default seeds in cassandra.yaml");
return Collections.unmodifiableList(defaultSeeds); return Collections.unmodifiableList(defaultSeeds);
} }
return Collections.unmodifiableList(seeds); return Collections.unmodifiableList(seeds);
@ -187,24 +173,19 @@ public class KubernetesSeedProvider implements SeedProvider {
protected List<InetAddress> createDefaultSeeds() protected List<InetAddress> createDefaultSeeds()
{ {
Config conf; Config conf;
try try {
{
conf = loadConfig(); conf = loadConfig();
} }
catch (Exception e) catch (Exception e) {
{
throw new AssertionError(e); throw new AssertionError(e);
} }
String[] hosts = conf.seed_provider.parameters.get("seeds").split(",", -1); String[] hosts = conf.seed_provider.parameters.get("seeds").split(",", -1);
List<InetAddress> seeds = new ArrayList<InetAddress>(); List<InetAddress> seeds = new ArrayList<InetAddress>();
for (String host : hosts) for (String host : hosts) {
{ try {
try
{
seeds.add(InetAddress.getByName(host.trim())); seeds.add(InetAddress.getByName(host.trim()));
} }
catch (UnknownHostException ex) catch (UnknownHostException ex) {
{
// not fatal... DD will bark if there end up being zero seeds. // not fatal... DD will bark if there end up being zero seeds.
logger.warn("Seed provider couldn't lookup host {}", host); logger.warn("Seed provider couldn't lookup host {}", host);
} }
@ -269,6 +250,4 @@ public class KubernetesSeedProvider implements SeedProvider {
static class Endpoints { static class Endpoints {
public List<Subset> subsets; public List<Subset> subsets;
} }
} }