This commit is contained in:
Nunzio Andrea Galante 2017-09-07 16:46:26 +00:00
parent be9b269716
commit 88759aebd2
5 changed files with 138 additions and 105 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 {
}
public Set<Algorithm> getAlgoFromIs() {
// TODO Auto-generated method stub
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) {
out.add(this.convertAlgo(a));
}
return out;
}
// public Set<Algorithm> getAlgoFromIs() {
// // TODO Auto-generated method stub
//
// 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) {
// out.add(this.convertAlgo(a));
// }
// return out;
// }
private Algorithm convertAlgo(GenericResource a) {
Algorithm out = new Algorithm();
// 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++) {
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);
}
out.setDependencies(deps);
return out;
}
// private Algorithm convertAlgo(GenericResource a) {
// Algorithm out = new Algorithm();
//
// // 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++) {
// 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);
// }
// out.setDependencies(deps);
// return out;
// }

View File

@ -17,7 +17,6 @@ import org.gcube.dataanalysis.dataminer.poolmanager.datamodel.Dependency;
import org.gcube.dataanalysis.dataminer.poolmanager.util.SVNUpdater;
import org.tmatesoft.svn.core.SVNException;
import Jampack.Print;
public abstract class DMPMJob {

View File

@ -9,9 +9,7 @@ import java.io.InputStreamReader;
import java.net.URL;
import java.util.Vector;
import javax.jms.ServerSession;
import org.apache.activemq.transport.tcp.ExceededMaximumConnectionsException;
import org.gcube.dataanalysis.dataminer.poolmanager.datamodel.Algorithm;
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;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.util.LinkedList;
import java.util.List;
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;
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.encryption.StringEncrypter;
import org.gcube.common.resources.gcore.GCoreEndpoint;
import org.gcube.common.resources.gcore.GenericResource;
import org.gcube.common.resources.gcore.ServiceEndpoint;
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.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 {
public class SendMail {
public SendMail() {
// TODO Auto-generated constructor stub
@ -40,11 +45,13 @@ public class SendMail extends StandardLocalInfraAlgorithm {
public void sendNotification(String subject, String body) throws Exception {
AnalysisLogger.getLogger()
.debug("Emailing System->Starting request of email in scope " + ScopeProvider.instance.get());
//AnalysisLogger.getLogger().debug("Emailing System->Starting request of email in scope " + ScopeProvider.instance.get());
String serviceAddress = InfraRetrieval.findEmailingSystemAddress(ScopeProvider.instance.get());
//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 {
+ SecurityTokenProvider.instance.get();
requestForMessage = requestForMessage.replace("http://", "https://").replace(":80", "");
AnalysisLogger.getLogger().debug("Emailing System->Request url is going to be " + requestForMessage);
//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");
@ -60,9 +67,9 @@ public class SendMail extends StandardLocalInfraAlgorithm {
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);
//AnalysisLogger.getLogger().debug("Emailing System->Emailing response OK ");
if (response == null) {
Exception e = new Exception("Error in email sending response");
throw e;
@ -102,6 +109,57 @@ public class SendMail extends StandardLocalInfraAlgorithm {
//
// }
public String getSocialService() {
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;
}
public String sendPostRequest(String endpoint, String requestParameters) {
// Build parameter string
String data = requestParameters;
try {
// Send the request
URL url = new URL(endpoint);
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream());
// write parameters
writer.write(data);
writer.flush();
// Get the response
StringBuffer answer = new StringBuffer();
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
answer.append(line);
}
writer.close();
reader.close();
// Output the response
return answer.toString();
} catch (MalformedURLException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
return null;
}
public String getAdminRoles() throws Exception{
@ -110,7 +168,8 @@ public class SendMail extends StandardLocalInfraAlgorithm {
//GcoreEndpointReader ep = new GcoreEndpointReader(ScopeProvider.instance.get());
String serviceAddress = InfraRetrieval.findEmailingSystemAddress(ScopeProvider.instance.get());
String serviceAddress = this.getSocialService();
//String serviceAddress = InfraRetrieval.findEmailingSystemAddress(ScopeProvider.instance.get());
//String serviceAddress = ep.getResourceEntyName();//"https://socialnetworking1.d4science.org/social-networking-library-ws/rest/";
@ -154,56 +213,27 @@ public class SendMail extends StandardLocalInfraAlgorithm {
public String getRootToken() throws Exception {
//ApplicationContext ctx = ContextProvider.get(); // get this info from
// SmartGears
//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) {
a = StringEncrypter.getEncrypter().decrypt(b.profile().accessPoints().iterator().next().password());
}
return a;
}
// public String getRootToken() throws Exception {
//
// //ApplicationContext ctx = ContextProvider.get(); // get this info from
// // SmartGears
// //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) {
// a = StringEncrypter.getEncrypter().decrypt(b.profile().accessPoints().iterator().next().password());
// }
// return a;
// }
@Override
public String getDescription() {
// TODO Auto-generated method stub
return null;
}
@Override
public void init() throws Exception {
// TODO Auto-generated method stub
}
@Override
protected void process() throws Exception {
// TODO Auto-generated method stub
}
@Override
protected void setInputParameters() {
// TODO Auto-generated method stub
}
@Override
public void shutdown() {
// TODO Auto-generated method stub
}
public static void main(String[] args) throws Exception {
//ScopeProvider.instance.set("/d4science.research-infrastructures.eu/gCubeApps/RPrototypingLab");
@ -216,16 +246,22 @@ public class SendMail extends StandardLocalInfraAlgorithm {
SendMail sm = new SendMail();
ScopeProvider.instance.set("/gcube/devNext/NextNext");
System.out.println(sm.getRootToken());
//ScopeProvider.instance.set("/gcube/devNext/NextNext");
//SecurityTokenProvider.instance.set("708e7eb8-11a7-4e9a-816b-c9ed7e7e99fe-98187548");
//System.out.println(sm.getRootToken());
//sm.getGenericResourceByName("");
ScopeProvider.instance.set("/gcube/preprod/preVRE");
SecurityTokenProvider.instance.set("2eceaf27-0e22-4dbe-8075-e09eff199bf9-98187548");
//sm.sendNotification(nh.getFailedSubject(), nh.getFailedBody("test failed"));
// sm.username(SecurityTokenProvider.instance.get());
//sm.retrieveAdminRole();
//sm.getAdminRoles();
System.out.println(sm.getAdmins());
//System.out.println(sm.getAdmins());
//System.out.println(sm.getAdmins());
// sm.sendNotification("test", "test");
//sm.sendNotification("test", "test");
//System.out.println(sm.getSocialService());
}
}