Skip to Content.
Sympa Menu

perfsonar-dev - perfsonar: r2345 - in trunk/perfsonar/src/org/perfsonar/service: commons/engine commons/registration commons/storage/xmldb/exist/rest lookupService/xmlType lookupService/xmlType/storage lookupService/xmlType/storage/exist

Subject: perfsonar development work

List archive

perfsonar: r2345 - in trunk/perfsonar/src/org/perfsonar/service: commons/engine commons/registration commons/storage/xmldb/exist/rest lookupService/xmlType lookupService/xmlType/storage lookupService/xmlType/storage/exist


Chronological Thread 
  • From:
  • To:
  • Subject: perfsonar: r2345 - in trunk/perfsonar/src/org/perfsonar/service: commons/engine commons/registration commons/storage/xmldb/exist/rest lookupService/xmlType lookupService/xmlType/storage lookupService/xmlType/storage/exist
  • Date: Mon, 23 Apr 2007 10:53:08 -0400

Author: mac
Date: 2007-04-23 10:53:08 -0400 (Mon, 23 Apr 2007)
New Revision: 2345

Added:
trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/storage/

trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/storage/DataCredential.java

trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/storage/LookupServiceDAO.java

trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/storage/LookupServiceDAOFactory.java

trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/storage/Test2.java

trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/storage/XMLDataStorage.java

trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/storage/exist/

trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/storage/exist/ExistHTTPDataStorage.java

trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/storage/exist/XQueryExistDAOImpl.java
Modified:
trunk/perfsonar/src/org/perfsonar/service/commons/engine/ActionType.java

trunk/perfsonar/src/org/perfsonar/service/commons/registration/GenericServiceLSRegistrator.java

trunk/perfsonar/src/org/perfsonar/service/commons/storage/xmldb/exist/rest/HTTPAccess.java

trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/EchoRequestAction.java

trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/LSAction.java

trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/LSCleanup.java

trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/LSCleanupLoader.java

trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/LSDeregisterAction.java

trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/LSGenericRegisterAction.java

trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/LSKeepaliveAction.java

trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/LSLookupAction.java

trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/LSRegisterAction.java

trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/XmlTypeLSServiceEngine.java
Log:
Changes in DB access in LS using DAO. DAO implementation for eXist XML DB

Modified:
trunk/perfsonar/src/org/perfsonar/service/commons/engine/ActionType.java
===================================================================
--- trunk/perfsonar/src/org/perfsonar/service/commons/engine/ActionType.java
2007-04-23 13:45:10 UTC (rev 2344)
+++ trunk/perfsonar/src/org/perfsonar/service/commons/engine/ActionType.java
2007-04-23 14:53:08 UTC (rev 2345)
@@ -44,31 +44,36 @@



- /**
- * Action type to request a measurement
- */
- public static final String LS_REGISTER = "LS_REGISTER";
+ /**

+ * Action type to request a measurement

+ */

+ public static final String LS_REGISTER = "LS_REGISTER";

+

+

+ /**

+ * Action type to request a measurement

+ */

+ public static final String LS_LOOKUP = "LS_LOOKUP";

+

+

+ /**

+ * Action type to request a measurement

+ */

+ public static final String LS_DEREGISTER = "LS_DEREGISTER";

+

+

+ /**

+ * Action type to request a measurement

+ */

+ public static final String LS_KEEPALIVE = "LS_KEEPALIVE";

+

+

+ /**

+ * Action type to LS Cleanup

+ */

+ public static final String LS_CLEANUP = "LS_CLEANUP";


- /**
- * Action type to request a measurement
- */
- public static final String LS_LOOKUP = "LS_LOOKUP";
-
-
- /**
- * Action type to request a measurement
- */
- public static final String LS_DEREGISTER = "LS_DEREGISTER";
-
-
- /**
- * Action type to request a measurement
- */
- public static final String LS_KEEPALIVE = "LS_KEEPALIVE";
-
-
-
// ----------------------------------------- Echo Action



Modified:
trunk/perfsonar/src/org/perfsonar/service/commons/registration/GenericServiceLSRegistrator.java
===================================================================
---
trunk/perfsonar/src/org/perfsonar/service/commons/registration/GenericServiceLSRegistrator.java
2007-04-23 13:45:10 UTC (rev 2344)
+++
trunk/perfsonar/src/org/perfsonar/service/commons/registration/GenericServiceLSRegistrator.java
2007-04-23 14:53:08 UTC (rev 2345)
@@ -90,42 +90,23 @@

Message message = getLSRegisterRequestMessage();

- String result = XMLUtils.serializeXML(message);
- //TODO: to remove
-
logger.debug("GenericServiceLSRegistrator: sending via Axis");

