From 0d82f32a3b4aa746ab717306cee2af3fa1aa56d6 Mon Sep 17 00:00:00 2001 From: Nunzio Andrea Galante Date: Mon, 24 Jul 2017 10:32:18 +0000 Subject: [PATCH] git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-analysis/dataminer-pool-manager@151222 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../service/ProductionPublishingJob.java | 51 +++++++++++++++++-- .../poolmanager/service/StagingJob.java | 22 ++++++-- .../poolmanager/util/CheckPermission.java | 4 +- .../poolmanager/util/NotificationHelper.java | 24 ++++++++- 4 files changed, 89 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/gcube/dataanalysis/dataminer/poolmanager/service/ProductionPublishingJob.java b/src/main/java/org/gcube/dataanalysis/dataminer/poolmanager/service/ProductionPublishingJob.java index 6c73e1f..c5514dd 100644 --- a/src/main/java/org/gcube/dataanalysis/dataminer/poolmanager/service/ProductionPublishingJob.java +++ b/src/main/java/org/gcube/dataanalysis/dataminer/poolmanager/service/ProductionPublishingJob.java @@ -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*** import org.gcube.dataanalysis.dataminer.poolmanager.datamodel.Algorithm; ***REMOVED*** ***REMOVED*** +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 { @@ -14,26 +21,33 @@ public class ProductionPublishingJob extends DMPMJob { private String targetVREName; private String targetVREToken; - public ProductionPublishingJob(SVNUpdater svnUpdater, Algorithm algorithm, /*Cluster prodCluster,*/ String targetVREName, String targetVREToken) { + public ProductionPublishingJob(SVNUpdater svnUpdater, Algorithm algorithm, /*Cluster prodCluster,*/ String targetVREName, String targetVREToken) throws FileNotFoundException, UnsupportedEncodingException { 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*** @Override protected void execute() { + SendMail sm = new SendMail(); + NotificationHelper nh = new NotificationHelper(); try { if (CheckPermission.apply(targetVREToken,targetVREName)){ ***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*** + public String getStatus(int exitstatus) throws FileNotFoundException, UnsupportedEncodingException { + + File m = new File(this.jobLogs + File.separator + this.id); + PrintWriter writer = new PrintWriter(m, "UTF-8"); + + String response = ""; + + if (exitstatus == 9) { + 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(){ + 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*** diff --git a/src/main/java/org/gcube/dataanalysis/dataminer/poolmanager/service/StagingJob.java b/src/main/java/org/gcube/dataanalysis/dataminer/poolmanager/service/StagingJob.java index 0d6350d..ae2107b 100644 --- a/src/main/java/org/gcube/dataanalysis/dataminer/poolmanager/service/StagingJob.java +++ b/src/main/java/org/gcube/dataanalysis/dataminer/poolmanager/service/StagingJob.java @@ -66,7 +66,7 @@ public class StagingJob extends DMPMJob { 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 { if (ret != 0) { 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 { 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 { return response; ***REMOVED*** + + public String buildInfo(){ + 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*** diff --git a/src/main/java/org/gcube/dataanalysis/dataminer/poolmanager/util/CheckPermission.java b/src/main/java/org/gcube/dataanalysis/dataminer/poolmanager/util/CheckPermission.java index db8b151..fe70170 100644 --- a/src/main/java/org/gcube/dataanalysis/dataminer/poolmanager/util/CheckPermission.java +++ b/src/main/java/org/gcube/dataanalysis/dataminer/poolmanager/util/CheckPermission.java @@ -17,10 +17,10 @@ public class CheckPermission { AuthorizationEntry entry = authorizationService().get(VREToken); if (entry.getContext().equals(vre)) { - 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*** diff --git a/src/main/java/org/gcube/dataanalysis/dataminer/poolmanager/util/NotificationHelper.java b/src/main/java/org/gcube/dataanalysis/dataminer/poolmanager/util/NotificationHelper.java index 1ec0a7c..5978f53 100644 --- a/src/main/java/org/gcube/dataanalysis/dataminer/poolmanager/util/NotificationHelper.java +++ b/src/main/java/org/gcube/dataanalysis/dataminer/poolmanager/util/NotificationHelper.java @@ -17,6 +17,10 @@ public class NotificationHelper { private String getSubjectHeader() { return "[DataMinerGhostInstallationRequestReport]"; ***REMOVED*** + + private String getSubjectHeaderRelease() { + return "[DataMinerReleaseInstallationRequestReport]"; + ***REMOVED*** private boolean isError() { return this.executionException!=null; @@ -30,13 +34,23 @@ public class NotificationHelper { return this.getSubjectHeader()+" is SUCCESS"; ***REMOVED*** + public String getSuccessSubjectRelease() { + return this.getSubjectHeaderRelease()+" is SUCCESS"; + ***REMOVED*** + + + public String getFailedSubjectRelease() { + return this.getSubjectHeaderRelease()+" is FAILED"; + ***REMOVED*** + + public String getFailedSubject() { return String.format(this.getSubjectHeader()+" is FAILED"); ***REMOVED*** - public String getSuccessBody() { + public String getSuccessBody(String info) { 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 { return body; ***REMOVED*** + public String getSuccessBodyRelease(String info) { + 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*** if(this.isError()) { ***REMOVED*** return this.getFailedSubject();