git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-analysis/dataminer-pool-manager@150838 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
3dabd84dad
commit
9abc3752a2
5
pom.xml
5
pom.xml
|
@ -60,6 +60,11 @@
|
|||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.json</groupId>
|
||||
<artifactId>json</artifactId>
|
||||
<version>20090211</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.tmatesoft.svnkit</groupId>
|
||||
|
|
|
@ -9,6 +9,7 @@ import org.gcube.common.authorization.library.AuthorizationEntry;
|
|||
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 ***REMOVED***
|
||||
|
@ -36,35 +37,32 @@ public class StagingJob extends DMPMJob ***REMOVED***
|
|||
protected void execute() ***REMOVED***
|
||||
ServiceConfiguration a = new ServiceConfiguration();
|
||||
CheckMethod b = new CheckMethod();
|
||||
SendMail sm = new SendMail();
|
||||
|
||||
|
||||
try ***REMOVED***
|
||||
|
||||
if (this.svnUpdater.checkIfAvaialable(this.algorithm.getLanguage(), this.algorithm.getDependencies())) ***REMOVED***
|
||||
this.svnUpdater.readRPRotoDeps(this.algorithm);
|
||||
int ret = this.executeAnsibleWorker(createWorker(this.algorithm, this.stagingCluster, false, "root"));
|
||||
|
||||
|
||||
|
||||
|
||||
if (ret == 0) ***REMOVED***
|
||||
|
||||
if (b.checkMethod(a.getStagingHost(), SecurityTokenProvider.instance.get())
|
||||
&& (b.algoExists(this.algorithm))) ***REMOVED***
|
||||
|
||||
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) ***REMOVED***
|
||||
e.printStackTrace();
|
||||
|
|
|
@ -33,7 +33,7 @@ public class NotificationHelper ***REMOVED***
|
|||
***REMOVED***
|
||||
|
||||
private String getSubjectHeader() ***REMOVED***
|
||||
return "[[DataMinerGhostInstallationRequestReport]]";
|
||||
return "[DataMinerGhostInstallationRequestReport]";
|
||||
***REMOVED***
|
||||
|
||||
private String getSpecificVREName() ***REMOVED***
|
||||
|
|
|
@ -190,6 +190,9 @@ public class SVNUpdater ***REMOVED***
|
|||
|
||||
|
||||
public boolean checkIfAvaialable(String file, Collection<Dependency> deps) throws SVNException ***REMOVED***
|
||||
SendMail sm = new SendMail();
|
||||
NotificationHelper nh = new NotificationHelper();
|
||||
|
||||
boolean check = false;
|
||||
try***REMOVED***
|
||||
System.out.println("Checking dependencies list: " + file);
|
||||
|
@ -198,9 +201,8 @@ public class SVNUpdater ***REMOVED***
|
|||
String lines[] = byteArrayOutputStream.toString().split("\\r?\\n");
|
||||
|
||||
if(deps.isEmpty())***REMOVED***
|
||||
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 ***REMOVED***
|
|||
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***
|
||||
|
|
|
@ -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;
|
||||
***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 ***REMOVED***
|
||||
|
||||
|
@ -30,11 +40,13 @@ public void sendNotification(String subject, String body) throws Exception ***RE
|
|||
|
||||
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 ***RE
|
|||
|
||||
|
||||
|
||||
public String username(String token) throws ObjectNotFound, Exception***REMOVED***
|
||||
AuthorizationEntry entry = authorizationService().get(token);
|
||||
System.out.println(entry.getClientInfo().getId());
|
||||
return entry.getClientInfo().getId();
|
||||
|
||||
***REMOVED***
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public String retrieveAdminRole() throws Exception***REMOVED***
|
||||
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)***REMOVED***
|
||||
Exception e = new Exception("Error in querying the recipient");
|
||||
throw e;
|
||||
***REMOVED***
|
||||
return response;
|
||||
|
||||
|
||||
***REMOVED***
|
||||
|
||||
|
||||
|
||||
public String getAdmins() throws Exception ***REMOVED***
|
||||
List<String> s = new LinkedList<String>();
|
||||
JSONObject obj = new JSONObject(this.retrieveAdminRole());
|
||||
JSONArray data = obj.getJSONArray("result");
|
||||
if (data != null) ***REMOVED***
|
||||
String[] names = new String[data.length()];
|
||||
for (int i = 0; i < data.length(); i++) ***REMOVED***
|
||||
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***
|
||||
|
||||
|
||||
|
||||
|
||||
***REMOVED***
|
||||
public String getDescription() ***REMOVED***
|
||||
***REMOVED***
|
||||
|
@ -91,11 +160,20 @@ public void sendNotification(String subject, String body) throws Exception ***RE
|
|||
***REMOVED***
|
||||
|
||||
public static void main(String[] args) throws Exception ***REMOVED***
|
||||
ScopeProvider.instance.set("/d4science.research-infrastructures.eu/gCubeApps/RPrototypingLab");
|
||||
SecurityTokenProvider.instance.set("***REMOVED***");
|
||||
***REMOVED*** ScopeProvider.instance.set("/d4science.research-infrastructures.eu/gCubeApps/RPrototypingLab");
|
||||
***REMOVED*** SecurityTokenProvider.instance.set("***REMOVED***");
|
||||
|
||||
***REMOVED***
|
||||
SecurityTokenProvider.instance.set("***REMOVED***");
|
||||
|
||||
|
||||
|
||||
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***
|
||||
|
|
Loading…
Reference in New Issue