Skip to Content.
Sympa Menu

perfsonar-dev - [pS-dev] [GEANT/SA2/ps-java-services] r6144 - in trunk/psBase3/perfsonar-messaging: . src src/main src/main/java src/main/java/net src/main/java/net/geant src/main/java/net/geant/perfsonar src/main/java/net/geant/perfsonar/messaging src/main/java/net/geant/perfsonar/templates src/test src/test/groovy src/test/groovy/net src/test/groovy/net/geant src/test/groovy/net/geant/perfsonar src/test/groovy/net/geant/perfsonar/templates src/test/java src/test/java/net src/test/java/net/geant src/test/java/net/geant/perfsonar src/test/java/net/geant/perfsonar/messaging src/test/java/net/geant/perfsonar/messaging/xpath src/test/java/net/geant/perfsonar/mp src/test/java/net/geant/perfsonar/mp/sshtelnet src/test/java/net/geant/perfsonar/templates

Subject: perfsonar development work

List archive

[pS-dev] [GEANT/SA2/ps-java-services] r6144 - in trunk/psBase3/perfsonar-messaging: . src src/main src/main/java src/main/java/net src/main/java/net/geant src/main/java/net/geant/perfsonar src/main/java/net/geant/perfsonar/messaging src/main/java/net/geant/perfsonar/templates src/test src/test/groovy src/test/groovy/net src/test/groovy/net/geant src/test/groovy/net/geant/perfsonar src/test/groovy/net/geant/perfsonar/templates src/test/java src/test/java/net src/test/java/net/geant src/test/java/net/geant/perfsonar src/test/java/net/geant/perfsonar/messaging src/test/java/net/geant/perfsonar/messaging/xpath src/test/java/net/geant/perfsonar/mp src/test/java/net/geant/perfsonar/mp/sshtelnet src/test/java/net/geant/perfsonar/templates


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

Author: psnc.pietrzak
Date: 2013-02-18 18:58:03 +0000 (Mon, 18 Feb 2013)
New Revision: 6144

Added:
trunk/psBase3/perfsonar-messaging/pom.xml
trunk/psBase3/perfsonar-messaging/src/
trunk/psBase3/perfsonar-messaging/src/main/
trunk/psBase3/perfsonar-messaging/src/main/java/
trunk/psBase3/perfsonar-messaging/src/main/java/net/
trunk/psBase3/perfsonar-messaging/src/main/java/net/geant/
trunk/psBase3/perfsonar-messaging/src/main/java/net/geant/perfsonar/

trunk/psBase3/perfsonar-messaging/src/main/java/net/geant/perfsonar/messaging/

trunk/psBase3/perfsonar-messaging/src/main/java/net/geant/perfsonar/messaging/Helper.java

trunk/psBase3/perfsonar-messaging/src/main/java/net/geant/perfsonar/messaging/ReferenceInterceptor.java

trunk/psBase3/perfsonar-messaging/src/main/java/net/geant/perfsonar/messaging/XPathConfiguration.java

trunk/psBase3/perfsonar-messaging/src/main/java/net/geant/perfsonar/messaging/XPathDeserializer.java

trunk/psBase3/perfsonar-messaging/src/main/java/net/geant/perfsonar/templates/

trunk/psBase3/perfsonar-messaging/src/main/java/net/geant/perfsonar/templates/TemplateEngine.java
trunk/psBase3/perfsonar-messaging/src/test/
trunk/psBase3/perfsonar-messaging/src/test/groovy/
trunk/psBase3/perfsonar-messaging/src/test/groovy/net/
trunk/psBase3/perfsonar-messaging/src/test/groovy/net/geant/
trunk/psBase3/perfsonar-messaging/src/test/groovy/net/geant/perfsonar/

trunk/psBase3/perfsonar-messaging/src/test/groovy/net/geant/perfsonar/templates/

trunk/psBase3/perfsonar-messaging/src/test/groovy/net/geant/perfsonar/templates/NMWG.groovy
trunk/psBase3/perfsonar-messaging/src/test/java/
trunk/psBase3/perfsonar-messaging/src/test/java/net/
trunk/psBase3/perfsonar-messaging/src/test/java/net/geant/
trunk/psBase3/perfsonar-messaging/src/test/java/net/geant/perfsonar/

trunk/psBase3/perfsonar-messaging/src/test/java/net/geant/perfsonar/messaging/

trunk/psBase3/perfsonar-messaging/src/test/java/net/geant/perfsonar/messaging/xpath/

trunk/psBase3/perfsonar-messaging/src/test/java/net/geant/perfsonar/messaging/xpath/XMLDogTest.java

trunk/psBase3/perfsonar-messaging/src/test/java/net/geant/perfsonar/messaging/xpath/XPathDeserializerTest.java
trunk/psBase3/perfsonar-messaging/src/test/java/net/geant/perfsonar/mp/

trunk/psBase3/perfsonar-messaging/src/test/java/net/geant/perfsonar/mp/sshtelnet/

trunk/psBase3/perfsonar-messaging/src/test/java/net/geant/perfsonar/mp/sshtelnet/Command.java

trunk/psBase3/perfsonar-messaging/src/test/java/net/geant/perfsonar/mp/sshtelnet/Router.java

trunk/psBase3/perfsonar-messaging/src/test/java/net/geant/perfsonar/templates/

trunk/psBase3/perfsonar-messaging/src/test/java/net/geant/perfsonar/templates/SelfTestResult.java
Log:
Extracted messaging from perfsonar-base.

Added: trunk/psBase3/perfsonar-messaging/pom.xml
===================================================================
--- trunk/psBase3/perfsonar-messaging/pom.xml (rev
0)
+++ trunk/psBase3/perfsonar-messaging/pom.xml 2013-02-18 18:58:03 UTC (rev
6144)
@@ -0,0 +1,108 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>net.geant.perfsonar</groupId>
+ <artifactId>parent</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <relativePath>../../parent/</relativePath>
+ </parent>
+
+ <artifactId>perfsonar-messaging</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <packaging>bundle</packaging>
+
+ <name>Library for serialization and deserialization of perfSONAR
messages.</name>
+
+ <developers>
+ <developer>
+ <id>blazej.pietrzak</id>
+ <name>Blazej Pietrzak</name>
+
<email></email>
+ <organization>PSNC</organization>
+
<organizationUrl>http://www.man.poznan.pl/</organizationUrl>
+ <roles>
+ <role>architect</role>
+ <role>developer</role>
+ </roles>
+ <timezone>+1</timezone>
+ </developer>
+ </developers>
+
+ <properties>
+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.9</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.velocity</groupId>
+ <artifactId>velocity</artifactId>
+ <version>1.7</version>
+ </dependency>
+ <dependency>
+ <groupId>cglib</groupId>
+ <artifactId>cglib</artifactId>
+ <version>2.2.2</version>
+ </dependency>
+ <dependency>
+ <groupId>jlibs</groupId>
+ <artifactId>jlibs-xmldog</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.groovy</groupId>
+ <artifactId>groovy-all</artifactId>
+ <version>1.8.2</version>
+ <type>jar</type>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <configuration>
+ <instructions>
+
<Export-Package>net.geant.perfsonar.*</Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.3.2</version> <!-- Groovy Eclipse
Compiler does not work with 3.0 -->
+ <configuration>
+
<compilerId>groovy-eclipse-compiler</compilerId>
+ <!-- set verbose to be true if you
want lots of uninteresting messages -->
+ <verbose>false</verbose>
+ </configuration>
+ <dependencies>
+ <dependency>
+
<groupId>org.codehaus.groovy</groupId>
+
<artifactId>groovy-eclipse-compiler</artifactId>
+ <version>2.7.0-01</version>
+ </dependency>
+ </dependencies>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>attach-tests-artifact</id>
+ <goals>
+ <goal>test-jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>

