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

100 lines
3.6 KiB
Java

package org.gcube.dataanalysis.dataminer.poolmanager.service;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
***REMOVED***
***REMOVED***
***REMOVED***
import org.gcube.dataanalysis.dataminer.poolmanager.datamodel.Cluster;
import org.gcube.dataanalysis.dataminer.poolmanager.util.CheckPermission;
import org.gcube.dataanalysis.dataminer.poolmanager.util.NotificationHelper;
import org.gcube.dataanalysis.dataminer.poolmanager.util.SVNUpdater;
import org.gcube.dataanalysis.dataminer.poolmanager.util.SendMail;
public class ProductionPublishingJob extends DMPMJob ***REMOVED***
private Algorithm algorithm;
***REMOVED***private Cluster prodCluster;
private String targetVREName;
private String targetVREToken;
public ProductionPublishingJob(SVNUpdater svnUpdater, Algorithm algorithm, /*Cluster prodCluster,*/ String targetVREName, String targetVREToken) throws FileNotFoundException, UnsupportedEncodingException ***REMOVED***
super(svnUpdater);
this.algorithm = algorithm;
***REMOVED***this.prodCluster = prodCluster;
this.targetVREName = targetVREName;
this.targetVREToken = targetVREToken;
this.jobLogs = new File(System.getProperty("user.home") + File.separator + "dataminer-pool-manager" + File.separator + "jobs");
this.jobLogs.mkdirs();
***REMOVED***
***REMOVED***
protected void execute() ***REMOVED***
SendMail sm = new SendMail();
NotificationHelper nh = new NotificationHelper();
try ***REMOVED***
if (CheckPermission.apply(targetVREToken,targetVREName))***REMOVED***
***REMOVED***this.svnUpdater.updateProdDeps(this.algorithm);
this.svnUpdater.updateSVNProdAlgorithmList(this.algorithm, this.targetVREName, this.algorithm.getFullname(), "Prod");
this.getStatus(9);
sm.sendNotification(nh.getSuccessSubjectRelease() + " for "+this.algorithm.getName()+ " algorithm", nh.getSuccessBodyRelease(this.buildInfo()));
return;
***REMOVED***
else this.getStatus(0);
sm.sendNotification(nh.getFailedSubjectRelease() + " for "+this.algorithm.getName()+ " algorithm", nh.getFailedBodyRelease(this.buildInfo()+" The user "+this.algorithm.getFullname()+ " is not authorized to access to the "+ targetVREName+ " VRE"));
return;
***REMOVED*** int ret = this.executeAnsibleWorker(
***REMOVED*** createWorker(this.algorithm, this.prodCluster, false, "gcube"));
***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 == 9) ***REMOVED***
response = "SVN REPOSITORY CORRECTLY UPDATED; THE CRON JOB WILL INSTALL THE ALGORITHM "+ this.algorithm.getName() + " IN THE VRE " + targetVREName;
writer.println(response);
***REMOVED***
if (exitstatus == 0) ***REMOVED***
response = "SVN REPOSITORY UPDATE FAI; THE CRON JOB WILL NOT BE ABLE TO INSTALL THE ALGORITHM "+this.algorithm.getName()+" IN THE VRE " + targetVREName;;
writer.println(response);
***REMOVED***writer.close();
***REMOVED***
writer.close();
return response;
***REMOVED***
public String buildInfo()***REMOVED***
return
"\n"+
"Algorithm details:\n"+"\n"+
"User: "+this.algorithm.getFullname()+"\n"+
"Algorithm name: "+this.algorithm.getName()+"\n"+
"Caller VRE: "+ScopeProvider.instance.get()+"\n"+
"Target VRE: "+targetVREName+"\n";
***REMOVED***
***REMOVED***