Skip to Content.
Sympa Menu

perfsonar-dev - r1521 - trunk/perfsonar/src/org/perfsonar/service/measurementPoint/snmpType

Subject: perfsonar development work

List archive

r1521 - trunk/perfsonar/src/org/perfsonar/service/measurementPoint/snmpType


Chronological Thread 
  • From:
  • To:
  • Subject: r1521 - trunk/perfsonar/src/org/perfsonar/service/measurementPoint/snmpType
  • Date: Tue, 8 Aug 2006 12:07:00 -0400

Author: loukik
Date: 2006-08-08 12:06:59 -0400 (Tue, 08 Aug 2006)
New Revision: 1521

Modified:

trunk/perfsonar/src/org/perfsonar/service/measurementPoint/snmpType/SNMPXQueryExpressionGenerator.java
Log:
I committed the wrong file (id 1520). This is the right one.

Fixed a bug which was causing no matches if any parameter was specified in a
metadata lookup request.
This bug fix now provides a much deeper insight into XQuery (at least for
me). Not in terms of logic but at least in terms of rules.
XQuery uses FLOWR (For, Let, Where, Order, Return). However, the usage of Let
and for need to understood well. This code shows that for statement should be
used while searching for parameters for example. There can be many parameter
elements and hence a for (which is more like an iteration) should be used
instead of let. In other situations where multiple occurances are not
expected, let can be used.

Also added namespace verification.

Modified:
trunk/perfsonar/src/org/perfsonar/service/measurementPoint/snmpType/SNMPXQueryExpressionGenerator.java
===================================================================
---
trunk/perfsonar/src/org/perfsonar/service/measurementPoint/snmpType/SNMPXQueryExpressionGenerator.java
2006-08-08 16:04:12 UTC (rev 1520)
+++
trunk/perfsonar/src/org/perfsonar/service/measurementPoint/snmpType/SNMPXQueryExpressionGenerator.java
2006-08-08 16:06:59 UTC (rev 1521)
@@ -79,6 +79,8 @@
// String orderDeclarationString = "";
String returnDeclarationString = "";

+ Vector nameSpaceDeclarationVector = new Vector();
+ Vector forDeclarationVector = new Vector();
Vector letDeclarationVector = new Vector();
Vector whereDeclarationVector = new Vector();

@@ -94,8 +96,18 @@
String OIDString = "";


- //request.
+ // lets start with the namespaces.
+ // Ideally, we should pick up the namespaces present in the message
and try to match them here
+ // For now, we will assume the namespaces are the ones in the
store.
+ // This will kind of validate the store content (and not the
message content)
+ // this might actually be seen as a bug by a few eyes :)

+ String namesp1=" declare namespace
nmwg='http://ggf.org/ns/nmwg/base/2.0/';";
+ String namesp2=" declare namespace
nmwgt='http://ggf.org/ns/nmwg/topology/2.0/';";
+
+ nameSpaceDeclarationVector.add(namesp1);
+ nameSpaceDeclarationVector.add(namesp2);
+
Metadata metadata = null;

try {
@@ -161,83 +173,126 @@
}

// for
- forDeclarationString = "for $metadata in /*:store/*:metadata";
+ String metadataforDeclr = "for $metadata in /*:store/nmwg:metadata";
+ forDeclarationVector.add(metadataforDeclr);


// let and where

