Skip to Content.
Sympa Menu

perfsonar-dev - [pS-dev] [GEANT/SA2/ps-java-services] r6434 - in trunk: perfsonar-java-base2/src/main/java/org/perfson ar/base2/service/configuration perfsonar-java-base2/src/ma in/java/org/perfsonar/base2/service/registration perfsonar -java-base2/src/main/java/org/perfsonar/base2/service/sche duler perfsonar-java-base2/src/main/java/org/perfsonar/bas e2/xml perfsonar-java-base2/src/main/java/org/perfsonar/ba se2/xml/nmwg perfsonar-java-rrd-ma/src/main/java/org/perfs onar/service/measurementArchive/rrdType perfsonar-java-rrd -ma/src/main/resources/perfsonar/conf perfsonar-java-rrd-m a/src/test/resources/perfsonar/conf

Subject: perfsonar development work

List archive

[pS-dev] [GEANT/SA2/ps-java-services] r6434 - in trunk: perfsonar-java-base2/src/main/java/org/perfson ar/base2/service/configuration perfsonar-java-base2/src/ma in/java/org/perfsonar/base2/service/registration perfsonar -java-base2/src/main/java/org/perfsonar/base2/service/sche duler perfsonar-java-base2/src/main/java/org/perfsonar/bas e2/xml perfsonar-java-base2/src/main/java/org/perfsonar/ba se2/xml/nmwg perfsonar-java-rrd-ma/src/main/java/org/perfs onar/service/measurementArchive/rrdType perfsonar-java-rrd -ma/src/main/resources/perfsonar/conf perfsonar-java-rrd-m a/src/test/resources/perfsonar/conf


Chronological Thread 
  • From:
  • To:
  • Subject: [pS-dev] [GEANT/SA2/ps-java-services] r6434 - in trunk: perfsonar-java-base2/src/main/java/org/perfson ar/base2/service/configuration perfsonar-java-base2/src/ma in/java/org/perfsonar/base2/service/registration perfsonar -java-base2/src/main/java/org/perfsonar/base2/service/sche duler perfsonar-java-base2/src/main/java/org/perfsonar/bas e2/xml perfsonar-java-base2/src/main/java/org/perfsonar/ba se2/xml/nmwg perfsonar-java-rrd-ma/src/main/java/org/perfs onar/service/measurementArchive/rrdType perfsonar-java-rrd -ma/src/main/resources/perfsonar/conf perfsonar-java-rrd-m a/src/test/resources/perfsonar/conf
  • Date: Tue, 4 Jun 2013 20:55:42 +0100 (BST)
  • Authentication-results: sfpop-ironport01.merit.edu; dkim=neutral (message not signed) header.i=none

Author: dante.delvaux
Date: 2013-06-04 20:55:42 +0100 (Tue, 04 Jun 2013)
New Revision: 6434

Added:

trunk/perfsonar-java-base2/src/main/java/org/perfsonar/base2/service/configuration/ASchedulingComponent.java

trunk/perfsonar-java-rrd-ma/src/main/java/org/perfsonar/service/measurementArchive/rrdType/RRDMAEchoServiceEngine.java
Removed:

trunk/perfsonar-java-base2/src/main/java/org/perfsonar/base2/service/configuration/SchedulingComponent.java

trunk/perfsonar-java-rrd-ma/src/main/java/org/perfsonar/service/measurementArchive/rrdType/EchoServiceEngine.java
Modified:

trunk/perfsonar-java-base2/src/main/java/org/perfsonar/base2/service/configuration/Configuration.java

trunk/perfsonar-java-base2/src/main/java/org/perfsonar/base2/service/registration/LSRegistrationAction.java

trunk/perfsonar-java-base2/src/main/java/org/perfsonar/base2/service/scheduler/SchedulingComponent.java

trunk/perfsonar-java-base2/src/main/java/org/perfsonar/base2/xml/Element.java

trunk/perfsonar-java-base2/src/main/java/org/perfsonar/base2/xml/nmwg/Metadata.java

trunk/perfsonar-java-rrd-ma/src/main/resources/perfsonar/conf/configuration.xml

trunk/perfsonar-java-rrd-ma/src/main/resources/perfsonar/conf/configuration.xml.template

trunk/perfsonar-java-rrd-ma/src/test/resources/perfsonar/conf/configuration.xml
Log:
RRD MA + pSbase2: Correcting some high priority PMD and FindBugs notices.