- //create document
-
+ //send request Document to url
+
try {
-
- DocumentBuilder builder = DocumentBuilderFactory.
- newInstance().newDocumentBuilder();
-
- Document requestDocument = builder.newDocument();

- requestDocument = message.getDOM(requestDocument);
-// String domres = XMLUtils.serializeDOM(requestDocument);
-// logger.debug("GenericServiceLSRegistrator: DOM: "+domres);

- logger.debug("GenericServiceLSRegistrator: Creating Axis
Client");
+ logger.debug("GenericServiceLSRegistrator: Creating Axis
Client");

- //send request Document to url
+ //return response as Message
+ String parserFile = configuration.getProperty(
+ "service.sax_parser.config");
+
AxisClient client = new AxisClient();
-
- Document responseDocument =
- client.sendRequest(lsUrl,requestDocument);
- logger.debug("GenericServiceLSRegistrator: sent");
-
- logger.debug("GenericServiceLSRegistrator: convert to
message");
+ Message responseMsg =
+ client.sendRequest(lsUrl,message, parserFile);

- //return response as Message
- String parserFile = configuration.getProperty(
- "service.sax_parser.config");
- Message msg = XMLUtils.convertToMessage(
- responseDocument,
- parserFile);
-
- return msg;
+ return responseMsg;

} catch (ParserConfigurationException e) {
logger.error("GenericServiceLSRegistrator: "+e.getMessage());

Modified:
trunk/perfsonar/src/org/perfsonar/service/commons/storage/xmldb/exist/rest/HTTPAccess.java
===================================================================
---
trunk/perfsonar/src/org/perfsonar/service/commons/storage/xmldb/exist/rest/HTTPAccess.java
2007-04-23 13:45:10 UTC (rev 2344)
+++
trunk/perfsonar/src/org/perfsonar/service/commons/storage/xmldb/exist/rest/HTTPAccess.java
2007-04-23 14:53:08 UTC (rev 2345)
@@ -149,7 +149,7 @@
String password) throws IOException {

//temp//
- boolean debug=true;
+ boolean debug=false;

//connect by HTTP with /exist/rest/db/COLLECTION
URL _url = new URL(url);

Modified:
trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/EchoRequestAction.java
===================================================================
---
trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/EchoRequestAction.java
2007-04-23 13:45:10 UTC (rev 2344)
+++
trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/EchoRequestAction.java
2007-04-23 14:53:08 UTC (rev 2345)
@@ -7,12 +7,12 @@
import org.perfsonar.service.commons.exceptions.PerfSONARException;
import org.perfsonar.service.commons.exceptions.RequestException;
import org.perfsonar.service.commons.exceptions.SystemException;
-import org.perfsonar.service.commons.storage.StorageManager;
-import org.perfsonar.service.commons.storage.xmldb.XmlDbResult;
import org.perfsonar.service.commons.util.ResultCodesUtil;
+import org.perfsonar.service.lookupService.xmlType.storage.LookupServiceDAO;

/**
* Handling EchoRequest
+ *
* @author Maciej Glowiak
*
*/
@@ -20,8 +20,8 @@

public final static String
SUPPORTED_EVENT_TYPE="http://schemas.perfsonar.net/tools/admin/echo/ls/2.0";;

- public EchoRequestAction(StorageManager xmlStorageManager) throws
SystemException {
- super(xmlStorageManager);
+ public EchoRequestAction(LookupServiceDAO dao) throws SystemException {
+ super(dao);
}

@Override
@@ -57,9 +57,8 @@

if (testDbConnection) {
try {
- String date = getDBDateTime(); //XQuery:
"fn:current-datetime()"
- message = message+"Test DB Connection - OK " +
- "(got database current time: ["+date+"])\n";
+ dao.isDBConnectivity(); //returns true if so, or exception
+ message = message+"Test DB Connection - OK\n";
} catch (PerfSONARException ex) {
throw new SystemException(
ex.getResultCode(),
@@ -79,9 +78,11 @@

try {
isSchemaStore =
- getDBSchema("LSStore") > 0; //XQuery:
"count(/nmwg:schema[@type='LSStore'])"

- isSchemaControl =
- getDBSchema("LSStore-control") > 0; //XQuery:
"count(/nmwg:schema[@type='LSStore-control'])"

+
dao.isDBCollection(LookupServiceDAO.LS_STORE_COLLECTION_TYPE);
+
+ isSchemaControl =
+
dao.isDBCollection(LookupServiceDAO.LS_STORE_CONTROL_COLLECTION_TYPE);
+
} catch (PerfSONARException ex) {
throw new SystemException(
ex.getResultCode(),
@@ -109,44 +110,6 @@


/**
- * Tests if paramstr is = "yes", "true" or "test"
- */
- private boolean testIfTrue(String paramstr) {
-
- return ("yes".equalsIgnoreCase(paramstr)||
- "true".equalsIgnoreCase(paramstr)||
- "test".equalsIgnoreCase(paramstr));
-
- }
-
-
- /**
- * Sends "fn:current-dateTime()" XQuery expression
- */
- private String getDBDateTime() throws SystemException, RequestException,
DataFormatException {
-
- String xq = "fn:current-dateTime()";
- XmlDbResult res = (XmlDbResult) xmlStorageManager.fetch(xq);
- return res.getResultAsString();
-
- }
-
-
- /**
- * Sends
"count(/nmwg:store[@type='schemaName')"
XQuery expression
- */
- private int getDBSchema(String schemaName) throws PerfSONARException {
-
- String xq =
- "declare namespace nmwg=\"http://ggf.org/ns/nmwg/base/2.0/\";; " +
- "
count(/nmwg:store[@type='"+schemaName+"'])";
- XmlDbResult res = (XmlDbResult) xmlStorageManager.fetch(xq);
- int result = Integer.parseInt(res.getResultAsString());
- return result;
- }
-
-
- /**
* Creates success.echo with additional message
*/
protected Message getEcho(Message request, String message)

Modified:
trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/LSAction.java
===================================================================
---
trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/LSAction.java
2007-04-23 13:45:10 UTC (rev 2344)
+++
trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/LSAction.java
2007-04-23 14:53:08 UTC (rev 2345)
@@ -16,10 +16,9 @@
import org.perfsonar.commons.auxiliary.ComponentNames;
import
org.perfsonar.commons.auxiliary.components.configuration.ConfigurationComponent;
import org.perfsonar.commons.auxiliary.components.logger.LoggerComponent;
-import org.perfsonar.service.commons.exceptions.DataFormatException;
-import org.perfsonar.service.commons.exceptions.RequestException;
+import org.perfsonar.service.commons.exceptions.PerfSONARException;
import org.perfsonar.service.commons.exceptions.SystemException;
-import org.perfsonar.service.commons.storage.StorageManager;
+import org.perfsonar.service.lookupService.xmlType.storage.LookupServiceDAO;

/**
* Generic class for all LS actions performed by XmlTypeLSServiceEngine
@@ -32,49 +31,17 @@
// --------------------------------------------------------------
Constants

/**
- * The name of the store collection (containing LS data/metadata
- */
- protected static final String LS_STORE_COLLECTION_TYPE = "LSStore";
-
-
- /**
- * The name of the control collection of LS
- */
- protected static final String LS_STORE_CONTROL_COLLECTION_TYPE =
"LSStore-control";
-
-
- /**
* LS Key name
*/
protected static final String LS_KEY = "lsKey";

- /**
- * Header for all XUpdates used in LS modifications
- */
- protected static final String XUPDATE_HEADER =
- "<xu:modifications version=\'1.0\'" +
- " xmlns:xu=\'http://www.xmldb.org/xupdate\'" +
- " xmlns:perfsonar='http://ggf.org/ns/nmwg/tools/org/perfsonar/1.0/'"+
- " xmlns:nmwg='http://ggf.org/ns/nmwg/base/2.0/'"+
- "
xmlns:psservice='http://ggf.org/ns/nmwg/tools/org/perfsonar/service/1.0/'"+
- " xmlns:nmwgt='http://ggf.org/ns/nmwg/topology/2.0/'"+
- "
xmlns:netutil='http://ggf.org/ns/nmwg/characteristic/utilization/2.0/'" +
- ">\n";
-
- /**
- * Footer for all XUpdates used in LS register
- */
- protected static final String XUPDATE_FOOTER = "</xu:modifications>";
-
-
-
// ----------------------------------------------------- Instance
variables


/**
* Local XML DB Access, Storage Manager
*/
- protected StorageManager xmlStorageManager = null;
+ protected LookupServiceDAO dao = null;


/**
@@ -92,9 +59,9 @@
// ------------------------------------------------------------
Constructor


- public LSAction(StorageManager xmlStorageManager) throws SystemException
{
+ public LSAction(LookupServiceDAO dao) throws SystemException {

- this.xmlStorageManager = xmlStorageManager;
+ this.dao = dao;

logger = (LoggerComponent)AuxiliaryComponentManager.
getInstance().getComponent(ComponentNames.LOGGER);
@@ -230,13 +197,34 @@
}
return res;
}
+
+ protected LookupServiceDAO getDAO() {
+
+ return this.dao;
+
+ }
+

+ /**
+ * Tests if paramstr is = "yes", "true" or "test" or "ok"
+ */
+ protected boolean testIfTrue(String paramstr) {
+
+ return ("yes".equalsIgnoreCase(paramstr)||
+ "true".equalsIgnoreCase(paramstr)||
+ "ok".equalsIgnoreCase(paramstr)||
+ "test".equalsIgnoreCase(paramstr));
+
+ }
+
+
+
// ----------------------------------------------- Abstract methods


public abstract Message performAction(
Message request)
- throws SystemException, RequestException, DataFormatException;
+ throws PerfSONARException;


// ---------------------------------------------------------- Inner
classes
@@ -270,5 +258,5 @@

} //ResultCode

-
+
} //LSAction

Modified:
trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/LSCleanup.java
===================================================================
---
trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/LSCleanup.java
2007-04-23 13:45:10 UTC (rev 2344)
+++
trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/LSCleanup.java
2007-04-23 14:53:08 UTC (rev 2345)
@@ -1,13 +1,12 @@
package org.perfsonar.service.lookupService.xmlType;

+import org.ggf.ns.nmwg.base.v2_0.Data;
import org.ggf.ns.nmwg.base.v2_0.Message;
+import org.ggf.ns.nmwg.base.v2_0.Metadata;
import
org.perfsonar.commons.auxiliary.components.simplescheduler.SchedulerAction;
-import org.perfsonar.service.commons.exceptions.DataFormatException;
import org.perfsonar.service.commons.exceptions.PerfSONARException;
-import org.perfsonar.service.commons.exceptions.RequestException;
import org.perfsonar.service.commons.exceptions.SystemException;
-import org.perfsonar.service.commons.storage.StorageManager;
-import org.perfsonar.service.commons.storage.xmldb.XmlDbResult;
+import org.perfsonar.service.lookupService.xmlType.storage.LookupServiceDAO;


/**
@@ -49,10 +48,10 @@
/**
* LSCleanup constructor
*/
- public LSCleanup(StorageManager xmlStorageManager)
+ public LSCleanup(LookupServiceDAO dao)
throws SystemException {

- super(xmlStorageManager);
+ super(dao);

//read service.ls.lookup_info_timeout
String prop = null;
@@ -81,82 +80,47 @@
* Scheduler Action for LS Cleanup
*/
public Message performAction(Message request)
- throws SystemException, RequestException, DataFormatException {
+ throws PerfSONARException {

//input parameter request - unimportant

-
long now = System.currentTimeMillis(); // current timestamp
+ logger.debug("LSCleanup: cleanup action, timestamp="+now);

- //process all keys from Database
- String[] keys = getMetadataKeys(xmlStorageManager);
+ //perform cleanup operation
+ dao.cleanupLookupInfo(now, getLsTTLInMillis());
+
+ //result usually unimportant, may be required if
+ //it was run not by Scheduler but by ServiceEngine
+ return getCleanupResponse();

- //for each of them check timestamp parameter
- for (int i=0; i<keys.length; i++) {
- if ("".equals(keys[i])) break;
+ }
+
+
+ private Message getCleanupResponse() {

- logger.debug("LSCleanup: checking key ["+keys[i]+"]");
+ ResultCode rc = createResultCode("success.ls.cleanup", "Action
success");

- String timestampStr = getControlParameter(
- keys[i],
- "timestamp",
- xmlStorageManager);
-
- long uptime = 0;
-
- //convert timestamp into long "uptime"
- if (timestampStr != null) {
- try {
- uptime = Long.parseLong(timestampStr);
- } catch (NumberFormatException ex) {
- logger.debug("LSCleanup: timestamp parameter for key
["+keys[i]+"] value=["+
- timestampStr+"] is not a number, omitting!");
- }
- }
-
- if (uptime==0) {
- logger.debug("LSCleanup: omitting key ["+keys[i]+"],
timestamp=0 or no timestamp parameter");
-
- //TODO: what to do?
- //do nothing...
-
- } else {
- long ttlsec = (uptime - now + getLsTTLInMillis())/1000;
- logger.debug("LSCleanup: Checking if time is exceeded for
key ["+keys[i]+"]: TTL=["+
- ((ttlsec<0)
- ?"exceeded from "+(-1*ttlsec)
- :"valid for "+ttlsec)+" seconds]");
-
- if ( (uptime + getLsTTLInMillis() - now ) < 0) {
-
- logger.info("LSCleanup: Time exceeded - " +
- "REMOVING metadata for key ["+
- keys[i]+"] and related data");
-
- //generate XUpdate that removes data
- //removes data from ALL schemas (LSStore,
LSStore-control)
- String query;
- query = XUPDATE_HEADER +
- "<xu:remove
select=\"/nmwg:store/nmwg:metadata[@id='"+
- keys[i]+"']\"/>\n" +
- "<xu:remove
select=\"/nmwg:store/nmwg:data[@metadataIdRef='"+
- keys[i]+"']\"/>\n" +
- XUPDATE_FOOTER;
+ Metadata[] responseMetadata = { rc.getMetadata() };

- //remove
-
- /****/
- xmlStorageManager.store(query); //XUpdate
- /****/
-
- } //if
-
- } //else
-
- } //for
+ Data[] responseData = null;
+ if (rc.getData() !=null ) {
+ responseData = new Data[1];
+ responseData[0] = rc.getData();
+ }

- return null; //result unimportant
+ Message response = new Message();
+
+ //doesn't really matter, it is changed by MessageHandler.
+ response.setType("LSCleanupResponse");
+
+ response.addChild(responseData[0]);
+ for(int j=0; j<responseMetadata.length; j++){
+ response.addChild(responseMetadata[j]);
+ }

+ return response;
+
}


@@ -171,54 +135,10 @@
return lsTTL * 1000; //because lsTTP is in seconds

}
-
-
+
/**
- * Get all metadata keys / metadata ids
+ * for scheduler
*/
- protected String[] getMetadataKeys(StorageManager xmlStorageManager)
- throws SystemException, RequestException, DataFormatException {
-
- String query =
- "declare namespace nmwg=\"http://ggf.org/ns/nmwg/base/2.0/\";; " +
-
"data(/nmwg:store[@type='"+LS_STORE_COLLECTION_TYPE+"']/nmwg:metadata/@id)";
-
- XmlDbResult edbres = (XmlDbResult)xmlStorageManager.fetch(query);
- String[] res = (String[])edbres.getResultAsStringArray();
-
- return res;
-
- }
-
-
- /**
- * Get control parameter for given key
- */
- protected String getControlParameter(
- String key,
- String parameterName, StorageManager xmlStorageManager)
- throws SystemException, RequestException,
DataFormatException {
-
- String query =
- "declare namespace nmwg=\"http://ggf.org/ns/nmwg/base/2.0/\";; " +
-
"/nmwg:store[@type='"+LS_STORE_CONTROL_COLLECTION_TYPE+
-
"']/nmwg:metadata[@id='"+key+
-
"']/nmwg:parameters/nmwg:parameter[@name='"+
- parameterName+"']/text()";
-
- XmlDbResult edbres = (XmlDbResult)xmlStorageManager.fetch(query);
- String[] resArray = (String[])edbres.getResultAsStringArray();
-
- try {
- String result = resArray[0];
- return result.trim();
- } catch (Exception ex) {
- return null;
- }
-
- }
-
-
public void runAction() {

iterations++;
@@ -232,6 +152,6 @@
}

}
+

-
} //LSCleanup

Modified:
trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/LSCleanupLoader.java
===================================================================
---
trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/LSCleanupLoader.java
2007-04-23 13:45:10 UTC (rev 2344)
+++
trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/LSCleanupLoader.java
2007-04-23 14:53:08 UTC (rev 2345)
@@ -6,8 +6,10 @@
import
org.perfsonar.commons.auxiliary.components.configuration.ConfigurationComponent;
import org.perfsonar.commons.auxiliary.components.logger.LoggerComponent;
import org.perfsonar.commons.auxiliary.components.simplescheduler.Scheduler;
+import org.perfsonar.service.commons.exceptions.PerfSONARException;
import org.perfsonar.service.commons.exceptions.SystemException;
-import org.perfsonar.service.commons.storage.StorageManager;
+import org.perfsonar.service.lookupService.xmlType.storage.LookupServiceDAO;
+import
org.perfsonar.service.lookupService.xmlType.storage.LookupServiceDAOFactory;


/**
@@ -36,7 +38,7 @@

private Scheduler scheduler;

- private StorageManager storage;
+ private LookupServiceDAO dao;


// ------------------------------------------------ public methods
@@ -111,32 +113,31 @@
//get storage component of specified type
try {

- String smType = config.getProperty("service.ls.db_type");
- storage = XmlTypeLSServiceEngine.getStorageManager(smType);
+ dao = LookupServiceDAOFactory.getDAO();

-// String storageVal = config.getProperty(
-// "component."+componentName+".storage_component");
-// logger.debug("LSCleanupLoader: parameter STORAGE="+storageVal);
+// String daoVal = config.getProperty(
+// "component."+componentName+".dao_component");
+// logger.debug("LSCleanupLoader: parameter dao="+daoVal);
//
-// storage = (StorageManager)
+// dao = (daoManager)
// AuxiliaryComponentManager.getInstance().
-// getComponent(storageVal);
+// getComponent(daoVal);

- if (storage==null)
- throw new SystemException("error.ls.no_storage",
+ if (dao==null)
+ throw new SystemException("error.ls.no_dao",
"No such component in AuxiliaryComponentManager");

- } catch (SystemException e) {
- throw new SystemException("error.ls.no_storage",
+ } catch (PerfSONARException e) {
+ throw new SystemException("error.ls.no_dao",
"LSCleanupLoader: no [component."+
- componentName+".storage_component] parameter. "
+ componentName+".dao_component] parameter. "
+e.getMessage());
}


//add cleanup action to scheduler (note time*1000 because it's
// in seconds and scheduler needs time in millis
- scheduler.addSchedulerTask(interval * 1000, new LSCleanup(storage));
+ scheduler.addSchedulerTask(interval * 1000, new LSCleanup(dao));

//done.


Modified:
trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/LSDeregisterAction.java
===================================================================
---
trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/LSDeregisterAction.java
2007-04-23 13:45:10 UTC (rev 2344)
+++
trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/LSDeregisterAction.java
2007-04-23 14:53:08 UTC (rev 2345)
@@ -1,12 +1,10 @@
package org.perfsonar.service.lookupService.xmlType;

-import org.ggf.ns.nmwg.base.v2_0.*;
-import org.perfsonar.service.commons.exceptions.DataFormatException;
+import org.ggf.ns.nmwg.base.v2_0.Message;
+import org.ggf.ns.nmwg.base.v2_0.Metadata;
import org.perfsonar.service.commons.exceptions.PerfSONARException;
-import org.perfsonar.service.commons.exceptions.RequestException;
import org.perfsonar.service.commons.exceptions.SystemException;
-import org.perfsonar.service.commons.storage.StorageManager;
-import org.perfsonar.service.commons.storage.xmldb.XmlDbResult;
+import org.perfsonar.service.lookupService.xmlType.storage.LookupServiceDAO;


/**
@@ -19,15 +17,15 @@

// --------------------------------------------------------------
Constants

- // ----------------------------------------------------- instance
variables
+ // ----------------------------------------------------- Instance
variables

- // -----------------------------------------------------------
Constructor
+ // ------------------------------------------------------------
Constructor


- public LSDeregisterAction(StorageManager xmlStorageManager)
- throws SystemException {
+ public LSDeregisterAction(LookupServiceDAO dao)
+ throws PerfSONARException {

- super(xmlStorageManager);
+ super(dao);

}

@@ -36,7 +34,7 @@


public Message performAction(Message request)
- throws SystemException, RequestException, DataFormatException {
+ throws PerfSONARException {

logger.debug(
"XmlTypeLSServiceEngine: LS deregister - action DEREGISTER
started");
@@ -62,94 +60,16 @@
throw new SystemException("error.ls.no_key", m);
}

- // Prepare query
- String query;
- String[] queryResults;
- int countMetadataRemoved = 0;
- int countDataRemoved =0;
+ int elementsRemoved = dao.removeLookupInfo(keyValue);

- //Query - get Data identifiers for given Key (all occurencies of Data
- //having metadataIdRef = Key)
-
- query = "declare namespace
nmwg=\"http://ggf.org/ns/nmwg/base/2.0/\";; "+
-
"data(/nmwg:store/nmwg:data[@metadataIdRef='"+keyValue+"']/@id)";
-
-
- XmlDbResult edbres = (XmlDbResult)xmlStorageManager.fetch(query);
- queryResults = (String[])edbres.getResultAsStringArray();
-
- if (queryResults!=null) {
-
- countDataRemoved = edbres.getCount();
-
- for (int i=0; i<queryResults.length; i++) {
- logger.debug("XmlTypeLSServiceEngine: removing
["+countDataRemoved+"] data elements id=["+
- queryResults[i]+"]");
- }
-
- }
-
-
- //If found at least one matching Data element, remove all
- if (countDataRemoved>0) {
-
- //generate XUpdate that removes data
- String remove = XUPDATE_HEADER +
- "<xu:remove
select=\"/nmwg:store/nmwg:data[@metadataIdRef='"
- + keyValue +"']\"/>\n"
- + XUPDATE_FOOTER;
-
- logger.debug("XmlTypeLSServiceEngine: Remove xupdate="+remove);
- xmlStorageManager.store(remove);
-
- }
-
- //Query - get metadata identifiers for Key (all occurencies of
Metadata
- //having id = Key : should be 0 or 1 !)
-
- query = "declare namespace
nmwg=\"http://ggf.org/ns/nmwg/base/2.0/\";; "+
-
"data(/nmwg:store/nmwg:metadata[@id='"+keyValue+"']/@id)";
-
- edbres = (XmlDbResult)xmlStorageManager.fetch(query); //XQuery
- queryResults = (String[])edbres.getResultAsStringArray();
-
- if (queryResults!=null) {
-
- countMetadataRemoved = edbres.getCount();
-
- for (int i=0; i<queryResults.length; i++) {
- logger.debug("XmlTypeLSServiceEngine: removing
["+countDataRemoved+"] metadata elements id=["+
- queryResults[i]+"]");
- }
-
- }
-
- //if found - remove (XUpdate)
- if (countDataRemoved>0) {
-
- //generate XUpdate that removes data
- //removes data from ALL schemas (LSStore, LSStore-control)
- query = XUPDATE_HEADER +
- "<xu:remove
select=\"/nmwg:store/nmwg:metadata[@id='"+
- keyValue+"']\"/>\n" +
- XUPDATE_FOOTER;
-
- xmlStorageManager.store(query); //XUpdate
-
- }
-
- //status of operation
-
- logger.debug("XmlTypeLSServiceEngine: Removed
data="+countDataRemoved+
- ", metadata="+countMetadataRemoved);
-
//Prepare result code

- if ((countDataRemoved==0) && (countMetadataRemoved==0))
- throw new SystemException("error.ls.key_not_found", "There were
no metadata and data for key ["+keyValue+"]");
- throw new SystemException("success.ls.deregister", "Removed ["+
- countMetadataRemoved+"] metadata and ["+
- countDataRemoved+"] data blocks for key ["+keyValue+"]");
+ if (elementsRemoved==0)
+ throw new PerfSONARException("error.ls.key_not_found",
+ "There were no metadata and data for key
["+keyValue+"]");
+ throw new SystemException("success.ls.deregister", "Removed total ["+
+ elementsRemoved+"] metadata and data elements for key ["+
+ keyValue+"]");

}


Modified:
trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/LSGenericRegisterAction.java
===================================================================
---
trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/LSGenericRegisterAction.java
2007-04-23 13:45:10 UTC (rev 2344)
+++
trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/LSGenericRegisterAction.java
2007-04-23 14:53:08 UTC (rev 2345)
@@ -2,11 +2,8 @@
package org.perfsonar.service.lookupService.xmlType;


-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.storage.StorageManager;
-import org.perfsonar.service.commons.storage.xmldb.XmlDbResult;
+import org.perfsonar.service.commons.exceptions.PerfSONARException;
+import org.perfsonar.service.lookupService.xmlType.storage.LookupServiceDAO;


/**
@@ -17,17 +14,14 @@
*/
public abstract class LSGenericRegisterAction extends LSAction {

-
- // --------------------------------------------------------------
Constants
-
-
+
// ------------------------------------------------------------
Constructor


- public LSGenericRegisterAction(StorageManager xmlStorageManager) throws
SystemException {
+ public LSGenericRegisterAction(LookupServiceDAO dao) throws
PerfSONARException {

//run super constructor (LSAction)
- super(xmlStorageManager);
+ super(dao);

}

@@ -39,254 +33,19 @@
* Updates timestamp parameter in LSStorage-control schema
* Sets it to current timestamp (System.currentTimeMillis())
*/
- protected long updateTime(String key, StorageManager xmlStorageManager)
- throws SystemException, RequestException, DataFormatException {
+ protected long updateTime(String key)
+ throws PerfSONARException {

//get current time
long now = System.currentTimeMillis();
- logger.debug("LSGenericRegisterAction: Update time... ["+now+"]");
+ logger.debug("[LS Registration] Update time... ["+now+"]");

//run setControlParameter, modify control schema of the LS
- setControlParameter(
- key,
- "timestamp",
- Long.toString(now),
- xmlStorageManager
- );
+ dao.setControlParameter(key, "timestamp", Long.toString(now));

return now;

}
-
-
-
- /**
- * Remove parameter from LSStorage-control. If metadata remains empty,
- * remove it as well
- * @throws DataFormatException
- * @throws RequestException
- * @throws SystemException
- */
- protected void removeControlParameter(
- String key,
- String parameterName,
- StorageManager xmlStorageManager) throws SystemException,
RequestException, DataFormatException {
-
- String remove = null;
-
- //remove single parameter
-
- logger.debug("LSGenericRegisterAction: remove parameter ["+
- parameterName+"] for key ["+key+"]");
-
- remove = XUPDATE_HEADER +
- "<xu:remove select=\"" +
-
"/nmwg:store[@type='"+LS_STORE_CONTROL_COLLECTION_TYPE+"']/nmwg:metadata[@id='"+key+
-
"']/nmwg:parameters/nmwg:parameter[@name='"+parameterName+"']"
+
- "\">\n" +
- "</xu:remove>\n"+
- XUPDATE_FOOTER;
-
- //remove data
- xmlStorageManager.store(remove);
-
- //check if metadata empty
-
- String query = "declare namespace
nmwg=\"http://ggf.org/ns/nmwg/base/2.0/\";; " +
-
"data(/nmwg:store[@type='"+LS_STORE_CONTROL_COLLECTION_TYPE+"']/nmwg:metadata[@id='"+key+"']/@id)";

- XmlDbResult res = (XmlDbResult)xmlStorageManager.fetch(query);
- int resnum = res.getCount();
-
- //metadata empty -> remove it
- if (resnum==0) {
-
- logger.debug("LSGenericRegisterAction: metadata block for key
["+key
- +"] remained empty, delete it");
-
- remove = XUPDATE_HEADER +
- "<xu:remove select=\"" +
-
"/nmwg:store[@type='"+LS_STORE_CONTROL_COLLECTION_TYPE+"']/nmwg:metadata[@id='"
- + key +"']\">\n" +
- "</xu:remove>\n"+
- XUPDATE_FOOTER;
-
- //remove empty metadata
- xmlStorageManager.store(remove);
-
- }
-
- } //remove parameter
-

-
-
- /**
- * Puts parameterValue into LSStore-control schema:
- *
nmwg:store[@type='LSStore-control']
/
- *
nmwg:metadata[@id='key']
/
- * nmwg:parameters /
nmwg:parameter[@name='parameterName']

- *
- */
- protected void setControlParameter(
- String key,
- String parameterName,
- String parameterValue,
- StorageManager xmlStorageManager)
- throws SystemException, RequestException,
DataFormatException {
-
- logger.debug("LSGenericRegisterAction: Set parameter ["+
- parameterName+"] = ["+parameterValue+"]");
-
- //initialize
-
- String query = null;
- int resnum = 0;
-
- //check if there is control metadata for such key
-
- query = "declare namespace
nmwg=\"http://ggf.org/ns/nmwg/base/2.0/\";; " +
-
"data(/nmwg:store[@type='"+LS_STORE_CONTROL_COLLECTION_TYPE+"']/nmwg:metadata[@id='"+key+"']/@id)";
-
- XmlDbResult res = (XmlDbResult)xmlStorageManager.fetch(query);
- resnum = res.getCount();
-
- //if there is no control metadata, put it
- if (resnum==0) {
-
- logger.debug("LSGenericRegisterAction: setParameter: no control
metadata, put metadata+parameters");
-
- String insert = XUPDATE_HEADER +
- "<xu:append
select=\"/nmwg:store[@type='"+LS_STORE_CONTROL_COLLECTION_TYPE+"']\"
child=\"last()\">\n" +
- " <nmwg:metadata id=\""+key+"\">\n" +
- " <nmwg:parameters id=\"control-parameters\">\n" +
- //empty content
- " </nmwg:parameters>\n" +
- " </nmwg:metadata>\n" +
- "</xu:append>\n"+
- XUPDATE_FOOTER;
-
- //put
- xmlStorageManager.store(insert);
-
- } else {
-
- //if there is the metadata, check if it has a parameters block
- query = "declare namespace
nmwg=\"http://ggf.org/ns/nmwg/base/2.0/\";; " +
-
"data(/nmwg:store[@type='"+LS_STORE_CONTROL_COLLECTION_TYPE+"']/nmwg:metadata[@id='"+
- key+"']/nmwg:parameters/@id)";
-
- res = (XmlDbResult)xmlStorageManager.fetch(query);
- resnum = res.getCount();
-
- if (resnum==0) {
-
- logger.debug("LSGenericRegisterAction: setParameter: no
parameters, put parameters");
-
- //put parameters
- String insert = XUPDATE_HEADER +
- "<xu:append
select=\"/nmwg:store[@type='"+LS_STORE_CONTROL_COLLECTION_TYPE+
-
"']/nmwg:metadata[@id='"+
key +"']\" child=\"last()\">\n" +
- " <nmwg:parameters id=\"control-parameters\">\n" +
- //empty content
- " </nmwg:parameters>\n" +
- "</xu:append>\n"+
- XUPDATE_FOOTER;
-
- //put parameters
- xmlStorageManager.store(insert);
- }
-
- }
-
- //check if there is parameter inside metadata
-
- query = "declare namespace
nmwg=\"http://ggf.org/ns/nmwg/base/2.0/\";; " +
-
"/nmwg:store[@type='"+LS_STORE_CONTROL_COLLECTION_TYPE+"']/nmwg:metadata[@id='"+key+
-
"']/nmwg:parameters/nmwg:parameter[@name='"+parameterName+"']";
-
- res = (XmlDbResult)xmlStorageManager.fetch(query);
- resnum = res.getCount();
-
- if (resnum==0) {
-
- //if there is no such parameter, put new one
-
- logger.debug("LSGenericRegisterAction: Set parameter
["+parameterName+
- "] not found, " +
- "insert new parameter ["+key+"]");
-
- String insert = XUPDATE_HEADER +
- "<xu:append select=\"" +
-
"/nmwg:store[@type='"+LS_STORE_CONTROL_COLLECTION_TYPE+"']/nmwg:metadata[@id='"
- +key+
- "']/nmwg:parameters" +
- "\"" +
- " child=\"last()\">\n" +
- " "+
-
- "<nmwg:parameter name=\""+parameterName+"\">" +
- parameterValue+ "</nmwg:parameter>"+
-
- "</xu:append>\n"+
- XUPDATE_FOOTER;
-
- //put (append)
- //logger.debug(insert);
- xmlStorageManager.store(insert);
-
- } else {
-
- //otherwise update it
-
- logger.debug("LSGenericRegisterAction: Set parameter ["
- +parameterName+"] found," +
- "update existing one");
-
- String update = XUPDATE_HEADER +
- "<xu:update select=\"" +
-
"/nmwg:store[@type='"+LS_STORE_CONTROL_COLLECTION_TYPE+"']/nmwg:metadata[@id='"
- +key+
-
"']/nmwg:parameters/nmwg:parameter[@name='"+parameterName+"']\">"
+
-
- parameterValue+
-
- "</xu:update>\n"+
- XUPDATE_FOOTER;
-
- //update
- //logger.debug(update);
- xmlStorageManager.store(update);
-
- }
-
- } //set parameter
-
-
- /**
- * Checks if there is any metadata for given key (in LSStore schema)
- */
- protected boolean checkIfKeyIsRegistered(String key, StorageManager
xmlStorageManager) throws SystemException, RequestException,
DataFormatException {
-
- try {
-
- String query =
- "declare namespace
nmwg=\"http://ggf.org/ns/nmwg/base/2.0/\";; " +
-
"data(/nmwg:store[@type='"+LS_STORE_COLLECTION_TYPE+"']/nmwg:metadata[@id='"+key+"']/@id)";

- XmlDbResult res = (XmlDbResult)xmlStorageManager.fetch(query);
-
- int resnum = res.getCount();
-
- if (resnum>0)
- return true; //key is registered
- else
- return false; //key not registered
-
- } catch (NullPointerException ex) {
- return false;
- }
-
- }
-
-
} //LSGenericRegisterAction

Modified:
trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/LSKeepaliveAction.java
===================================================================
---
trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/LSKeepaliveAction.java
2007-04-23 13:45:10 UTC (rev 2344)
+++
trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/LSKeepaliveAction.java
2007-04-23 14:53:08 UTC (rev 2345)
@@ -4,9 +4,11 @@
import org.ggf.ns.nmwg.base.v2_0.Message;
import org.ggf.ns.nmwg.base.v2_0.Metadata;
import org.perfsonar.service.commons.exceptions.DataFormatException;
+import org.perfsonar.service.commons.exceptions.PerfSONARException;
import org.perfsonar.service.commons.exceptions.RequestException;
import org.perfsonar.service.commons.exceptions.SystemException;
import org.perfsonar.service.commons.storage.StorageManager;
+import org.perfsonar.service.lookupService.xmlType.storage.LookupServiceDAO;

/**
* KEEPALIVE - register/keepalive Action
@@ -24,10 +26,10 @@
// ------------------------------------------------------------
Constructor


- public LSKeepaliveAction(StorageManager xmlStorageManager)
- throws SystemException {
+ public LSKeepaliveAction(LookupServiceDAO dao)
+ throws PerfSONARException {

- super(xmlStorageManager);
+ super(dao);

}

@@ -39,7 +41,7 @@


public Message performAction(Message request)
- throws SystemException, RequestException, DataFormatException {
+ throws PerfSONARException {

logger.debug("LSRegisterAction: LS keepalive action started");
//Get Metadata from Request
@@ -63,12 +65,12 @@
throw new SystemException("error.ls.no_key", m);
}

- if (checkIfKeyIsRegistered(keyValue, xmlStorageManager)) {
+ if (dao.isLookupInfo(keyValue)) {

logger.debug("LSKeepaliveAction: KEEPALIVE - update time");

//key is registered, update time
- updateTime(keyValue, xmlStorageManager);
+ updateTime(keyValue);

} else {
String m="LSKeepaliveAction: Key ["+keyValue+
@@ -83,7 +85,9 @@
response.setType(request.getType());


- ResultCode rc = createResultCode("success.ls.keepalive", "Keepalive
- Time updated");
+ ResultCode rc = createResultCode(
+ "success.ls.keepalive",
+ "Keepalive - Time updated");

Metadata[] responseMetadata = { rc.getMetadata() };
Data[] responseData = null;

Modified:
trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/LSLookupAction.java
===================================================================
---
trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/LSLookupAction.java
2007-04-23 13:45:10 UTC (rev 2344)
+++
trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/LSLookupAction.java
2007-04-23 14:53:08 UTC (rev 2345)
@@ -1,14 +1,13 @@
package org.perfsonar.service.lookupService.xmlType;

-import org.ggf.ns.nmwg.base.v2_0.*;
+import org.ggf.ns.nmwg.base.v2_0.Data;
+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.perfsonar.commons.util.XMLUtils;
-import org.perfsonar.service.commons.exceptions.DataFormatException;
import org.perfsonar.service.commons.exceptions.PerfSONARException;
-import org.perfsonar.service.commons.exceptions.RequestException;
import org.perfsonar.service.commons.exceptions.SystemException;
-import org.perfsonar.service.commons.storage.StorageManager;
-import org.perfsonar.service.commons.storage.xmldb.XmlDbResult;
-import
org.perfsonar.service.commons.storage.xmldb.exist.rest.ExistDbHTTPAccess;
+import org.perfsonar.service.lookupService.xmlType.storage.LookupServiceDAO;

/**
* LOOKUP Action
@@ -41,10 +40,10 @@
// -----------------------------------------------------------
Constructor


- public LSLookupAction(StorageManager xmlStorageManager)
- throws SystemException {
+ public LSLookupAction(LookupServiceDAO dao)
+ throws PerfSONARException {

- super(xmlStorageManager);
+ super(dao);

}

@@ -52,19 +51,18 @@
// --------------------------------------------------------- Public
methods


- public Message performAction(Message request)
- throws SystemException, RequestException, DataFormatException {
+ public Message performAction(Message request) throws PerfSONARException {

logger.debug(
"XmlTypeLSServiceEngine: LS lookup - action LOOKUP started");

//Get metadata from request
- //TODO: change [0] on... ???

Metadata[] mdArray = request.getMetadataArray();

if(mdArray.length != 1){
- String m = "XmlTypeLSServiceEngine: LSLookup currently only
supports single Metadata in requst message";
+ String m = "XmlTypeLSServiceEngine: LSLookup currently only" +
+ " supports single Metadata in requst message";
logger.fatal(m);
throw new SystemException("error.ls.not_supported", m);
}
@@ -135,16 +133,10 @@

//Performing XQuery operation on the database
logger.debug("XmlTypeLSServiceEngine: perform query");
- String[] results;

-
-
/* XQuery */
- XmlDbResult edbres = (XmlDbResult)xmlStorageManager.fetch(query);
- results = (String[])edbres.getResultAsStringArray();
+ String[] results = dao.performXQuery(query);

-
-
logger.debug("XmlTypeLSServiceEngine: Got [["+
results.length+"]] results from DB");


Modified:
trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/LSRegisterAction.java
===================================================================
---
trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/LSRegisterAction.java
2007-04-23 13:45:10 UTC (rev 2344)
+++
trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/LSRegisterAction.java
2007-04-23 14:53:08 UTC (rev 2345)
@@ -1,18 +1,18 @@
package org.perfsonar.service.lookupService.xmlType;

import java.util.Collection;
-import java.util.Iterator;

-import org.ggf.ns.nmwg.base.v2_0.*;
-import org.perfsonar.commons.util.XMLUtils;
-import org.perfsonar.service.commons.exceptions.DataFormatException;
-import org.perfsonar.service.commons.exceptions.RequestException;
+import org.ggf.ns.nmwg.base.v2_0.Data;
+import org.ggf.ns.nmwg.base.v2_0.Key;
+import org.ggf.ns.nmwg.base.v2_0.Message;
+import org.ggf.ns.nmwg.base.v2_0.Metadata;
+import org.perfsonar.service.commons.exceptions.PerfSONARException;
import org.perfsonar.service.commons.exceptions.SystemException;
-import org.perfsonar.service.commons.storage.StorageManager;
+import org.perfsonar.service.lookupService.xmlType.storage.LookupServiceDAO;


/**
- * REGISTER Action
+ * REGISTER and UPDATE Action
*
* @author Maciej Glowiak
*
@@ -33,29 +33,21 @@
// -----------------------------------------------------------
Constructor


- public LSRegisterAction(StorageManager xmlStorageManager)
- throws SystemException {
+ public LSRegisterAction(LookupServiceDAO dao)
+ throws PerfSONARException {

- super(xmlStorageManager);
+ super(dao);

- //read service.ls.lookup_info_timeout
-
String prop = null;
try {
prop = configuration.getProperty("service.ls.allow_replace");
- } catch (SystemException ex) {
- prop=null;
- }
+ } catch (SystemException ex) { prop=null; }
+ if (testIfTrue(prop))
+ allowReplaceIfAlreadyRegistered = true;
+ else
+ allowReplaceIfAlreadyRegistered = false;

- if (prop!=null) {
- if ("yes".equalsIgnoreCase(prop)||"true".equalsIgnoreCase(prop))
- allowReplaceIfAlreadyRegistered = true;
- else
- allowReplaceIfAlreadyRegistered = false;
- } else
- allowReplaceIfAlreadyRegistered = DEFAULT_ALLOW_REPLACE;
-
- logger.debug("LSRegisterAction: service.ls.lookup_info_timeout="+
+ logger.debug("[LS Registration] service.ls.allow_replace="+
allowReplaceIfAlreadyRegistered);
}

@@ -63,20 +55,18 @@
// --------------------------------------------------------- Public
methods


- public Message performAction(Message request)
- throws SystemException, RequestException, DataFormatException {
+ public Message performAction(Message request) throws PerfSONARException {

- logger.debug(
- "LSRegisterAction: LS register - action REGISTER started");
+ logger.debug("[LS Registration] Action started");

//Get Metadata from request

Metadata requestMetadata = getMetadataFromRequest(request);
if (requestMetadata==null) {
- String m="LSRegisterAction: No metadata in request";
+ String m="[LS Registration] No metadata in incoming request";
logger.error(m);
throw new SystemException("error.ls.no_metadata", m);
- }
+ }

//get accessPoint from Metadata - obligatory element
//if it's empty or null SystemException will be thrown
@@ -89,238 +79,139 @@

//Try to get Key from Metadata
String keyValue = getKeyFromMetadata(requestMetadata, LS_KEY);

- if (keyValue != null) keyValue = keyValue.trim(); //TODO: trim is
temporary
+ logger.debug("[LS Registration] Key from metadata=["+keyValue+"]");

- logger.debug("LSRegisterAction: LS key=["+keyValue+"]");
-
-
-
//========check metadata========
+
+ //id of new metadata in the LS. Will be keyValue (update) or just
+ //accessPoint (register)
+ String metadataId = null;

+ boolean doRemove = false;
+ boolean doRemoveOldKey = false;

//check keyValue

if (keyValue == null) { //REGISTER

//let the key value be accesspoint
- logger.debug("LSRegisterAction: key = accessPoint");
+ logger.debug("[LS Registration] Action is Registration (DB Key =
accessPoint)");
+ metadataId = accessPoint; //trimmed

- keyValue = accessPoint;
-
} else { //UPDATE

+ logger.debug("[LS Registration] Action is Update (DB Key =
keyValue)");
+
//always enable register especially if data is registered!
allowReplaceIfAlreadyRegistered = true;
-
+
//but check the key if it's already been in the DB
- if (!checkIfKeyIsRegistered(keyValue, xmlStorageManager)) {
-
- String m = "LSRegisterAction: key from request [" + keyValue
+
- "] not found in the storage. " +
- "Can't UPDATE such data, because can't determine what data
should be updated";
+ if (!dao.isLookupInfo(keyValue)) {
+ String m = "[LS Registration] key from request [" + keyValue
+
+ "] not found in the storage. " +
+ "Can't UPDATE such data, because can't determine what
data should be updated";
logger.debug(m);
- throw new
DataFormatException("error.ls.update.key_not_found", m);
-
+ throw new SystemException ("error.ls.update.key_not_found",
m);
}

+ doRemoveOldKey = true; //remove also old key
+
+ //database key should be key value
+ metadataId = accessPoint;
+
//remove key element from metadata
- requestMetadata.setKey(null);
+ requestMetadata.setKey(null);

- }
-
- // check keyValue again, it may be accessPoint now
- if (keyValue==null) {
- String m = "LSRegisterAction: Cannot register " +
- "Lookup Info without Metadata/accessPoint or Key";
+ } //end if key==null
+
+ // check DB key again, it may be accessPoint now and we're not
+ // sure whether it's not empty. Are we?
+ if ("".equals(metadataId)) {
+ String m = "[LS Registration] Cannot register Lookup Info " +
+ "without or with empty metadata Id (check Key or " +
+ "accessPoint values)";
logger.error(m);
throw new SystemException("error.ls.no_key", m);
}


//========check data========
-
-
- //Get all Data elements, suppose they all belong to metadata
- //(data map is created in the constructor of Message, so Null Ptr
Exc
- //won't be thrown!)
- Collection reqDataArr = request.getDataMap().values();
-
- //if there is no data! -- to be discussed
- //there should be at least ONE trigger -- to be discussed
- if (reqDataArr.size() < 1) {
- String m = "LSRegisterAction: " +
- "Request must have at least one data element - trigger)
";
- logger.error(m);
- throw new SystemException("error.ls.no_data_trigger", m);
- }
-
+
+ Data[] dataElements = getDataElements(request);

//=========process with register/update===========

-
- String removeUpdate = null;
-
//check if there is metadata with the same key:
//if so, check if you're allowed to update data (to remove them)
//throw exception if you're not allowed
- if (checkIfKeyIsRegistered(keyValue,xmlStorageManager)) {
+ if (dao.isLookupInfo(metadataId)) {

- logger.debug("LSRegisterAction: Key is already " +
- "registered in DB (metadata), allow_update="+
- allowReplaceIfAlreadyRegistered);
+ logger.debug("[LS Registration] Such Lookup Info ("+metadataId+"
is already " +
+ "registered in DB. Allow_update is"+
allowReplaceIfAlreadyRegistered);

if (allowReplaceIfAlreadyRegistered) {

- logger.debug("LSRegisterAction: old data will be replaced by
new set of data");
+ logger.debug("[LS Registration] old data will be replaced by
new set of data");
+ doRemove = true;

- removeUpdate =
- "<xu:remove
select=\"/nmwg:store[@type='"+LS_STORE_COLLECTION_TYPE+"']/nmwg:metadata[@id='"
- +keyValue+"']\" />\n" +
- "<xu:remove
select=\"/nmwg:store[@type='"+LS_STORE_COLLECTION_TYPE+"']/nmwg:data[@metadataIdRef='"
- +keyValue+"']\" />\n";
-
- //if update key, keyvalue contains old key, accessPoint new
one
- //but we must delete also old control information

- if (!keyValue.equals(accessPoint)) {
- logger.debug("LSRegisterAction: remove control
information for old key (DB key was changed)");
- removeUpdate=removeUpdate+
- "<xu:remove
select=\"/nmwg:store[@type='"+LS_STORE_CONTROL_COLLECTION_TYPE+"']/nmwg:metadata[@id='"
- +keyValue+"']\" />\n";
- }
-
} else {

- String m = "LSRegisterAction: Can't replace data";
+ String m = "[LS Registration] Can't replace data";
logger.error(m);
- //TODO: what to do? Remove everything?
throw new SystemException("error.ls.cant_replace_data", m);

}

- }
+ } //if dao...

//change metadata id
- requestMetadata.setId(accessPoint);
+ requestMetadata.setId(metadataId);

- //Prepare XUpdate for Metadata
- String updateMeta = "<xu:append
select=\"/nmwg:store[@type='"+LS_STORE_COLLECTION_TYPE+"']\"
child=\"last()\">\n" +
- XMLUtils.serializeXML(requestMetadata) +
- "\n</xu:append>\n";
-
-
- //Prepare XUpdate data
+ //enumerate all data elements
+ for (int i=0; i< dataElements.length; i++) {

-
- //create array for data xupdate
- String updateData[] = new String[reqDataArr.size()];
-
- //for each datas
- long currTime = System.currentTimeMillis();
- int datanum = 0;
-
- Iterator reqDataArrIterator = reqDataArr.iterator();
-
- while (reqDataArrIterator.hasNext()) {
-
- Data requestData = (Data)reqDataArrIterator.next();
-
-// //TODO: what to check?
-// if (requestData==null) {
-// String m = "XmlTypeLSServiceEngine: Cannot register " +
-// "Lookup Info without Data";
-// logger.error(m);
-// throw new SystemException(m);
-// }
-
+ Data d = dataElements[i];
//change data references
-
- requestData.setId(accessPoint+"/"+currTime+"/"+datanum);
- requestData.setMetadataIdRef(accessPoint);
-
- //Prepare XUpdate for Data
- //fill updateData structure
+ d.setId(accessPoint+/*"/"+currTime+*/"/"+i);
+ d.setMetadataIdRef(accessPoint);

- updateData[datanum] =
- "<xu:append
select=\"/nmwg:store[@type='"+
- LS_STORE_COLLECTION_TYPE+"']\" child=\"last()\">\n" +
- XMLUtils.serializeXML(requestData) +
- "\n</xu:append>\n";
-
- datanum++;
-
}
-
- //if no errors and exceptions reported/thrown, put metadata and
data into DB
-

- StringBuffer update=new StringBuffer(XUPDATE_HEADER);
-
- //remove old data (if necessary)
- if (removeUpdate!=null) {
- update.append(removeUpdate);
+ //remove old lookup information if there is any
+ if (doRemove) {
+ logger.info("[LS Registration] Remove old Lookup Info
("+metadataId+")");
+ dao.removeLookupInfo(metadataId);
}

- //put metadata
- update.append(updateMeta);
-
- logger.debug("LSRegisterAction: "+
- ((removeUpdate!=null)?
- "remove old entries"
- :
- "") + ", insert metadata and ["
- + updateData.length+"] data elements");
-
- for (int i=0; i<updateData.length; i++) {
- update.append(updateData[i]);
+ //remove old Lookup Info as well - if update and
+ //there is lookup info with different key
+ if (doRemoveOldKey && (!keyValue.equals(metadataId))) {
+ logger.info("[LS Registration] Remove old Lookup Info
("+keyValue+")");
+ dao.removeLookupInfo(keyValue);
}
- update.append(XUPDATE_FOOTER);
-
- //XUpdate
- xmlStorageManager.store(update.toString());

+ //register new lookup info
+ dao.putLookupInfo(requestMetadata, dataElements);
+ logger.info("[LS Registration] Put new Lookup Info ("+
+ metadataId+") metadata + "+dataElements.length+" data
elements");

//update control time - last modification
- updateTime(accessPoint /*keyValue*/, xmlStorageManager); //TODO:
change xmlStorageManager to LSstorage-control
-
- //return Key
- // xpath:////nmwg:metadata/nmwg:key/
- //
nmwg:parameters:/nmwg:parameter[@id="lsKey"]
-
- ResultCode rc = createResultCode("success.ls.register",
- "Data has been registered with key ["+keyValue+"]");
-
- rc.getMetadata().setKey( createLSKey(keyValue) );
- Metadata[] responseMetadata = { rc.getMetadata() };
-
- Data[] responseData = null;
- if (rc.getData() !=null) {
- responseData = new Data[1];
- responseData[0] = rc.getData();
- }
-
- Message response = new Message();
-
- //XXX: Again, what type is appropriate?
- response.setType("LSRegisterResponse");
+ updateTime(metadataId);

- response.addChild(responseData[0]);
- for(int j=0; j<responseMetadata.length; j++){
- response.addChild(responseMetadata[j]);
- }
+ //get response with success code and key
+ return getLSRegisterResponse(metadataId);

- return response;
+ } //end performAction

- }

-
/**
* Returns serviceType from metadata or throws SystemException if null
or empty
* @param requestMetadata
* @return service type
* @throws SystemException if null or empty
*/
- protected String getServiceType(Metadata requestMetadata) throws
SystemException {
- //service type
+ protected String getServiceType(Metadata requestMetadata) throws
PerfSONARException {
+
String serviceType = null;
try {
serviceType = ((org.ggf.ns.nmwg.tools.org.perfsonar.v1_0.Subject)
@@ -328,7 +219,7 @@
getServiceType().getServiceType().trim();
if (serviceType.equals("")) throw new RuntimeException("empty");
} catch (RuntimeException e) {
- String m="LSRegisteraction: No serviceType in request -
"+e.getMessage();
+ String m="[LS Registration] No serviceType in request -
"+e.getMessage();
logger.error(m);
throw new SystemException("error.ls.no_service_type", m);

}
@@ -342,8 +233,8 @@
* @return service Name
* @throws SystemException if null or empty
*/
- protected String getServiceName(Metadata requestMetadata) throws
SystemException {
-// service name
+ protected String getServiceName(Metadata requestMetadata) throws
PerfSONARException {
+
String serviceName = null;
try {
serviceName = ((org.ggf.ns.nmwg.tools.org.perfsonar.v1_0.Subject)
@@ -351,7 +242,7 @@
getServiceName().getServiceName().trim();
if (serviceName.equals("")) throw new RuntimeException("empty");
} catch (RuntimeException e) {
- String m="LSRegisteraction: No serviceName in request -
"+e.getMessage();
+ String m="[LS Registration] No serviceName in request -
"+e.getMessage();
logger.error(m);
throw new SystemException("error.ls.no_service_name", m);

}
@@ -366,7 +257,7 @@
* @throws SystemException if null or empty
*/
protected String getAccessPoint(Metadata requestMetadata)
- throws SystemException {
+ throws PerfSONARException {
String accessPoint = null;
try {

@@ -377,7 +268,7 @@
if (accessPoint.equals("")) throw new RuntimeException("empty");

} catch (RuntimeException e) {
- String m="LSRegisteraction: No access_point in request -
"+e.getMessage();
+ String m="[LS Registration] No access_point in request -
"+e.getMessage();
logger.error(m);
throw new SystemException("error.ls.no_access_point", m);

}
@@ -385,9 +276,76 @@
return accessPoint;

}
+
+ /**
+ * Return data elements as Data[] from given Message
+ * @param request
+ * @return
+ * @throws PerfSONARException
+ */
+ protected Data[] getDataElements(Message request) throws
PerfSONARException {
+ try {
+ //Get all Data elements, suppose they all belong to metadata
+ //(data map is created in the constructor of Message, so
+ //NullPointerException won't be thrown!)
+ Collection<Data> reqDataArr = request.getDataMap().values();
+
+ //if there is no data! -- to be discussed
+ //there should be at least ONE trigger -- to be discussed
+ if (reqDataArr.size() < 1) {
+ String m = "[LS Registration] " +
+ "Request must have at least one data element -
trigger) ";
+ logger.error(m);
+ throw new SystemException("error.ls.no_data_trigger", m);
+ }
+
+ //convert dataArr to Data[]
+ Data[] dataElements = (Data[])
+ reqDataArr.toArray(new
Data[reqDataArr.size()]);
+
+ return dataElements;
+
+ } catch (RuntimeException ex) {
+ throw new SystemException("error.ls.no_data_trigger",
+ "error during converting data elements:
"+ex.getMessage());
+ }
+ }
+
+
+ /**
+ * Returns Message with response containing result code (success) and key
+ * value
+ * @param keyValue
+ * @return
+ */
+ protected Message getLSRegisterResponse(String keyValue) {
+ //return Key
+ // xpath:////nmwg:metadata/nmwg:key/
+ //
nmwg:parameters:/nmwg:parameter[@id="lsKey"]
+
+ ResultCode rc = createResultCode("success.ls.register",
+ "Data has been registered with key ["+keyValue+"]");
+
+ rc.getMetadata().setKey( createLSKey(keyValue) );
+ Metadata[] responseMetadata = { rc.getMetadata() };
+
+ Data[] responseData = null;
+ if (rc.getData() !=null) {
+ responseData = new Data[1];
+ responseData[0] = rc.getData();
+ }
+
+ Message response = new Message();

+ //doesn't really matter, it is changed by MessageHandler.
+ response.setType("LSRegisterResponse");

- // -------------------------------------------------------- Private
methods
+ response.addChild(responseData[0]);
+ for(int j=0; j<responseMetadata.length; j++){
+ response.addChild(responseMetadata[j]);
+ }
+ return response;
+ }


/**
@@ -396,7 +354,7 @@
* @param keyValue
* @return Key element
*/
- private org.ggf.ns.nmwg.base.v2_0.Key createLSKey(String keyValue) {
+ private Key createLSKey(String keyValue) {

org.ggf.ns.nmwg.base.v2_0.Key key =
new org.ggf.ns.nmwg.base.v2_0.Key();

Modified:
trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/XmlTypeLSServiceEngine.java
===================================================================
---
trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/XmlTypeLSServiceEngine.java
2007-04-23 13:45:10 UTC (rev 2344)
+++
trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/XmlTypeLSServiceEngine.java
2007-04-23 14:53:08 UTC (rev 2345)
@@ -15,11 +15,9 @@
import org.perfsonar.service.commons.exceptions.PerfSONARException;
import org.perfsonar.service.commons.exceptions.RequestException;
import org.perfsonar.service.commons.exceptions.SystemException;
-import org.perfsonar.service.commons.storage.xmldb.XmlDbDataRepository;
-import org.perfsonar.service.commons.storage.xmldb.XmlDbStorageManager;
-import org.perfsonar.service.commons.storage.xmldb.exist.ExistDbFactory;
-import org.perfsonar.service.commons.storage.xmldb.XmlDbConstants;
-import org.perfsonar.service.commons.util.ResultCodesUtil;
+import org.perfsonar.service.lookupService.xmlType.storage.DataCredential;
+import org.perfsonar.service.lookupService.xmlType.storage.LookupServiceDAO;
+import
org.perfsonar.service.lookupService.xmlType.storage.LookupServiceDAOFactory;

/**
* ServiceEngine class for LookupService. (The heart of the LookupService)
@@ -68,11 +66,13 @@
*/
private ConfigurationComponent config;

+
/**
- * Storage Manager Type
+ * Data Access Object for LS
*/
- private String smType;
+ private LookupServiceDAO dao;

+
/**
* Construction for the service engine
*/
@@ -88,6 +88,11 @@
config = (ConfigurationComponent)AuxiliaryComponentManager.
getInstance().getComponent(ComponentNames.CONFIG);

+ try {
+ dao = LookupServiceDAOFactory.getDAO();
+ } catch (PerfSONARException e) {
+ throw new SystemException(e.getResultCode(),
e.getResultDescription());
+ }

this.serviceEngineType = SERVICE_ENGINE_TYPE;

@@ -97,11 +102,10 @@
ActionType.LS_LOOKUP,
ActionType.LS_DEREGISTER,
ActionType.LS_KEEPALIVE,
+ ActionType.LS_CLEANUP,
ActionType.ECHO
};

- smType = config.getProperty("service.ls.db_type");
-
} //constructor


@@ -109,7 +113,6 @@
// --------------------------------------------------------- public
methods


-
/**
* Method which provides access the type of ServiceEngine.
* It implements the method definition in ServiceEngine Interface
@@ -176,41 +179,38 @@

// ------------ serving actions
---------------------------------------

+
+ try { //TODO: temporary try - perfsonar exception
+
//Take an action
if (actionType.equals(ActionType.LS_REGISTER)) {
-
- XmlDbStorageManager xmlDbStorageManager =
- getStorageManager(smType);
-
- LSAction action = new LSRegisterAction(xmlDbStorageManager);
+
+ LSAction action = new LSRegisterAction(dao);
response = action.performAction(request);

} else if (actionType.equals(ActionType.LS_LOOKUP)) {
-
- XmlDbStorageManager xmlDbStorageManager =
- getStorageManager(smType);
- LSAction action = new LSLookupAction(xmlDbStorageManager);
+
+ LSAction action = new LSLookupAction(dao);
response = action.performAction(request);

} else if (actionType.equals(ActionType.LS_DEREGISTER)) {
-
- XmlDbStorageManager xmlDbStorageManager =
- getStorageManager(smType);
- LSAction action = new LSDeregisterAction(xmlDbStorageManager);
+
+ LSAction action = new LSDeregisterAction(dao);
response = action.performAction(request);

} else if (actionType.equals(ActionType.LS_KEEPALIVE)) {
-
- XmlDbStorageManager xmlDbStorageManager =
- getStorageManager(smType);
- LSAction action = new LSKeepaliveAction(xmlDbStorageManager);
+
+ LSAction action = new LSKeepaliveAction(dao);
response = action.performAction(request);

+ } else if (actionType.equals(ActionType.LS_CLEANUP)) {
+
+ LSAction action = new LSCleanup(dao);
+ response = action.performAction(request);
+
} else if (actionType.equals(ActionType.ECHO)) {

- XmlDbStorageManager xmlDbStorageManager =
- getStorageManager(smType);
- LSAction action = new EchoRequestAction(xmlDbStorageManager);

+ LSAction action = new EchoRequestAction(dao);
response = action.performAction(request);

} else {
@@ -231,34 +231,10 @@
//Return Response Message

return response;
-
- } //takeAction
-

+ } catch (PerfSONARException p) { throw new
SystemException(p.getResultCode(), p.getResultDescription()); } //temporary

- protected static XmlDbStorageManager getStorageManager(String type)
- throws SystemException {
-
- XmlDbDataRepository dataRepository =
- ExistDbFactory.getDataRepositoryByProperties(
- type,
- "service.ls.db_uri",
- "service.ls.db_username",
- "service.ls.db_password");
-
- XmlDbStorageManager storageManager =
- ExistDbFactory.getXMLStorageManager(
- type, dataRepository);
- storageManager.setResultType(
- XmlDbStorageManager.XML_DB_RESULT_TYPE);
+ } //takeAction

-
- return storageManager;
-
- }

-
-
-
-
} //XmlTypeLSServiceEngine

Added:
trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/storage/DataCredential.java


Property changes on:
trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/storage/DataCredential.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native

Added:
trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/storage/LookupServiceDAO.java


Property changes on:
trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/storage/LookupServiceDAO.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native

Added:
trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/storage/LookupServiceDAOFactory.java


Property changes on:
trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/storage/LookupServiceDAOFactory.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native

Added:
trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/storage/Test2.java


Property changes on:
trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/storage/Test2.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native

Added:
trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/storage/XMLDataStorage.java


Property changes on:
trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/storage/XMLDataStorage.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native

Added:
trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/storage/exist/ExistHTTPDataStorage.java


Property changes on:
trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/storage/exist/ExistHTTPDataStorage.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native

Added:
trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/storage/exist/XQueryExistDAOImpl.java


Property changes on:
trunk/perfsonar/src/org/perfsonar/service/lookupService/xmlType/storage/exist/XQueryExistDAOImpl.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native



  • perfsonar: r2345 - in trunk/perfsonar/src/org/perfsonar/service: commons/engine commons/registration commons/storage/xmldb/exist/rest lookupService/xmlType lookupService/xmlType/storage lookupService/xmlType/storage/exist, svnlog, 04/23/2007

Archive powered by MHonArc 2.6.16.

Top of Page