2017-04-19 16:59:36 +02:00
|
|
|
package org.gcube.dataanalysis.dataminer.poolmanager.clients;
|
|
|
|
|
|
|
|
import java.io.BufferedReader;
|
2023-01-18 17:56:48 +01:00
|
|
|
import java.io.IOException;
|
2017-04-19 16:59:36 +02:00
|
|
|
import java.io.InputStreamReader;
|
2023-01-18 17:56:48 +01:00
|
|
|
import java.net.URL;
|
2017-04-19 16:59:36 +02:00
|
|
|
import java.util.LinkedList;
|
2023-01-18 17:56:48 +01:00
|
|
|
import java.util.List;
|
2017-05-12 17:32:14 +02:00
|
|
|
|
2023-01-18 17:56:48 +01:00
|
|
|
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
|
|
|
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
|
|
|
import org.gcube.common.scope.api.ScopeProvider;
|
2017-04-19 16:59:36 +02:00
|
|
|
import org.gcube.dataanalysis.dataminer.poolmanager.datamodel.Cluster;
|
|
|
|
import org.gcube.dataanalysis.dataminer.poolmanager.datamodel.Host;
|
2017-06-19 18:34:44 +02:00
|
|
|
import org.gcube.dataanalysis.dataminer.poolmanager.util.CheckPermission;
|
2023-01-18 17:56:48 +01:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
2017-12-20 12:01:01 +01:00
|
|
|
|
2017-04-19 16:59:36 +02:00
|
|
|
import au.com.bytecode.opencsv.CSVReader;
|
|
|
|
|
2023-01-18 17:56:48 +01:00
|
|
|
public class HAProxy {
|
2017-04-19 16:59:36 +02:00
|
|
|
|
2017-12-20 12:01:01 +01:00
|
|
|
private Logger logger;
|
|
|
|
|
2017-04-19 16:59:36 +02:00
|
|
|
private CSVReader reader;
|
|
|
|
|
2023-01-18 17:56:48 +01:00
|
|
|
public HAProxy() {
|
2017-12-20 12:01:01 +01:00
|
|
|
this.logger = LoggerFactory.getLogger(HAProxy.class);
|
2023-01-18 17:56:48 +01:00
|
|
|
}
|
2017-12-20 12:01:01 +01:00
|
|
|
|
2023-01-18 17:56:48 +01:00
|
|
|
// 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;
|
|
|
|
//
|
|
|
|
// }
|
2017-04-19 16:59:36 +02:00
|
|
|
|
2023-01-18 17:56:48 +01:00
|
|
|
public Cluster MapCluster() throws IOException {
|
2017-04-19 16:59:36 +02:00
|
|
|
Cluster cl = new Cluster();
|
|
|
|
String HProxy = ISClient.getHProxy();
|
2023-01-18 17:56:48 +01:00
|
|
|
//Prod HAproxy
|
|
|
|
if (HProxy.equals("dataminer-cluster1.d4science.org")) {
|
2017-04-19 16:59:36 +02:00
|
|
|
cl.setName("dataminer_cluster1");
|
2023-01-18 17:56:48 +01:00
|
|
|
}
|
|
|
|
if (HProxy.equals("dataminer-bigdata.d4science.org")) {
|
2017-04-19 16:59:36 +02:00
|
|
|
cl.setName("bigdata");
|
2023-01-18 17:56:48 +01:00
|
|
|
}
|
|
|
|
if (HProxy.equals("dataminer-cluster1.d4science.org")) {
|
2017-04-19 16:59:36 +02:00
|
|
|
cl.setName("dataminer_cluster1");
|
2023-01-18 17:56:48 +01:00
|
|
|
}
|
|
|
|
if (HProxy.equals("dataminer-cloud1.d4science.org")) {
|
2017-04-19 16:59:36 +02:00
|
|
|
cl.setName("dataminer_cloud1");
|
2023-01-18 17:56:48 +01:00
|
|
|
}
|
|
|
|
if (HProxy.equals("dataminer-prototypes.d4science.org")) {
|
2017-04-19 16:59:36 +02:00
|
|
|
cl.setName("prototypes");
|
2023-01-18 17:56:48 +01:00
|
|
|
}
|
|
|
|
if (HProxy.equals("dataminer.d4science.org")) {
|
2017-04-19 16:59:36 +02:00
|
|
|
cl.setName("gcubeapps");
|
2023-01-18 17:56:48 +01:00
|
|
|
}
|
|
|
|
if (HProxy.equals("dataminer-genericworkers.d4science.org")) {
|
2017-04-19 16:59:36 +02:00
|
|
|
cl.setName("genericworkers");
|
2023-01-18 17:56:48 +01:00
|
|
|
}
|
|
|
|
if (HProxy.equals("dataminer-genericworkers-proto.d4science.org")) {
|
2017-04-19 16:59:36 +02:00
|
|
|
cl.setName("genericworkers_proto");
|
2023-01-18 17:56:48 +01:00
|
|
|
}
|
|
|
|
//dev HAProxy
|
|
|
|
if (HProxy.equals("dataminer-d-workers.d4science.org")||(HProxy.equals("dataminer-d-d4s.d4science.org"))) {
|
2017-04-19 16:59:36 +02:00
|
|
|
cl.setName("devnext_backend");
|
2023-01-18 17:56:48 +01:00
|
|
|
}
|
|
|
|
//preProd HAProxy
|
|
|
|
// if (HProxy.equals("dataminer1-pre.d4science.org")) {
|
|
|
|
// cl.setName("dataminer1-pre.d4science.org");
|
|
|
|
// }
|
2017-04-19 16:59:36 +02:00
|
|
|
return cl;
|
|
|
|
|
2023-01-18 17:56:48 +01:00
|
|
|
}
|
2017-04-19 18:20:29 +02:00
|
|
|
|
|
|
|
|
2023-01-18 17:56:48 +01:00
|
|
|
public List<Host> listDataMinersByCluster(String targetVREToken,String targetVRE) throws IOException {
|
2017-05-12 17:32:14 +02:00
|
|
|
|
|
|
|
SecurityTokenProvider.instance.set(targetVREToken);
|
|
|
|
ScopeProvider.instance.set(targetVRE);
|
|
|
|
|
2023-01-18 17:56:48 +01:00
|
|
|
// next op to use when Cluster info available in the IS
|
|
|
|
// Cluster cluster = this.getClusterByHProxy();
|
2017-04-19 16:59:36 +02:00
|
|
|
Cluster cluster = this.MapCluster();
|
|
|
|
List<Host> out = new LinkedList<Host>();
|
2017-04-28 15:26:47 +02:00
|
|
|
Host a = new Host();
|
2017-04-19 16:59:36 +02:00
|
|
|
|
2023-01-18 17:56:48 +01:00
|
|
|
//no proxy dataminer (preprod)
|
|
|
|
if (cluster.getName() == null){
|
2017-04-28 15:26:47 +02:00
|
|
|
a.setName(ISClient.getHProxy());
|
|
|
|
out.add(a);
|
2023-01-18 17:56:48 +01:00
|
|
|
}
|
2017-04-28 15:26:47 +02:00
|
|
|
|
2023-01-18 17:56:48 +01:00
|
|
|
// if preprod, just one dm available
|
|
|
|
// if (cluster.getName().equals("dataminer1-pre.d4science.org")) {
|
|
|
|
// a.setName("dataminer1-pre.d4science.org");
|
|
|
|
// out.add(a);
|
|
|
|
//}
|
|
|
|
else {
|
|
|
|
// prod
|
|
|
|
//URL stockURL = new
|
|
|
|
//URL("http://data.d4science.org/Yk4zSFF6V3JOSytNd3JkRDlnRFpDUUR5TnRJZEw2QjRHbWJQNStIS0N6Yz0");
|
|
|
|
URL stockURL = new URL("http://"+ ISClient.getHProxy() +":8880/;csv");
|
|
|
|
//URL stockURL = new URL("http://data.d4science.org/c29KTUluTkZnRlB0WXE5NVNaZnRoR0dtYThUSmNTVlhHbWJQNStIS0N6Yz0");
|
|
|
|
//System.out.println(stockURL);
|
|
|
|
// dev
|
|
|
|
//URL stockURL = new
|
|
|
|
//URL("http://data.d4science.org/c29KTUluTkZnRlB0WXE5NVNaZnRoR0dtYThUSmNTVlhHbWJQNStIS0N6Yz0");
|
2017-04-28 15:26:47 +02:00
|
|
|
BufferedReader in = new BufferedReader(new InputStreamReader(stockURL.openStream()));
|
|
|
|
reader = new CSVReader(in, ',');
|
|
|
|
String[] nextLine;
|
2023-01-18 17:56:48 +01:00
|
|
|
while ((nextLine = reader.readNext()) != null) {
|
|
|
|
if (nextLine[1].equals("BACKEND") || (nextLine[1].equals("FRONTEND"))) {
|
2017-04-28 15:26:47 +02:00
|
|
|
continue;
|
2023-01-18 17:56:48 +01:00
|
|
|
}
|
|
|
|
if (nextLine[0].equals(cluster.getName())) {
|
2017-04-28 16:26:40 +02:00
|
|
|
Host b = new Host();
|
|
|
|
b.setName(nextLine[1]);
|
|
|
|
out.add(b);
|
2017-12-20 12:01:01 +01:00
|
|
|
this.logger.info(b.getFullyQualifiedName());
|
2023-01-18 17:56:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-12-20 12:01:01 +01:00
|
|
|
this.logger.info(out.toString());
|
2017-04-19 16:59:36 +02:00
|
|
|
return out;
|
|
|
|
|
2023-01-18 17:56:48 +01:00
|
|
|
}
|
2017-04-19 16:59:36 +02:00
|
|
|
|
2023-01-18 17:56:48 +01:00
|
|
|
public static void main(String[] args) throws ObjectNotFound, Exception {
|
2017-04-19 17:01:21 +02:00
|
|
|
HAProxy a = new HAProxy();
|
2023-01-18 17:56:48 +01:00
|
|
|
//ScopeProvider.instance.set("/gcube/devNext/NextNext");
|
|
|
|
//ScopeProvider.instance.set("/d4science.research-infrastructures.eu/gCubeApps/RPrototypingLab");
|
2023-01-19 10:39:04 +01:00
|
|
|
SecurityTokenProvider.instance.set("");
|
2017-06-19 18:34:44 +02:00
|
|
|
|
|
|
|
CheckPermission test = new CheckPermission();
|
2023-01-19 10:39:04 +01:00
|
|
|
CheckPermission.apply("", "/gcube/devNext/NextNext");
|
2017-06-19 18:34:44 +02:00
|
|
|
|
|
|
|
|
2023-01-18 17:56:48 +01:00
|
|
|
//ScopeProvider.instance.set("/d4science.research-infrastructures.eu/gCubeApps/RPrototypingLab");
|
|
|
|
// System.out.println(a.getHProxy());
|
|
|
|
// System.out.println(a.MapCluster());
|
2023-01-19 10:39:04 +01:00
|
|
|
//System.out.println(a.listDataMinersByCluster("","/gcube/devNext/NextNext"));
|
2023-01-18 17:56:48 +01:00
|
|
|
// System.out.println(a.listDataMinersByCluster());
|
2017-04-19 17:01:21 +02:00
|
|
|
|
2023-01-18 17:56:48 +01:00
|
|
|
// List<Dependency> list = new LinkedList<Dependency>();
|
|
|
|
// Dependency aa = new Dependency();
|
|
|
|
// aa.setName("testnunzio");
|
|
|
|
// aa.setType("cran:");
|
|
|
|
// list.add(aa);
|
2017-04-19 17:01:21 +02:00
|
|
|
|
2023-01-18 17:56:48 +01:00
|
|
|
// a.checkSVNdep();
|
|
|
|
// System.out.println(a.getDataminer("dataminer1-devnext.d4science.org").getDomain());
|
|
|
|
// System.out.println(a.listDataminersInVRE());
|
|
|
|
}
|
|
|
|
}
|