154 lines
5.1 KiB
Java
154 lines
5.1 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;
|
|
|
|
public class StagingJob extends DMPMJob ***REMOVED***
|
|
|
|
private Algorithm algorithm;
|
|
private Cluster stagingCluster;
|
|
***REMOVED*** private Cluster rProtoCluster;
|
|
private String rProtoVREName;
|
|
|
|
public StagingJob(SVNUpdater svnUpdater, Algorithm algorithm,
|
|
Cluster stagingCluster, /* Cluster rProtoCluster, */
|
|
String rProtoVREName) 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;
|
|
|
|
File m = new File(this.jobLogs + File.separator + this.id + "_exitStatus");
|
|
PrintWriter writer = new PrintWriter(m, "UTF-8");
|
|
writer.println(this.getStatus(0));
|
|
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.getRProtoDependencyFile(this.algorithm.getLanguage()),
|
|
this.algorithm.getDependencies());
|
|
|
|
if (!undefinedDependencies.isEmpty()) ***REMOVED***
|
|
|
|
String message = "Following dependencies are not defined:\n";
|
|
for (String n : undefinedDependencies) ***REMOVED***
|
|
message += "\n" + n;
|
|
***REMOVED***
|
|
|
|
sm.sendNotification(nh.getFailedSubject() +" for "+this.algorithm.getName()+ " algorithm", nh.getFailedBody(this.buildInfo()+message));
|
|
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.getStagingHost(), SecurityTokenProvider.instance.get())
|
|
&& (b.algoExists(this.algorithm))) ***REMOVED***
|
|
|
|
System.out.println("Interface check ok!");
|
|
System.out.println("Both the files exist at the correct path!");
|
|
|
|
this.svnUpdater.updateSVNRProtoAlgorithmList(this.algorithm, this.rProtoVREName,
|
|
this.algorithm.getFullname(), "Proto");
|
|
|
|
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);
|
|
writer.close();
|
|
***REMOVED***
|
|
|
|
if (exitstatus == 9) ***REMOVED***
|
|
response = "COMPLETED";
|
|
writer.println(response);
|
|
writer.close();
|
|
***REMOVED***
|
|
|
|
if (exitstatus == 2) ***REMOVED***
|
|
response = "FAILED";
|
|
writer.println(response);
|
|
writer.close();
|
|
***REMOVED***
|
|
return response;
|
|
***REMOVED***
|
|
|
|
|
|
public String buildInfo()***REMOVED***
|
|
ServiceConfiguration a = new ServiceConfiguration();
|
|
return
|
|
"\n"+
|
|
"\n"+
|
|
"User: "+this.algorithm.getFullname()+"\n"+
|
|
"Algorithm name: "+this.algorithm.getName()+"\n"+
|
|
"Staging DataMiner Host: "+ a.getStagingHost()+
|
|
"Caller VRE: "+rProtoVREName+
|
|
"Target VRE: "+rProtoVREName;
|
|
***REMOVED***
|
|
|
|
***REMOVED***
|