42 lines
1.1 KiB
Java
42 lines
1.1 KiB
Java
package org.gcube.vremanagement.executor.client;
|
|
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Random;
|
|
|
|
import org.gcube.vremanagement.executor.api.rest.SmartExecutor;
|
|
import org.gcube.vremanagement.executor.client.query.Discover;
|
|
|
|
/**
|
|
* @author Luca Frosini (ISTI - CNR)
|
|
*/
|
|
public class SmartExecutorClientFactory {
|
|
|
|
private static String FORCED_URL = null;
|
|
|
|
protected static void forceToURL(String url) {
|
|
FORCED_URL = url;
|
|
}
|
|
|
|
public static SmartExecutor create(String pluginName, Map<String,String> capabilites) {
|
|
|
|
if(FORCED_URL != null) {
|
|
return new SmartExecutorClientImpl(pluginName, FORCED_URL);
|
|
}
|
|
|
|
Discover discover = new Discover(Constants.SERVICE_ENTRY_NAME);
|
|
discover.filterByPluginName(pluginName);
|
|
discover.filterByCapabilities(capabilites);
|
|
List<String> addresses = discover.getAddresses();
|
|
|
|
Random random = new Random();
|
|
int index = random.nextInt(addresses.size());
|
|
return new SmartExecutorClientImpl(pluginName, addresses.get(index));
|
|
}
|
|
|
|
public static SmartExecutor create(String pluginName, String address) {
|
|
return new SmartExecutorClientImpl(pluginName, address);
|
|
}
|
|
|
|
}
|