diff --git a/src/main/java/org/gcube/vremanagement/executor/client/util/SmartExecutorPluginQuery.java b/src/main/java/org/gcube/vremanagement/executor/client/util/SmartExecutorPluginQuery.java index 11543a1..5bb0687 100644 --- a/src/main/java/org/gcube/vremanagement/executor/client/util/SmartExecutorPluginQuery.java +++ b/src/main/java/org/gcube/vremanagement/executor/client/util/SmartExecutorPluginQuery.java @@ -79,10 +79,18 @@ public class SmartExecutorPluginQuery implements Query { throw new DiscoveryException("No running SmartExecutor wich match the requested conditions"); } - /* Getting randomly one the host */ + /* + * Generating a random number, assuring that is positive and + * and limiting from 0 to the number of discovered ServiceEndpoints + * Please note that there is only one ServiceEndpoints for each running + * ghn + */ Random random = new Random(); - int i = random.nextInt() % serviceEndpoints.size(); + int number = random.nextInt(); + number = (number < 0) ? -number : number; + int i = number % serviceEndpoints.size(); + /* Getting random hosts using the generated random number*/ String hostedOn = serviceEndpoints.get(i).profile().runtime().hostedOn(); gCoreEndpointDiscoveryQuery.addCondition(format(containsFormat, hostedOn));