569 lines
23 KiB
Java
569 lines
23 KiB
Java
***REMOVED***package org.gcube.dataanalysis.dataminer.poolmanager.service;
|
|
***REMOVED***
|
|
***REMOVED***import java.io.BufferedReader;
|
|
***REMOVED***import java.io.File;
|
|
***REMOVED******REMOVED***
|
|
***REMOVED***import java.io.InputStreamReader;
|
|
***REMOVED******REMOVED***
|
|
***REMOVED******REMOVED***
|
|
***REMOVED***import java.net.URLConnection;
|
|
***REMOVED******REMOVED***
|
|
***REMOVED***import java.util.UUID;
|
|
***REMOVED***
|
|
***REMOVED***import org.gcube.dataanalysis.dataminer.poolmanager.ansiblebridge.AnsibleBridge;
|
|
***REMOVED***import org.gcube.dataanalysis.dataminer.poolmanager.clients.ISClient;
|
|
***REMOVED******REMOVED***
|
|
***REMOVED***import org.gcube.dataanalysis.dataminer.poolmanager.datamodel.AlgorithmSet;
|
|
***REMOVED***import org.gcube.dataanalysis.dataminer.poolmanager.datamodel.Cluster;
|
|
***REMOVED***import org.gcube.dataanalysis.dataminer.poolmanager.datamodel.Host;
|
|
***REMOVED***import org.gcube.dataanalysis.dataminer.poolmanager.process.AlgorithmPackageParser;
|
|
***REMOVED***import org.gcube.dataanalysis.dataminer.poolmanager.rest.PoolManager;
|
|
***REMOVED******REMOVED***
|
|
***REMOVED******REMOVED***
|
|
***REMOVED***
|
|
***REMOVED***public class DataminerPoolManager implements PoolManager ***REMOVED***
|
|
***REMOVED***
|
|
***REMOVED***
|
|
***REMOVED*** private static final Logger LOGGER = LoggerFactory.getLogger(DataminerPoolManager.class);
|
|
***REMOVED***
|
|
***REMOVED***
|
|
***REMOVED******REMOVED*** static Collection<Algorithm> algorithms;
|
|
***REMOVED******REMOVED***
|
|
***REMOVED******REMOVED*** static Collection<AlgorithmSet> sets;
|
|
***REMOVED******REMOVED***
|
|
***REMOVED******REMOVED*** static ***REMOVED***
|
|
***REMOVED******REMOVED*** algorithms = new Vector<>();
|
|
***REMOVED******REMOVED*** ***REMOVED***
|
|
***REMOVED******REMOVED***
|
|
***REMOVED******REMOVED*** public DataminerPoolManager() ***REMOVED***
|
|
***REMOVED******REMOVED*** ***REMOVED***
|
|
***REMOVED******REMOVED***
|
|
***REMOVED******REMOVED*** /**
|
|
***REMOVED******REMOVED*** * Add a new algorithm to the set of known ones. No further action is expected
|
|
***REMOVED******REMOVED*** * on the pool.
|
|
***REMOVED******REMOVED*** */
|
|
***REMOVED******REMOVED*** public void publishAlgorithm(Algorithm algorithm) ***REMOVED***
|
|
***REMOVED******REMOVED*** algorithms.add(algorithm);
|
|
***REMOVED******REMOVED*** ***REMOVED***
|
|
***REMOVED******REMOVED***
|
|
***REMOVED******REMOVED*** /**
|
|
***REMOVED******REMOVED*** * Re-deploy the given algorithm wherever it's installed
|
|
***REMOVED******REMOVED*** *
|
|
***REMOVED******REMOVED*** * @param algorithm
|
|
***REMOVED******REMOVED*** */
|
|
***REMOVED******REMOVED*** /*
|
|
***REMOVED******REMOVED*** * public void updateAlgorithm(Algorithm algorithm) ***REMOVED*** ***REMOVED*** TODO implement this ***REMOVED***
|
|
***REMOVED******REMOVED*** */
|
|
***REMOVED******REMOVED***
|
|
***REMOVED******REMOVED*** /**
|
|
***REMOVED******REMOVED*** * Add the give algorithm to the given set
|
|
***REMOVED******REMOVED*** *
|
|
***REMOVED******REMOVED*** * @param algorithmId
|
|
***REMOVED******REMOVED*** * @param setId
|
|
***REMOVED******REMOVED*** */
|
|
***REMOVED******REMOVED*** public void addAlgorithmToSet(String algorithmName, String setName) ***REMOVED***
|
|
***REMOVED******REMOVED*** AlgorithmSet set = this.getAlgorithmSet(setName);
|
|
***REMOVED******REMOVED*** Algorithm algorithm = this.getAlgorithm(algorithmName);
|
|
***REMOVED******REMOVED*** if (set != null && algorithm != null) ***REMOVED***
|
|
***REMOVED******REMOVED*** set.addAlgorithm(algorithm);
|
|
***REMOVED******REMOVED*** this.updateClusters();
|
|
***REMOVED******REMOVED*** ***REMOVED***
|
|
***REMOVED******REMOVED*** ***REMOVED***
|
|
***REMOVED******REMOVED***
|
|
***REMOVED******REMOVED*** /**
|
|
***REMOVED******REMOVED*** * Apply the given set of algorithms to the given cluster
|
|
***REMOVED******REMOVED*** *
|
|
***REMOVED******REMOVED*** * @param setId
|
|
***REMOVED******REMOVED*** * @param clusterId
|
|
***REMOVED******REMOVED*** */
|
|
***REMOVED******REMOVED*** public void applyAlgorithmSetToCluster(String setName, String clusterName) ***REMOVED***
|
|
***REMOVED******REMOVED*** AlgorithmSet set = this.getAlgorithmSet(setName);
|
|
***REMOVED******REMOVED*** Cluster cluster = new ISClient().getCluster(clusterName);
|
|
***REMOVED******REMOVED*** if (set != null && cluster != null) ***REMOVED***
|
|
***REMOVED******REMOVED*** cluster.addAlgorithmSet(set);
|
|
***REMOVED******REMOVED*** this.updateClusters();
|
|
***REMOVED******REMOVED*** ***REMOVED***
|
|
***REMOVED******REMOVED*** ***REMOVED***
|
|
***REMOVED******REMOVED***
|
|
***REMOVED******REMOVED*** private AlgorithmSet getAlgorithmSet(String name) ***REMOVED***
|
|
***REMOVED******REMOVED*** for (AlgorithmSet set : sets) ***REMOVED***
|
|
***REMOVED******REMOVED*** if (name.equals(set.getName())) ***REMOVED***
|
|
***REMOVED******REMOVED*** return set;
|
|
***REMOVED******REMOVED*** ***REMOVED***
|
|
***REMOVED******REMOVED*** ***REMOVED***
|
|
***REMOVED******REMOVED*** return null;
|
|
***REMOVED******REMOVED*** ***REMOVED***
|
|
***REMOVED******REMOVED***
|
|
***REMOVED******REMOVED*** private Algorithm getAlgorithm(String name) ***REMOVED***
|
|
***REMOVED******REMOVED*** for (Algorithm a : algorithms) ***REMOVED***
|
|
***REMOVED******REMOVED*** if (name.equals(a.getName())) ***REMOVED***
|
|
***REMOVED******REMOVED*** return a;
|
|
***REMOVED******REMOVED*** ***REMOVED***
|
|
***REMOVED******REMOVED*** ***REMOVED***
|
|
***REMOVED******REMOVED*** return null;
|
|
***REMOVED******REMOVED*** ***REMOVED***
|
|
***REMOVED***
|
|
***REMOVED***
|
|
***REMOVED***
|
|
***REMOVED***
|
|
***REMOVED******REMOVED***
|
|
***REMOVED******REMOVED*** public void getLogId(final Algorithm algorithm, final String vre) ***REMOVED***
|
|
***REMOVED******REMOVED*** new Thread() ***REMOVED***
|
|
***REMOVED******REMOVED*** public void run() ***REMOVED***
|
|
***REMOVED******REMOVED*** while (true) ***REMOVED***
|
|
***REMOVED******REMOVED*** try ***REMOVED***
|
|
***REMOVED******REMOVED*** addAlgorithmToVRE(algorithm, vre);
|
|
***REMOVED******REMOVED*** ***REMOVED*** catch (Exception e) ***REMOVED***
|
|
***REMOVED******REMOVED*** ***REMOVED***log here
|
|
***REMOVED******REMOVED*** ***REMOVED***
|
|
***REMOVED******REMOVED*** ***REMOVED***
|
|
***REMOVED******REMOVED*** ***REMOVED***
|
|
***REMOVED******REMOVED*** ***REMOVED***.start();
|
|
***REMOVED******REMOVED******REMOVED***
|
|
***REMOVED******REMOVED***
|
|
***REMOVED******REMOVED***
|
|
***REMOVED***
|
|
***REMOVED******REMOVED*** public String getLogId()***REMOVED***
|
|
***REMOVED******REMOVED*** PrintStream console = System.out;
|
|
***REMOVED******REMOVED*** File path = new File(worker.getWorkdir() + File.separator + "logs");
|
|
***REMOVED******REMOVED*** path.mkdirs();
|
|
***REMOVED******REMOVED*** File n = new File(path + File.separator + worker.getWorkerId());
|
|
***REMOVED******REMOVED*** FileOutputStream fos = new FileOutputStream(n);
|
|
***REMOVED******REMOVED*** PrintStream ps = new PrintStream(fos);
|
|
***REMOVED******REMOVED*** System.setOut(ps);
|
|
***REMOVED******REMOVED*** worker.apply();
|
|
***REMOVED******REMOVED*** System.setOut(console);
|
|
***REMOVED******REMOVED*** worker.apply();
|
|
***REMOVED******REMOVED*** System.out.println("Log stored to to " + n.getAbsolutePath());
|
|
***REMOVED******REMOVED******REMOVED***
|
|
***REMOVED***
|
|
***REMOVED***
|
|
***REMOVED***
|
|
***REMOVED***
|
|
***REMOVED******REMOVED*** public String getLogById(String id) throws IOException ***REMOVED***
|
|
***REMOVED******REMOVED*** String strLine = null;
|
|
***REMOVED******REMOVED*** try***REMOVED***
|
|
***REMOVED******REMOVED*** FileInputStream fstream = new FileInputStream("/tmp/dataminer-pool-manager/work/"+id+"/logs/"+id);
|
|
***REMOVED******REMOVED*** BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
|
|
***REMOVED******REMOVED*** /* read log line by line */
|
|
***REMOVED******REMOVED*** while ((strLine = br.readLine()) != null) ***REMOVED***
|
|
***REMOVED******REMOVED*** /* parse strLine to obtain what you want */
|
|
***REMOVED******REMOVED*** System.out.println (strLine);
|
|
***REMOVED******REMOVED*** ***REMOVED***
|
|
***REMOVED******REMOVED*** br.close();
|
|
***REMOVED******REMOVED*** ***REMOVED*** catch (Exception e) ***REMOVED***
|
|
***REMOVED******REMOVED*** System.err.println("Error: " + e.getMessage());
|
|
***REMOVED******REMOVED*** ***REMOVED***
|
|
***REMOVED******REMOVED*** return strLine;
|
|
***REMOVED******REMOVED******REMOVED***
|
|
***REMOVED***
|
|
***REMOVED***
|
|
***REMOVED*** public String getScriptFromURL(URL url) throws IOException ***REMOVED***
|
|
***REMOVED*** if (url == null) ***REMOVED***
|
|
***REMOVED*** return null;
|
|
***REMOVED*** ***REMOVED***
|
|
***REMOVED*** URLConnection yc = url.openConnection();
|
|
***REMOVED*** BufferedReader input = new BufferedReader(new InputStreamReader(
|
|
***REMOVED*** yc.getInputStream()));
|
|
***REMOVED*** String line;
|
|
***REMOVED*** StringBuffer buffer = new StringBuffer();
|
|
***REMOVED*** while ((line = input.readLine()) != null) ***REMOVED***
|
|
***REMOVED*** buffer.append(line + "\n");
|
|
***REMOVED*** ***REMOVED***
|
|
***REMOVED*** String bufferScript = buffer.substring(0, buffer.length());
|
|
***REMOVED*** input.close();
|
|
***REMOVED*** return bufferScript;
|
|
***REMOVED*** ***REMOVED***
|
|
***REMOVED***
|
|
***REMOVED***
|
|
***REMOVED***
|
|
***REMOVED***
|
|
***REMOVED***
|
|
***REMOVED*** /**
|
|
***REMOVED*** * Publish the given algorithm in the given VRE
|
|
***REMOVED*** *
|
|
***REMOVED*** * @param algorithmName
|
|
***REMOVED*** * @param vre
|
|
***REMOVED*** *
|
|
***REMOVED*** */
|
|
***REMOVED*** public String addAlgorithmToVRE(Algorithm algorithm, final String vre) throws IOException ***REMOVED***
|
|
***REMOVED*** ***REMOVED*** create a fake algorithm set
|
|
***REMOVED*** final AlgorithmSet algoSet = new AlgorithmSet();
|
|
***REMOVED*** algoSet.setName("fake");
|
|
***REMOVED*** algoSet.addAlgorithm(algorithm);
|
|
***REMOVED*** final String uuid = UUID.randomUUID().toString();
|
|
***REMOVED***
|
|
***REMOVED*** new Thread(new Runnable() ***REMOVED***
|
|
***REMOVED******REMOVED***
|
|
***REMOVED*** public void run() ***REMOVED***
|
|
***REMOVED*** ***REMOVED***
|
|
***REMOVED*** try ***REMOVED***
|
|
***REMOVED*** addAlgorithmsToVRE(algoSet, vre, uuid);
|
|
***REMOVED*** ***REMOVED*** catch (IOException e) ***REMOVED***
|
|
***REMOVED*** ***REMOVED*** TODO Auto-generated catch block
|
|
***REMOVED*** e.printStackTrace();
|
|
***REMOVED*** ***REMOVED***
|
|
***REMOVED*** ***REMOVED***
|
|
***REMOVED******REMOVED***).start();
|
|
***REMOVED*** ***REMOVED***this line will execute immediately, not waiting for your task to complete
|
|
***REMOVED*** System.out.println(uuid);
|
|
***REMOVED*** return uuid;
|
|
***REMOVED*** ***REMOVED***
|
|
***REMOVED***
|
|
***REMOVED***
|
|
***REMOVED***
|
|
***REMOVED*** public URL getURLfromWorkerLog(String a) throws MalformedURLException, UnknownHostException***REMOVED***
|
|
***REMOVED***
|
|
***REMOVED*** File path = new File(System.getProperty("user.home")+File.separator+"/gcube/dataminer-pool-manager/work/"+a+File.separator+"logs");
|
|
***REMOVED*** path.mkdirs();
|
|
***REMOVED*** File n = new File(path + File.separator +a);
|
|
***REMOVED*** ***REMOVED***String addr = InetAddress.getLocalHost().getHostAddress();
|
|
***REMOVED***
|
|
***REMOVED*** return new File(n.getPath()).toURI().toURL();
|
|
***REMOVED*** ***REMOVED***
|
|
***REMOVED***
|
|
***REMOVED***
|
|
***REMOVED*** public String addAlgorithmsToVRE(AlgorithmSet algorithms, String vre, String uuid) throws IOException ***REMOVED***
|
|
***REMOVED***
|
|
***REMOVED*** ***REMOVED*** create the cluster (dataminers in the vre)
|
|
***REMOVED*** Cluster cluster = new Cluster();
|
|
***REMOVED*** for(Host h:new ISClient().listDataminersInVRE()) ***REMOVED***
|
|
***REMOVED*** cluster.addHost(h);
|
|
***REMOVED*** ***REMOVED***
|
|
***REMOVED***
|
|
***REMOVED*** ***REMOVED*** apply the changes
|
|
***REMOVED*** AnsibleBridge a = new AnsibleBridge();
|
|
***REMOVED*** return a.applyAlgorithmSetToCluster(algorithms, cluster,uuid).getWorkerId();
|
|
***REMOVED***
|
|
***REMOVED*** ***REMOVED***
|
|
***REMOVED***
|
|
***REMOVED*** public Algorithm extractAlgorithm(String url) throws IOException ***REMOVED***
|
|
***REMOVED*** return new AlgorithmPackageParser().parsePackage(url);
|
|
***REMOVED*** ***REMOVED***
|
|
***REMOVED***
|
|
***REMOVED***
|
|
***REMOVED***@Override
|
|
***REMOVED***public void getLogId(Algorithm algo, String vre) ***REMOVED***
|
|
***REMOVED*** ***REMOVED*** TODO Auto-generated method stub
|
|
***REMOVED***
|
|
***REMOVED******REMOVED***
|
|
***REMOVED***
|
|
***REMOVED***
|
|
***REMOVED***@Override
|
|
***REMOVED***public String getLogById(String logId) throws IOException ***REMOVED***
|
|
***REMOVED*** ***REMOVED*** TODO Auto-generated method stub
|
|
***REMOVED*** return null;
|
|
***REMOVED******REMOVED***
|
|
***REMOVED***
|
|
***REMOVED***
|
|
***REMOVED***
|
|
***REMOVED***
|
|
***REMOVED***
|
|
***REMOVED******REMOVED***
|
|
package org.gcube.dataanalysis.dataminer.poolmanager.service;
|
|
|
|
import java.io.BufferedReader;
|
|
import java.io.File;
|
|
***REMOVED***
|
|
import java.io.InputStreamReader;
|
|
***REMOVED***
|
|
***REMOVED***
|
|
import java.net.URLConnection;
|
|
***REMOVED***
|
|
import java.util.UUID;
|
|
|
|
import org.gcube.dataanalysis.dataminer.poolmanager.ansiblebridge.AnsibleBridge;
|
|
import org.gcube.dataanalysis.dataminer.poolmanager.clients.ISClient;
|
|
***REMOVED***
|
|
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;
|
|
***REMOVED***
|
|
***REMOVED***
|
|
|
|
public class DataminerPoolManager implements PoolManager ***REMOVED***
|
|
|
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(DataminerPoolManager.class);
|
|
|
|
|
|
***REMOVED*** static Collection<Algorithm> algorithms;
|
|
***REMOVED***
|
|
***REMOVED*** static Collection<AlgorithmSet> sets;
|
|
***REMOVED***
|
|
***REMOVED*** static ***REMOVED***
|
|
***REMOVED*** algorithms = new Vector<>();
|
|
***REMOVED*** ***REMOVED***
|
|
***REMOVED***
|
|
***REMOVED*** public DataminerPoolManager() ***REMOVED***
|
|
***REMOVED*** ***REMOVED***
|
|
***REMOVED***
|
|
***REMOVED*** /**
|
|
***REMOVED*** * Add a new algorithm to the set of known ones. No further action is expected
|
|
***REMOVED*** * on the pool.
|
|
***REMOVED*** */
|
|
***REMOVED*** public void publishAlgorithm(Algorithm algorithm) ***REMOVED***
|
|
***REMOVED*** algorithms.add(algorithm);
|
|
***REMOVED*** ***REMOVED***
|
|
***REMOVED***
|
|
***REMOVED*** /**
|
|
***REMOVED*** * Re-deploy the given algorithm wherever it's installed
|
|
***REMOVED*** *
|
|
***REMOVED*** * @param algorithm
|
|
***REMOVED*** */
|
|
***REMOVED*** /*
|
|
***REMOVED*** * public void updateAlgorithm(Algorithm algorithm) ***REMOVED*** ***REMOVED*** TODO implement this ***REMOVED***
|
|
***REMOVED*** */
|
|
***REMOVED***
|
|
***REMOVED*** /**
|
|
***REMOVED*** * Add the give algorithm to the given set
|
|
***REMOVED*** *
|
|
***REMOVED*** * @param algorithmId
|
|
***REMOVED*** * @param setId
|
|
***REMOVED*** */
|
|
***REMOVED*** public void addAlgorithmToSet(String algorithmName, String setName) ***REMOVED***
|
|
***REMOVED*** AlgorithmSet set = this.getAlgorithmSet(setName);
|
|
***REMOVED*** Algorithm algorithm = this.getAlgorithm(algorithmName);
|
|
***REMOVED*** if (set != null && algorithm != null) ***REMOVED***
|
|
***REMOVED*** set.addAlgorithm(algorithm);
|
|
***REMOVED*** this.updateClusters();
|
|
***REMOVED*** ***REMOVED***
|
|
***REMOVED*** ***REMOVED***
|
|
***REMOVED***
|
|
***REMOVED*** /**
|
|
***REMOVED*** * Apply the given set of algorithms to the given cluster
|
|
***REMOVED*** *
|
|
***REMOVED*** * @param setId
|
|
***REMOVED*** * @param clusterId
|
|
***REMOVED*** */
|
|
***REMOVED*** public void applyAlgorithmSetToCluster(String setName, String clusterName) ***REMOVED***
|
|
***REMOVED*** AlgorithmSet set = this.getAlgorithmSet(setName);
|
|
***REMOVED*** Cluster cluster = new ISClient().getCluster(clusterName);
|
|
***REMOVED*** if (set != null && cluster != null) ***REMOVED***
|
|
***REMOVED*** cluster.addAlgorithmSet(set);
|
|
***REMOVED*** this.updateClusters();
|
|
***REMOVED*** ***REMOVED***
|
|
***REMOVED*** ***REMOVED***
|
|
***REMOVED***
|
|
***REMOVED*** private AlgorithmSet getAlgorithmSet(String name) ***REMOVED***
|
|
***REMOVED*** for (AlgorithmSet set : sets) ***REMOVED***
|
|
***REMOVED*** if (name.equals(set.getName())) ***REMOVED***
|
|
***REMOVED*** return set;
|
|
***REMOVED*** ***REMOVED***
|
|
***REMOVED*** ***REMOVED***
|
|
***REMOVED*** return null;
|
|
***REMOVED*** ***REMOVED***
|
|
***REMOVED***
|
|
***REMOVED*** private Algorithm getAlgorithm(String name) ***REMOVED***
|
|
***REMOVED*** for (Algorithm a : algorithms) ***REMOVED***
|
|
***REMOVED*** if (name.equals(a.getName())) ***REMOVED***
|
|
***REMOVED*** return a;
|
|
***REMOVED*** ***REMOVED***
|
|
***REMOVED*** ***REMOVED***
|
|
***REMOVED*** return null;
|
|
***REMOVED*** ***REMOVED***
|
|
|
|
|
|
|
|
|
|
***REMOVED***
|
|
***REMOVED*** public void getLogId(final Algorithm algorithm, final String vre) ***REMOVED***
|
|
***REMOVED*** new Thread() ***REMOVED***
|
|
***REMOVED*** public void run() ***REMOVED***
|
|
***REMOVED*** while (true) ***REMOVED***
|
|
***REMOVED*** try ***REMOVED***
|
|
***REMOVED*** addAlgorithmToVRE(algorithm, vre);
|
|
***REMOVED*** ***REMOVED*** catch (Exception e) ***REMOVED***
|
|
***REMOVED*** ***REMOVED***log here
|
|
***REMOVED*** ***REMOVED***
|
|
***REMOVED*** ***REMOVED***
|
|
***REMOVED*** ***REMOVED***
|
|
***REMOVED*** ***REMOVED***.start();
|
|
***REMOVED******REMOVED***
|
|
***REMOVED***
|
|
***REMOVED***
|
|
|
|
***REMOVED*** public String getLogId()***REMOVED***
|
|
***REMOVED*** PrintStream console = System.out;
|
|
***REMOVED*** File path = new File(worker.getWorkdir() + File.separator + "logs");
|
|
***REMOVED*** path.mkdirs();
|
|
***REMOVED*** File n = new File(path + File.separator + worker.getWorkerId());
|
|
***REMOVED*** FileOutputStream fos = new FileOutputStream(n);
|
|
***REMOVED*** PrintStream ps = new PrintStream(fos);
|
|
***REMOVED*** System.setOut(ps);
|
|
***REMOVED*** worker.apply();
|
|
***REMOVED*** System.setOut(console);
|
|
***REMOVED*** worker.apply();
|
|
***REMOVED*** System.out.println("Log stored to to " + n.getAbsolutePath());
|
|
***REMOVED******REMOVED***
|
|
|
|
|
|
|
|
|
|
***REMOVED*** public String getLogById(String id) throws IOException ***REMOVED***
|
|
***REMOVED*** String strLine = null;
|
|
***REMOVED*** try***REMOVED***
|
|
***REMOVED*** FileInputStream fstream = new FileInputStream("/tmp/dataminer-pool-manager/work/"+id+"/logs/"+id);
|
|
***REMOVED*** BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
|
|
***REMOVED*** /* read log line by line */
|
|
***REMOVED*** while ((strLine = br.readLine()) != null) ***REMOVED***
|
|
***REMOVED*** /* parse strLine to obtain what you want */
|
|
***REMOVED*** System.out.println (strLine);
|
|
***REMOVED*** ***REMOVED***
|
|
***REMOVED*** br.close();
|
|
***REMOVED*** ***REMOVED*** catch (Exception e) ***REMOVED***
|
|
***REMOVED*** System.err.println("Error: " + e.getMessage());
|
|
***REMOVED*** ***REMOVED***
|
|
***REMOVED*** return strLine;
|
|
***REMOVED******REMOVED***
|
|
|
|
|
|
public String getScriptFromURL(URL url) throws IOException ***REMOVED***
|
|
if (url == null) ***REMOVED***
|
|
return null;
|
|
***REMOVED***
|
|
URLConnection yc = url.openConnection();
|
|
BufferedReader input = new BufferedReader(new InputStreamReader(
|
|
yc.getInputStream()));
|
|
String line;
|
|
StringBuffer buffer = new StringBuffer();
|
|
while ((line = input.readLine()) != null) ***REMOVED***
|
|
buffer.append(line + "\n");
|
|
***REMOVED***
|
|
String bufferScript = buffer.substring(0, buffer.length());
|
|
input.close();
|
|
return bufferScript;
|
|
***REMOVED***
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
* Publish the given algorithm in the given VRE
|
|
*
|
|
* @param algorithmName
|
|
* @param vre
|
|
*
|
|
*/
|
|
public String addAlgorithmToVRE(Algorithm algorithm, final String vre)
|
|
throws IOException ***REMOVED***
|
|
***REMOVED*** 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() ***REMOVED***
|
|
@Override
|
|
public void run() ***REMOVED***
|
|
***REMOVED*** TODO Auto-generated method stub
|
|
try ***REMOVED***
|
|
addAlgorithmsToVRE(algoSet, vre, uuid);
|
|
***REMOVED*** catch (IOException e) ***REMOVED***
|
|
***REMOVED*** TODO Auto-generated catch block
|
|
e.printStackTrace();
|
|
***REMOVED***
|
|
***REMOVED***
|
|
***REMOVED***).start();
|
|
***REMOVED*** this line will execute immediately, not waiting for your task to complete
|
|
System.out.println(uuid);
|
|
return uuid;
|
|
***REMOVED***
|
|
|
|
public String addAlgorithmToHost(Algorithm algorithm, final String hostname)
|
|
throws IOException ***REMOVED***
|
|
***REMOVED*** 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() ***REMOVED***
|
|
@Override
|
|
public void run() ***REMOVED***
|
|
***REMOVED*** TODO Auto-generated method stub
|
|
try ***REMOVED***
|
|
addAlgorithmsToHost(algoSet, hostname, uuid);
|
|
***REMOVED*** catch (IOException e) ***REMOVED***
|
|
***REMOVED*** TODO Auto-generated catch block
|
|
e.printStackTrace();
|
|
***REMOVED***
|
|
***REMOVED***
|
|
***REMOVED***).start();
|
|
***REMOVED*** this line will execute immediately, not waiting for your task to complete
|
|
System.out.println(uuid);
|
|
return uuid;
|
|
***REMOVED***
|
|
|
|
|
|
public URL getURLfromWorkerLog(String a) throws MalformedURLException, UnknownHostException***REMOVED***
|
|
|
|
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);
|
|
***REMOVED***String addr = InetAddress.getLocalHost().getHostAddress();
|
|
|
|
return new File(n.getPath()).toURI().toURL();
|
|
***REMOVED***
|
|
|
|
|
|
|
|
public String addAlgorithmsToVRE(AlgorithmSet algorithms, String vre, String uuid) throws IOException ***REMOVED***
|
|
|
|
***REMOVED*** create the cluster (dataminers in the vre)
|
|
Cluster cluster = new Cluster();
|
|
for(Host h:new ISClient().listDataminersInVRE()) ***REMOVED***
|
|
cluster.addHost(h);
|
|
***REMOVED***
|
|
|
|
***REMOVED*** apply the changes
|
|
AnsibleBridge a = new AnsibleBridge();
|
|
return a.applyAlgorithmSetToCluster(algorithms, cluster,uuid).getWorkerId();
|
|
|
|
***REMOVED***
|
|
|
|
public String addAlgorithmsToHost(AlgorithmSet algorithms, String hostname, String uuid) throws IOException ***REMOVED***
|
|
|
|
***REMOVED*** create the cluster (dataminers in the vre)
|
|
Cluster cluster = new Cluster();
|
|
cluster.addHost(new ISClient().getDataminer(hostname));
|
|
***REMOVED*** for(Host h:new ISClient().listDataminersInVRE()) ***REMOVED***
|
|
***REMOVED*** cluster.addHost(h);
|
|
***REMOVED*** ***REMOVED***
|
|
|
|
***REMOVED*** apply the changes
|
|
AnsibleBridge a = new AnsibleBridge();
|
|
return a.applyAlgorithmSetToCluster(algorithms, cluster,uuid).getWorkerId();
|
|
|
|
***REMOVED***
|
|
|
|
|
|
public Algorithm extractAlgorithm(String url) throws IOException ***REMOVED***
|
|
return new AlgorithmPackageParser().parsePackage(url);
|
|
***REMOVED***
|
|
|
|
|
|
@Override
|
|
public void getLogId(Algorithm algo, String vre) ***REMOVED***
|
|
***REMOVED*** TODO Auto-generated method stub
|
|
|
|
***REMOVED***
|
|
|
|
|
|
@Override
|
|
public String getLogById(String logId) throws IOException ***REMOVED***
|
|
***REMOVED*** TODO Auto-generated method stub
|
|
return null;
|
|
***REMOVED***
|
|
|
|
|
|
|
|
|
|
|
|
***REMOVED***
|
|
|
|
|