dataminer-pool-manager/src/main/java/org/gcube/dataanalysis/dataminer/poolmanager/service/StagingJob.java

164 lines
5.5 KiB
Java

package org.gcube.dataanalysis.dataminer.poolmanager.service;
import static org.gcube.common.authorization.client.Constants.authorizationService;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.Collection;
import org.gcube.common.authorization.library.AuthorizationEntry;
***REMOVED***
***REMOVED***
***REMOVED***
import org.gcube.dataanalysis.dataminer.poolmanager.datamodel.Cluster;
import org.gcube.dataanalysis.dataminer.poolmanager.util.CheckMethod;
import org.gcube.dataanalysis.dataminer.poolmanager.util.NotificationHelper;
import org.gcube.dataanalysis.dataminer.poolmanager.util.SVNUpdater;
import org.gcube.dataanalysis.dataminer.poolmanager.util.SendMail;
import org.gcube.dataanalysis.dataminer.poolmanager.util.ServiceConfiguration;
import org.gcube.smartgears.ContextProvider;
import org.gcube.smartgears.context.application.ApplicationContext;
public class StagingJob extends DMPMJob ***REMOVED***
private Algorithm algorithm;
private Cluster stagingCluster;
***REMOVED*** private Cluster rProtoCluster;
private String rProtoVREName;
private String env;
public StagingJob(SVNUpdater svnUpdater, Algorithm algorithm,
Cluster stagingCluster, /* Cluster rProtoCluster, */
String rProtoVREName, String env) throws FileNotFoundException, UnsupportedEncodingException ***REMOVED***
super(svnUpdater);
this.jobLogs = new File(
System.getProperty("user.home") + File.separator + "dataminer-pool-manager" + File.separator + "jobs");
this.jobLogs.mkdirs();
this.algorithm = algorithm;
this.stagingCluster = stagingCluster;
***REMOVED*** this.rProtoCluster = rProtoCluster;
this.rProtoVREName = rProtoVREName;
this.env = env;
***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();
***REMOVED***
***REMOVED***
protected void execute() ***REMOVED***
ServiceConfiguration a = new ServiceConfiguration();
CheckMethod b = new CheckMethod();
SendMail sm = new SendMail();
NotificationHelper nh = new NotificationHelper();
try ***REMOVED***
Collection<String> undefinedDependencies = this.svnUpdater.getUndefinedDependencies(
this.svnUpdater.getDependencyFile(this.algorithm.getLanguage(),env),
this.algorithm.getDependencies());
if (!undefinedDependencies.isEmpty()) ***REMOVED***
String message = "Following dependencies are not defined:\n";
for (String n : undefinedDependencies) ***REMOVED***
message += "\n" + n +"\n";
***REMOVED***
this.getStatus(2);
sm.sendNotification(nh.getFailedSubject() +" for "+this.algorithm.getName()+ " algorithm", nh.getFailedBody(message+this.buildInfo()));
return;
***REMOVED***
int ret = this.executeAnsibleWorker(createWorker(this.algorithm, this.stagingCluster, false, "root"));
if (ret != 0) ***REMOVED***
this.getStatus(2);
sm.sendNotification(nh.getFailedSubject() + " for "+this.algorithm.getName()+ " algorithm", nh.getFailedBody(this.buildInfo()+"Installation failed. Return code=" + ret));
return;
***REMOVED***
if (ret == 0) ***REMOVED***
this.getStatus(0);
if (b.checkMethod(a.getHost(this.env), SecurityTokenProvider.instance.get())
&& (b.algoExists(this.algorithm, this.env))) ***REMOVED***
System.out.println("Interface check ok!");
System.out.println("Both the files exist at the correct path!");
this.svnUpdater.updateSVNAlgorithmList(this.algorithm, this.rProtoVREName,
this.algorithm.getFullname(), env);
this.getStatus(9);
sm.sendNotification(nh.getSuccessSubject() + " for "+this.algorithm.getName()+ " algorithm", nh.getSuccessBody(this.buildInfo()));
return;
***REMOVED*** else
this.getStatus(2);
sm.sendNotification(nh.getFailedSubject() + " for "+this.algorithm.getName()+ " algorithm",
nh.getFailedBody(
this.buildInfo()+"\n"+
"Installation completed but DataMiner Interface not working correctly or files "
+ this.algorithm.getName() + ".jar and " + this.algorithm.getName()
+ "_interface.jar not availables at the expected path"));
return;
***REMOVED***
***REMOVED*** catch (Exception e) ***REMOVED***
e.printStackTrace();
***REMOVED***
***REMOVED***
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);
***REMOVED***writer.close();
***REMOVED***
if (exitstatus == 9) ***REMOVED***
response = "COMPLETED";
writer.println(response);
***REMOVED***writer.close();
***REMOVED***
if (exitstatus == 2) ***REMOVED***
response = "FAILED";
writer.println(response);
***REMOVED***writer.close();
***REMOVED***
writer.close();
return response;
***REMOVED***
public String buildInfo()***REMOVED***
ServiceConfiguration a = new ServiceConfiguration();
return
"\n"+
"Algorithm details:\n"+"\n"+
"User: "+this.algorithm.getFullname()+"\n"+
"Algorithm name: "+this.algorithm.getName()+"\n"+
"Staging DataMiner Host: "+ a.getHost(this.env)+"\n"+
"Caller VRE: "+rProtoVREName+"\n"+
"Target VRE: "+rProtoVREName+"\n";
***REMOVED***
***REMOVED***