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

412 lines
14 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;
import java.awt.color.ICC_ColorSpace;
***REMOVED***
import java.net.MalformedURLException;
import java.net.ProxySelector;
***REMOVED***
import java.net.UnknownHostException;
***REMOVED***
***REMOVED***
import java.util.Random;
import java.util.Set;
import java.util.UUID;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import org.apache.commons.lang.math.RandomUtils;
***REMOVED***
***REMOVED***
import org.gcube.dataanalysis.dataminer.poolmanager.clients.ISClient;
import org.gcube.dataanalysis.dataminer.poolmanager.datamodel.Algorithm;
import org.gcube.dataanalysis.dataminer.poolmanager.datamodel.AlgorithmSet;
import org.gcube.dataanalysis.dataminer.poolmanager.datamodel.Dependency;
import org.gcube.dataanalysis.dataminer.poolmanager.service.DataminerPoolManager;
import org.gcube.dataanalysis.dataminer.poolmanager.util.PropertiesBasedProxySelector;
***REMOVED***
***REMOVED***
import org.tmatesoft.svn.core.SVNException;
import ch.qos.logback.core.subst.Token;
@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("name") String name,
@QueryParam("description") String description,
@QueryParam("category") String category,
@DefaultValue("transducerers") @QueryParam("algorithmType") String algorithmType,
@DefaultValue("N") @QueryParam("skipJava") String skipJava,
@DefaultValue("false") @QueryParam("publish") boolean publish,
@DefaultValue("false") @QueryParam("updateSVN") boolean updateSVN)
throws IOException, InterruptedException, SVNException {
Algorithm algo = this.getAlgorithm(algorithm, /*vre*/null, null, name, description, category, algorithmType, skipJava);
***REMOVED*** publish algo
if (publish) {
service.addAlgToIs(algo);
***REMOVED***
return service.addAlgorithmToVRE(algo, ScopeProvider.instance.get(),/*updateSVN,*/false);
***REMOVED***
***REMOVED***Test Phase
***REMOVED***The DMPM contacts the Staging Dataminer and installs the algorithm and the dependencies
@GET
@Path("/algo/add")
@Produces("text/plain")
public String addAlgorithmToStagingHost(
@QueryParam("algorithm") String algorithm,
@DefaultValue("insert hostname here") @QueryParam("hostname") String hostname,
@QueryParam("name") String name,
@QueryParam("description") String description,
@QueryParam("category") String category,
@DefaultValue("transducerers") @QueryParam("algorithmType") String algorithmType,
@DefaultValue("N") @QueryParam("skipJava") String skipJava,
@DefaultValue("prodtoken") @QueryParam("prodtoken") String prodtoken,
@DefaultValue("true") @QueryParam("test") boolean test)
throws IOException, InterruptedException, SVNException {
String id="";
Algorithm algo = this.getAlgorithm(algorithm, ScopeProvider.instance.get(), hostname, name, description, category, algorithmType,skipJava);
***REMOVED***test phase
if(test){
service.addAlgorithmToHost(algo, hostname,true);
id = service.addAlgorithmToVRE(algo, ScopeProvider.instance.get(),true);
***REMOVED***
***REMOVED***release phase
if(!test){
SecurityTokenProvider.instance.set(prodtoken);
id = service.addAlgorithmToVRE(algo, ScopeProvider.instance.get(),false);
***REMOVED***
return id;
***REMOVED***
private Algorithm getAlgorithm(String algorithm, String vre, String hostname, String name, String description,
String category, String algorithmType, String skipJava) throws IOException, InterruptedException {
Algorithm algo = service.extractAlgorithm(algorithm);
if (algo.getCategory() == null) {
algo.setCategory(category);
***REMOVED*** else
algo.setCategory(algo.getCategory());
if (algo.getAlgorithmType() == null) {
algo.setAlgorithmType(algorithmType);
***REMOVED*** else
algo.setAlgorithmType(algo.getCategory());
if (algo.getSkipJava() == null) {
algo.setSkipJava(skipJava);
***REMOVED*** else
algo.setSkipJava(algo.getSkipJava());
if (algo.getName() == null) {
algo.setName(name);
***REMOVED*** else
algo.setName(algo.getName());
if (algo.getDescription() == null) {
algo.setDescription(description);
;
***REMOVED*** else
algo.setDescription(algo.getDescription());
return algo;
***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, SVNException {
***REMOVED*** System.out.println(System.getProperty("user.home")+File.separator+"/gcube/dataminer-pool-manager");
***REMOVED*** ProxySelector.setDefault(new
***REMOVED*** PropertiesBasedProxySelector("/home/ngalante/.proxy-settings"));
***REMOVED***ScopeProvider.instance.set("/d4science.research-infrastructures.eu/gCubeApps/RPrototypingLab");
SecurityTokenProvider.instance.set("3a23bfa4-4dfe-44fc-988f-194b91071dd2-843339462");
***REMOVED*** PoolManager aa = new DataminerPoolManager();
***REMOVED*** System.out.println(aa.getAlgoById("ICHTHYOP_MODEL_ONE_BY_ONE@3141d3aa-5f93-409f-b6f8-9fae0a6c0ee3"));
***REMOVED*** System.out.println(aa.getAlgoFromIs());
RestPoolManager a = new RestPoolManager();
a.addAlgorithmToVRE(
"http:***REMOVED***data.d4science.org/TVc0TW9Ud1FjYlppK0NHd2pvU0owNmRFWHE4OW4xSGNHbWJQNStIS0N6Yz0",
"test",
null,
null,
"N",
"transducerers",
false,
false);
***REMOVED*** a.addAlgorithmToHost(
***REMOVED*** "http:***REMOVED***data.d4science.org/MnovRjZIdGV5WlB0WXE5NVNaZnRoRVg0SU8xZWpWQlFHbWJQNStIS0N6Yz0",
***REMOVED*** "dataminer1-pre.d4science.org",
***REMOVED*** "ICHTHYOP_MODEL_ONE_BY_ONE", null, "ICHTHYOP_MODEL", "transducerers",
***REMOVED*** "N",false, false);
RestPoolManager b = new RestPoolManager();
b.addAlgorithmToStagingHost(
"http:***REMOVED***data.d4science.org/TVc0TW9Ud1FjYlppK0NHd2pvU0owNmRFWHE4OW4xSGNHbWJQNStIS0N6Yz0",
"dataminer1-devnext.d4science.org",
null,
null,
"N",
"transducerers",
false,
false
***REMOVED*** PoolManager aa = new DataminerPoolManager();
***REMOVED*** List<String> ls = new LinkedList<String>();
***REMOVED*** String afa = "test";
***REMOVED*** ls.add(afa);
***REMOVED***
***REMOVED*** System.out.println(aa.updateSVN("r_deb_pkgs.txt", ls));
***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 URL getURLfromWorkerLog(String logUrl) throws MalformedURLException, UnknownHostException {
***REMOVED*** TODO Auto-generated method stub
return null;
***REMOVED***
@Override
public void addAlgToIs(Algorithm algo) {
***REMOVED*** TODO Auto-generated method stub
***REMOVED***
@Override
public Set<Algorithm> getAlgoFromIs() {
***REMOVED*** TODO Auto-generated method stub
return null;
***REMOVED***
@Override
public List<String> updateSVN(String file, List<String> ldep) throws SVNException {
***REMOVED*** TODO Auto-generated method stub
return null;
***REMOVED***
@Override
public String addAlgorithmToHost(Algorithm algo, String host, boolean test)
throws IOException, InterruptedException {
***REMOVED*** TODO Auto-generated method stub
return null;
***REMOVED***
@Override
public String addAlgorithmToVRE(Algorithm algo, String vre, boolean test)
throws IOException, InterruptedException {
***REMOVED*** TODO Auto-generated method stub
return null;
***REMOVED***
***REMOVED***