101 lines
3.3 KiB
Java
101 lines
3.3 KiB
Java
package org.gcube.dataanalysis.dataminer.poolmanager.service;
|
|
|
|
import java.io.File;
|
|
import java.io.FileOutputStream;
|
|
***REMOVED***
|
|
import java.io.PrintStream;
|
|
***REMOVED***
|
|
***REMOVED***
|
|
import java.util.UUID;
|
|
|
|
import org.gcube.dataanalysis.dataminer.poolmanager.ansible.AnsibleWorker;
|
|
import org.gcube.dataanalysis.dataminer.poolmanager.ansiblebridge.AnsibleBridge;
|
|
import org.gcube.dataanalysis.dataminer.poolmanager.datamodel.Algorithm;
|
|
***REMOVED***
|
|
import org.gcube.dataanalysis.dataminer.poolmanager.datamodel.Dependency;
|
|
import org.gcube.dataanalysis.dataminer.poolmanager.util.SVNUpdater;
|
|
import org.tmatesoft.svn.core.SVNException;
|
|
|
|
public abstract class DMPMJob {
|
|
|
|
|
|
protected SVNUpdater svnUpdater;
|
|
protected File jobLogs;
|
|
|
|
protected String id;
|
|
|
|
public DMPMJob(SVNUpdater svnUpdater){
|
|
this.svnUpdater = svnUpdater;
|
|
this.id = UUID.randomUUID().toString();
|
|
|
|
***REMOVED***TODO: dmpm work directory should be loaded from configuration file
|
|
this.jobLogs = new File(System.getProperty("user.home")+File.separator+"dataminer-pool-manager"+File.separator+"jobs");
|
|
|
|
this.jobLogs.mkdirs();
|
|
***REMOVED***
|
|
|
|
|
|
public String start(){
|
|
new Thread(new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
try {
|
|
execute();
|
|
***REMOVED*** catch (Exception e) {
|
|
e.printStackTrace();
|
|
***REMOVED***
|
|
***REMOVED***
|
|
***REMOVED***).start();
|
|
|
|
return this.id;
|
|
***REMOVED***
|
|
|
|
protected AnsibleWorker createWorker(Algorithm algo,
|
|
Cluster dataminerCluster,
|
|
boolean includeAlgorithmDependencies,
|
|
String user){
|
|
AnsibleBridge ansibleBridge = new AnsibleBridge();
|
|
try {
|
|
return ansibleBridge.createWorker(algo, dataminerCluster, includeAlgorithmDependencies, user);
|
|
***REMOVED*** catch (IOException e) {
|
|
e.printStackTrace();
|
|
***REMOVED***
|
|
return null;
|
|
|
|
***REMOVED***
|
|
|
|
protected abstract void execute();
|
|
|
|
protected int executeAnsibleWorker(AnsibleWorker worker) throws IOException, InterruptedException, SVNException{
|
|
File path = new File(worker.getWorkdir() + File.separator + "jobs");
|
|
path.mkdirs();
|
|
File n = new File(this.jobLogs + File.separator + this.id);
|
|
FileOutputStream fos = new FileOutputStream(n, true);
|
|
PrintStream ps = new PrintStream(fos);
|
|
return worker.execute(ps);
|
|
***REMOVED***
|
|
|
|
***REMOVED***
|
|
***REMOVED*** protected void updateSVNDependencies(Algorithm algo, boolean stagingVRE) throws IOException, SVNException {
|
|
***REMOVED*** for (Dependency d : algo.getDependencies()) {
|
|
***REMOVED***
|
|
***REMOVED*** if (d.getType().equals("os")) {
|
|
***REMOVED*** List<String> ls = new LinkedList<String>();
|
|
***REMOVED*** ls.add(d.getName());
|
|
***REMOVED*** this.svnUpdater.updateSVN((stagingVRE ? "test_": "") + "r_deb_pkgs.txt", ls);
|
|
***REMOVED*** ***REMOVED***
|
|
***REMOVED*** if (d.getType().equals("cran")) {
|
|
***REMOVED*** List<String> ls = new LinkedList<String>();
|
|
***REMOVED*** ls.add(d.getName());
|
|
***REMOVED*** this.svnUpdater.updateSVN((stagingVRE ? "test_": "") + "r_cran_pkgs.txt", ls);
|
|
***REMOVED*** ***REMOVED***
|
|
***REMOVED*** if (d.getType().equals("github")) {
|
|
***REMOVED*** List<String> ls = new LinkedList<String>();
|
|
***REMOVED*** ls.add(d.getName());
|
|
***REMOVED*** this.svnUpdater.updateSVN((stagingVRE ? "test_": "") + "r_github_pkgs.txt", ls);
|
|
***REMOVED*** ***REMOVED***
|
|
***REMOVED*** ***REMOVED***
|
|
***REMOVED******REMOVED***
|
|
|
|
***REMOVED***
|