Actually, the current form of the ConsulIpFinder has changed, with all of my
testing.
```
public ConsulIpFinder(OkHttpClient okHttpClient) {
this.okHttpClient = okHttpClient;
this.consulUrl = buildConsulUrl();
this.consulVersionTag = buildConsulVersionTag();
this.consulEnvTag = buildConsulEnvTag();
this.myDiscoveryAddr = buildMyDiscoveryAddr();
setShared(true);
}
@Override
public Collection<InetSocketAddress> getRegisteredAddresses() throws
IgniteSpiException {
// Get whatever List of Nodes is currently available in Consul
Set<InetSocketAddress> consulAddresses = new HashSet<>();
consulAddresses.addAll(getAddressesFromConsul());
// Always add my self to the List
consulAddresses.add(myDiscoveryAddr);
return Collections.unmodifiableCollection(consulAddresses);
}
@Override
public void registerAddresses(Collection<InetSocketAddress> addrs)
throws IgniteSpiException {}
@Override
public void unregisterAddresses(Collection<InetSocketAddress> addrs)
throws IgniteSpiException {}
/**
* NOTE: this method should always call the LOCAL Consul agent
*/
private List<InetSocketAddress> getAddressesFromConsul() {
//
http://1.2.3.4:8500/v1/health/service/foo-ignitedisco-test?passing&tag=ver-1.2-SNAPSHOT&tag=env-test
try {
HttpUrl.Builder urlBuilder =
HttpUrl.parse(consulUrl).newBuilder();
// Only Services that are passing
urlBuilder.addQueryParameter("passing", null);
// Only Services that are in the same Env and at the exact same
Version
urlBuilder.addQueryParameter("tag", consulEnvTag);
if (consulVersionTag != null) {
urlBuilder.addQueryParameter("tag", consulVersionTag);
}
String url = urlBuilder.build().toString();
Request request = new Request.Builder().url(url).build();
Response response = okHttpClient.newCall(request).execute();
if (!response.isSuccessful()) {
// Caught in the catch() below....
throw new
IOException("event=ipFinderErrorResponseCodeReceived, response=" +
response);
}
String responseData = response.body().string();
JsonNode root = objectMapper.readTree(responseData);
return processConsulJson(root);
} catch (IOException ee) {
log.error("event=ipFinderErrorReadingFromConsul, consulUrl={}",
consulUrl, ee);
return Collections.emptyList();
}
}
```
--
View this message in context:
http://apache-ignite-users.70518.x6.nabble.com/Race-Condition-at-Grid-Startup-tp13038p13069.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.