This commit is contained in:
Nunzio Andrea Galante 2017-04-19 14:59:36 +00:00
parent a7215f24a3
commit f7488f8b0e
3 changed files with 191 additions and 108 deletions

View File

@ -0,0 +1,163 @@
package org.gcube.dataanalysis.dataminer.poolmanager.clients;
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.Vector;
import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.dataanalysis.dataminer.poolmanager.datamodel.Cluster;
import org.gcube.dataanalysis.dataminer.poolmanager.datamodel.Dependency;
import org.gcube.dataanalysis.dataminer.poolmanager.datamodel.Domain;
import org.gcube.dataanalysis.dataminer.poolmanager.datamodel.Host;
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;
import org.tmatesoft.svn.core.SVNDepth;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager;
import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory;
import org.tmatesoft.svn.core.io.SVNRepository;
import org.tmatesoft.svn.core.io.SVNRepositoryFactory;
import org.tmatesoft.svn.core.wc.ISVNOptions;
import org.tmatesoft.svn.core.wc.SVNClientManager;
import org.tmatesoft.svn.core.wc.SVNRevision;
import org.tmatesoft.svn.core.wc.SVNUpdateClient;
import org.tmatesoft.svn.core.wc.SVNWCUtil;
import au.com.bytecode.opencsv.CSVReader;
public class HAProxy {
private CSVReader reader;
public Cluster getClusterByHProxy() throws IOException {
Cluster cl = new Cluster();
String HProxy = ISClient.getHProxy();
URL stockURL = new URL("http://data.d4science.org/Yk4zSFF6V3JOSytNd3JkRDlnRFpDUUR5TnRJZEw2QjRHbWJQNStIS0N6Yz0");
BufferedReader in = new BufferedReader(new InputStreamReader(stockURL.openStream()));
reader = new CSVReader(in);
String [] nextLine;
while ((nextLine = reader.readNext()) != null) {
//rules to add
if (HProxy.contains(nextLine[0])){
cl.setName(nextLine[0]);
}
}
return cl;
}
public Cluster MapCluster() throws IOException {
Cluster cl = new Cluster();
String HProxy = ISClient.getHProxy();
if (HProxy.equals("dataminer-cluster1.d4science.org")) {
cl.setName("dataminer_cluster1");
}
if (HProxy.equals("dataminer-bigdata.d4science.org")) {
cl.setName("bigdata");
}
if (HProxy.equals("dataminer-cluster1.d4science.org")) {
cl.setName("dataminer_cluster1");
}
if (HProxy.equals("dataminer-cloud1.d4science.org")) {
cl.setName("dataminer_cloud1");
}
if (HProxy.equals("dataminer-prototypes.d4science.org")) {
cl.setName("prototypes");
}
if (HProxy.equals("dataminer.d4science.org")) {
cl.setName("gcubeapps");
}
if (HProxy.equals("dataminer-genericworkers.d4science.org")) {
cl.setName("genericworkers");
}
if (HProxy.equals("dataminer-genericworkers-proto.d4science.org")) {
cl.setName("genericworkers_proto");
}
if (HProxy.equals("dataminer-d-workers.d4science.org")) {
cl.setName("devnext_backend");
}
return cl;
}
public List<Host> listDataMinersByCluster() throws IOException {
//next op to use when Cluster info available in the IS
//Cluster cluster = this.getClusterByHProxy();
Cluster cluster = this.MapCluster();
List<Host> out = new LinkedList<Host>();
//prod
URL stockURL = new URL("http://data.d4science.org/Yk4zSFF6V3JOSytNd3JkRDlnRFpDUUR5TnRJZEw2QjRHbWJQNStIS0N6Yz0");
//dev
//URL stockURL = new URL("http://data.d4science.org/c29KTUluTkZnRlB0WXE5NVNaZnRoR0dtYThUSmNTVlhHbWJQNStIS0N6Yz0");
BufferedReader in = new BufferedReader(new InputStreamReader(stockURL.openStream()));
reader = new CSVReader(in, ',');
String[] nextLine;
while ((nextLine = reader.readNext()) != null) {
if (nextLine[1].equals("BACKEND")||(nextLine[1].equals("FRONTEND"))){
continue;
}
if (nextLine[0].equals(cluster.getName())) {
Host a = new Host();
a.setName(nextLine[1]);
out.add(a);
System.out.println(a.getFullyQualifiedName());
}
}
return out;
}
public static void main(String[] args) throws IOException, SVNException {
HAProxy a = new HAProxy();
ScopeProvider.instance.set("/gcube/devNext/NextNext");
//System.out.println(a.getHProxy());
//System.out.println(a.MapCluster());
System.out.println(a.listDataMinersByCluster());
//System.out.println(a.listDataMinersByCluster());
//List<Dependency> list = new LinkedList<Dependency>();
//Dependency aa = new Dependency();
//aa.setName("testnunzio");
//aa.setType("cran:");
//list.add(aa);
//a.checkSVNdep();
//System.out.println(a.getDataminer("dataminer1-devnext.d4science.org").getDomain());
//System.out.println(a.listDataminersInVRE());
}
}

