perfsonar-dev - perfsonar: r5361 - in branches/new-structure-with-base2/ps-mdm-ls: . src/main/java/org/perfsonar/service/lookupservice src/main/java/org/perfsonar/service/lookupservice/registration src/main/java/org/perfsonar/service/lookupservice/registration/summarization src/main/java/org/perfsonar/service/lookupservice/servlets src/main/java/org/perfsonar/service/lookupservice/storage src/main/java/org/perfsonar/service/lookupservice/storage/exist src/main/java/org/perfsonar/service/lookupservice/summarization src/main/java/org/perfsonar/service/utilities
Subject: perfsonar development work
List archive
perfsonar: r5361 - in branches/new-structure-with-base2/ps-mdm-ls: . src/main/java/org/perfsonar/service/lookupservice src/main/java/org/perfsonar/service/lookupservice/registration src/main/java/org/perfsonar/service/lookupservice/registration/summarization src/main/java/org/perfsonar/service/lookupservice/servlets src/main/java/org/perfsonar/service/lookupservice/storage src/main/java/org/perfsonar/service/lookupservice/storage/exist src/main/java/org/perfsonar/service/lookupservice/summarization src/main/java/org/perfsonar/service/utilities
Chronological Thread
- From:
- To:
- Subject: perfsonar: r5361 - in branches/new-structure-with-base2/ps-mdm-ls: . src/main/java/org/perfsonar/service/lookupservice src/main/java/org/perfsonar/service/lookupservice/registration src/main/java/org/perfsonar/service/lookupservice/registration/summarization src/main/java/org/perfsonar/service/lookupservice/servlets src/main/java/org/perfsonar/service/lookupservice/storage src/main/java/org/perfsonar/service/lookupservice/storage/exist src/main/java/org/perfsonar/service/lookupservice/summarization src/main/java/org/perfsonar/service/utilities
- Date: Mon, 30 Nov 2009 08:17:51 -0500
Author: trzaszcz
Date: 2009-11-30 08:17:51 -0500 (Mon, 30 Nov 2009)
New Revision: 5361
Modified:
branches/new-structure-with-base2/ps-mdm-ls/pom.xml
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/EchoServiceEngine.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/LSQueryServiceEngine.java
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/LSRegisterServiceEngine.java
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/ThreadPoolComponent.java
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/registration/LsTTLParameterStatus.java
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/registration/summarization/Trie.java
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/registration/summarization/TrieNode.java
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/servlets/ExistDbInitializerServlet.java
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/storage/LookupServiceDAOFactory.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/MultipleFilesExistDAOImpl.java
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/storage/exist/SummarizationDAOImpl.java
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/summarization/SummarizationBuilder.java
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/utilities/ResourceBundle.java
Log:
refactoring - pmd reports, findbugs
Modified: branches/new-structure-with-base2/ps-mdm-ls/pom.xml
===================================================================
--- branches/new-structure-with-base2/ps-mdm-ls/pom.xml 2009-11-30 12:59:54
UTC (rev 5360)
+++ branches/new-structure-with-base2/ps-mdm-ls/pom.xml 2009-11-30 13:17:51
UTC (rev 5361)
@@ -85,7 +85,8 @@
<configuration>
<webResources>
<resource>
-
<directory>${basedir}/log4j/${log4j}</directory>
+
<directory>${basedir}/log4j/${log4j}
+ </directory>
<includes>
<include>log4j.properties</include>
</includes>
@@ -144,8 +145,45 @@
</webApp>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-pmd-plugin</artifactId>
+ <version>2.3</version>
+ <configuration>
+ <linkXref>true</linkXref>
+ <sourceEncoding>utf-8</sourceEncoding>
+ <minimumTokens>100</minimumTokens>
+ <targetJdk>1.6</targetJdk>
+ </configuration>
+ </plugin>
</plugins>
</build>
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-project-info-reports-plugin
+ </artifactId>
+ <reportSets>
+ <reportSet>
+ <reports>
+ <report>index</report>
+ <report>cim</report>
+ </reports>
+ </reportSet>
+ </reportSets>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>findbugs-maven-plugin</artifactId>
+ <version>2.0.1</version>
+ <configuration>
+ <xmlOutput>true</xmlOutput>
+
<xmlOutputDirectory>target/site</xmlOutputDirectory>
+ </configuration>
+ </plugin>
+ </plugins>
+ </reporting>
<repositories>
@@ -268,7 +306,6 @@
</dependency>
</dependencies>
-
<profiles>
<profile>
<activation>
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-11-30 12:59:54 UTC (rev 5360)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/DiscoveryQueryGenerator.java
2009-11-30 13:17:51 UTC (rev 5361)
@@ -129,11 +129,8 @@
StringBuffer q = new StringBuffer();
// 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");
- ;
+ 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");
Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/EchoServiceEngine.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/EchoServiceEngine.java
2009-11-30 12:59:54 UTC (rev 5360)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/EchoServiceEngine.java
2009-11-30 13:17:51 UTC (rev 5361)
@@ -36,7 +36,6 @@
* @throws PerfSONARException
*/
public EchoServiceEngine() throws PerfSONARException {
-
super();
}
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-11-30 12:59:54 UTC (rev 5360)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/GenericLSServiceEngine.java
2009-11-30 13:17:51 UTC (rev 5361)
@@ -42,7 +42,9 @@
for (Metadata m : request.getMetadataCollection()) {
try {
eventType = m.getFirstEventType().getEventType();
- } catch (RuntimeException ex) {}
+ } catch (RuntimeException ex) {
+ ex.printStackTrace();
+ }
if (eventType!=null) break;
}
return eventType;
@@ -141,7 +143,9 @@
try {
String txt = p.getText().trim();
return txt;
- } catch (Exception e) {}
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
return null;
}
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-11-30 12:59:54 UTC (rev 5360)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/LSDiscoveryAction.java
2009-11-30 13:17:51 UTC (rev 5361)
@@ -15,166 +15,175 @@
/**
* Discovery action (LS Query / Discovery)
+ *
* @author Maciej Glowiak
- *
+ *
*/
public class LSDiscoveryAction {
- private static final Logger logger =
Logger.getLogger(LSDiscoveryAction.class.getName());
-
- private LookupServiceDAO dao;
+ private static final Logger logger = Logger
+ .getLogger(LSDiscoveryAction.class.getName());
- protected boolean verbose = true;
-
-
- public LSDiscoveryAction(LookupServiceDAO dao) {
+ private LookupServiceDAO dao;
- this.dao = dao;
-
- }
+ protected boolean verbose = true;
-
- public void performAction(
- ServiceMessage serviceRequest, ServiceMessage serviceResponse,
- Message requestMessage, Metadata requestMetadata, Element
subject)
- throws PerfSONARException {
-
- logger.debug("LSDiscoveryAction started - found summary eventType");
+ public LSDiscoveryAction(LookupServiceDAO dao) {
- //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");
+ this.dao = dao;
- //query for list of services
- HashSet<String> resultSet = queryForListOfServices(subject);
+ }
- //prepare response
- Message response = new Message();
- //set Data container
- Data data = new Data();
- data.setId("discovery-results");
- data.setMetadataIdRef("discovery-metadata");
- response.setData(data);
- //Set Metadata
- requestMetadata.setId("discovery-metadata");
- response.setMetadata(requestMetadata);
-
-
- if (resultSet.size() == 0) {
- //generate result code when no results
- addNothingFoundMessage(data);
-
- } else {
- //fill the response with the results
-
- logger.debug("Got list of "+resultSet.size()+" unique services");
+ public void performAction(ServiceMessage serviceRequest,
+ ServiceMessage serviceResponse, Message
requestMessage,
+ Metadata requestMetadata, Element subject)
+ throws PerfSONARException {
- //query for services metadata, omit when empty
- Collection<Element> results =
queryForServicesMetadata(resultSet);
-
- //parse all metadata elements from resultSet and put them info
data
- //(add results to message)
- if (results!=null) {
- for (Element e : results) {
- if ("metadata".equals(e.getName())) {
- logger.debug("Add result metadata ["+e.getId()+"] to
data ["+data.getId()+"]");
- data.addChild(e);
- }
- }
- } else {
- //generate result code when no results
- addNothingFoundMessage(data);
- }
- }
+ logger.debug("LSDiscoveryAction started - found summary
eventType");
- //return the response (either for success or error)
- serviceResponse.setElement(response);
- }
+ // 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");
+ // query for list of services
+ HashSet<String> resultSet = queryForListOfServices(subject);
+ // prepare response
+ Message response = new Message();
+ // set Data container
+ Data data = new Data();
+ data.setId("discovery-results");
+ data.setMetadataIdRef("discovery-metadata");
+ response.setData(data);
+ // Set Metadata
+ requestMetadata.setId("discovery-metadata");
+ response.setMetadata(requestMetadata);
- private void addNothingFoundMessage(Data data) {
+ if (resultSet.size() == 0) {
+ // generate result code when no results
+ addNothingFoundMessage(data);
- logger.debug("Result set empty - generating result code");
-
- Element datum = new Element("datum","nmwgr",
"http://ggf.org/ns/nmwg/result/2.0/");
- datum.setText("Nothing returned for search.");
- data.addChild(datum);
- }
+ } else {
+ // fill the response with the results
+ logger
+ .debug("Got list of " +
resultSet.size()
+ + " unique services");
- /**
- * Performs query and returns list of metadata blocks
- * If no metadata block, null is returned
- * @param resultSet
- * @return
- * @throws PerfSONARException
- */
- private Collection<Element> queryForServicesMetadata(HashSet<String>
resultSet) throws PerfSONARException {
+ // query for services metadata, omit when empty
+ Collection<Element> results =
queryForServicesMetadata(resultSet);
- //generate specific query for metadata blocks
- StringBuffer qb = new StringBuffer();
- qb.append("declare namespace
nmwg='http://ggf.org/ns/nmwg/base/2.0/'; \n");
- qb.append("declare namespace
nmwgt='http://ggf.org/ns/nmwg/topology/2.0/'; \n");
- qb.append("let $list := (\n");
-
- boolean first = true;
- for (String r : resultSet) {
- if ("".equals(r)) {
- logger.debug("service URL empty - omit");
- } else {
- if (first) first=false;
- else qb.append(", \n");
- qb.append("'"+r+"'");
- }
- }
- //if no address accepted, do not perform second query, return null
- if (first == true) return null; //!!
-
- qb.append(") \n");
- qb.append("for $id in $list \n");
- qb.append("let $m :=
/nmwg:store[@type='LSStore']/nmwg:metadata[@id=$id]
\n");
- qb.append("return $m \n");
-
- String query = qb.toString();
- if (verbose)
logger.debug("\n------------------------------------------------\nQUERY
2:\n------------------------------------------------\n"+query+"\n");
- XMLDBResult results = dao.performXQuery(query);
- return results.getResults();
- }
+ // parse all metadata elements from resultSet and put
them info data
+ // (add results to message)
+ if (results != null) {
+ for (Element e : results) {
+ if ("metadata".equals(e.getName())) {
+ logger.debug("Add result
metadata [" + e.getId()
+ + "] to data
[" + data.getId() + "]");
+ data.addChild(e);
+ }
+ }
+ } else {
+ // generate result code when no results
+ addNothingFoundMessage(data);
+ }
+ }
+ // return the response (either for success or error)
+ serviceResponse.setElement(response);
+ }
- private HashSet<String> queryForListOfServices(Element subject) throws
PerfSONARException {
+ private void addNothingFoundMessage(Data data) {
- logger.debug("Subject found");
-
- //create query generator passing subject
- DiscoveryQueryGenerator gen = new DiscoveryQueryGenerator(subject);
- String query = gen.generateQuery();
- logger.debug(gen.printQueryParameters());
+ logger.debug("Result set empty - generating result code");
- /* XQuery. Will return string array containing metadata blocks*/
- logger.debug("perform search with XQuery");
- /*
- * Query 1 - service names
- */
-
logger.debug("\n------------------------------------------------\nQUERY
1:\n------------------------------------------------\n"+query+"\n");
+ Element datum = new Element("datum", "nmwgr",
+ "http://ggf.org/ns/nmwg/result/2.0/");
+ datum.setText("Nothing returned for search.");
+ data.addChild(datum);
+ }
- XMLDBResult dbres = dao.performXQuery(query);
- String[] resultArr = dbres.getTextResults();
-
- //copy to set removing duplicates
- HashSet<String> resultSet = new HashSet<String>();
- try {
- for (String r : resultArr) {
- resultSet.add(r);
- }
- } catch (RuntimeException rex) {
- //just break if NullPointer or other runtime ex.
- }
- return resultSet;
- }
+ /**
+ * Performs query and returns list of metadata blocks If no metadata
block,
+ * null is returned
+ *
+ * @param resultSet
+ * @return
+ * @throws PerfSONARException
+ */
+ private Collection<Element> queryForServicesMetadata(
+ HashSet<String> resultSet) throws PerfSONARException {
+ // generate specific query for metadata blocks
+ StringBuffer qb = new StringBuffer();
+ qb
+ .append("declare namespace
nmwg='http://ggf.org/ns/nmwg/base/2.0/'; \n");
+ qb
+ .append("declare namespace
nmwgt='http://ggf.org/ns/nmwg/topology/2.0/'; \n");
+ qb.append("let $list := (\n");
+ boolean first = true;
+ for (String r : resultSet) {
+ if ("".equals(r)) {
+ logger.debug("service URL empty - omit");
+ } else {
+ if (first)
+ first = false;
+ else
+ qb.append(", \n");
+ qb.append("'" + r + "'");
+ }
+ }
+ // if no address accepted, do not perform second query,
return null
+ if (first == true)
+ return null; // !!
+
+ qb.append(") \n");
+ qb.append("for $id in $list \n");
+ qb
+ .append("let $m :=
/nmwg:store[@type='LSStore']/nmwg:metadata[@id=$id]
\n");
+ qb.append("return $m \n");
+
+ String query = qb.toString();
+ if (verbose)
+ logger
+
.debug("\n------------------------------------------------\nQUERY
2:\n------------------------------------------------\n"
+ + query + "\n");
+ XMLDBResult results = dao.performXQuery(query);
+ return results.getResults();
+ }
+
+ private HashSet<String> queryForListOfServices(Element subject)
+ throws PerfSONARException {
+
+ logger.debug("Subject found");
+
+ // create query generator passing subject
+ DiscoveryQueryGenerator gen = new
DiscoveryQueryGenerator(subject);
+ String query = gen.generateQuery();
+ logger.debug(gen.printQueryParameters());
+
+ /* XQuery. Will return string array containing metadata
blocks */
+ logger.debug("perform search with XQuery");
+ /*
+ * Query 1 - service names
+ */
+ logger
+
.debug("\n------------------------------------------------\nQUERY
1:\n------------------------------------------------\n"
+ + query + "\n");
+
+ XMLDBResult dbres = dao.performXQuery(query);
+ String[] resultArr = dbres.getTextResults();
+
+ // copy to set removing duplicates
+ HashSet<String> resultSet = new HashSet<String>();
+ for (String r : resultArr) {
+ resultSet.add(r);
+ }
+ return resultSet;
+ }
+
}
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-11-30 12:59:54 UTC (rev 5360)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/LSQueryServiceEngine.java
2009-11-30 13:17:51 UTC (rev 5361)
@@ -82,7 +82,9 @@
try {
eventType = m.getFirstEventType().getEventType();
logger.debug("Found eventType [+eventType+]");
- } catch (Exception ex) {}
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
//try to get subject
try {
@@ -90,7 +92,9 @@
metadataWithSubject = m;
logger.debug("Found subject (namespace
"+subject.getNamespacePrefix()+")");
- } catch (Exception ex) {}
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
//try to get parameters
try {
@@ -98,6 +102,8 @@
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) {
+ //TODO : improve it !!
+ //ex.printStackTrace();
}
}
Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/LSRegisterServiceEngine.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/LSRegisterServiceEngine.java
2009-11-30 12:59:54 UTC (rev 5360)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/LSRegisterServiceEngine.java
2009-11-30 13:17:51 UTC (rev 5361)
@@ -162,6 +162,7 @@
logger.debug("[LS Registration] Key from metadata=["
+ keyValue
+ "]");
} catch (Exception ex) {
+ ex.printStackTrace();
}
// ========check metadata========
Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/ThreadPoolComponent.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/ThreadPoolComponent.java
2009-11-30 12:59:54 UTC (rev 5360)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/ThreadPoolComponent.java
2009-11-30 13:17:51 UTC (rev 5361)
@@ -16,7 +16,9 @@
try {
maximumNumberOfThreads =
this.getOption("max").getValueAsInteger();
- } catch (Exception e) { }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
pool = Executors.newFixedThreadPool(maximumNumberOfThreads);
}
Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/registration/LsTTLParameterStatus.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/registration/LsTTLParameterStatus.java
2009-11-30 12:59:54 UTC (rev 5360)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/registration/LsTTLParameterStatus.java
2009-11-30 13:17:51 UTC (rev 5361)
@@ -1,13 +1,11 @@
package org.perfsonar.service.lookupservice.registration;
+import java.util.Locale;
+
public enum LsTTLParameterStatus {
- NONE,
- ACCEPTED,
- OUT_OF_BOUND,
- NOT_A_NUMBER;
-
-
- public String toString(){
- return this.name().toLowerCase();
+ NONE, ACCEPTED, OUT_OF_BOUND, NOT_A_NUMBER;
+
+ public String toString() {
+ return this.name().toLowerCase(Locale.getDefault());
}
}
Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/registration/summarization/Trie.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/registration/summarization/Trie.java
2009-11-30 12:59:54 UTC (rev 5360)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/registration/summarization/Trie.java
2009-11-30 13:17:51 UTC (rev 5361)
@@ -10,238 +10,244 @@
* Summarization code
*
* @author swany
- *
+ *
*/
public class Trie {
- private int nodeCount;
+ private int nodeCount;
- private ArrayList<TrieNode> keyList = new ArrayList<TrieNode>();
+ private ArrayList<TrieNode> keyList = new ArrayList<TrieNode>();
- public ArrayList<TrieNode> getKeyList() {
- return keyList;
- }
+ public ArrayList<TrieNode> getKeyList() {
+ return keyList;
+ }
- private TrieNode rootNode;
+ private TrieNode rootNode;
- public Trie(TrieNode rootnode) {
- rootNode = rootnode;
- }
+ public Trie(TrieNode rootnode) {
+ rootNode = rootnode;
+ }
- public TrieNode getRootNode() {
- return rootNode;
- }
-
- private long firstDigit(long key, long keyLength) {
- return ((key >> (keyLength - 1)) & 1);
- }
+ public TrieNode getRootNode() {
+ return rootNode;
+ }
- public Trie Add(long key, long keyLength, Object data) {
- nodeCount++;
- rootNode.incrementChildCount();
-
- if (firstDigit(key, keyLength) == 1) {
- if (rootNode.getChildOne() != null) {
- rootNode.getChildOne().Add(key, keyLength, data);
- }
- else {
- rootNode.setChildOne(new TrieNode(key, keyLength));
- rootNode.getChildOne().setData(data);
- }
- } else {
- if (rootNode.getChildZero() != null) {
- rootNode.getChildZero().Add(key, keyLength, data);
- }
- else {
- rootNode.setChildZero(new TrieNode(key, keyLength));
- rootNode.getChildZero().setData(data);
- }
- }
- return this;
- }
+ private long firstDigit(long key, long keyLength) {
+ return ((key >> (keyLength - 1)) & 1);
+ }
- public boolean FindExactMatch(long key, long keyLength) {
- if (firstDigit(key, keyLength) == 1)
- return rootNode.getChildOne() != null &&
rootNode.getChildOne().FindExactMatch(key, keyLength);
- else
- return rootNode.getChildZero() != null &&
rootNode.getChildZero().FindExactMatch(key, keyLength);
- }
+ public Trie Add(long key, long keyLength, Object data) {
+ nodeCount++;
+ rootNode.incrementChildCount();
- // public Trie Merge(Trie trie) {
- // List<Long> keys = trie.GetKeys();
- // for (Long key : keys)
- // this.Add(Long.parseLong(key.toString()),
Constants.MAX_KEY_LENGTH);
- // return this;
- // }
+ if (firstDigit(key, keyLength) == 1) {
+ if (rootNode.getChildOne() != null) {
+ rootNode.getChildOne().Add(key, keyLength,
data);
+ } else {
+ rootNode.setChildOne(new TrieNode(key,
keyLength));
+ rootNode.getChildOne().setData(data);
+ }
+ } else {
+ if (rootNode.getChildZero() != null) {
+ rootNode.getChildZero().Add(key, keyLength,
data);
+ } else {
+ rootNode.setChildZero(new TrieNode(key,
keyLength));
+ rootNode.getChildZero().setData(data);
+ }
+ }
+ return this;
+ }
- public List<Long> GetKeys() {
- long key = 0;
- long position = Constants.MAX_KEY_LENGTH;
- List<Long> keys = new ArrayList<Long>();
+ public boolean FindExactMatch(long key, long keyLength) {
+ if (firstDigit(key, keyLength) == 1)
+ return rootNode.getChildOne() != null
+ &&
rootNode.getChildOne().FindExactMatch(key, keyLength);
+ else
+ return rootNode.getChildZero() != null
+ &&
rootNode.getChildZero().FindExactMatch(key, keyLength);
+ }
- if (rootNode.getChildZero() != null)
- keys = GetKeys(keys, rootNode.getChildZero(), key, position);
+ // public Trie Merge(Trie trie) {
+ // List<Long> keys = trie.GetKeys();
+ // for (Long key : keys)
+ // this.Add(Long.parseLong(key.toString()), Constants.MAX_KEY_LENGTH);
+ // return this;
+ // }
- if (rootNode.getChildOne() != null)
- keys = GetKeys(keys, rootNode.getChildOne(), key, position);
+ public List<Long> GetKeys() {
+ long key = 0;
+ long position = Constants.MAX_KEY_LENGTH;
+ List<Long> keys = new ArrayList<Long>();
- return keys;
- }
+ if (rootNode.getChildZero() != null)
+ keys = GetKeys(keys, rootNode.getChildZero(), key,
position);
- private List<Long> GetKeys(List<Long> keys, TrieNode node, long key,
long position) {
- key = key | (node.getKey() << (position - node.getKeyLength()));
+ if (rootNode.getChildOne() != null)
+ keys = GetKeys(keys, rootNode.getChildOne(), key,
position);
- if (node.getChildZero() != null)
- keys = GetKeys(keys, node.getChildZero(), key, position -
node.getKeyLength());
- if (node.getChildOne() != null)
- keys = GetKeys(keys, node.getChildOne(), key, position -
node.getKeyLength());
+ return keys;
+ }
- for (long i = 0; i < node.getValueCount(); i++) {
- keys.add(key);
- }
- return keys;
- }
+ private List<Long> GetKeys(List<Long> keys, TrieNode node, long key,
+ long position) {
+ key = key | (node.getKey() << (position -
node.getKeyLength()));
- //returns the best match of keys for the given inputs
- public TrieNode FindBestMatch(long key, long keyLength) {
- //implements the best match by digging all the way to the leaf based
on the key difference.
- if (firstDigit(key, keyLength) == 1) {
- if (rootNode.getChildOne() != null)
- return rootNode.getChildOne().FindBestMatch(key, keyLength);
- else
- return null;
- } else if (rootNode.getChildZero() == null)
- return null;
- return rootNode.getChildZero().FindBestMatch(key, keyLength);
- }
+ if (node.getChildZero() != null)
+ keys = GetKeys(keys, node.getChildZero(), key,
position
+ - node.getKeyLength());
+ if (node.getChildOne() != null)
+ keys = GetKeys(keys, node.getChildOne(), key, position
+ - node.getKeyLength());
- public boolean Equals(Trie trie) {
- if (trie != null) {
- if (this.getCount() == trie.getCount()) {
- List<Long> list1 = this.GetKeys();
- List<Long> list2 = trie.GetKeys();
+ for (long i = 0; i < node.getValueCount(); i++) {
+ keys.add(key);
+ }
+ return keys;
+ }
- for (int i = 0; i < this.nodeCount; i++) {
- if (!list1.get(i).equals(list2.get(i)))
- return false;
- }
- return true;
- }
- }
- return false;
- }
+ // returns the best match of keys for the given inputs
+ public TrieNode FindBestMatch(long key, long keyLength) {
+ // implements the best match by digging all the way to the
leaf based on
+ // the key difference.
+ if (firstDigit(key, keyLength) == 1) {
+ if (rootNode.getChildOne() != null)
+ return
rootNode.getChildOne().FindBestMatch(key, keyLength);
+ else
+ return null;
+ } else if (rootNode.getChildZero() == null)
+ return null;
+ return rootNode.getChildZero().FindBestMatch(key, keyLength);
+ }
- public long getCount() {
- return nodeCount;
- }
+ public boolean Equals(Trie trie) {
+ if (trie != null && (this.getCount() == trie.getCount())) {
+ List<Long> list1 = this.GetKeys();
+ List<Long> list2 = trie.GetKeys();
- public boolean Remove(long key, long keyLength) {
- TrieNode root;
+ for (int i = 0; i < this.nodeCount; i++) {
+ if (!list1.get(i).equals(list2.get(i)))
+ return false;
+ }
+ return true;
+ }
+ return false;
+ }
- root = firstDigit(key, keyLength) == 1 ? rootNode.getChildOne() :
rootNode.getChildZero();
+ public long getCount() {
+ return nodeCount;
+ }
- if (Remove(root, key, keyLength, 0)) {
- nodeCount--;
- return true;
- }
- return false;
- }
+ public boolean Remove(long key, long keyLength) {
+ TrieNode root;
- private boolean Remove(TrieNode node, long key, long keyLength, long
currentKeyLength) {
+ root = firstDigit(key, keyLength) == 1 ?
rootNode.getChildOne()
+ : rootNode.getChildZero();
- boolean success;
- TrieNode child;
+ if (Remove(root, key, keyLength, 0)) {
+ nodeCount--;
+ return true;
+ }
+ return false;
+ }
- currentKeyLength += node.getKeyLength();
+ private boolean Remove(TrieNode node, long key, long keyLength,
+ long currentKeyLength) {
- if (currentKeyLength == keyLength && node.getKey() == (key & 1)) {
- // by setting node.m_valueCount to -1, we indicate that it can
be deleted
- if (node.getValueCount() > 1)
- node.setValueCount(node.getValueCount() - 1);
- else {
- if (node.getChildZero() == null && node.getChildOne() ==
null)
- node.setValueCount(node.getValueCount() - 1);
- else
- node.setValueCount(0);
- }
- return true;
- } else if (firstDigit(key, keyLength - currentKeyLength) == 1)
- child = node.getChildOne();
- else
- child = node.getChildZero();
+ boolean success;
+ TrieNode child;
- success = ((child != null) && Remove(child, key, keyLength,
currentKeyLength));
+ currentKeyLength += node.getKeyLength();
- if (success) {
- // check if we need to delete nodes as we go back along the path
- // the node is safe to be deleted if its valueCount = -1
+ if (currentKeyLength == keyLength && node.getKey() == (key &
1)) {
+ // by setting node.m_valueCount to -1, we indicate
that it can be
+ // deleted
+ if (node.getValueCount() > 1)
+ node.setValueCount(node.getValueCount() - 1);
+ else {
+ if (node.getChildZero() == null &&
node.getChildOne() == null)
+
node.setValueCount(node.getValueCount() - 1);
+ else
+ node.setValueCount(0);
+ }
+ return true;
+ } else if (firstDigit(key, keyLength - currentKeyLength) == 1)
+ child = node.getChildOne();
+ else
+ child = node.getChildZero();
- if (child.getValueCount() < 0) {
- if (child.getKey() == 1)
- node.setChildOne(null);
- else
- node.setChildZero(null);
+ success = ((child != null) && Remove(child, key, keyLength,
+ currentKeyLength));
- if (node.getValueCount() == 0 && node.getChildZero() == null
&& node.getChildOne() == null)
- node.setValueCount(-1);
- }
- }
- return success;
- }
+ if (success && child.getValueCount() < 0) {
+ // check if we need to delete nodes as we go back
along the path
+ // the node is safe to be deleted if its valueCount =
-1
+ if (child.getKey() == 1)
+ node.setChildOne(null);
+ else
+ node.setChildZero(null);
- public void mostDominantKeyList() {
+ if (node.getValueCount() == 0 && node.getChildZero()
== null
+ && node.getChildOne() == null)
+ node.setValueCount(-1);
+ }
+ return success;
+ }
- TrieNode childOne = rootNode.getChildOne();
- TrieNode childZero = rootNode.getChildZero();
+ public void mostDominantKeyList() {
- if (childOne != null) {
- mostDominantKeyList(childOne, childOne.getKey(),
Constants.MAX_KEY_LENGTH);
- }
- if (childZero != null) {
- mostDominantKeyList(childZero, childZero.getKey(),
Constants.MAX_KEY_LENGTH);
- }
- }
+ TrieNode childOne = rootNode.getChildOne();
+ TrieNode childZero = rootNode.getChildZero();
- private void mostDominantKeyList(TrieNode node, long key, long position)
{
+ if (childOne != null) {
+ mostDominantKeyList(childOne, childOne.getKey(),
+ Constants.MAX_KEY_LENGTH);
+ }
+ if (childZero != null) {
+ mostDominantKeyList(childZero, childZero.getKey(),
+ Constants.MAX_KEY_LENGTH);
+ }
+ }
- TrieNode childZero = node.getChildZero();
- TrieNode childOne = node.getChildOne();
+ private void mostDominantKeyList(TrieNode node, long key, long
position) {
- key = key | (node.getKey() << (position - node.getKeyLength()));
- position = position - node.getKeyLength();
- if (childZero != null) {
- mostDominantKeyList(childZero, key, position);
- }
- if (childOne != null) {
- mostDominantKeyList(childOne, key, position);
- }
- if ((node.getChildOne() != null) && (node.getChildZero() != null))
- keyList.add(new TrieNode(key, position));
- }
-
- public void printDot(String fileName) throws FileNotFoundException {
- FileOutputStream file = new FileOutputStream(fileName);
- PrintStream p = new PrintStream(file);
- long position = Constants.MAX_KEY_LENGTH;
- long currentKey = 0;
- p.println("digraph g {");
- rootNode.printDotNode(p, rootNode, position, currentKey);
- p.println("}");
- p.close();
- }
-
- public ArrayList<String> listInternalNodes() {
- long position = Constants.MAX_KEY_LENGTH;
- long currentKey = 0;
- ArrayList<String> listOfNodes = new ArrayList<String>();
- rootNode.listInternalNodes(listOfNodes, position, currentKey);
- return listOfNodes;
- }
-
- public ArrayList<String> listSummaryNodes() {
- long position = Constants.MAX_KEY_LENGTH;
- long currentKey = 0;
- ArrayList<String> listOfNodes = new ArrayList<String>();
- rootNode.listSummaryNodes(listOfNodes, position, currentKey);
- return listOfNodes;
- }
+ TrieNode childZero = node.getChildZero();
+ TrieNode childOne = node.getChildOne();
+
+ key = key | (node.getKey() << (position -
node.getKeyLength()));
+ position = position - node.getKeyLength();
+ if (childZero != null) {
+ mostDominantKeyList(childZero, key, position);
+ }
+ if (childOne != null) {
+ mostDominantKeyList(childOne, key, position);
+ }
+ if ((node.getChildOne() != null) && (node.getChildZero() !=
null))
+ keyList.add(new TrieNode(key, position));
+ }
+
+ public void printDot(String fileName) throws FileNotFoundException {
+ FileOutputStream file = new FileOutputStream(fileName);
+ PrintStream p = new PrintStream(file);
+ long position = Constants.MAX_KEY_LENGTH;
+ long currentKey = 0;
+ p.println("digraph g {");
+ rootNode.printDotNode(p, rootNode, position, currentKey);
+ p.println("}");
+ p.close();
+ }
+
+ public ArrayList<String> listInternalNodes() {
+ long position = Constants.MAX_KEY_LENGTH;
+ long currentKey = 0;
+ ArrayList<String> listOfNodes = new ArrayList<String>();
+ rootNode.listInternalNodes(listOfNodes, position, currentKey);
+ return listOfNodes;
+ }
+
+ public ArrayList<String> listSummaryNodes() {
+ long position = Constants.MAX_KEY_LENGTH;
+ long currentKey = 0;
+ ArrayList<String> listOfNodes = new ArrayList<String>();
+ rootNode.listSummaryNodes(listOfNodes, position, currentKey);
+ return listOfNodes;
+ }
}
Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/registration/summarization/TrieNode.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/registration/summarization/TrieNode.java
2009-11-30 12:59:54 UTC (rev 5360)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/registration/summarization/TrieNode.java
2009-11-30 13:17:51 UTC (rev 5361)
@@ -172,9 +172,6 @@
if(newNode.childOne == null && newNode.childZero == null){
this.childCount++;
- if(newNode.childCount > 1) {
- //System.out.println("--confusion--");
- }
newNode.childCount = 0;
}
}
Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/servlets/ExistDbInitializerServlet.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/servlets/ExistDbInitializerServlet.java
2009-11-30 12:59:54 UTC (rev 5360)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/servlets/ExistDbInitializerServlet.java
2009-11-30 13:17:51 UTC (rev 5361)
@@ -4,6 +4,7 @@
import java.io.IOException;
import java.io.PrintWriter;
import java.net.URISyntaxException;
+import java.util.Locale;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
@@ -148,11 +149,13 @@
*/
protected boolean allowUser(String auth, String username, String
password)
throws IOException {
- if (auth == null)
+ if (auth == null){
return false;
+ }
- if (!auth.toUpperCase().startsWith("BASIC "))
+ if (!auth.toUpperCase(Locale.getDefault()).startsWith("BASIC
")){
return false;
+ }
String userpassEncoded = auth.substring(6);
Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/storage/LookupServiceDAOFactory.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/storage/LookupServiceDAOFactory.java
2009-11-30 12:59:54 UTC (rev 5360)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/storage/LookupServiceDAOFactory.java
2009-11-30 13:17:51 UTC (rev 5361)
@@ -9,9 +9,9 @@
private static Logger
logger=Logger.getLogger(LookupServiceDAOFactory.class);
- private static LookupServiceDAO dao = null;
- private static LookupServiceDAO daoRO = null;
- private static SummarizationDAO summariaztionDAO=null;
+ private static volatile LookupServiceDAO dao = null;
+ private static volatile LookupServiceDAO daoRO = null;
+ private static volatile SummarizationDAO summariaztionDAO=null;
private final static String LS_DAO = "lsdao";
private final static String LS_DAO_RO = "lsdao-ro";
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-11-30 12:59:54 UTC (rev 5360)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/storage/exist/CommonExistDAOImpl.java
2009-11-30 13:17:51 UTC (rev 5361)
@@ -28,18 +28,17 @@
private XMLDataStorage dataStorage;
private String dataCollection;
private DataCredential dataCredential;
-
- /**
- * The name of the store collection (containing LS data/metadata
- */
- public static final String LS_STORE_COLLECTION_TYPE = "LSStore";
-
-
- /**
- * The name of the control collection of LS
- */
- public static final String LS_STORE_CONTROL_COLLECTION_TYPE =
"LSStore-control";
+ /**
+ * The name of the store collection (containing LS data/metadata
+ */
+ public static final String LS_STORE_COLLECTION_TYPE = "LSStore";
+
+ /**
+ * The name of the control collection of LS
+ */
+ 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";
/**
@@ -57,24 +56,17 @@
}
public void init() throws PerfSONARException {
- try {
- String existConfigComponent =
getOption("exist-config").getValue();
- XMLDBComponent xmlDbComponent = (XMLDBComponent)
ConfigurationManager
-
.getInstance().getConfiguration().getAuxiliaryComponent(
- existConfigComponent);
+ 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");
- }
-
+ setDataCollection(xmlDbComponent.getUri());
+ setDataCredential(xmlDbComponent.getCredential());
}
public void destroy() throws PerfSONARException {
-
+
}
public void run() {
Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/storage/exist/MultipleFilesExistDAOImpl.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/storage/exist/MultipleFilesExistDAOImpl.java
2009-11-30 12:59:54 UTC (rev 5360)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/storage/exist/MultipleFilesExistDAOImpl.java
2009-11-30 13:17:51 UTC (rev 5361)
@@ -1,8 +1,11 @@
package org.perfsonar.service.lookupservice.storage.exist;
+import java.io.IOException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
+import javax.xml.stream.XMLStreamException;
+
import org.perfsonar.base2.service.exceptions.PerfSONARException;
import org.perfsonar.base2.service.storage.xml.XMLDBResult;
import org.perfsonar.base2.xml.Element;
@@ -20,7 +23,6 @@
*/
public class MultipleFilesExistDAOImpl extends XQueryDAOSupportImpl {
- //
---------------------------------------------------------------constants
private static final String XMLNS = "
xmlns:nmwgt=\"http://ggf.org/ns/nmwg/topology/2.0/\" "
+ " xmlns:nmwg=\"http://ggf.org/ns/nmwg/base/2.0/\" "
@@ -33,10 +35,6 @@
private static final String LS_STORE_FOOTER = "\n</nmwg:store>";
- public MultipleFilesExistDAOImpl() {
- super();
- }
-
public void putLookupInfo(Metadata m, Data[] d) throws
PerfSONARException {
StringBuffer sb = new StringBuffer();
@@ -49,21 +47,25 @@
StringBufferOutputStream os = new
StringBufferOutputStream(sb);
// convert metadata to String
- try {
// put metadata
- ser.write(os, m);
-
- // put datas
- for (int i = 0; i < d.length; i++) {
- ser.write(os, d[i]);
+ try {
+ ser.write(os, m);
+ // put datas
+ for (int i = 0; i < d.length; i++) {
+ ser.write(os, d[i]);
+ }
+ } catch (XMLStreamException e1) {
+ throw new PerfSONARException("error/parse",
+ "Cannot serialize elements in
MulipleFilesExistDAOImpl");
+ } catch (IOException e1) {
+ throw new PerfSONARException("error/parse",
+ "Cannot serialize elements in
MulipleFilesExistDAOImpl");
}
- } catch (Exception e) {
- throw new PerfSONARException("error/parse",
- "Cannot serialize elements in
MulipleFilesExistDAOImpl");
- }
+
+
sb.append(LS_STORE_FOOTER);
// convert to md5
@@ -71,7 +73,7 @@
try {
uploadStoreFile(md5(m.getId()) + ".xml",
sb.toString());
} catch (NoSuchAlgorithmException e) {
- e.printStackTrace();
+ throw new PerfSONARException("md5 - algorithm not
found",e);
}
}
@@ -83,7 +85,7 @@
try {
removeFile(md5(metadataId) + ".xml");
} catch (NoSuchAlgorithmException e) {
- e.printStackTrace();
+ throw new PerfSONARException("md5 - algorithm not
found",e);
}
String xquery = XQUERY_DECLARE_NAMESPACES + " for $i in " +
"("
Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/storage/exist/SummarizationDAOImpl.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/storage/exist/SummarizationDAOImpl.java
2009-11-30 12:59:54 UTC (rev 5360)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/storage/exist/SummarizationDAOImpl.java
2009-11-30 13:17:51 UTC (rev 5361)
@@ -1,8 +1,11 @@
package org.perfsonar.service.lookupservice.storage.exist;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import javax.xml.stream.XMLStreamException;
+
import org.perfsonar.base2.service.exceptions.PerfSONARException;
import org.perfsonar.base2.service.storage.xml.XMLDBResult;
import org.perfsonar.base2.xml.Element;
@@ -30,10 +33,10 @@
StringBuffer sb = new StringBuffer();
- // performance improvement
-// sb.append(LOCK);
+ // performance improvement
+ // sb.append(LOCK);
sb.append("xmldb:copy('/db/copy/', '/db/ls/',
'LSStore-summary.xml')");
-// sb.append(")");
+ // sb.append(")");
performXQuery(sb.toString());
}
@@ -51,10 +54,14 @@
try {
ser.write(os, m);
- } catch (Exception e) {
+ } catch (XMLStreamException e) {
throw new PerfSONARException("error/parse",
"Cannot serialize elements in
XQueryExistDAOImpl");
+ } catch (IOException e) {
+ throw new PerfSONARException("error/parse",
+ "Cannot serialize elements in
XQueryExistDAOImpl");
}
+
// send XQuery
xmls.append(" )\n");
@@ -69,11 +76,14 @@
StringBuffer sb = new StringBuffer();
- sb.append(" declare namespace
nmwg=\"http://ggf.org/ns/nmwg/base/2.0/\"; \n");
+ sb
+ .append(" declare namespace
nmwg=\"http://ggf.org/ns/nmwg/base/2.0/\"; \n");
sb.append(" for $d in
/nmwg:store[@type='LSStore']/nmwg:data
\n");
sb.append(" let $metaIdRef := data($d/@metadataIdRef) \n");
- sb.append(" for $val in
$d/nmwg:metadata/*:subject//*:ifAddress/text() \n");
- sb.append(" return if (empty($val)) then $val else
concat($metaIdRef,',',$val) \n");
+ sb
+ .append(" for $val in
$d/nmwg:metadata/*:subject//*:ifAddress/text() \n");
+ sb
+ .append(" return if (empty($val)) then $val
else concat($metaIdRef,',',$val) \n");
return performXQuery(sb.toString()).getTextResults();
@@ -121,9 +131,7 @@
public XMLDBResult getSummaryData() throws PerfSONARException {
StringBuffer sb = new StringBuffer();
sb.append(DECLARE_NMWG_NAMESPACE);
-// sb.append(LOCK);
sb.append("/nmwg:store[@type='LSStore-summary']/nmwg:metadata");
-// sb.append(")");
return performXQuery(sb.toString());
}
@@ -143,16 +151,17 @@
for (int c = 0; c < data.size(); c++) {
Element element = data.get(c);
try {
-
ser.write(os, element);
- if (c != data.size() - 1) {
- xmls.append(", \n");
- }
-
- } catch (Exception e) {
+ } catch (XMLStreamException e) {
throw new PerfSONARException("error/parse",
"Cannot serialize elements in
XQueryExistDAOImpl");
+ } catch (IOException e) {
+ throw new PerfSONARException("error/parse",
+ "Cannot serialize elements in
XQueryExistDAOImpl");
}
+ if (c != data.size() - 1) {
+ xmls.append(", \n");
+ }
}
// send XQuery
xmls.append(" )\n");
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-11-30 12:59:54 UTC (rev 5360)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/storage/exist/XQueryExistDAOImpl.java
2009-11-30 13:17:51 UTC (rev 5361)
@@ -1,5 +1,9 @@
package org.perfsonar.service.lookupservice.storage.exist;
+import java.io.IOException;
+
+import javax.xml.stream.XMLStreamException;
+
import org.perfsonar.base2.service.exceptions.PerfSONARException;
import org.perfsonar.base2.service.storage.xml.XMLDBResult;
import org.perfsonar.base2.xml.ElementSerializer;
@@ -67,23 +71,24 @@
xmls.append(" (\n"); // IMPORTANT - begin Xquery collection
(m, d, d,
// ...)
- try {
// add metadata to StringBuffer
- ser.write(os, m);
-
- // convert data to Strings
- for (int i = 0; i < d.length; i++) {
- xmls.append(", \n"); // IMPORTANT - separator
for next element
- // of Xquery collection (m, d, d, ...)
- ser.write(os, d[i]);
-
+ try {
+ ser.write(os, m);
+ // convert data to Strings
+ for (int i = 0; i < d.length; i++) {
+ xmls.append(", \n"); // IMPORTANT -
separator for next element
+ // of Xquery collection (m, d, d, ...)
+ ser.write(os, d[i]);
+ }
+ } catch (XMLStreamException e) {
+ throw new PerfSONARException("error/parse",
+ "Cannot serialize elements in
XQueryExistDAOImpl");
+ } catch (IOException e) {
+ throw new PerfSONARException("error/parse",
+ "Cannot serialize elements in
XQueryExistDAOImpl");
}
- } catch (Exception e) {
- throw new PerfSONARException("error/parse",
- "Cannot serialize elements in
XQueryExistDAOImpl");
- }
// send XQuery
xmls.append(" )\n"); // IMPORTANT - end of Xquery collection
(m, d, d,
// ...)
Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/summarization/SummarizationBuilder.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/summarization/SummarizationBuilder.java
2009-11-30 12:59:54 UTC (rev 5360)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/summarization/SummarizationBuilder.java
2009-11-30 13:17:51 UTC (rev 5361)
@@ -16,32 +16,27 @@
import
org.perfsonar.service.lookupservice.registration.summarization.SummarizeIpAddrs;
import org.perfsonar.service.lookupservice.storage.SummarizationDAO;
-
-
/**
- *
+ *
* Builds summarization message
*
* @author Slawomir Trzaszczka
*/
public class SummarizationBuilder {
- private final Logger logger = Logger
- .getLogger(SummarizationBuilder.class);
-
- private enum SummarizationVariableType{
- IP,DOMAIN,EVENT_TYPE,KEYWORD;
+ private final Logger logger =
Logger.getLogger(SummarizationBuilder.class);
+
+ private enum SummarizationVariableType {
+ IP, DOMAIN, EVENT_TYPE, KEYWORD;
};
-
+
private SummarizationDAO dao;
-
-
- public SummarizationBuilder(SummarizationDAO dao){
+
+ public SummarizationBuilder(SummarizationDAO dao) {
this.dao = dao;
}
-
-
- public List<Element> build(){
+
+ public List<Element> build() {
logger.debug("Getting Summary register data");
// get all topology information (IPs)
@@ -50,87 +45,90 @@
Map<String, ServiceSummary> summaries = null;
try {
summaries = getAllServicesSummaries();
- } catch (PerfSONARException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- // now having all data in "summaries" structure and need to
summarize
- // IPs, domains separately. EventTypes will remain the same.
+
+
+ // now having all data in "summaries" structure and
need to summarize
+ // IPs, domains separately. EventTypes will remain
the same.
+ // boolean doIPSummarization =
+ //
config.getProperty("service.ls.do_ip_summarization");
+ // work on the same data - summarize and store in
"summaries" structure
+ for (ServiceSummary s : summaries.values()) {
- // boolean doIPSummarization =
- // config.getProperty("service.ls.do_ip_summarization");
- // work on the same data - summarize and store in "summaries"
structure
- for (ServiceSummary s : summaries.values()) {
+ // summarize IPs
+
s.setIpAddresses(summarizeIPAddresses(s.getIpAddresses()));
- // summarize IPs
-
s.setIpAddresses(summarizeIPAddresses(s.getIpAddresses()));
+ // summarize domains
+
s.setDomains(summarizeDomains(s.getDomains()));
- // summarize domains
- s.setDomains(summarizeDomains(s.getDomains()));
+ // summarize eventTypes
+ // no summarization, just store
- // summarize eventTypes
- // no summarization, just store
+ // summarize keywords
+ // no summarization, just store
- // summarize keywords
- // no summarization, just store
+ }
- }
+ DiscoveryRequestGenerator gen = new
DiscoveryRequestGenerator();
+ Message msg = gen.createMessageElement();
- DiscoveryRequestGenerator gen = new
DiscoveryRequestGenerator();
- Message msg = gen.createMessageElement();
+ // for every single summary get XML
+ for (Entry<String, ServiceSummary> s :
summaries.entrySet()) {
- // for every single summary get XML
- for (Entry<String, ServiceSummary> s : summaries.entrySet()) {
+ Element subject =
gen.createSubjectElement(msg, s.getKey());
- Element subject = gen.createSubjectElement(msg,
s.getKey());
+ for (String ip :
s.getValue().getIpAddresses()) {
- for (String ip : s.getValue().getIpAddresses()) {
+ // split results - ip/netmask or
assume 32 as netmask if wrong
+ // format
+ String[] ipvals = ip.split("/", 2);
+ if (ipvals.length != 2) {
+ ipvals = new String[] { ip,
"32" };
+ }
+ gen.createAddressElement(subject,
ipvals[0], ipvals[1]);
+ }
- // split results - ip/netmask or assume 32 as
netmask if wrong
- // format
- String[] ipvals = ip.split("/", 2);
- if (ipvals.length != 2) {
- ipvals = new String[] { ip, "32" };
+ for (String dom : s.getValue().getDomains()) {
+ gen.createDomainElement(subject, dom);
}
- gen.createAddressElement(subject, ipvals[0],
ipvals[1]);
- }
- for (String dom : s.getValue().getDomains()) {
- gen.createDomainElement(subject, dom);
- }
+ // get sum of parameters to determine whether
there is any parameter
+ // to be printed
+ int paramsSum =
s.getValue().getEventTypes().size()
+ +
s.getValue().getKeywords().size();
+ // if it is at least one, put it.
+ if (paramsSum > 0) {
+ Element parametersElement = gen
+
.createParametersElement(subject);
- // get sum of parameters to determine whether there
is any parameter
- // to be printed
- int paramsSum = s.getValue().getEventTypes().size()
- + s.getValue().getKeywords().size();
- // if it is at least one, put it.
- if (paramsSum > 0) {
- Element parametersElement = gen
-
.createParametersElement(subject);
-
- for (String evt :
s.getValue().getEventTypes()) {
-
gen.createParameterElement(parametersElement, "eventType",
- evt);
+ for (String evt :
s.getValue().getEventTypes()) {
+
gen.createParameterElement(parametersElement, "eventType",
+ evt);
+ }
+ for (String kw :
s.getValue().getKeywords()) {
+ gen
+
.createParameterElement(parametersElement,
+
"keyword", kw);
+ }
}
- for (String kw : s.getValue().getKeywords()) {
- gen
-
.createParameterElement(parametersElement,
-
"keyword", kw);
- }
+
}
+ return gen.getDataList();
+
+ } catch (PerfSONARException e) {
+ e.printStackTrace();
}
- return gen.getDataList();
+ return null;
}
-
/**
* Get topology data and eventTypes from all services store it in
* Map<String, ServiceSummary>
*
- * @return - map - key - metadataId, value is a set of
Ip/keyword/domain sets
+ * @return - map - key - metadataId, value is a set of
Ip/keyword/domain
+ * sets
*/
private Map<String, ServiceSummary> getAllServicesSummaries()
throws PerfSONARException {
@@ -141,20 +139,18 @@
String[] eventTypeResults = dao.queryEventTypeResults();
String[] keywordResults = dao.queryKeywordResults();
- logger
-
.debug("LSSummaryServiceContent.getAllServicesSummaries: got summary from
database. Number of: ");
- try {
- logger.debug(" - IP: [" + ipResults.length +
"]");
- logger.debug(" - domains: [" +
domainResults.length + "]");
- logger.debug(" - eventvTypes: [" +
eventTypeResults.length
- + "]");
- } catch (Exception ex) {
- }
+
logger.debug("LSSummaryServiceContent.getAllServicesSummaries: got summary
from database. Number of: ");
+ logger.debug("- IP: [" + ipResults.length + "]");
+ logger.debug("- domains: [" + domainResults.length + "]");
+ logger.debug("- eventvTypes: [" + eventTypeResults.length+
"]");
populateSummary(summaries, ipResults,
SummarizationVariableType.IP);
- populateSummary(summaries, domainResults,
SummarizationVariableType.DOMAIN);
- populateSummary(summaries, eventTypeResults,
SummarizationVariableType.EVENT_TYPE);
- populateSummary(summaries, keywordResults,
SummarizationVariableType.KEYWORD);
+ populateSummary(summaries, domainResults,
+ SummarizationVariableType.DOMAIN);
+ populateSummary(summaries, eventTypeResults,
+ SummarizationVariableType.EVENT_TYPE);
+ populateSummary(summaries, keywordResults,
+ SummarizationVariableType.KEYWORD);
return summaries;
@@ -174,7 +170,7 @@
try {
result = SummarizeIpAddrs.getSummary(ipAddresses);
} catch (Exception ex) {
- //TODO: change exception !!
+ // TODO: change exception !!
logger.warn("IP summarization failed. " + "Exception:
" + ex
+ " : " + ex.getMessage());
result = ipAddresses;
@@ -243,6 +239,8 @@
case KEYWORD:
summary.getKeywords().add(content);
break;
+ default :
+ System.err.print("Uknown
SummarizationVariableType");
}
}
Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/utilities/ResourceBundle.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/utilities/ResourceBundle.java
2009-11-30 12:59:54 UTC (rev 5360)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/utilities/ResourceBundle.java
2009-11-30 13:17:51 UTC (rev 5361)
@@ -7,6 +7,7 @@
* Provides oportunity to read messages from properties files
*
* @author Slawomir Trzaszczka
+ *
*/
public class ResourceBundle {
@@ -24,7 +25,7 @@
messageFormat = new MessageFormat("");
}
- public static ResourceBundle getInstance() {
+ public static synchronized ResourceBundle getInstance() {
if (rb == null) {
rb = new ResourceBundle();
}
- perfsonar: r5361 - in branches/new-structure-with-base2/ps-mdm-ls: . src/main/java/org/perfsonar/service/lookupservice src/main/java/org/perfsonar/service/lookupservice/registration src/main/java/org/perfsonar/service/lookupservice/registration/summarization src/main/java/org/perfsonar/service/lookupservice/servlets src/main/java/org/perfsonar/service/lookupservice/storage src/main/java/org/perfsonar/service/lookupservice/storage/exist src/main/java/org/perfsonar/service/lookupservice/summarization src/main/java/org/perfsonar/service/utilities, svnlog, 11/30/2009
Archive powered by MHonArc 2.6.16.