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

Loading…
Cancel
Save