2017-05-12 17:32:14 +02:00
|
|
|
package org.gcube.dataanalysis.dataminer.poolmanager.service;
|
|
|
|
|
2017-06-19 18:34:44 +02:00
|
|
|
import static org.gcube.common.authorization.client.Constants.authorizationService;
|
|
|
|
|
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
|
|
|
import org.gcube.common.authorization.library.AuthorizationEntry;
|
|
|
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
2017-06-30 15:49:04 +02:00
|
|
|
import org.gcube.common.scope.api.ScopeProvider;
|
2017-05-12 17:32:14 +02:00
|
|
|
import org.gcube.dataanalysis.dataminer.poolmanager.datamodel.Algorithm;
|
|
|
|
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-06-30 15:49:04 +02:00
|
|
|
import org.gcube.dataanalysis.dataminer.poolmanager.util.ServiceConfiguration;
|
2017-07-24 16:50:38 +02:00
|
|
|
import org.gcube.smartgears.ContextProvider;
|
|
|
|
import org.gcube.smartgears.context.application.ApplicationContext;
|
2017-05-12 17:32:14 +02:00
|
|
|
|
|
|
|
public class StagingJob extends DMPMJob {
|
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
|
|
|
// private Cluster rProtoCluster;
|
2017-05-17 18:16:25 +02:00
|
|
|
private String rProtoVREName;
|
2017-09-20 18:51:21 +02:00
|
|
|
//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-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 {
|
2017-05-12 17:32:14 +02:00
|
|
|
super(svnUpdater);
|
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
|
|
|
// this.rProtoCluster = rProtoCluster;
|
2017-05-17 18:16:25 +02:00
|
|
|
this.rProtoVREName = rProtoVREName;
|
2017-09-20 18:51:21 +02:00
|
|
|
//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
|
|
|
//File m = new File(this.jobLogs + File.separator + this.id + "_exitStatus");
|
|
|
|
//PrintWriter writer = new PrintWriter(m, "UTF-8");
|
|
|
|
this.getStatus(0);
|
|
|
|
//writer.close();
|
2017-07-18 15:22:29 +02:00
|
|
|
|
2017-05-12 17:32:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void execute() {
|
2017-06-30 15:49:04 +02:00
|
|
|
ServiceConfiguration a = new ServiceConfiguration();
|
|
|
|
CheckMethod b = 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 {
|
2017-07-05 17:50:42 +02:00
|
|
|
|
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
|
|
|
|
|
|
|
if (!undefinedDependencies.isEmpty()) {
|
|
|
|
|
|
|
|
String message = "Following dependencies are not defined:\n";
|
|
|
|
for (String n : undefinedDependencies) {
|
2017-07-26 21:21:07 +02:00
|
|
|
message += "\n" + n +"\n";
|
2017-07-06 17:34:45 +02:00
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2017-07-31 13:21:47 +02:00
|
|
|
//before the installation to check if the files exist
|
2017-09-20 18:51:21 +02:00
|
|
|
b.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
|
|
|
|
|
|
|
if (ret != 0) {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-07-06 17:34:45 +02:00
|
|
|
if (ret == 0) {
|
2017-07-13 18:13:18 +02:00
|
|
|
this.getStatus(0);
|
2017-09-20 18:51:21 +02:00
|
|
|
//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
|
|
|
//System.out.println("2 - Checking existing in env: "+ this.env);
|
2017-07-05 17:50:42 +02:00
|
|
|
|
2017-07-26 23:46:07 +02:00
|
|
|
|
2017-10-27 23:30:20 +02:00
|
|
|
if (b.checkMethod(a.getStagingHost(), SecurityTokenProvider.instance.get())&&(b.algoExists(this.algorithm))) {
|
2017-07-18 15:22:29 +02:00
|
|
|
|
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
|
|
|
} else
|
|
|
|
this.getStatus(2);
|
2017-07-24 12:32:18 +02: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-07-13 18:13:18 +02:00
|
|
|
}
|
2017-05-12 17:32:14 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-13 18:13:18 +02:00
|
|
|
public String getStatus(int exitstatus) throws FileNotFoundException, UnsupportedEncodingException {
|
|
|
|
|
|
|
|
File m = new File(this.jobLogs + File.separator + this.id + "_exitStatus");
|
|
|
|
PrintWriter writer = new PrintWriter(m, "UTF-8");
|
|
|
|
|
|
|
|
String response = "";
|
|
|
|
|
|
|
|
if (exitstatus == 0) {
|
|
|
|
response = "IN PROGRESS";
|
|
|
|
writer.println(response);
|
2017-07-24 18:51:47 +02:00
|
|
|
//writer.close();
|
2017-07-13 18:13:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (exitstatus == 9) {
|
|
|
|
response = "COMPLETED";
|
|
|
|
writer.println(response);
|
2017-07-24 18:51:47 +02:00
|
|
|
//writer.close();
|
2017-07-13 18:13:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (exitstatus == 2) {
|
|
|
|
response = "FAILED";
|
|
|
|
writer.println(response);
|
2017-07-24 18:51:47 +02:00
|
|
|
//writer.close();
|
2017-07-13 18:13:18 +02:00
|
|
|
}
|
2017-07-24 18:51:47 +02:00
|
|
|
writer.close();
|
2017-07-13 18:13:18 +02:00
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
2017-07-24 12:32:18 +02:00
|
|
|
|
2017-10-30 22:38:11 +01:00
|
|
|
public String buildInfo() throws UnsupportedEncodingException{
|
2017-07-24 12:32:18 +02:00
|
|
|
ServiceConfiguration a = new ServiceConfiguration();
|
|
|
|
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-09-20 18:51:21 +02:00
|
|
|
"Staging DataMiner Host: "+ a.getStagingHost()+"\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
|
|
|
}
|
2017-07-24 16:50:38 +02:00
|
|
|
|
|
|
|
|
2017-07-24 12:32:18 +02:00
|
|
|
|
2017-05-12 17:32:14 +02:00
|
|
|
}
|