Skip to Content.
Sympa Menu

perfsonar-dev - perfsonar: r4209 - trunk/geant2_java-xml-ls/src/main/java/org/perfsonar/service/lookupService/xmlType

Subject: perfsonar development work

List archive

perfsonar: r4209 - trunk/geant2_java-xml-ls/src/main/java/org/perfsonar/service/lookupService/xmlType


Chronological Thread 
  • From:
  • To:
  • Subject: perfsonar: r4209 - trunk/geant2_java-xml-ls/src/main/java/org/perfsonar/service/lookupService/xmlType
  • Date: Wed, 16 Jul 2008 08:07:32 -0400

Author: mac
Date: 2008-07-16 08:07:32 -0400 (Wed, 16 Jul 2008)
New Revision: 4209

Modified:

trunk/geant2_java-xml-ls/src/main/java/org/perfsonar/service/lookupService/xmlType/EchoRequestAction.java
Log:
self test

Modified:
trunk/geant2_java-xml-ls/src/main/java/org/perfsonar/service/lookupService/xmlType/EchoRequestAction.java
===================================================================
---
trunk/geant2_java-xml-ls/src/main/java/org/perfsonar/service/lookupService/xmlType/EchoRequestAction.java
2008-07-16 12:01:01 UTC (rev 4208)
+++
trunk/geant2_java-xml-ls/src/main/java/org/perfsonar/service/lookupService/xmlType/EchoRequestAction.java
2008-07-16 12:07:32 UTC (rev 4209)
@@ -1,10 +1,11 @@
package org.perfsonar.service.lookupService.xmlType;

+import org.ggf.ns.nmwg.base.v2_0.Data;
+import org.ggf.ns.nmwg.base.v2_0.Datum;
+import org.ggf.ns.nmwg.base.v2_0.EventType;
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.Parameter;
import org.perfsonar.base.exceptions.PerfSONARException;
-import org.perfsonar.service.base.util.ResultCodesUtil;
import org.perfsonar.service.lookupService.xmlType.storage.LookupServiceDAO;

/**
@@ -15,8 +16,29 @@
*/
public class EchoRequestAction extends LSAction {

- public final static String
SUPPORTED_EVENT_TYPE="http://schemas.perfsonar.net/tools/admin/echo/ls/2.0";;
+ public final static String[] SUPPORTED_EVENT_TYPES= {
+ "http://schemas.perfsonar.net/tools/admin/echo/ls/2.0";,
+ "http://schemas.perfsonar.net/tools/admin/selftest/1.0";
+ };

+ private boolean isEventTypeSupported(String evt) {
+ boolean i = false;
+ for (String s : SUPPORTED_EVENT_TYPES) {
+ if (s.equals(evt)) { i = true; break; }
+ }
+ return i;
+ }
+
+ private String getEventTypesString() {
+ StringBuffer sb = new StringBuffer();
+ for (int i=0; i<SUPPORTED_EVENT_TYPES.length; i++) {
+ if (i>0) sb.append(" | ");
+ sb.append(SUPPORTED_EVENT_TYPES[i]);
+ }
+ return sb.toString();
+ }
+
+
public EchoRequestAction(LookupServiceDAO dao) throws PerfSONARException
{
super(dao);
}
@@ -31,121 +53,143 @@
try {
//check eventtype
String eventType = metadata.getEventType().getEventType();
- if (!(eventType.equals(SUPPORTED_EVENT_TYPE)))
+
+ if (!(isEventTypeSupported(eventType)))
throw new
PerfSONARException("error.ls.eventtype_not_supported",
"LS EchoRequest error: " +
"Not supported event type ["+eventType+"]. " +
- "Must be: ["+SUPPORTED_EVENT_TYPE+"]");
+ "Must be: ["+getEventTypesString()+"]");

} catch (RuntimeException ex) {
throw new PerfSONARException("error.ls.no_eventtype",
"LS EchoRequest error: " +
"Error while determining eventType (possibly no
eventType at all). " +
- "EventType must be ["+SUPPORTED_EVENT_TYPE+"]. " +
+ "EventType must be ["+getEventTypesString()+"]. " +
"Nested exception is : "+ex.getMessage());
}

- String message = ""; //additional message
+
+ Message msg = new Message();
+ msg.setId("EchoResponse");
+
+ Metadata meta = new Metadata();
+ meta.setId("result-code-metadata");
+
+ EventType evt = new EventType();
+
evt.setEventType("http://schemas.perfsonar.net/tools/admin/selftest/1.0";);
+ meta.setEventType(evt);

- //test parameters (if present in //metadata/parameters/parameter)
+ msg.setMetadata(meta);

- //parameter testDBConnection
- boolean testDbConnection=getBooleanParameter(metadata,
"testDBConnection");
+ Data data = new Data();
+ data.setId("result-code-data");
+ data.setMetadataIdRef("result-code-metadata");
+ msg.setData(data);

