2017-05-12 17:32:14 +02:00
|
|
|
package org.gcube.dataanalysis.dataminer.poolmanager.service;
|
|
|
|
|
2017-07-13 18:13:18 +02:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
import java.io.PrintWriter;
|
|
|
|
import java.io.UnsupportedEncodingException;
|
2017-07-06 17:34:45 +02:00
|
|
|
import java.util.Collection;
|
|
|
|
|
2017-06-19 18:34:44 +02:00
|
|
|
***REMOVED***
|
2017-05-12 17:32:14 +02:00
|
|
|
***REMOVED***
|
2017-11-08 16:12:38 +01:00
|
|
|
import org.gcube.dataanalysis.dataminer.poolmanager.clients.configuration.DMPMClientConfiguratorManager;
|
2017-06-30 15:49:04 +02:00
|
|
|
***REMOVED***
|
2017-05-12 17:32:14 +02:00
|
|
|
import org.gcube.dataanalysis.dataminer.poolmanager.datamodel.Cluster;
|
2017-06-30 15:49:04 +02:00
|
|
|
import org.gcube.dataanalysis.dataminer.poolmanager.util.CheckMethod;
|
2017-07-06 17:34:45 +02:00
|
|
|
import org.gcube.dataanalysis.dataminer.poolmanager.util.NotificationHelper;
|
2017-05-12 17:32:14 +02:00
|
|
|
import org.gcube.dataanalysis.dataminer.poolmanager.util.SVNUpdater;
|
2017-07-06 14:54:04 +02:00
|
|
|
import org.gcube.dataanalysis.dataminer.poolmanager.util.SendMail;
|
2017-11-08 16:12:38 +01:00
|
|
|
***REMOVED***
|
|
|
|
***REMOVED***
|
2017-05-12 17:32:14 +02:00
|
|
|
|
|
|
|
public class StagingJob extends DMPMJob ***REMOVED***
|
2017-07-06 17:34:45 +02:00
|
|
|
|
2017-05-12 17:32:14 +02:00
|
|
|
private Algorithm algorithm;
|
|
|
|
private Cluster stagingCluster;
|
2017-07-13 18:13:18 +02:00
|
|
|
***REMOVED*** private Cluster rProtoCluster;
|
2017-05-17 18:16:25 +02:00
|
|
|
private String rProtoVREName;
|
2017-09-20 18:51:21 +02:00
|
|
|
***REMOVED***private String env;
|
2017-08-29 17:43:31 +02:00
|
|
|
private String category;
|
|
|
|
private String algorithm_type;
|
2017-07-26 21:21:07 +02:00
|
|
|
|
2017-11-08 16:12:38 +01:00
|
|
|
private Logger logger;
|
2017-05-12 17:32:14 +02:00
|
|
|
|
2017-07-13 18:13:18 +02:00
|
|
|
public StagingJob(SVNUpdater svnUpdater, Algorithm algorithm,
|
|
|
|
Cluster stagingCluster, /* Cluster rProtoCluster, */
|
2017-09-20 18:51:21 +02:00
|
|
|
String rProtoVREName, String category, String algorithm_type/*, String env*/) throws FileNotFoundException, UnsupportedEncodingException ***REMOVED***
|
2017-05-12 17:32:14 +02:00
|
|
|
super(svnUpdater);
|
2017-11-08 16:12:38 +01:00
|
|
|
this.logger = LoggerFactory.getLogger(StagingJob.class);
|
|
|
|
|
2017-07-13 18:13:18 +02:00
|
|
|
this.jobLogs = new File(
|
|
|
|
System.getProperty("user.home") + File.separator + "dataminer-pool-manager" + File.separator + "jobs");
|
|
|
|
this.jobLogs.mkdirs();
|
|
|
|
|
2017-05-12 17:32:14 +02:00
|
|
|
this.algorithm = algorithm;
|
|
|
|
this.stagingCluster = stagingCluster;
|
2017-07-13 18:13:18 +02:00
|
|
|
***REMOVED*** this.rProtoCluster = rProtoCluster;
|
2017-05-17 18:16:25 +02:00
|
|
|
this.rProtoVREName = rProtoVREName;
|
2017-09-20 18:51:21 +02:00
|
|
|
***REMOVED***this.env = env;
|
2017-08-29 17:43:31 +02:00
|
|
|
this.category = category;
|
|
|
|
this.algorithm_type = algorithm_type;
|
2017-07-26 21:21:07 +02:00
|
|
|
|
2017-07-18 15:22:29 +02:00
|
|
|
|
2017-07-24 18:51:47 +02:00
|
|
|
***REMOVED***File m = new File(this.jobLogs + File.separator + this.id + "_exitStatus");
|
|
|
|
***REMOVED***PrintWriter writer = new PrintWriter(m, "UTF-8");
|
|
|
|
this.getStatus(0);
|
|
|
|
***REMOVED***writer.close();
|
2017-07-18 15:22:29 +02:00
|
|
|
|
2017-05-12 17:32:14 +02:00
|
|
|
***REMOVED***
|
|
|
|
|
|
|
|
***REMOVED***
|
|
|
|
protected void execute() ***REMOVED***
|
2017-11-08 16:12:38 +01:00
|
|
|
|
|
|
|
this.logger.debug("Executing staging job...");
|
|
|
|
|
|
|
|
CheckMethod methodChecker = new CheckMethod();
|
2017-07-06 14:54:04 +02:00
|
|
|
SendMail sm = new SendMail();
|
2017-07-06 17:34:45 +02:00
|
|
|
NotificationHelper nh = new NotificationHelper();
|
2017-07-05 17:50:42 +02:00
|
|
|
|
2017-05-12 17:32:14 +02:00
|
|
|
try ***REMOVED***
|
2017-07-05 17:50:42 +02:00
|
|
|
|
2017-11-08 16:12:38 +01:00
|
|
|
this.logger.debug("Checking dependencies...");
|
2017-07-06 17:34:45 +02:00
|
|
|
Collection<String> undefinedDependencies = this.svnUpdater.getUndefinedDependencies(
|
2017-09-20 18:51:21 +02:00
|
|
|
this.svnUpdater.getDependencyFile(this.algorithm.getLanguage()/*,env*/),
|
2017-07-13 18:13:18 +02:00
|
|
|
this.algorithm.getDependencies());
|
2017-07-06 17:34:45 +02:00
|
|
|
|
2017-11-08 16:12:38 +01:00
|
|
|
if (!undefinedDependencies.isEmpty())
|
|
|
|
***REMOVED***
|
|
|
|
this.logger.debug("Some dependencies are not defined");
|
2017-07-06 17:34:45 +02:00
|
|
|
String message = "Following dependencies are not defined:\n";
|
|
|
|
for (String n : undefinedDependencies) ***REMOVED***
|
2017-07-26 21:21:07 +02:00
|
|
|
message += "\n" + n +"\n";
|
2017-07-06 17:34:45 +02:00
|
|
|
***REMOVED***
|
2017-07-26 21:21:07 +02:00
|
|
|
this.getStatus(2);
|
2017-07-06 17:34:45 +02:00
|
|
|
|
2017-07-26 21:35:08 +02:00
|
|
|
sm.sendNotification(nh.getFailedSubject() +" for "+this.algorithm.getName()+ " algorithm", nh.getFailedBody(message+"\n\n"+this.buildInfo()));
|
2017-07-06 17:34:45 +02:00
|
|
|
return;
|
|
|
|
***REMOVED***
|
|
|
|
|
2017-07-31 13:21:47 +02:00
|
|
|
***REMOVED***before the installation to check if the files exist
|
2017-11-08 16:12:38 +01:00
|
|
|
methodChecker.deleteFiles(this.algorithm/*, env*/);
|
2017-07-31 13:21:47 +02:00
|
|
|
|
2017-07-06 17:34:45 +02:00
|
|
|
int ret = this.executeAnsibleWorker(createWorker(this.algorithm, this.stagingCluster, false, "root"));
|
2017-10-27 23:30:20 +02:00
|
|
|
System.out.println("Return code= "+ret);
|
2017-07-13 18:13:18 +02:00
|
|
|
|
2017-11-08 16:12:38 +01:00
|
|
|
if (ret != 0)
|
|
|
|
***REMOVED***
|
|
|
|
this.logger.debug("Ansible work failed, return code "+ret);
|
2017-07-13 18:13:18 +02:00
|
|
|
this.getStatus(2);
|
2017-07-26 21:35:08 +02:00
|
|
|
sm.sendNotification(nh.getFailedSubject() + " for "+this.algorithm.getName()+ " algorithm", nh.getFailedBody("Installation failed. Return code=" + ret)+"\n\n"+this.buildInfo());
|
2017-07-18 15:22:29 +02:00
|
|
|
return;
|
2017-07-13 18:13:18 +02:00
|
|
|
***REMOVED***
|
|
|
|
|
2017-11-08 16:12:38 +01:00
|
|
|
if (ret == 0)
|
|
|
|
***REMOVED***
|
|
|
|
this.logger.debug("Operation completed");
|
2017-07-13 18:13:18 +02:00
|
|
|
this.getStatus(0);
|
2017-09-20 18:51:21 +02:00
|
|
|
***REMOVED***System.out.println("1 - Checking existing in env: "+ env);
|
2017-07-26 23:46:07 +02:00
|
|
|
|
2017-09-20 18:51:21 +02:00
|
|
|
***REMOVED***System.out.println("2 - Checking existing in env: "+ this.env);
|
2017-11-08 16:12:38 +01:00
|
|
|
this.logger.debug("Checking the method...");
|
2017-07-05 17:50:42 +02:00
|
|
|
|
2017-07-26 23:46:07 +02:00
|
|
|
|
2017-11-08 16:12:38 +01:00
|
|
|
if (methodChecker.checkMethod(DMPMClientConfiguratorManager.getInstance().getStagingConfiguration().getHost(), SecurityTokenProvider.instance.get())&&(methodChecker.algoExists(this.algorithm)))
|
|
|
|
***REMOVED***
|
|
|
|
this.logger.debug("Method OK and algo exists");
|
2017-07-17 23:52:54 +02:00
|
|
|
System.out.println("Interface check ok!");
|
|
|
|
System.out.println("Both the files exist at the correct path!");
|
2017-07-18 15:22:29 +02:00
|
|
|
|
2017-09-20 18:51:21 +02:00
|
|
|
this.svnUpdater.updateSVNStagingAlgorithmList(this.algorithm, this.rProtoVREName,this.category, this.algorithm_type,
|
|
|
|
this.algorithm.getFullname()/*, env*/);
|
2017-07-18 15:22:29 +02:00
|
|
|
|
2017-07-13 18:13:18 +02:00
|
|
|
this.getStatus(9);
|
2017-07-26 21:35:08 +02:00
|
|
|
sm.sendNotification(nh.getSuccessSubject() + " for "+this.algorithm.getName()+ " algorithm", nh.getSuccessBody("\n\n"+this.buildInfo()));
|
2017-07-18 15:22:29 +02:00
|
|
|
return;
|
2017-07-13 18:13:18 +02:00
|
|
|
***REMOVED*** else
|
2017-11-08 16:12:38 +01:00
|
|
|
***REMOVED***
|
|
|
|
this.logger.debug("Operation failed");
|
2017-07-13 18:13:18 +02:00
|
|
|
this.getStatus(2);
|
2017-11-08 16:12:38 +01:00
|
|
|
sm.sendNotification(nh.getFailedSubject() + " for "+this.algorithm.getName()+ " algorithm",
|
2017-07-18 15:22:29 +02:00
|
|
|
nh.getFailedBody(
|
2017-07-26 23:46:07 +02:00
|
|
|
"\n"+
|
2017-07-18 15:22:29 +02:00
|
|
|
"Installation completed but DataMiner Interface not working correctly or files "
|
|
|
|
+ this.algorithm.getName() + ".jar and " + this.algorithm.getName()
|
2017-07-26 21:35:08 +02:00
|
|
|
+ "_interface.jar not availables at the expected path")+"\n\n"+this.buildInfo());
|
2017-07-18 15:22:29 +02:00
|
|
|
return;
|
2017-11-08 16:12:38 +01:00
|
|
|
***REMOVED***
|
2017-07-13 18:13:18 +02:00
|
|
|
***REMOVED***
|
2017-05-12 17:32:14 +02:00
|
|
|
***REMOVED*** catch (Exception e) ***REMOVED***
|
|
|
|
e.printStackTrace();
|
|
|
|
***REMOVED***
|
|
|
|
***REMOVED***
|
|
|
|
|
2017-07-13 18:13:18 +02:00
|
|
|
public String getStatus(int exitstatus) throws FileNotFoundException, UnsupportedEncodingException ***REMOVED***
|
|
|
|
|
|
|
|
File m = new File(this.jobLogs + File.separator + this.id + "_exitStatus");
|
|
|
|
PrintWriter writer = new PrintWriter(m, "UTF-8");
|
|
|
|
|
|
|
|
String response = "";
|
|
|
|
|
|
|
|
if (exitstatus == 0) ***REMOVED***
|
|
|
|
response = "IN PROGRESS";
|
|
|
|
writer.println(response);
|
2017-07-24 18:51:47 +02:00
|
|
|
***REMOVED***writer.close();
|
2017-07-13 18:13:18 +02:00
|
|
|
***REMOVED***
|
|
|
|
|
|
|
|
if (exitstatus == 9) ***REMOVED***
|
|
|
|
response = "COMPLETED";
|
|
|
|
writer.println(response);
|
2017-07-24 18:51:47 +02:00
|
|
|
***REMOVED***writer.close();
|
2017-07-13 18:13:18 +02:00
|
|
|
***REMOVED***
|
|
|
|
|
|
|
|
if (exitstatus == 2) ***REMOVED***
|
|
|
|
response = "FAILED";
|
|
|
|
writer.println(response);
|
2017-07-24 18:51:47 +02:00
|
|
|
***REMOVED***writer.close();
|
2017-07-13 18:13:18 +02:00
|
|
|
***REMOVED***
|
2017-07-24 18:51:47 +02:00
|
|
|
writer.close();
|
2017-07-13 18:13:18 +02:00
|
|
|
return response;
|
|
|
|
***REMOVED***
|
|
|
|
|
2017-07-24 12:32:18 +02:00
|
|
|
|
2017-10-30 22:38:11 +01:00
|
|
|
public String buildInfo() throws UnsupportedEncodingException***REMOVED***
|
2017-11-08 16:12:38 +01:00
|
|
|
|
2017-07-24 12:32:18 +02:00
|
|
|
return
|
|
|
|
"\n"+
|
2017-07-24 18:51:47 +02:00
|
|
|
"Algorithm details:\n"+"\n"+
|
2017-07-24 12:32:18 +02:00
|
|
|
"User: "+this.algorithm.getFullname()+"\n"+
|
|
|
|
"Algorithm name: "+this.algorithm.getName()+"\n"+
|
2017-11-08 16:12:38 +01:00
|
|
|
"Staging DataMiner Host: "+ DMPMClientConfiguratorManager.getInstance().getStagingConfiguration().getHost()+"\n"+
|
2017-08-29 17:43:31 +02:00
|
|
|
"Caller VRE: "+ScopeProvider.instance.get()+"\n"+
|
2017-07-24 17:57:53 +02:00
|
|
|
"Target VRE: "+rProtoVREName+"\n";
|
2017-07-24 12:32:18 +02:00
|
|
|
***REMOVED***
|
2017-07-24 16:50:38 +02:00
|
|
|
|
|
|
|
|
2017-07-24 12:32:18 +02:00
|
|
|
|
2017-05-12 17:32:14 +02:00
|
|
|
***REMOVED***
|