Skip to Content.
Sympa Menu

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

Subject: perfsonar development work

List archive

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


Chronological Thread 
  • From:
  • To:
  • Subject: perfsonar: r4478 - trunk/geant2_java-xml-ls/src/main/java/org/perfsonar/service/lookupService/xmlType
  • Date: Thu, 11 Sep 2008 10:15:45 -0400

Author: mac
Date: 2008-09-11 10:15:45 -0400 (Thu, 11 Sep 2008)
New Revision: 4478

Modified:

trunk/geant2_java-xml-ls/src/main/java/org/perfsonar/service/lookupService/xmlType/DiscoveryQueryGenerator.java

trunk/geant2_java-xml-ls/src/main/java/org/perfsonar/service/lookupService/xmlType/LSLookupAction.java
Log:
LS Discovery for hLS

Modified:
trunk/geant2_java-xml-ls/src/main/java/org/perfsonar/service/lookupService/xmlType/DiscoveryQueryGenerator.java
===================================================================
---
trunk/geant2_java-xml-ls/src/main/java/org/perfsonar/service/lookupService/xmlType/DiscoveryQueryGenerator.java
2008-09-10 07:08:59 UTC (rev 4477)
+++
trunk/geant2_java-xml-ls/src/main/java/org/perfsonar/service/lookupService/xmlType/DiscoveryQueryGenerator.java
2008-09-11 14:15:45 UTC (rev 4478)
@@ -16,43 +16,12 @@
import org.perfsonar.base.util.XMLUtils;
import org.w3c.dom.Document;

-
+/**
+ * Discovery Query Generator
+ * @author Maciej Glowiak
+ *
+ */
public class DiscoveryQueryGenerator {
-/*
- <nmwg:metadata id="meta1">
- <summary:subject
xmlns:summary="http://ggf.org/ns/nmwg/tools/org/perfsonar/service/lookup/summarization/2.0/";
id="subject.1">
-
-<!-- can have multiples of each, note that this creates an 'or' relationship
-->
- <nmtb:address
xmlns:nmtb="http://ogf.org/schema/network/topology/base/20070828/";
type="ipv4">128.4.133.167</nmtb:address>
- <nmtb:address
xmlns:nmtb="http://ogf.org/schema/network/topology/base/20070828/"type="ipv4";>128.4.100.45</nmtb:address>
-
- <nmtb:domain
xmlns:nmtb="http://ogf.org/schema/network/topology/base/20070828/";>
- <nmtb:name type="dns">edu</nmtb:name>
- </nmtb:domain>
-
- <nmtb:domain
xmlns:nmtb="http://ogf.org/schema/network/topology/base/20070828/";>
- <nmtb:name type="dns">udel.edu</nmtb:name>
- </nmtb:domain>
-
-
<nmwg:eventType>http://ggf.org/ns/nmwg/characteristic/utilization/2.0</nmwg:eventType>
-
<nmwg:eventType>http://ggf.org/ns/nmwg/characteristic/errors/2.0</nmwg:eventType>
-
- <summary:parameters>
- <nmwg:parameter name="keyword">project:Geant2</nmwg:parameter>
- </summary:parameters>
-
-<!-- the combination of all things is an 'and' relationsip, this entire
subject is therefore:
-
-('128.4.133.167' or '128.4.100.45') and
-('udel.edu' or 'edu') and
-('http://ggf.org/ns/nmwg/characteristic/utilization/2.0' or
'http://ggf.org/ns/nmwg/characteristic/errors/2.0') and
-('project:Geant2')
-
--->
-
- </summary:subject>
-
-*/
private Subject discoverySubject = null;
private boolean extracted = false;

@@ -61,6 +30,8 @@
HashSet<String> eventTypes = new HashSet<String>();
HashSet<String> keywords = new HashSet<String>();

+ String query = null;
+
public DiscoveryQueryGenerator(Subject discoverySubject) {
setSubject(discoverySubject);
}
@@ -81,8 +52,6 @@

for (Object o : discoverySubject.getChildMap().values()) {

- System.out.println("--read-- "+o.getClass());
-
if (o instanceof Address) {

Address ipAddress = (Address)o;
@@ -123,6 +92,7 @@
} //else
}//for
}
+ extracted = true;
}

private void addEventType(EventType eventType) {
@@ -153,28 +123,90 @@
}


