This commit is contained in:
Nunzio Andrea Galante 2017-09-07 16:46:26 +00:00
parent 661dacd21b
commit 4fbb06f7df
5 changed files with 135 additions and 102 deletions

View File

@ -65,11 +65,11 @@
<artifactId>stringtemplate</artifactId>
<version>[4.0.0, 4.1.0)</version>
</dependency>
<dependency>
<!-- <dependency>
<groupId>org.gcube.dataanalysis</groupId>
<artifactId>ecological-engine-smart-executor</artifactId>
<version>[1.4.0-SNAPSHOT, 1.6.0-SNAPSHOT]</version>
</dependency>
</dependency> -->
<dependency>

View File

@ -252,43 +252,43 @@ public class ISClient ***REMOVED***
***REMOVED***
public Set<Algorithm> getAlgoFromIs() ***REMOVED***
***REMOVED***
Set<Algorithm> out = new HashSet<Algorithm>();
SimpleQuery query = queryFor(GenericResource.class);
query.addCondition("$resource/Profile/SecondaryType/text() eq 'StatisticalManagerAlgorithm'")
.setResult("$resource");
DiscoveryClient<GenericResource> client = clientFor(GenericResource.class);
List<GenericResource> ds = client.submit(query);
for (GenericResource a : ds) ***REMOVED***
out.add(this.convertAlgo(a));
***REMOVED***
return out;
***REMOVED*** public Set<Algorithm> getAlgoFromIs() ***REMOVED***
***REMOVED******REMOVED***
***REMOVED***
***REMOVED*** Set<Algorithm> out = new HashSet<Algorithm>();
***REMOVED*** SimpleQuery query = queryFor(GenericResource.class);
***REMOVED*** query.addCondition("$resource/Profile/SecondaryType/text() eq 'StatisticalManagerAlgorithm'")
***REMOVED*** .setResult("$resource");
***REMOVED*** DiscoveryClient<GenericResource> client = clientFor(GenericResource.class);
***REMOVED*** List<GenericResource> ds = client.submit(query);
***REMOVED*** for (GenericResource a : ds) ***REMOVED***
***REMOVED*** out.add(this.convertAlgo(a));
***REMOVED*** ***REMOVED***
***REMOVED*** return out;
***REMOVED******REMOVED***
private Algorithm convertAlgo(GenericResource a) ***REMOVED***
Algorithm out = new Algorithm();
***REMOVED*** out.setId(a.profile().body().getElementsByTagName("id").item(0).getTextContent());
out.setAlgorithmType(a.profile().body().getElementsByTagName("algorithmType").item(0).getTextContent());
out.setCategory(a.profile().body().getElementsByTagName("category").item(0).getTextContent());
out.setClazz(a.profile().body().getElementsByTagName("clazz").item(0).getTextContent());
out.setName(a.profile().name());
out.setPackageURL(a.profile().body().getElementsByTagName("packageURL").item(0).getTextContent());
out.setSkipJava(a.profile().body().getElementsByTagName("skipJava").item(0).getTextContent());
out.setDescription(a.profile().description());
Set<org.gcube.dataanalysis.dataminer.poolmanager.datamodel.Dependency> deps = new HashSet<org.gcube.dataanalysis.dataminer.poolmanager.datamodel.Dependency>();
for (int i = 0; i < a.profile().body().getElementsByTagName("dependencies").getLength(); i++) ***REMOVED***
org.gcube.dataanalysis.dataminer.poolmanager.datamodel.Dependency d1 = new org.gcube.dataanalysis.dataminer.poolmanager.datamodel.Dependency();
d1.setName(a.profile().body().getElementsByTagName("dependencies").item(i).getTextContent());
deps.add(d1);
***REMOVED***
out.setDependencies(deps);
return out;
***REMOVED*** private Algorithm convertAlgo(GenericResource a) ***REMOVED***
***REMOVED*** Algorithm out = new Algorithm();
***REMOVED***
***REMOVED*** ***REMOVED*** out.setId(a.profile().body().getElementsByTagName("id").item(0).getTextContent());
***REMOVED*** out.setAlgorithmType(a.profile().body().getElementsByTagName("algorithmType").item(0).getTextContent());
***REMOVED*** out.setCategory(a.profile().body().getElementsByTagName("category").item(0).getTextContent());
***REMOVED*** out.setClazz(a.profile().body().getElementsByTagName("clazz").item(0).getTextContent());
***REMOVED*** out.setName(a.profile().name());
***REMOVED*** out.setPackageURL(a.profile().body().getElementsByTagName("packageURL").item(0).getTextContent());
***REMOVED*** out.setSkipJava(a.profile().body().getElementsByTagName("skipJava").item(0).getTextContent());
***REMOVED*** out.setDescription(a.profile().description());
***REMOVED***
***REMOVED*** Set<org.gcube.dataanalysis.dataminer.poolmanager.datamodel.Dependency> deps = new HashSet<org.gcube.dataanalysis.dataminer.poolmanager.datamodel.Dependency>();
***REMOVED*** for (int i = 0; i < a.profile().body().getElementsByTagName("dependencies").getLength(); i++) ***REMOVED***
***REMOVED*** org.gcube.dataanalysis.dataminer.poolmanager.datamodel.Dependency d1 = new org.gcube.dataanalysis.dataminer.poolmanager.datamodel.Dependency();
***REMOVED*** d1.setName(a.profile().body().getElementsByTagName("dependencies").item(i).getTextContent());
***REMOVED*** deps.add(d1);
***REMOVED*** ***REMOVED***
***REMOVED*** out.setDependencies(deps);
***REMOVED*** return out;
***REMOVED******REMOVED***

