From 17c944b4dee03dbc095c0c34c5bb168759fee210 Mon Sep 17 00:00:00 2001 From: Nunzio Andrea Galante Date: Thu, 7 Sep 2017 16:46:26 +0000 Subject: [PATCH] git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-analysis/dataminer-pool-manager@152900 82a268e6-3cf1-43bd-a215-b396298e98cf --- pom.xml | 4 +- .../poolmanager/clients/ISClient.java | 64 +++---- .../poolmanager/service/DMPMJob.java | 1 - .../poolmanager/util/CheckMethod.java | 2 - .../dataminer/poolmanager/util/SendMail.java | 164 +++++++++++------- 5 files changed, 134 insertions(+), 101 deletions(-) diff --git a/pom.xml b/pom.xml index cdfa6c4..e123857 100644 --- a/pom.xml +++ b/pom.xml @@ -65,11 +65,11 @@ stringtemplate [4.0.0, 4.1.0) - + diff --git a/src/main/java/org/gcube/dataanalysis/dataminer/poolmanager/clients/ISClient.java b/src/main/java/org/gcube/dataanalysis/dataminer/poolmanager/clients/ISClient.java index 75055bf..ff4f316 100644 --- a/src/main/java/org/gcube/dataanalysis/dataminer/poolmanager/clients/ISClient.java +++ b/src/main/java/org/gcube/dataanalysis/dataminer/poolmanager/clients/ISClient.java @@ -252,43 +252,43 @@ public class ISClient { ***REMOVED*** - public Set getAlgoFromIs() { - ***REMOVED*** TODO Auto-generated method stub - - Set out = new HashSet(); - SimpleQuery query = queryFor(GenericResource.class); - query.addCondition("$resource/Profile/SecondaryType/text() eq 'StatisticalManagerAlgorithm'") - .setResult("$resource"); - DiscoveryClient client = clientFor(GenericResource.class); - List ds = client.submit(query); - for (GenericResource a : ds) { - out.add(this.convertAlgo(a)); - ***REMOVED*** -***REMOVED*** +***REMOVED*** public Set getAlgoFromIs() { +***REMOVED*** ***REMOVED*** TODO Auto-generated method stub ***REMOVED*** +***REMOVED*** Set out = new HashSet(); +***REMOVED*** SimpleQuery query = queryFor(GenericResource.class); +***REMOVED*** query.addCondition("$resource/Profile/SecondaryType/text() eq 'StatisticalManagerAlgorithm'") +***REMOVED*** .setResult("$resource"); +***REMOVED*** DiscoveryClient client = clientFor(GenericResource.class); +***REMOVED*** List ds = client.submit(query); +***REMOVED*** for (GenericResource a : ds) { +***REMOVED*** out.add(this.convertAlgo(a)); +***REMOVED*** ***REMOVED*** +***REMOVED******REMOVED*** +***REMOVED******REMOVED*** - private Algorithm convertAlgo(GenericResource a) { - 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 deps = new HashSet(); - 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); - ***REMOVED*** - out.setDependencies(deps); +***REMOVED*** private Algorithm convertAlgo(GenericResource a) { +***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 deps = new HashSet(); +***REMOVED*** 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(); +***REMOVED*** d1.setName(a.profile().body().getElementsByTagName("dependencies").item(i).getTextContent()); +***REMOVED*** deps.add(d1); +***REMOVED*** ***REMOVED*** +***REMOVED*** out.setDependencies(deps); +***REMOVED******REMOVED*** +***REMOVED******REMOVED*** diff --git a/src/main/java/org/gcube/dataanalysis/dataminer/poolmanager/service/DMPMJob.java b/src/main/java/org/gcube/dataanalysis/dataminer/poolmanager/service/DMPMJob.java index 41d8e86..1302b31 100644 --- a/src/main/java/org/gcube/dataanalysis/dataminer/poolmanager/service/DMPMJob.java +++ b/src/main/java/org/gcube/dataanalysis/dataminer/poolmanager/service/DMPMJob.java @@ -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 { diff --git a/src/main/java/org/gcube/dataanalysis/dataminer/poolmanager/util/CheckMethod.java b/src/main/java/org/gcube/dataanalysis/dataminer/poolmanager/util/CheckMethod.java index ce83a27..a7db4fc 100644 --- a/src/main/java/org/gcube/dataanalysis/dataminer/poolmanager/util/CheckMethod.java +++ b/src/main/java/org/gcube/dataanalysis/dataminer/poolmanager/util/CheckMethod.java @@ -9,9 +9,7 @@ import java.io.InputStream; ***REMOVED*** 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; diff --git a/src/main/java/org/gcube/dataanalysis/dataminer/poolmanager/util/SendMail.java b/src/main/java/org/gcube/dataanalysis/dataminer/poolmanager/util/SendMail.java index a8b4ce1..b5dc261 100644 --- a/src/main/java/org/gcube/dataanalysis/dataminer/poolmanager/util/SendMail.java +++ b/src/main/java/org/gcube/dataanalysis/dataminer/poolmanager/util/SendMail.java @@ -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; +***REMOVED*** +***REMOVED*** +***REMOVED*** +import java.io.OutputStreamWriter; +import java.net.MalformedURLException; +***REMOVED*** +import java.net.URLConnection; import java.net.URLEncoder; ***REMOVED*** ***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; + +***REMOVED*** + 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() { ***REMOVED*** 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()); + ***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 { + 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 { 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) { Exception e = new Exception("Error in email sending response"); throw e; @@ -102,6 +109,57 @@ public class SendMail extends StandardLocalInfraAlgorithm { ***REMOVED*** ***REMOVED******REMOVED*** + public String getSocialService() { + SimpleQuery query = queryFor(GCoreEndpoint.class); + query.addCondition("$resource/Profile/ServiceName/text() eq 'SocialNetworking'"); + DiscoveryClient client = clientFor(GCoreEndpoint.class); + List 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*** Build parameter string + String data = requestParameters; + try { + + ***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) { + answer.append(line); + ***REMOVED*** + writer.close(); + reader.close(); + + ***REMOVED*** Output the response + return answer.toString(); + + ***REMOVED*** catch (MalformedURLException ex) { + ex.printStackTrace(); + ***REMOVED*** catch (IOException ex) { + ex.printStackTrace(); + ***REMOVED*** + return null; +***REMOVED*** + + + public String getAdminRoles() throws Exception{ @@ -110,7 +168,8 @@ public class SendMail extends StandardLocalInfraAlgorithm { ***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 { - public String getRootToken() throws Exception { - - ***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 client2 = clientFor(ServiceEndpoint.class); - List df = client2.submit(query2); - - for (ServiceEndpoint b : df) { - a = StringEncrypter.getEncrypter().decrypt(b.profile().accessPoints().iterator().next().password()); - ***REMOVED*** - return a; +***REMOVED*** public String getRootToken() throws Exception { ***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 client2 = clientFor(ServiceEndpoint.class); +***REMOVED*** List df = client2.submit(query2); +***REMOVED*** +***REMOVED*** for (ServiceEndpoint b : df) { +***REMOVED*** a = StringEncrypter.getEncrypter().decrypt(b.profile().accessPoints().iterator().next().password()); +***REMOVED*** ***REMOVED*** +***REMOVED*** return a; +***REMOVED******REMOVED*** - - @Override - public String getDescription() { - ***REMOVED*** TODO Auto-generated method stub - return null; -***REMOVED*** - @Override - public void init() throws Exception { - ***REMOVED*** TODO Auto-generated method stub - -***REMOVED*** - - @Override - protected void process() throws Exception { - ***REMOVED*** TODO Auto-generated method stub - -***REMOVED*** - - @Override - protected void setInputParameters() { - ***REMOVED*** TODO Auto-generated method stub - -***REMOVED*** - - @Override - public void shutdown() { - ***REMOVED*** TODO Auto-generated method stub - -***REMOVED*** public static void main(String[] args) throws Exception { ***REMOVED***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()); + ***REMOVED***ScopeProvider.instance.set("/gcube/devNext/NextNext"); + ***REMOVED***SecurityTokenProvider.instance.set("708e7eb8-11a7-4e9a-816b-c9ed7e7e99fe-98187548"); + ***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***