Skip to Content.
Sympa Menu

perfsonar-dev - [pS-dev] [GEANT/SA2/ps-java-services] r6147 - in trunk/psBase3/perfsonar-base/src: main/java/net/geant/perfsonar test/resources/net/geant/perfsonar/mp/sshtelnet

Subject: perfsonar development work

List archive

[pS-dev] [GEANT/SA2/ps-java-services] r6147 - in trunk/psBase3/perfsonar-base/src: main/java/net/geant/perfsonar test/resources/net/geant/perfsonar/mp/sshtelnet


Chronological Thread 
  • From:
  • To:
  • Subject: [pS-dev] [GEANT/SA2/ps-java-services] r6147 - in trunk/psBase3/perfsonar-base/src: main/java/net/geant/perfsonar test/resources/net/geant/perfsonar/mp/sshtelnet
  • Date: Mon, 18 Feb 2013 19:56:18 +0000 (GMT)
  • Authentication-results: sfpop-ironport05.merit.edu; dkim=neutral (message not signed) header.i=none

Author: psnc.pietrzak
Date: 2013-02-18 19:56:18 +0000 (Mon, 18 Feb 2013)
New Revision: 6147

Removed:

trunk/psBase3/perfsonar-base/src/main/java/net/geant/perfsonar/LSRegistrationTask.java

trunk/psBase3/perfsonar-base/src/test/resources/net/geant/perfsonar/mp/sshtelnet/LSRegister.template
Modified:

trunk/psBase3/perfsonar-base/src/main/java/net/geant/perfsonar/PerfSONAR.java
Log:
extracted lookup service functionality.

