refactoring
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-analysis/dataminer-pool-manager@148420 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
c546a46269
commit
f8959752cc
34
.classpath
34
.classpath
|
@ -1,34 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
|
||||
<classpathentry kind="lib" path="/home/ngalante/Downloads/servlet-api-2.5.jar"/>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
42
.project
42
.project
|
@ -1,42 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>dataminer-pool-manager</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.wst.jsdt.core.javascriptValidator</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.wst.common.project.facet.core.builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.wst.validation.validationbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
|
||||
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
|
||||
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
|
@ -116,9 +116,32 @@ public class AnsibleWorker {
|
|||
// Serialize role in the workdir
|
||||
AnsibleSerializeHelper.serializeRole(r, this.getRolesDir());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public int execute(PrintStream ps)
|
||||
throws IOException, InterruptedException, SVNException {
|
||||
|
||||
System.out.println(this.getWorkdir());
|
||||
try {
|
||||
Process p = Runtime.getRuntime().exec("ansible-playbook -v -i " + this.getInventoryFile().getAbsolutePath()
|
||||
+ " " + this.getPlaybookFile().getAbsolutePath());
|
||||
|
||||
inheritIO(p.getInputStream(), ps);
|
||||
inheritIO(p.getErrorStream(), ps);
|
||||
|
||||
|
||||
return p.waitFor();
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void apply(AlgorithmSet as, PrintStream ps, boolean test)
|
||||
throws IOException, InterruptedException, SVNException {
|
||||
// TODO execute the playbook and return output
|
||||
|
|
|
@ -89,9 +89,55 @@ public class AnsibleBridge {
|
|||
|
||||
|
||||
|
||||
public AnsibleWorker createWorker() {
|
||||
public AnsibleWorker createWorker(Algorithm algorithm, Cluster dataminerCluster, boolean includeAlgorithmDependencies, String user) throws IOException {
|
||||
File workerRoot = new File(this.getWorkDir(), UUID.randomUUID().toString());
|
||||
AnsibleWorker worker = new AnsibleWorker(workerRoot);
|
||||
|
||||
List<Role> algoRoles = new Vector<>();
|
||||
|
||||
// add algorithms and dependencies to the worker
|
||||
for (Role r : this.generateRoles(algorithm)) {
|
||||
algoRoles.add(r);
|
||||
worker.addRole(r);
|
||||
}
|
||||
|
||||
//to comment the for in case of just install algo
|
||||
if(includeAlgorithmDependencies){
|
||||
for (Dependency d : algorithm.getDependencies()) {
|
||||
for (Role r : this.generateRoles(d)) {
|
||||
worker.addRole(r);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// add static roles
|
||||
for(Role r:this.getStaticRoleManager().getStaticRoles()) {
|
||||
worker.addRole(r);
|
||||
}
|
||||
|
||||
// generate the inventory
|
||||
Inventory inventory = new Inventory();
|
||||
for (Host h : dataminerCluster.getHosts()) {
|
||||
AnsibleHost ah = new AnsibleHost(h.getName());
|
||||
inventory.addHost(ah, "universe");
|
||||
inventory.addHost(ah, "d4science");
|
||||
}
|
||||
worker.setInventory(inventory);
|
||||
|
||||
// generate the playbook
|
||||
Playbook playbook = new Playbook();
|
||||
playbook.setRemote_user(user);
|
||||
playbook.applyTo("universe");
|
||||
for(Role r:algoRoles) {
|
||||
// add only 'add' roles
|
||||
if(!r.getName().endsWith("remove")) {
|
||||
playbook.addRole(r.getName());
|
||||
}
|
||||
}
|
||||
|
||||
worker.setPlaybook(playbook);
|
||||
|
||||
return worker;
|
||||
}
|
||||
|
||||
|
|
|
@ -42,7 +42,12 @@ public interface PoolManager {
|
|||
|
||||
String addAlgorithmToVRE(Algorithm algo, String vre, boolean test ) throws IOException, InterruptedException;
|
||||
String addAlgorithmToHost(Algorithm algo, String host,boolean test) throws IOException, InterruptedException;
|
||||
|
||||
|
||||
|
||||
String stageAlgorithm(String algorithmPackageURL) throws IOException, InterruptedException;
|
||||
String publishAlgorithm(String algorithmPackageURL, String targetVREToken) throws IOException, InterruptedException;
|
||||
|
||||
|
||||
Algorithm extractAlgorithm(String url) throws IOException;
|
||||
|
||||
String getLogById(String logId) throws IOException;
|
||||
|
|
|
@ -1,281 +1,52 @@
|
|||
//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.awt.color.ICC_ColorSpace;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.ProxySelector;
|
||||
import java.net.URL;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
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;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
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;
|
||||
import org.gcube.dataanalysis.dataminer.poolmanager.util.AlgorithmBuilder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.tmatesoft.svn.core.SVNException;
|
||||
|
||||
import ch.qos.logback.core.subst.Token;
|
||||
import javax.ws.rs.*;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@Path("/")
|
||||
public class RestPoolManager implements PoolManager {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(RestPoolManager.class);
|
||||
|
||||
private PoolManager service = new DataminerPoolManager();
|
||||
private DataminerPoolManager service = new DataminerPoolManager();
|
||||
|
||||
|
||||
@GET
|
||||
@Path("/algorithm/stage")
|
||||
@Produces("text/plain")
|
||||
public String stageAlgorithm(String algorithmPackageURL) throws IOException, InterruptedException {
|
||||
Algorithm algo = AlgorithmBuilder.create(algorithmPackageURL);
|
||||
return this.service.stageAlgorithm(algo);
|
||||
}
|
||||
|
||||
|
||||
@GET
|
||||
@Path("/algorithm/add")
|
||||
@Produces("text/plain")
|
||||
public String publishAlgorithm(String algorithmPackageURL, String targetVREToken) throws IOException, InterruptedException {
|
||||
Algorithm algo = AlgorithmBuilder.create(algorithmPackageURL);
|
||||
return this.service.publishAlgorithm(algo, targetVREToken);
|
||||
}
|
||||
|
||||
/*
|
||||
* /scopes/<scope> POST // add an algorithm to all dataminers in the scope
|
||||
* /hosts/<hostname> POST // 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);
|
||||
// publish algo
|
||||
if (publish) {
|
||||
service.addAlgToIs(algo);
|
||||
}
|
||||
return service.addAlgorithmToVRE(algo, ScopeProvider.instance.get(),/*updateSVN,*/false);
|
||||
}
|
||||
|
||||
//Test Phase
|
||||
//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);
|
||||
|
||||
//test phase
|
||||
if(test){
|
||||
service.addAlgorithmToHost(algo, hostname,true);
|
||||
id = service.addAlgorithmToVRE(algo, ScopeProvider.instance.get(),true);
|
||||
}
|
||||
//release phase
|
||||
if(!test){
|
||||
SecurityTokenProvider.instance.set(prodtoken);
|
||||
id = service.addAlgorithmToVRE(algo, ScopeProvider.instance.get(),false);
|
||||
}
|
||||
|
||||
return id;
|
||||
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
} else
|
||||
algo.setCategory(algo.getCategory());
|
||||
|
||||
if (algo.getAlgorithmType() == null) {
|
||||
algo.setAlgorithmType(algorithmType);
|
||||
} else
|
||||
algo.setAlgorithmType(algo.getCategory());
|
||||
|
||||
if (algo.getSkipJava() == null) {
|
||||
algo.setSkipJava(skipJava);
|
||||
} else
|
||||
algo.setSkipJava(algo.getSkipJava());
|
||||
|
||||
if (algo.getName() == null) {
|
||||
algo.setName(name);
|
||||
} else
|
||||
algo.setName(algo.getName());
|
||||
|
||||
if (algo.getDescription() == null) {
|
||||
algo.setDescription(description);
|
||||
;
|
||||
} else
|
||||
algo.setDescription(algo.getDescription());
|
||||
|
||||
return algo;
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/log")
|
||||
@Produces("text/plain")
|
||||
|
@ -304,40 +75,6 @@ public class RestPoolManager implements PoolManager {
|
|||
// System.out.println(aa.getAlgoById("ICHTHYOP_MODEL_ONE_BY_ONE@3141d3aa-5f93-409f-b6f8-9fae0a6c0ee3"));
|
||||
// System.out.println(aa.getAlgoFromIs());
|
||||
|
||||
|
||||
RestPoolManager a = new RestPoolManager();
|
||||
a.addAlgorithmToVRE(
|
||||
"http://data.d4science.org/TVc0TW9Ud1FjYlppK0NHd2pvU0owNmRFWHE4OW4xSGNHbWJQNStIS0N6Yz0",
|
||||
"test",
|
||||
null,
|
||||
null,
|
||||
"N",
|
||||
"transducerers",
|
||||
false,
|
||||
false);
|
||||
|
||||
// a.addAlgorithmToHost(
|
||||
// "http://data.d4science.org/MnovRjZIdGV5WlB0WXE5NVNaZnRoRVg0SU8xZWpWQlFHbWJQNStIS0N6Yz0",
|
||||
// "dataminer1-pre.d4science.org",
|
||||
// "ICHTHYOP_MODEL_ONE_BY_ONE", null, "ICHTHYOP_MODEL", "transducerers",
|
||||
// "N",false, false);
|
||||
RestPoolManager b = new RestPoolManager();
|
||||
|
||||
b.addAlgorithmToStagingHost(
|
||||
"http://data.d4science.org/TVc0TW9Ud1FjYlppK0NHd2pvU0owNmRFWHE4OW4xSGNHbWJQNStIS0N6Yz0",
|
||||
"dataminer1-devnext.d4science.org",
|
||||
null,
|
||||
null,
|
||||
"N",
|
||||
"transducerers",
|
||||
false,
|
||||
false
|
||||
// PoolManager aa = new DataminerPoolManager();
|
||||
// List<String> ls = new LinkedList<String>();
|
||||
// String afa = "test";
|
||||
// ls.add(afa);
|
||||
//
|
||||
// System.out.println(aa.updateSVN("r_deb_pkgs.txt", ls));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,68 +1,142 @@
|
|||
package org.gcube.dataanalysis.dataminer.poolmanager.service;
|
||||
|
||||
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.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.StringWriter;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.net.UnknownHostException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.resources.gcore.GenericResource;
|
||||
import org.gcube.common.resources.gcore.HostingNode;
|
||||
import org.gcube.common.resources.gcore.Resources;
|
||||
import org.gcube.common.resources.gcore.Software.Profile.Dependency;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.dataanalysis.dataminer.poolmanager.ansible.AnsibleWorker;
|
||||
import org.gcube.dataanalysis.dataminer.poolmanager.ansiblebridge.AnsibleBridge;
|
||||
import org.gcube.dataanalysis.dataminer.poolmanager.clients.HAProxy;
|
||||
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.Cluster;
|
||||
import org.gcube.dataanalysis.dataminer.poolmanager.datamodel.Host;
|
||||
import org.gcube.dataanalysis.dataminer.poolmanager.process.AlgorithmPackageParser;
|
||||
import org.gcube.dataanalysis.dataminer.poolmanager.rest.PoolManager;
|
||||
import org.gcube.dataanalysis.dataminer.poolmanager.datamodel.*;
|
||||
import org.gcube.informationsystem.publisher.AdvancedScopedPublisher;
|
||||
import org.gcube.informationsystem.publisher.RegistryPublisherFactory;
|
||||
import org.gcube.informationsystem.publisher.ScopedPublisher;
|
||||
import org.gcube.informationsystem.publisher.exception.RegistryNotFoundException;
|
||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.tmatesoft.svn.core.SVNCommitInfo;
|
||||
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.wc.SVNFileUtil;
|
||||
import org.tmatesoft.svn.core.internal.wc.admin.SVNChecksumInputStream;
|
||||
import org.tmatesoft.svn.core.io.ISVNEditor;
|
||||
import org.tmatesoft.svn.core.io.SVNRepository;
|
||||
import org.tmatesoft.svn.core.io.SVNRepositoryFactory;
|
||||
import org.tmatesoft.svn.core.io.diff.SVNDeltaGenerator;
|
||||
import org.tmatesoft.svn.core.wc.SVNWCUtil;
|
||||
|
||||
public class DataminerPoolManager implements PoolManager {
|
||||
import java.io.*;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.*;
|
||||
|
||||
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
|
||||
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
|
||||
|
||||
public class DataminerPoolManager {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(DataminerPoolManager.class);
|
||||
|
||||
|
||||
public String stageAlgorithm(Algorithm algo) throws IOException, InterruptedException {
|
||||
|
||||
Cluster cluster = new Cluster();
|
||||
Host h = new Host();
|
||||
h.setName(getStagingDataminerHostname());
|
||||
cluster.addHost(h);
|
||||
|
||||
//Assumes the service is running in RPrototypingLab
|
||||
String token = SecurityTokenProvider.instance.get();
|
||||
|
||||
return addAlgorithmToCluster(algo, cluster, true, "root", true, token);
|
||||
}
|
||||
|
||||
public String publishAlgorithm(Algorithm algo, String targetVREToken) throws IOException, InterruptedException {
|
||||
Cluster cluster = new Cluster();
|
||||
for (Host h : new HAProxy().listDataMinersByCluster()) {
|
||||
cluster.addHost(h);
|
||||
}
|
||||
return addAlgorithmToCluster(algo, cluster, false, "gcube", false, targetVREToken);
|
||||
|
||||
}
|
||||
|
||||
|
||||
private String getStagingDataminerHostname(){
|
||||
return null;
|
||||
}
|
||||
|
||||
private void updateSVNDependencies(Algorithm algo, boolean stagingVRE) throws IOException, SVNException {
|
||||
for (Dependency d : algo.getDependencies()) {
|
||||
|
||||
if (d.getType().equals("os")) {
|
||||
List<String> ls = new LinkedList<String>();
|
||||
ls.add(d.getName());
|
||||
this.updateSVN(stagingVRE ? "test_": "" + "r_deb_pkgs.txt", ls);
|
||||
}
|
||||
if (d.getType().equals("cran")) {
|
||||
List<String> ls = new LinkedList<String>();
|
||||
ls.add(d.getName());
|
||||
this.updateSVN(stagingVRE ? "test_": "" + "r_cran_pkgs.txt", ls);
|
||||
}
|
||||
if (d.getType().equals("github")) {
|
||||
List<String> ls = new LinkedList<String>();
|
||||
ls.add(d.getName());
|
||||
this.updateSVN(stagingVRE ? "test_": "" + "r_github_pkgs.txt", ls);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void createISResource(Algorithm algo, String vreToken){
|
||||
//TODO: implement method
|
||||
|
||||
//TODO: create the resource only if not already present
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param algo
|
||||
* @param dataminerCluster
|
||||
* @return uuid of the execution
|
||||
*/
|
||||
public String addAlgorithmToCluster(
|
||||
final Algorithm algo,
|
||||
Cluster dataminerCluster,
|
||||
boolean includeAlgorithmDependencies,
|
||||
String user,
|
||||
final boolean stagingVRE,
|
||||
final String targetVREToken) throws IOException {
|
||||
|
||||
AnsibleBridge ansibleBridge = new AnsibleBridge();
|
||||
final AnsibleWorker worker = ansibleBridge.createWorker(algo, dataminerCluster, includeAlgorithmDependencies, user);
|
||||
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
File path = new File(worker.getWorkdir() + File.separator + "logs");
|
||||
path.mkdirs();
|
||||
File n = new File(path + File.separator + worker.getWorkerId());
|
||||
FileOutputStream fos = new FileOutputStream(n);
|
||||
PrintStream ps = new PrintStream(fos);
|
||||
int retValue = worker.execute(ps);
|
||||
System.out.println("Log stored to to " + n.getAbsolutePath());
|
||||
|
||||
if(retValue == 0) {
|
||||
updateSVNDependencies(algo, stagingVRE);
|
||||
createISResource(algo, targetVREToken);
|
||||
}
|
||||
// destroy the worker
|
||||
worker.destroy();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
|
||||
// this line will execute immediately, not waiting for task to
|
||||
// complete
|
||||
return worker.getWorkerId();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String getScriptFromURL(URL url) throws IOException {
|
||||
if (url == null) {
|
||||
|
@ -152,6 +226,7 @@ public class DataminerPoolManager implements PoolManager {
|
|||
return uuid;
|
||||
}
|
||||
|
||||
|
||||
public URL getURLfromWorkerLog(String a) throws MalformedURLException, UnknownHostException {
|
||||
|
||||
File path = new File(System.getProperty("user.home") + File.separator + "dataminer-pool-manager/work/"
|
||||
|
@ -209,23 +284,7 @@ public class DataminerPoolManager implements PoolManager {
|
|||
return a.applyAlgorithmSetToCluster(algorithms, cluster, uuid, /*updateSVN,*/test).getWorkerId();
|
||||
|
||||
}
|
||||
|
||||
|
||||
public Algorithm extractAlgorithm(String url) throws IOException {
|
||||
return new AlgorithmPackageParser().parsePackage(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getLogId(Algorithm algo, String vre) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLogById(String logId) throws IOException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
// 2017 March 29
|
||||
|
||||
|
@ -256,7 +315,6 @@ public class DataminerPoolManager implements PoolManager {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAlgToIs(Algorithm algo) {
|
||||
GenericResource a = new GenericResource();
|
||||
a.newProfile().name(algo.getName()).type("StatisticalManagerAlgorithm").description(algo.getDescription());
|
||||
|
@ -317,16 +375,6 @@ public class DataminerPoolManager implements PoolManager {
|
|||
return out;
|
||||
}
|
||||
|
||||
// public Algorithm getAlgoById(String id) {
|
||||
// for (Algorithm aa : this.getAlgoFromIs()) {
|
||||
// if (aa.getId().equals(id)) {
|
||||
// return aa;
|
||||
// }
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
|
||||
@Override
|
||||
public Set<Algorithm> getAlgoFromIs() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
@ -343,8 +391,6 @@ public class DataminerPoolManager implements PoolManager {
|
|||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public List<String> updateSVN(String file, List<String> ldep) throws SVNException, IOException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
package org.gcube.dataanalysis.dataminer.poolmanager.util;
|
||||
|
||||
import org.gcube.dataanalysis.dataminer.poolmanager.datamodel.Algorithm;
|
||||
import org.gcube.dataanalysis.dataminer.poolmanager.process.AlgorithmPackageParser;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Created by ggiammat on 5/9/17.
|
||||
*/
|
||||
public class AlgorithmBuilder {
|
||||
|
||||
|
||||
public static Algorithm create(String algorithmPackageURL) throws IOException, InterruptedException {
|
||||
return create(algorithmPackageURL, null, null, null, null, null, null, null);
|
||||
}
|
||||
|
||||
public static Algorithm create(String algorithmPackageURL, String vre, String hostname, String name, String description,
|
||||
String category, String algorithmType, String skipJava) throws IOException, InterruptedException {
|
||||
Algorithm algo = new AlgorithmPackageParser().parsePackage(algorithmPackageURL);
|
||||
|
||||
|
||||
if(category != null){
|
||||
algo.setCategory(category);
|
||||
}
|
||||
|
||||
//FIXME: do the same done for category
|
||||
if (algo.getAlgorithmType() == null) {
|
||||
algo.setAlgorithmType(algorithmType);
|
||||
} else
|
||||
algo.setAlgorithmType(algo.getCategory());
|
||||
|
||||
if (algo.getSkipJava() == null) {
|
||||
algo.setSkipJava(skipJava);
|
||||
} else
|
||||
algo.setSkipJava(algo.getSkipJava());
|
||||
|
||||
if (algo.getName() == null) {
|
||||
algo.setName(name);
|
||||
} else
|
||||
algo.setName(algo.getName());
|
||||
|
||||
if (algo.getDescription() == null) {
|
||||
algo.setDescription(description);
|
||||
;
|
||||
} else
|
||||
algo.setDescription(algo.getDescription());
|
||||
|
||||
return algo;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue