Skip to Content.
Sympa Menu

perfsonar-dev - perfsonar: r5021 - branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice

Subject: perfsonar development work

List archive

perfsonar: r5021 - branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice


Chronological Thread 
  • From:
  • To:
  • Subject: perfsonar: r5021 - branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice
  • Date: Wed, 4 Mar 2009 09:09:02 -0500

Author: mac
Date: 2009-03-04 09:09:02 -0500 (Wed, 04 Mar 2009)
New Revision: 5021

Removed:

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

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

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

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

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

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

branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/LSRegisterAction.java
Log:
Query, Discovery and Register work

Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/DiscoveryQueryGenerator.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/DiscoveryQueryGenerator.java
2009-03-04 14:07:36 UTC (rev 5020)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/DiscoveryQueryGenerator.java
2009-03-04 14:09:02 UTC (rev 5021)
@@ -5,7 +5,6 @@

import org.perfsonar.base2.service.exceptions.PerfSONARException;
import org.perfsonar.base2.xml.Element;
-import org.perfsonar.base2.xml.nmwg.Subject;

/**
* Discovery Query Generator
@@ -43,17 +42,17 @@
if (!extracted) {

for (Element e : discoverySubject.getChildren()) {
-
- if (e.equals("address")) {
+ String elementName = e.getName() ;
+ if (elementName .equals("address")) {
addIpAddress(e);

- } else if (e.equals("domain")) {
+ } else if (elementName.equals("domain")) {
addDomain(e);

- } else if (e.equals("eventType")) {
+ } else if (elementName.equals("eventType")) {
addEventType(e);

- } else if (e.equals("parameters")) {
+ } else if (elementName.equals("parameters")) {

for (Element p : e.getChildren("parameter")) {

@@ -185,51 +184,27 @@



- public void print() {
-
System.out.println("==================================================");
- System.out.println(ipAddresses);
-
System.out.println("==================================================");
- System.out.println(domains);
-
System.out.println("==================================================");
- System.out.println(eventTypes);
-
System.out.println("==================================================");
- System.out.println(keywords);
- System.out.println("DONE");
+
+ public StringBuffer printQueryParameters() {
+ StringBuffer sb = new StringBuffer();
+ sb.append("Discovery Query Parameters\n");
+ sb.append("==================================================\n");
+ sb.append(ipAddresses);
+ sb.append("\n");
+ sb.append("==================================================\n");
+ sb.append(domains);
+ sb.append("\n");
+ sb.append("==================================================\n");
+ sb.append(eventTypes);
+ sb.append("\n");
+ sb.append("==================================================\n");
+ sb.append(keywords);
+ sb.append("\n");
+ sb.append("==================================================\n");
+ return sb;
}


-
- /**
- * @param args
- */
- public static void main(String[] args) throws Exception {
- String xml = "/home/mac/projects/perfsonar/discovery.xml";
- String configFile =
"/home/mac/projects/perfsonar/trunk/geant2_java-xml-ls/conf/conf-rpm/objects.config";

-
-// //read from file to NMWG
-// Document doc = XMLUtils.convertXMLFileToDom(xml);
-// Message m = XMLUtils.convertToMessage( doc , configFile);
-//
-// //get subject
-// Metadata meta = m.getMetadataArray()[0];
-// Subject subj = (Subject)meta.getSubject();
-//
-// //-----------------------------------------------------------
-//
-// //generate query -- main part
-// DiscoveryQueryGenerator g = new DiscoveryQueryGenerator(subj);

-// //g.extractSubject();
-// String query = g.generateQuery();
-//
-// //-----------------------------------------------------------
-//
-// //g.print(); //for debugging
-//
-// System.out.println(query);
-
- }
-
-
public String getQuery() {

return query;

Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/GenericLSServiceEngine.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/GenericLSServiceEngine.java
2009-03-04 14:07:36 UTC (rev 5020)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/GenericLSServiceEngine.java
2009-03-04 14:09:02 UTC (rev 5021)
@@ -1,5 +1,6 @@
package org.perfsonar.service.lookupservice;

+import org.apache.log4j.Logger;
import org.perfsonar.base2.service.configuration.Configuration;
import org.perfsonar.base2.service.configuration.ConfigurationManager;
import org.perfsonar.base2.service.exceptions.PerfSONARException;
@@ -12,6 +13,8 @@

public abstract class GenericLSServiceEngine implements ServiceEngine {

+ private static final Logger logger =
Logger.getLogger(LSRegisterAction.class.getName());
+
protected LookupServiceDAO dao;

protected Configuration configuration;
@@ -78,13 +81,16 @@
*/
protected String getParameterFromKey(
Metadata requestMetadata, String parameterName) {
-
+
for (Element key : requestMetadata.getChildren("key")) {
+
for (Element params : key.getChildren("parameters")) {
for (Element p : params.getChildren("parameter")) {
String parameterValue = extractParameterValue(p);
- if (parameterName.equals(p.getName()))
- return parameterValue; //if key has keyId and
+ if (parameterName.equals(p.getName())) {
+ logger.debug("Found Parameter ["+parameterName+"] in
metadata ["+requestMetadata+"]");
+ return parameterValue; //if key has keyId and
+ }
}
}
}

Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/LSDiscoveryAction.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/LSDiscoveryAction.java
2009-03-04 14:07:36 UTC (rev 5020)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/LSDiscoveryAction.java
2009-03-04 14:09:02 UTC (rev 5021)
@@ -11,10 +11,13 @@
import org.perfsonar.base2.xml.nmwg.Data;
import org.perfsonar.base2.xml.nmwg.Message;
import org.perfsonar.base2.xml.nmwg.Metadata;
-import org.perfsonar.base2.xml.nmwgr.Datum;
import org.perfsonar.service.lookupservice.storage.LookupServiceDAO;

-
+/**
+ * Discovery action (LS Query / Discovery)
+ * @author Maciej Glowiak
+ *
+ */
public class LSDiscoveryAction {

private static final Logger logger =
Logger.getLogger(LSDiscoveryAction.class.getName());
@@ -38,7 +41,8 @@

logger.debug("LSDiscoveryAction started - found summary eventType");

- //check subject
+ //check subject URI
+ //if not <summary:subject> return error
if
(!"http://ggf.org/ns/nmwg/tools/org/perfsonar/service/lookup/summarization/2.0/";.
equals(subject.getNamespaceUri()))
throw new PerfSONARException("error/ls/no_subject", "Subject
is not summary:subject");
@@ -83,10 +87,10 @@
//generate result code when no results
addNothingFoundMessage(data);
}
-
- //return the response with results or error.
- serviceResponse.setElement(response);
}
+
+ //return the response (either for success or error)
+ serviceResponse.setElement(response);
}


@@ -95,7 +99,7 @@

logger.debug("Result set empty - generating result code");

- Datum datum = new Datum();
+ Element datum = new Element("datum","nmwgr",
"http://ggf.org/ns/nmwg/result/2.0/";);
datum.setText("Nothing returned for search.");
data.addChild(datum);
}
@@ -148,7 +152,7 @@
//create query generator passing subject
DiscoveryQueryGenerator gen = new DiscoveryQueryGenerator(subject);
String query = gen.generateQuery();
- gen.print();
+ logger.debug(gen.printQueryParameters());

/* XQuery. Will return string array containing metadata blocks*/
logger.debug("perform search with XQuery");

Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/LSQueryAction.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/LSQueryAction.java
2009-03-04 14:07:36 UTC (rev 5020)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/LSQueryAction.java
2009-03-04 14:09:02 UTC (rev 5021)
@@ -9,22 +9,24 @@
import org.perfsonar.base2.xml.nmwg.Message;
import org.perfsonar.base2.xml.nmwg.Metadata;
import org.perfsonar.service.lookupservice.storage.LookupServiceDAO;
-import org.perfsonar.service.lookupservice.storage.LookupServiceDAOFactory;

-
+/**
+ * Action responsible for LS Query
+ * @author Maciej Glowiak
+ *
+ */
public class LSQueryAction {

private static final Logger logger =
Logger.getLogger(LSQueryAction.class.getName());
-
+
private LookupServiceDAO dao;

public LSQueryAction(LookupServiceDAO dao) {

this.dao = dao;

- }
-
-
+ }
+
public void performQuery(
ServiceMessage serviceRequest, ServiceMessage serviceResponse,
Message message, Element subject, String lsOutput)
@@ -53,11 +55,12 @@
//Performing XQuery operation on the database
logger.debug("Perform query");

- /* XQuery */
- LookupServiceDAO dao = LookupServiceDAOFactory.getDAO();
+ /* ------------- XQuery ------------- */

XMLDBResult results = dao.performXQuery(query);

+ /* ------------- XQuery ------------- */
+
logger.debug("Got ["+results.getElementsCount()+"] results from DB");

//create ServiceEngineResponse and put there the results

Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/LSQueryServiceEngine.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/LSQueryServiceEngine.java
2009-03-04 14:07:36 UTC (rev 5020)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/LSQueryServiceEngine.java
2009-03-04 14:09:02 UTC (rev 5021)
@@ -30,18 +30,13 @@
"service.lookup.xpath", //DEPRECATED
"service.lookup.xquery", //DEPRECATED

"http://ggf.org/ns/nmwg/tools/org/perfsonar/service/lookup/xquery/1.0";,
-
"http://ggf.org/ns/nmwg/tools/org/perfsonar/service/lookup/xquery/1.0/";,

"http://ggf.org/ns/nmwg/tools/org/perfsonar/service/lookup/xpath/1.0";,
-
"http://ggf.org/ns/nmwg/tools/org/perfsonar/service/lookup/xpath/1.0/";,

"http://ogf.org/ns/nmwg/tools/org/perfsonar/service/lookup/discovery/xquery/2.0";,
-
"http://ogf.org/ns/nmwg/tools/org/perfsonar/service/lookup/discovery/xquery/2.0/";,

"http://ogf.org/ns/nmwg/tools/org/perfsonar/service/lookup/query/xquery/2.0";,
-
"http://ogf.org/ns/nmwg/tools/org/perfsonar/service/lookup/query/xquery/2.0/";,
};

private String[] discoveryEventTypes = {

"http://ogf.org/ns/nmwg/tools/org/perfsonar/service/lookup/discovery/summary/2.0";,
-
"http://ogf.org/ns/nmwg/tools/org/perfsonar/service/lookup/discovery/summary/2.0/";,
};


@@ -62,7 +57,8 @@
// --------------------------------------------------------- Public
methods


- public void takeAction(ServiceMessage serviceRequest, ServiceMessage
serviceResponse) throws PerfSONARException {
+ public void takeAction(ServiceMessage serviceRequest, ServiceMessage
serviceResponse)
+ throws PerfSONARException {

logger.debug("Action LOOKUP started");

@@ -73,6 +69,7 @@
String eventType = null;
String lsOutput = null;
Element subject = null;
+ Metadata metadataWithSubject = null;

//Process metadata
for (Element e : requestMessage.getChildren("metadata")) {
@@ -91,14 +88,17 @@
//try to get subject
try {
subject = m.getSubject();
- logger.debug("Found subject");
+ metadataWithSubject = m;
+ logger.debug("Found subject (namespace
"+subject.getNamespacePrefix()+")");
} catch (Exception ex) {}

//try to get parameters
try {
- lsOutput =
m.getParameters().getFirstParameter("lsOutput").getValue();
+
+ lsOutput =
m.getParameters("http://ggf.org/ns/nmwg/tools/org/perfsonar/service/lookup/xquery/1.0/";).getFirstParameter("lsOutput").getValue();
logger.debug("Found lsOutput parameter ["+lsOutput+"]");
- } catch (Exception ex) {}
+ } catch (Exception ex) {
+ }

}
}
@@ -115,11 +115,14 @@

} else if (isLookupDiscovery(eventType)) {
logger.debug("EventType ["+eventType+"] accepted, taking
LSDiscovery action");
-// LSDiscoveryAction discovery = new LSDiscoveryAction(dao);
//process DISCOVERY
-// discovery.performAction(
-// serviceRequest, serviceResponse,
-// requestMessage, subject);
+ LSDiscoveryAction discovery = new LSDiscoveryAction(dao);
//process DISCOVERY

+ logger.debug("!!!!!!!!! subject:"+subject);
+
+ discovery.performAction(
+ serviceRequest, serviceResponse,
+ requestMessage, metadataWithSubject, subject);
+
} else {
String m = "Event Type ["+eventType+"] not found, unknown or not
supported";
logger.error(m);
@@ -128,19 +131,21 @@

}

- private boolean inArray(String needle, String[] haystack) {
- for (String h : haystack)
+ private boolean eventTypeInArray(String needle, String[] haystack) {
+ for (String h : haystack) {
if (h.equals(needle)) return true;
+ else if (h.equals(needle+"/")) return true;
+ }
return false;
}

private boolean isLookupDiscovery(String queryType) {
- return inArray(queryType, discoveryEventTypes);
+ return eventTypeInArray(queryType, discoveryEventTypes);
}


private boolean isLookupQuery(String queryType) {
- return inArray(queryType, queryEventTypes);
+ return eventTypeInArray(queryType, queryEventTypes);
}

} //LSLookupAction

Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/LSRegisterAction.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/LSRegisterAction.java
2009-03-04 14:07:36 UTC (rev 5020)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/LSRegisterAction.java
2009-03-04 14:09:02 UTC (rev 5021)
@@ -8,6 +8,7 @@
import org.perfsonar.base2.service.requesthandler.ServiceMessage;
import org.perfsonar.base2.service.util.ResultCodesUtil;
import org.perfsonar.base2.xml.nmwg.Data;
+import org.perfsonar.base2.xml.nmwg.EventType;
import org.perfsonar.base2.xml.nmwg.Key;
import org.perfsonar.base2.xml.nmwg.Message;
import org.perfsonar.base2.xml.nmwg.Metadata;
@@ -29,14 +30,12 @@

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

- private final static boolean DEFAULT_ALLOW_REPLACE = true;
-
private static final Logger logger =
Logger.getLogger(LSRegisterAction.class.getName());

// ----------------------------------------------------- Instance
variables


- private boolean allowReplaceIfAlreadyRegistered = DEFAULT_ALLOW_REPLACE;
+ private boolean allowReplaceIfAlreadyRegistered = true;


// -----------------------------------------------------------
Constructor
@@ -45,19 +44,19 @@
public LSRegisterAction() throws PerfSONARException {

super();
+//ALLOW_REPLACE
+// //extract parameters from configuration
+// String prop = null;
+// try {
+// prop = configuration.getExtensionOption("ls-settings",
"allow_replace");
+// } catch (PerfSONARException ex) { prop=null; }
+// if (testIfTrue(prop))
+// allowReplaceIfAlreadyRegistered = true;
+// else
+// allowReplaceIfAlreadyRegistered = false;
+// logger.debug("[LS Registration] service.ls.allow_replace="+
+// allowReplaceIfAlreadyRegistered);

- //extract parameters from configuration
- String prop = null;
- try {
- prop = configuration.getExtensionOption("ls-settings",
"allow_replace");
- } catch (PerfSONARException ex) { prop=null; }
- if (testIfTrue(prop))
- allowReplaceIfAlreadyRegistered = true;
- else
- allowReplaceIfAlreadyRegistered = false;
- logger.debug("[LS Registration] service.ls.allow_replace="+
- allowReplaceIfAlreadyRegistered);
-
}