- if (testDbConnection) {
- try {
- dao.isDBConnectivity(); //returns true if so, or exception
- message = message+"Test DB Connection - OK\n";
- } catch (PerfSONARException ex) {
- throw new PerfSONARException(
- ex.getResultCode(),
- "LS EchoRequest (Test DB Connection) error: " +
- "Database connection to the LookupService is not
established. " +
- "Nested exception is : "+ex.getResultDescription());
- }
+ boolean test;
+ String s;
+
+ //test db connectivity
+
+ test = false;
+ s = "";
+ try {
+ test = dao.isDBConnectivity(); //returns true if so, or exception
+ } catch (Exception ex) {
+ test = false;
+ s = ex.getMessage();
}
+ if (test)
+ addResultCode(
+ data,
+ "exist-db-connectivity",
+ "success.ls.selftest.dbconnectivity",
+ "eXist DB connection established");
+ else
+ addResultCode(
+ data,
+ "exist-db-connectivity",
+ "error.ls.selftest.dbconnectivity",
+ "eXist DB connection not working: "+s);

- //parameter testDBSchema
- boolean testDbSchema=getBooleanParameter(metadata, "testDBSchema");;
+ //test db collection LSStore
+
+ test = false;
+ s = "";
+ try {
+ test =
dao.isDBCollection(LookupServiceDAO.LS_STORE_COLLECTION_TYPE); //returns true
if so, or exception
+ } catch (Exception ex) {
+ test = false;
+ s = ex.getMessage();
+ }
+ if (test)
+ addResultCode(
+ data,
+ "exist-db-collection-store",
+ "success.ls.selftest.collection.lsstore",
+ "collection LSStore exists and is accessible");
+ else
+ addResultCode(
+ data,
+ "exist-db-collection-store",
+ "error.ls.selftest.collection.lsstore",
+ "collection LSStore does not exist or is not accessible:
"+s);

- if (testDbSchema) {
-
- boolean isSchemaStore = false;
- boolean isSchemaControl = false;
-
- try {
- isSchemaStore =
-
dao.isDBCollection(LookupServiceDAO.LS_STORE_COLLECTION_TYPE);
-
- isSchemaControl =
-
dao.isDBCollection(LookupServiceDAO.LS_STORE_CONTROL_COLLECTION_TYPE);
-
- } catch (PerfSONARException ex) {
- throw new PerfSONARException(
- ex.getResultCode(),
- "LS EchoRequest (Test DB Schema) error: " +
- "Database connection to the LookupService is not
established or" +
- " storage is not set properly. " +
- "Nested exception is : "+ex.getResultDescription());
- }
-
- if (isSchemaStore)
- message = message+"Test DB Schema: [LSStore] - OK\n";
- else throw new PerfSONARException(
- "error.echo.no_storage_content",
- "EchoRequest error: No [LSStore] schema");
-
- if (isSchemaControl)
- message = message+"Test DB Schema: [LSStore-control] - OK\n";
- else throw new PerfSONARException(
- "error.echo.no_storage_content",
- "EchoRequest error: No [LSStore-control] schema");

+ //test db collection LSStore-control
+ test = false;
+ s = "";
+ try {
+ test =
dao.isDBCollection(LookupServiceDAO.LS_STORE_CONTROL_COLLECTION_TYPE);
//returns true if so, or exception
+ } catch (Exception ex) {
+ test = false;
+ s = ex.getMessage();
}
+ if (test)
+ addResultCode(
+ data,
+ "exist-db-collection-store-control",
+ "success.ls.selftest.collection.lsstore-control",
+ "collection LSStore exists and is accessible");
+ else
+ addResultCode(
+ data,
+ "exist-db-collection-store-control",
+ "error.ls.selftest.collection.lsstore-control",
+ "collection LSStore-control does not exist or is not
accessible: "+s);

- return getEcho(request, message); //get success.echo result code
with additional message
+ return msg;
}


- /**
- * Creates success.echo with additional message
- */
- protected Message getEcho(Message request, String message)
- throws PerfSONARException {
+ private void addResultCode(Data incomingData, String name, String code,
String desc) {

- Message response = new Message();
+// <!-- metadata/data block for result of first test -->

- logger.debug("EchoRequestAction: Sending success.echo");
- PerfSONARException pex =
- new PerfSONARException(
- "success.echo",
- "LS EchoRequest - This is the successful echo response
from the Lookup Service."+
- ((!("".equals(message)))?
- " Additional message is:\n"+message
- :
- "")
- );
-
- ResultCodesUtil.createResultCodeMetadata(response, pex);
+// <nmwg:metadata id="bwctl_command_test">
+//
<nmwg:eventType>http://schemas.perfsonar.net/tools/admin/selftest/MP/BWCTL/bwctl_command_test/success/1.0</nmwg:eventType>
+// </nmwg:metadata>

- return response;
-
- }
-
+// <nmwg:data id="data_bwctl_command_test"
metadataIdRef="bwctl_command_test">
+// <nmwg:datum>BWCTL tool /usr/local/bin/bwctl found </nmwg:datum>
+// </nmwg:data>
+
+
+ Metadata meta = new Metadata();
+ meta.setId(name);

- /**
- * Gets boolean parameter from metadata/parameters/parameter
- */
- private boolean getBooleanParameter(Metadata metadata, String paramName)
{
- try {
- Parameter param = metadata.getParameterByName(paramName);
- String paramstr=param.getParameterValue();
- boolean value=testIfTrue(paramstr);
- logger.debug("EchoRequestAction: parameter ["+paramName+"] is
["+value+"]");
- return value;
- } catch (RuntimeException ex) {
- return false;
- }
+ EventType evt = new EventType();
+ evt.setEventType(code);
+ meta.setEventType(evt);
+ incomingData.setMetadata(meta);
+
+ Data data = new Data();
+ data.setId(name+"-data");
+ data.setMetadataIdRef(name);
+ Datum d = new Datum();
+ d.setValue(desc);
+ data.addChild(d);
+
+ incomingData.addChild(data);
}
-
-
+
} //EchoRequestAction



  • perfsonar: r4209 - trunk/geant2_java-xml-ls/src/main/java/org/perfsonar/service/lookupService/xmlType, svnlog, 07/16/2008

Archive powered by MHonArc 2.6.16.

Top of Page