Copied:
trunk/perfsonar-java-base2/src/main/java/org/perfsonar/base2/service/configuration/ASchedulingComponent.java
(from rev 6428,
trunk/perfsonar-java-base2/src/main/java/org/perfsonar/base2/service/configuration/SchedulingComponent.java)
===================================================================
---
trunk/perfsonar-java-base2/src/main/java/org/perfsonar/base2/service/configuration/ASchedulingComponent.java
(rev 0)
+++
trunk/perfsonar-java-base2/src/main/java/org/perfsonar/base2/service/configuration/ASchedulingComponent.java
2013-06-04 19:55:42 UTC (rev 6434)
@@ -0,0 +1,33 @@
+package org.perfsonar.base2.service.configuration;
+
+import org.perfsonar.base2.service.exceptions.PerfSONARException;
+
+public abstract class ASchedulingComponent extends Component {
+
+ // ----------------------------------------------------------- Variables
+
+ private Actions actions = new Actions();
+
+ // -----------------------------------------------------------
Constructor
+
+ public ASchedulingComponent() {
+ super();
+ }
+
+ // ----------------------------------------------------------- Methods
+
+ public abstract void init() throws PerfSONARException;
+
+ public abstract void destroy() throws PerfSONARException;
+
+ public void addActions(Actions actions) {
+
+ this.actions = actions;
+
+ }
+
+ public Actions getActions() {
+ return actions;
+ }
+
+} // ASchedulingComponent

Modified:
trunk/perfsonar-java-base2/src/main/java/org/perfsonar/base2/service/configuration/Configuration.java
===================================================================
---
trunk/perfsonar-java-base2/src/main/java/org/perfsonar/base2/service/configuration/Configuration.java
2013-06-04 18:58:51 UTC (rev 6433)
+++
trunk/perfsonar-java-base2/src/main/java/org/perfsonar/base2/service/configuration/Configuration.java
2013-06-04 19:55:42 UTC (rev 6434)
@@ -7,6 +7,7 @@
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
+import java.util.NoSuchElementException;

import org.perfsonar.base2.service.exceptions.PerfSONARException;

@@ -58,9 +59,11 @@
}

