This commit is contained in:
Nunzio Andrea Galante 2017-07-06 12:54:04 +00:00
parent 62088fcd1d
commit 2c7aebf178
6 changed files with 105 additions and 20 deletions

View File

@ -60,6 +60,11 @@
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20090211</version>
</dependency>
<dependency>
<groupId>org.tmatesoft.svnkit</groupId>

View File

@ -87,8 +87,8 @@ public class RestPoolManager implements PoolManager {
ScopeProvider.instance.set("/d4science.research-infrastructures.eu/gCubeApps/RPrototypingLab");
***REMOVED*** SecurityTokenProvider.instance.set("708e7eb8-11a7-4e9a-816b-c9ed7e7e99fe-98187548");
***REMOVED***AuthorizationEntry entry = authorizationService().get("708e7eb8-11a7-4e9a-816b-c9ed7e7e99fe-98187548");
***REMOVED***System.out.println(entry.getContext());
***REMOVED*** AuthorizationEntry entry = authorizationService().get("708e7eb8-11a7-4e9a-816b-c9ed7e7e99fe-98187548");
***REMOVED*** System.out.println(entry.getContext());
RestPoolManager a = new RestPoolManager();

View File

@ -9,6 +9,7 @@ import org.gcube.dataanalysis.dataminer.poolmanager.datamodel.Algorithm;
***REMOVED***
import org.gcube.dataanalysis.dataminer.poolmanager.util.CheckMethod;
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 {
@ -36,35 +37,32 @@ public class StagingJob extends DMPMJob {
protected void execute() {
ServiceConfiguration a = new ServiceConfiguration();
CheckMethod b = new CheckMethod();
SendMail sm = new SendMail();
try {
if (this.svnUpdater.checkIfAvaialable(this.algorithm.getLanguage(), this.algorithm.getDependencies())) {
this.svnUpdater.readRPRotoDeps(this.algorithm);
int ret = this.executeAnsibleWorker(createWorker(this.algorithm, this.stagingCluster, false, "root"));
if (ret == 0) {
if (b.checkMethod(a.getStagingHost(), SecurityTokenProvider.instance.get())
&& (b.algoExists(this.algorithm))) {
sm.sendNotification("", "");
***REMOVED*** this.svnUpdater.updateRPRotoDeps(this.algorithm);
this.svnUpdater.updateSVNRProtoAlgorithmList(this.algorithm, this.rProtoVREName,
this.algorithm.getFullname(), "Proto");
***REMOVED*** int ret2 = this.executeAnsibleWorker(
***REMOVED*** createWorker(this.algorithm, this.rProtoCluster,
***REMOVED*** false, "gcube"));
***REMOVED***
***REMOVED***
***REMOVED***
else sm.sendNotification("", "");
***REMOVED*** catch (Exception e) {
e.printStackTrace();

View File

@ -33,7 +33,7 @@ public class NotificationHelper {
***REMOVED***
private String getSubjectHeader() {
return "[[DataMinerGhostInstallationRequestReport]]";
return "[DataMinerGhostInstallationRequestReport]";
***REMOVED***
private String getSpecificVREName() {

View File

@ -190,6 +190,9 @@ public class SVNUpdater {
public boolean checkIfAvaialable(String file, Collection<Dependency> deps) throws SVNException {
SendMail sm = new SendMail();
NotificationHelper nh = new NotificationHelper();
boolean check = false;
try{
System.out.println("Checking dependencies list: " + file);
@ -198,9 +201,8 @@ public class SVNUpdater {
String lines[] = byteArrayOutputStream.toString().split("\\r?\\n");
if(deps.isEmpty()){
SendMail sm = new SendMail();
NotificationHelper nh = new NotificationHelper();
sm.sendNotification(nh.getSubject(), nh.getBody());
Exception e = new Exception("No dependency specified for this algorithm");
throw e;
***REMOVED***
@ -216,6 +218,8 @@ public class SVNUpdater {
check = true;
***REMOVED*** else
check = false;
Exception e = new Exception("One or more of the following dependencies are not correctly written: "+b);
throw e;
***REMOVED***
***REMOVED***
***REMOVED***

View File

@ -1,14 +1,24 @@
package org.gcube.dataanalysis.dataminer.poolmanager.util;
import static org.gcube.common.authorization.client.Constants.authorizationService;
import java.net.URLEncoder;
***REMOVED***
***REMOVED***
import org.apache.activemq.transport.stomp.Stomp.Headers.Send;
***REMOVED***
import org.gcube.common.authorization.library.AuthorizationEntry;
***REMOVED***
***REMOVED***
import org.gcube.contentmanagement.graphtools.utils.HttpRequest;
import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger;
import org.gcube.dataanalysis.ecoengine.interfaces.StandardLocalInfraAlgorithm;
import org.gcube.dataanalysis.executor.util.InfraRetrieval;
import org.json.JSONArray;
import org.json.JSONObject;
import com.sun.xml.internal.bind.v2.runtime.unmarshaller.XsiNilLoader.Array;
public class SendMail extends StandardLocalInfraAlgorithm {
@ -30,11 +40,13 @@ public void sendNotification(String subject, String body) throws Exception {
AnalysisLogger.getLogger().debug("Emailing System->Request url is going to be " + requestForMessage);
***REMOVED*** put the sender, the recipients, subject and body of the mail here
subject=URLEncoder.encode(subject,"UTF-8");
body=URLEncoder.encode(body,"UTF-8");
String requestParameters = "sender=dataminer&recipients="+SecurityTokenProvider.instance.get()+"&subject="+subject+"&body="+body;
String requestParameters = "&sender=dataminer&recipients="+this.getAdmins()+"&subject="+subject+"&body="+body;
String response = HttpRequest.sendPostRequest(requestForMessage, requestParameters);
AnalysisLogger.getLogger().debug("Emailing System->Emailing response OK ");
@ -52,6 +64,63 @@ public void sendNotification(String subject, String body) throws Exception {
public String username(String token) throws ObjectNotFound, Exception{
AuthorizationEntry entry = authorizationService().get(token);
System.out.println(entry.getClientInfo().getId());
return entry.getClientInfo().getId();
***REMOVED***
public String retrieveAdminRole() throws Exception{
String serviceAddress = InfraRetrieval.findEmailingSystemAddress(ScopeProvider.instance.get());
if (!serviceAddress.endsWith("/"))
serviceAddress = serviceAddress+"/";
String requestForMessage = serviceAddress + "2/users/get-usernames-by-global-role";
requestForMessage = requestForMessage.replace("https:***REMOVED***", "http:***REMOVED***").replace(":80", ""); ***REMOVED*** remove the port (or set it to 443) otherwise you get an SSL error
String requestParameters = "role-name=Administrator"+"&gcube-token=" + SecurityTokenProvider.instance.get();
String response = HttpRequest.sendGetRequest(requestForMessage,requestParameters);
System.out.println(response.toString());
if (response==null){
Exception e = new Exception("Error in querying the recipient");
throw e;
***REMOVED***
return response;
***REMOVED***
public String getAdmins() throws Exception {
List<String> s = new LinkedList<String>();
JSONObject obj = new JSONObject(this.retrieveAdminRole());
JSONArray data = obj.getJSONArray("result");
if (data != null) {
String[] names = new String[data.length()];
for (int i = 0; i < data.length(); i++) {
names[i] = data.getString(i);
s.add(names[i]);
***REMOVED***
s.add(this.username(SecurityTokenProvider.instance.get()));
***REMOVED***
System.out.println(s);
return s.toString();
***REMOVED***
@Override
public String getDescription() {
***REMOVED*** TODO Auto-generated method stub
@ -91,11 +160,20 @@ public void sendNotification(String subject, String body) throws Exception {
***REMOVED***
public static void main(String[] args) throws Exception {
ScopeProvider.instance.set("/d4science.research-infrastructures.eu/gCubeApps/RPrototypingLab");
SecurityTokenProvider.instance.set("3a23bfa4-4dfe-44fc-988f-194b91071dd2-843339462");
***REMOVED*** ScopeProvider.instance.set("/d4science.research-infrastructures.eu/gCubeApps/RPrototypingLab");
***REMOVED*** SecurityTokenProvider.instance.set("3a23bfa4-4dfe-44fc-988f-194b91071dd2-843339462");
ScopeProvider.instance.set("/gcube/devNext");
SecurityTokenProvider.instance.set("708e7eb8-11a7-4e9a-816b-c9ed7e7e99fe-98187548");
NotificationHelper nh = new NotificationHelper();
SendMail sm = new SendMail();
sm.sendNotification(nh.getSubject(), nh.getBody());
***REMOVED***sm.username(SecurityTokenProvider.instance.get());
***REMOVED***sm.retrieveAdminRole();
sm.getAdmins();
***REMOVED***sm.sendNotification("test", "test");
***REMOVED***
***REMOVED***