Added:
trunk/psBase3/perfsonar-messaging/src/main/java/net/geant/perfsonar/messaging/Helper.java
===================================================================
---
trunk/psBase3/perfsonar-messaging/src/main/java/net/geant/perfsonar/messaging/Helper.java
(rev 0)
+++
trunk/psBase3/perfsonar-messaging/src/main/java/net/geant/perfsonar/messaging/Helper.java
2013-02-18 18:58:03 UTC (rev 6144)
@@ -0,0 +1,17 @@
+package net.geant.perfsonar.messaging;
+
+
+/**
+ * Helper class for creating subclasses on the fly.
+ *
+ * @author <a
href="mailto:">Blazej
Pietrzak</a>
+ */
+public class Helper {
+ /**
+ * @return <code>true</code> if the object is a subclass
+ * generated by <code>createMock</code> method.
+ */
+ public static boolean isConfigurationInstance(Object object) {

+ return
object.getClass().getName().contains("EnhancerByCGLIB");
+ }
+}

Added:
trunk/psBase3/perfsonar-messaging/src/main/java/net/geant/perfsonar/messaging/ReferenceInterceptor.java
===================================================================
---
trunk/psBase3/perfsonar-messaging/src/main/java/net/geant/perfsonar/messaging/ReferenceInterceptor.java
(rev 0)
+++
trunk/psBase3/perfsonar-messaging/src/main/java/net/geant/perfsonar/messaging/ReferenceInterceptor.java
2013-02-18 18:58:03 UTC (rev 6144)
@@ -0,0 +1,29 @@
+package net.geant.perfsonar.messaging;
+
+import java.lang.reflect.Method;
+
+import net.sf.cglib.proxy.MethodInterceptor;
+import net.sf.cglib.proxy.MethodProxy;
+
+/**
+ * Used for reference configurations.
+ * Decides what will happen when a method is invoked when configuring a
reference.
+ *
+ * @author <a
href="mailto:">Blazej
Pietrzak</a>
+ */
+public class ReferenceInterceptor implements MethodInterceptor {
+
+ public Object intercept(Object obj, Method method, Object[] args,
+ MethodProxy proxy) throws Throwable {
+
+ if (method.getName().equals("toString") ||
method.getName().equals("hashCode") || method.getName().equals("finalize")) {
+ return proxy.invokeSuper(obj, args);
+ }
+
+ if (args.length != 0)
+ throw new IllegalArgumentException(method + "
identifier method must have zero arguments.");
+
+ XPathDeserializer.putIdentifier(method.getDeclaringClass(),
method);
+ return null;
+ }
+}

Added:
trunk/psBase3/perfsonar-messaging/src/main/java/net/geant/perfsonar/messaging/XPathConfiguration.java
===================================================================
---
trunk/psBase3/perfsonar-messaging/src/main/java/net/geant/perfsonar/messaging/XPathConfiguration.java
(rev 0)
+++
trunk/psBase3/perfsonar-messaging/src/main/java/net/geant/perfsonar/messaging/XPathConfiguration.java
2013-02-18 18:58:03 UTC (rev 6144)
@@ -0,0 +1,55 @@
+package net.geant.perfsonar.messaging;
+
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.List;
+
+import net.sf.cglib.proxy.Enhancer;
+import net.sf.cglib.proxy.MethodInterceptor;
+import net.sf.cglib.proxy.MethodProxy;
+
+/**
+ * Allows to configure method invocations when XPath expressions are
evaluated.
+ *
+ * @author <a
href="mailto:">Blazej
Pietrzak</a>
+ */
+public class XPathConfiguration implements MethodInterceptor {
+
+ private String xpath;
+ private Object object;
+
+ private static final List<String> restrictedMethodNames =
Arrays.asList("toString", "hashCode", "finalize");
+
+ public XPathConfiguration(String xpath) {
+ this.xpath = xpath;
+ }
+
+ @SuppressWarnings("unchecked")
+ public <T> T then(Class<T> controller) throws InstantiationException,
IllegalAccessException {
+ return (T) Enhancer.create(controller, this);
+ }
+
+ @SuppressWarnings("unchecked")
+ public <T> T then(Class<T> clazz, T object) throws
InstantiationException, IllegalAccessException {
+ this.object = object;
+ return (T) Enhancer.create(clazz, this);
+ }
+
+ public Object intercept(Object obj, Method method, Object[] args,
+ MethodProxy proxy) throws Throwable {
+
+ if (restrictedMethodNames.contains(method.getName())) {
+ return proxy.invokeSuper(obj, args);
+ }
+
+ if (args.length != 1)
+ throw new IllegalArgumentException("Setter method
must have exactly one argument of type String.");
+
+ if (this.object != null)
+ XPathDeserializer.putXPath(xpath, object, method);
+ else
+ XPathDeserializer.putXPath(xpath, method);
+
+ return null;
+ }
+}

Added:
trunk/psBase3/perfsonar-messaging/src/main/java/net/geant/perfsonar/messaging/XPathDeserializer.java
===================================================================
---
trunk/psBase3/perfsonar-messaging/src/main/java/net/geant/perfsonar/messaging/XPathDeserializer.java
(rev 0)
+++
trunk/psBase3/perfsonar-messaging/src/main/java/net/geant/perfsonar/messaging/XPathDeserializer.java
2013-02-18 18:58:03 UTC (rev 6144)
@@ -0,0 +1,235 @@
+package net.geant.perfsonar.messaging;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.xpath.XPathException;
+
+import jlibs.xml.DefaultNamespaceContext;
+import jlibs.xml.sax.dog.NodeItem;
+import jlibs.xml.sax.dog.XMLDog;
+import jlibs.xml.sax.dog.XPathResults;
+import jlibs.xml.sax.dog.expr.Expression;
+
+import net.sf.cglib.proxy.Enhancer;
+
+import org.jaxen.saxpath.SAXPathException;
+import org.xml.sax.InputSource;
+
+/**
+ * Deserializes data from XML stream.
+ *
+ * This class provides API for configuring XPath expressions that trigger
+ * method invocation with values of the expression evaluation.
+ * Please note that it uses streaming XPaths, so only a subset of
expressions can
+ * be used. Those that require creation of DOM tree are not allowed.
+ *
+ * There are two approaches to configure deserializer: via API or via
annotations.
+ * By invoking:
+ * <code>declarePrefix("nmwg", uri)</code>
+ * one informs the deserializer about prefixes for various namespaces.
+ * By invoking:
+ *
<code>whenXPath("/nmwg:message/@id").then(NMWGMessage.class).setId(any(String.class))</code>
+ * deserializer will fire setId method from instance of NMWGMesssage class
and provide
+ * as an argument the result of XPath expression provided in whenXPath
method.
+ * During configuration no real method is executed.
+ * The following configuration is developer friendly. It statically checks
whether
+ * the method exists and in case of refactoring it will be reconfigured
automatically.
+ *
+ * By invoking:
+ * <code>whenXPath(
+ *
"nmwg:message/nmwg:data[starts-with(@metadataIdRef,
'metadata')]/@metadataIdRef")
+ * .then(Command.class).setCurrentRouter(
+ * getReference(Router.class,
identifier(Router.class).getId()));</code>
+ *
+ * deserializer will invoke setCurrentRouter method and will provide a real
instance (not string)
+ * of Router class identified by getId method in defined in Router class.
+ *
+ * Configuring deserializer via annotations requires psbase3-apt tool to be
present on the classpath during compilation.
+ * By invoking:
+ *
<code>@XPath(xpath="nmwg:message/nmwg:metadata[@id='meta']/nmwg:eventType/text()",
+ *
namespaces=@Namespace(prefix="nmwg",
uri=NMWG_URI)) public void setEventType(String type)</code>
+ *
+ * setEventType method will be invoked when the xpath will be evaluated.
+ *
+ * @author <a
href="mailto:">Blazej
Pietrzak</a>
+ *
+ */
+public class XPathDeserializer {
+
+ private final static DefaultNamespaceContext context = new
DefaultNamespaceContext();
+ private Map<Class<?>, List<Object>> instances = new
Hashtable<Class<?>, List<Object>>();
+
+ private static Map<Method, Object> objects = new Hashtable<Method,
Object>();
+ private static Map<String, Method> xpaths = new Hashtable<String,
Method>();
+ private static Map<Class<?>, Method> identifiers = new
Hashtable<Class<?>, Method>();
+
+ public static void declarePrefix(String prefix, String uri) {
+ context.declarePrefix(prefix, uri);
+ }
+
+ public static XPathConfiguration whenXPath(String xpath) {
+ return new XPathConfiguration(xpath);
+ }
+
+ public static <T> T getReference(Class<T> type, String id) throws
InstantiationException, IllegalAccessException {
+ return type.newInstance();
+ }
+
+ @SuppressWarnings("unchecked")
+ public static <T> T identifier(Class<T> type) {
+ return (T) Enhancer.create(type, new ReferenceInterceptor());
+ }
+
+ public static <T> T any(Class<T> type) {
+ return null;
+ }
+
+ public static void putXPath(String xpath, Object object, Method
method) {
+ objects.put(method, object);
+ xpaths.put(xpath, method);
+ }
+
+ public static void putXPath(String xpath, Method method) {
+ xpaths.put(xpath, method);
+ }
+
+ public static void clearConfiguration() {
+ xpaths.clear();
+ }
+
+ private static Set<String> getXPaths() {
+ return xpaths.keySet();
+ }
+
+ private static Method getXPathMethod(String xpath) {
+ return xpaths.get(xpath);
+ }
+
+ public XPathDeserializer() {
+ }
+
+ /**
+ * Deserializes objects from xml stream using streaming XPath
expressions.
+ */
+ public List<?> deserialize(InputSource reader) throws
SAXPathException, XPathException, IllegalArgumentException,
IllegalAccessException, InvocationTargetException, InstantiationException {

+ final XMLDog dog = new XMLDog(context);
+ final List<Expression> expressions = new
ArrayList<Expression>();
+ for (String xpath : XPathDeserializer.getXPaths()) {
+ expressions.add(dog.addXPath(xpath));
+ }
+
+ final XPathResults results = dog.sniff(reader);
+
+ for (Expression expr : sort(expressions)) {
+ @SuppressWarnings("unchecked")
+ final Collection<NodeItem> temp =
(Collection<NodeItem>) results.getResult(expr);
+ if (temp.size() <= 0) continue;
+ final Method method =
XPathDeserializer.getXPathMethod(expr.getXPath());
+
+ for (NodeItem item : temp) {
+ if
(method.getParameterTypes()[0].equals(String.class)) {
+ method.invoke(getInstance(method),
item.value);
+ } else {
+ final Object reference =
getReference(item.value, identifiers.get(method.getParameterTypes()[0]));
+ if (reference == null) continue;
+ method.invoke(getInstance(method),
reference);
+ }
+
+ increment(method);
+ }
+ }
+
+ final List<Object> result = new ArrayList<Object>();
+ for (List<Object> temp : instances.values())
+ result.addAll(temp);
+ return result;
+
+ }
+
+ @SuppressWarnings("unchecked")
+ public <T> List<T> getObjects(Class<T> type, List<Object> objects) {
+ final List<T> result = new ArrayList<T>();
+ for (Object obj : objects) {
+ if (obj.getClass().equals(type)) {
+ result.add((T) obj);
+ }
+ }
+ return result;
+ }
+
+ private List<Expression> sort(List<Expression> expressions) {
+ final List<Expression> result = new ArrayList<Expression>();
+ final Iterator<Expression> iter = expressions.iterator();
+
+ if (expressions.size() <= 0)
+ return result;
+
+ for (Expression expr = iter.next(); iter.hasNext(); expr =
iter.next()) {
+ Method method =
XPathDeserializer.getXPathMethod(expr.getXPath());
+ if (method == null)
+ throw new RuntimeException("Cannot find
method for xpath " + expr.getXPath());
+ if
(method.getParameterTypes()[0].equals(String.class)) {
+ result.add(expr);
+ iter.remove();
+ }
+ }
+
+ result.addAll(expressions);
+
+ return result;
+ }
+
+ private Object getReference(String value, Method identifierMethod)
throws IllegalArgumentException, IllegalAccessException,
InvocationTargetException {
+ if (instances.get(identifierMethod.getDeclaringClass()) ==
null)
+ return null;
+
+ for (Object instance :
instances.get(identifierMethod.getDeclaringClass())) {
+ if (identifierMethod.invoke(instance).equals(value))
+ return instance;
+ }
+ return null;
+ }
+
+ private void increment(Method method) {
+ if (counts.get(method) == null)
+ counts.put(method, 0);
+
+ counts.put(method, counts.get(method) + 1);
+ }
+
+ private Map<Method, Integer> counts = new Hashtable<Method,
Integer>();
+
+ private int getCount(Method method) {
+ if (counts.get(method) == null)
+ counts.put(method, 0);
+
+ return counts.get(method);
+ }
+
+ private Object getInstance(Method method) throws
InstantiationException, IllegalAccessException {
+ if (Modifier.isStatic(method.getModifiers()))
+ return null;
+ if (objects.get(method) != null)
+ return objects.get(method);
+ if (instances.get(method.getDeclaringClass()) == null) {
+ instances.put(method.getDeclaringClass(), new
ArrayList<Object>());
+ }
+ if (instances.get(method.getDeclaringClass()).size() <
getCount(method) + 1)
+
instances.get(method.getDeclaringClass()).add(method.getDeclaringClass().newInstance());
+
+ return
instances.get(method.getDeclaringClass()).get(getCount(method));
+ }
+
+ protected static void putIdentifier(Class<?> declaringClass, Method
method) {
+ XPathDeserializer.identifiers.put(declaringClass, method);
+ }
+}

Added:
trunk/psBase3/perfsonar-messaging/src/main/java/net/geant/perfsonar/templates/TemplateEngine.java
===================================================================
---
trunk/psBase3/perfsonar-messaging/src/main/java/net/geant/perfsonar/templates/TemplateEngine.java
(rev 0)
+++
trunk/psBase3/perfsonar-messaging/src/main/java/net/geant/perfsonar/templates/TemplateEngine.java
2013-02-18 18:58:03 UTC (rev 6144)
@@ -0,0 +1,68 @@
+package net.geant.perfsonar.templates;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Writer;
+
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.app.VelocityEngine;
+
+/**
+ * Provides facade to the underlying template engine. This implementation
uses
+ * Velocity engine.
+ *
+ * @author <a
href="mailto:">Blazej
Pietrzak</a>
+ *
+ */
+public class TemplateEngine {
+ private final static VelocityEngine templateEngine = new
VelocityEngine();
+ private final static VelocityContext context = new VelocityContext();
+
+ static {
+ try {
+ templateEngine.init();
+ } catch (Exception ex) { }
+ }
+
+ private static InputStream getTemplate(Class<?> homeDir, String name)
+ throws IOException {
+ final InputStream in =
homeDir.getClassLoader().getResourceAsStream(
+ getFullPath(homeDir, name));
+
+ if (in == null)
+ throw new IOException("Template " + name + " cannot
be found.");
+ return in;
+ }
+
+ private static String getFullPath(Class<?> homeDir, String name) {
+ String result = homeDir.getPackage().getName();
+ for (; result.indexOf(".") != -1; result = result.replace(".",
+ File.separator))
+ ;
+ return result + File.separator + name;
+ }
+
+ /**
+ * Writes to the stream provided by writer argument, the template
found in
+ * the directory where the given class is stored using the template
provided
+ * by name.
+ *
+ */
+ public static void evaluate(Writer writer, Class<?> homeDir, String
name)
+ throws IOException {
+ // TODO change to not deprecated
+ templateEngine.evaluate(context, writer, "successMessage",
+ getTemplate(homeDir, name));
+ }
+
+
+ /**
+ * Put data to the context. Data can be used in templates with a
macro ${identifier}
+ * where identifier is the name put in the context.
+ * More on template engine can be found at Apache Velocity website.
+ */
+ public static void put(String name, Object value) {
+ context.put(name, value);
+ }
+}

Added:
trunk/psBase3/perfsonar-messaging/src/test/groovy/net/geant/perfsonar/templates/NMWG.groovy
===================================================================
---
trunk/psBase3/perfsonar-messaging/src/test/groovy/net/geant/perfsonar/templates/NMWG.groovy
(rev 0)
+++
trunk/psBase3/perfsonar-messaging/src/test/groovy/net/geant/perfsonar/templates/NMWG.groovy
2013-02-18 18:58:03 UTC (rev 6144)
@@ -0,0 +1,216 @@
+package net.geant.perfsonar.templates
+
+import net.geant.perfsonar.mp.sshtelnet.Command;
+import net.geant.perfsonar.mp.sshtelnet.Router;
+
+
+import java.io.InputStream;
+import java.io.Reader;
+
+import groovy.xml.MarkupBuilder
+
+class NMWG {
+ private static Reader createRequest(id, eventType, version) {
+ def writer = new StringWriter()
+ MarkupBuilder xml = new MarkupBuilder(writer)
+ xml.mkp.xmlDeclaration(version:"1.0", encoding:"UTF-8")
+
xml.'nmwg:message'('xmlns:nmwg':'http://ggf.org/ns/nmwg/base/2.0/', id:id,
type:"EchoRequest") {
+ 'nmwg:metadata'(id:"meta") {
+ 'nmwg:eventType'
"http://schemas.perfsonar.net/tools/admin/${eventType}/${version}";
+ }
+ 'nmwg:data'(id:"data", metadataIdRef:"meta")
+ }
+
+ writer.write("\n");
+ new StringReader(writer.toString())
+ }
+
+ static Reader toEchoRequest(String id) {
+ createRequest(id, "echo", "2.0")
+ }
+
+ static Reader toSelfTestRequest(String id) {
+ createRequest(id, "selftest", "1.0")
+ }
+
+ static Reader toMetadataKeyRequest(String id) {
+ def writer = new StringWriter()
+ MarkupBuilder xml = new MarkupBuilder(writer)
+
xml.'nmwg:message'('xmlns:nmwg':'http://ggf.org/ns/nmwg/base/2.0/', id:id,
type:"MetadataKeyRequest") {
+ 'nmwg:metadata'(id:"meta") {
+ 'nmwg:subject'(id:"server") {
+ 'nmwg:parameters'(id:"params") {
+
'nmwg:parameter'(name:"param", "SES")
+ }
+ }
+ }
+ 'nmwg:data'(id:"data", metadataIdRef:"meta")
+ }
+
+ new StringReader(writer.toString())
+ }
+
+ static Reader toSetupDataRequest(String id, Command... commands) {
+ def idx = 0;
+ final def writer = new StringWriter()
+ final MarkupBuilder xml = new MarkupBuilder(writer)
+ xml.mkp.xmlDeclaration(version:"1.0", encoding:"UTF-8")
+
xml.'nmwg:message'('xmlns:nmwg':'http://ggf.org/ns/nmwg/base/2.0/',
'xmlns:nmwgtopo':'http://ggf.org/ns/nmwg/topology/2.0/', id:id,
type:"SetupDataRequest") {
+ commands.each { command ->
+ 'nmwg:metadata'(id:"meta${idx}") {
+ 'nmwg:subject'(id:"subject${idx}") {
+
'nmwgtopo:endPoint'(type:"hostname", command.routerName)
+ }
+ 'nmwg:parameters'(id:"params${idx}") {
+
'nmwg:parameter'(name:"command", value:command.name)
+
'nmwg:parameter'(name:"description", value:command.description)
+
'nmwg:parameter'(name:"syntax", value:command.syntax)
+ }
+ 'nmwg:eventType' command.eventType
+ }
+ 'nmwg:data'(id:"data${idx}",
metadataIdRef:"meta${idx}")
+ }
+ }
+ new StringReader(writer.toString())
+ }
+
+ static Reader toSelfTestResponse(requestId, SelfTestResult... tests) {
+ createResponse(requestId) {
+ 'nmwg:metadata'(id:"meta") {
+ 'nmwg:eventType'
"http://schemas.perfsonar.net/tools/admin/selftest/1.0";
+ }
+ 'nmwg:data'(id:"data", metadataIdRef:"meta") {
+ tests.each { test ->
+ 'nmwg:metadata'(id:"${test.name}") {
+ 'nmwg:eventType'
"http://schemas.perfsonar.net/tools/admin/selftest/MP/SSHTELNET/${test.name}/${test.status}/1.0";
+ }
+ 'nmwg:data'(id:"data_${test.name}",
metadataIdRef:"${test.name}") {
+ 'nmwg:datum' test.message
+ }
+ }
+ }
+ }
+ }
+
+ static Reader toEchoResponse(requestId) {
+ createResponse(requestId) {
+ 'nmwg:metadata'(id:"result-code") {
+ 'nmwg:eventType' "echo/success"
+ }
+ 'nmwg:data'(id:"result-code-description",
metadataIdRef:"result-code") {
+
'nmwgr:datum'('xmlns:nmwgr':"http://ggf.org/ns/nmwg/result/2.0/";,
+ "This is the success echo response
from the service.")
+ }
+ }
+ }
+
+ private static Reader createResponse(requestId, body) {
+ final def writer = new StringWriter()
+ final MarkupBuilder xml = new MarkupBuilder(writer)
+ xml.mkp.xmlDeclaration(version:"1.0", encoding:"UTF-8")
+
xml.'nmwg:message'('xmlns:nmwg':"http://ggf.org/ns/nmwg/base/2.0/";,
+ id:"Resp_${requestId}", messageIdRef:"${requestId}",
type:"EchoResponse", body)
+
+ new StringReader(writer.toString())
+ }
+
+ public static Reader toMetadataKeyResponse(String requestId,
Router... routers) {
+ def idx = 0;
+ final def writer = new StringWriter()
+ final MarkupBuilder xml = new MarkupBuilder(writer)
+ xml.mkp.xmlDeclaration(version:"1.0", encoding:"UTF-8")
+
xml.'nmwg:message'('xmlns:nmwg':"http://ggf.org/ns/nmwg/base/2.0/";,
+ id:"${requestId}_resp", messageIdRef:"${requestId}",
type:"MetadataKeyResponse") {
+
+ routers.each { router ->
+ 'nmwg:metadata'(id:"metadata${idx}") {
+ 'nmwg:subject'(id:"subject${idx}",
router.name)
+
'nmwg:parameters'(id:"metaParams${idx}") {
+ 'nmwg:parameter'(name:"url",
value:router.address.hostAddress)
+ }
+ }
+ idx++
+ }
+
+ idx = 0
+ routers.each { router ->
+ 'nmwg:metadata'(id:"resultCodeMeta_${idx}") {
+
'nmwg:subject'(id:"resultCodeSubj_${idx}", metadataIdRef:"metadata${idx}")
+
'nmwg:eventType'("success.mp.sshtelnet")
+ }
+ 'nmwg:data'(id:"resultCodeMeta_${idx}",
metadataIdRef:"resultCodeMeta_${idx}") {
+
'nmwgr:datum'('xmlns:nmwgr':"http://ggf.org/ns/nmwg/result/2.0/";,
"Successfully executed MetaDataKeyRequest")
+ }
+ idx++
+ }
+
+ idx = 0
+ routers.each { router ->
+ 'nmwg:data'(id:"data${idx}",
metadataIdRef:"metadata${idx}") {
+ router.commands.each { command ->
+
'nmwgr:datum'('xmlns:nmwgr':"http://ggf.org/ns/nmwg/result/2.0/";) {
+
'nmwg:parameters'(id:"params${idx}") {

+
'nmwg:parameter'(name:"command", value:command.name)
+
'nmwg:parameter'(name:"description", value:command.description)
+ if
(command.syntax == null)
+
'nmwg:parameter'(name:"syntax")
+ else
+
'nmwg:parameter'(name:"syntax", value:command.syntax)
+ }
+
'nmwg:eventType'(command.eventType)
+ }
+ }
+ }
+ idx++
+ }
+ }
+
+ new StringReader(writer.toString())
+ }
+
+ public static Reader toSetupDataResponse(String requestId, Command...
commands) {
+ def idx = 0;
+ final def writer = new StringWriter()
+ final MarkupBuilder xml = new MarkupBuilder(writer)
+ xml.mkp.xmlDeclaration(version:"1.0", encoding:"UTF-8")
+
xml.'nmwg:message'('xmlns:nmwg':"http://ggf.org/ns/nmwg/base/2.0/";,
id:"${requestId}_resp", messageIdRef:"${requestId}",
type:"SetupDataResponse") {
+ commands.each { command ->
+ 'nmwg:metadata'(id:"meta${idx}") {
+ 'nmwg:subject'(id:"subject${idx}") {
+
'nmwgtopo:endPoint'('xmlns:nmwgtopo':"http://ggf.org/ns/nmwg/topology/2.0/";,
type:"hostname", command.routerName)
+ }
+ 'nmwg:parameters'(id:"params${idx}")
+ 'nmwg:eventType'(command.eventType)
+ }
+
+ 'nmwg:data'(id:"data${idx}",
metadataIdRef:"meta${idx}") {
+ 'nmwg:datum'(command.result)
+ }
+
'nmwg:metadata'(id:"resultCodeMeta_meta${idx}") {
+
'nmwg:subject'(id:"resultCodeSubj_meta${idx}", metadataIdRef:"meta${idx}")
+ 'nmwg:eventType'("success.mp.sshtelnet")
+ }
+ 'nmwg:data'(id:"resultCodeData_meta${idx}",
metadataIdRef:"resultCodeMeta_meta${idx}") {
+
'nmwgr:datum'('xmlns:nmwgr':"http://ggf.org/ns/nmwg/result/2.0/";,
"Successfully executed request")
+ }
+
+ idx++
+ }
+ }
+ new StringReader(writer.toString())
+ }
+
+ public static Reader toLSResponse(String id) {
+ def writer = new StringWriter()
+ MarkupBuilder xml = new MarkupBuilder(writer)
+
xml.'nmwg:message'('xmlns:nmwg':'http://ggf.org/ns/nmwg/base/2.0/',
id:"${id}_resp", messageIdRef:id, type:"LSRegisterResponse") {
+ 'nmwg:metadata'(id:"meta") {
+ 'nmwg:eventType' "success"
+ 'nmwg:key' "${id}"
+ }
+ 'nmwg:data'(id:"data", metadataIdRef:"meta")
+ }
+
+ new StringReader(writer.toString())
+ }
+}

Added:
trunk/psBase3/perfsonar-messaging/src/test/java/net/geant/perfsonar/messaging/xpath/XMLDogTest.java
===================================================================
---
trunk/psBase3/perfsonar-messaging/src/test/java/net/geant/perfsonar/messaging/xpath/XMLDogTest.java
(rev 0)
+++
trunk/psBase3/perfsonar-messaging/src/test/java/net/geant/perfsonar/messaging/xpath/XMLDogTest.java
2013-02-18 18:58:03 UTC (rev 6144)
@@ -0,0 +1,85 @@
+package net.geant.perfsonar.messaging.xpath;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+import jlibs.xml.DefaultNamespaceContext;
+import jlibs.xml.sax.dog.NodeItem;
+import jlibs.xml.sax.dog.XMLDog;
+import jlibs.xml.sax.dog.expr.Expression;
+import jlibs.xml.sax.dog.expr.InstantEvaluationListener;
+import jlibs.xml.sax.dog.sniff.DOMBuilder;
+import jlibs.xml.sax.dog.sniff.Event;
+import net.geant.perfsonar.templates.NMWG;
+
+import org.jaxen.saxpath.SAXPathException;
+import org.junit.Before;
+import org.junit.Test;
+import org.xml.sax.InputSource;
+
+public class XMLDogTest {
+ private static final String REQUEST_ID = "request1";
+ private DefaultNamespaceContext nsContext;
+ private XMLDog dog;
+ private String xpathResult;
+
+ @Before
+ public void givenXMLDog() {
+ nsContext = new DefaultNamespaceContext();
+ nsContext.declarePrefix("nmwg",
"http://ggf.org/ns/nmwg/base/2.0/";);
+ dog = new XMLDog(nsContext);
+ }
+
+ @Test
+ public void shouldEvaluatePrimitiveTypesFromStream() throws Exception
{
+ final Event event = createEvent("string(nmwg:message/@id)",
new InstantEvaluationListener() {
+ @Override
+ public void onNodeHit(Expression expression, NodeItem
nodeItem) { fail(); }
+
+ @Override
+ public void finishedNodeSet(Expression expression) {
fail(); }
+
+ @Override
+ public void onResult(Expression expression, Object
result) {
+ xpathResult = result.toString();
+ }
+ });
+
+ dog.sniff(event, new
InputSource(NMWG.toEchoRequest(REQUEST_ID)), false/*useSTAX*/);
+ Thread.sleep(1000);
+ assertEquals(REQUEST_ID, xpathResult);
+ }
+
+ @Test
+ public void shouldEvaluateNodesFromStream() throws Exception {
+ final Event event = createEvent("nmwg:message/@id", new
InstantEvaluationListener() {
+ private String tempResult;
+ @Override
+ public void onNodeHit(Expression expression, NodeItem
nodeItem) {
+ tempResult = nodeItem.value;
+ }
+
+ @Override
+ public void finishedNodeSet(Expression expression) {
+ xpathResult = tempResult;
+ }
+
+ @Override
+ public void onResult(Expression expression, Object
result) {
+ fail();
+ }
+ });
+
+ dog.sniff(event, new
InputSource(NMWG.toEchoRequest(REQUEST_ID)), false/*useSTAX*/);
+ Thread.sleep(1000);
+ assertEquals(REQUEST_ID, xpathResult);
+ }
+
+ private Event createEvent(String xpath, InstantEvaluationListener
listener) throws SAXPathException {
+ dog.addXPath(xpath);
+ final Event event = dog.createEvent(); // must be after all
expressions are added.
+ event.setXMLBuilder(new DOMBuilder());
+ event.setListener(listener);
+ return event;
+ }
+
+}

Added:
trunk/psBase3/perfsonar-messaging/src/test/java/net/geant/perfsonar/messaging/xpath/XPathDeserializerTest.java
===================================================================
---
trunk/psBase3/perfsonar-messaging/src/test/java/net/geant/perfsonar/messaging/xpath/XPathDeserializerTest.java
(rev 0)
+++
trunk/psBase3/perfsonar-messaging/src/test/java/net/geant/perfsonar/messaging/xpath/XPathDeserializerTest.java
2013-02-18 18:58:03 UTC (rev 6144)
@@ -0,0 +1,93 @@
+package net.geant.perfsonar.messaging.xpath;
+
+import static net.geant.perfsonar.messaging.XPathDeserializer.any;
+import static net.geant.perfsonar.messaging.XPathDeserializer.declarePrefix;
+import static net.geant.perfsonar.messaging.XPathDeserializer.getReference;
+import static net.geant.perfsonar.messaging.XPathDeserializer.identifier;
+import static net.geant.perfsonar.messaging.XPathDeserializer.whenXPath;
+import static org.junit.Assert.assertEquals;
+
+import java.io.Reader;
+import java.net.InetAddress;
+import java.util.Arrays;
+import java.util.List;
+
+import net.geant.perfsonar.messaging.XPathDeserializer;
+import net.geant.perfsonar.mp.sshtelnet.Command;
+import net.geant.perfsonar.mp.sshtelnet.Router;
+import net.geant.perfsonar.templates.NMWG;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.xml.sax.InputSource;
+
+public class XPathDeserializerTest {
+ private static final String REQUEST_ID = "1";
+
+ private Router[] routers;
+ private Reader reader;
+ private XPathDeserializer deserializer;
+
+ @Before
+ public void givenMessageAndDeserializationConfigured() throws
Exception {
+
+ routers = new Router[] {
+ new Router("metadata0", "test1",
+
InetAddress.getAllByName("192.168.1.1")[0],
+ Command.PING_IPV6),
+ new Router("metadata1", "test2",
+
InetAddress.getAllByName("192.168.1.2")[0],
+ Command.SHOW_ENVIRONMENT) };
+
+ reader = NMWG.toMetadataKeyResponse(REQUEST_ID, routers);
+
+ declarePrefix("nmwg", "http://ggf.org/ns/nmwg/base/2.0/";);
+ declarePrefix("nmwgr", "http://ggf.org/ns/nmwg/result/2.0/";);
+
+
whenXPath("nmwg:message/nmwg:metadata[starts-with(@id,'metadata')]/@id")
+ .then(Router.class).setId(any(String.class));
+
+ whenXPath(
+
"nmwg:message/nmwg:metadata/nmwg:subject[starts-with(@id, 'subject')]/text()")
+
.then(Router.class).setName(any(String.class));
+
+ whenXPath(
+
"nmwg:message/nmwg:metadata[starts-with(nmwg:subject/@id,
'subject')]/nmwg:parameters/nmwg:parameter[@name='url']/@value")
+
.then(Router.class).setAddress(any(String.class));
+
+ whenXPath(
+
"nmwg:message/nmwg:data[starts-with(@metadataIdRef,
'metadata')]/@metadataIdRef")
+ .then(Command.class).setCurrentRouter(
+ getReference(Router.class,
identifier(Router.class).getId()));
+
+ whenXPath(
+
"nmwg:message/nmwg:data[starts-with(@metadataIdRef,
'metadata')]/nmwgr:datum/nmwg:parameters/nmwg:parameter[@name='command']/@value")
+
.then(Command.class).setName(any(String.class));
+
+ whenXPath(
+
"nmwg:message/nmwg:data[starts-with(@metadataIdRef,
'metadata')]/nmwgr:datum/nmwg:parameters/nmwg:parameter[@name='description']/@value")
+
.then(Command.class).setDescription(any(String.class));
+
+ whenXPath(
+
"nmwg:message/nmwg:data[starts-with(@metadataIdRef,
'metadata')]/nmwgr:datum/nmwg:parameters/nmwg:parameter[@name='syntax']/@value")
+
.then(Command.class).setSyntax(any(String.class));
+
+ deserializer = new XPathDeserializer();
+ }
+
+ @After
+ public void clearConfiguration() {
+ XPathDeserializer.clearConfiguration();
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void shouldReturnRouters() throws Exception {
+ final List<Object> actual = (List<Object>)
deserializer.deserialize(new InputSource(reader));
+
+ assertEquals(Arrays.asList(Command.PING_IPV6,
Command.SHOW_ENVIRONMENT), deserializer.getObjects(Command.class, actual));
+ assertEquals(Arrays.asList(new Router("metadata0", "test1",
InetAddress.getAllByName("192.168.1.1")[0]),
+ new Router("metadata1", "test2",
InetAddress.getAllByName("192.168.1.2")[0])),
deserializer.getObjects(Router.class, actual));
+ }
+}

Added:
trunk/psBase3/perfsonar-messaging/src/test/java/net/geant/perfsonar/mp/sshtelnet/Command.java
===================================================================
---
trunk/psBase3/perfsonar-messaging/src/test/java/net/geant/perfsonar/mp/sshtelnet/Command.java
(rev 0)
+++
trunk/psBase3/perfsonar-messaging/src/test/java/net/geant/perfsonar/mp/sshtelnet/Command.java
2013-02-18 18:58:03 UTC (rev 6144)
@@ -0,0 +1,163 @@
+package net.geant.perfsonar.mp.sshtelnet;
+
+import java.io.IOException;
+
+public class Command {
+
+ public static final Command PING = new Command("ping", "ping an [ip
address]", "[ip address]", "IP_PING");
+
+ public static Command SHOW_ENVIRONMENT = new Command("show
environment", "show chassis environment", "",
"http://schemas.perfsonar.net/tools/sshtelnet/STATUS_SHOW_ENVIRONMENT/1.0";);
+
+ public static final Command TRACE_IPV4 = new Command("trace", "trace
the IPv4 path to [ip address]", "[ip address]",
"http://schemas.perfsonar.net/tools/sshtelnet/IP_TRACEROUTE/1.0";);
+
+ public static final Command TRACE_IPV6 = new Command("trace ipv6",
"trace the ipv6 path to [IPv6 address]", "[IPv6 address]",
"http://schemas.perfsonar.net/tools/sshtelnet/IPv6_TRACEROUTE/1.0";);
+
+ public static final Command SHOW_INTERFACES_FILTERS = new
Command("show interfaces filters", "display ip access lists", "",
"http://schemas.perfsonar.net/tools/sshtelnet/IP_ACCESS_LIST/1.0";);
+
+ //public static final Command SHOW_IPV6_INTERFACES_FILTERS = new
Command("show interfaces filters", "display IPv6 access lists");
+
+ public static final Command SHOW_IPV6_INTERFACES = new Command("show
interfaces", "display the interfaces which are configured for IPv6",
"[interface] extensive",
"http://schemas.perfsonar.net/tools/sshtelnet/IPv6_INTERFACES/1.0";);
+
+ public static final Command PING_IPV6 = new Command("ping inet6",
"ping an [IPv6 address]", "[IPv6 address]",
"http://schemas.perfsonar.net/tools/sshtelnet/IPv6_PING/1.0";);
+
+ public static final Command TRACEROUTER_IPV6 = new
Command("traceroute inet6", "trace the ipv6 path to [ipv6 address]", "[IPv6
address]",
"http://schemas.perfsonar.net/tools/sshtelnet/IPv6_TRACEROUTE/1.0";);
+
+ private static Router currentRouter;
+
+ private String routerName;
+
+ private String name;
+ private String description;
+ private String syntax;
+
+ private Router router;
+
+ private String eventType;
+
+ private Command(String name, String description, String syntax,
String eventType) {
+ this(currentRouter, name, description, syntax, eventType);
+ }
+
+ private Command(Router router, String name, String description,
String syntax, String eventType) {
+ this.router = router;
+ this.name = name;
+ this.description = description;
+ this.syntax = syntax;
+ this.eventType = eventType;
+ }
+
+ public Command() {
+ this(currentRouter, null, null, null, null);
+ }
+
+ public String getEventType() {
+ return eventType;
+ }
+
+ public void setEventType(String eventType) {
+ this.eventType = eventType;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public String getSyntax() {
+ return syntax;
+ }
+
+ public void execute() throws IOException {
+ //router.execute(this);
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result
+ + ((description == null) ? 0 :
description.hashCode());
+ result = prime * result + ((name == null) ? 0 :
name.hashCode());
+ result = prime * result + ((syntax == null) ? 0 :
syntax.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ Command other = (Command) obj;
+ if (description == null) {
+ if (other.description != null)
+ return false;
+ } else if (!description.equals(other.description))
+ return false;
+ if (name == null) {
+ if (other.name != null)
+ return false;
+ } else if (!name.equals(other.name))
+ return false;
+ if (syntax == null) {
+ if (other.syntax != null)
+ return false;
+ } else if (!syntax.equals(other.syntax))
+ return false;
+ return true;
+ }
+
+ public void setCurrentRouter(Router router) {
+ Command.currentRouter = router;
+ this.router = router;
+ }
+
+ public void setRouter(Router router) {
+ this.router = router;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public void setSyntax(String syntax) {
+ this.syntax = syntax;
+ }
+
+ @Override
+ public String toString() {
+ return "Command [name=" + name + ", description=" +
description
+ + ", syntax=" + syntax + ", router=" +
(router != null ? router.getName() : routerName) + "]";
+ }
+
+ public String getResult() {
+ return "For address family: IPv4 Unicast@@@@@@For address
family: IPv6 Unicast@@@@@@For address family: VPNv4 Unicast@@@@@@For address
family: IPv4 Multicast@@@@@@For address family: IPv6 Multicast@@@@@@For
address family: NSAP Unicast@@@---END---";
+ }
+
+ public String getRouterName() {
+ return routerName;
+ }
+
+ public void setRouterName(String routerName) {
+ this.routerName = routerName;
+ }
+
+ public Command newInstance() {
+ final Command result = new Command();
+ result.setDescription(this.description);
+ result.setEventType(this.eventType);
+ result.setName(this.name);
+ result.setRouterName(this.routerName);
+ result.setSyntax(this.syntax);
+ return result;
+ }
+}

Added:
trunk/psBase3/perfsonar-messaging/src/test/java/net/geant/perfsonar/mp/sshtelnet/Router.java
===================================================================
---
trunk/psBase3/perfsonar-messaging/src/test/java/net/geant/perfsonar/mp/sshtelnet/Router.java
(rev 0)
+++
trunk/psBase3/perfsonar-messaging/src/test/java/net/geant/perfsonar/mp/sshtelnet/Router.java
2013-02-18 18:58:03 UTC (rev 6144)
@@ -0,0 +1,148 @@
+package net.geant.perfsonar.mp.sshtelnet;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+public class Router {
+
+ private static final int PORT_UNDEFINED = -1;
+
+ public String name;
+
+ public InetAddress address;
+
+ public int port;
+
+ private String id;
+
+ private List<Command> commands = new ArrayList<Command>();
+
+ public Router() {
+
+ }
+
+ public Router(String id, String name, InetAddress address, Command...
commands) {
+ this(id, name, address, PORT_UNDEFINED, commands);
+ }
+
+ public Router(String id, String name, InetAddress address, int port,
Command... commands) {
+ this.id = id;
+ this.name = name;
+ this.address = address;
+ this.port = port;
+ for (Command c : commands) {
+ c.setRouter(this);
+ addCommand(c);
+ }
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public InetAddress getAddress() {
+ return address;
+ }
+
+ public int getPort() {
+ return port;
+ }
+
+ public void addCommand(Command command) {
+ commands.add(command);
+ }
+
+ public List<Command> getCommands() {
+ return Collections.unmodifiableList(commands);
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((address == null) ? 0 :
address.hashCode());
+ result = prime * result
+ + ((commands == null) ? 0 :
commands.hashCode());
+ result = prime * result + ((id == null) ? 0 : id.hashCode());
+ result = prime * result + ((name == null) ? 0 :
name.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ Router other = (Router) obj;
+ if (address == null) {
+ if (other.address != null)
+ return false;
+ } else if (!address.equals(other.address))
+ return false;
+ if (commands == null) {
+ if (other.commands != null)
+ return false;
+ } else if (!commands.equals(other.commands))
+ return false;
+ if (id == null) {
+ if (other.id != null)
+ return false;
+ } else if (!id.equals(other.id))
+ return false;
+ if (name == null) {
+ if (other.name != null)
+ return false;
+ } else if (!name.equals(other.name))
+ return false;
+ return true;
+ }
+
+// public RouterConnection connect() throws IOException {
+// //return connectionManager.connect(url, port);
+// return null;
+// }
+
+ @Override
+ public String toString() {
+ return "Router [name=" + name + ", address=" + address + ",
id=" + id
+ + ", commands=" + commands + "]";
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public void setAddress(String address) throws UnknownHostException {
+ this.address = InetAddress.getAllByName(address)[0];
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void startAddingCommands(String routerId) {
+ // TODO Auto-generated method stub
+
+ }
+
+// public void execute(Command command) throws IOException {
+// RouterConnection conn = null;
+// try {
+// conn = connect();
+// //command.result =
device.filter(conn.execute(device.toCommand(command)));
+// } finally {
+// if (conn != null)
+// conn.close();
+// }
+// }
+}

Added:
trunk/psBase3/perfsonar-messaging/src/test/java/net/geant/perfsonar/templates/SelfTestResult.java
===================================================================
---
trunk/psBase3/perfsonar-messaging/src/test/java/net/geant/perfsonar/templates/SelfTestResult.java
(rev 0)
+++
trunk/psBase3/perfsonar-messaging/src/test/java/net/geant/perfsonar/templates/SelfTestResult.java
2013-02-18 18:58:03 UTC (rev 6144)
@@ -0,0 +1,21 @@
+package net.geant.perfsonar.templates;
+
+public class SelfTestResult {
+ protected String name;
+ protected String message;
+ protected String status;
+
+ private SelfTestResult(String name, String message, String status) {
+ this.name = name;
+ this.message = message;
+ this.status = status;
+ }
+
+ public static SelfTestResult failure(String name, String message) {
+ return new SelfTestResult(name, message, "failure");
+ }
+
+ public static SelfTestResult success(String name, String message) {
+ return new SelfTestResult(name, message, "success");
+ }
+}



  • [pS-dev] [GEANT/SA2/ps-java-services] r6144 - in trunk/psBase3/perfsonar-messaging: . src src/main src/main/java src/main/java/net src/main/java/net/geant src/main/java/net/geant/perfsonar src/main/java/net/geant/perfsonar/messaging src/main/java/net/geant/perfsonar/templates src/test src/test/groovy src/test/groovy/net src/test/groovy/net/geant src/test/groovy/net/geant/perfsonar src/test/groovy/net/geant/perfsonar/templates src/test/java src/test/java/net src/test/java/net/geant src/test/java/net/geant/perfsonar src/test/java/net/geant/perfsonar/messaging src/test/java/net/geant/perfsonar/messaging/xpath src/test/java/net/geant/perfsonar/mp src/test/java/net/geant/perfsonar/mp/sshtelnet src/test/java/net/geant/perfsonar/templates, svn-noreply, 02/18/2013

Archive powered by MHonArc 2.6.16.

Top of Page