2017-03-03 19:10:02 +01:00
|
|
|
//package org.gcube.dataanalysis.dataminer.poolmanager.rest;
|
|
|
|
//
|
|
|
|
//import java.io.IOException;
|
|
|
|
//import java.net.MalformedURLException;
|
|
|
|
//import java.net.ProxySelector;
|
|
|
|
//import java.net.URL;
|
|
|
|
//import java.net.UnknownHostException;
|
|
|
|
//
|
|
|
|
//import javax.ws.rs.GET;
|
|
|
|
//import javax.ws.rs.Path;
|
|
|
|
//import javax.ws.rs.Produces;
|
|
|
|
//import javax.ws.rs.QueryParam;
|
|
|
|
//
|
|
|
|
//import org.gcube.common.scope.api.ScopeProvider;
|
|
|
|
//import org.gcube.dataanalysis.dataminer.poolmanager.datamodel.Algorithm;
|
|
|
|
//import org.gcube.dataanalysis.dataminer.poolmanager.service.DataminerPoolManager;
|
|
|
|
//import org.gcube.dataanalysis.dataminer.poolmanager.util.PropertiesBasedProxySelector;
|
|
|
|
//import org.slf4j.Logger;
|
|
|
|
//import org.slf4j.LoggerFactory;
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//@Path("/")
|
|
|
|
//public class RestPoolManager implements PoolManager {
|
|
|
|
//
|
|
|
|
// private static final Logger LOGGER = LoggerFactory.getLogger(RestPoolManager.class);
|
|
|
|
//
|
|
|
|
// private PoolManager service = new DataminerPoolManager();
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// @GET
|
|
|
|
// @Path("/add")
|
|
|
|
// @Produces("text/plain")
|
|
|
|
// public String addAlgorithmToVRE(
|
|
|
|
// @QueryParam("algorithm") String algorithm,
|
|
|
|
// @QueryParam("vre") String vre,
|
|
|
|
// @QueryParam("name") String name,
|
|
|
|
// @QueryParam("description") String description,
|
|
|
|
// @QueryParam("category") String category,
|
|
|
|
// @QueryParam("algorithmType") String algorithmType,
|
|
|
|
// @QueryParam("skipJava") String skipJava) throws IOException, InterruptedException {
|
|
|
|
// // TODO Auto-generated method stub
|
|
|
|
// LOGGER.debug("Adding algorithm =" + algorithm + " to VRE =" + vre);
|
|
|
|
// Algorithm algo = service.extractAlgorithm(algorithm);
|
|
|
|
//
|
|
|
|
// if (algo.getCategory() == null){
|
|
|
|
// algo.setCategory(category);
|
|
|
|
// } else category = algo.getCategory();
|
|
|
|
//
|
|
|
|
// if (algo.getAlgorithmType() == null){
|
|
|
|
// algo.setAlgorithmType(algorithmType);
|
|
|
|
// } else algorithmType = algo.getCategory();
|
|
|
|
//
|
|
|
|
// if (algo.getSkipJava() == null){
|
|
|
|
// algo.setSkipJava(skipJava);
|
|
|
|
// } else skipJava = algo.getSkipJava();
|
|
|
|
//
|
|
|
|
// if (algo.getName() == null){
|
|
|
|
// algo.setCategory(name);
|
|
|
|
// } else name = algo.getName();
|
|
|
|
//
|
|
|
|
// if (algo.getDescription() == null){
|
|
|
|
// algo.setDescription(description);;
|
|
|
|
// } else description = algo.getDescription();
|
|
|
|
//
|
|
|
|
// return service.addAlgorithmToVRE(algo, vre);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// @GET
|
|
|
|
// @Path("/log")
|
|
|
|
// @Produces("text/plain")
|
|
|
|
// public String getLogById(@QueryParam("logUrl") String logUrl) throws IOException {
|
|
|
|
// // TODO Auto-generated method stub
|
|
|
|
// LOGGER.debug("Returning Log =" + logUrl);
|
|
|
|
// return service.getScriptFromURL(service.getURLfromWorkerLog(logUrl));
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// @Override
|
|
|
|
// public Algorithm extractAlgorithm(String url) throws IOException {
|
|
|
|
// // TODO Auto-generated method stub
|
|
|
|
// return null;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// public static void main(String[] args) throws IOException, InterruptedException {
|
|
|
|
// RestPoolManager a = new RestPoolManager();
|
|
|
|
// //System.out.println(System.getProperty("user.home")+File.separator+"/gcube/dataminer-pool-manager");
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// //ProxySelector.setDefault(new PropertiesBasedProxySelector("/home/ngalante/.proxy-settings"));
|
|
|
|
//
|
|
|
|
// ScopeProvider.instance.set("/gcube/devNext/NextNext");
|
|
|
|
// a.addAlgorithmToVRE(
|
|
|
|
// "http://data.d4science.org/S2h1RHZGd0JpWnBjZk9qTytQTndqcDRLVHNrQUt6QjhHbWJQNStIS0N6Yz0",
|
|
|
|
// "/gcube/devNext/NextNext",
|
|
|
|
// null, null, "test", "transducerers", "N");
|
|
|
|
//
|
|
|
|
// //System.out.println(a.getLogById("34ac474d-b9df-4929-87e1-2a0ae26cf898"));
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// @Override
|
|
|
|
// public void getLogId(Algorithm algo, String vre) {
|
|
|
|
// // TODO Auto-generated method stub
|
|
|
|
//
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// @Override
|
|
|
|
// public String getScriptFromURL(URL logId) throws IOException {
|
|
|
|
// // TODO Auto-generated method stub
|
|
|
|
// return null;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// @Override
|
|
|
|
// public String addAlgorithmToVRE(Algorithm algo, String vre) throws IOException, InterruptedException {
|
|
|
|
// // TODO Auto-generated method stub
|
|
|
|
// return null;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// @Override
|
|
|
|
// public URL getURLfromWorkerLog(String logUrl) throws MalformedURLException, UnknownHostException {
|
|
|
|
// // TODO Auto-generated method stub
|
|
|
|
// return null;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//}
|
|
|
|
package org.gcube.dataanalysis.dataminer.poolmanager.rest;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.net.MalformedURLException;
|
|
|
|
import java.net.ProxySelector;
|
|
|
|
import java.net.URL;
|
|
|
|
import java.net.UnknownHostException;
|
2017-03-29 16:06:46 +02:00
|
|
|
import java.util.Random;
|
|
|
|
import java.util.Set;
|
|
|
|
import java.util.UUID;
|
2017-03-03 19:10:02 +01:00
|
|
|
|
2017-04-04 19:32:53 +02:00
|
|
|
import javax.ws.rs.DefaultValue;
|
2017-03-03 19:10:02 +01:00
|
|
|
import javax.ws.rs.GET;
|
|
|
|
import javax.ws.rs.Path;
|
|
|
|
import javax.ws.rs.Produces;
|
|
|
|
import javax.ws.rs.QueryParam;
|
|
|
|
|
2017-03-29 16:06:46 +02:00
|
|
|
import org.apache.commons.lang.math.RandomUtils;
|
2017-03-03 19:10:02 +01:00
|
|
|
import org.gcube.common.scope.api.ScopeProvider;
|
|
|
|
import org.gcube.dataanalysis.dataminer.poolmanager.datamodel.Algorithm;
|
|
|
|
import org.gcube.dataanalysis.dataminer.poolmanager.service.DataminerPoolManager;
|
|
|
|
import org.gcube.dataanalysis.dataminer.poolmanager.util.PropertiesBasedProxySelector;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Path("/")
|
|
|
|
public class RestPoolManager implements PoolManager {
|
|
|
|
|
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(RestPoolManager.class);
|
|
|
|
|
|
|
|
private PoolManager service = new DataminerPoolManager();
|
|
|
|
|
|
|
|
/*
|
|
|
|
/scopes/<scope> POST // add an algorithm to all dataminers in the scope
|
|
|
|
/hosts/<hostname> POST // add an algorithm to the given host
|
|
|
|
*/
|
|
|
|
|
2017-03-29 16:06:46 +02:00
|
|
|
@GET
|
2017-03-03 19:10:02 +01:00
|
|
|
@Path("/scopes/add")
|
|
|
|
@Produces("text/plain")
|
|
|
|
public String addAlgorithmToVRE(
|
|
|
|
@QueryParam("algorithm") String algorithm,
|
|
|
|
@QueryParam("vre") String vre,
|
|
|
|
@QueryParam("name") String name,
|
|
|
|
@QueryParam("description") String description,
|
|
|
|
@QueryParam("category") String category,
|
2017-04-04 19:32:53 +02:00
|
|
|
@DefaultValue("transducerers") @QueryParam("algorithmType") String algorithmType,
|
|
|
|
@DefaultValue("N") @QueryParam("skipJava") String skipJava,
|
|
|
|
@DefaultValue("false") @QueryParam("publish") boolean publish) throws IOException, InterruptedException {
|
2017-03-03 19:10:02 +01:00
|
|
|
Algorithm algo= this.getAlgorithm(algorithm, vre, null, name, description, category, algorithmType, skipJava);
|
2017-04-04 19:32:53 +02:00
|
|
|
|
|
|
|
if (publish){
|
|
|
|
service.addAlgToIs(algo);
|
|
|
|
}
|
2017-03-03 19:10:02 +01:00
|
|
|
return service.addAlgorithmToVRE(algo, vre);
|
|
|
|
}
|
|
|
|
|
|
|
|
@GET
|
|
|
|
@Path("/hosts/add")
|
|
|
|
@Produces("text/plain")
|
|
|
|
public String addAlgorithmToHost(
|
|
|
|
@QueryParam("algorithm") String algorithm,
|
|
|
|
@QueryParam("hostname") String hostname,
|
|
|
|
@QueryParam("name") String name,
|
|
|
|
@QueryParam("description") String description,
|
|
|
|
@QueryParam("category") String category,
|
2017-04-04 19:32:53 +02:00
|
|
|
@DefaultValue("transducerers") @QueryParam("algorithmType") String algorithmType,
|
|
|
|
@DefaultValue("N") @QueryParam("skipJava") String skipJava) throws IOException, InterruptedException {
|
2017-03-03 19:10:02 +01:00
|
|
|
Algorithm algo= this.getAlgorithm(algorithm, null, hostname, name, description, category, algorithmType, skipJava);
|
|
|
|
return service.addAlgorithmToHost(algo, hostname);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Algorithm getAlgorithm(
|
|
|
|
String algorithm,
|
|
|
|
String vre,
|
|
|
|
String hostname,
|
|
|
|
String name,
|
|
|
|
String description,
|
|
|
|
String category,
|
|
|
|
String algorithmType,
|
|
|
|
String skipJava) throws IOException, InterruptedException {
|
|
|
|
LOGGER.debug("Adding algorithm =" + algorithm + " to VRE =" + vre);
|
|
|
|
Algorithm algo = service.extractAlgorithm(algorithm);
|
2017-04-04 19:32:53 +02:00
|
|
|
|
2017-03-03 19:10:02 +01:00
|
|
|
|
|
|
|
if (algo.getCategory() == null){
|
|
|
|
algo.setCategory(category);
|
2017-03-29 16:45:22 +02:00
|
|
|
} else algo.setCategory(algo.getCategory());
|
2017-03-03 19:10:02 +01:00
|
|
|
|
|
|
|
if (algo.getAlgorithmType() == null){
|
|
|
|
algo.setAlgorithmType(algorithmType);
|
2017-03-29 16:45:22 +02:00
|
|
|
} else algo.setAlgorithmType(algo.getCategory());
|
2017-03-03 19:10:02 +01:00
|
|
|
|
|
|
|
if (algo.getSkipJava() == null){
|
|
|
|
algo.setSkipJava(skipJava);
|
2017-03-29 16:45:22 +02:00
|
|
|
} else algo.setSkipJava(algo.getSkipJava());
|
2017-03-03 19:10:02 +01:00
|
|
|
|
|
|
|
if (algo.getName() == null){
|
2017-04-03 14:35:03 +02:00
|
|
|
algo.setName(name);
|
|
|
|
} else algo.setName(algo.getName());
|
2017-03-03 19:10:02 +01:00
|
|
|
|
|
|
|
if (algo.getDescription() == null){
|
|
|
|
algo.setDescription(description);;
|
2017-03-29 16:45:22 +02:00
|
|
|
} else algo.setDescription(algo.getDescription());
|
|
|
|
|
2017-03-03 19:10:02 +01:00
|
|
|
return algo;
|
|
|
|
}
|
|
|
|
|
2017-04-04 19:32:53 +02:00
|
|
|
|
2017-03-03 19:10:02 +01:00
|
|
|
|
|
|
|
@GET
|
|
|
|
@Path("/log")
|
|
|
|
@Produces("text/plain")
|
|
|
|
public String getLogById(@QueryParam("logUrl") String logUrl) throws IOException {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
LOGGER.debug("Returning Log =" + logUrl);
|
|
|
|
return service.getScriptFromURL(service.getURLfromWorkerLog(logUrl));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Algorithm extractAlgorithm(String url) throws IOException {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) throws IOException, InterruptedException {
|
|
|
|
//System.out.println(System.getProperty("user.home")+File.separator+"/gcube/dataminer-pool-manager");
|
|
|
|
//ProxySelector.setDefault(new PropertiesBasedProxySelector("/home/ngalante/.proxy-settings"));
|
|
|
|
|
|
|
|
ScopeProvider.instance.set("/gcube/devNext/NextNext");
|
|
|
|
|
2017-03-29 16:06:46 +02:00
|
|
|
//PoolManager aa = new DataminerPoolManager();
|
|
|
|
//System.out.println(aa.getAlgoById("ICHTHYOP_MODEL_ONE_BY_ONE@3141d3aa-5f93-409f-b6f8-9fae0a6c0ee3"));
|
|
|
|
//System.out.println(aa.getAlgoFromIs());
|
|
|
|
|
2017-03-03 19:10:02 +01:00
|
|
|
|
2017-03-29 16:06:46 +02:00
|
|
|
RestPoolManager a = new RestPoolManager();
|
|
|
|
//a.addAlgorithmToVRE(
|
|
|
|
//"http://data.d4science.org/S2h1RHZGd0JpWnBjZk9qTytQTndqcDRLVHNrQUt6QjhHbWJQNStIS0N6Yz0",
|
|
|
|
//"/gcube/devNext/NextNext",
|
|
|
|
//null, null, "test", "transducerers", "N");
|
|
|
|
|
2017-03-03 19:10:02 +01:00
|
|
|
a.addAlgorithmToHost(
|
2017-04-04 19:32:53 +02:00
|
|
|
"http://data.d4science.org/dENQTTMxdjNZcGRpK0NHd2pvU0owMFFzN0VWemw3Zy9HbWJQNStIS0N6Yz0",
|
2017-03-29 16:06:46 +02:00
|
|
|
"dataminer1-devnext.d4science.org",
|
|
|
|
"ICHTHYOP_MODEL_ONE_BY_ONE", null, "ICHTHYOP_MODEL", "transducerers", "N");
|
2017-03-03 19:10:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-29 16:06:46 +02:00
|
|
|
|
2017-03-03 19:10:02 +01:00
|
|
|
@Override
|
|
|
|
public void getLogId(Algorithm algo, String vre) {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getScriptFromURL(URL logId) throws IOException {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String addAlgorithmToVRE(Algorithm algo, String vre) throws IOException, InterruptedException {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String addAlgorithmToHost(Algorithm algo, String hostname)
|
|
|
|
throws IOException, InterruptedException {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public URL getURLfromWorkerLog(String logUrl) throws MalformedURLException, UnknownHostException {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2017-03-29 16:06:46 +02:00
|
|
|
@Override
|
|
|
|
public void addAlgToIs(Algorithm algo) {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Set<Algorithm> getAlgoFromIs() {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2017-04-03 14:35:03 +02:00
|
|
|
|
2017-03-03 19:10:02 +01:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|