This commit is contained in:
Nunzio Andrea Galante 2017-07-06 12:54:04 +00:00
parent ac7fe0f1ef
commit 73d4602510
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");
// SecurityTokenProvider.instance.set("708e7eb8-11a7-4e9a-816b-c9ed7e7e99fe-98187548");
//AuthorizationEntry entry = authorizationService().get("708e7eb8-11a7-4e9a-816b-c9ed7e7e99fe-98187548");
//System.out.println(entry.getContext());
// AuthorizationEntry entry = authorizationService().get("708e7eb8-11a7-4e9a-816b-c9ed7e7e99fe-98187548");
// System.out.println(entry.getContext());
RestPoolManager a = new RestPoolManager();

View File

@ -9,6 +9,7 @@ import org.gcube.dataanalysis.dataminer.poolmanager.datamodel.Algorithm;
import org.gcube.dataanalysis.dataminer.poolmanager.datamodel.Cluster;
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("", "");
// this.svnUpdater.updateRPRotoDeps(this.algorithm);
this.svnUpdater.updateSVNRProtoAlgorithmList(this.algorithm, this.rProtoVREName,
this.algorithm.getFullname(), "Proto");
// int ret2 = this.executeAnsibleWorker(
// createWorker(this.algorithm, this.rProtoCluster,
// false, "gcube"));
}
}
}
else sm.sendNotification("", "");
} catch (Exception e) {
e.printStackTrace();

View File

@ -33,7 +33,7 @@ public class NotificationHelper {
}
private String getSubjectHeader() {
return "[[DataMinerGhostInstallationRequestReport]]";
return "[DataMinerGhostInstallationRequestReport]";
}
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;
}
@ -216,6 +218,8 @@ public class SVNUpdater {
check = true;
} else
check = false;
Exception e = new Exception("One or more of the following dependencies are not correctly written: "+b);
throw e;
}
}
}

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;
import java.util.LinkedList;
import java.util.List;
import org.apache.activemq.transport.stomp.Stomp.Headers.Send;
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
import org.gcube.common.authorization.library.AuthorizationEntry;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider;
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);
// 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();
}
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://", "http://").replace(":80", ""); // 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;
}
return response;
}
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]);
}
s.add(this.username(SecurityTokenProvider.instance.get()));
}
System.out.println(s);
return s.toString();
}
@Override
public String getDescription() {
// TODO Auto-generated method stub
@ -91,11 +160,20 @@ public void sendNotification(String subject, String body) throws Exception {
}
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");
// ScopeProvider.instance.set("/d4science.research-infrastructures.eu/gCubeApps/RPrototypingLab");
// 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());
//sm.username(SecurityTokenProvider.instance.get());
//sm.retrieveAdminRole();
sm.getAdmins();
//sm.sendNotification("test", "test");
}
}