if (ifIPAddress != "") {

- String letDeclr = "let $i"+letDeclarationVector.size()+":=
$metadata/*:subject/*:interface/*:ipAddress";
+ String letDeclr = "let $i"+letDeclarationVector.size()+":=
$metadata/nmwg:subject/nmwgt:interface/nmwgt:ipAddress";
String whereDeclr = "$i"+letDeclarationVector.size()+"=
'"+ifIPAddress+"'";
letDeclarationVector.add(letDeclr);
whereDeclarationVector.add(whereDeclr);
}

if(ifIPAddressType!="") {
- String letDeclr = "let $i"+letDeclarationVector.size()+":=
upper-case($metadata/*:subject/*:interface/*:ipAddress/@type)";
+ String letDeclr = "let $i"+letDeclarationVector.size()+":=
upper-case($metadata/nmwg:subject/nmwgt:interface/nmwgt:ipAddress/@type)";
String whereDeclr = "$i"+letDeclarationVector.size()+"=
'"+ifIPAddressType.toUpperCase()+"'";
letDeclarationVector.add(letDeclr);
whereDeclarationVector.add(whereDeclr);
}

if(ifHostName!="") {
- String letDeclr = "let $i"+letDeclarationVector.size()+":=
$metadata/*:subject/*:interface/*:hostName";
+ String letDeclr = "let $i"+letDeclarationVector.size()+":=
$metadata/nmwg:subject/nmwgt:interface/nmwgt:hostName";
String whereDeclr = "$i"+letDeclarationVector.size()+"=
'"+ifHostName+"'";
letDeclarationVector.add(letDeclr);
whereDeclarationVector.add(whereDeclr);
}

if(ifDescription!="") {
- String letDeclr = "let $i"+letDeclarationVector.size()+":=
$metadata/*:subject/*:interface/*:ifDescription";
+ String letDeclr = "let $i"+letDeclarationVector.size()+":=
$metadata/nmwg:subject/nmwgt:interface/nmwgt:ifDescription";
String whereDeclr = "$i"+letDeclarationVector.size()+"=
'"+ifDescription+"'";
letDeclarationVector.add(letDeclr);
whereDeclarationVector.add(whereDeclr);
}

if(ifName!="") {
- String letDeclr = "let $i"+letDeclarationVector.size()+":=
$metadata/*:subject/*:interface/*:ifName";
+ String letDeclr = "let $i"+letDeclarationVector.size()+":=
$metadata/nmwg:subject/nmwgt:interface/nmwgt:ifName";
String whereDeclr = "$i"+letDeclarationVector.size()+"=
'"+ifName+"'";
letDeclarationVector.add(letDeclr);
whereDeclarationVector.add(whereDeclr);
}

- // slightly different declaration manner for parameters, we don't
need so many declarations (let)
+ // slightly different declaration manner for parameters,
+ // we need to use for declarations here as there can be many
parameters

if(OIDString!="" || OIDAlias!="" || snmpAgent!="" ||
snmpAgentPort!="" || snmpVersion!="") {

- String parameterDeclrVariable =
"$i"+letDeclarationVector.size();
- String letDeclr = "let "+parameterDeclrVariable+":=
$metadata/*:parameters/*:parameter";
- letDeclarationVector.add(letDeclr);
-
-
+
if(OIDString!="") {
+ String parameterDeclrVariable =
"$f"+forDeclarationVector.size();
+ String forDeclaration = "for "+parameterDeclrVariable+" in
$metadata/nmwg:parameters/nmwg:parameter";
+ forDeclarationVector.add(forDeclaration);
+
String whereDeclr =
parameterDeclrVariable+"/@name='OIDString' and
"+parameterDeclrVariable+"='"+OIDString+"'";
whereDeclarationVector.add(whereDeclr);
}

if(OIDAlias!="") {
+ String parameterDeclrVariable =
"$f"+forDeclarationVector.size();
+ String forDeclaration = "for "+parameterDeclrVariable+" in
$metadata/nmwg:parameters/nmwg:parameter";
+ forDeclarationVector.add(forDeclaration);
+
String whereDeclr =
parameterDeclrVariable+"/@name='OIDAlias' and
"+parameterDeclrVariable+"='"+OIDAlias+"'";
whereDeclarationVector.add(whereDeclr);
}

if(snmpAgent!="") {
+ String parameterDeclrVariable =
"$f"+forDeclarationVector.size();
+ String forDeclaration = "for "+parameterDeclrVariable+" in
$metadata/nmwg:parameters/nmwg:parameter";
+ forDeclarationVector.add(forDeclaration);
+
String whereDeclr =
parameterDeclrVariable+"/@name='SNMPAgent' and
"+parameterDeclrVariable+"='"+snmpAgent+"'";
whereDeclarationVector.add(whereDeclr);
}

if(snmpAgentPort!="") {
+ String parameterDeclrVariable =
"$f"+forDeclarationVector.size();
+ String forDeclaration = "for "+parameterDeclrVariable+" in
$metadata/nmwg:parameters/nmwg:parameter";
+ forDeclarationVector.add(forDeclaration);
+
String whereDeclr =
parameterDeclrVariable+"/@name='SNMPAgentPort' and
"+parameterDeclrVariable+"='"+snmpAgentPort+"'";
whereDeclarationVector.add(whereDeclr);
}

if(snmpVersion!="") {
+ String parameterDeclrVariable =
"$f"+forDeclarationVector.size();
+ String forDeclaration = "for "+parameterDeclrVariable+" in
$metadata/nmwg:parameters/nmwg:parameter";
+ forDeclarationVector.add(forDeclaration);
+
String whereDeclr =
parameterDeclrVariable+"/@name='SNMPVersion' and
"+parameterDeclrVariable+"='"+snmpVersion+"'";
whereDeclarationVector.add(whereDeclr);
}

}

+
+ if(nameSpaceDeclarationVector.size()>0) {
+
+ for(int i=0;i<nameSpaceDeclarationVector.size();i++) {
+
+ nameSpaceDeclarationString =
nameSpaceDeclarationString.concat((String)nameSpaceDeclarationVector.get(i));
+ nameSpaceDeclarationString =
nameSpaceDeclarationString.concat(" \n");
+
+ }
+
+ }
+
+
+ if(forDeclarationVector.size()>0) {
+
+ for(int i=0;i<forDeclarationVector.size();i++) {
+
+ forDeclarationString =
forDeclarationString.concat((String)forDeclarationVector.get(i));
+ forDeclarationString = forDeclarationString.concat(" \n");
+
+ }
+
+ }
+
+
if(letDeclarationVector.size()>0){

for(int i=0;i<letDeclarationVector.size();i++) {
@@ -275,7 +330,6 @@
keyQuery = keyQuery.concat(nameSpaceDeclarationString);
keyQuery = keyQuery.concat(" \n");
keyQuery = keyQuery.concat(forDeclarationString);
- keyQuery = keyQuery.concat(" \n");
keyQuery = keyQuery.concat(letDeclarationString);
keyQuery = keyQuery.concat(whereDeclarationString);
keyQuery = keyQuery.concat(" \n");
@@ -283,10 +337,8 @@
// keyQuery = keyQuery.concat(" \n");
keyQuery = keyQuery.concat(returnDeclarationString);

+ logger.debug("SNMPXQueryExpressGenerator.getKeyQuery: XQuery
Expression for discovering metadata elements is: \n"+keyQuery);

-
- logger.debug("SNMPXQueryExpressGenerator.getKeyQuery: XQuery
Expression for discovering metadata elements is: "+keyQuery);
-
return keyQuery;
}




  • r1521 - trunk/perfsonar/src/org/perfsonar/service/measurementPoint/snmpType, svnlog, 08/08/2006

Archive powered by MHonArc 2.6.16.

Top of Page