@@ -69,8 +68,8 @@
//extract message
Message request = serviceRequest.getMessageElement();

- logger.debug("[LS Registration] Action started");
-
+ logger.debug("[LS Registration] Action started, service is
"+(isGLS()?"GlobalLS":"HomeLS"));
+
//Get Metadata from request

Metadata requestMetadata = getFirstMetadataFromRequest(request);
@@ -79,21 +78,26 @@
logger.error(m);
throw new PerfSONARException("error.ls.no_metadata", m);
}
+ logger.debug("[LS Registration] Getting metadata from request:
["+requestMetadata.getId()+"]");

// ----------------------------------------- BEGIN OF GLS code
-
+ EventType reqEvT = null;
String reqEventType = null;
//check eventType
try {
- reqEventType =
requestMetadata.getFirstEventType().getEventType();
+ reqEvT = requestMetadata.getFirstEventType();
+ reqEventType = reqEvT.getEventType();
logger.debug("[LS Registration] service event type is
["+reqEventType+"]");
} catch (Exception ex) {
+ logger.debug("[LS Registration] No event type in metadata");
+
}
-
+
//if no eventType and home LS -- use Service evt.
//for backward compatibility
if ((!isGLS()) && (reqEventType == null)) {
reqEventType = SERVICE_EVENT_TYPE;
+ logger.debug("[LS Registration] Taking default eventType
["+SERVICE_EVENT_TYPE+"]");
}

//check GLS
@@ -113,11 +117,10 @@
}

//reset event type - will not be used anymore
+ requestMetadata.removeChild(reqEvT);

- requestMetadata.setEventType(null);

// ----------------------------------------- END OF GLS code
-
//get accessPoint from Metadata - obligatory element
//if it's empty or null PerfSONARException will be thrown
String accessPoint = getAccessPoint(requestMetadata);
@@ -125,12 +128,17 @@
//check other mandatory elements, dont care about results
//if they're empty or null PerfSONARException will be thrown
getServiceName(requestMetadata);
+
getServiceType(requestMetadata);
-
+
//Try to get Key from Metadata
- String keyValue = getParameterFromKey(requestMetadata, LS_KEY);

- logger.debug("[LS Registration] Key from metadata=["+keyValue+"]");
-
+ String keyValue=null;
+ try{
+ keyValue = getParameterFromKey(requestMetadata, LS_KEY);
+ logger.debug("[LS Registration] Key from
metadata=["+keyValue+"]");
+ } catch (Exception ex) {
+ }
+
//========check metadata========

//id of new metadata in the LS. Will be keyValue (update) or just
@@ -143,7 +151,6 @@
//check keyValue

if (keyValue == null) { //REGISTER
-
//let the key value be accesspoint
logger.debug("[LS Registration] Action is Registration (DB Key =
accessPoint)");
metadataId = accessPoint; //trimmed
@@ -173,7 +180,7 @@
requestMetadata.setKey(null);

} //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)) {
@@ -184,7 +191,6 @@
throw new PerfSONARException("error.ls.no_key", m);
}

-
//========check data========

logger.debug("[LS Registration] get data elements");
@@ -204,7 +210,7 @@

if (allowReplaceIfAlreadyRegistered) {

- logger.debug("[LS Registration] 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;

} else {
@@ -217,7 +223,7 @@

} //if dao...

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

//enumerate all data elements
@@ -233,24 +239,23 @@
//remove old lookup information if there is any
if (doRemove) {
logger.info("[LS Registration] Remove old Lookup Info
("+metadataId+")");
- dao.removeLookupInfo(metadataId);
+ int num = dao.removeLookupInfo(metadataId);
+ logger.debug("[LS Registration] Removed ["+num+"] old entries");
}

//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);
+ logger.info("[LS Registration] Remove old Lookup Info - other
key ("+keyValue+")");
+ int num = dao.removeLookupInfo(keyValue);
+ logger.debug("[LS Registration] Removed ["+num+"] old entries");
}
-
//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(metadataId);
-
//get response with success code and key
serviceResponse.setElement(getLSRegisterResponse(metadataId));


Deleted:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/LSRegisterAction_test.java



  • perfsonar: r5021 - branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice, svnlog, 03/04/2009

Archive powered by MHonArc 2.6.16.

Top of Page