git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-analysis/dataminer-pool-manager@148412 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
67951c80e5
commit
c546a46269
|
@ -24,6 +24,7 @@ import org.gcube.dataanalysis.dataminer.poolmanager.ansiblebridge.AnsibleSeriali
|
|||
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.tmatesoft.svn.core.SVNException;
|
||||
import org.tmatesoft.svn.core.SVNURL;
|
||||
import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager;
|
||||
|
@ -118,7 +119,7 @@ public class AnsibleWorker {
|
|||
|
||||
|
||||
|
||||
public void apply(AlgorithmSet as, PrintStream ps, boolean updateSVN)
|
||||
public void apply(AlgorithmSet as, PrintStream ps, boolean test)
|
||||
throws IOException, InterruptedException, SVNException {
|
||||
// TODO execute the playbook and return output
|
||||
System.out.println(this.getWorkdir());
|
||||
|
@ -128,43 +129,70 @@ public class AnsibleWorker {
|
|||
|
||||
inheritIO(p.getInputStream(), ps);
|
||||
inheritIO(p.getErrorStream(), ps);
|
||||
|
||||
if (updateSVN) {
|
||||
int exitValue = p.waitFor();
|
||||
if (exitValue == 0) {
|
||||
|
||||
|
||||
|
||||
int exitValue = p.waitFor();
|
||||
if (exitValue == 0) {
|
||||
if (test) {
|
||||
for (Algorithm algo : as.getAlgorithms()) {
|
||||
|
||||
|
||||
for (Dependency d : algo.getDependencies()) {
|
||||
|
||||
if (d.getType().equals("os")) {
|
||||
List<String> ls = new LinkedList<String>();
|
||||
ls.add(d.getName());
|
||||
this.updateSVN("r_deb_pkgs.txt", ls);
|
||||
this.updateSVN("test_r_deb_pkgs.txt", ls);
|
||||
}
|
||||
if (d.getType().equals("cran")) {
|
||||
List<String> ls = new LinkedList<String>();
|
||||
ls.add(d.getName());
|
||||
this.updateSVN("r_cran_pkgs.txt", ls);
|
||||
this.updateSVN("test_r_cran_pkgs.txt", ls);
|
||||
}
|
||||
if (d.getType().equals("github")) {
|
||||
List<String> ls = new LinkedList<String>();
|
||||
ls.add(d.getName());
|
||||
this.updateSVN("r_github_pkgs.txt", ls);
|
||||
this.updateSVN("test_r_github_pkgs.txt", ls);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else if(!test){
|
||||
for (Algorithm algo : as.getAlgorithms()) {
|
||||
|
||||
for (Dependency d : algo.getDependencies()) {
|
||||
|
||||
if (d.getType().equals("os")) {
|
||||
List<String> ls = new LinkedList<String>();
|
||||
ls.add(d.getName());
|
||||
this.updateSVN("r_deb_pkgs.txt", ls);
|
||||
}
|
||||
if (d.getType().equals("cran")) {
|
||||
List<String> ls = new LinkedList<String>();
|
||||
ls.add(d.getName());
|
||||
this.updateSVN("r_cran_pkgs.txt", ls);
|
||||
}
|
||||
if (d.getType().equals("github")) {
|
||||
List<String> ls = new LinkedList<String>();
|
||||
ls.add(d.getName());
|
||||
this.updateSVN("r_github_pkgs.txt", ls);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
for (Algorithm algo : as.getAlgorithms()) {
|
||||
DataminerPoolManager a = new DataminerPoolManager();
|
||||
a.addAlgToIs(algo);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// System.out.println("TODO: execute: ansible-playbook -v -i " +
|
||||
// this.getInventoryFile().getName() + " " +
|
||||
// this.getPlaybookFile().getName());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -158,13 +158,13 @@ public class AnsibleBridge {
|
|||
}
|
||||
}
|
||||
|
||||
public AnsibleWorker applyAlgorithmSetToCluster(AlgorithmSet as, Cluster cluster, boolean updateSVN) throws IOException, InterruptedException, SVNException {
|
||||
public AnsibleWorker applyAlgorithmSetToCluster(AlgorithmSet as, Cluster cluster, /*boolean updateSVN,*/ boolean test) throws IOException, InterruptedException, SVNException {
|
||||
|
||||
|
||||
return applyAlgorithmSetToCluster (as,cluster,UUID.randomUUID().toString(),updateSVN);
|
||||
return applyAlgorithmSetToCluster (as,cluster,UUID.randomUUID().toString(),/*updateSVN,*/ test);
|
||||
}
|
||||
|
||||
public AnsibleWorker applyAlgorithmSetToCluster(AlgorithmSet as, Cluster cluster,String uuid, boolean updateSVN) throws IOException, InterruptedException, SVNException {
|
||||
public AnsibleWorker applyAlgorithmSetToCluster(AlgorithmSet as, Cluster cluster,String uuid, /*boolean updateSVN,*/ boolean test) throws IOException, InterruptedException, SVNException {
|
||||
AnsibleWorker worker = new AnsibleWorker(new File(this.getWorkDir(), uuid));
|
||||
|
||||
|
||||
|
@ -176,11 +176,14 @@ public class AnsibleBridge {
|
|||
algoRoles.add(r);
|
||||
worker.addRole(r);
|
||||
}
|
||||
//to comment the for in case of just install algo
|
||||
if(test){
|
||||
for (Dependency d : a.getDependencies()) {
|
||||
for (Role r : this.generateRoles(d)) {
|
||||
worker.addRole(r);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// add static roles
|
||||
|
@ -199,7 +202,9 @@ public class AnsibleBridge {
|
|||
|
||||
// generate the playbook
|
||||
Playbook playbook = new Playbook();
|
||||
playbook.setRemote_user("root");
|
||||
if(test){
|
||||
playbook.setRemote_user("root");}
|
||||
playbook.setRemote_user("gcube");
|
||||
playbook.applyTo("universe");
|
||||
for(Role r:algoRoles) {
|
||||
// add only 'add' roles
|
||||
|
@ -220,7 +225,7 @@ public class AnsibleBridge {
|
|||
|
||||
//System.setErr(console);
|
||||
|
||||
worker.apply(as,ps,updateSVN);
|
||||
worker.apply(as,ps,test);
|
||||
//System.setOut(console);
|
||||
//worker.apply();
|
||||
System.out.println("Log stored to to " + n.getAbsolutePath());
|
||||
|
|
|
@ -72,6 +72,7 @@ public class ISClient {
|
|||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
|
||||
// return the HProxy hostname in the VRE
|
||||
public static String getHProxy() {
|
||||
|
|
|
@ -35,12 +35,13 @@ import java.util.List;
|
|||
import java.util.Set;
|
||||
|
||||
import org.gcube.dataanalysis.dataminer.poolmanager.datamodel.Algorithm;
|
||||
import org.gcube.dataanalysis.dataminer.poolmanager.datamodel.AlgorithmSet;
|
||||
import org.tmatesoft.svn.core.SVNException;
|
||||
|
||||
public interface PoolManager {
|
||||
|
||||
String addAlgorithmToVRE(Algorithm algo, String vre, boolean svn ) throws IOException, InterruptedException;
|
||||
String addAlgorithmToHost(Algorithm algo, String host, boolean svn) throws IOException, InterruptedException;
|
||||
String addAlgorithmToVRE(Algorithm algo, String vre, boolean test ) throws IOException, InterruptedException;
|
||||
String addAlgorithmToHost(Algorithm algo, String host,boolean test) throws IOException, InterruptedException;
|
||||
|
||||
Algorithm extractAlgorithm(String url) throws IOException;
|
||||
|
||||
|
@ -57,5 +58,5 @@ public interface PoolManager {
|
|||
Set<Algorithm> getAlgoFromIs();
|
||||
List<String> updateSVN(String file, List<String> ldep) throws SVNException, IOException;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -161,9 +161,11 @@ 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;
|
||||
|
@ -171,6 +173,8 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
import org.tmatesoft.svn.core.SVNException;
|
||||
|
||||
import ch.qos.logback.core.subst.Token;
|
||||
|
||||
@Path("/")
|
||||
public class RestPoolManager implements PoolManager {
|
||||
|
||||
|
@ -201,37 +205,46 @@ public class RestPoolManager implements PoolManager {
|
|||
if (publish) {
|
||||
service.addAlgToIs(algo);
|
||||
}
|
||||
return service.addAlgorithmToVRE(algo, ScopeProvider.instance.get(),updateSVN);
|
||||
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("/hosts/add")
|
||||
@Path("/algo/add")
|
||||
@Produces("text/plain")
|
||||
public String addAlgorithmToHost(
|
||||
@QueryParam("algorithm") String algorithm,
|
||||
@QueryParam("hostname") String hostname,
|
||||
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("false") @QueryParam("publish") boolean publish,
|
||||
@DefaultValue("false") @QueryParam("updateSVN") boolean updateSVN)
|
||||
@DefaultValue("prodtoken") @QueryParam("prodtoken") String prodtoken,
|
||||
@DefaultValue("true") @QueryParam("test") boolean test)
|
||||
throws IOException, InterruptedException, SVNException {
|
||||
Algorithm algo = this.getAlgorithm(algorithm, null, hostname, name, description, category, algorithmType,
|
||||
skipJava);
|
||||
// publish algo
|
||||
if (publish) {
|
||||
service.addAlgToIs(algo);
|
||||
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);
|
||||
}
|
||||
return service.addAlgorithmToHost(algo, hostname,updateSVN);
|
||||
//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 {
|
||||
LOGGER.debug("Adding algorithm =" + algorithm + " to VRE =" + ScopeProvider.instance.get());
|
||||
Algorithm algo = service.extractAlgorithm(algorithm);
|
||||
|
||||
if (algo.getCategory() == null) {
|
||||
|
@ -283,8 +296,10 @@ public class RestPoolManager implements PoolManager {
|
|||
// ProxySelector.setDefault(new
|
||||
// PropertiesBasedProxySelector("/home/ngalante/.proxy-settings"));
|
||||
|
||||
ScopeProvider.instance.set("/gcube/devNext/NextNext");
|
||||
|
||||
//ScopeProvider.instance.set("/d4science.research-infrastructures.eu/gCubeApps/RPrototypingLab");
|
||||
SecurityTokenProvider.instance.set("3a23bfa4-4dfe-44fc-988f-194b91071dd2-843339462");
|
||||
|
||||
|
||||
// PoolManager aa = new DataminerPoolManager();
|
||||
// System.out.println(aa.getAlgoById("ICHTHYOP_MODEL_ONE_BY_ONE@3141d3aa-5f93-409f-b6f8-9fae0a6c0ee3"));
|
||||
// System.out.println(aa.getAlgoFromIs());
|
||||
|
@ -306,9 +321,17 @@ public class RestPoolManager implements PoolManager {
|
|||
// "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";
|
||||
|
@ -357,21 +380,32 @@ public class RestPoolManager implements PoolManager {
|
|||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public String addAlgorithmToVRE(Algorithm algo, String vre, boolean svn) throws IOException, InterruptedException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public String addAlgorithmToHost(Algorithm algo, String host, boolean svn)
|
||||
public String addAlgorithmToHost(Algorithm algo, String host, boolean test)
|
||||
throws IOException, InterruptedException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String addAlgorithmToVRE(Algorithm algo, String vre, boolean test)
|
||||
throws IOException, InterruptedException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,265 +1,3 @@
|
|||
//package org.gcube.dataanalysis.dataminer.poolmanager.service;
|
||||
//
|
||||
//import java.io.BufferedReader;
|
||||
//import java.io.File;
|
||||
//import java.io.IOException;
|
||||
//import java.io.InputStreamReader;
|
||||
//import java.net.MalformedURLException;
|
||||
//import java.net.URL;
|
||||
//import java.net.URLConnection;
|
||||
//import java.net.UnknownHostException;
|
||||
//import java.util.UUID;
|
||||
//
|
||||
//import org.gcube.dataanalysis.dataminer.poolmanager.ansiblebridge.AnsibleBridge;
|
||||
//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.slf4j.Logger;
|
||||
//import org.slf4j.LoggerFactory;
|
||||
//
|
||||
//public class DataminerPoolManager implements PoolManager {
|
||||
//
|
||||
//
|
||||
// private static final Logger LOGGER = LoggerFactory.getLogger(DataminerPoolManager.class);
|
||||
//
|
||||
//
|
||||
//// static Collection<Algorithm> algorithms;
|
||||
////
|
||||
//// static Collection<AlgorithmSet> sets;
|
||||
////
|
||||
//// static {
|
||||
//// algorithms = new Vector<>();
|
||||
//// }
|
||||
////
|
||||
//// public DataminerPoolManager() {
|
||||
//// }
|
||||
////
|
||||
//// /**
|
||||
//// * Add a new algorithm to the set of known ones. No further action is expected
|
||||
//// * on the pool.
|
||||
//// */
|
||||
//// public void publishAlgorithm(Algorithm algorithm) {
|
||||
//// algorithms.add(algorithm);
|
||||
//// }
|
||||
////
|
||||
//// /**
|
||||
//// * Re-deploy the given algorithm wherever it's installed
|
||||
//// *
|
||||
//// * @param algorithm
|
||||
//// */
|
||||
//// /*
|
||||
//// * public void updateAlgorithm(Algorithm algorithm) { // TODO implement this }
|
||||
//// */
|
||||
////
|
||||
//// /**
|
||||
//// * Add the give algorithm to the given set
|
||||
//// *
|
||||
//// * @param algorithmId
|
||||
//// * @param setId
|
||||
//// */
|
||||
//// public void addAlgorithmToSet(String algorithmName, String setName) {
|
||||
//// AlgorithmSet set = this.getAlgorithmSet(setName);
|
||||
//// Algorithm algorithm = this.getAlgorithm(algorithmName);
|
||||
//// if (set != null && algorithm != null) {
|
||||
//// set.addAlgorithm(algorithm);
|
||||
//// this.updateClusters();
|
||||
//// }
|
||||
//// }
|
||||
////
|
||||
//// /**
|
||||
//// * Apply the given set of algorithms to the given cluster
|
||||
//// *
|
||||
//// * @param setId
|
||||
//// * @param clusterId
|
||||
//// */
|
||||
//// public void applyAlgorithmSetToCluster(String setName, String clusterName) {
|
||||
//// AlgorithmSet set = this.getAlgorithmSet(setName);
|
||||
//// Cluster cluster = new ISClient().getCluster(clusterName);
|
||||
//// if (set != null && cluster != null) {
|
||||
//// cluster.addAlgorithmSet(set);
|
||||
//// this.updateClusters();
|
||||
//// }
|
||||
//// }
|
||||
////
|
||||
//// private AlgorithmSet getAlgorithmSet(String name) {
|
||||
//// for (AlgorithmSet set : sets) {
|
||||
//// if (name.equals(set.getName())) {
|
||||
//// return set;
|
||||
//// }
|
||||
//// }
|
||||
//// return null;
|
||||
//// }
|
||||
////
|
||||
//// private Algorithm getAlgorithm(String name) {
|
||||
//// for (Algorithm a : algorithms) {
|
||||
//// if (name.equals(a.getName())) {
|
||||
//// return a;
|
||||
//// }
|
||||
//// }
|
||||
//// return null;
|
||||
//// }
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
////
|
||||
//// public void getLogId(final Algorithm algorithm, final String vre) {
|
||||
//// new Thread() {
|
||||
//// public void run() {
|
||||
//// while (true) {
|
||||
//// try {
|
||||
//// addAlgorithmToVRE(algorithm, vre);
|
||||
//// } catch (Exception e) {
|
||||
//// //log here
|
||||
//// }
|
||||
//// }
|
||||
//// }
|
||||
//// }.start();
|
||||
//// }
|
||||
////
|
||||
////
|
||||
//
|
||||
//// public String getLogId(){
|
||||
//// PrintStream console = System.out;
|
||||
//// 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);
|
||||
//// System.setOut(ps);
|
||||
//// worker.apply();
|
||||
//// System.setOut(console);
|
||||
//// worker.apply();
|
||||
//// System.out.println("Log stored to to " + n.getAbsolutePath());
|
||||
//// }
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//// public String getLogById(String id) throws IOException {
|
||||
//// String strLine = null;
|
||||
//// try{
|
||||
//// FileInputStream fstream = new FileInputStream("/tmp/dataminer-pool-manager/work/"+id+"/logs/"+id);
|
||||
//// BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
|
||||
//// /* read log line by line */
|
||||
//// while ((strLine = br.readLine()) != null) {
|
||||
//// /* parse strLine to obtain what you want */
|
||||
//// System.out.println (strLine);
|
||||
//// }
|
||||
//// br.close();
|
||||
//// } catch (Exception e) {
|
||||
//// System.err.println("Error: " + e.getMessage());
|
||||
//// }
|
||||
//// return strLine;
|
||||
//// }
|
||||
//
|
||||
//
|
||||
// public String getScriptFromURL(URL url) throws IOException {
|
||||
// if (url == null) {
|
||||
// return null;
|
||||
// }
|
||||
// URLConnection yc = url.openConnection();
|
||||
// BufferedReader input = new BufferedReader(new InputStreamReader(
|
||||
// yc.getInputStream()));
|
||||
// String line;
|
||||
// StringBuffer buffer = new StringBuffer();
|
||||
// while ((line = input.readLine()) != null) {
|
||||
// buffer.append(line + "\n");
|
||||
// }
|
||||
// String bufferScript = buffer.substring(0, buffer.length());
|
||||
// input.close();
|
||||
// return bufferScript;
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * Publish the given algorithm in the given VRE
|
||||
// *
|
||||
// * @param algorithmName
|
||||
// * @param vre
|
||||
// *
|
||||
// */
|
||||
// public String addAlgorithmToVRE(Algorithm algorithm, final String vre) throws IOException {
|
||||
// // create a fake algorithm set
|
||||
// final AlgorithmSet algoSet = new AlgorithmSet();
|
||||
// algoSet.setName("fake");
|
||||
// algoSet.addAlgorithm(algorithm);
|
||||
// final String uuid = UUID.randomUUID().toString();
|
||||
//
|
||||
// new Thread(new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// // TODO Auto-generated method stub
|
||||
// try {
|
||||
// addAlgorithmsToVRE(algoSet, vre, uuid);
|
||||
// } catch (IOException e) {
|
||||
// // TODO Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
// }).start();
|
||||
// //this line will execute immediately, not waiting for your task to complete
|
||||
// System.out.println(uuid);
|
||||
// return uuid;
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
// public URL getURLfromWorkerLog(String a) throws MalformedURLException, UnknownHostException{
|
||||
//
|
||||
// File path = new File(System.getProperty("user.home")+File.separator+"/gcube/dataminer-pool-manager/work/"+a+File.separator+"logs");
|
||||
// path.mkdirs();
|
||||
// File n = new File(path + File.separator +a);
|
||||
// //String addr = InetAddress.getLocalHost().getHostAddress();
|
||||
//
|
||||
// return new File(n.getPath()).toURI().toURL();
|
||||
// }
|
||||
//
|
||||
//
|
||||
// public String addAlgorithmsToVRE(AlgorithmSet algorithms, String vre, String uuid) throws IOException {
|
||||
//
|
||||
// // create the cluster (dataminers in the vre)
|
||||
// Cluster cluster = new Cluster();
|
||||
// for(Host h:new ISClient().listDataminersInVRE()) {
|
||||
// cluster.addHost(h);
|
||||
// }
|
||||
//
|
||||
// // apply the changes
|
||||
// AnsibleBridge a = new AnsibleBridge();
|
||||
// return a.applyAlgorithmSetToCluster(algorithms, cluster,uuid).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;
|
||||
//}
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//}
|
||||
package org.gcube.dataanalysis.dataminer.poolmanager.service;
|
||||
|
||||
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
|
||||
|
@ -325,134 +63,7 @@ public class DataminerPoolManager implements PoolManager {
|
|||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(DataminerPoolManager.class);
|
||||
|
||||
// static Collection<Algorithm> algorithms;
|
||||
//
|
||||
// static Collection<AlgorithmSet> sets;
|
||||
//
|
||||
// static {
|
||||
// algorithms = new Vector<>();
|
||||
// }
|
||||
//
|
||||
// public DataminerPoolManager() {
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Add a new algorithm to the set of known ones. No further action is
|
||||
// expected
|
||||
// * on the pool.
|
||||
// */
|
||||
// public void publishAlgorithm(Algorithm algorithm) {
|
||||
// algorithms.add(algorithm);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Re-deploy the given algorithm wherever it's installed
|
||||
// *
|
||||
// * @param algorithm
|
||||
// */
|
||||
// /*
|
||||
// * public void updateAlgorithm(Algorithm algorithm) { // TODO implement
|
||||
// this }
|
||||
// */
|
||||
//
|
||||
// /**
|
||||
// * Add the give algorithm to the given set
|
||||
// *
|
||||
// * @param algorithmId
|
||||
// * @param setId
|
||||
// */
|
||||
// public void addAlgorithmToSet(String algorithmName, String setName) {
|
||||
// AlgorithmSet set = this.getAlgorithmSet(setName);
|
||||
// Algorithm algorithm = this.getAlgorithm(algorithmName);
|
||||
// if (set != null && algorithm != null) {
|
||||
// set.addAlgorithm(algorithm);
|
||||
// this.updateClusters();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Apply the given set of algorithms to the given cluster
|
||||
// *
|
||||
// * @param setId
|
||||
// * @param clusterId
|
||||
// */
|
||||
// public void applyAlgorithmSetToCluster(String setName, String
|
||||
// clusterName) {
|
||||
// AlgorithmSet set = this.getAlgorithmSet(setName);
|
||||
// Cluster cluster = new ISClient().getCluster(clusterName);
|
||||
// if (set != null && cluster != null) {
|
||||
// cluster.addAlgorithmSet(set);
|
||||
// this.updateClusters();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private AlgorithmSet getAlgorithmSet(String name) {
|
||||
// for (AlgorithmSet set : sets) {
|
||||
// if (name.equals(set.getName())) {
|
||||
// return set;
|
||||
// }
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// private Algorithm getAlgorithm(String name) {
|
||||
// for (Algorithm a : algorithms) {
|
||||
// if (name.equals(a.getName())) {
|
||||
// return a;
|
||||
// }
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
|
||||
//
|
||||
// public void getLogId(final Algorithm algorithm, final String vre) {
|
||||
// new Thread() {
|
||||
// public void run() {
|
||||
// while (true) {
|
||||
// try {
|
||||
// addAlgorithmToVRE(algorithm, vre);
|
||||
// } catch (Exception e) {
|
||||
// //log here
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }.start();
|
||||
// }
|
||||
//
|
||||
//
|
||||
|
||||
// public String getLogId(){
|
||||
// PrintStream console = System.out;
|
||||
// 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);
|
||||
// System.setOut(ps);
|
||||
// worker.apply();
|
||||
// System.setOut(console);
|
||||
// worker.apply();
|
||||
// System.out.println("Log stored to to " + n.getAbsolutePath());
|
||||
// }
|
||||
|
||||
// public String getLogById(String id) throws IOException {
|
||||
// String strLine = null;
|
||||
// try{
|
||||
// FileInputStream fstream = new
|
||||
// FileInputStream("/tmp/dataminer-pool-manager/work/"+id+"/logs/"+id);
|
||||
// BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
|
||||
// /* read log line by line */
|
||||
// while ((strLine = br.readLine()) != null) {
|
||||
// /* parse strLine to obtain what you want */
|
||||
// System.out.println (strLine);
|
||||
// }
|
||||
// br.close();
|
||||
// } catch (Exception e) {
|
||||
// System.err.println("Error: " + e.getMessage());
|
||||
// }
|
||||
// return strLine;
|
||||
// }
|
||||
|
||||
|
||||
public String getScriptFromURL(URL url) throws IOException {
|
||||
if (url == null) {
|
||||
return null;
|
||||
|
@ -476,7 +87,7 @@ public class DataminerPoolManager implements PoolManager {
|
|||
* @param vre
|
||||
*
|
||||
*/
|
||||
public String addAlgorithmToVRE(Algorithm algorithm, final String vre, final boolean updateSVN) throws IOException {
|
||||
public String addAlgorithmToVRE(Algorithm algorithm, final String vre, /*final boolean updateSVN*/ final boolean test) throws IOException {
|
||||
// create a fake algorithm set
|
||||
final AlgorithmSet algoSet = new AlgorithmSet();
|
||||
algoSet.setName("fake");
|
||||
|
@ -489,7 +100,7 @@ public class DataminerPoolManager implements PoolManager {
|
|||
// TODO Auto-generated method stub
|
||||
try {
|
||||
try {
|
||||
addAlgorithmsToVRE(algoSet, vre, uuid, updateSVN);
|
||||
addAlgorithmsToVRE(algoSet, vre, uuid, /*updateSVN*/test);
|
||||
} catch (SVNException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
|
@ -503,13 +114,13 @@ public class DataminerPoolManager implements PoolManager {
|
|||
}
|
||||
}
|
||||
}).start();
|
||||
// this line will execute immediately, not waiting for your task to
|
||||
// this line will execute immediately, not waiting for task to
|
||||
// complete
|
||||
System.out.println(uuid);
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public String addAlgorithmToHost(Algorithm algorithm, final String hostname, final boolean updateSVN) throws IOException {
|
||||
public String addAlgorithmToHost(Algorithm algorithm, final String hostname, /*final boolean updateSVN*/ final boolean test) throws IOException {
|
||||
// create a fake algorithm set
|
||||
final AlgorithmSet algoSet = new AlgorithmSet();
|
||||
algoSet.setName("fake");
|
||||
|
@ -521,7 +132,8 @@ public class DataminerPoolManager implements PoolManager {
|
|||
public void run() {
|
||||
// TODO Auto-generated method stub
|
||||
try {
|
||||
addAlgorithmsToHost(algoSet, hostname, uuid, updateSVN);
|
||||
if(test){
|
||||
addAlgorithmsToStagingHost(algoSet, hostname, uuid, /*updateSVN,*/test);}
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
|
@ -551,7 +163,7 @@ public class DataminerPoolManager implements PoolManager {
|
|||
return new File(n.getPath()).toURI().toURL();
|
||||
}
|
||||
|
||||
public String addAlgorithmsToVRE(AlgorithmSet algorithms, String vre, String uuid, boolean updateSVN) throws IOException, InterruptedException, SVNException {
|
||||
public String addAlgorithmsToVRE(AlgorithmSet algorithms, String vre, String uuid, /*boolean updateSVN,*/ boolean test) throws IOException, InterruptedException, SVNException {
|
||||
|
||||
// create the cluster (dataminers in the vre)
|
||||
Cluster cluster = new Cluster();
|
||||
|
@ -562,11 +174,11 @@ public class DataminerPoolManager implements PoolManager {
|
|||
|
||||
// apply the changes
|
||||
AnsibleBridge a = new AnsibleBridge();
|
||||
return a.applyAlgorithmSetToCluster(algorithms, cluster, uuid, updateSVN).getWorkerId();
|
||||
return a.applyAlgorithmSetToCluster(algorithms, cluster, uuid, /*updateSVN,*/ test).getWorkerId();
|
||||
|
||||
}
|
||||
|
||||
public String addAlgorithmsToHost(AlgorithmSet algorithms, String hostname, String uuid, boolean updateSVN)
|
||||
public String addAlgorithmsToHost(AlgorithmSet algorithms, String hostname, String uuid, /*boolean updateSVN,*/boolean test)
|
||||
throws IOException, InterruptedException, SVNException {
|
||||
|
||||
// create the cluster (dataminers in the vre)
|
||||
|
@ -581,11 +193,23 @@ public class DataminerPoolManager implements PoolManager {
|
|||
// }
|
||||
// apply the changes
|
||||
AnsibleBridge a = new AnsibleBridge();
|
||||
return a.applyAlgorithmSetToCluster(algorithms, cluster, uuid, updateSVN).getWorkerId();
|
||||
return a.applyAlgorithmSetToCluster(algorithms, cluster, uuid, /*updateSVN,*/test).getWorkerId();
|
||||
|
||||
}
|
||||
|
||||
|
||||
public String addAlgorithmsToStagingHost(AlgorithmSet algorithms, String hostname, String uuid, /*boolean updateSVN,*/boolean test)
|
||||
throws IOException, InterruptedException, SVNException {
|
||||
Cluster cluster = new Cluster();
|
||||
Host h = new Host();
|
||||
h.setName(hostname);
|
||||
cluster.addHost(h);
|
||||
|
||||
AnsibleBridge a = new AnsibleBridge();
|
||||
return a.applyAlgorithmSetToCluster(algorithms, cluster, uuid, /*updateSVN,*/test).getWorkerId();
|
||||
|
||||
}
|
||||
|
||||
|
||||
public Algorithm extractAlgorithm(String url) throws IOException {
|
||||
return new AlgorithmPackageParser().parsePackage(url);
|
||||
|
@ -726,4 +350,13 @@ public class DataminerPoolManager implements PoolManager {
|
|||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue