Skip to Content.
Sympa Menu

perfsonar-dev - perfsonar: r5323 - in branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/storage: . exist

Subject: perfsonar development work

List archive

perfsonar: r5323 - in branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/storage: . exist


Chronological Thread 
  • From:
  • To:
  • Subject: perfsonar: r5323 - in branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/storage: . exist
  • Date: Thu, 22 Oct 2009 07:57:30 -0400

Author: trzaszcz
Date: 2009-10-22 07:57:29 -0400 (Thu, 22 Oct 2009)
New Revision: 5323

Added:

branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/storage/XQueryDAOSupport.java

branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/storage/exist/XQueryDAOSupportImpl.java
Modified:

branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/storage/LookupServiceDAO.java

branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/storage/SummarizationDAO.java

branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/storage/exist/CommonExistDAOImpl.java

branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/storage/exist/XQueryExistDAOImpl.java
Log:
refactorization

Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/storage/LookupServiceDAO.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/storage/LookupServiceDAO.java
2009-10-22 11:08:20 UTC (rev 5322)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/storage/LookupServiceDAO.java
2009-10-22 11:57:29 UTC (rev 5323)
@@ -2,11 +2,10 @@

import org.perfsonar.base2.service.exceptions.PerfSONARException;
import org.perfsonar.base2.service.storage.xml.DataCredential;
-import org.perfsonar.base2.service.storage.xml.XMLDBResult;
import org.perfsonar.base2.xml.nmwg.Data;
import org.perfsonar.base2.xml.nmwg.Metadata;

-public interface LookupServiceDAO {
+public interface LookupServiceDAO extends XQueryDAOSupport{



@@ -21,19 +20,6 @@
*/
public static final String LS_STORE_CONTROL_COLLECTION_TYPE =
"LSStore-control";

- public final static String DECLARE_NMWG_NAMESPACE =
- "declare namespace nmwg='http://ggf.org/ns/nmwg/base/2.0/'; \n";
-
- /**
- * Namespaces declaration for perfSONAR
- */
- public final static String XQUERY_DECLARE_NAMESPACES =
- "declare namespace
perfsonar='http://ggf.org/ns/nmwg/tools/org/perfsonar/1.0/'; \n"+
- DECLARE_NMWG_NAMESPACE +
- "declare namespace
psservice='http://ggf.org/ns/nmwg/tools/org/perfsonar/service/1.0/'; \n"+
- "declare namespace nmwgt='http://ggf.org/ns/nmwg/topology/2.0/';
\n"+
- "declare namespace
netutil='http://ggf.org/ns/nmwg/characteristic/utilization/2.0/'; \n\n";
-
// --------------------------------------------------------- Public
methods

/**
@@ -75,28 +61,6 @@
public void setControlParameter(String metadataId, String parameter,
String value) throws PerfSONARException;

/**
- * Perform XQuery operation
- * @param xquery
- * @return
- * @throws PerfSONARException
- */
- public XMLDBResult performXQuery(String xquery) throws
PerfSONARException;
-
- /**
- * Sets internal DAO parameter (may be used for specific configuration)
- * @param param
- * @param value
- */
- public void setDAOParameter(String param, String value);
-
- /**
- * Gets internal DAO parameter (may be used for specific configuration)
- * @param param
- * @return
- */
- public String getDAOParameter(String param);
-
- /**
* Sets username and password
* @param dc
*/

Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/storage/SummarizationDAO.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/storage/SummarizationDAO.java
2009-10-22 11:08:20 UTC (rev 5322)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/storage/SummarizationDAO.java
2009-10-22 11:57:29 UTC (rev 5323)
@@ -13,7 +13,7 @@
* @author trzaszcz
*
*/
-public interface SummarizationDAO extends LookupServiceDAO {
+public interface SummarizationDAO{

/**
*

Added:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/storage/XQueryDAOSupport.java

Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/storage/exist/CommonExistDAOImpl.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/storage/exist/CommonExistDAOImpl.java
2009-10-22 11:08:20 UTC (rev 5322)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/storage/exist/CommonExistDAOImpl.java
2009-10-22 11:57:29 UTC (rev 5323)
@@ -1,202 +1,94 @@
package org.perfsonar.service.lookupservice.storage.exist;

-import java.util.HashMap;
-
import org.apache.log4j.Logger;
import org.perfsonar.base2.service.configuration.Component;
import org.perfsonar.base2.service.configuration.ConfigurationManager;
import org.perfsonar.base2.service.exceptions.PerfSONARException;
import org.perfsonar.base2.service.storage.xml.DataCredential;
import org.perfsonar.base2.service.storage.xml.XMLDBComponent;
-import org.perfsonar.base2.service.storage.xml.XMLDBResult;
import org.perfsonar.base2.service.storage.xml.XMLDataStorage;
import org.perfsonar.base2.service.storage.xml.exist.ExistHTTPDataStorage;
-import org.perfsonar.base2.xml.Element;
import org.perfsonar.service.lookupservice.LSRegisterServiceEngine;
-import org.perfsonar.service.lookupservice.storage.LookupServiceDAO;
+
/**
- * Abstract implementation of LookupServiceDAO
- * Implements all generic functions of DAO. Mostly contains
- * XQuery functionality for getting information from Exist DB XML.
+ * Abstract implementation of LookupServiceDAO Implements all generic
functions
+ * of DAO. Mostly contains XQuery functionality for getting information from
+ * Exist DB XML.
*
* Data modification functionality will be implemented in other sub-classes
*
* @author Maciej Glowiak
- *
+ *
*/
-public abstract class CommonExistDAOImpl extends Component implements
LookupServiceDAO {
+public abstract class CommonExistDAOImpl extends Component {

- protected static final Logger logger =
Logger.getLogger(LSRegisterServiceEngine.class.getName());
-
- private XMLDataStorage dataStorage;
- private String dataCollection;
- private DataCredential dataCredential;
- private HashMap<String,String> parameters;
+ protected static final Logger logger = Logger
+ .getLogger(LSRegisterServiceEngine.class.getName());

- public CommonExistDAOImpl() {
- super();
- dataStorage = new ExistHTTPDataStorage();
- parameters = new HashMap<String,String>();
- }
+ private XMLDataStorage dataStorage;
+ private String dataCollection;
+ private DataCredential dataCredential;

- /**
- * Returns pair of numbers separated by space: "#M #D" where #M is number
- * of metadata blocks with specific metadataId, #D is number of related
- * data blocks (metadataIdRef=metadataId)
- * @param metadataId
- * @return
- * @throws PerfSONARException
- */
- public String countLookupInfo(String metadataId) throws
PerfSONARException {
-
- String xquery =
- DECLARE_NMWG_NAMESPACE +
- "concat(" +
-
"count(/nmwg:store[@type='"+
-
LS_STORE_COLLECTION_TYPE+"']/nmwg:metadata[@id='"+metadataId+"']),
" +
- "' ', " +
-
"count(/nmwg:store[@type='"+
-
LS_STORE_COLLECTION_TYPE+"']/nmwg:data[@metadataIdRef='"+metadataId+"']))";
-
- //remove by xquery
- XMLDBResult res = dataStorage.performXQuery(xquery, dataCollection,
dataCredential);
-
- //return "M D" where M is count(metadata), D is count(data)
- return res.getFirstElement().getText();
-
- }
+ public final static String DECLARE_NMWG_NAMESPACE = "declare
namespace nmwg='http://ggf.org/ns/nmwg/base/2.0/'; \n";

- public boolean isLookupInfo(String metadataId) throws PerfSONARException
{
-
- String result = countLookupInfo(metadataId);
- return !("0 0".equals(result));
-
- }
+ /**
+ * Namespaces declaration for perfSONAR
+ */
+ public final static String XQUERY_DECLARE_NAMESPACES = "declare
namespace perfsonar='http://ggf.org/ns/nmwg/tools/org/perfsonar/1.0/'; \n"
+ + DECLARE_NMWG_NAMESPACE
+ + "declare namespace
psservice='http://ggf.org/ns/nmwg/tools/org/perfsonar/service/1.0/'; \n"
+ + "declare namespace
nmwgt='http://ggf.org/ns/nmwg/topology/2.0/'; \n"
+ + "declare namespace
netutil='http://ggf.org/ns/nmwg/characteristic/utilization/2.0/'; \n\n";

- /**
- * Returns control parameter, if not present, null value will be
returned.
- */
- public String getControlParameter(String metadataId, String parameter)
throws PerfSONARException {
-
- String xquery =
- DECLARE_NMWG_NAMESPACE +
-
-
"data(/nmwg:store[@type='"+
- LS_STORE_CONTROL_COLLECTION_TYPE+
-
"']/nmwg:metadata[@id='"+
- metadataId+
-
"']/nmwg:parameters/nmwg:parameter[@name='"+parameter+"']/@value)";
-
- //remove by xquery
- XMLDBResult res = dataStorage.performXQuery(xquery, dataCollection,
dataCredential);
-
- Element result = null;
- result=res.getFirstElement();
+ public CommonExistDAOImpl() {
+ super();
+ dataStorage = new ExistHTTPDataStorage();
+ }

- //if not present null will be returned
- if (result==null) return null;
- if (result.getText()==null) return null;
+ public void init() throws PerfSONARException {
+ try {
+ String existConfigComponent =
getOption("exist-config").getValue();
+ XMLDBComponent xmlDbComponent = (XMLDBComponent)
ConfigurationManager
+
.getInstance().getConfiguration().getAuxiliaryComponent(
+ existConfigComponent);

- //else return value
- return result.getText();
-
- }
+ setDataCollection(xmlDbComponent.getUri());
+ setDataCredential(xmlDbComponent.getCredential());
+ } catch (Exception ex) {
+ throw new PerfSONARException(
+ "error/xmldb",
+ "LS Exist DAO cannot load settings.
exist-config configuration block is missing or wrong setting");
+ }

- public XMLDBResult performXQuery(String xquery) throws
PerfSONARException {
-
- XMLDBResult res = dataStorage.performXQuery(xquery, dataCollection,
dataCredential);
-
- return res;
-
- }
+ }

- public void setDAOParameter(String param, String value) {
- parameters.put(param, value);
- }
+ public void destroy() throws PerfSONARException {
+
+ }

- public String getDAOParameter(String param) {
- return (String) parameters.get(param);
- }
+ public void run() {
+ // do nothing
+ }

- public void setDataCredential(DataCredential dc) {
-
- this.dataCredential = dc;
-
- }
+ public void setDataCredential(DataCredential dc) {
+ this.dataCredential = dc;
+ }

- public void setDataCollection(String dc) {
- this.dataCollection = dc;
-
- }
+ public void setDataCollection(String dc) {
+ this.dataCollection = dc;

- public boolean isDBCollection(String collection) throws
PerfSONARException {
-
- String xquery =
- DECLARE_NMWG_NAMESPACE +
- "
count(/nmwg:store[@type='"+collection+"'])";
- XMLDBResult res = dataStorage.performXQuery(
- xquery, dataCollection, dataCredential);
- int result = res.getTotal();
- return (result>0);
- }
+ }

- public boolean isDBConnectivity() throws PerfSONARException {
-
- String xquery = "fn:current-dateTime()";
- dataStorage.performXQuery(xquery, dataCollection, dataCredential);
- return true;
-
- }
+ protected String getDataCollection() {
+ return dataCollection;
+ }

- // ------------------------------------------------------ protected
methods
-
- protected String getDataCollection() {
- return dataCollection;
- }
+ protected DataCredential getDataCredential() {
+ return dataCredential;
+ }

- protected DataCredential getDataCredential() {
- return dataCredential;
- }
+ protected XMLDataStorage getDataStorage() {
+ return dataStorage;
+ }

- protected XMLDataStorage getDataStorage() {
- return dataStorage;
- }
-
- protected HashMap<String, String> getParameters() {
- return parameters;
- }
-
- // --------------------------------------------------------- from
Component
-
- public void init() throws PerfSONARException {
- try {
- String existConfigComponent =
getOption("exist-config").getValue();
- XMLDBComponent xmlDbComponent =
- (XMLDBComponent)
ConfigurationManager.getInstance().getConfiguration().
- getAuxiliaryComponent(existConfigComponent);
-
- setDataCollection(xmlDbComponent.getUri());
- setDataCredential(xmlDbComponent.getCredential());
- } catch (Exception ex) {
- throw new PerfSONARException("error/xmldb",
- "LS Exist DAO cannot load settings. exist-config
configuration block is missing or wrong setting");
- }
-
- }
-
-
- public void destroy() throws PerfSONARException {
-
- dataStorage = null;
- dataCollection = null;
- dataCredential = null;
- parameters.clear();
- parameters = null;
- }
-
- public void run(){
- //do nothing
- }
-
-
}
\ No newline at end of file

Added:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/storage/exist/XQueryDAOSupportImpl.java

Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/storage/exist/XQueryExistDAOImpl.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/storage/exist/XQueryExistDAOImpl.java
2009-10-22 11:08:20 UTC (rev 5322)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/storage/exist/XQueryExistDAOImpl.java
2009-10-22 11:57:29 UTC (rev 5323)
@@ -6,6 +6,7 @@
import org.perfsonar.base2.xml.StringBufferOutputStream;
import org.perfsonar.base2.xml.nmwg.Data;
import org.perfsonar.base2.xml.nmwg.Metadata;
+import org.perfsonar.service.lookupservice.storage.LookupServiceDAO;

/**
* Implementation of LookupServiceDAO: eXist HTTP connection using XQuery for
@@ -15,7 +16,7 @@
* @author Maciej Glowiak
*
*/
-public class XQueryExistDAOImpl extends CommonExistDAOImpl {
+public class XQueryExistDAOImpl extends XQueryDAOSupportImpl implements
LookupServiceDAO {

//
---------------------------------------------------------------constants

@@ -30,18 +31,7 @@
protected static final String UPDATE_LSSTORE = "
/nmwg:store[@type='"
+ LS_STORE_COLLECTION_TYPE + "'] ";

- // protected static final String UPDATE_LSSTORE_SUMMARY =
- //
"/nmwg:store[@type='"
- // + LS_STORE_SUMMARY_COLLECTION_TYPE + "']";

- // ------------------------------------------------------instance
variables
-
- public XQueryExistDAOImpl() {
- super();
- }
-
- // --------------------------------------------------------- Public
methods
-
@Override
public void putLookupInfo(Metadata m, Data[] d) throws
PerfSONARException {

@@ -101,17 +91,16 @@
xmls.append(UPDATE_LSSTORE);

String query = xmls.toString();
- getDataStorage().performXQuery(query, getDataCollection(),
- getDataCredential());
+ performXQuery(query);
}
+
@Override
public int removeLookupInfo(String metadataId) throws
PerfSONARException {

String xquery = XQUERY_DECLARE_NAMESPACES + UPDATE_FOR
+ getRemoveLookupInfoXQueryPart(metadataId) +
UPDATE_REMOVE;
// remove by xquery
- XMLDBResult res = getDataStorage().performXQuery(xquery,
- getDataCollection(), getDataCredential());
+ XMLDBResult res = performXQuery(xquery);
logger.debug("REMOVE LOOKUP QUERY:\n" + xquery);
logger.debug("REMOVE LOOKUP RESULT:\n" + res);
if (res != null)
@@ -120,6 +109,7 @@
return -1; // if error

}
+
@Override
public int cleanupLookupInfo(long timestamp, long defaultInterval)
throws PerfSONARException {
@@ -159,12 +149,11 @@

// System.out.println("---\n"+xquery+"\n---\n");

- XMLDBResult res = getDataStorage().performXQuery(xquery,
- getDataCollection(), getDataCredential());
+ XMLDBResult res = performXQuery(xquery);

return res.getTextResults().length;
}
-
+
@Override
public void setControlParameter(String metadataId, String parameter,
String value) throws PerfSONARException {
@@ -209,11 +198,10 @@
"return $command \n";

// put
- getDataStorage().performXQuery(xquery, getDataCollection(),
- getDataCredential());
+ performXQuery(xquery);

} // set parameter
-
+
protected String getRemoveLookupInfoXQueryPart(String metadataId) {
return
// a set of ()
@@ -232,4 +220,54 @@

"/nmwg:store[@type='"
+ LS_STORE_COLLECTION_TYPE
+
"']/nmwg:data[@metadataIdRef='"
+ metadataId + "']" + ")";
}
+
+ /**
+ * Returns pair of numbers separated by space: "#M #D" where #M is
number of
+ * metadata blocks with specific metadataId, #D is number of related
data
+ * blocks (metadataIdRef=metadataId)
+ *
+ * @param metadataId
+ * @return
+ * @throws PerfSONARException
+ */
+ public String countLookupInfo(String metadataId) throws
PerfSONARException {
+
+ String xquery = DECLARE_NMWG_NAMESPACE + "concat("
+ +
"count(/nmwg:store[@type='"
+ LS_STORE_COLLECTION_TYPE
+ +
"']/nmwg:metadata[@id='"
+ metadataId + "']), " + "' ', "
+ +
"count(/nmwg:store[@type='"
+ LS_STORE_COLLECTION_TYPE
+ +
"']/nmwg:data[@metadataIdRef='"
+ metadataId + "']))";
+
+ // remove by xquery
+ XMLDBResult res = performXQuery(xquery);
+
+ // return "M D" where M is count(metadata), D is count(data)
+ return res.getFirstElement().getText();
+
+ }
+
+ public boolean isLookupInfo(String metadataId) throws
PerfSONARException {
+
+ String result = countLookupInfo(metadataId);
+ return !("0 0".equals(result));
+
+ }
+
+ public boolean isDBCollection(String collection) throws
PerfSONARException {
+
+ String xquery = DECLARE_NMWG_NAMESPACE + "
count(/nmwg:store[@type='"
+ + collection + "'])";
+ XMLDBResult res = performXQuery(xquery);
+ int result = res.getTotal();
+ return (result > 0);
+ }
+
+ public boolean isDBConnectivity() throws PerfSONARException {
+
+ String xquery = "fn:current-dateTime()";
+ performXQuery(xquery);
+ return true;
+
+ }
+
}



  • perfsonar: r5323 - in branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/storage: . exist, svnlog, 10/22/2009

Archive powered by MHonArc 2.6.16.

Top of Page