View File

@ -17,7 +17,6 @@ import org.gcube.dataanalysis.dataminer.poolmanager.datamodel.Dependency;
import org.gcube.dataanalysis.dataminer.poolmanager.util.SVNUpdater;
***REMOVED***
import Jampack.Print;
public abstract class DMPMJob ***REMOVED***

View File

@ -9,9 +9,7 @@ import java.io.InputStreamReader;
***REMOVED***
import java.util.Vector;
import javax.jms.ServerSession;
import org.apache.activemq.transport.tcp.ExceededMaximumConnectionsException;
***REMOVED***
import com.jcraft.jsch.Channel;

View File

@ -4,11 +4,17 @@ import static org.gcube.common.authorization.client.Constants.authorizationServi
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
import java.io.BufferedReader;
***REMOVED***
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
***REMOVED***
***REMOVED***
import java.net.URLConnection;
import java.net.URLEncoder;
import java.util.LinkedList;
***REMOVED***
import org.apache.activemq.transport.stomp.Stomp.Headers.Send;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
@ -16,14 +22,13 @@ import org.apache.http.util.EntityUtils;
***REMOVED***
import org.gcube.common.authorization.library.AuthorizationEntry;
***REMOVED***
import org.gcube.common.encryption.StringEncrypter;
import org.gcube.common.resources.gcore.GCoreEndpoint;
import org.gcube.common.resources.gcore.GenericResource;
import org.gcube.common.resources.gcore.ServiceEndpoint;
***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.gcube.dataanalysis.dataminer.poolmanager.datamodel.Host;
import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
import org.gcube.smartgears.ContextProvider;
@ -32,7 +37,7 @@ import org.json.JSONArray;
import org.json.JSONObject;
public class SendMail extends StandardLocalInfraAlgorithm ***REMOVED***
public class SendMail ***REMOVED***
public SendMail() ***REMOVED***
***REMOVED*** TODO Auto-generated constructor stub
@ -40,11 +45,13 @@ public class SendMail extends StandardLocalInfraAlgorithm ***REMOVED***
public void sendNotification(String subject, String body) throws Exception ***REMOVED***
AnalysisLogger.getLogger()
.debug("Emailing System->Starting request of email in scope " + ScopeProvider.instance.get());
***REMOVED***AnalysisLogger.getLogger().debug("Emailing System->Starting request of email in scope " + ScopeProvider.instance.get());
String serviceAddress = InfraRetrieval.findEmailingSystemAddress(ScopeProvider.instance.get());
***REMOVED***String serviceAddress = InfraRetrieval.findEmailingSystemAddress(ScopeProvider.instance.get());
String serviceAddress = this.getSocialService();
if (!serviceAddress.endsWith("/"))
serviceAddress = serviceAddress + "/";
@ -52,7 +59,7 @@ public class SendMail extends StandardLocalInfraAlgorithm ***REMOVED***
+ SecurityTokenProvider.instance.get();
requestForMessage = requestForMessage.replace("http:***REMOVED***", "https:***REMOVED***").replace(":80", "");
AnalysisLogger.getLogger().debug("Emailing System->Request url is going to be " + requestForMessage);
***REMOVED***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");
@ -60,9 +67,9 @@ public class SendMail extends StandardLocalInfraAlgorithm ***REMOVED***
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 ");
String response = this.sendPostRequest(requestForMessage, requestParameters);
***REMOVED***AnalysisLogger.getLogger().debug("Emailing System->Emailing response OK ");
if (response == null) ***REMOVED***
Exception e = new Exception("Error in email sending response");
throw e;
@ -102,6 +109,57 @@ public class SendMail extends StandardLocalInfraAlgorithm ***REMOVED***
***REMOVED***
***REMOVED******REMOVED***
public String getSocialService() ***REMOVED***
SimpleQuery query = queryFor(GCoreEndpoint.class);
query.addCondition("$resource/Profile/ServiceName/text() eq 'SocialNetworking'");
DiscoveryClient<GCoreEndpoint> client = clientFor(GCoreEndpoint.class);
List<GCoreEndpoint> resources = client.submit(query);
String a = resources.get(0).profile().endpointMap().get("jersey-servlet").uri().toString();
return a;
***REMOVED***
public String sendPostRequest(String endpoint, String requestParameters) ***REMOVED***
***REMOVED*** Build parameter string
String data = requestParameters;
try ***REMOVED***
***REMOVED*** Send the request
URL url = new URL(endpoint);
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream());
***REMOVED*** write parameters
writer.write(data);
writer.flush();
***REMOVED*** Get the response
StringBuffer answer = new StringBuffer();
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = reader.readLine()) != null) ***REMOVED***
answer.append(line);
***REMOVED***
writer.close();
reader.close();
***REMOVED*** Output the response
return answer.toString();
***REMOVED*** catch (MalformedURLException ex) ***REMOVED***
ex.printStackTrace();
***REMOVED*** catch (IOException ex) ***REMOVED***
ex.printStackTrace();
***REMOVED***
***REMOVED***
***REMOVED***
public String getAdminRoles() throws Exception***REMOVED***
@ -110,7 +168,8 @@ public class SendMail extends StandardLocalInfraAlgorithm ***REMOVED***
***REMOVED***GcoreEndpointReader ep = new GcoreEndpointReader(ScopeProvider.instance.get());
String serviceAddress = InfraRetrieval.findEmailingSystemAddress(ScopeProvider.instance.get());
String serviceAddress = this.getSocialService();
***REMOVED***String serviceAddress = InfraRetrieval.findEmailingSystemAddress(ScopeProvider.instance.get());
***REMOVED***String serviceAddress = ep.getResourceEntyName();***REMOVED***"https:***REMOVED***socialnetworking1.d4science.org/social-networking-library-ws/rest/";
@ -154,56 +213,27 @@ public class SendMail extends StandardLocalInfraAlgorithm ***REMOVED***
public String getRootToken() throws Exception ***REMOVED***
***REMOVED***ApplicationContext ctx = ContextProvider.get(); ***REMOVED*** get this info from
***REMOVED*** SmartGears
***REMOVED***System.out.println(ctx.container().configuration().infrastructure());
String a = "";
SimpleQuery query2 = queryFor(ServiceEndpoint.class);
query2.addCondition("$resource/Profile/Name/text() eq 'SAIService'").setResult("$resource");
DiscoveryClient<ServiceEndpoint> client2 = clientFor(ServiceEndpoint.class);
List<ServiceEndpoint> df = client2.submit(query2);
for (ServiceEndpoint b : df) ***REMOVED***
a = StringEncrypter.getEncrypter().decrypt(b.profile().accessPoints().iterator().next().password());
***REMOVED***
return a;
***REMOVED*** public String getRootToken() throws Exception ***REMOVED***
***REMOVED***
***REMOVED*** ***REMOVED***ApplicationContext ctx = ContextProvider.get(); ***REMOVED*** get this info from
***REMOVED*** ***REMOVED*** SmartGears
***REMOVED*** ***REMOVED***System.out.println(ctx.container().configuration().infrastructure());
***REMOVED*** String a = "";
***REMOVED*** SimpleQuery query2 = queryFor(ServiceEndpoint.class);
***REMOVED*** query2.addCondition("$resource/Profile/Name/text() eq 'SAIService'").setResult("$resource");
***REMOVED***
***REMOVED*** DiscoveryClient<ServiceEndpoint> client2 = clientFor(ServiceEndpoint.class);
***REMOVED*** List<ServiceEndpoint> df = client2.submit(query2);
***REMOVED***
***REMOVED*** for (ServiceEndpoint b : df) ***REMOVED***
***REMOVED*** a = StringEncrypter.getEncrypter().decrypt(b.profile().accessPoints().iterator().next().password());
***REMOVED*** ***REMOVED***
***REMOVED*** return a;
***REMOVED******REMOVED***
***REMOVED***
public String getDescription() ***REMOVED***
***REMOVED***
***REMOVED***
***REMOVED***
***REMOVED***
public void init() throws Exception ***REMOVED***
***REMOVED***
***REMOVED***
***REMOVED***
protected void process() throws Exception ***REMOVED***
***REMOVED***
***REMOVED***
***REMOVED***
protected void setInputParameters() ***REMOVED***
***REMOVED***
***REMOVED***
***REMOVED***
public void shutdown() ***REMOVED***
***REMOVED***
***REMOVED***
public static void main(String[] args) throws Exception ***REMOVED***
***REMOVED***ScopeProvider.instance.set("/d4science.research-infrastructures.eu/gCubeApps/RPrototypingLab");
@ -216,16 +246,22 @@ public class SendMail extends StandardLocalInfraAlgorithm ***REMOVED***
SendMail sm = new SendMail();
ScopeProvider.instance.set("/gcube/devNext/NextNext");
System.out.println(sm.getRootToken());
***REMOVED***ScopeProvider.instance.set("/gcube/devNext/NextNext");
***REMOVED***SecurityTokenProvider.instance.set("***REMOVED***");
***REMOVED***System.out.println(sm.getRootToken());
***REMOVED***sm.getGenericResourceByName("");
ScopeProvider.instance.set("/gcube/preprod/preVRE");
SecurityTokenProvider.instance.set("2eceaf27-0e22-4dbe-8075-e09eff199bf9-98187548");
***REMOVED***sm.sendNotification(nh.getFailedSubject(), nh.getFailedBody("test failed"));
***REMOVED*** sm.username(SecurityTokenProvider.instance.get());
***REMOVED***sm.retrieveAdminRole();
***REMOVED***sm.getAdminRoles();
System.out.println(sm.getAdmins());
***REMOVED***System.out.println(sm.getAdmins());
***REMOVED***System.out.println(sm.getAdmins());
***REMOVED*** sm.sendNotification("test", "test");
***REMOVED***sm.sendNotification("test", "test");
***REMOVED***System.out.println(sm.getSocialService());
***REMOVED***
***REMOVED***