-
- public String getQuery() {
+ /**
+ * Generates query and stores to query property
+ * @return
+ * @throws PerfSONARException
+ */
+ public String generateQuery() throws PerfSONARException {

+ if (!extracted) extractSubject();
+
StringBuffer q = new StringBuffer();
- //TODO: generate query
+
+ //add declarations
+ q.append("declare namespace nmwg='http://ggf.org/ns/nmwg/base/2.0/';
\n");
+ q.append("declare namespace
nmwgt='http://ggf.org/ns/nmwg/topology/2.0/'; \n");;
+
+ //add for expression
+ q.append("for $d in
/nmwg:store[@type='LSStore']/nmwg:data
\n");
+ if ((ipAddresses.size() + domains.size() + keywords.size() +
eventTypes.size()) > 0) {
+
+ //generate query conditions
+ q.append("where \n");
+
+ int i=0;
+ i += putCollectionToQueryBuffer(q, ipAddresses,
"$d/nmwg:metadata//nmwgt:ifAddress", (i>0), null);
+ i += putCollectionToQueryBuffer(q, domains,
"$d/nmwg:metadata//nmwgt:hostName", (i>0), "ends-with");
+ i += putCollectionToQueryBuffer(q, eventTypes,
"$d/nmwg:metadata/nmwg:eventType", (i>0), null);
+ i += putCollectionToQueryBuffer(q, keywords,
"$d/nmwg:metadata//nmwg:parameter[@name='keyword']",
(i>0), null);
+
+ }
+ //add return statemet
+ q.append("return data($d/@metadataIdRef)");
+
+ query = q.toString();
+ return query;

- /*
- for $i in
/store[@type='LSStore']
- ...all constraints...
- return $metadata
- */
+ }
+
+
+ /**
+ * Makes AND/OR query
+ * @param q buffer to be appended
+ * @param col collection where to take data from
+ * @param element name of an element to be checked
+ * @param addAND indicates whether to add AND at the beginning of the
expression
+ * @param function name of function, if null then equal "=" will be used
+ * @return number of elements added
+ */
+ private int putCollectionToQueryBuffer(
+ StringBuffer q,
+ Collection<String> col,
+ String element,
+ boolean addAND,
+ String function) {
+
+ if ((col.size()>0) && (addAND==true)) q.append(" and \n");

- return q.toString();
+ int i=0;
+ for (String c : col) {
+ if (i==0) q.append("(");
+ else q.append(" or ");
+ if (function==null) {
+ q.append(" ");
+ q.append(element);
+ q.append(" = '");
+ q.append(c);
+ q.append("' ");
+ } else {
+ q.append(" ");
+ q.append(function);
+ q.append("(");
+ q.append(element);
+ q.append(",'");
+ q.append(c);
+ q.append("') ");
+ }
+ i++;
+ }
+ if (i>0) q.append(")\n");
+ return i;

}



-
-
-
-
public void print() {

System.out.println("==================================================");
System.out.println(ipAddresses);
@@ -196,18 +228,33 @@
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();
- DiscoveryQueryGenerator g = new DiscoveryQueryGenerator(subj);

- g.extractSubject();
- g.print();

+ //-----------------------------------------------------------

+ //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:
trunk/geant2_java-xml-ls/src/main/java/org/perfsonar/service/lookupService/xmlType/LSLookupAction.java
===================================================================
---
trunk/geant2_java-xml-ls/src/main/java/org/perfsonar/service/lookupService/xmlType/LSLookupAction.java
2008-09-10 07:08:59 UTC (rev 4477)
+++
trunk/geant2_java-xml-ls/src/main/java/org/perfsonar/service/lookupService/xmlType/LSLookupAction.java
2008-09-11 14:15:45 UTC (rev 4478)
@@ -84,20 +84,28 @@
logger.debug("XmlTypeLSServiceEngine: Query type (EventType) is ["+
queryType +"]");

+
+ /* begin of GLS code */
+
+ if
("http://ogf.org/ns/nmwg/tools/org/perfsonar/service/lookup/discovery/summary/2.0".equals(queryType))
{
+
+ LSDiscoveryAction discovery = new LSDiscoveryAction(dao);
+ return discovery.performAction(request, requestMetadata);
+ }
+
+ /* end of GLS code */
+
+
// check if the query type can be satisfied
boolean queryTypeCanBeSatisfied = false;

-// for (int itr=0; itr<acceptedQueryTypes.length; itr++) {
-// if (acceptedQueryTypes[itr].equals(queryType)) {
-// queryTypeCanBeSatisfied = true;
-// break;
-// }
-// }
-
- /* BEGIN OF TEMPORARY CODE: for gLS */
- queryTypeCanBeSatisfied = true;
- /* END OF TEMPORARY CODE: for gLS */
-
+ for (int itr=0; itr<acceptedQueryTypes.length; itr++) {
+ if (acceptedQueryTypes[itr].equals(queryType)) {
+ queryTypeCanBeSatisfied = true;
+ break;
+ }
+ }
+
if (!queryTypeCanBeSatisfied) {
String m = "XmlTypeLSServiceEngine: Query Type specified: ["
+ queryType + "] is not supported";



  • perfsonar: r4478 - trunk/geant2_java-xml-ls/src/main/java/org/perfsonar/service/lookupService/xmlType, svnlog, 09/11/2008

Archive powered by MHonArc 2.6.16.

Top of Page