Assuring that the generated random number is positive

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/vre-management/smart-executor-client@112002 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2015-02-13 11:41:30 +00:00
parent 4bda8dc2d7
commit 2eeb9419c8
1 changed files with 10 additions and 2 deletions

View File

@ -79,10 +79,18 @@ public class SmartExecutorPluginQuery implements Query<EndpointReference> {
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));