dataminer-pool-manager/src/main/java/org/gcube/dataanalysis/dataminer/poolmanager/clients/ISClient.java

223 lines
7.7 KiB
Java

***REMOVED******REMOVED***
***REMOVED***
***REMOVED***import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
***REMOVED***import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
***REMOVED***
***REMOVED***import java.util.Collection;
***REMOVED******REMOVED***
***REMOVED***import java.util.Vector;
***REMOVED***
***REMOVED***import org.gcube.common.resources.gcore.ServiceEndpoint;
***REMOVED******REMOVED***
***REMOVED***import org.gcube.dataanalysis.dataminer.poolmanager.datamodel.Domain;
***REMOVED******REMOVED***
***REMOVED***import org.gcube.resources.discovery.client.api.DiscoveryClient;
***REMOVED***import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
***REMOVED***
***REMOVED***public class ISClient {
***REMOVED***
***REMOVED*** /**
***REMOVED*** * Return the list of hosts (dataminers) in a given VRE
***REMOVED*** *
***REMOVED*** * @param vreName
***REMOVED*** * @return
***REMOVED*** */
***REMOVED*** public Collection<Host> listDataminersInVRE() {
***REMOVED***
***REMOVED*** boolean remote = false;
***REMOVED***
***REMOVED*** if (!remote) {
***REMOVED*** Collection<Host> out = new Vector<>();
***REMOVED*** Host h = new Host();
***REMOVED*** ***REMOVED***h.setName("bb-dataminer.res.eng.it");
***REMOVED*** ***REMOVED***h.setName("vm101.ui.savba.sk");
***REMOVED*** h.setName("dataminer1-devnext.d4science.org");
***REMOVED*** out.add(h);
***REMOVED*** return out;
***REMOVED*** ***REMOVED*** else {
***REMOVED***
***REMOVED*** SimpleQuery query = queryFor(ServiceEndpoint.class);
***REMOVED***
***REMOVED*** ***REMOVED***old version
***REMOVED*** ***REMOVED***query.addCondition("$resource/Profile/Category/text() eq 'DataAnalysis'")
***REMOVED*** ***REMOVED***.addCondition("$resource/Profile/Name/text() eq 'DataMiner'");
***REMOVED***
***REMOVED*** query.addCondition("$resource/Profile/Platform/Name/text() eq 'DataMiner'");
***REMOVED***
***REMOVED*** DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
***REMOVED***
***REMOVED*** List<ServiceEndpoint> resources = client.submit(query);
***REMOVED***
***REMOVED*** Collection<Host> out = new Vector<>();
***REMOVED*** for (ServiceEndpoint r : resources) {
***REMOVED*** Host h = new Host();
***REMOVED*** h.setName(r.profile().runtime().hostedOn());
***REMOVED*** out.add(h);
***REMOVED*** ***REMOVED***
***REMOVED*** return out;
***REMOVED*** ***REMOVED***
***REMOVED*** ***REMOVED***
***REMOVED***
***REMOVED*** public static void main(String[] args) {
***REMOVED*** ISClient a = new ISClient();
***REMOVED*** ScopeProvider.instance.set("/gcube/devNext/NextNext");
***REMOVED*** System.out.println(a.listDataminersInVRE());
***REMOVED******REMOVED***
***REMOVED******REMOVED***
***REMOVED***
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
***REMOVED***
***REMOVED***
***REMOVED***
import java.net.MalformedURLException;
***REMOVED***
import java.util.Collection;
import java.util.LinkedHashMap;
***REMOVED***
***REMOVED***
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.Vector;
import org.gcube.common.resources.gcore.ServiceEndpoint;
***REMOVED***
***REMOVED***
import org.gcube.dataanalysis.dataminer.poolmanager.datamodel.Domain;
***REMOVED***
import org.gcube.dataanalysis.dataminer.poolmanager.datamodel.comparator.HostComparator;
import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
***REMOVED***
public class ISClient {
***REMOVED***
public Host getDataminer(String hostname) {
Host h = new Host();
boolean remote2 = true;
if (!remote2) {
h.setName("dataminer1-devnext.d4science.org");
return h;
***REMOVED*** else {
SimpleQuery query = queryFor(ServiceEndpoint.class);
query.addCondition("$resource/Profile/RunTime/HostedOn/text() eq '" + hostname + "'");
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
List<ServiceEndpoint> resources = client.submit(query);
ServiceEndpoint a = resources.get(0);
h.setName(a.profile().runtime().hostedOn());
***REMOVED***
return h;
***REMOVED***
***REMOVED*** return the HProxy hostname in the VRE
public String getHProxy(){
Host h = new Host();
SimpleQuery query = queryFor(ServiceEndpoint.class);
query.addCondition("$resource/Profile/Platform/Name/text() eq 'DataMinerAlone'");
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
List<ServiceEndpoint> resources = client.submit(query);
h.setName(resources.get(0).profile().runtime().hostedOn());
return h.getName();
***REMOVED***
public Cluster getClusterByHProxy() throws IOException {
Cluster cl = new Cluster();
String HProxy = this.getHProxy();
URL stockURL = new URL("http:***REMOVED***data.d4science.org/Yk4zSFF6V3JOSytNd3JkRDlnRFpDUUR5TnRJZEw2QjRHbWJQNStIS0N6Yz0");
BufferedReader in = new BufferedReader(new InputStreamReader(stockURL.openStream()));
reader = new CSVReader(in);
String [] nextLine;
while ((nextLine = reader.readNext()) != null) {
***REMOVED***rules to add
if (HProxy.contains(nextLine[0])){
cl.setName(nextLine[0]);
***REMOVED***
***REMOVED***
return cl;
***REMOVED***
public List<Host> listDataMinersByCluster() throws IOException {
Cluster cluster = this.getClusterByHProxy();
***REMOVED***
URL stockURL = new URL("http:***REMOVED***data.d4science.org/Yk4zSFF6V3JOSytNd3JkRDlnRFpDUUR5TnRJZEw2QjRHbWJQNStIS0N6Yz0");
BufferedReader in = new BufferedReader(new InputStreamReader(stockURL.openStream()));
reader = new CSVReader(in, ',');
String[] nextLine;
while ((nextLine = reader.readNext()) != null) {
if (nextLine[0].equals(cluster.getName())) {
***REMOVED***
a.setName(nextLine[1]);
***REMOVED***
System.out.println(a.getFullyQualifiedName());
***REMOVED***
***REMOVED***
***REMOVED***
***REMOVED***
/**
* Return the list of hosts (dataminers) in a given VRE
*
* @param vreName
* @return
*/
public Collection<Host> listDataminersInVRE() {
boolean remote = false;
if (!remote) {
Collection<Host> out = new Vector<>();
Host h = new Host();
***REMOVED***h.setName("bb-dataminer.res.eng.it");
***REMOVED***h.setName("vm101.ui.savba.sk");
h.setName("dataminer1-devnext.d4science.org");
out.add(h);
return out;
***REMOVED*** else {
SimpleQuery query = queryFor(ServiceEndpoint.class);
***REMOVED***old version
***REMOVED***query.addCondition("$resource/Profile/Category/text() eq 'DataAnalysis'")
***REMOVED***.addCondition("$resource/Profile/Name/text() eq 'DataMiner'");
query.addCondition("$resource/Profile/Platform/Name/text() eq 'DataMiner'");
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
List<ServiceEndpoint> resources = client.submit(query);
Collection<Host> out = new Vector<>();
for (ServiceEndpoint r : resources) {
Host h = new Host();
h.setName(r.profile().runtime().hostedOn());
out.add(h);
***REMOVED***
return out;
***REMOVED***
***REMOVED***
public static void main(String[] args) throws IOException {
ISClient a = new ISClient();
ScopeProvider.instance.set("/gcube/devNext/NextNext");
***REMOVED***System.out.println(a.getHProxy());
System.out.println(a.getClusterByHProxy());
System.out.println(a.listDataMinersByCluster());
***REMOVED***System.out.println(a.getDataminer("dataminer1-devnext.d4science.org").getDomain());
***REMOVED***System.out.println(a.listDataminersInVRE());
***REMOVED***
***REMOVED***