This commit is contained in:
Nunzio Andrea Galante 2017-04-19 15:01:21 +00:00
parent 1a3ccdc31b
commit bc31c95bf5
1 changed files with 44 additions and 88 deletions

View File

@ -1,80 +1,39 @@
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 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 {
public Cluster MapCluster() throws IOException {
Cluster cl = new Cluster();
String HProxy = ISClient.getHProxy();
if (HProxy.equals("dataminer-cluster1.d4science.org")) {
@ -104,27 +63,27 @@ public Cluster MapCluster() throws IOException {
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();
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
// prod
URL stockURL = new URL("http://data.d4science.org/Yk4zSFF6V3JOSytNd3JkRDlnRFpDUUR5TnRJZEw2QjRHbWJQNStIS0N6Yz0");
//dev
//URL stockURL = new URL("http://data.d4science.org/c29KTUluTkZnRlB0WXE5NVNaZnRoR0dtYThUSmNTVlhHbWJQNStIS0N6Yz0");
// 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"))){
if (nextLine[1].equals("BACKEND") || (nextLine[1].equals("FRONTEND"))) {
continue;
}
@ -137,27 +96,24 @@ public List<Host> listDataMinersByCluster() throws IOException {
}
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);
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());
//a.checkSVNdep();
//System.out.println(a.getDataminer("dataminer1-devnext.d4science.org").getDomain());
//System.out.println(a.listDataminersInVRE());
}
// 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());
}
}