Skip to content

Commit

Permalink
Merge pull request #213 from mwringe/HWKMETRICS-88
Browse files Browse the repository at this point in the history
HWKMETRICS-88
  • Loading branch information
Stefan Negrea committed May 14, 2015
2 parents 1032472 + 4a7aa1f commit 9d92b23
Showing 1 changed file with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public class OpenshiftSeedProvider implements SeedProvider {
private static final String CASSANDRA_NODES_SERVICE_NAME_ENVAR_NAME = "CASSANDRA_NODES_SERVICE_NAME";
private static final String DEFAULT_CASSANDRA_NODES_SERVICE_NAME = "cassandra-nodes";

// properties to determine how long to wait for the service to come online.
// Currently set to 60 seconds
private static final int SERVICE_TRIES = 30;
private static final int SERVICE_TRY_WAIT_TIME_MILLISECONDS = 2000;

//Required Constructor
public OpenshiftSeedProvider(Map<String, String> args) {
}
Expand All @@ -52,11 +57,31 @@ public List<InetAddress> getSeeds() {

String serviceName = getEnv(CASSANDRA_NODES_SERVICE_NAME_ENVAR_NAME, DEFAULT_CASSANDRA_NODES_SERVICE_NAME);
try {
InetAddress[] inetAddresses = InetAddress.getAllByName(serviceName);
InetAddress[] inetAddresses = null;

// we need to wait until the service is started
for (int i = 0; i < SERVICE_TRIES; i++) {
try {
inetAddresses = InetAddress.getAllByName(serviceName);
} catch (UnknownHostException e) {
if (i == (SERVICE_TRIES - 1)) {
logger.error("Could not detect service. Aborting.");
throw e;
} else {
logger.warn("Could not detect service '" + serviceName +
"'. It may not be up yet trying again.", e);
Thread.sleep(SERVICE_TRY_WAIT_TIME_MILLISECONDS);
}
}
}

if (inetAddresses == null) {
inetAddresses = InetAddress.getAllByName(serviceName);
}

logger.debug(inetAddresses.length + " addresses found for service name " + serviceName);

if (inetAddresses.length > 1) {
if (inetAddresses.length >= 1) {
for (InetAddress inetAddress : inetAddresses) {
logger.debug("Adding address " + inetAddress.getHostAddress() + " to seed list");
seeds.add(inetAddress);
Expand Down

0 comments on commit 9d92b23

Please sign in to comment.