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

139 lines
4.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;
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(), nh.getFailedBody(message));
return;
***REMOVED***
int ret = this.executeAnsibleWorker(createWorker(this.algorithm, this.stagingCluster, false, "root"));
***REMOVED*** Integer s = null;
***REMOVED*** s = Integer.valueOf(ret);
***REMOVED***
***REMOVED*** if (s == null) ***REMOVED***
***REMOVED*** this.getStatus(0);
***REMOVED*** ***REMOVED***
if (ret != 0) ***REMOVED***
this.getStatus(2);
sm.sendNotification(nh.getFailedSubject(), nh.getFailedBody("Installation failed. Return code=" + ret));
***REMOVED***
if (ret == 0) ***REMOVED***
this.getStatus(0);
if (b.checkMethod(a.getStagingHost(), SecurityTokenProvider.instance.get())
&& (b.algoExists(this.algorithm))) ***REMOVED***
this.svnUpdater.updateSVNRProtoAlgorithmList(this.algorithm, this.rProtoVREName,
this.algorithm.getFullname(), "Proto");
this.getStatus(9);
sm.sendNotification(nh.getSuccessSubject(), nh.getSuccessBody());
***REMOVED*** else
this.getStatus(2);
sm.sendNotification(nh.getFailedSubject(),
nh.getFailedBody("DataMiner Interface not working or files " + this.algorithm.getName()
+ ".jar and " + this.algorithm.getName()
+ "_interface.jar not available at the expected path"));
***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***
***REMOVED***