This commit is contained in:
Nunzio Andrea Galante 2017-07-24 10:32:18 +00:00
parent 1217ed589b
commit a6d01da01a
4 changed files with 89 additions and 12 deletions

View File

@ -1,11 +1,18 @@
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***
@ -14,26 +21,33 @@ public class ProductionPublishingJob extends DMPMJob ***REMOVED***
private String targetVREName;
private String targetVREToken;
public ProductionPublishingJob(SVNUpdater svnUpdater, Algorithm algorithm, /*Cluster prodCluster,*/ String targetVREName, String targetVREToken) ***REMOVED***
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()));
***REMOVED***
***REMOVED*** int ret = this.executeAnsibleWorker(
***REMOVED*** createWorker(this.algorithm, this.prodCluster, false, "gcube"));
@ -43,5 +57,34 @@ public class ProductionPublishingJob extends DMPMJob ***REMOVED***
***REMOVED***
public String getStatus(int exitstatus) throws FileNotFoundException, UnsupportedEncodingException ***REMOVED***
File m = new File(this.jobLogs + File.separator + this.id);
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);
writer.close();
***REMOVED***
return response;
***REMOVED***
public String buildInfo()***REMOVED***
return
"\n"+
"\n"+
"User: "+this.algorithm.getFullname()+"\n"+
"Algorithm name: "+this.algorithm.getName()+"\n"+
"Caller VRE: "+ScopeProvider.instance.get()+"\n"+
"Target VRE: "+ targetVREToken;
***REMOVED***
***REMOVED***

View File

@ -66,7 +66,7 @@ public class StagingJob extends DMPMJob ***REMOVED***
message += "\n" + n;
***REMOVED***
sm.sendNotification(nh.getFailedSubject(), nh.getFailedBody(message));
sm.sendNotification(nh.getFailedSubject() +" for "+this.algorithm.getName()+ " algorithm", nh.getFailedBody(this.buildInfo()+message));
return;
***REMOVED***
@ -75,7 +75,7 @@ public class StagingJob extends DMPMJob ***REMOVED***
if (ret != 0) ***REMOVED***
this.getStatus(2);
sm.sendNotification(nh.getFailedSubject(), nh.getFailedBody("Installation failed. Return code=" + ret));
sm.sendNotification(nh.getFailedSubject() + " for "+this.algorithm.getName()+ " algorithm", nh.getFailedBody(this.buildInfo()+"Installation failed. Return code=" + ret));
return;
***REMOVED***
@ -92,12 +92,13 @@ public class StagingJob extends DMPMJob ***REMOVED***
this.algorithm.getFullname(), "Proto");
this.getStatus(9);
sm.sendNotification(nh.getSuccessSubject(), nh.getSuccessBody());
sm.sendNotification(nh.getSuccessSubject() + "for "+this.algorithm.getName()+ " algorithm", nh.getSuccessBody(this.buildInfo()));
return;
***REMOVED*** else
this.getStatus(2);
sm.sendNotification(nh.getFailedSubject(),
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"));
@ -136,4 +137,17 @@ public class StagingJob extends DMPMJob ***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***

View File

@ -17,10 +17,10 @@ public class CheckPermission ***REMOVED***
AuthorizationEntry entry = authorizationService().get(VREToken);
if (entry.getContext().equals(vre)) ***REMOVED***
System.out.println("OK!");
System.out.println("Authorization OK!");
return true;
***REMOVED***
System.out.println("Not a valid token recognized for the VRE: "+vre);
return false;
***REMOVED***

View File

@ -17,6 +17,10 @@ public class NotificationHelper ***REMOVED***
private String getSubjectHeader() ***REMOVED***
return "[DataMinerGhostInstallationRequestReport]";
***REMOVED***
private String getSubjectHeaderRelease() ***REMOVED***
return "[DataMinerReleaseInstallationRequestReport]";
***REMOVED***
private boolean isError() ***REMOVED***
return this.executionException!=null;
@ -30,13 +34,23 @@ public class NotificationHelper ***REMOVED***
return this.getSubjectHeader()+" is SUCCESS";
***REMOVED***
public String getSuccessSubjectRelease() ***REMOVED***
return this.getSubjectHeaderRelease()+" is SUCCESS";
***REMOVED***
public String getFailedSubjectRelease() ***REMOVED***
return this.getSubjectHeaderRelease()+" is FAILED";
***REMOVED***
public String getFailedSubject() ***REMOVED***
return String.format(this.getSubjectHeader()+" is FAILED");
***REMOVED***
public String getSuccessBody() ***REMOVED***
public String getSuccessBody(String info) ***REMOVED***
String message = String.format("The installation of the algorithm in the ghost dataminer is completed successfully.");
message+="\n\nYou can retrieve experiment results under the '/DataMiner' e-Infrastructure Workspace folder or from the DataMiner interface.";
message+="\n\nYou can retrieve experiment results under the '/DataMiner' e-Infrastructure Workspace folder or from the DataMiner interface.\n\n"+ info;
return message;
***REMOVED***
@ -46,6 +60,12 @@ public class NotificationHelper ***REMOVED***
return body;
***REMOVED***
public String getSuccessBodyRelease(String info) ***REMOVED***
String message = String.format("SVN REPOSITORY CORRECTLY UPDATED.");
message+="\n\n The CRON job will install the algorithm in the target VRE \n\n"+ info;
return message;
***REMOVED***
***REMOVED*** public String getSubject() ***REMOVED***
***REMOVED*** if(this.isError()) ***REMOVED***
***REMOVED*** return this.getFailedSubject();