View File

@ -142,7 +142,7 @@ public class ISClient {
// return the HProxy hostname in the VRE
public String getHProxy(){
public static String getHProxy(){
Host h = new Host();
SimpleQuery query = queryFor(ServiceEndpoint.class);
query.addCondition("$resource/Profile/Platform/Name/text() eq 'DataMiner'");
@ -154,115 +154,34 @@ public String getHProxy(){
//return the Cluster hostname from the IS
//to develop
public Cluster getCluster(){
Cluster cl = new Cluster();
String HProxy = this.getHProxy();
SimpleQuery query = queryFor(ServiceEndpoint.class);
query.addCondition("$resource/Profile/Platform/Name/text() eq 'DataMiner'");
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
List<ServiceEndpoint> resources = client.submit(query);
cl.setName(resources.get(0).profile().runtime().hostedOn());
return null;
}
//public Cluster getCluster(){
// Cluster cl = new Cluster();
// String HProxy = this.getHProxy();
// SimpleQuery query = queryFor(ServiceEndpoint.class);
// query.addCondition("$resource/Profile/Platform/Name/text() eq 'DataMiner'");
// DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
// List<ServiceEndpoint> resources = client.submit(query);
// cl.setName(resources.get(0).profile().runtime().hostedOn());
// return null;
//
//}
//return the dataminer hostnames from the IS
//to develop
public List<Host> getDM(){
Cluster cl = new Cluster();
String HProxy = this.getHProxy();
SimpleQuery query = queryFor(ServiceEndpoint.class);
query.addCondition("$resource/Profile/Platform/Name/text() eq 'DataMiner'");
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
List<ServiceEndpoint> resources = client.submit(query);
cl.setName(resources.get(0).profile().runtime().hostedOn());
return null;
//public List<Host> getDM(){
// Cluster cl = new Cluster();
// String HProxy = this.getHProxy();
// SimpleQuery query = queryFor(ServiceEndpoint.class);
// query.addCondition("$resource/Profile/Platform/Name/text() eq 'DataMiner'");
// DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
// List<ServiceEndpoint> resources = client.submit(query);
// cl.setName(resources.get(0).profile().runtime().hostedOn());
// return null;
//
//}
}
public Cluster getClusterByHProxy() throws IOException {
Cluster cl = new Cluster();
String HProxy = this.getHProxy();
URL stockURL = new URL("http://data.d4science.org/Yk4zSFF6V3JOSytNd3JkRDlnRFpDUUR5TnRJZEw2QjRHbWJQNStIS0N6Yz0");
BufferedReader in = new BufferedReader(new InputStreamReader(stockURL.openStream()));
reader = new CSVReader(in);
String [] nextLine;
while ((nextLine = reader.readNext()) != null) {
//rules to add
if (HProxy.contains(nextLine[0])){
cl.setName(nextLine[0]);
}
}
return cl;
}
public Cluster MapCluster() throws IOException {
Cluster cl = new Cluster();
String HProxy = this.getHProxy();
if (HProxy.equals("dataminer-cluster1.d4science.org")) {
cl.setName("dataminer_cluster1");
}
if (HProxy.equals("dataminer-bigdata.d4science.org")) {
cl.setName("bigdata");
}
if (HProxy.equals("dataminer-cluster1.d4science.org")) {
cl.setName("dataminer_cluster1");
}
if (HProxy.equals("dataminer-cloud1.d4science.org")) {
cl.setName("dataminer_cloud1");
}
if (HProxy.equals("dataminer-prototypes.d4science.org")) {
cl.setName("prototypes");
}
if (HProxy.equals("dataminer.d4science.org")) {
cl.setName("gcubeapps");
}
if (HProxy.equals("dataminer-genericworkers.d4science.org")) {
cl.setName("genericworkers");
}
if (HProxy.equals("dataminer-genericworkers-proto.d4science.org")) {
cl.setName("genericworkers_proto");
}
if (HProxy.equals("dataminer-d-workers.d4science.org")) {
cl.setName("devnext_backend");
}
return cl;
}
public List<Host> listDataMinersByCluster() throws IOException {
//next op to use when Cluster info available in the IS
//Cluster cluster = this.getClusterByHProxy();
Cluster cluster = this.MapCluster();
List<Host> out = new LinkedList<Host>();
//prod
//URL stockURL = new URL("http://data.d4science.org/Yk4zSFF6V3JOSytNd3JkRDlnRFpDUUR5TnRJZEw2QjRHbWJQNStIS0N6Yz0");
//dev
URL stockURL = new URL("http://data.d4science.org/c29KTUluTkZnRlB0WXE5NVNaZnRoR0dtYThUSmNTVlhHbWJQNStIS0N6Yz0");
BufferedReader in = new BufferedReader(new InputStreamReader(stockURL.openStream()));
reader = new CSVReader(in, ',');
String[] nextLine;
while ((nextLine = reader.readNext()) != null) {
if (nextLine[1].equals("BACKEND")||(nextLine[1].equals("FRONTEND"))){
continue;
}
if (nextLine[0].equals(cluster.getName())) {
Host a = new Host();
a.setName(nextLine[1]);
out.add(a);
System.out.println(a.getFullyQualifiedName());
}
}
return out;
}
/**
* Return the list of hosts (dataminers) in a given VRE
*
@ -310,7 +229,7 @@ public List<Host> listDataMinersByCluster() throws IOException {
ScopeProvider.instance.set("/gcube/devNext/NextNext");
//System.out.println(a.getHProxy());
//System.out.println(a.MapCluster());
System.out.println(a.listDataMinersByCluster());
//System.out.println(a.listDataMinersByCluster());
//System.out.println(a.listDataMinersByCluster());

View File

@ -292,6 +292,7 @@ import org.gcube.common.resources.gcore.Resources;
import org.gcube.common.resources.gcore.Software.Profile.Dependency;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.dataanalysis.dataminer.poolmanager.ansiblebridge.AnsibleBridge;
import org.gcube.dataanalysis.dataminer.poolmanager.clients.HAProxy;
import org.gcube.dataanalysis.dataminer.poolmanager.clients.ISClient;
import org.gcube.dataanalysis.dataminer.poolmanager.datamodel.Algorithm;
import org.gcube.dataanalysis.dataminer.poolmanager.datamodel.AlgorithmSet;
@ -540,7 +541,7 @@ public class DataminerPoolManager implements PoolManager {
// create the cluster (dataminers in the vre)
Cluster cluster = new Cluster();
for (Host h : new ISClient().listDataMinersByCluster()) {
for (Host h : new HAProxy().listDataMinersByCluster()) {
//for (Host h : new ISClient().listDataminersInVRE()) {
cluster.addHost(h);
}