perfsonar-dev - Re: [pS-dev] simple echo functionality in the base
Subject: perfsonar development work
List archive
- From: Roman Lapacz <>
- To: "" <>
- Subject: Re: [pS-dev] simple echo functionality in the base
- Date: Fri, 23 Feb 2007 15:21:31 +0100
Hi,
I've just changed eventType value in the echo request. Now the message of simple echo looks like this:
<nmwg:message type="EchoRequest"
id="id1"
xmlns:nmwg="http://ggf.org/ns/nmwg/base/2.0/">
<nmwg:metadata id="meta">
<nmwg:eventType>http://www.perfsonar.net/tools/admin/echo/2.0</nmwg:eventType>
</nmwg:metadata>
<nmwg:data id="data" metadataIdRef="meta"/>
</nmwg:message>
Roman
Roman Lapacz wrote:
This is what I promised to send yesterday during the confcall:
In order to have simple echo functionality in the service (which uses Java base) follow the steps:
1) update org.perfsonar.commons.messages.EchoRequest class from SVN (see below)
2) in service.properties file insert echo message handler EchoRequest into service.ma.message_types property, example for RRD MA:
service.ma.message_types=MetadataKeyRequest,SetupDataRequest,MeasurementArchiveStoreRequest,EchoRequest
3) compile and (re)deploy the service
... and now send simple echo request to the service (request is presented below)
Roman
-------- Original Message --------
Subject: [pS-dev] r2098 - in trunk/perfsonar/src/org/perfsonar: commons/messages service/measurementArchive/rrdType
Date: Wed, 21 Feb 2007 05:57:42 -0500
From:
Reply-To:
To:
Author: roman
Date: 2007-02-21 05:57:41 -0500 (Wed, 21 Feb 2007)
New Revision: 2098
Modified:
trunk/perfsonar/src/org/perfsonar/commons/messages/EchoRequest.java
trunk/perfsonar/src/org/perfsonar/service/measurementArchive/rrdType/RRDTypeMAServiceEngine.java
Log:
Handling simple echo request has been moved to the base (org.perfsonar.commons.messages.EchoRequest) so all services which will use EchoRequest class as a message handler will support this message type.
simple echo request:
<nmwg:message type="EchoRequest"
id="id1"
xmlns:nmwg="http://ggf.org/ns/nmwg/base/2.0/">
<nmwg:metadata id="meta">
<nmwg:eventType>echo</nmwg:eventType>
</nmwg:metadata>
<nmwg:data id="data" metadataIdRef="meta"/>
</nmwg:message>
If the service has to support more advanced types of echo request (different eventType) then the implementation of it should be put in the ServiceEngine (use of ActionType checking; see takeAction method in ServiceEngine).
Modified: trunk/perfsonar/src/org/perfsonar/commons/messages/EchoRequest.java
===================================================================
--- trunk/perfsonar/src/org/perfsonar/commons/messages/EchoRequest.java 2007-02-21 10:40:09 UTC (rev 2097)
+++ trunk/perfsonar/src/org/perfsonar/commons/messages/EchoRequest.java 2007-02-21 10:57:41 UTC (rev 2098)
@@ -6,11 +6,20 @@
package org.perfsonar.commons.messages;
+import org.perfsonar.service.commons.exceptions.PerfSONARException;
+import org.perfsonar.service.commons.exceptions.DataFormatException;
+import org.perfsonar.service.commons.exceptions.RequestException;
import org.perfsonar.service.commons.exceptions.SystemException;
+import org.perfsonar.service.commons.exceptions.ResourceException;
import org.perfsonar.service.commons.engine.ActionType;
+import org.perfsonar.service.commons.util.ResultCodesUtil;
+import org.ggf.ns.nmwg.base.v2_0.Message;
import org.ggf.ns.nmwg.base.v2_0.Metadata;
+import org.ggf.ns.nmwg.base.v2_0.Data;
+import org.ggf.ns.nmwg.base.v2_0.EventType;
+import java.util.ArrayList;
import java.util.Map;
@@ -48,6 +57,116 @@
}
+ public Message execute(Message reqMessage) {
+ ArrayList<Message> output = new ArrayList<Message>();
+ for (Message inputMessage: extractMultipleRequests(reqMessage)) {
+
+ try {
+
+ output.add(
+ executeEcho(inputMessage));
+
+ } catch (PerfSONARException e) {
+
+ output.add(
+ ResultCodesUtil.createResultCodeMetadata(
+ null, e));
+
+ } +
+ }
+
+ //do one message from all result messages + Message respMessage = mergeMultipleResponses(output);
+
+ //if no metadata inside, print error
+ if (respMessage.getMetadataMap().values().size() == 0) {
+ ResultCodesUtil.createResultCodeMetadata(
+ respMessage, + new PerfSONARException(
+ "warning.common.no_metadata",
+ "No output metadata was returned by MessageHandler."+
+ " Maybe there was no data trigger, or data trigger "+
+ " didn't have valid metadataIdRef? ")
+ );
+
+ }
+
+ respMessage.setId(reqMessage.getId() + "_resp");
+ respMessage.setType(reqMessage.getType().replaceFirst("Request", "Response"));
+ respMessage.setMessageIdRef(reqMessage.getId());
+
+ return respMessage;
+
+ }
+
+
+ protected Message executeEcho(Message request)
+ throws SystemException, RequestException, DataFormatException, ResourceException {
+
+ Data data = request.getDataArray()[0];
+ Metadata metadata = request.getMetadata(data.getMetadataIdRef());
+
+ EventType eventType = metadata.getEventType();
+ if (eventType == null) {
+ logger.debug("EchoRequest.executeEcho: The request does not contain "
+ + "eventType element");
+ throw new SystemException(
+ "error.request",
+ "EchoRequest.executeEcho: The request does not contain "
+ + "eventType element");
+ }
+
+ Message response = null;
+ + if (eventType.getEventType().equals("echo")) {
+ response = executeSimpleEcho();
+ } else if (eventType.getEventType().equals("echo")){
+ response = getEmptyEventTypeResponse();
+ } else {
+ response = serviceEngine.takeAction(getType(), request);
+ }
+
+ return response;
+
+ }
+
+
+ protected Message executeSimpleEcho() {
+
+ logger.debug("EchoRequest: executeSimpleEcho()");
+
+ Message response = new Message();
+
+ PerfSONARException pex =
+ new PerfSONARException(
+ "success.echo",
+ "This is the echo response from the service.");
+
+ ResultCodesUtil.createResultCodeMetadata(response, pex);
+
+ return response;
+
+ }
+
+
+ protected Message getEmptyEventTypeResponse() {
+
+ Message response = new Message();
+
+ PerfSONARException pex =
+ new PerfSONARException(
+ "error.echo",
+ "EventType is empty.");
+
+ ResultCodesUtil.createResultCodeMetadata(response, pex);
+
+ return response;
+
+ }
+
+
+
} //EchoRequest
Modified: trunk/perfsonar/src/org/perfsonar/service/measurementArchive/rrdType/RRDTypeMAServiceEngine.java
===================================================================
--- trunk/perfsonar/src/org/perfsonar/service/measurementArchive/rrdType/RRDTypeMAServiceEngine.java 2007-02-21 10:40:09 UTC (rev 2097)
+++ trunk/perfsonar/src/org/perfsonar/service/measurementArchive/rrdType/RRDTypeMAServiceEngine.java 2007-02-21 10:57:41 UTC (rev 2098)
@@ -820,18 +820,19 @@
}
- protected Message getEcho(Message request)
- throws SystemException, RequestException, DataFormatException {
+ protected Message getEcho(Message request) {
Message response = new Message();
PerfSONARException pex =
new PerfSONARException(
- "success.echo",
- "This is the echo response from the service.");
+ "error.request",
+ "This eventType in echo request is not supported");
+ // this method will be used for advanced types of echo request
+
ResultCodesUtil.createResultCodeMetadata(response, pex);
- +
return response;
}
- simple echo functionality in the base, Roman Lapacz, 02/23/2007
- Re: [pS-dev] simple echo functionality in the base, Roman Lapacz, 02/23/2007
- Re: [pS-dev] simple echo functionality in the base, Loukik Kudarimoti, 02/23/2007
- Re: [pS-dev] simple echo functionality in the base, Roman Lapacz, 02/23/2007
- Re: [pS-dev] simple echo functionality in the base, Loukik Kudarimoti, 02/23/2007
- Re: [pS-dev] simple echo functionality in the base, Roman Lapacz, 02/23/2007
Archive powered by MHonArc 2.6.16.