Deleted:
trunk/psBase3/perfsonar-base/src/main/java/net/geant/perfsonar/LSRegistrationTask.java
===================================================================
---
trunk/psBase3/perfsonar-base/src/main/java/net/geant/perfsonar/LSRegistrationTask.java
2013-02-18 19:39:36 UTC (rev 6146)
+++
trunk/psBase3/perfsonar-base/src/main/java/net/geant/perfsonar/LSRegistrationTask.java
2013-02-18 19:56:18 UTC (rev 6147)
@@ -1,150 +0,0 @@
-package net.geant.perfsonar;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.PipedInputStream;
-import java.io.PipedOutputStream;
-import java.io.Writer;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Hashtable;
-import java.util.List;
-import java.util.Map;
-
-import javax.xml.namespace.QName;
-import javax.xml.transform.stream.StreamSource;
-import javax.xml.ws.Dispatch;
-import javax.xml.ws.Service;
-import javax.xml.ws.soap.SOAPBinding;
-
-import net.geant.perfsonar.nmwg.response.TemplateEngine;
-import net.geant.perfsonar.xpath.Helper;
-import net.geant.perfsonar.xpath.XPathDeserializer;
-
-import org.xml.sax.InputSource;
-
-/**
- * Registers a service to Lookup Service.
- * If the service is already registered (key was returned from LS
successfully) it sends keepalive messages.
- * It uses LSRegister.template template found in the directory where the
controller method that provides data for registration is defined.
- *
- * In order to configure the handler for the Lookup Service registration the
following
- * code snippet must be used:
- *
<code>configure(registerToLookupService(ServiceController.class).details())</code>
- * where configure method belongs to Configuration class.
- *
- * @author <a
href="mailto:">Blazej
Pietrzak</a>
- */
-public class LSRegistrationTask implements Runnable {
-
- private static List<String> lsAddresses = new ArrayList<String>();
-
- public List<String> getLSAddresses() {
- return lsAddresses;
- }
-
- public void addLSAddress(String address) {
- if (address == null)
- return;
-
- if (!lsAddresses.contains(address))
- lsAddresses.add(address);
- }
-
- public static <T> T registerToLookupService(Class<T> controller) {
- return Helper.createMock(controller, new HandlerConfiguration(
- "LSRegister"));
- }
-
- private Map<String, String> keys = new Hashtable<String, String>();
- private Logger logger;
- private PerfSONAR service;
-
- public LSRegistrationTask(Logger logger, PerfSONAR service) {
- this.logger = logger;
- this.service = service;
- }
-
- public LSRegistrationTask() {
- this(null, null);
- }
-
- public void run() {
- for (String address : getLSAddresses()) {
- try {
- registerToLookupService(address);
- } catch (Exception ex) {
- logger.error("Could not register to Lookup
Service at: " + address, ex);
- }
- }
- }
-
- @SuppressWarnings("unchecked")
- protected synchronized void registerToLookupService(final String
address) throws IllegalArgumentException, IllegalAccessException,
InvocationTargetException, InstantiationException, IOException {
- final Method m = Configuration.getHandler("LSRegister");
- if (m == null)
- return;
-
- final PipedInputStream in = new PipedInputStream();
- final PipedOutputStream out = new PipedOutputStream(in);
-
service.getScheduler().runInParallel(createLSMessageTask(address, m, out));
-
- if (keys.get(address) == null) {
- final XPathDeserializer deserializer = new
XPathDeserializer();
- final NMWGMessage msg;
- try {
- msg =
deserializer.getObjects(NMWGMessage.class, (List<Object>)
deserializer.deserialize(new InputSource(getLSClient(address).invoke(new
StreamSource(in)).getInputStream()))).get(0);
- if (msg.getKey() != null) {
- keys.put(address, msg.getKey());
- }
- } catch (Exception e) {
- logger.error("Could not deserialize key from
Lookup Service response.", e);
- }
- } else
- getLSClient(address).invoke(new StreamSource(in));
- }
-
- private Runnable createLSMessageTask(final String address, final
Method m, final OutputStream out) {
- return new Runnable() {
-
- private final Writer writer = new
OutputStreamWriter(out);
-
- public void run() {
- try {
- if (keys.get(address) == null) {
-
TemplateEngine.put("requestId", "request1");
- TemplateEngine.put("result",
m.invoke(m.getDeclaringClass().newInstance()));
- TemplateEngine.put("service",
service);
-
TemplateEngine.evaluate(writer, m.getDeclaringClass(), "LSRegister.template");
- } else {
-
writer.write(getKeepAliveMessage(keys.get(address)));
- }
- writer.flush();
- writer.close();
- out.close();
- } catch (Exception ex) {
- logger.error("Could not register in
LookupService.", ex);
- }
- }
-
- private String getKeepAliveMessage(String key) {
- return "<?xml version='1.0'
encoding='UTF-8'?>"
- + "<nmwg:message id='request1'
type='LSKeepaliveRequest' xmlns:nmwg='http://ggf.org/ns/nmwg/base/2.0/'>"
- + "<nmwg:metadata
id='key_to_keepalive'><nmwg:key>" + key + "</nmwg:key></nmwg:metadata>"
- + "<nmwg:data id='d1'
metadataIdRef='key_to_keepalive' />"
- + "</nmwg:message>\n";
- }
- };
- }
-
- private Dispatch<StreamSource> getLSClient(final String address) {
- final String NAMESPACE = "http://base3.perfsonar.geant.net/";;
- final QName PORT = new QName(NAMESPACE, "PerfSONARPort");
- final Service service = Service.create(new QName(NAMESPACE,
"PerfSONARService"));
- service.addPort(PORT, SOAPBinding.SOAP11HTTP_BINDING,
address);
- final Dispatch<StreamSource> client =
service.createDispatch(PORT, StreamSource.class, Service.Mode.PAYLOAD);
- return client;
- }
-}

Modified:
trunk/psBase3/perfsonar-base/src/main/java/net/geant/perfsonar/PerfSONAR.java
===================================================================
---
trunk/psBase3/perfsonar-base/src/main/java/net/geant/perfsonar/PerfSONAR.java
2013-02-18 19:39:36 UTC (rev 6146)
+++
trunk/psBase3/perfsonar-base/src/main/java/net/geant/perfsonar/PerfSONAR.java
2013-02-18 19:56:18 UTC (rev 6147)
@@ -1,8 +1,8 @@
package net.geant.perfsonar;

-import static net.geant.perfsonar.xpath.XPathDeserializer.any;
-import static net.geant.perfsonar.xpath.XPathDeserializer.declarePrefix;
-import static net.geant.perfsonar.xpath.XPathDeserializer.whenXPath;
+import static net.geant.perfsonar.messaging.XPathDeserializer.any;
+import static net.geant.perfsonar.messaging.XPathDeserializer.declarePrefix;
+import static net.geant.perfsonar.messaging.XPathDeserializer.whenXPath;

import java.io.IOException;
import java.io.StringReader;
@@ -21,11 +21,11 @@
import javax.xml.ws.Provider;

import net.geant.perfsonar.base.Scheduler;
-import net.geant.perfsonar.nmwg.response.EchoResponse;
-import net.geant.perfsonar.nmwg.response.SelfTestResponse;
-import net.geant.perfsonar.nmwg.response.TemplateEngine;
+import net.geant.perfsonar.response.EchoResponse;
+import net.geant.perfsonar.response.SelfTestResponse;
+import net.geant.perfsonar.templates.TemplateEngine;
+import net.geant.perfsonar.messaging.XPathDeserializer;
import net.geant.perfsonar.selftest.SelfTestRunner;
-import net.geant.perfsonar.xpath.XPathDeserializer;

import org.slf4j.LoggerFactory;
import org.xml.sax.InputSource;
@@ -223,7 +223,7 @@
/**
* @return scheduler that uses thread pool.
*/
- protected Scheduler getScheduler() {
+ public Scheduler getScheduler() {
return scheduler;
}


Deleted:
trunk/psBase3/perfsonar-base/src/test/resources/net/geant/perfsonar/mp/sshtelnet/LSRegister.template
===================================================================
---
trunk/psBase3/perfsonar-base/src/test/resources/net/geant/perfsonar/mp/sshtelnet/LSRegister.template
2013-02-18 19:39:36 UTC (rev 6146)
+++
trunk/psBase3/perfsonar-base/src/test/resources/net/geant/perfsonar/mp/sshtelnet/LSRegister.template
2013-02-18 19:56:18 UTC (rev 6147)
@@ -1,30 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<nmwg:message id="${requestId}" type="LSRegisterRequest"
xmlns:nmwg="http://ggf.org/ns/nmwg/base/2.0/";>
- <nmwg:metadata id="serviceLookupInfo">
-
<nmwg:eventType>http://ogf.org/ns/nmwg/tools/org/perfsonar/service/lookup/registration/service/2.0</nmwg:eventType>
- <nmwg:subject id="commonParameters" name="perfsonar">
- <psservice:service id="serviceParameters"
xmlns:psservice="http://ggf.org/ns/nmwg/tools/org/perfsonar/service/1.0/";>
-
<psservice:accessPoint>http://localhost:9000/perfsonar-sshtelnet-mp</psservice:accessPoint>
-
<psservice:serviceName>${service.serviceName}</psservice:serviceName>
-
<psservice:serviceType>${service.serviceType}</psservice:serviceType>
- </psservice:service>
- </nmwg:subject>
- </nmwg:metadata>
- <nmwg:data metadataIdRef="serviceLookupInfo">
- <nmwg:metadata id="metadata0">
- <nmwg:subject
id="subject0">DummyCiscoRouter</nmwg:subject>
- <nmwg:parameters id="metaParams0">
- <nmwg:parameter name="class_name"
value="org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.CiscoAdapter"
/>
- <nmwg:parameter name="url" value="0.0.0.0" />
- <nmwg:parameter name="port" value="0" />
- <nmwg:parameter name="prompt"
value="DummyRouter&gt;" />
- <nmwg:parameter name="rate" value="500" />
- <nmwg:parameter name="username"
value="dummyUser" />
- <nmwg:parameter name="password"
value="ab05D8Z22537EdEzaWmlmA==" />
- <nmwg:parameter name="timeout" value="10000"
/>
- <nmwg:parameter name="numberOfUsers"
value="0" />
- <nmwg:parameter name="cache" value="0" />
- </nmwg:parameters>
- </nmwg:metadata>
- </nmwg:data>
-</nmwg:message>



  • [pS-dev] [GEANT/SA2/ps-java-services] r6147 - in trunk/psBase3/perfsonar-base/src: main/java/net/geant/perfsonar test/resources/net/geant/perfsonar/mp/sshtelnet, svn-noreply, 02/18/2013

Archive powered by MHonArc 2.6.16.

Top of Page