Skip to content

Commit

Permalink
Merge pull request kubernetes#23909 from k82/k8se-cassandra-java-example
Browse files Browse the repository at this point in the history
Automatic merge from submit-queue

Corrected cassandra example's indent.

No logic changed; just correct java code's indent.
  • Loading branch information
k8s-merge-robot committed May 4, 2016
2 parents 1642083 + 59bab9b commit d2f70ef
Showing 1 changed file with 25 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,10 @@ public class KubernetesSeedProvider implements SeedProvider {
*/
private List<InetAddress> defaultSeeds;


private TrustManager[] trustAll;

private HostnameVerifier trustAllHosts;


/**
* Create new Seeds
* @param params
Expand All @@ -80,22 +78,21 @@ public KubernetesSeedProvider(Map<String, String> 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
Expand Down Expand Up @@ -133,14 +130,10 @@ public List<InetAddress> 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));

Expand All @@ -151,29 +144,22 @@ public List<InetAddress> 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);
Expand All @@ -187,24 +173,19 @@ public List<InetAddress> getSeeds() {
protected List<InetAddress> 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<InetAddress> seeds = new ArrayList<InetAddress>();
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);
}
Expand Down Expand Up @@ -269,6 +250,4 @@ static class Subset {
static class Endpoints {
public List<Subset> subsets;
}


}

0 comments on commit d2f70ef

Please sign in to comment.