perfsonar-dev - [pS-dev] [GEANT/SA2/ps-java-services] r6359 - in trunk/perfsonar-base/sample-service: . src/main/java/net/geant/perfsonar/mp/sshtelnet src/main/resources/net/geant/perfsonar/mp/sshtelnet src/test/java/net/geant/perfsonar src/test/java/net/geant/perfsonar/mp/sshtelnet
Subject: perfsonar development work
List archive
[pS-dev] [GEANT/SA2/ps-java-services] r6359 - in trunk/perfsonar-base/sample-service: . src/main/java/net/geant/perfsonar/mp/sshtelnet src/main/resources/net/geant/perfsonar/mp/sshtelnet src/test/java/net/geant/perfsonar src/test/java/net/geant/perfsonar/mp/sshtelnet
Chronological Thread
- From:
- To:
- Subject: [pS-dev] [GEANT/SA2/ps-java-services] r6359 - in trunk/perfsonar-base/sample-service: . src/main/java/net/geant/perfsonar/mp/sshtelnet src/main/resources/net/geant/perfsonar/mp/sshtelnet src/test/java/net/geant/perfsonar src/test/java/net/geant/perfsonar/mp/sshtelnet
- Date: Mon, 6 May 2013 18:04:11 +0100 (BST)
- Authentication-results: sfpop-ironport07.merit.edu; dkim=neutral (message not signed) header.i=none
Author: psnc.pietrzak
Date: 2013-05-06 18:04:11 +0100 (Mon, 06 May 2013)
New Revision: 6359
Added:
trunk/perfsonar-base/sample-service/src/main/java/net/geant/perfsonar/mp/sshtelnet/RouterReference.java
trunk/perfsonar-base/sample-service/src/test/java/net/geant/perfsonar/mp/sshtelnet/ConfigurationFileCheckerTest.java
Removed:
trunk/perfsonar-base/sample-service/src/test/java/net/geant/perfsonar/SSHTelnetMPWebServiceTest.java
Modified:
trunk/perfsonar-base/sample-service/pom.xml
trunk/perfsonar-base/sample-service/src/main/java/net/geant/perfsonar/mp/sshtelnet/Command.java
trunk/perfsonar-base/sample-service/src/main/java/net/geant/perfsonar/mp/sshtelnet/ConfigurationFileChecker.java
trunk/perfsonar-base/sample-service/src/main/java/net/geant/perfsonar/mp/sshtelnet/Router.java
trunk/perfsonar-base/sample-service/src/main/java/net/geant/perfsonar/mp/sshtelnet/SSHTelnetMPService.java
trunk/perfsonar-base/sample-service/src/main/java/net/geant/perfsonar/mp/sshtelnet/ServiceController.java
trunk/perfsonar-base/sample-service/src/main/resources/net/geant/perfsonar/mp/sshtelnet/MetadataKeyResponse.template
trunk/perfsonar-base/sample-service/src/test/java/net/geant/perfsonar/mp/sshtelnet/LSRegisterTest.java
trunk/perfsonar-base/sample-service/src/test/java/net/geant/perfsonar/mp/sshtelnet/SSHTelnetMPTest.java
Log:
Corrected compilation error.
Modified: trunk/perfsonar-base/sample-service/pom.xml
===================================================================
--- trunk/perfsonar-base/sample-service/pom.xml 2013-05-06 13:51:21 UTC (rev
6358)
+++ trunk/perfsonar-base/sample-service/pom.xml 2013-05-06 17:04:11 UTC (rev
6359)
@@ -5,7 +5,7 @@
<parent>
<groupId>net.geant.perfsonar</groupId>
<artifactId>parent</artifactId>
- <version>1.0.1</version>
+ <version>1.0.2</version>
<relativePath>../../parent/</relativePath>
</parent>
@@ -15,12 +15,31 @@
<name>Sample perfSONAR service and tests for the framework.</name>
- <scm>
+ <scm>
<connection>scm:svn:http://svn.geant.net/GEANT/SA2/ps-java-services/trunk/perfsonar-base/sample-service/</connection>
<developerConnection>scm:svn:svn+ssh:///GEANT/SA2/ps-java-services/trunk/perfsonar-base/sample-service/</developerConnection>
<url>https://svn.geant.net/fisheye/browse/SA2T3-ps-java-services/trunk/perfsonar-base/sample-service/</url>
</scm>
+
+ <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>net.geant.perfsonar.base</groupId>
@@ -37,11 +56,14 @@
<artifactId>annotations</artifactId>
<version>3.0.0-SNAPSHOT</version>
</dependency>
- <dependency> <!-- Remove it if you want to use API instead of
annotations -->
+
+ <!-- Remove it if you want to use API instead of annotations
-->
+ <dependency>
<groupId>net.geant.perfsonar.base</groupId>
<artifactId>apt</artifactId>
<version>3.0.0-SNAPSHOT</version>
</dependency>
+
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Modified:
trunk/perfsonar-base/sample-service/src/main/java/net/geant/perfsonar/mp/sshtelnet/Command.java
===================================================================
---
trunk/perfsonar-base/sample-service/src/main/java/net/geant/perfsonar/mp/sshtelnet/Command.java
2013-05-06 13:51:21 UTC (rev 6358)
+++
trunk/perfsonar-base/sample-service/src/main/java/net/geant/perfsonar/mp/sshtelnet/Command.java
2013-05-06 17:04:11 UTC (rev 6359)
@@ -2,9 +2,16 @@
import java.io.IOException;
+import net.geant.perfsonar.annotations.Identifier;
import net.geant.perfsonar.annotations.Namespace;
import net.geant.perfsonar.annotations.XPath;
+import net.geant.perfsonar.annotations.XPaths;
+/**
+ * Command executed on a router.
+ *
+ * @author <a
href="mailto:">Blazej
Pietrzak</a>
+ */
public class Command {
public static final Command PING = new Command("ping", "ping an [ip
address]", "[ip address]", "IP_PING");
@@ -24,40 +31,56 @@
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 routerName;
private String name;
private String description;
private String syntax;
-
+ private String eventType;
+ private String id;
+ private String result;
+
private Router router;
-
- private String eventType;
+
+ Command(Command cmd, String routerName) {
+ setDescription(cmd.description);
+ setEventType(cmd.eventType);
+ setName(cmd.name);
+ setSyntax(cmd.syntax);
+ setRouterName(routerName);
+ }
private Command(String name, String description, String syntax,
String eventType) {
- this(currentRouter, name, description, syntax, eventType);
+ this(RouterReference.getCurrentRouter(), 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;
+ this.router = router;
+ if (router != null)
+ router.addCommand(this);
}
public Command() {
- this(currentRouter, null, null, null, null);
+ this(RouterReference.getCurrentRouter(), null, null, null,
null);
}
+ public void setRouter(Router router) {
+ this.router = router;
+ }
+
public String getEventType() {
return eventType;
}
- @XPath(xpath="nmwg:message/nmwg:metadata/nmwg:eventType/text()")
+ @XPaths({
+
@XPath(xpath="nmwg:message[@type='MetadataKeyResponse']/nmwg:data/nmwgr:datum/nmwg:eventType/text()",
namespaces=@Namespace(prefix="nmwgr",
uri="http://ggf.org/ns/nmwg/result/2.0/")),
+
@XPath(xpath="nmwg:message[@type='SetupDataRequest']/nmwg:metadata/nmwg:eventType/text()"),
+
@XPath(xpath="nmwg:message[@type='SetupDataResponse']/nmwg:metadata[nmwg:subject/nmwgtopo:endPoint]/nmwg:eventType/text()")
+ })
public void setEventType(String eventType) {
this.eventType = eventType;
}
@@ -76,6 +99,7 @@
public void execute() throws IOException {
//router.execute(this);
+ result = "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---";
}
@Override
@@ -84,7 +108,15 @@
int result = 1;
result = prime * result
+ ((description == null) ? 0 :
description.hashCode());
+ result = prime * result
+ + ((eventType == null) ? 0 :
eventType.hashCode());
+ result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + ((name == null) ? 0 :
name.hashCode());
+ result = prime * result
+ + ((this.result == null) ? 0 :
this.result.hashCode());
+ result = prime * result + ((router == null) ? 0 :
router.hashCode());
+ result = prime * result
+ + ((routerName == null) ? 0 :
routerName.hashCode());
result = prime * result + ((syntax == null) ? 0 :
syntax.hashCode());
return result;
}
@@ -98,16 +130,37 @@
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 (eventType == null) {
+ if (other.eventType != null)
+ return false;
+ } else if (!eventType.equals(other.eventType))
+ return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
+ if (result == null) {
+ if (other.result != null)
+ return false;
+ } else if (!result.equals(other.result))
+ return false;
+ if (router == null) {
+ if (other.router != null)
+ return false;
+ } else if (!router.getName().equals(other.router.getName()))
+ return false;
+ if (routerName == null) {
+ if (other.routerName != null)
+ return false;
+ } else if (!routerName.equals(other.routerName))
+ return false;
if (syntax == null) {
if (other.syntax != null)
return false;
@@ -116,38 +169,38 @@
return true;
}
- public void setCurrentRouter(Router router) {
- Command.currentRouter = router;
- this.router = router;
- }
-
- public void setRouter(Router router) {
- this.router = router;
- }
-
-
@XPath(xpath="nmwg:message/nmwg:metadata/nmwg:parameters/nmwg:parameter[@name='command']/@value")
+ @XPaths({
+
@XPath(xpath="nmwg:message/nmwg:data[starts-with(@metadataIdRef,
'metadata')]/nmwgr:datum/nmwg:parameters/nmwg:parameter[@name='command']/@value",
namespaces=@Namespace(prefix="nmwgr",
uri="http://ggf.org/ns/nmwg/result/2.0/")),
+
@XPath(xpath="nmwg:message/nmwg:metadata/nmwg:parameters/nmwg:parameter[@name='command']/@value")
+ })
public void setName(String name) {
this.name = name;
}
-
@XPath(xpath="nmwg:message/nmwg:metadata/nmwg:parameters/nmwg:parameter[@name='description']/@value")
+ @XPaths({
+ @XPath(xpath="nmwg:message/nmwg:data[starts-with(@metadataIdRef,
'metadata')]/nmwgr:datum/nmwg:parameters/nmwg:parameter[@name='description']/@value"),
+
@XPath(xpath="nmwg:message/nmwg:metadata/nmwg:parameters/nmwg:parameter[@name='description']/@value")
+ })
public void setDescription(String description) {
this.description = description;
}
-
@XPath(xpath="nmwg:message/nmwg:metadata/nmwg:parameters/nmwg:parameter[@name='syntax']/@value")
+ @XPaths({
+
@XPath(xpath="nmwg:message/nmwg:data[starts-with(@metadataIdRef,
'metadata')]/nmwgr:datum/nmwg:parameters/nmwg:parameter[@name='syntax']/@value"),
+
@XPath(xpath="nmwg:message/nmwg:metadata/nmwg:parameters/nmwg:parameter[@name='syntax']/@value")
+ })
public void setSyntax(String syntax) {
this.syntax = syntax;
}
@Override
public String toString() {
- return "Command [name=" + name + ", description=" +
description
+ return "Command [id=" + id + ", name=" + name + ",
eventType=" + eventType + ", 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---";
+ return result;
}
public String getRouterName() {
@@ -158,14 +211,19 @@
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;
+
+
@XPath(xpath="nmwg:message[@type='SetupDataResponse']/nmwg:metadata[nmwg:subject/nmwgtopo:endPoint]/@id")
+ public void setId(String id) {
+ this.id = id;
}
+
+ @Identifier
+ public String getId() {
+ return id;
+ }
+
+ @XPath(xpath="nmwg:message/nmwg:data[starts-with(@metadataIdRef,
'meta')]/nmwg:datum/text()")
+ public void setResult(String result) {
+ this.result = result;
+ }
}
Modified:
trunk/perfsonar-base/sample-service/src/main/java/net/geant/perfsonar/mp/sshtelnet/ConfigurationFileChecker.java
===================================================================
---
trunk/perfsonar-base/sample-service/src/main/java/net/geant/perfsonar/mp/sshtelnet/ConfigurationFileChecker.java
2013-05-06 13:51:21 UTC (rev 6358)
+++
trunk/perfsonar-base/sample-service/src/main/java/net/geant/perfsonar/mp/sshtelnet/ConfigurationFileChecker.java
2013-05-06 17:04:11 UTC (rev 6359)
@@ -30,24 +30,40 @@
}
public void run() {
- if (!file.exists()) {
+ if (!configurationExists()) {
System.err.println("Configuration file: " +
file.getAbsolutePath()
+ " is missing");
return;
}
- if (file.lastModified() > lastModified) {
+ if (isModified()) {
lastModified = file.lastModified();
configureDeserialization();
XPathDeserializer deserializer = new
XPathDeserializer();
try {
deserializer.deserialize(new InputSource(new
FileInputStream(file)));
- } catch (Exception ex) {
+ } catch (Throwable ex) {
ex.printStackTrace();
}
}
- }
+ }
+
+ protected boolean configurationExists() {
+ return file.exists();
+ }
+
+ protected boolean isModified() {
+ return file.lastModified() > lastModified;
+ }
+ protected long getCurrentModified() {
+ return lastModified;
+ }
+
+ protected long lastModified() {
+ return file.lastModified();
+ }
+
private void configureDeserialization() {
//When configuring XPath the configurator creates a subclass
of SSHTelnetMPService that registers method invocations.
//The instance executes base class constructor of
SSHTelnetMPService which creates this task.
@@ -65,6 +81,8 @@
whenXPath(
"ns:configuration/ns:service/ns:auxiliaryComponents/ns:component[@name='scheduling']/ns:actions/ns:action[@name='registration']/ns:option[starts-with(@name,
'lsAddress')]/@value")
.then(LSRegistrationTask.class).addLSAddress(any(String.class));
- } catch (Exception ex) { }
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
}
}
Modified:
trunk/perfsonar-base/sample-service/src/main/java/net/geant/perfsonar/mp/sshtelnet/Router.java
===================================================================
---
trunk/perfsonar-base/sample-service/src/main/java/net/geant/perfsonar/mp/sshtelnet/Router.java
2013-05-06 13:51:21 UTC (rev 6358)
+++
trunk/perfsonar-base/sample-service/src/main/java/net/geant/perfsonar/mp/sshtelnet/Router.java
2013-05-06 17:04:11 UTC (rev 6359)
@@ -1,27 +1,35 @@
package net.geant.perfsonar.mp.sshtelnet;
+import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import net.geant.perfsonar.annotations.Identifier;
+import net.geant.perfsonar.annotations.XPath;
+
+/**
+ * Router that runs commands.
+ *
+ * @author <a
href="mailto:">Blazej
Pietrzak</a>
+ */
public class Router {
private static final int PORT_UNDEFINED = -1;
- public String name;
+ private String name;
- public InetAddress address;
+ private InetAddress address;
- public int port;
+ private int port;
private String id;
private List<Command> commands = new ArrayList<Command>();
public Router() {
-
}
public Router(String id, String name, InetAddress address, Command...
commands) {
@@ -34,8 +42,8 @@
this.address = address;
this.port = port;
for (Command c : commands) {
+ addCommand(c);
c.setRouter(this);
- addCommand(c);
}
}
@@ -52,7 +60,8 @@
}
public void addCommand(Command command) {
- commands.add(command);
+ if (!commands.contains(command))
+ commands.add(command);
}
public List<Command> getCommands() {
@@ -90,11 +99,6 @@
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;
@@ -103,10 +107,9 @@
return true;
}
-// public RouterConnection connect() throws IOException {
-// //return connectionManager.connect(url, port);
-// return null;
-// }
+ public void connect() throws IOException {
+ throw new IOException("Not implemented yet.");
+ }
@Override
public String toString() {
@@ -114,18 +117,22 @@
+ ", commands=" + commands + "]";
}
+
@XPath(xpath="nmwg:message[@type='MetadataKeyResponse']/nmwg:metadata[nmwg:parameters]/nmwg:subject/text()")
public void setName(String name) {
this.name = name;
}
+
@XPath(xpath="nmwg:message[@type='MetadataKeyResponse']/nmwg:metadata/nmwg:parameters/nmwg:parameter[@name='url']/@value")
public void setAddress(String address) throws UnknownHostException {
this.address = InetAddress.getAllByName(address)[0];
}
+
@XPath(xpath="nmwg:message[@type='MetadataKeyResponse']/nmwg:metadata[nmwg:parameters]/@id")
public void setId(String id) {
this.id = id;
}
+ @Identifier
public String getId() {
return id;
}
Added:
trunk/perfsonar-base/sample-service/src/main/java/net/geant/perfsonar/mp/sshtelnet/RouterReference.java
===================================================================
---
trunk/perfsonar-base/sample-service/src/main/java/net/geant/perfsonar/mp/sshtelnet/RouterReference.java
(rev 0)
+++
trunk/perfsonar-base/sample-service/src/main/java/net/geant/perfsonar/mp/sshtelnet/RouterReference.java
2013-05-06 17:04:11 UTC (rev 6359)
@@ -0,0 +1,24 @@
+package net.geant.perfsonar.mp.sshtelnet;
+
+import net.geant.perfsonar.annotations.XPath;
+
+
+/**
+ * Used for injecting Router instances in Command objects.
+ *
+ * @author <a
href="mailto:">Blazej
Pietrzak</a>
+ *
+ */
+public class RouterReference {
+
+ private static Router currentRouter = null;
+
+
@XPath(xpath="nmwg:message[@type='MetadataKeyResponse']/nmwg:data/@metadataIdRef")
+ public void setCurrentRouter(Router router) {
+ RouterReference.currentRouter = router;
+ }
+
+ public static Router getCurrentRouter() {
+ return RouterReference.currentRouter;
+ }
+}
Modified:
trunk/perfsonar-base/sample-service/src/main/java/net/geant/perfsonar/mp/sshtelnet/SSHTelnetMPService.java
===================================================================
---
trunk/perfsonar-base/sample-service/src/main/java/net/geant/perfsonar/mp/sshtelnet/SSHTelnetMPService.java
2013-05-06 13:51:21 UTC (rev 6358)
+++
trunk/perfsonar-base/sample-service/src/main/java/net/geant/perfsonar/mp/sshtelnet/SSHTelnetMPService.java
2013-05-06 17:04:11 UTC (rev 6359)
@@ -5,13 +5,22 @@
import static
net.geant.perfsonar.ls.LSRegistrationTask.registerToLookupService;
import static net.geant.perfsonar.messaging.XPathDeserializer.any;
import static net.geant.perfsonar.messaging.XPathDeserializer.whenXPath;
+import static net.geant.perfsonar.selftest.SelfTestRunner.addSelfTest;
+import static net.geant.perfsonar.selftest.SelfTestRunner.configureForType;
+import static net.geant.perfsonar.selftest.SelfTestRunner.selfTestData;
+import java.util.Collections;
+import java.util.List;
+
import javax.xml.ws.WebServiceProvider;
import net.geant.perfsonar.PerfSONAR;
import net.geant.perfsonar.ServiceType;
import net.geant.perfsonar.ls.LSRegistrationTask;
+/**
+ * @author <a
href="mailto:">Blazej
Pietrzak</a>
+ */
@WebServiceProvider
public class SSHTelnetMPService extends PerfSONAR {
@@ -25,6 +34,8 @@
public SSHTelnetMPService() {
super();
+
+ configureService();
scheduler.runEvery(HOUR, lsRegistrationTask);
scheduler.runEvery(SECOND, new
ConfigurationFileChecker(this));
@@ -40,9 +51,9 @@
return "SSHTELNET";
}
- static {
+ private void configureService() {
try {
- if (!isUsingAPT()) {
+ if (!usingAPT) {
// if apt is not in classpath (maven dependencies)
one must
// provide configuration using API
configure(when("MetadataKeyRequest").then(
@@ -60,7 +71,7 @@
"nmwg:message/nmwg:metadata/nmwg:subject/nmwgtopo:endPoint/text()")
.then(Command.class).setRouterName(any(String.class));
-
whenXPath("nmwg:message/nmwg:metadata/nmwg:eventType/text()")
+
whenXPath("nmwg:message[@type='SetupDataRequest']/nmwg:metadata/nmwg:eventType/text()")
.then(Command.class).setEventType(any(String.class));
whenXPath(
@@ -74,10 +85,17 @@
whenXPath(
"nmwg:message/nmwg:metadata/nmwg:parameters/nmwg:parameter[@name='syntax']/@value")
.then(Command.class).setSyntax(any(String.class));
+
+ addSelfTest("connect to
${arg.getAddress().toString()}", "Connected to
${arg.getAddress().toString()}",
ServiceController.class).connect(any(Router.class));
+ configureForType(Router.class,
selfTestData(ServiceController.class).listAvailableRoutersAndCommands());
}
} catch (Exception ex) {
}
}
+
+ public boolean isAPT() {
+ return usingAPT;
+ }
/**
* Sets timeout in seconds between subsequent
registrations/keepalives to
@@ -96,4 +114,8 @@
public synchronized int getLookupServiceInterval() {
return lsInterval;
}
+
+ protected List<String> getLSAddresses() {
+ return
Collections.unmodifiableList(lsRegistrationTask.getLSAddresses());
+ }
}
Modified:
trunk/perfsonar-base/sample-service/src/main/java/net/geant/perfsonar/mp/sshtelnet/ServiceController.java
===================================================================
---
trunk/perfsonar-base/sample-service/src/main/java/net/geant/perfsonar/mp/sshtelnet/ServiceController.java
2013-05-06 13:51:21 UTC (rev 6358)
+++
trunk/perfsonar-base/sample-service/src/main/java/net/geant/perfsonar/mp/sshtelnet/ServiceController.java
2013-05-06 17:04:11 UTC (rev 6359)
@@ -9,10 +9,16 @@
import net.geant.perfsonar.annotations.LookupServiceRegister;
import net.geant.perfsonar.annotations.request.MetadataKey;
import net.geant.perfsonar.annotations.request.SetupData;
+import net.geant.perfsonar.annotations.selftest.SelfTest;
+import net.geant.perfsonar.annotations.selftest.SelfTestData;
+/**
+ * @author <a
href="mailto:">Blazej
Pietrzak</a>
+ */
public class ServiceController {
public ServiceController() { }
+ @SelfTestData
@MetadataKey
@LookupServiceRegister
public List<Router> listAvailableRoutersAndCommands() throws
UnknownHostException {
@@ -28,4 +34,9 @@
command.execute();
return command;
}
+
+ @SelfTest(name = "connect to ${arg.getAddress().toString()}",
successMessage = "Connected to ${arg.getAddress().toString()}")
+ public void connect(Router router) throws IOException {
+ router.connect();
+ }
}
Modified:
trunk/perfsonar-base/sample-service/src/main/resources/net/geant/perfsonar/mp/sshtelnet/MetadataKeyResponse.template
===================================================================
---
trunk/perfsonar-base/sample-service/src/main/resources/net/geant/perfsonar/mp/sshtelnet/MetadataKeyResponse.template
2013-05-06 13:51:21 UTC (rev 6358)
+++
trunk/perfsonar-base/sample-service/src/main/resources/net/geant/perfsonar/mp/sshtelnet/MetadataKeyResponse.template
2013-05-06 17:04:11 UTC (rev 6359)
@@ -25,11 +25,7 @@
<nmwg:parameters id="params${idx}">
<nmwg:parameter name="command" value="${command.name}" />
<nmwg:parameter name="description"
value="${command.description}" />
-#if (${command.syntax})
- <nmwg:parameter name="syntax" />
-#else
- <nmwg:parameter name="syntax" value="${command.syntax} />
-#end
+ <nmwg:parameter name="syntax" value="${command.syntax}" />
</nmwg:parameters>
<nmwg:eventType>${command.eventType}</nmwg:eventType>
</nmwgr:datum>
Deleted:
trunk/perfsonar-base/sample-service/src/test/java/net/geant/perfsonar/SSHTelnetMPWebServiceTest.java
===================================================================
---
trunk/perfsonar-base/sample-service/src/test/java/net/geant/perfsonar/SSHTelnetMPWebServiceTest.java
2013-05-06 13:51:21 UTC (rev 6358)
+++
trunk/perfsonar-base/sample-service/src/test/java/net/geant/perfsonar/SSHTelnetMPWebServiceTest.java
2013-05-06 17:04:11 UTC (rev 6359)
@@ -1,45 +0,0 @@
-package net.geant.perfsonar;
-
-import static org.junit.Assert.assertEquals;
-
-import java.io.IOException;
-
-import javax.xml.ws.Endpoint;
-
-import net.geant.perfsonar.helpers.PerfSONARServiceClient;
-import net.geant.perfsonar.helpers.Response;
-import net.geant.perfsonar.mp.sshtelnet.SSHTelnetMPService;
-import net.geant.perfsonar.templates.NMWG;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.xml.sax.SAXException;
-
-public class SSHTelnetMPWebServiceTest {
- private static final String REQUEST_ID = "request1";
- private static final String SERVICE_URL =
"http://localhost:9000/perfsonar-java-sshtelnet-mp";
-
- private SSHTelnetMPService service = new SSHTelnetMPService();
- private Endpoint endpoint;
-
- @Before
- public void givenSSHTelnetMPWebService() throws InterruptedException,
IOException {
- endpoint = Endpoint.publish(SERVICE_URL, service);
-
- }
-
- @After
- public void stopServices() {
- endpoint.stop();
- service.stop();
- endpoint = null;
- service = null;
- }
-
- @Test
- public void shouldSayEcho() throws SAXException, InterruptedException
{
- final PerfSONARServiceClient client = new
PerfSONARServiceClient(SERVICE_URL);
- assertEquals(new Response(NMWG.toEchoResponse(REQUEST_ID)),
client.echo(REQUEST_ID));
- }
-}
Added:
trunk/perfsonar-base/sample-service/src/test/java/net/geant/perfsonar/mp/sshtelnet/ConfigurationFileCheckerTest.java
===================================================================
---
trunk/perfsonar-base/sample-service/src/test/java/net/geant/perfsonar/mp/sshtelnet/ConfigurationFileCheckerTest.java
(rev 0)
+++
trunk/perfsonar-base/sample-service/src/test/java/net/geant/perfsonar/mp/sshtelnet/ConfigurationFileCheckerTest.java
2013-05-06 17:04:11 UTC (rev 6359)
@@ -0,0 +1,38 @@
+package net.geant.perfsonar.mp.sshtelnet;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class ConfigurationFileCheckerTest {
+
+ private SSHTelnetMPService service;
+
+ @Before
+ public void givenService() {
+ service = new SSHTelnetMPService();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ service.stop();
+ service = null;
+ }
+
+ @Test
+ public void shouldReadLookupServiceInterval() {
+ ConfigurationFileChecker config = new
ConfigurationFileChecker(service);
+
+ assertTrue(config.isModified());
+ assertTrue(config.configurationExists());
+
+ config.run();
+ assertEquals(2, service.getLookupServiceInterval());
+
+
+ }
+
+}
Modified:
trunk/perfsonar-base/sample-service/src/test/java/net/geant/perfsonar/mp/sshtelnet/LSRegisterTest.java
===================================================================
---
trunk/perfsonar-base/sample-service/src/test/java/net/geant/perfsonar/mp/sshtelnet/LSRegisterTest.java
2013-05-06 13:51:21 UTC (rev 6358)
+++
trunk/perfsonar-base/sample-service/src/test/java/net/geant/perfsonar/mp/sshtelnet/LSRegisterTest.java
2013-05-06 17:04:11 UTC (rev 6359)
@@ -17,5 +17,4 @@
protected int getLSInterval() {
return service.getLookupServiceInterval();
}
-
}
Modified:
trunk/perfsonar-base/sample-service/src/test/java/net/geant/perfsonar/mp/sshtelnet/SSHTelnetMPTest.java
===================================================================
---
trunk/perfsonar-base/sample-service/src/test/java/net/geant/perfsonar/mp/sshtelnet/SSHTelnetMPTest.java
2013-05-06 13:51:21 UTC (rev 6358)
+++
trunk/perfsonar-base/sample-service/src/test/java/net/geant/perfsonar/mp/sshtelnet/SSHTelnetMPTest.java
2013-05-06 17:04:11 UTC (rev 6359)
@@ -1,22 +1,33 @@
package net.geant.perfsonar.mp.sshtelnet;
-import static net.geant.perfsonar.templates.SelfTestResult.failure;
-import static net.geant.perfsonar.templates.SelfTestResult.success;
+import static net.geant.perfsonar.messaging.SelfTestResult.failure;
+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 static org.junit.Assert.fail;
import java.io.IOException;
import java.io.Reader;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
import net.geant.perfsonar.helpers.PerfSONARClient;
import net.geant.perfsonar.helpers.Response;
+import net.geant.perfsonar.messaging.XPathDeserializer;
import net.geant.perfsonar.templates.NMWG;
-import net.geant.perfsonar.templates.SelfTestResult;
+import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.xml.sax.SAXException;
+import org.xml.sax.InputSource;
public class SSHTelnetMPTest {
@@ -24,51 +35,149 @@
static final String REQUEST_ID = "request1";
private PerfSONARClient client;
- private final SSHTelnetMPService service = new SSHTelnetMPService();
+ private SSHTelnetMPService service;
@Before
public void givenPerfSONARClient() {
+ service = new SSHTelnetMPService();
client = new PerfSONARClient(service);
+ new RouterReference().setCurrentRouter(null);
}
-
+
+ @After
+ public void tearDown() {
+ client = null;
+ service.stop();
+ service = null;
+ }
+
@Test
public void checkEcho() throws Exception {
assertEquals(new Response(NMWG.toEchoResponse(REQUEST_ID)),
client.echo(REQUEST_ID));
}
@Test
- public void checkSelfTest() throws SAXException {
- assertEquals(
- new Response(NMWG.toSelfTestResponse(
- REQUEST_ID,
- new SelfTestResult[] {
-
success("test1", "Test passed.", "SSHTELNET", "MP"),
-
failure("test2", "Test failed.", "SSHTELNET", "MP"), })),
- client.selfTest(REQUEST_ID));
+ public void checkSelfTest() throws Exception {
+ assertEquals(Arrays.asList(
+ failure("connect to /10.10.14.4", "Not implemented
yet.", "SSHTELNET", "MP"),
+ failure("connect to /10.10.14.5", "Not implemented
yet.", "SSHTELNET", "MP")),
+ sort(client.selfTest(REQUEST_ID)));
}
+ private <T> List<T> sort(List<T> list) {
+ @SuppressWarnings("unchecked")
+ final T[] result = (T[]) list.toArray();
+ Arrays.sort(result);
+ return Arrays.asList(result);
+ }
+
@Test
- public void checkMetadataKey() throws SAXException, IOException {
- print(client.listAvailableCommands(REQUEST_ID).getReader());
+ public void checkMetadataKey() throws Exception {
+ configureResponseDeserialization();
+
+ final XPathDeserializer deserializer = new
XPathDeserializer();
+
+ @SuppressWarnings("unchecked")
+ final List<Object> actual = (List<Object>)
deserializer.deserialize(new
InputSource(client.listAvailableCommands(REQUEST_ID).getReader()));
+
+ assertEquals(Arrays.asList(Command.SHOW_ENVIRONMENT,
Command.PING, Command.SHOW_INTERFACES_FILTERS),
deserializer.getObjects(Command.class, actual));
+
+ assertEquals(Arrays.asList(
+ new Router("metadata0", "Cisco",
InetAddress.getAllByName("10.10.14.4")[0], Command.SHOW_ENVIRONMENT,
Command.PING),
+ new Router("metadata1", "JuniperGeantAmsterdam",
InetAddress.getByName("10.10.14.5"), Command.SHOW_INTERFACES_FILTERS)),
+
+ deserializer.getObjects(Router.class, actual));
}
+ private void configureResponseDeserialization() throws
InstantiationException,
+ IllegalAccessException, UnknownHostException {
+
+ if (service.isAPT())
+ return;
+
+ declarePrefix("nmwg", "http://ggf.org/ns/nmwg/base/2.0/");
+ declarePrefix("nmwgr", "http://ggf.org/ns/nmwg/result/2.0/");
+ declarePrefix("nmwgtopo",
"http://ggf.org/ns/nmwg/topology/2.0/");
+
+
whenXPath("nmwg:message[@type='MetadataKeyResponse']/nmwg:metadata[nmwg:parameters]/@id")
+ .then(Router.class).setId(any(String.class));
+
+ whenXPath(
+
"nmwg:message[@type='MetadataKeyResponse']/nmwg:metadata[nmwg:parameters]/nmwg:subject/text()")
+
.then(Router.class).setName(any(String.class));
+
+ whenXPath(
+
"nmwg:message[@type='MetadataKeyResponse']/nmwg:metadata/nmwg:parameters/nmwg:parameter[@name='url']/@value")
+
.then(Router.class).setAddress(any(String.class));
+
+ whenXPath(
+
"nmwg:message[@type='MetadataKeyResponse']/nmwg:data/@metadataIdRef")
+ .then(RouterReference.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));
+
+ whenXPath(
+
"nmwg:message[@type='MetadataKeyResponse']/nmwg:data/nmwgr:datum/nmwg:eventType/text()")
+
.then(Command.class).setEventType(any(String.class));
+
+ //SetupData
+
whenXPath("nmwg:message/nmwg:metadata/nmwg:parameters/nmwg:parameter[@name='command']/@value")
+
.then(Command.class).setName(any(String.class));
+
+
whenXPath("nmwg:message/nmwg:metadata/nmwg:parameters/nmwg:parameter[@name='description']/@value")
+
.then(Command.class).setDescription(any(String.class));
+
+
whenXPath("nmwg:message/nmwg:metadata/nmwg:parameters/nmwg:parameter[@name='syntax']/@value")
+
.then(Command.class).setSyntax(any(String.class));
+
+
whenXPath("nmwg:message[@type='SetupDataResponse']/nmwg:metadata[nmwg:subject/nmwgtopo:endPoint]/@id")
+ .then(Command.class).setId(any(String.class));
+
+ whenXPath(
+
"nmwg:message[@type='SetupDataResponse']/nmwg:metadata/nmwg:subject/nmwgtopo:endPoint/text()")
+
.then(Command.class).setRouterName(any(String.class));
+
+ whenXPath(
+
"nmwg:message[@type='SetupDataResponse']/nmwg:metadata[nmwg:subject/nmwgtopo:endPoint]/nmwg:eventType/text()")
+
.then(Command.class).setEventType(any(String.class));
+
+ whenXPath(
+
"nmwg:message/nmwg:data[starts-with(@metadataIdRef,
'meta')]/nmwg:datum/text()")
+
.then(Command.class).setResult(any(String.class));
+ }
+
@Test
public void checkSetupDataRequest() throws Exception {
- final Command command1 = (Command) Command.SHOW_ENVIRONMENT
- .newInstance();
- command1.setRouterName("host1");
- final Command command2 = (Command)
Command.PING_IPV6.newInstance();
- command2.setRouterName("host2");
- print(client.executeCommands(REQUEST_ID, command1, command2)
- .getReader());
+ final Command command1 = new
Command(Command.SHOW_ENVIRONMENT, "host1");
+ final Command command2 = new Command(Command.PING_IPV6,
"host2");
+
+ configureResponseDeserialization();
+ final XPathDeserializer deserializer = new
XPathDeserializer();
+
+ @SuppressWarnings("unchecked")
+ final List<Object> actual = (List<Object>)
deserializer.deserialize(new InputSource(client.executeCommands(REQUEST_ID,
command1, command2).getReader()));
+
+ command1.setResult("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---");
+ command2.setResult("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---");
+ resetUnneededFields(command1);
+ resetUnneededFields(command2);
+ assertEquals(Arrays.asList(command1, command2),
deserializer.getObjects(Command.class, actual));
}
- private void print(Reader reader) throws IOException {
- String printed = "";
- for (int i = reader.read(); i != -1; i = reader.read()) {
- printed += (char) i;
- }
-
- logger.debug(printed);
+ private void resetUnneededFields(Command cmd) {
+ cmd.setDescription(null);
+ cmd.setName(null);
+ cmd.setSyntax(null);
}
}
- [pS-dev] [GEANT/SA2/ps-java-services] r6359 - in trunk/perfsonar-base/sample-service: . src/main/java/net/geant/perfsonar/mp/sshtelnet src/main/resources/net/geant/perfsonar/mp/sshtelnet src/test/java/net/geant/perfsonar src/test/java/net/geant/perfsonar/mp/sshtelnet, svn-noreply, 05/06/2013
Archive powered by MHonArc 2.6.16.