Service discovery query now supports both old and new service class

master
Luca Frosini 2 years ago
parent 03ac8f4fb6
commit c55988cc8a

@ -51,9 +51,9 @@ public class GCatClientDiscovery {
private static SimpleQuery queryForService(){
private static SimpleQuery queryForService(String serviceClass){
return ICFactory.queryFor(GCoreEndpoint.class)
.addCondition(String.format(classFormat, GCatConstants.SERVICE_CLASS))
.addCondition(String.format(classFormat, serviceClass))
.addCondition(String.format(nameFormat, GCatConstants.SERVICE_NAME))
.addCondition(String.format(statusFormat))
.addVariable("$entry","$resource/Profile/AccessPoint/RunningInstanceInterfaces/Endpoint")
@ -61,9 +61,9 @@ public class GCatClientDiscovery {
.setResult("$entry/text()");
}
private static SimpleQuery queryForProxy(){
private static SimpleQuery queryForProxy(String serviceClass){
return ICFactory.queryFor(ServiceEndpoint.class)
.addCondition(String.format(serviceEndpointCategoryFormat, GCatConstants.SERVICE_CLASS))
.addCondition(String.format(serviceEndpointCategoryFormat, serviceClass))
.addCondition(String.format(serviceEndpointNameFormat, GCatConstants.SERVICE_NAME))
.addCondition(String.format(serviceEndpointstatusFormat))
.addVariable("$entry","$resource/Profile/AccessPoint/Interface/Endpoint")
@ -76,17 +76,24 @@ public class GCatClientDiscovery {
List<String> addresses = new ArrayList<>();
try {
SimpleQuery proxyQuery = queryForProxy();
SimpleQuery proxyQuery = queryForProxy(GCatConstants.SERVICE_CLASS);
addresses = ICFactory.client().submit(proxyQuery);
if(addresses==null || addresses.isEmpty()){
throw new Exception("No ResourceRegistry Proxy Found");
proxyQuery = queryForProxy(GCatConstants.OLD_SERVICE_CLASS);
addresses = ICFactory.client().submit(proxyQuery);
if(addresses==null || addresses.isEmpty()){
throw new Exception("No ResourceRegistry Proxy Found");
}
}
} catch (Exception e) {
logger.debug("{}. Looking for RunningInstance.", e.getMessage());
SimpleQuery serviceQuery = queryForService();
SimpleQuery serviceQuery = queryForService(GCatConstants.SERVICE_CLASS);
addresses = ICFactory.client().submit(serviceQuery);
if(addresses==null || addresses.isEmpty()){
serviceQuery = queryForService(GCatConstants.OLD_SERVICE_CLASS);
addresses = ICFactory.client().submit(serviceQuery);
}
}
return addresses;
}
@ -115,7 +122,7 @@ public class GCatClientDiscovery {
List<String> addresses = getAddresses();
if(addresses==null || addresses.isEmpty()){
String error = String.format("No %s:%s found in the current context", GCatConstants.SERVICE_CLASS, GCatConstants.SERVICE_NAME);
String error = String.format("No (%s or %s):%s found in the current context", GCatConstants.SERVICE_CLASS, GCatConstants.OLD_SERVICE_CLASS, GCatConstants.SERVICE_NAME);
throw new RuntimeException(error);
}
Random random = new Random();

Loading…
Cancel
Save