dataminer-pool-manager/src/main/java/org/gcube/dataanalysis/dataminer/poolmanager/rest/RestPoolManager.java

366 lines
13 KiB
Java

***REMOVED***package org.gcube.dataanalysis.dataminer.poolmanager.rest;
***REMOVED***
***REMOVED******REMOVED***
***REMOVED***import java.net.MalformedURLException;
***REMOVED***import java.net.ProxySelector;
***REMOVED******REMOVED***
***REMOVED***import java.net.UnknownHostException;
***REMOVED***
***REMOVED***import javax.ws.rs.GET;
***REMOVED***import javax.ws.rs.Path;
***REMOVED***import javax.ws.rs.Produces;
***REMOVED***import javax.ws.rs.QueryParam;
***REMOVED***
***REMOVED******REMOVED***
***REMOVED***import org.gcube.dataanalysis.dataminer.poolmanager.datamodel.Algorithm;
***REMOVED***import org.gcube.dataanalysis.dataminer.poolmanager.service.DataminerPoolManager;
***REMOVED***import org.gcube.dataanalysis.dataminer.poolmanager.util.PropertiesBasedProxySelector;
***REMOVED******REMOVED***
***REMOVED******REMOVED***
***REMOVED***
***REMOVED***
***REMOVED***@Path("/")
***REMOVED***public class RestPoolManager implements PoolManager {
***REMOVED***
***REMOVED*** private static final Logger LOGGER = LoggerFactory.getLogger(RestPoolManager.class);
***REMOVED***
***REMOVED*** private PoolManager service = new DataminerPoolManager();
***REMOVED***
***REMOVED***
***REMOVED*** @GET
***REMOVED*** @Path("/add")
***REMOVED*** @Produces("text/plain")
***REMOVED*** public String addAlgorithmToVRE(
***REMOVED*** @QueryParam("algorithm") String algorithm,
***REMOVED*** @QueryParam("vre") String vre,
***REMOVED*** @QueryParam("name") String name,
***REMOVED*** @QueryParam("description") String description,
***REMOVED*** @QueryParam("category") String category,
***REMOVED*** @QueryParam("algorithmType") String algorithmType,
***REMOVED*** @QueryParam("skipJava") String skipJava) throws IOException, InterruptedException {
***REMOVED*** ***REMOVED*** TODO Auto-generated method stub
***REMOVED*** LOGGER.debug("Adding algorithm =" + algorithm + " to VRE =" + vre);
***REMOVED*** Algorithm algo = service.extractAlgorithm(algorithm);
***REMOVED***
***REMOVED*** if (algo.getCategory() == null){
***REMOVED*** algo.setCategory(category);
***REMOVED*** ***REMOVED*** else category = algo.getCategory();
***REMOVED***
***REMOVED*** if (algo.getAlgorithmType() == null){
***REMOVED*** algo.setAlgorithmType(algorithmType);
***REMOVED*** ***REMOVED*** else algorithmType = algo.getCategory();
***REMOVED***
***REMOVED*** if (algo.getSkipJava() == null){
***REMOVED*** algo.setSkipJava(skipJava);
***REMOVED*** ***REMOVED*** else skipJava = algo.getSkipJava();
***REMOVED***
***REMOVED*** if (algo.getName() == null){
***REMOVED*** algo.setCategory(name);
***REMOVED*** ***REMOVED*** else name = algo.getName();
***REMOVED***
***REMOVED*** if (algo.getDescription() == null){
***REMOVED*** algo.setDescription(description);;
***REMOVED*** ***REMOVED*** else description = algo.getDescription();
***REMOVED***
***REMOVED*** return service.addAlgorithmToVRE(algo, vre);
***REMOVED******REMOVED***
***REMOVED***
***REMOVED***
***REMOVED*** @GET
***REMOVED*** @Path("/log")
***REMOVED*** @Produces("text/plain")
***REMOVED*** public String getLogById(@QueryParam("logUrl") String logUrl) throws IOException {
***REMOVED*** ***REMOVED*** TODO Auto-generated method stub
***REMOVED*** LOGGER.debug("Returning Log =" + logUrl);
***REMOVED*** return service.getScriptFromURL(service.getURLfromWorkerLog(logUrl));
***REMOVED******REMOVED***
***REMOVED***
***REMOVED***
***REMOVED***
***REMOVED***
***REMOVED***
***REMOVED*** @Override
***REMOVED*** public Algorithm extractAlgorithm(String url) throws IOException {
***REMOVED*** ***REMOVED*** TODO Auto-generated method stub
***REMOVED*** return null;
***REMOVED******REMOVED***
***REMOVED***
***REMOVED***
***REMOVED*** public static void main(String[] args) throws IOException, InterruptedException {
***REMOVED*** RestPoolManager a = new RestPoolManager();
***REMOVED*** ***REMOVED***System.out.println(System.getProperty("user.home")+File.separator+"/gcube/dataminer-pool-manager");
***REMOVED***
***REMOVED***
***REMOVED*** ***REMOVED***ProxySelector.setDefault(new PropertiesBasedProxySelector("/home/ngalante/.proxy-settings"));
***REMOVED***
***REMOVED*** ScopeProvider.instance.set("/gcube/devNext/NextNext");
***REMOVED*** a.addAlgorithmToVRE(
***REMOVED*** "http:***REMOVED***data.d4science.org/S2h1RHZGd0JpWnBjZk9qTytQTndqcDRLVHNrQUt6QjhHbWJQNStIS0N6Yz0",
***REMOVED*** "/gcube/devNext/NextNext",
***REMOVED*** null, null, "test", "transducerers", "N");
***REMOVED***
***REMOVED*** ***REMOVED***System.out.println(a.getLogById("34ac474d-b9df-4929-87e1-2a0ae26cf898"));
***REMOVED******REMOVED***
***REMOVED***
***REMOVED***
***REMOVED*** @Override
***REMOVED*** public void getLogId(Algorithm algo, String vre) {
***REMOVED*** ***REMOVED*** TODO Auto-generated method stub
***REMOVED***
***REMOVED******REMOVED***
***REMOVED***
***REMOVED***
***REMOVED*** @Override
***REMOVED*** public String getScriptFromURL(URL logId) throws IOException {
***REMOVED*** ***REMOVED*** TODO Auto-generated method stub
***REMOVED*** return null;
***REMOVED******REMOVED***
***REMOVED***
***REMOVED***
***REMOVED*** @Override
***REMOVED*** public String addAlgorithmToVRE(Algorithm algo, String vre) throws IOException, InterruptedException {
***REMOVED*** ***REMOVED*** TODO Auto-generated method stub
***REMOVED*** return null;
***REMOVED******REMOVED***
***REMOVED***
***REMOVED***
***REMOVED*** @Override
***REMOVED*** public URL getURLfromWorkerLog(String logUrl) throws MalformedURLException, UnknownHostException {
***REMOVED*** ***REMOVED*** TODO Auto-generated method stub
***REMOVED*** return null;
***REMOVED******REMOVED***
***REMOVED***
***REMOVED***
***REMOVED***
***REMOVED***
***REMOVED***
***REMOVED***
***REMOVED***
***REMOVED***
***REMOVED***
***REMOVED***
***REMOVED******REMOVED***
package org.gcube.dataanalysis.dataminer.poolmanager.rest;
***REMOVED***
import java.net.MalformedURLException;
import java.net.ProxySelector;
***REMOVED***
import java.net.UnknownHostException;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
***REMOVED***
import org.gcube.dataanalysis.dataminer.poolmanager.datamodel.Algorithm;
import org.gcube.dataanalysis.dataminer.poolmanager.service.DataminerPoolManager;
import org.gcube.dataanalysis.dataminer.poolmanager.util.PropertiesBasedProxySelector;
***REMOVED***
***REMOVED***
@Path("/")
public class RestPoolManager implements PoolManager {
private static final Logger LOGGER = LoggerFactory.getLogger(RestPoolManager.class);
private PoolManager service = new DataminerPoolManager();
/*
/scopes/<scope> POST ***REMOVED*** add an algorithm to all dataminers in the scope
/hosts/<hostname> POST ***REMOVED*** add an algorithm to the given host
*/
@GET
@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,
@QueryParam("algorithmType") String algorithmType,
@QueryParam("skipJava") String skipJava) throws IOException, InterruptedException {
Algorithm algo= this.getAlgorithm(algorithm, vre, null, name, description, category, algorithmType, skipJava);
return service.addAlgorithmToVRE(algo, vre);
***REMOVED***
@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,
@QueryParam("algorithmType") String algorithmType,
@QueryParam("skipJava") String skipJava) throws IOException, InterruptedException {
Algorithm algo= this.getAlgorithm(algorithm, null, hostname, name, description, category, algorithmType, skipJava);
return service.addAlgorithmToHost(algo, hostname);
***REMOVED***
private Algorithm getAlgorithm(
String algorithm,
String vre,
String hostname,
String name,
String description,
String category,
String algorithmType,
String skipJava) throws IOException, InterruptedException {
***REMOVED*** 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);
***REMOVED*** else category = algo.getCategory();
if (algo.getAlgorithmType() == null){
algo.setAlgorithmType(algorithmType);
***REMOVED*** else algorithmType = algo.getCategory();
if (algo.getSkipJava() == null){
algo.setSkipJava(skipJava);
***REMOVED*** else skipJava = algo.getSkipJava();
if (algo.getName() == null){
algo.setCategory(name);
***REMOVED*** else name = algo.getName();
if (algo.getDescription() == null){
algo.setDescription(description);;
***REMOVED*** else description = algo.getDescription();
return algo;
***REMOVED***
***REMOVED*** @GET
***REMOVED*** @Path("/add")
***REMOVED*** @Produces("text/plain")
***REMOVED*** public String addAlgorithmToVRE(
***REMOVED*** @QueryParam("algorithm") String algorithm,
***REMOVED*** @QueryParam("vre") String vre,
***REMOVED*** @QueryParam("name") String name,
***REMOVED*** @QueryParam("description") String description,
***REMOVED*** @QueryParam("category") String category,
***REMOVED*** @QueryParam("algorithmType") String algorithmType,
***REMOVED*** @QueryParam("skipJava") String skipJava) throws IOException, InterruptedException {
***REMOVED*** ***REMOVED*** TODO Auto-generated method stub
***REMOVED*** LOGGER.debug("Adding algorithm =" + algorithm + " to VRE =" + vre);
***REMOVED*** Algorithm algo = service.extractAlgorithm(algorithm);
***REMOVED***
***REMOVED*** if (algo.getCategory() == null){
***REMOVED*** algo.setCategory(category);
***REMOVED*** ***REMOVED*** else category = algo.getCategory();
***REMOVED***
***REMOVED*** if (algo.getAlgorithmType() == null){
***REMOVED*** algo.setAlgorithmType(algorithmType);
***REMOVED*** ***REMOVED*** else algorithmType = algo.getCategory();
***REMOVED***
***REMOVED*** if (algo.getSkipJava() == null){
***REMOVED*** algo.setSkipJava(skipJava);
***REMOVED*** ***REMOVED*** else skipJava = algo.getSkipJava();
***REMOVED***
***REMOVED*** if (algo.getName() == null){
***REMOVED*** algo.setCategory(name);
***REMOVED*** ***REMOVED*** else name = algo.getName();
***REMOVED***
***REMOVED*** if (algo.getDescription() == null){
***REMOVED*** algo.setDescription(description);;
***REMOVED*** ***REMOVED*** else description = algo.getDescription();
***REMOVED***
***REMOVED*** return service.addAlgorithmToVRE(algo, vre);
***REMOVED******REMOVED***
@GET
@Path("/log")
@Produces("text/plain")
public String getLogById(@QueryParam("logUrl") String logUrl) throws IOException {
***REMOVED*** TODO Auto-generated method stub
LOGGER.debug("Returning Log =" + logUrl);
return service.getScriptFromURL(service.getURLfromWorkerLog(logUrl));
***REMOVED***
@Override
public Algorithm extractAlgorithm(String url) throws IOException {
***REMOVED*** TODO Auto-generated method stub
return null;
***REMOVED***
public static void main(String[] args) throws IOException, InterruptedException {
RestPoolManager a = new RestPoolManager();
***REMOVED***System.out.println(System.getProperty("user.home")+File.separator+"/gcube/dataminer-pool-manager");
***REMOVED***ProxySelector.setDefault(new PropertiesBasedProxySelector("/home/ngalante/.proxy-settings"));
ScopeProvider.instance.set("/gcube/devNext/NextNext");
***REMOVED*** a.addAlgorithmToVRE(
***REMOVED*** "http:***REMOVED***data.d4science.org/S2h1RHZGd0JpWnBjZk9qTytQTndqcDRLVHNrQUt6QjhHbWJQNStIS0N6Yz0",
***REMOVED*** "/gcube/devNext/NextNext",
***REMOVED*** null, null, "test", "transducerers", "N");
a.addAlgorithmToHost(
"http:***REMOVED***data.d4science.org/S2h1RHZGd0JpWnBjZk9qTytQTndqcDRLVHNrQUt6QjhHbWJQNStIS0N6Yz0",
"dataminer1-devnext.d4science.org",
null, null, "test", "transducerers", "N");
***REMOVED***System.out.println(a.getLogById("34ac474d-b9df-4929-87e1-2a0ae26cf898"));
***REMOVED***
@Override
public void getLogId(Algorithm algo, String vre) {
***REMOVED*** TODO Auto-generated method stub
***REMOVED***
@Override
public String getScriptFromURL(URL logId) throws IOException {
***REMOVED*** TODO Auto-generated method stub
return null;
***REMOVED***
@Override
public String addAlgorithmToVRE(Algorithm algo, String vre) throws IOException, InterruptedException {
***REMOVED*** TODO Auto-generated method stub
return null;
***REMOVED***
@Override
public String addAlgorithmToHost(Algorithm algo, String hostname)
throws IOException, InterruptedException {
***REMOVED*** TODO Auto-generated method stub
return null;
***REMOVED***
@Override
public URL getURLfromWorkerLog(String logUrl) throws MalformedURLException, UnknownHostException {
***REMOVED*** TODO Auto-generated method stub
return null;
***REMOVED***
***REMOVED***