if (s == null) {
- for (String sname : services.keySet()) {
- s = getService(sname);
- break;
+ // Otherwise, get first Service
+ try {
+ s = services.values().iterator().next();
+ } catch (NoSuchElementException ex) {
+ s = null;
}
}


Deleted:
trunk/perfsonar-java-base2/src/main/java/org/perfsonar/base2/service/configuration/SchedulingComponent.java
===================================================================
---
trunk/perfsonar-java-base2/src/main/java/org/perfsonar/base2/service/configuration/SchedulingComponent.java
2013-06-04 18:58:51 UTC (rev 6433)
+++
trunk/perfsonar-java-base2/src/main/java/org/perfsonar/base2/service/configuration/SchedulingComponent.java
2013-06-04 19:55:42 UTC (rev 6434)
@@ -1,37 +0,0 @@
-/**
- * $Id: SchedulingComponent.java 4698 2008-11-20 13:26:25Z roman $
- * Project: perfSONAR
- */
-package org.perfsonar.base2.service.configuration;
-
-import org.perfsonar.base2.service.exceptions.PerfSONARException;
-
-public abstract class SchedulingComponent extends Component {
-
- // ----------------------------------------------------------- Variables
-
- private Actions actions = new Actions();
-
- // -----------------------------------------------------------
Constructor
-
- public SchedulingComponent() {
- super();
- }
-
- // ----------------------------------------------------------- Methods
-
- public abstract void init() throws PerfSONARException;
-
- public abstract void destroy() throws PerfSONARException;
-
- public void addActions(Actions actions) {
-
- this.actions = actions;
-
- }
-
- public Actions getActions() {
- return actions;
- }
-
-} // SchedulingComponent

Modified:
trunk/perfsonar-java-base2/src/main/java/org/perfsonar/base2/service/registration/LSRegistrationAction.java
===================================================================
---
trunk/perfsonar-java-base2/src/main/java/org/perfsonar/base2/service/registration/LSRegistrationAction.java
2013-06-04 18:58:51 UTC (rev 6433)
+++
trunk/perfsonar-java-base2/src/main/java/org/perfsonar/base2/service/registration/LSRegistrationAction.java
2013-06-04 19:55:42 UTC (rev 6434)
@@ -5,8 +5,6 @@
import java.util.LinkedList;
import java.util.List;

-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.perfsonar.base2.service.exceptions.PerfSONARException;
import org.perfsonar.base2.service.requesthandler.ServiceMessage;
import org.perfsonar.base2.xml.Element;
@@ -21,8 +19,6 @@
*/
public class LSRegistrationAction extends AbstractRegistrationAction {

- protected Logger logger = LoggerFactory.getLogger(getClass());
-
private boolean keepAliveEnabled = false;

private LinkedList<URL> lsAddresses;

Modified:
trunk/perfsonar-java-base2/src/main/java/org/perfsonar/base2/service/scheduler/SchedulingComponent.java
===================================================================
---
trunk/perfsonar-java-base2/src/main/java/org/perfsonar/base2/service/scheduler/SchedulingComponent.java
2013-06-04 18:58:51 UTC (rev 6433)
+++
trunk/perfsonar-java-base2/src/main/java/org/perfsonar/base2/service/scheduler/SchedulingComponent.java
2013-06-04 19:55:42 UTC (rev 6434)
@@ -2,6 +2,7 @@

import java.util.Collection;

+import org.perfsonar.base2.service.configuration.ASchedulingComponent;
import org.perfsonar.base2.service.configuration.Action;
import org.perfsonar.base2.service.exceptions.PerfSONARException;

@@ -12,7 +13,7 @@
* @author Maciej Glowiak
* @author Roman Lapacz
*/
-public class SchedulingComponent extends
org.perfsonar.base2.service.configuration.SchedulingComponent {
+public class SchedulingComponent extends ASchedulingComponent {

// ----------------------------------------------------------- Variables


Modified:
trunk/perfsonar-java-base2/src/main/java/org/perfsonar/base2/xml/Element.java
===================================================================
---
trunk/perfsonar-java-base2/src/main/java/org/perfsonar/base2/xml/Element.java
2013-06-04 18:58:51 UTC (rev 6433)
+++
trunk/perfsonar-java-base2/src/main/java/org/perfsonar/base2/xml/Element.java
2013-06-04 19:55:42 UTC (rev 6434)
@@ -4,6 +4,7 @@
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
+import java.util.NoSuchElementException;

import javax.xml.namespace.NamespaceContext;

@@ -327,10 +328,11 @@
if (myChildren == null) {
return null;
}
- for (Element ch : myChildren) {
- return ch;
+ try {
+ return myChildren.iterator().next();
+ } catch (NoSuchElementException ex) {
+ return null;
}
- return null;
}

/**

Modified:
trunk/perfsonar-java-base2/src/main/java/org/perfsonar/base2/xml/nmwg/Metadata.java
===================================================================
---
trunk/perfsonar-java-base2/src/main/java/org/perfsonar/base2/xml/nmwg/Metadata.java
2013-06-04 18:58:51 UTC (rev 6433)
+++
trunk/perfsonar-java-base2/src/main/java/org/perfsonar/base2/xml/nmwg/Metadata.java
2013-06-04 19:55:42 UTC (rev 6434)
@@ -46,9 +46,7 @@

public EventType getFirstEventType() {
if (eventTypes != null && !eventTypes.isEmpty()) {
- for (EventType e : eventTypes) {
- return e;
- }
+ return eventTypes.get(0);
}
return null;
}

Deleted:
trunk/perfsonar-java-rrd-ma/src/main/java/org/perfsonar/service/measurementArchive/rrdType/EchoServiceEngine.java
===================================================================
---
trunk/perfsonar-java-rrd-ma/src/main/java/org/perfsonar/service/measurementArchive/rrdType/EchoServiceEngine.java
2013-06-04 18:58:51 UTC (rev 6433)
+++
trunk/perfsonar-java-rrd-ma/src/main/java/org/perfsonar/service/measurementArchive/rrdType/EchoServiceEngine.java
2013-06-04 19:55:42 UTC (rev 6434)
@@ -1,262 +0,0 @@
-package org.perfsonar.service.measurementArchive.rrdType;
-
-import org.perfsonar.base2.service.exceptions.PerfSONARException;
-import org.perfsonar.base2.service.requesthandler.ServiceMessage;
-import org.perfsonar.base2.service.configuration.ConfigurationManager;
-import org.perfsonar.base2.service.configuration.Configuration;
-import org.perfsonar.base2.service.util.ResultCodesUtil;
-
-import org.perfsonar.base2.xml.nmwg.Message;
-import org.perfsonar.base2.xml.nmwg.Metadata;
-import org.perfsonar.base2.xml.nmwg.Data;
-import org.perfsonar.base2.xml.nmwg.Key;
-import org.perfsonar.base2.xml.nmwg.EventType;
-import org.perfsonar.base2.xml.Element;
-
-import
org.perfsonar.service.measurementArchive.rrdType.storage.MetadataStorageDAO;
-import
org.perfsonar.service.measurementArchive.rrdType.storage.MetadataStorageDAOFactory;
-
-import
org.perfsonar.service.measurementArchive.rrdType.storage.DataStorageDAO;
-import
org.perfsonar.service.measurementArchive.rrdType.storage.DataStorageDAOFactory;
-
-import java.util.ArrayList;
-
-public class EchoServiceEngine extends
org.perfsonar.base2.service.requesthandler.EchoServiceEngine
-{
- // ------------------------------------------------------------- class
fields
-
-
- // TODO: Should eventTypes for success be full URL or only the last bit
(like in the echo success from pSbase2)
- public static final String ECHO_METADATA_TEST =
- "http://schemas.perfsonar.net/tools/admin/selftest/1"; +
".0/metadata-test";
- public static final String ECHO_RRD_FETCH_TEST =
- "http://schemas.perfsonar.net/tools/admin/selftest/1"; +
".0/rrd-fetch-test";
-
- protected static final String SERVICE_TYPE_OPTION_NAME = "serviceType";
- protected static final String SERVICE_NAME_OPTION_NAME = "serviceName";
-
- protected String serviceType = "";
- protected String serviceName = "";
-
- protected static final String METADATA_TEST_SUCCESS_RESULT_CODE_RESPONSE
=
- "Fetching metadata from DB is " + "correct.";
- protected static final String
RRD_FETCH_TEST_SUCCESS_RESULT_CODE_RESPONSE =
- "Fetching data from RRD file is " + "correct.";
-
-
- // ------------------------------------------------------------- methods
-
- public void takeAction(ServiceMessage serviceRequest, ServiceMessage
serviceResponse) throws PerfSONARException {
- logger.info("Simple Echo Service Engine started.");
-
- Message response = null;
-
- Configuration configuration =
ConfigurationManager.getInstance().getConfiguration();
- serviceType =
configuration.getLookupInformationOption(SERVICE_TYPE_OPTION_NAME);
- serviceName =
configuration.getLookupInformationOption(SERVICE_NAME_OPTION_NAME);
-
- Message request = serviceRequest.getMessageElement();
- String eventType = getEventType(request);
- if (eventType.equals(ECHO_EVENT_TYPE)) {
- response = simpleEchoAction();
- } else if (eventType.equals(ECHO_SELF_TEST + "/1.0")) {
- response = selfTestAction();
- } else if (eventType.equals(ECHO_METADATA_TEST)) {
- response = metadataTestAction(request, "metadata-test");
- } else if (eventType.equals(ECHO_RRD_FETCH_TEST)) {
- response = rrdFetchTestAction(request, "rrd-fetch-test");
- } else {
- errorCode();
- }
-
- response.setId("Resp_" + request.getAttribute("id"));
- response.addAttribute("type", "EchoResponse");
-
- serviceResponse.setElement(response);
- }
-
- protected Message simpleEchoAction() throws PerfSONARException {
- logger.debug("Echo request received.");
- return
ResultCodesUtil.generateResultMessage(ECHO_SUCCESS_RESULT_CODE,
ECHO_SUCCESS_RESULT_CODE_DSC);
- }
-
- /**
- * An RRD MA self test consist of the following:
- * - check service is installed properly and is working (this also test
the configuration file can be read)
- * - response to a EchoRequest
- * - check the SQL DB can be accessed
- * - response to a generic MetadataKeyRequest (random/generic metadata
fetch)
- * - check an RRD file can be read
- * - response to a generic SetupDataRequest (random/generic fetch)
- * @return
- * @throws PerfSONARException
- */
- protected Message selfTestAction() throws PerfSONARException {
- Message[] testResponses = new Message[3];
- testResponses[0] = simpleEchoAction();
- testResponses[1] =
metadataTestAction(getNewEchoMessage("EchoRequest", ECHO_METADATA_TEST),
"metadata-test");
- testResponses[2] =
rrdFetchTestAction(getNewEchoMessage("EchoRequest", ECHO_RRD_FETCH_TEST),
"rrd-fetch-test");
-
- Message response = getNewEchoMessage("EchoResponse", ECHO_SELF_TEST
+ "/1.0");
- Data responseData = response.getDataCollection().iterator().next();
-
- Metadata metadata = null;
- Data data = null;
-
- for (int i = 0; i < testResponses.length; i++) {
- metadata =
testResponses[i].getMetadataCollection().iterator().next();
- data = testResponses[i].getDataCollection().iterator().next();
-
- metadata.setId(metadata.getId() + "_t" + i);
- data.setId(data.getId() + "_t" + i);
- data.setMetadataIdRef(metadata.getId());
-
- responseData.addChild(metadata);
- responseData.addChild(data);
- }
-
- return response;
- }
-
- /**
- * This test that the metadata DB is actually available.
- *
- * We could also add a test to check that the DB schema is correct.
- *
- * @param request
- * @param testName
- * @return
- */
- protected Message metadataTestAction(Message request, String testName) {
- logger.debug("We're being asked to do a metadata test.");
-
- try {
- Element element = getMetadataConfigurationElements(request);
-
- if (element != null) {
- logger.info("Metadata test is ok!");
- return getResultMessage(
- ECHO_SELF_TEST + "/" + serviceType + "/" +
serviceName.replace(' ', '_') + "/" + testName
- + "/success/1.0",
METADATA_TEST_SUCCESS_RESULT_CODE_RESPONSE);
- } else {
- throw new PerfSONARException("test_exception", "Could not
get element from metadata DB.");
- }
- } catch (PerfSONARException ex) {
- logger.warn("Metadata test action failed: {}",
ex.getResultDescription());
- return getResultMessage(
- ECHO_SELF_TEST + "/" + serviceType + "/" +
serviceName.replace(' ', '_') + "/" + testName
- + "/failure/1.0", ex.getResultDescription());
- }
- }
-
- /**
- * This test that at least a RRD file is readable.
- *
- * @param request
- * @param testName
- * @return
- */
- protected Message rrdFetchTestAction(Message request, String testName) {
- logger.debug("We're being asked to do a rrd fetch test.");
-
- try {
- Element element = getMetadataConfigurationElements(request);
- if (element == null) {
- String msg = "No data elements in the metadata
configuration.";
- logger.warn(msg);
- return getResultMessage(
- ECHO_SELF_TEST + "/" + serviceType + "/" +
serviceName.replace(' ', '_') + "/" + testName
- + "/failure/1.0", msg);
- }
-
- Key key = ((Data) element).getKey();
- if (key == null) {
- String msg = "No key in data element with id='" +
element.getId() + "' in the metadata configuration.";
- logger.warn(msg);
- return getResultMessage(
- ECHO_SELF_TEST + "/" + serviceType + "/" +
serviceName.replace(' ', '_') + "/" + testName
- + "/failure/1.0", msg);
- }
-
- Metadata metadata = new Metadata();
- metadata.setKey(key);
- Data data = new Data();
- data.setMetadataIdRef(metadata.getId());
- Message dataRequest = new Message();
- dataRequest.setMetadata(metadata);
- dataRequest.setData(data);
-
- DataStorageDAO dao = DataStorageDAOFactory.getDAO();
- Data fetchedData = dao.fetch(dataRequest);
-
- if (fetchedData != null) {
- logger.info("RRD fetch test is ok!");
- return getResultMessage(
- ECHO_SELF_TEST + "/" + serviceType + "/" +
serviceName.replace(' ', '_') + "/" + testName
- + "/success/1.0",
RRD_FETCH_TEST_SUCCESS_RESULT_CODE_RESPONSE);
- } else {
- logger.warn("RRD fetch test action failed: No data fetched
from rrd file.");
- return getResultMessage(
- ECHO_SELF_TEST + "/" + serviceType + "/" +
serviceName.replace(' ', '_') + "/" + testName
- + "/failure/1.0", "No data fetched from rrd file.");
- }
- } catch (PerfSONARException ex) {
- logger.warn("RRD fetch test action failed: {}",
ex.getResultDescription());
- return getResultMessage(
- ECHO_SELF_TEST + "/" + serviceType + "/" +
serviceName.replace(' ', '_') + "/" + testName
- + "/failure/1.0", ex.getResultDescription());
- }
-
- }
-
-
- /**
- * Reads a metadata element from the metadata DB
- * @param request
- * @return
- * @throws PerfSONARException
- */
- protected Element getMetadataConfigurationElements(Message request)
throws PerfSONARException {
- MetadataStorageDAO dao = MetadataStorageDAOFactory.getDAO();
- ArrayList<Element> results = (ArrayList<Element>) dao.fetch(request);
- Element element = null;
-
- if (results != null && results.size() == 2) {
- // We're only interested in the second Element (data)
- element = results.get(1);
- }
-
- return element;
- }
-
-
- /**
- * Generates a Echo Request message to be used by the Self Test
- * @param messageType
- * @param eventType
- * @return
- * @throws PerfSONARException
- */
- protected Message getNewEchoMessage(String messageType, String
eventType) throws PerfSONARException {
- Message message = new Message();
- message.setType(messageType);
-
- Metadata metadata = new Metadata();
- EventType evt = new EventType(eventType, "nmwg");
- metadata.addChild(evt);
- message.setMetadata(metadata);
-
- Data data = new Data();
- data.setMetadataIdRef(metadata.getId());
- message.setData(data);
-
- return message;
- }
-
-
- protected void errorCode() throws PerfSONARException {
- throw new PerfSONARException("query_exception", "Wrong echo
eventType value in the request.");
- }
-
-
-} //EchoServiceEngine

Copied:
trunk/perfsonar-java-rrd-ma/src/main/java/org/perfsonar/service/measurementArchive/rrdType/RRDMAEchoServiceEngine.java
(from rev 6428,
trunk/perfsonar-java-rrd-ma/src/main/java/org/perfsonar/service/measurementArchive/rrdType/EchoServiceEngine.java)
===================================================================
---
trunk/perfsonar-java-rrd-ma/src/main/java/org/perfsonar/service/measurementArchive/rrdType/RRDMAEchoServiceEngine.java
(rev 0)
+++
trunk/perfsonar-java-rrd-ma/src/main/java/org/perfsonar/service/measurementArchive/rrdType/RRDMAEchoServiceEngine.java
2013-06-04 19:55:42 UTC (rev 6434)
@@ -0,0 +1,262 @@
+package org.perfsonar.service.measurementArchive.rrdType;
+
+import org.perfsonar.base2.service.exceptions.PerfSONARException;
+import org.perfsonar.base2.service.requesthandler.ServiceMessage;
+import org.perfsonar.base2.service.configuration.ConfigurationManager;
+import org.perfsonar.base2.service.configuration.Configuration;
+import org.perfsonar.base2.service.util.ResultCodesUtil;
+
+import org.perfsonar.base2.xml.nmwg.Message;
+import org.perfsonar.base2.xml.nmwg.Metadata;
+import org.perfsonar.base2.xml.nmwg.Data;
+import org.perfsonar.base2.xml.nmwg.Key;
+import org.perfsonar.base2.xml.nmwg.EventType;
+import org.perfsonar.base2.xml.Element;
+
+import
org.perfsonar.service.measurementArchive.rrdType.storage.MetadataStorageDAO;
+import
org.perfsonar.service.measurementArchive.rrdType.storage.MetadataStorageDAOFactory;
+
+import
org.perfsonar.service.measurementArchive.rrdType.storage.DataStorageDAO;
+import
org.perfsonar.service.measurementArchive.rrdType.storage.DataStorageDAOFactory;
+
+import java.util.ArrayList;
+
+public class RRDMAEchoServiceEngine extends
org.perfsonar.base2.service.requesthandler.EchoServiceEngine
+{
+ // ------------------------------------------------------------- class
fields
+
+
+ // TODO: Should eventTypes for success be full URL or only the last bit
(like in the echo success from pSbase2)
+ public static final String ECHO_METADATA_TEST =
+ "http://schemas.perfsonar.net/tools/admin/selftest/1"; +
".0/metadata-test";
+ public static final String ECHO_RRD_FETCH_TEST =
+ "http://schemas.perfsonar.net/tools/admin/selftest/1"; +
".0/rrd-fetch-test";
+
+ protected static final String SERVICE_TYPE_OPTION_NAME = "serviceType";
+ protected static final String SERVICE_NAME_OPTION_NAME = "serviceName";
+
+ protected String serviceType = "";
+ protected String serviceName = "";
+
+ protected static final String METADATA_TEST_SUCCESS_RESULT_CODE_RESPONSE
=
+ "Fetching metadata from DB is " + "correct.";
+ protected static final String
RRD_FETCH_TEST_SUCCESS_RESULT_CODE_RESPONSE =
+ "Fetching data from RRD file is " + "correct.";
+
+
+ // ------------------------------------------------------------- methods
+
+ public void takeAction(ServiceMessage serviceRequest, ServiceMessage
serviceResponse) throws PerfSONARException {
+ logger.info("Simple Echo Service Engine started.");
+
+ Message response = null;
+
+ Configuration configuration =
ConfigurationManager.getInstance().getConfiguration();
+ serviceType =
configuration.getLookupInformationOption(SERVICE_TYPE_OPTION_NAME);
+ serviceName =
configuration.getLookupInformationOption(SERVICE_NAME_OPTION_NAME);
+
+ Message request = serviceRequest.getMessageElement();
+ String eventType = getEventType(request);
+ if (eventType.equals(ECHO_EVENT_TYPE)) {
+ response = simpleEchoAction();
+ } else if (eventType.equals(ECHO_SELF_TEST + "/1.0")) {
+ response = selfTestAction();
+ } else if (eventType.equals(ECHO_METADATA_TEST)) {
+ response = metadataTestAction(request, "metadata-test");
+ } else if (eventType.equals(ECHO_RRD_FETCH_TEST)) {
+ response = rrdFetchTestAction(request, "rrd-fetch-test");
+ } else {
+ errorCode();
+ }
+
+ response.setId("Resp_" + request.getAttribute("id"));
+ response.addAttribute("type", "EchoResponse");
+
+ serviceResponse.setElement(response);
+ }
+
+ protected Message simpleEchoAction() throws PerfSONARException {
+ logger.debug("Echo request received.");
+ return
ResultCodesUtil.generateResultMessage(ECHO_SUCCESS_RESULT_CODE,
ECHO_SUCCESS_RESULT_CODE_DSC);
+ }
+
+ /**
+ * An RRD MA self test consist of the following:
+ * - check service is installed properly and is working (this also test
the configuration file can be read)
+ * - response to a EchoRequest
+ * - check the SQL DB can be accessed
+ * - response to a generic MetadataKeyRequest (random/generic metadata
fetch)
+ * - check an RRD file can be read
+ * - response to a generic SetupDataRequest (random/generic fetch)
+ * @return
+ * @throws PerfSONARException
+ */
+ protected Message selfTestAction() throws PerfSONARException {
+ Message[] testResponses = new Message[3];
+ testResponses[0] = simpleEchoAction();
+ testResponses[1] =
metadataTestAction(getNewEchoMessage("EchoRequest", ECHO_METADATA_TEST),
"metadata-test");
+ testResponses[2] =
rrdFetchTestAction(getNewEchoMessage("EchoRequest", ECHO_RRD_FETCH_TEST),
"rrd-fetch-test");
+
+ Message response = getNewEchoMessage("EchoResponse", ECHO_SELF_TEST
+ "/1.0");
+ Data responseData = response.getDataCollection().iterator().next();
+
+ Metadata metadata = null;
+ Data data = null;
+
+ for (int i = 0; i < testResponses.length; i++) {
+ metadata =
testResponses[i].getMetadataCollection().iterator().next();
+ data = testResponses[i].getDataCollection().iterator().next();
+
+ metadata.setId(metadata.getId() + "_t" + i);
+ data.setId(data.getId() + "_t" + i);
+ data.setMetadataIdRef(metadata.getId());
+
+ responseData.addChild(metadata);
+ responseData.addChild(data);
+ }
+
+ return response;
+ }
+
+ /**
+ * This test that the metadata DB is actually available.
+ *
+ * We could also add a test to check that the DB schema is correct.
+ *
+ * @param request
+ * @param testName
+ * @return
+ */
+ protected Message metadataTestAction(Message request, String testName) {
+ logger.debug("We're being asked to do a metadata test.");
+
+ try {
+ Element element = getMetadataConfigurationElements(request);
+
+ if (element != null) {
+ logger.info("Metadata test is ok!");
+ return getResultMessage(
+ ECHO_SELF_TEST + "/" + serviceType + "/" +
serviceName.replace(' ', '_') + "/" + testName
+ + "/success/1.0",
METADATA_TEST_SUCCESS_RESULT_CODE_RESPONSE);
+ } else {
+ throw new PerfSONARException("test_exception", "Could not
get element from metadata DB.");
+ }
+ } catch (PerfSONARException ex) {
+ logger.warn("Metadata test action failed: {}",
ex.getResultDescription());
+ return getResultMessage(
+ ECHO_SELF_TEST + "/" + serviceType + "/" +
serviceName.replace(' ', '_') + "/" + testName
+ + "/failure/1.0", ex.getResultDescription());
+ }
+ }
+
+ /**
+ * This test that at least a RRD file is readable.
+ *
+ * @param request
+ * @param testName
+ * @return
+ */
+ protected Message rrdFetchTestAction(Message request, String testName) {
+ logger.debug("We're being asked to do a rrd fetch test.");
+
+ try {
+ Element element = getMetadataConfigurationElements(request);
+ if (element == null) {
+ String msg = "No data elements in the metadata
configuration.";
+ logger.warn(msg);
+ return getResultMessage(
+ ECHO_SELF_TEST + "/" + serviceType + "/" +
serviceName.replace(' ', '_') + "/" + testName
+ + "/failure/1.0", msg);
+ }
+
+ Key key = ((Data) element).getKey();
+ if (key == null) {
+ String msg = "No key in data element with id='" +
element.getId() + "' in the metadata configuration.";
+ logger.warn(msg);
+ return getResultMessage(
+ ECHO_SELF_TEST + "/" + serviceType + "/" +
serviceName.replace(' ', '_') + "/" + testName
+ + "/failure/1.0", msg);
+ }
+
+ Metadata metadata = new Metadata();
+ metadata.setKey(key);
+ Data data = new Data();
+ data.setMetadataIdRef(metadata.getId());
+ Message dataRequest = new Message();
+ dataRequest.setMetadata(metadata);
+ dataRequest.setData(data);
+
+ DataStorageDAO dao = DataStorageDAOFactory.getDAO();
+ Data fetchedData = dao.fetch(dataRequest);
+
+ if (fetchedData != null) {
+ logger.info("RRD fetch test is ok!");
+ return getResultMessage(
+ ECHO_SELF_TEST + "/" + serviceType + "/" +
serviceName.replace(' ', '_') + "/" + testName
+ + "/success/1.0",
RRD_FETCH_TEST_SUCCESS_RESULT_CODE_RESPONSE);
+ } else {
+ logger.warn("RRD fetch test action failed: No data fetched
from rrd file.");
+ return getResultMessage(
+ ECHO_SELF_TEST + "/" + serviceType + "/" +
serviceName.replace(' ', '_') + "/" + testName
+ + "/failure/1.0", "No data fetched from rrd file.");
+ }
+ } catch (PerfSONARException ex) {
+ logger.warn("RRD fetch test action failed: {}",
ex.getResultDescription());
+ return getResultMessage(
+ ECHO_SELF_TEST + "/" + serviceType + "/" +
serviceName.replace(' ', '_') + "/" + testName
+ + "/failure/1.0", ex.getResultDescription());
+ }
+
+ }
+
+
+ /**
+ * Reads a metadata element from the metadata DB
+ * @param request
+ * @return
+ * @throws PerfSONARException
+ */
+ protected Element getMetadataConfigurationElements(Message request)
throws PerfSONARException {
+ MetadataStorageDAO dao = MetadataStorageDAOFactory.getDAO();
+ ArrayList<Element> results = (ArrayList<Element>) dao.fetch(request);
+ Element element = null;
+
+ if (results != null && results.size() == 2) {
+ // We're only interested in the second Element (data)
+ element = results.get(1);
+ }
+
+ return element;
+ }
+
+
+ /**
+ * Generates a Echo Request message to be used by the Self Test
+ * @param messageType
+ * @param eventType
+ * @return
+ * @throws PerfSONARException
+ */
+ protected Message getNewEchoMessage(String messageType, String
eventType) throws PerfSONARException {
+ Message message = new Message();
+ message.setType(messageType);
+
+ Metadata metadata = new Metadata();
+ EventType evt = new EventType(eventType, "nmwg");
+ metadata.addChild(evt);
+ message.setMetadata(metadata);
+
+ Data data = new Data();
+ data.setMetadataIdRef(metadata.getId());
+ message.setData(data);
+
+ return message;
+ }
+
+
+ protected void errorCode() throws PerfSONARException {
+ throw new PerfSONARException("query_exception", "Wrong echo
eventType value in the request.");
+ }
+
+
+} //RRDMAEchoServiceEngine

Modified:
trunk/perfsonar-java-rrd-ma/src/main/resources/perfsonar/conf/configuration.xml
===================================================================
---
trunk/perfsonar-java-rrd-ma/src/main/resources/perfsonar/conf/configuration.xml
2013-06-04 18:58:51 UTC (rev 6433)
+++
trunk/perfsonar-java-rrd-ma/src/main/resources/perfsonar/conf/configuration.xml
2013-06-04 19:55:42 UTC (rev 6434)
@@ -21,7 +21,7 @@
<messageHandler>

<message
handler="org.perfsonar.base2.service.messages.GenericMessageHandler"
type="EchoRequest">
- <option name="ServiceEngine"
value="org.perfsonar.service.measurementArchive.rrdType.EchoServiceEngine"/>
+ <option name="ServiceEngine"
value="org.perfsonar.service.measurementArchive.rrdType.RRDMAEchoServiceEngine"/>
<option name="authN" value="no"/>
</message>


Modified:
trunk/perfsonar-java-rrd-ma/src/main/resources/perfsonar/conf/configuration.xml.template
===================================================================
---
trunk/perfsonar-java-rrd-ma/src/main/resources/perfsonar/conf/configuration.xml.template
2013-06-04 18:58:51 UTC (rev 6433)
+++
trunk/perfsonar-java-rrd-ma/src/main/resources/perfsonar/conf/configuration.xml.template
2013-06-04 19:55:42 UTC (rev 6434)
@@ -23,7 +23,7 @@
<messageHandler>

<message
handler="org.perfsonar.base2.service.messages.GenericMessageHandler"
type="EchoRequest">
- <option name="ServiceEngine"
value="org.perfsonar.service.measurementArchive.rrdType.EchoServiceEngine"/>
+ <option name="ServiceEngine"
value="org.perfsonar.service.measurementArchive.rrdType.RRDMAEchoServiceEngine"/>
<option name="authN" value="no"/>
</message>


Modified:
trunk/perfsonar-java-rrd-ma/src/test/resources/perfsonar/conf/configuration.xml
===================================================================
---
trunk/perfsonar-java-rrd-ma/src/test/resources/perfsonar/conf/configuration.xml
2013-06-04 18:58:51 UTC (rev 6433)
+++
trunk/perfsonar-java-rrd-ma/src/test/resources/perfsonar/conf/configuration.xml
2013-06-04 19:55:42 UTC (rev 6434)
@@ -21,7 +21,7 @@
<messageHandler>

<message
handler="org.perfsonar.base2.service.messages.GenericMessageHandler"
type="EchoRequest">
- <option name="ServiceEngine"
value="org.perfsonar.service.measurementArchive.rrdType.EchoServiceEngine"/>
+ <option name="ServiceEngine"
value="org.perfsonar.service.measurementArchive.rrdType.RRDMAEchoServiceEngine"/>
<option name="authN" value="no"/>
</message>




  • [pS-dev] [GEANT/SA2/ps-java-services] r6434 - in trunk: perfsonar-java-base2/src/main/java/org/perfson ar/base2/service/configuration perfsonar-java-base2/src/ma in/java/org/perfsonar/base2/service/registration perfsonar -java-base2/src/main/java/org/perfsonar/base2/service/sche duler perfsonar-java-base2/src/main/java/org/perfsonar/bas e2/xml perfsonar-java-base2/src/main/java/org/perfsonar/ba se2/xml/nmwg perfsonar-java-rrd-ma/src/main/java/org/perfs onar/service/measurementArchive/rrdType perfsonar-java-rrd -ma/src/main/resources/perfsonar/conf perfsonar-java-rrd-m a/src/test/resources/perfsonar/conf, svn-noreply, 06/04/2013

Archive powered by MHonArc 2.6.16.

Top of Page