perfsonar-dev - [pS-dev] [GEANT/SA2/ps-java-services] r6032 - in trunk/perfsonar-java-rrd-ma-SQL_backend: . src sr c/checkstyle src/main/java/org/perfsonar/service src/main/ java/org/perfsonar/service/measurementArchive/rrdType src/ main/java/org/perfsonar/service/measurementArchive/rrdType /storage src/main/java/org/perfsonar/service/measurementAr chive/rrdType/storage/exist src/main/java/org/perfsonar/se rvice/measurementArchive/rrdType/storage/exist/query src/m ain/java/org/perfsonar/service/measurementArchive/rrdType/ storage/persistence src/main/java/org/perfsonar/service/me asurementArchive/rrdType/storage/persistence/entity src/ma in/java/org/perfsonar/service/measurementArchive/rrdType/s torage/rrd src/main/java/org/perfsonar/service/measurement Archive/rrdType/storage/sql src/main/java/org/perfsonar/se rvice/measurementArchive/rrdType/storage/sql/query src/mai n/java/org/perfsonar/service/temp
Subject: perfsonar development work
List archive
[pS-dev] [GEANT/SA2/ps-java-services] r6032 - in trunk/perfsonar-java-rrd-ma-SQL_backend: . src sr c/checkstyle src/main/java/org/perfsonar/service src/main/ java/org/perfsonar/service/measurementArchive/rrdType src/ main/java/org/perfsonar/service/measurementArchive/rrdType /storage src/main/java/org/perfsonar/service/measurementAr chive/rrdType/storage/exist src/main/java/org/perfsonar/se rvice/measurementArchive/rrdType/storage/exist/query src/m ain/java/org/perfsonar/service/measurementArchive/rrdType/ storage/persistence src/main/java/org/perfsonar/service/me asurementArchive/rrdType/storage/persistence/entity src/ma in/java/org/perfsonar/service/measurementArchive/rrdType/s torage/rrd src/main/java/org/perfsonar/service/measurement Archive/rrdType/storage/sql src/main/java/org/perfsonar/se rvice/measurementArchive/rrdType/storage/sql/query src/mai n/java/org/perfsonar/service/temp
Chronological Thread
- From:
- To:
- Subject: [pS-dev] [GEANT/SA2/ps-java-services] r6032 - in trunk/perfsonar-java-rrd-ma-SQL_backend: . src sr c/checkstyle src/main/java/org/perfsonar/service src/main/ java/org/perfsonar/service/measurementArchive/rrdType src/ main/java/org/perfsonar/service/measurementArchive/rrdType /storage src/main/java/org/perfsonar/service/measurementAr chive/rrdType/storage/exist src/main/java/org/perfsonar/se rvice/measurementArchive/rrdType/storage/exist/query src/m ain/java/org/perfsonar/service/measurementArchive/rrdType/ storage/persistence src/main/java/org/perfsonar/service/me asurementArchive/rrdType/storage/persistence/entity src/ma in/java/org/perfsonar/service/measurementArchive/rrdType/s torage/rrd src/main/java/org/perfsonar/service/measurement Archive/rrdType/storage/sql src/main/java/org/perfsonar/se rvice/measurementArchive/rrdType/storage/sql/query src/mai n/java/org/perfsonar/service/temp
- Date: Mon, 19 Nov 2012 07:56:19 +0000 (GMT)
Author: nordunet.behrmann
Date: 2012-11-19 07:56:19 +0000 (Mon, 19 Nov 2012)
New Revision: 6032
Added:
trunk/perfsonar-java-rrd-ma-SQL_backend/src/checkstyle/
trunk/perfsonar-java-rrd-ma-SQL_backend/src/checkstyle/checkstyle.xml
Removed:
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/temp/Data.java
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/temp/Metadata.java
Modified:
trunk/perfsonar-java-rrd-ma-SQL_backend/pom.xml
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/Axis2PerfsonarServiceConnPoint.java
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/EchoServiceEngine.java
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/MetadataKeyMessageHandler.java
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/MetadataKeyServiceEngine.java
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/SetupDataServiceEngine.java
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/DataStorageDAO.java
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/DataStorageDAOFactory.java
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/MetadataStorageDAO.java
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/MetadataStorageDAOFactory.java
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/exist/ExistMetadataStorageDAOImpl.java
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/exist/QueryGeneratorManager.java
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/exist/query/DiscardsQueryGenerator.java
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/exist/query/ErrorsQueryGenerator.java
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/exist/query/InterfaceBasedQueryGenerator.java
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/exist/query/QueryGenerator.java
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/exist/query/RandomFetchTestQueryGenerator.java
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/exist/query/SNMPQueryGenerator.java
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/exist/query/UtilizationQueryGenerator.java
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/exist/query/XmlDbAccessTestQueryGenerator.java
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/exist/query/XmlDbContentTestQueryGenerator.java
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/persistence/MetadaKeyResponse.java
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/persistence/SetupDataKeyResponse.java
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/persistence/entity/Interfaces.java
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/rrd/DiscardsResponseGenerator.java
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/rrd/ErrorsResponseGenerator.java
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/rrd/GenericResponseGenerator.java
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/rrd/RRDDataStorageDAOImpl.java
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/rrd/ResponseGenerator.java
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/rrd/Rrd.java
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/rrd/RrdException.java
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/rrd/RrdLibrary.java
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/rrd/TimeDateUtil.java
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/rrd/UtilizationResponseGenerator.java
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/sql/MysqlMetadataStorageDAOImpl.java
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/sql/query/QueryGenerator.java
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/temp/ConnectionTester.java
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/temp/FetchData.java
Log:
perfsonar-java-rrd-ma-SQL_backend: Enforce coding conventions with checkstyle
Also updates lots of classes to follow the coding conventions.
Modified: trunk/perfsonar-java-rrd-ma-SQL_backend/pom.xml
===================================================================
--- trunk/perfsonar-java-rrd-ma-SQL_backend/pom.xml 2012-10-22 15:38:39
UTC (rev 6031)
+++ trunk/perfsonar-java-rrd-ma-SQL_backend/pom.xml 2012-11-19 07:56:19
UTC (rev 6032)
@@ -168,6 +168,28 @@
</executions>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <version>2.9.1</version>
+ <executions>
+ <execution>
+ <id>check-style</id>
+ <goals>
+ <goal>check</goal>
+ </goals>
+ <phase>validate</phase>
+ <configuration>
+ <consoleOutput>true</consoleOutput>
+
<logViolationsToConsole>true</logViolationsToConsole>
+ <failsOnError>true</failsOnError>
+ <failOnViolation>true</failOnViolation>
+
<configLocation>src/checkstyle/checkstyle.xml</configLocation>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
<!-- execution: mvn -Djetty.port=9999 jetty:run-war -->
<plugin>
<groupId>org.mortbay.jetty</groupId>
Added: trunk/perfsonar-java-rrd-ma-SQL_backend/src/checkstyle/checkstyle.xml
===================================================================
--- trunk/perfsonar-java-rrd-ma-SQL_backend/src/checkstyle/checkstyle.xml
(rev 0)
+++ trunk/perfsonar-java-rrd-ma-SQL_backend/src/checkstyle/checkstyle.xml
2012-11-19 07:56:19 UTC (rev 6032)
@@ -0,0 +1,210 @@
+<?xml version="1.0"?>
+<!DOCTYPE module PUBLIC
+ "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
+ "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
+
+<!--
+ Based on the default checkstyle configuration, but with minor
+ modifications based on established conventions in existing
+ perfsonar code.
+-->
+
+<!--
+
+ Checkstyle configuration that checks the sun coding conventions from:
+
+ - the Java Language Specification at
+ http://java.sun.com/docs/books/jls/second_edition/html/index.html
+
+ - the Sun Code Conventions at http://java.sun.com/docs/codeconv/
+
+ - the Javadoc guidelines at
+ http://java.sun.com/j2se/javadoc/writingdoccomments/index.html
+
+ - the JDK Api documentation http://java.sun.com/j2se/docs/api/index.html
+
+ - some best practices
+
+ Checkstyle is very configurable. Be sure to read the documentation at
+ http://checkstyle.sf.net (or in your downloaded distribution).
+
+ Most Checks are configurable, be sure to consult the documentation.
+
+ To completely disable a check, just comment it out or delete it from the
file.
+
+ Finally, it is worth reading the documentation.
+
+-->
+
+<module name="Checker">
+ <!--
+ If you set the basedir property below, then all reported file
+ names will be relative to the specified directory. See
+ http://checkstyle.sourceforge.net/5.x/config.html#Checker
+
+ <property name="basedir" value="${basedir}"/>
+ -->
+
+ <!-- Checks that a package-info.java file exists for each package.
-->
+ <!-- See http://checkstyle.sf.net/config_javadoc.html#JavadocPackage -->
+ <!--module name="JavadocPackage"/-->
+
+ <!-- Checks whether files end with a new line. -->
+ <!-- See http://checkstyle.sf.net/config_misc.html#NewlineAtEndOfFile -->
+ <module name="NewlineAtEndOfFile"/>
+
+ <!-- Checks that property files contain the same keys. -->
+ <!-- See http://checkstyle.sf.net/config_misc.html#Translation -->
+ <module name="Translation"/>
+
+ <!-- Checks for Size Violations. -->
+ <!-- See http://checkstyle.sf.net/config_sizes.html -->
+ <module name="FileLength"/>
+
+ <!-- Checks for whitespace -->
+ <!-- See http://checkstyle.sf.net/config_whitespace.html -->
+ <module name="FileTabCharacter"/>
+
+ <!-- Miscellaneous other checks. -->
+ <!-- See http://checkstyle.sf.net/config_misc.html -->
+ <module name="RegexpSingleline">
+ <property name="format" value="\s+$"/>
+ <property name="minimum" value="0"/>
+ <property name="maximum" value="0"/>
+ <property name="message" value="Line has trailing spaces."/>
+ </module>
+
+ <!-- Checks for Headers -->
+ <!-- See http://checkstyle.sf.net/config_header.html -->
+ <!-- <module name="Header"> -->
+ <!-- <property name="headerFile" value="${checkstyle.header.file}"/>
-->
+ <!-- <property name="fileExtensions" value="java"/> -->
+ <!-- </module> -->
+
+ <module name="TreeWalker">
+
+ <!-- Checks for Javadoc comments. -->
+ <!-- See http://checkstyle.sf.net/config_javadoc.html -->
+ <!--module name="JavadocMethod"/>
+ <module name="JavadocType"/>
+ <module name="JavadocVariable"/-->
+ <module name="JavadocStyle"/>
+
+
+ <!-- Checks for Naming Conventions. -->
+ <!-- See http://checkstyle.sf.net/config_naming.html -->
+ <module name="ConstantName"/>
+ <module name="LocalFinalVariableName"/>
+ <module name="LocalVariableName"/>
+ <module name="MemberName"/>
+ <module name="MethodName"/>
+ <module name="PackageName"/>
+ <module name="ParameterName"/>
+ <module name="StaticVariableName"/>
+ <module name="TypeName"/>
+
+
+ <!-- Checks for imports -->
+ <!-- See http://checkstyle.sf.net/config_import.html -->
+ <module name="AvoidStarImport"/>
+ <module name="IllegalImport"/> <!-- defaults to sun.* packages -->
+ <module name="RedundantImport"/>
+ <module name="UnusedImports"/>
+
+
+ <!-- Checks for Size Violations. -->
+ <!-- See http://checkstyle.sf.net/config_sizes.html -->
+ <module name="LineLength">
+ <property name="max" value="120"/>
+ </module>
+ <module name="MethodLength">
+ <property name="severity" value="warning"/>
+ </module>
+ <module name="ParameterNumber">
+ <property name="severity" value="warning"/>
+ </module>
+
+
+ <!-- Checks for whitespace -->
+ <!-- See http://checkstyle.sf.net/config_whitespace.html -->
+ <module name="EmptyForIteratorPad"/>
+ <module name="GenericWhitespace"/>
+ <module name="MethodParamPad"/>
+ <module name="NoWhitespaceAfter"/>
+ <module name="NoWhitespaceBefore"/>
+ <module name="OperatorWrap"/>
+ <module name="ParenPad"/>
+ <module name="TypecastParenPad"/>
+ <module name="WhitespaceAfter"/>
+ <module name="WhitespaceAround"/>
+
+
+ <!-- Modifier Checks -->
+ <!-- See http://checkstyle.sf.net/config_modifiers.html -->
+ <module name="ModifierOrder"/>
+ <module name="RedundantModifier"/>
+
+
+ <!-- Checks for blocks. You know, those {}'s -->
+ <!-- See http://checkstyle.sf.net/config_blocks.html -->
+ <module name="AvoidNestedBlocks"/>
+ <module name="EmptyBlock">
+ <property name="tokens"
+
value="LITERAL_DO,LITERAL_FINALLY,LITERAL_ELSE,LITERAL_FOR,LITERAL_TRY,LITERAL_WHILE,INSTANCE_INIT,STATIC_INIT"/>
+ </module>
+ <module name="LeftCurly">
+ <property name="option" value="nl"/>
+ <property name="tokens"
value="CLASS_DEF,INTERFACE_DEF,METHOD_DEF"/>
+ </module>
+ <module name="NeedBraces"/>
+ <module name="RightCurly"/>
+
+
+ <!-- Checks for common coding problems -->
+ <!-- See http://checkstyle.sf.net/config_coding.html -->
+ <!--module name="AvoidInlineConditionals"/-->
+ <module name="DoubleCheckedLocking"/> <!-- MY FAVOURITE -->
+ <module name="EmptyStatement"/>
+ <module name="EqualsHashCode"/>
+ <module name="HiddenField">
+ <property name="tokens" value="VARIABLE_DEF"/>
+ </module>
+ <module name="IllegalInstantiation"/>
+ <module name="InnerAssignment"/>
+ <!--module name="MagicNumber"/-->
+ <module name="MissingSwitchDefault"/>
+ <module name="RedundantThrows">
+ <property name="suppressLoadErrors" value="true"/>
+ </module>
+ <module name="SimplifyBooleanExpression"/>
+ <module name="SimplifyBooleanReturn"/>
+
+ <!-- Checks for class design -->
+ <!-- See http://checkstyle.sf.net/config_design.html -->
+ <!--module name="DesignForExtension"/-->
+ <module name="FinalClass"/>
+ <module name="HideUtilityClassConstructor"/>
+ <module name="InterfaceIsType"/>
+ <module name="VisibilityModifier">
+ <property name="protectedAllowed" value="true"/>
+ </module>
+
+
+ <!-- Miscellaneous other checks. -->
+ <!-- See http://checkstyle.sf.net/config_misc.html -->
+ <module name="ArrayTypeStyle"/>
+ <!--module name="FinalParameters"/-->
+ <module name="TodoComment">
+ <property name="severity" value="warning"/>
+ </module>
+ <module name="UpperEll"/>
+
+ <module name="FileContentsHolder"/>
+ </module>
+
+ <module name="SuppressionCommentFilter">
+ <property name="offCommentFormat" value="CHECKSTYLE_OFF: ALL"/>
+ <property name="onCommentFormat" value="CHECKSTYLE_ON: ALL"/>
+ </module>
+
+</module>
Modified:
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/Axis2PerfsonarServiceConnPoint.java
===================================================================
---
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/Axis2PerfsonarServiceConnPoint.java
2012-10-22 15:38:39 UTC (rev 6031)
+++
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/Axis2PerfsonarServiceConnPoint.java
2012-11-19 07:56:19 UTC (rev 6032)
@@ -2,12 +2,10 @@
import org.perfsonar.base2.service.axis2interface.PerfsonarService;
-public class Axis2PerfsonarServiceConnPoint extends PerfsonarService {
-
-
- public Axis2PerfsonarServiceConnPoint() {
+public class Axis2PerfsonarServiceConnPoint extends PerfsonarService
+{
+ public Axis2PerfsonarServiceConnPoint()
+ {
super();
}
-
-
-} //Axis2PerfsonarServiceConnPoint
\ No newline at end of file
+} //Axis2PerfsonarServiceConnPoint
Modified:
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/EchoServiceEngine.java
===================================================================
---
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/EchoServiceEngine.java
2012-10-22 15:38:39 UTC (rev 6031)
+++
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/EchoServiceEngine.java
2012-11-19 07:56:19 UTC (rev 6032)
@@ -20,23 +20,23 @@
import
org.perfsonar.service.measurementArchive.rrdType.storage.DataStorageDAOFactory;
import java.util.Collection;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-/**
- * $Id$
- */
-public class EchoServiceEngine extends
org.perfsonar.base2.service.requesthandler.EchoServiceEngine {
-
-
+public class EchoServiceEngine extends
org.perfsonar.base2.service.requesthandler.EchoServiceEngine
+{
// ------------------------------------------------------------- class
fields
- private static final Logger logger =
LoggerFactory.getLogger(EchoServiceEngine.class);
+ private static final Logger LOGGER =
LoggerFactory.getLogger(EchoServiceEngine.class);
- public static final String ECHO_RANDOM_FETCH_TEST =
"http://schemas.perfsonar.net/tools/admin/selftest/1.0/random-fetch-test";
- public static final String ECHO_XMLDB_ACCESS_TEST =
"http://schemas.perfsonar.net/tools/admin/selftest/1.0/xmldb-access-test";
- public static final String ECHO_XMLDB_CONTENT_TEST =
"http://schemas.perfsonar.net/tools/admin/selftest/1.0/xmldb-content-test";
+ public static final String ECHO_RANDOM_FETCH_TEST =
+ "http://schemas.perfsonar.net/tools/admin/selftest/1" +
".0/random-fetch-test";
+ public static final String ECHO_XMLDB_ACCESS_TEST =
+ "http://schemas.perfsonar.net/tools/admin/selftest/1" +
".0/xmldb-access-test";
+ public static final String ECHO_XMLDB_CONTENT_TEST =
+ "http://schemas.perfsonar.net/tools/admin/selftest/1" +
".0/xmldb-content-test";
protected static final String SERVICE_TYPE_OPTION_NAME = "serviceType";
protected static final String SERVICE_NAME_OPTION_NAME = "serviceName";
@@ -44,16 +44,17 @@
protected String serviceType = "";
protected String serviceName = "";
- protected static final String
RANDOM_FETCH_TEST_SUCCESS_RESULT_CODE_RESPONSE = "Fetching data from rrd file
is correct.";
+ protected static final String
RANDOM_FETCH_TEST_SUCCESS_RESULT_CODE_RESPONSE =
+ "Fetching data from rrd file is " + "correct.";
// ------------------------------------------------------------- methods
- public void takeAction(ServiceMessage serviceRequest, ServiceMessage
serviceResponse)
- throws PerfSONARException {
+ public void takeAction(ServiceMessage serviceRequest, ServiceMessage
serviceResponse) throws PerfSONARException
+ {
- logger.debug("Simple echo ServiceEngine started.");
+ LOGGER.debug("Simple echo ServiceEngine started.");
Message response = null;
@@ -63,12 +64,19 @@
Message request = serviceRequest.getMessageElement();
String eventType = getEventType(request);
- if (eventType.equals(ECHO_EVENT_TYPE)) response = simpleEchoAction();
- else if (eventType.equals(ECHO_SELF_TEST+"/1.0")) response =
selfTestAction();
- else if (eventType.equals(ECHO_RANDOM_FETCH_TEST)) response =
randomFetchTestAction(request, "random-fetch-test");
- else if (eventType.equals(ECHO_XMLDB_ACCESS_TEST)) response =
xmldbSimpleTestAction(request, "xmldb-access-test");
- else if (eventType.equals(ECHO_XMLDB_CONTENT_TEST)) response =
xmldbSimpleTestAction(request, "xmldb-content-test");
- else errorCode();
+ if (eventType.equals(ECHO_EVENT_TYPE)) {
+ response = simpleEchoAction();
+ } else if (eventType.equals(ECHO_SELF_TEST + "/1.0")) {
+ response = selfTestAction();
+ } else if (eventType.equals(ECHO_RANDOM_FETCH_TEST)) {
+ response = randomFetchTestAction(request, "random-fetch-test");
+ } else if (eventType.equals(ECHO_XMLDB_ACCESS_TEST)) {
+ response = xmldbSimpleTestAction(request, "xmldb-access-test");
+ } else if (eventType.equals(ECHO_XMLDB_CONTENT_TEST)) {
+ response = xmldbSimpleTestAction(request, "xmldb-content-test");
+ } else {
+ errorCode();
+ }
response.setId("Resp_" + request.getAttribute("id"));
response.addAttribute("type", "EchoResponse");
@@ -78,19 +86,24 @@
}
- protected Message simpleEchoAction() throws PerfSONARException {
+ protected Message simpleEchoAction() throws PerfSONARException
+ {
return
ResultCodesUtil.generateResultMessage(ECHO_SUCCESS_RESULT_CODE,
ECHO_SUCCESS_RESULT_CODE_DSC);
}
- protected Message selfTestAction() throws PerfSONARException {
+ protected Message selfTestAction() throws PerfSONARException
+ {
Message[] testResponses = new Message[3];
- testResponses[0] =
randomFetchTestAction(getNewEchoMessage("EchoRequest",
ECHO_RANDOM_FETCH_TEST), "random-fetch-test");
- testResponses[1] =
xmldbSimpleTestAction(getNewEchoMessage("EchoRequest",
ECHO_XMLDB_ACCESS_TEST), "xmldb-access-test");
- testResponses[2] =
xmldbSimpleTestAction(getNewEchoMessage("EchoRequest",
ECHO_XMLDB_CONTENT_TEST), "xmldb-content-test");
+ testResponses[0] =
randomFetchTestAction(getNewEchoMessage("EchoRequest",
ECHO_RANDOM_FETCH_TEST),
+ "random-fetch-test");
+ testResponses[1] =
xmldbSimpleTestAction(getNewEchoMessage("EchoRequest",
ECHO_XMLDB_ACCESS_TEST),
+ "xmldb-access-test");
+ testResponses[2] =
xmldbSimpleTestAction(getNewEchoMessage("EchoRequest",
ECHO_XMLDB_CONTENT_TEST),
+ "xmldb-content-test");
- Message response = getNewEchoMessage("EchoResponse",
ECHO_SELF_TEST+"/1.0");
+ Message response = getNewEchoMessage("EchoResponse", ECHO_SELF_TEST
+ "/1.0");
Data responseData = response.getDataCollection().iterator().next();
Metadata metadata = null;
@@ -115,21 +128,25 @@
}
- protected Message randomFetchTestAction(Message request, String
testName) {
+ protected Message randomFetchTestAction(Message request, String testName)
+ {
try {
Element element = getMetadataConfigurationElements(request);
- if (element == null)
+ if (element == null) {
return getResultMessage(
- ECHO_SELF_TEST + "/" + serviceType + "/" +
serviceName.replace(' ', '_') + "/" + testName + "/failure/1.0",
- "No data elements in the metadata configuration.");
+ ECHO_SELF_TEST + "/" + serviceType + "/" +
serviceName.replace(' ', '_') + "/" + testName
+ + "/failure/1.0", "No data elements in the metadata
configuration.");
+ }
- Key key = ((Data)element).getKey();
- if (key == null)
+ Key key = ((Data) element).getKey();
+ if (key == null) {
return getResultMessage(
- ECHO_SELF_TEST + "/" + serviceType + "/" +
serviceName.replace(' ', '_') + "/" + testName + "/failure/1.0",
- "No key in data element with id='" + element.getId() +"'
in the metadata configuration.");
+ ECHO_SELF_TEST + "/" + serviceType + "/" +
serviceName.replace(' ', '_') + "/" + testName
+ + "/failure/1.0",
+ "No key in data element with id='" + element.getId() +
"' in the metadata configuration.");
+ }
Metadata metadata = new Metadata();
metadata.setKey(key);
@@ -142,67 +159,62 @@
DataStorageDAO dao = DataStorageDAOFactory.getDAO();
Data fetchedData = dao.fetch(dataRequest);
- if (fetchedData != null)
+ if (fetchedData != null) {
return getResultMessage(
- ECHO_SELF_TEST + "/" + serviceType + "/" +
serviceName.replace(' ', '_') + "/" + testName + "/success/1.0",
- RANDOM_FETCH_TEST_SUCCESS_RESULT_CODE_RESPONSE);
- else
+ ECHO_SELF_TEST + "/" + serviceType + "/" +
serviceName.replace(' ', '_') + "/" + testName
+ + "/success/1.0",
RANDOM_FETCH_TEST_SUCCESS_RESULT_CODE_RESPONSE);
+ } else {
return getResultMessage(
- ECHO_SELF_TEST + "/" + serviceType + "/" +
serviceName.replace(' ', '_') + "/" + testName + "/failure/1.0",
- "No data fetched from rrd file.");
-
-
+ ECHO_SELF_TEST + "/" + serviceType + "/" +
serviceName.replace(' ', '_') + "/" + testName
+ + "/failure/1.0", "No data fetched from rrd file.");
+ }
} catch (PerfSONARException ex) {
return getResultMessage(
- ECHO_SELF_TEST + "/" + serviceType + "/" +
serviceName.replace(' ', '_') + "/" + testName + "/failure/1.0",
- ex.getResultDescription());
+ ECHO_SELF_TEST + "/" + serviceType + "/" +
serviceName.replace(' ', '_') + "/" + testName
+ + "/failure/1.0", ex.getResultDescription());
}
}
- protected Message xmldbSimpleTestAction(Message request, String
testName) {
+ protected Message xmldbSimpleTestAction(Message request, String testName)
+ {
try {
-
Element element = getMetadataConfigurationElements(request);
- if (element != null)
+ if (element != null) {
return getResultMessage(
- ECHO_SELF_TEST + "/" + serviceType + "/" +
serviceName.replace(' ', '_') + "/" + testName + "/success/1.0",
- (Data) element);
- else
- throw new PerfSONARException(
- "test_exception",
- "Could not get element from xml db.");
-
+ ECHO_SELF_TEST + "/" + serviceType + "/" +
serviceName.replace(' ', '_') + "/" + testName
+ + "/success/1.0", (Data) element);
+ } else {
+ throw new PerfSONARException("test_exception", "Could not
get element from xml db.");
+ }
} catch (PerfSONARException ex) {
return getResultMessage(
- ECHO_SELF_TEST + "/" + serviceType + "/" +
serviceName.replace(' ', '_') + "/" + testName + "/failure/1.0",
- ex.getResultDescription());
+ ECHO_SELF_TEST + "/" + serviceType + "/" +
serviceName.replace(' ', '_') + "/" + testName
+ + "/failure/1.0", ex.getResultDescription());
}
}
- protected Element getMetadataConfigurationElements(Message request)
- throws PerfSONARException {
-
+ protected Element getMetadataConfigurationElements(Message request)
throws PerfSONARException
+ {
MetadataStorageDAO dao = MetadataStorageDAOFactory.getDAO();
Collection<Element> results = dao.fetch(request);
Element element = null;
- if (results != null)
- if (results.size() == 1)
- element = results.iterator().next();
+ if (results != null && results.size() == 1) {
+ element = results.iterator().next();
+ }
return element;
-
}
- protected Message getNewEchoMessage(String messageType, String eventType)
- throws PerfSONARException {
+ protected Message getNewEchoMessage(String messageType, String
eventType) throws PerfSONARException
+ {
Message message = new Message();
message.setType(messageType);
@@ -221,11 +233,10 @@
}
- protected void errorCode() throws PerfSONARException {
- throw new PerfSONARException(
- "query_exception",
- "Wrong echo eventType value in the request.");
+ protected void errorCode() throws PerfSONARException
+ {
+ throw new PerfSONARException("query_exception", "Wrong echo
eventType value in the request.");
}
-} //EchoServiceEngine
\ No newline at end of file
+} //EchoServiceEngine
Modified:
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/MetadataKeyMessageHandler.java
===================================================================
---
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/MetadataKeyMessageHandler.java
2012-10-22 15:38:39 UTC (rev 6031)
+++
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/MetadataKeyMessageHandler.java
2012-11-19 07:56:19 UTC (rev 6032)
@@ -31,57 +31,57 @@
* Abstract class that does all the things that a "request" message
* handler will need to do.
*
- * @author Maciej Glowiak
- * @author Roman Lapacz
- * @author Jeff Boote
- * @author Piotr Pikusa
+ * @author Maciej Glowiak
+ * @author Roman Lapacz
+ * @author Jeff Boote
+ * @author Piotr Pikusa
*/
-public class MetadataKeyMessageHandler implements MessageHandler {
+public class MetadataKeyMessageHandler implements MessageHandler
+{
+ private static final Logger LOGGER =
LoggerFactory.getLogger(MetadataKeyMessageHandler.class);
- private static final Logger logger =
LoggerFactory.getLogger(MetadataKeyMessageHandler.class);
+ public MetadataKeyMessageHandler() throws PerfSONARException
+ {
-
- public MetadataKeyMessageHandler() throws PerfSONARException {
-
}
- protected ServiceEngine getServiceEngine(String serviceEngineClassName)
- throws Exception {
+ protected ServiceEngine getServiceEngine(String serviceEngineClassName)
throws Exception
+ {
- ServiceEngine se = (ServiceEngine)Class.forName(
- serviceEngineClassName ).newInstance();
+ ServiceEngine se = (ServiceEngine)
Class.forName(serviceEngineClassName).newInstance();
- return se;
+ return se;
}
- protected void checkAuth(Configuration c, String messageType) throws
PerfSONARException {
+ protected void checkAuth(Configuration c, String messageType) throws
PerfSONARException
+ {
try {
String authR =
c.getMessageHandler(messageType).getOption("authR").getValue();
- logger.debug("Checking authorization: "+authR);
+ LOGGER.debug("Checking authorization: " + authR);
if ("yes".equals(authR)) {
- AuthNComponent authComponent =
(AuthNComponent)c.getAuxiliaryComponent("auth");
+ AuthNComponent authComponent = (AuthNComponent)
c.getAuxiliaryComponent("auth");
authComponent.requestAuthR(messageType, null);
- }
- else {
+ } else {
String authN =
c.getMessageHandler(messageType).getOption("authN").getValue();
- logger.debug("Checking authentication: "+authN);
+ LOGGER.debug("Checking authentication: " + authN);
if ("yes".equals(authN)) {
- AuthNComponent authComponent =
(AuthNComponent)c.getAuxiliaryComponent("auth");
+ AuthNComponent authComponent = (AuthNComponent)
c.getAuxiliaryComponent("auth");
authComponent.requestAuthN(messageType);
}
}
- } catch (RuntimeException ex) { }
+ } catch (RuntimeException ex) {
+ }
}
- public void execute(ServiceMessage request, ServiceMessage response)
- throws PerfSONARException {
+ public void execute(ServiceMessage request, ServiceMessage response)
throws PerfSONARException
+ {
Message reqMessage = (Message) request.getElement();
- logger.debug("Message Handler started for message type
["+reqMessage.getType()+"]");
-
//logger.debug("--------------------\n"+reqMessage+"\n------------------------\n");
+ LOGGER.debug("Message Handler started for message type [" +
reqMessage.getType() + "]");
+
//LOGGER.debug("--------------------\n"+reqMessage+"\n------------------------\n");
//get Service engine for this message
String messageType = null;
@@ -95,41 +95,42 @@
//service engine
serviceEngineClassName = c.getServiceEngineOption(messageType);
serviceEngine = getServiceEngine(serviceEngineClassName);
- if (serviceEngine == null) throw new NullPointerException(
- "Cannot Instantiate ServiceEngine class
["+serviceEngineClassName+"]");
+ if (serviceEngine == null) {
+ throw new NullPointerException(
+ "Cannot Instantiate ServiceEngine class [" +
serviceEngineClassName + "]");
+ }
} catch (Exception ex) {
- String m = "Cannot find ServiceEngine ["+serviceEngineClassName +
- "] for message type ["+messageType+"], nested exception
was:"+
- ex.toString();
- PerfSONARException pse = new PerfSONARException(
- "no_service_engine", m);
- logger.error(m,ex);
+ String m = "Cannot find ServiceEngine [" + serviceEngineClassName
+ + "] for message type [" + messageType + "], nested
exception was:"
+ + ex.toString();
+ PerfSONARException pse = new
PerfSONARException("no_service_engine", m);
+ LOGGER.error(m, ex);
- response.setElement(
- ResultCodesUtil.generateResultMessage(null, pse));
- return; //finish when cannot execute ServiceEngine
+ response.setElement(ResultCodesUtil.generateResultMessage(null,
pse));
+ return; //finish when cannot execute ServiceEngine
}
ArrayList<MessagePair> output = new ArrayList<MessagePair>();
- List<Message> inputMessages=extractMultipleRequests(reqMessage);
- if(inputMessages.isEmpty()){
- //TODO: url event types
- throw new
PerfSONARException("error.common.no_metadata_data_pair","There were no
metadata/data pairs found in the message");
+ List<Message> inputMessages = extractMultipleRequests(reqMessage);
+ if (inputMessages.isEmpty()) {
+ //TODO: url event types
+ throw new
PerfSONARException("error.common.no_metadata_data_pair",
+ "There were no metadata/data pairs
found in the message");
}
-
- for (Message inputMessage: inputMessages) {
+ for (Message inputMessage : inputMessages) {
+
ServiceMessage reqSM = new ServiceMessage(inputMessage);
ServiceMessage resSM = new ServiceMessage();
try {
- logger.debug("Request.execute: run Service Engine for
extracted request");
+ LOGGER.debug("Request.execute: run Service Engine for
extracted request");
//run service engine and add result to output list
try {
@@ -139,16 +140,16 @@
} catch (RuntimeException rex) {
//just in case of unexpected runtime exception such as
//null, indexoutofbounds, classcast, etc.
- logger.error("Service engine failed", rex);
- throw new PerfSONARException(
- "runtime_exception", "Runtime exception in
ServiceEngine: "+rex.getMessage(), rex);
+ LOGGER.error("Service engine failed", rex);
+ throw new PerfSONARException("runtime_exception",
+ "Runtime exception in
ServiceEngine: " + rex.getMessage(), rex);
}
} catch (PerfSONARException e) {
//if an exception was thrown, convert it to result code
//and add as a new message (to be joined) to array
- logger.error("Message handler result code: "+e);
-
resSM.setElement(ResultCodesUtil.generateResultMessage(e.getResultCode(),e.getMessage()));
+ LOGGER.error("Message handler result code: " + e);
+
resSM.setElement(ResultCodesUtil.generateResultMessage(e.getResultCode(),
e.getMessage()));
}
@@ -170,7 +171,8 @@
}
- protected ArrayList<Message> extractMultipleRequests(Message reqMessage)
{
+ protected ArrayList<Message> extractMultipleRequests(Message reqMessage)
+ {
ArrayList<Message> messages = new ArrayList<Message>();
Collection<Data> dataTriggers = reqMessage.getDataMap().values();
@@ -181,13 +183,14 @@
Message message = new Message();
try {
- Map<String,Metadata> metadatas = new
HashMap<String,Metadata>();
+ Map<String, Metadata> metadatas = new HashMap<String,
Metadata>();
getChaining(reqMessage, metadataIdRef, metadatas);
- Map<String,Metadata> mergedMetadatas =
mergeAllMetadata(metadatas);
+ Map<String, Metadata> mergedMetadatas =
mergeAllMetadata(metadatas);
- for (Metadata metadata : mergedMetadatas.values())
+ for (Metadata metadata : mergedMetadatas.values()) {
message.setMetadata(metadata);
+ }
message.setId(reqMessage.getId());
message.setType(reqMessage.getType());
@@ -210,107 +213,126 @@
}
- public class MessagePair {
+ public class MessagePair
+ {
private ServiceMessage request = null;
private ServiceMessage response = null;
- public MessagePair(ServiceMessage request, ServiceMessage response) {
+
+ public MessagePair(ServiceMessage request, ServiceMessage response)
+ {
this.request = request;
this.response = response;
}
- public void setRequest(ServiceMessage request) { this.request =
request; }
- public void setResponse(ServiceMessage response) { this.response =
response; }
- public ServiceMessage getRequest() { return request; }
- public ServiceMessage getResponse() { return response; }
+
+ public void setRequest(ServiceMessage request)
+ {
+ this.request = request;
+ }
+
+ public void setResponse(ServiceMessage response)
+ {
+ this.response = response;
+ }
+
+ public ServiceMessage getRequest()
+ {
+ return request;
+ }
+
+ public ServiceMessage getResponse()
+ {
+ return response;
+ }
}
- protected MessagePair mergeMultipleResponses(ArrayList<MessagePair>
messagePairs){
-
- final Map<String, String> ids = new Hashtable<String, String>();
+ protected MessagePair mergeMultipleResponses(ArrayList<MessagePair>
messagePairs)
+ {
- if (messagePairs == null || messagePairs.size() == 0)
+ final Map<String, String> ids = new Hashtable<String, String>();
+
+ if (messagePairs == null || messagePairs.isEmpty()) {
return null;
-
-
-
-
- /*
- * BUG 508 fixing begin
- */
- else if (messagePairs.size() == 1 &&
messagePairs.get(0).getResponse().getText() != null &&
messagePairs.get(0).getResponse().getElement() == null){
-
- StringBuilder responseText = new StringBuilder();
- String t =
messagePairs.get(0).getRequest().getElement().getAttribute("type");
- String type = (t == null? "": t.replaceFirst("Request",
"Response"));
- responseText.append("<nmwg:message
type=\"").append(type).append("\"
xmlns:nmwg=\"http://ggf.org/ns/nmwg/base/2.0/\"
xmlns=\"http://ggf.org/ns/nmwg/base/2.0/\"
xmlns:nmwgt=\"http://ggf.org/ns/nmwg/topology/2.0/\">");
-
responseText.append(messagePairs.get(0).getResponse().getText());
+ } else if (messagePairs.size() == 1 &&
messagePairs.get(0).getResponse().getText() != null
+ && messagePairs.get(0).getResponse().getElement() == null) {
+ /*
+ * BUG 508 fixing begin
+ */
+ StringBuilder responseText = new StringBuilder();
+ String t =
messagePairs.get(0).getRequest().getElement().getAttribute("type");
+ String type = (t == null ? "" : t.replaceFirst("Request",
"Response"));
+ responseText.append("<nmwg:message type=\"").append(type).append(
+ "\" xmlns:nmwg=\"http://ggf.org/ns/nmwg/base/2.0/\"
xmlns=\"http://ggf.org/ns/nmwg/base/2.0/\" "
+ +
"xmlns:nmwgt=\"http://ggf.org/ns/nmwg/topology/2.0/\">");
+ responseText.append(messagePairs.get(0).getResponse().getText());
responseText.append("</nmwg:message>");
messagePairs.get(0).getResponse().setText(responseText.toString());
return messagePairs.get(0);
/*
* BUG 508 fixing end
*/
-
- }else if(messagePairs.size() == 1)
- return messagePairs.get(0);
-
- else {
- int metaid=0;
- int dataid=0;
+ } else if (messagePairs.size() == 1) {
+ return messagePairs.get(0);
+ } else {
+ int metaid = 0;
+ int dataid = 0;
+
//create new common response message
Message respMessage = new Message();
-
-
+
/*
- * Bug 508 fixing - BEGIN
- */
+ * Bug 508 fixing - BEGIN
+ */
//Prepare Message Text
StringBuilder responseText = new StringBuilder();
String t =
messagePairs.get(0).getRequest().getElement().getAttribute("type");
- String type = (t == null? "": t.replaceFirst("Request",
"Response"));
- responseText.append("<nmwg:message
type=\"").append(type).append("\"
xmlns:nmwg=\"http://ggf.org/ns/nmwg/base/2.0/\"
xmlns=\"http://ggf.org/ns/nmwg/base/2.0/\"
xmlns:nmwgt=\"http://ggf.org/ns/nmwg/topology/2.0/\">");
-
+ String type = (t == null ? "" : t.replaceFirst("Request",
"Response"));
+ responseText.append("<nmwg:message type=\"").append(type).append(
+ "\" xmlns:nmwg=\"http://ggf.org/ns/nmwg/base/2.0/\"
xmlns=\"http://ggf.org/ns/nmwg/base/2.0/\" "
+ +
"xmlns:nmwgt=\"http://ggf.org/ns/nmwg/topology/2.0/\">");
+
//Concatenate Messages
int messageCounter = 0;
for (MessagePair messagePair : messagePairs) {
-
- if(messagePair.getResponse().getText() != null &&
messagePair.getResponse().getElement() == null){
- //If it's true it means that on message pairs list
there is no response which has element object so responses can be concatenated
-
-
responseText.append(messagePair.getResponse().getText());
- messageCounter++;
-
- }
- else{
- break;
- }
+
+ if (messagePair.getResponse().getText() != null &&
messagePair.getResponse().getElement() == null) {
+ //If it's true it means that on message pairs list there
is no response which has element object
+ // so responses can be concatenated
+
+ responseText.append(messagePair.getResponse().getText());
+ messageCounter++;
+
+ } else {
+ break;
+ }
}
responseText.append("</nmwg:message>");
-
- //If it's true it means that on message pairs list there is no
response which has element object so responses can be concatenated
- if(messagePairs.size() == messageCounter){
-
messagePairs.get(0).getResponse().setText(responseText.toString());
- return messagePairs.get(0);
-
+
+ //If it's true it means that on message pairs list there is no
response which has element object so
+ // responses can be concatenated
+ if (messagePairs.size() == messageCounter) {
+
messagePairs.get(0).getResponse().setText(responseText.toString());
+ return messagePairs.get(0);
+
}
/*
- * Bug 508 fixing - END
+ * Bug 508 fixing - END
*/
-
-
+
for (MessagePair messagePair : messagePairs) {
//ServiceMessage request = messagePair.getRequest();
ServiceMessage response = messagePair.getResponse();
Message m = (Message) response.getElement();
-
-
- if (m == null) return messagePair;
+ if (m == null) {
+ return messagePair;
+ }
+
Collection<Metadata> metadatas = m.getMetadataMap().values();
Collection<Data> datas = m.getDataMap().values();
@@ -320,13 +342,13 @@
//get old meta id
String meta1id = meta1.getId();
//compute new meta id
- String newMeta1id = meta1id+"_"+metaid;
+ String newMeta1id = meta1id + "_" + metaid;
//set new id
meta1.setId(newMeta1id);
metaid++;
-
+
ids.put(meta1id, newMeta1id);
/*
@@ -344,10 +366,10 @@
* mapping.add(oldId, newId);
*
*/
- if ((meta1.getSubject() != null)
- && (meta1.getSubject().getMetadataIdRef() !=
null)) {
- if (ids.get(meta1.getSubject().getMetadataIdRef()) !=
null)
-
meta1.getSubject().setMetadataIdRef(ids.get(meta1.getSubject().getMetadataIdRef()));
+ if ((meta1.getSubject() != null) &&
(meta1.getSubject().getMetadataIdRef() != null)) {
+ if (ids.get(meta1.getSubject().getMetadataIdRef())
!= null) {
+
meta1.getSubject().setMetadataIdRef(ids.get(meta1.getSubject().getMetadataIdRef()));
+ }
}
//put metadata to new common response message
@@ -360,7 +382,7 @@
//put data
if (data1.getMetadataIdRef().equals(meta1id)) {
- data1.setId(data1.getId() + "_"+dataid);
+ data1.setId(data1.getId() + "_" + dataid);
//change data metadata id ref to new meta id
data1.setMetadataIdRef(newMeta1id);
@@ -382,45 +404,42 @@
/**
- * Find metadata chain for metadata ID (the last metadata in chain)
+ * Find metadata chain for metadata ID (the last metadata in chain).
*
- * @param inputMessage message to process (won't be changed)
+ * @param inputMessage message to process (won't be changed)
* @param lastMetadataId id of metadata which is last in chain
* @return map <id,metadata>
* @throws NoSuchMetadataException thrown if there is no metadata with
given ID
*/
- protected Map<String,Metadata> getChaining(
- Message inputMessage, String metadataId, Map<String,Metadata>
metadatas)
- throws NoSuchMetadataException {
+ protected Map<String, Metadata> getChaining(Message inputMessage, String
metadataId, Map<String,
+ Metadata> metadatas) throws NoSuchMetadataException
+ {
- if (metadataId == null) throw new NoSuchMetadataException();
- Metadata metadata = inputMessage.getMetadata(metadataId);
- if (metadata == null) throw new NoSuchMetadataException();
+ if (metadataId == null) {
+ throw new NoSuchMetadataException();
+ }
+ Metadata metadata = inputMessage.getMetadata(metadataId);
+ if (metadata == null) {
+ throw new NoSuchMetadataException();
+ }
metadatas.put(metadata.getId(), metadata);
//metadataIdRef in Subject
//prevent endless loop
- if (metadata.getSubject() != null) {
-
- if ( (metadata.getSubject().getMetadataIdRef()!=null)&&
- !("".equals(metadata.getSubject().getMetadataIdRef()))&&
-
!(metadata.getId().equals(metadata.getSubject().getMetadataIdRef()))) {
-
- getChaining(
- inputMessage,
- metadata.getSubject().getMetadataIdRef(),
- metadatas);
- }
-
+ if (metadata.getSubject() != null
+ && (metadata.getSubject().getMetadataIdRef() != null)
+ && !(metadata.getSubject().getMetadataIdRef() != null &&
metadata.getSubject().getMetadataIdRef().isEmpty())
+ &&
!(metadata.getId().equals(metadata.getSubject().getMetadataIdRef()))) {
+ getChaining(inputMessage,
metadata.getSubject().getMetadataIdRef(), metadatas);
}
String chainedMetadataId = metadata.getMetadataIdRef();
//get other chain, prevent endless loop
- if ( (chainedMetadataId!=null)&&
- !("".equals(chainedMetadataId))&&
- !(metadata.getId().equals(chainedMetadataId))) {
+ if ((chainedMetadataId != null)
+ && !(chainedMetadataId != null && chainedMetadataId.isEmpty())
+ && !(metadata.getId().equals(chainedMetadataId))) {
getChaining(inputMessage, chainedMetadataId, metadatas);
}
@@ -431,11 +450,13 @@
/**
- * Merge chained metadata elements
+ * Merge chained metadata elements.
+ *
* @param metadatas map of metadata elements
* @return metadatas map of merged metadata elements
*/
- public Map<String,Metadata> mergeAllMetadata(Map<String,Metadata>
metadatas) {
+ public Map<String, Metadata> mergeAllMetadata(Map<String, Metadata>
metadatas)
+ {
return metadatas;
}
@@ -446,19 +467,9 @@
* exception.
*
* @author Maciej Glowiak
- *
*/
- protected class NoSuchMetadataException extends Exception {
-
+ protected class NoSuchMetadataException extends Exception
+ {
private static final long serialVersionUID = -3725261560519487460L;
-
}
-
-
-} //GenericMessageHandler
-
-
-
-
-
-
+}
Modified:
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/MetadataKeyServiceEngine.java
===================================================================
---
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/MetadataKeyServiceEngine.java
2012-10-22 15:38:39 UTC (rev 6031)
+++
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/MetadataKeyServiceEngine.java
2012-11-19 07:56:19 UTC (rev 6032)
@@ -13,17 +13,18 @@
/**
-
*@author
Roman Lapacz
<>
-
*@author
Piotr Pikusa
<>
+ * @author Roman Lapacz
<>
+ * @author Piotr Pikusa
<>
*/
-public class MetadataKeyServiceEngine implements ServiceEngine {
+public class MetadataKeyServiceEngine implements ServiceEngine
+{
// ------------------------------------------------------------- methods
- public void takeAction(ServiceMessage serviceRequest, ServiceMessage
serviceResponse)
- throws PerfSONARException {
+ public void takeAction(ServiceMessage serviceRequest, ServiceMessage
serviceResponse) throws PerfSONARException
+ {
// process the base chaining
// request = messageProcess(request);
@@ -32,10 +33,9 @@
Message request = serviceRequest.getMessageElement();
Data data = request.getDataMap().values().iterator().next();
- if (data == null)
- throw new PerfSONARException(
- "query_exception",
- "no data trigger");
+ if (data == null) {
+ throw new PerfSONARException("query_exception", "no data
trigger");
+ }
Map metadataMap = request.getMetadataMap();
Metadata metadata = (Metadata)
metadataMap.get(data.getMetadataIdRef());
@@ -46,31 +46,26 @@
} catch (NullPointerException npex) {
- throw new PerfSONARException(
- "query_exception",
- "getting the key is impossible "
- + npex.toString());
+ throw new PerfSONARException("query_exception", "getting the key
is impossible " + npex.toString());
}
}
- protected Message messageProcess(Message message)
- throws PerfSONARException {
+ protected Message messageProcess(Message message) throws
PerfSONARException
+ {
// TODO
return message;
}
- protected void getKey(Metadata metadata,
- Map metadataMap,
- ServiceMessage serviceResponse,
- MetadataStorageDAO dao)
- throws PerfSONARException {
+ protected void getKey(Metadata metadata, Map metadataMap, ServiceMessage
serviceResponse,
+ MetadataStorageDAO dao) throws PerfSONARException
+ {
- if (metadata.getSubject() != null ) {
+ if (metadata.getSubject() != null) {
if (metadata.getSubject().getMetadataIdRef() == null) {
@@ -78,30 +73,25 @@
Message query = new Message();
query.setType("MetadataKeyRequest");
query.addChild(metadata);
-
+
String results = "";
-
- results = dao.rawFetch(query);
-
-
-
+
+ results = dao.rawFetch(query);
+
+
serviceResponse.setText(results);
serviceResponse.setElement(null);
} else {
- throw new PerfSONARException(
- "functional_chaining_query_exception",
- "functional chaining in the MetadataKeyRequest is not
supported");
+ throw new
PerfSONARException("functional_chaining_query_exception",
+ "functional chaining in the
MetadataKeyRequest is not supported");
}
} else {
- throw new PerfSONARException(
- "query_exception",
- "no subject element in metadata id="
- + metadata.getId());
+ throw new PerfSONARException("query_exception", "no subject
element in metadata id=" + metadata.getId());
}
@@ -109,4 +99,4 @@
}
-} //MetadataKeyServiceEngine
\ No newline at end of file
+} //MetadataKeyServiceEngine
Modified:
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/SetupDataServiceEngine.java
===================================================================
---
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/SetupDataServiceEngine.java
2012-10-22 15:38:39 UTC (rev 6031)
+++
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/SetupDataServiceEngine.java
2012-11-19 07:56:19 UTC (rev 6032)
@@ -24,53 +24,48 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-/**
- * $Id: SetupDataServiceEngine.java 4684 2008-11-03 13:07:33Z roman $
- */
-public class SetupDataServiceEngine implements ServiceEngine {
-
-
+public class SetupDataServiceEngine implements ServiceEngine
+{
// ------------------------------------------------------------- class
fields
protected static final String SELECT_NAMESPACE =
"http://ggf.org/ns/nmwg/ops/select/2.0";
- private static final Logger logger =
LoggerFactory.getLogger(SetupDataServiceEngine.class);
+ private static final Logger LOGGER =
LoggerFactory.getLogger(SetupDataServiceEngine.class);
// ------------------------------------------------------------- methods
- public void takeAction(ServiceMessage serviceRequest, ServiceMessage
serviceResponse)
- throws PerfSONARException {
- Message response = new Message();
- DataStorageDAO dao = DataStorageDAOFactory.getDAO();
+ public void takeAction(ServiceMessage serviceRequest, ServiceMessage
serviceResponse) throws PerfSONARException
+ {
+ Message response = new Message();
+ DataStorageDAO dao = DataStorageDAOFactory.getDAO();
-
-
- /*
+
+ /*
Message request = (Message)serviceRequest.getElement();
- logger.info("REQUEST:\n "+request.getText());
+ LOGGER.info("REQUEST:\n "+request.getText());
HashMap<Metadata, Data> pairs = getMetadataDataPairs(request);
HashMap<Metadata, Data> pairsToQuery = checkMetadata(pairs);
-
+
if(pairsToQuery.size() == 0){
- for (Metadata metadata : pairs.keySet()) {
- Message dReq = new Message();
+ for (Metadata metadata : pairs.keySet()) {
+ Message dReq = new Message();
dReq.addChild(metadata);
Data fetchedData = dao.fetch(dReq);
fetchedData.setMetadataIdRef(metadata.getId());
-
+
response.addChild(metadata);
response.addChild(fetchedData);
- }
+ }
}else{
-
+
}
*/
-
+
/*TEMP: IMPORTANT EVERYTHING WHAT IS BELOW IS OLD CODE. The new code
is up*/
-
+
//Message response = new Message();
//DataStorageDAO dao = DataStorageDAOFactory.getDAO();
getRequestKey(serviceRequest, serviceResponse);
@@ -82,10 +77,10 @@
Metadata metadata = null;
Map metadataMap = keyMessage.getMetadataMap();
- if (metadataMap.size() != 0){
- if (data.getMetadataIdRef() != null)
- metadata =
- (Metadata) metadataMap.get(data.getMetadataIdRef());
+ if (!metadataMap.isEmpty()) {
+ if (data.getMetadataIdRef() != null) {
+ metadata = (Metadata)
metadataMap.get(data.getMetadataIdRef());
+ }
data.toString();
}
Message dReq = new Message();
@@ -99,171 +94,172 @@
response.addChild(metadata);
fetchedData.setMetadataIdRef(metadata.getId());
}
-
+
response.addChild(fetchedData);
}
-
- logger.debug("Response: {}", response);
+
+ LOGGER.debug("Response: {}", response);
serviceResponse.setElement(response);
}
-
-
-
+
/**
- * It pairs metadata and data from one message and put the pairs into
the HashMap. Because chaining is not supported, then
+ * It pairs metadata and data from one message and put the pairs into
the HashMap. Because chaining is not
+ * supported, then
* if metadata and data counters are different it throws exception
+ *
* @param message
* @return
* @throws PerfSONARException when metadata counter doesn't match to
data counter
*/
- protected HashMap<Metadata, Data> getMetadataDataPairs(Message message)
throws PerfSONARException{
- HashMap<Metadata, Data> pairs = new HashMap<Metadata, Data>();
- int dataCounter = 0;
- int metadataCounter = 0;
-
- if(message.getDataMap() == null){
- throw new PerfSONARException("query_exception","There is no
data entries in the request");
- }
- if(message.getMetadataMap() == null){
- throw new PerfSONARException("query_exception","There is no
metadata entries in the request");
- }
-
- //This searching is O(n^2) but for most cases it will be fast because
of few pairs in request (most often only one)
+ protected HashMap<Metadata, Data> getMetadataDataPairs(Message message)
throws PerfSONARException
+ {
+ HashMap<Metadata, Data> pairs = new HashMap<Metadata, Data>();
+ int dataCounter = 0;
+ int metadataCounter = 0;
+
+ if (message.getDataMap() == null) {
+ throw new PerfSONARException("query_exception", "There is no
data entries in the request");
+ }
+ if (message.getMetadataMap() == null) {
+ throw new PerfSONARException("query_exception", "There is no
metadata entries in the request");
+ }
+
+ //This searching is O(n^2) but for most cases it will be fast
because of few pairs in request (most often
+ // only one)
for (Data data : message.getDataMap().values()) {
- dataCounter++;
- metadataCounter = 0;
- for (Metadata metadata : message.getMetadataMap().values()) {
- metadataCounter++;
-
if(data.getMetadataIdRef().trim().equals(metadata.getId().trim())){
- pairs.put(metadata, data);
- }
- }
+ dataCounter++;
+ metadataCounter = 0;
+ for (Metadata metadata : message.getMetadataMap().values()) {
+ metadataCounter++;
+ if
(data.getMetadataIdRef().trim().equals(metadata.getId().trim())) {
+ pairs.put(metadata, data);
+ }
+ }
}
- if(metadataCounter != dataCounter) throw new
PerfSONARException("query_exception","metadata and data counter doesn't
match");
-
- return pairs;
+ if (metadataCounter != dataCounter) {
+ throw new PerfSONARException("query_exception", "metadata and
data counter doesn't match");
+ }
+
+ return pairs;
}
-
-
+
+
/**
- * It cheks metadata if it includes the full key. If it does, then there
is no query to SQL database, what saves time. It returns
- * the map with metadata-data pairs, where metadatas don't include the
full key
+ * It cheks metadata if it includes the full key. If it does, then there
is no query to SQL database,
+ * what saves time. It returns
+ * the map with metadata-data pairs, where metadatas don't include the
full key
+ *
* @param pairs
* @return
*/
- protected HashMap<Metadata, Data> checkMetadata(HashMap<Metadata, Data>
pairs) throws PerfSONARException{
-
- HashMap<Metadata, Data> _pairs = new HashMap<Metadata, Data>();
-
- for (Metadata metadata : pairs.keySet()) {
- //First check if key is included and the most important
parameter - file is in. If not other metadata params don't have to be checked
- if (metadata.getKey()== null ||
-
metadata.getKey().getParameters("http://ggf.org/ns/nmwg/base/2.0/") == null ||
-
metadata.getKey().getParameters("http://ggf.org/ns/nmwg/base/2.0/").getFirstParameterValue("file")
== null){
-
- if( pairs.get(metadata).getKey() == null ||
-
pairs.get(metadata).getKey().getParameters("http://ggf.org/ns/nmwg/base/2.0/")
== null ||
-
pairs.get(metadata).getKey().getParameters("http://ggf.org/ns/nmwg/base/2.0/").getFirstParameterValue("file")
== null){
-
- _pairs.put(metadata, pairs.get(metadata));
- continue;
-
- }else{
- metadata.setKey(pairs.get(metadata).getKey());
- }
- }
- else{
+ protected HashMap<Metadata, Data> checkMetadata(HashMap<Metadata, Data>
pairs) throws PerfSONARException
+ {
+ HashMap<Metadata, Data> result = new HashMap<Metadata, Data>();
+
+ for (Metadata metadata : pairs.keySet()) {
+ //First check if key is included and the most important
parameter - file is in. If not other metadata
+ // params don't have to be checked
+ if (metadata.getKey() == null
+ ||
metadata.getKey().getParameters("http://ggf.org/ns/nmwg/base/2.0/") == null
+ ||
metadata.getKey().getParameters("http://ggf.org/ns/nmwg/base/2.0/").getFirstParameterValue("file")
+ == null) {
+ if (pairs.get(metadata).getKey() == null
+ ||
pairs.get(metadata).getKey().getParameters("http://ggf.org/ns/nmwg/base/2.0/")
== null
+ || pairs.get(metadata).getKey().getParameters(
+
"http://ggf.org/ns/nmwg/base/2.0/").getFirstParameterValue("file") == null) {
+ result.put(metadata, pairs.get(metadata));
+ continue;
+ } else {
+ metadata.setKey(pairs.get(metadata).getKey());
+ }
+ } else {
if (metadata.getSubject() != null) {
- Element interf =
metadata.getSubject().getFirstChild("interface");
- if (interf != null) {
- if(interf.getFirstChild("ifAddress") ==
null || interf.getFirstChild("ifAddress").getText().trim().equals("")){
- _pairs.put(metadata,
pairs.get(metadata));
- continue;
- }
- if(interf.getFirstChild("hostName") == null
|| interf.getFirstChild("hostName").getText().trim().equals("")){
- _pairs.put(metadata,
pairs.get(metadata));
- continue;
- }
- if(interf.getFirstChild("ifName") == null
|| interf.getFirstChild("ifName").getText().trim().equals("")){
- _pairs.put(metadata,
pairs.get(metadata));
- continue;
- }
- if(interf.getFirstChild("direction") ==
null || interf.getFirstChild("direction").getText().trim().equals("")){
- _pairs.put(metadata,
pairs.get(metadata));
- continue;
- }
- if(interf.getFirstChild("capacity") == null
|| interf.getFirstChild("capacity").getText().trim().equals("")){
- _pairs.put(metadata,
pairs.get(metadata));
- continue;
- }
- }else{
- throw new PerfSONARException(
- "query_exception",
- "no interface element in metadata
element");
- }
- } else {
- throw new PerfSONARException(
- "query_exception",
- "no subject element in metadata element");
+ Element interf =
metadata.getSubject().getFirstChild("interface");
+ if (interf != null) {
+ if (interf.getFirstChild("ifAddress") == null ||
interf.getFirstChild(
+ "ifAddress").getText().trim().isEmpty()) {
+ result.put(metadata, pairs.get(metadata));
+ continue;
+ }
+ if (interf.getFirstChild("hostName") == null ||
interf.getFirstChild(
+ "hostName").getText().trim().isEmpty()) {
+ result.put(metadata, pairs.get(metadata));
+ continue;
+ }
+ if (interf.getFirstChild("ifName") == null ||
interf.getFirstChild(
+ "ifName").getText().trim().isEmpty()) {
+ result.put(metadata, pairs.get(metadata));
+ continue;
+ }
+ if (interf.getFirstChild("direction") == null ||
interf.getFirstChild(
+ "direction").getText().trim().isEmpty()) {
+ result.put(metadata, pairs.get(metadata));
+ continue;
+ }
+ if (interf.getFirstChild("capacity") == null ||
interf.getFirstChild(
+ "capacity").getText().trim().isEmpty()) {
+ result.put(metadata, pairs.get(metadata));
+ continue;
+ }
+ } else {
+ throw new PerfSONARException("query_exception", "no
interface element in metadata element");
+ }
+ } else {
+ throw new PerfSONARException("query_exception", "no
subject element in metadata element");
}
}
- }
- return _pairs;
-
+ }
+ return result;
+
}
-
- protected void getRequestKey(ServiceMessage serviceRequest,
ServiceMessage serviceResponse)
- throws PerfSONARException {
+ protected void getRequestKey(ServiceMessage serviceRequest,
ServiceMessage serviceResponse) throws
+ PerfSONARException
+ {
+
MetadataStorageDAO dao = MetadataStorageDAOFactory.getDAO();
Message request = (Message) serviceRequest.getElement();
Data data = request.getDataMap().values().iterator().next();
- if (data == null)
- throw new PerfSONARException(
- "query_exception",
- "no data trigger");
-
-
-
+ if (data == null) {
+ throw new PerfSONARException("query_exception", "no data
trigger");
+ }
+
Map metadataMap = request.getMetadataMap();
Metadata metadata = (Metadata)
metadataMap.get(data.getMetadataIdRef());
//try {
- Message message = new Message();
- serviceResponse.setElement(message);
- serviceResponse.setText(null);
+ Message message = new Message();
+ serviceResponse.setElement(message);
+ serviceResponse.setText(null);
- getKey(metadata, null, metadataMap, message, dao);
+ getKey(metadata, null, metadataMap, message, dao);
//} catch (NullPointerException npex) {
- /*(throw new PerfSONARException(
- "query_exception",
- "getting the key is impossible "
- + npex.toString());
- */
- //npex.printStackTrace();
- //logger.error("PSNC ERROR:" + npex.getMessage());
+ /*(throw new PerfSONARException(
+ "query_exception",
+ "getting the key is impossible "
+ + npex.toString());
+ */
+ //npex.printStackTrace();
+ //LOGGER.error("PSNC ERROR:" + npex.getMessage());
//}
}
- protected void getKey(Metadata metadata,
- Data data,
- Map metadataMap,
- Message message,
- MetadataStorageDAO dao)
- throws PerfSONARException {
+ protected void getKey(Metadata metadata, Data data, Map metadataMap,
Message message,
+ MetadataStorageDAO dao) throws PerfSONARException
+ {
- if (metadata.getSubject() != null ) {
+ if (metadata.getSubject() != null) {
if (metadata.getSubject().getMetadataIdRef() == null) {
@@ -272,8 +268,9 @@
query.addChild(metadata);
Collection<Element> results = dao.fetch(query);
- for (Element element : results)
+ for (Element element : results) {
message.addChild(element);
+ }
} else {
@@ -283,10 +280,8 @@
eventType =
metadata.getFirstEventType().getEventType().trim();
} catch (Exception ex) {
- throw new PerfSONARException(
- "query_exception",
- "something wrong with eventType in metadata id="
- + metadata.getId());
+ throw new PerfSONARException("query_exception",
+ "something wrong with
eventType in metadata id=" + metadata.getId());
}
if
(metadata.getFirstEventType().getEventType().trim().equals(SELECT_NAMESPACE))
{
@@ -299,28 +294,26 @@
for (Object d : message.getDataMap().values()) {
- Key key = null;
- if ((key = ((Data)d).getKey()) != null){
- key.setParameters(params);
- logger.debug("PSNC: KEY not NULL!");
+ Key key = ((Data) d).getKey();
+ if (key != null) {
+ key.setParameters(params);
+ LOGGER.debug("PSNC: KEY not NULL!");
}
-
+
}
} else {
- throw new PerfSONARException(
- "query_exception",
- "eventType " + eventType + " in metadata id=" +
metadata.getId()
- + " is not supported");
+ throw new PerfSONARException("query_exception",
+ "eventType " + eventType +
" in metadata id=" + metadata.getId()
+ + " is not supported");
}
}
} else {
+ Key key = metadata.getKey();
+ if (key != null) {
- Key key = null;
- if ((key = metadata.getKey()) != null) {
-
if (data == null) {
data = new Data();
@@ -352,15 +345,14 @@
query.addChild(metadata);
Collection<Element> results = dao.fetch(query);
- for (Element element : results)
+ for (Element element : results) {
message.addChild(element);
+ }
} else if (key == null) {
- throw new PerfSONARException(
- "query_exception",
- "no eventType or key element in metadata id="
- + metadata.getId());
+ throw new PerfSONARException("query_exception",
+ "no eventType or key element in
metadata id=" + metadata.getId());
}
}
@@ -370,7 +362,8 @@
private static long seq = 0;
- public static String getSeq() {
+ public static String getSeq()
+ {
String strSeq = null;
try {
@@ -386,7 +379,4 @@
}
-
-
-
-} //SetupDataServiceEngine
\ No newline at end of file
+} //SetupDataServiceEngine
Modified:
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/DataStorageDAO.java
===================================================================
---
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/DataStorageDAO.java
2012-10-22 15:38:39 UTC (rev 6031)
+++
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/DataStorageDAO.java
2012-11-19 07:56:19 UTC (rev 6032)
@@ -4,16 +4,9 @@
import org.perfsonar.base2.xml.Element;
import org.perfsonar.base2.xml.nmwg.Data;
+public interface DataStorageDAO
+{
+ Data fetch(Element request) throws PerfSONARException;
-/**
- * $Id: DataStorageDAO.java 4684 2008-11-03 13:07:33Z roman $
- */
-public interface DataStorageDAO {
-
-
- public Data fetch(Element request) throws PerfSONARException;
-
- public void store(Element request) throws PerfSONARException;
-
-
-} //DataStorageDAO
\ No newline at end of file
+ void store(Element request) throws PerfSONARException;
+} //DataStorageDAO
Modified:
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/DataStorageDAOFactory.java
===================================================================
---
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/DataStorageDAOFactory.java
2012-10-22 15:38:39 UTC (rev 6031)
+++
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/DataStorageDAOFactory.java
2012-11-19 07:56:19 UTC (rev 6032)
@@ -3,37 +3,39 @@
import org.perfsonar.base2.service.configuration.ConfigurationManager;
import org.perfsonar.base2.service.exceptions.PerfSONARException;
-/**
- * $Id: DataStorageDAOFactory.java 4684 2008-11-03 13:07:33Z roman $
- */
-public class DataStorageDAOFactory {
-
-
+public final class DataStorageDAOFactory
+{
private static DataStorageDAO dao = null;
public static final String DATA_STORAGE_DAO_NAME = "dataStorageDAO";
+ private DataStorageDAOFactory()
+ {
+ }
- public static DataStorageDAO getDAO() throws PerfSONARException {
+ public static DataStorageDAO getDAO() throws PerfSONARException
+ {
return getDAO(DATA_STORAGE_DAO_NAME);
}
- public static DataStorageDAO getDAO(String name) throws
PerfSONARException {
+ public static DataStorageDAO getDAO(String name) throws
PerfSONARException
+ {
- if (dao != null) return dao;
+ if (dao != null) {
+ return dao;
+ }
try {
dao = (DataStorageDAO) ConfigurationManager.getInstance().
- getConfiguration().getAuxiliaryComponent(name);
+ getConfiguration().getAuxiliaryComponent(name);
return dao;
- } catch (Exception ex) {
- throw new PerfSONARException(
- "no_data_storage_dao",
- "Cannot return 'dataStorageDAO' component; " +
ex.toString());
+ } catch (Exception ex) {
+ throw new PerfSONARException("no_data_storage_dao",
+ "Cannot return 'dataStorageDAO'
component; " + ex.toString());
}
}
-} //DataStorageDAOFactory
\ No newline at end of file
+} //DataStorageDAOFactory
Modified:
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/MetadataStorageDAO.java
===================================================================
---
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/MetadataStorageDAO.java
2012-10-22 15:38:39 UTC (rev 6031)
+++
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/MetadataStorageDAO.java
2012-11-19 07:56:19 UTC (rev 6032)
@@ -5,21 +5,15 @@
import java.util.Collection;
-/**
- * $Id: MetadataStorageDAO.java 4684 2008-11-03 13:07:33Z roman $
- */
-public interface MetadataStorageDAO {
+public interface MetadataStorageDAO
+{
+ Collection<Element> fetch(Element request) throws PerfSONARException;
+ String rawFetch(Element request) throws PerfSONARException;
- public Collection<Element> fetch(Element request) throws
PerfSONARException;
+ void store(Element request) throws PerfSONARException;
- public String rawFetch(Element request) throws PerfSONARException;
+ void update(Element request) throws PerfSONARException;
- public void store(Element request) throws PerfSONARException;
-
- public void update(Element request) throws PerfSONARException;
-
- public void remove(Element request) throws PerfSONARException;
-
-
-} //MetadataStorageDAO
\ No newline at end of file
+ void remove(Element request) throws PerfSONARException;
+} //MetadataStorageDAO
Modified:
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/MetadataStorageDAOFactory.java
===================================================================
---
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/MetadataStorageDAOFactory.java
2012-10-22 15:38:39 UTC (rev 6031)
+++
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/MetadataStorageDAOFactory.java
2012-11-19 07:56:19 UTC (rev 6032)
@@ -3,38 +3,40 @@
import org.perfsonar.base2.service.configuration.ConfigurationManager;
import org.perfsonar.base2.service.exceptions.PerfSONARException;
-/**
- * $Id: MetadataStorageDAOFactory.java 4684 2008-11-03 13:07:33Z roman $
- */
-public class MetadataStorageDAOFactory {
-
-
+public final class MetadataStorageDAOFactory
+{
private static MetadataStorageDAO dao = null;
public static final String METADATA_STORAGE_DAO_NAME =
"metadataStorageDAO2";
+ private MetadataStorageDAOFactory()
+ {
+ }
- public static MetadataStorageDAO getDAO() throws PerfSONARException {
+ public static MetadataStorageDAO getDAO() throws PerfSONARException
+ {
return getDAO(METADATA_STORAGE_DAO_NAME);
}
- public static MetadataStorageDAO getDAO(String name) throws
PerfSONARException {
+ public static MetadataStorageDAO getDAO(String name) throws
PerfSONARException
+ {
- if (dao != null) return dao;
+ if (dao != null) {
+ return dao;
+ }
try {
- dao = (MetadataStorageDAO)ConfigurationManager.getInstance().
- getConfiguration().getAuxiliaryComponent(name);
+ dao = (MetadataStorageDAO) ConfigurationManager.getInstance().
+ getConfiguration().getAuxiliaryComponent(name);
return dao;
- } catch (Exception ex) {
- throw new PerfSONARException(
- "no_metadata_storage_dao",
- "Cannot return 'metadataStorageDAO' component; " +
ex.toString());
+ } catch (Exception ex) {
+ throw new PerfSONARException("no_metadata_storage_dao",
+ "Cannot return
'metadataStorageDAO' component; " + ex.toString());
}
}
-} //MetadataStorageDAOFactory
\ No newline at end of file
+} //MetadataStorageDAOFactory
Modified:
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/exist/ExistMetadataStorageDAOImpl.java
===================================================================
---
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/exist/ExistMetadataStorageDAOImpl.java
2012-10-22 15:38:39 UTC (rev 6031)
+++
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/exist/ExistMetadataStorageDAOImpl.java
2012-11-19 07:56:19 UTC (rev 6032)
@@ -24,19 +24,17 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-/**
- * $Id: ExistMetadataStorageDAOImpl.java 4684 2008-11-03 13:07:33Z roman $
- */
-public class ExistMetadataStorageDAOImpl extends Component implements
MetadataStorageDAO {
+public class ExistMetadataStorageDAOImpl extends Component implements
MetadataStorageDAO
+{
// ------------------------------------------------------------- class
fields
- private static final Logger logger =
LoggerFactory.getLogger(ExistMetadataStorageDAOImpl.class);
+ private static final Logger LOGGER =
LoggerFactory.getLogger(ExistMetadataStorageDAOImpl.class);
- private XMLDataStorage dataStorage = null;
- private String dataCollection = null;
+ private XMLDataStorage dataStorage = null;
+ private String dataCollection = null;
private DataCredential dataCredential = null;
private QueryGeneratorManager queryGeneratorManager = null;
@@ -45,16 +43,16 @@
// ------------------------------------------------------------- class
const
- protected final static String EXIST_COMPONENT_REFERENCE = "exist-config";
+ protected static final String EXIST_COMPONENT_REFERENCE = "exist-config";
- protected final static String
QUERY_GENERATOR_MANAGER_COMPONENT_REFERENCE =
- "queryGeneratorManager-config";
+ protected static final String
QUERY_GENERATOR_MANAGER_COMPONENT_REFERENCE = "queryGeneratorManager-config";
// -------------------------------------------------------------
constructor
- public ExistMetadataStorageDAOImpl() throws PerfSONARException {
+ public ExistMetadataStorageDAOImpl() throws PerfSONARException
+ {
super();
dataStorage = new ExtendedExistHTTPDataStorage();
@@ -65,32 +63,32 @@
// ------------------------------------------------------------- methods
- public void run() throws PerfSONARException {
+ public void run() throws PerfSONARException
+ {
}
- public void init() throws PerfSONARException {
+ public void init() throws PerfSONARException
+ {
- Configuration configuration =
- ConfigurationManager.
- getInstance().
- getConfiguration();
+ Configuration configuration = ConfigurationManager.
+ getInstance().
+ getConfiguration();
String existConfigComponent =
getOption(EXIST_COMPONENT_REFERENCE).getValue();
- XMLDBComponent xmlDbComponent =
- (XMLDBComponent)
configuration.getAuxiliaryComponent(existConfigComponent);
+ XMLDBComponent xmlDbComponent = (XMLDBComponent)
configuration.getAuxiliaryComponent(existConfigComponent);
setDataCollection(xmlDbComponent.getUri());
setDataCredential(xmlDbComponent.getCredential());
- String queryGeneratorManagerComponent =
-
getOption(QUERY_GENERATOR_MANAGER_COMPONENT_REFERENCE).getValue();
- queryGeneratorManager = (QueryGeneratorManager)
-
configuration.getAuxiliaryComponent(queryGeneratorManagerComponent);
+ String queryGeneratorManagerComponent =
getOption(QUERY_GENERATOR_MANAGER_COMPONENT_REFERENCE).getValue();
+ queryGeneratorManager = (QueryGeneratorManager)
configuration.getAuxiliaryComponent(
+ queryGeneratorManagerComponent);
}
- public void destroy() throws PerfSONARException {
+ public void destroy() throws PerfSONARException
+ {
dataStorage = null;
dataCollection = null;
@@ -101,19 +99,20 @@
}
- public Collection<Element> fetch(Element request) throws
PerfSONARException {
+ public Collection<Element> fetch(Element request) throws
PerfSONARException
+ {
String query = queryGeneratorManager.getQuery(request);
- XMLDBResult result = dataStorage.performXQuery(
- query, this.dataCollection, this.dataCredential);
+ XMLDBResult result = dataStorage.performXQuery(query,
this.dataCollection, this.dataCredential);
return result.getResults();
}
- public String rawFetch(Element request) throws PerfSONARException {
+ public String rawFetch(Element request) throws PerfSONARException
+ {
String query = queryGeneratorManager.getQuery(request);
/*String results =
@@ -121,57 +120,59 @@
query, this.dataCollection, this.dataCredential, request);
*/
FetchData fd = new FetchData();
- fd.fetchMetadataMessage();
- String results = fd.MetadataContent;
+ fd.fetchMetadataMessage();
+ String results = fd.getMetadataContent();
return results;
}
- public void store(Element request) throws PerfSONARException {
- throw new PerfSONARException(
- "storing_not_supported",
- "Can not store metadata elements.");
+ public void store(Element request) throws PerfSONARException
+ {
+ throw new PerfSONARException("storing_not_supported", "Can not store
metadata elements.");
}
- public void update(Element request) throws PerfSONARException {
- throw new PerfSONARException(
- "updating_not_supported",
- "Can not update metadata elements.");
+ public void update(Element request) throws PerfSONARException
+ {
+ throw new PerfSONARException("updating_not_supported", "Can not
update metadata elements.");
}
- public void remove(Element request) throws PerfSONARException {
- throw new PerfSONARException(
- "removing_not_supported",
- "Can not remove metadata elements.");
+ public void remove(Element request) throws PerfSONARException
+ {
+ throw new PerfSONARException("removing_not_supported", "Can not
remove metadata elements.");
}
// -------------------------------------------------------------
protected methods
- public void setDataCredential(DataCredential dc) {
+ public void setDataCredential(DataCredential dc)
+ {
this.dataCredential = dc;
}
- public DataCredential getDataCredential() {
+ public DataCredential getDataCredential()
+ {
return dataCredential;
}
- public void setDataCollection(String dc) {
+ public void setDataCollection(String dc)
+ {
this.dataCollection = dc;
}
- public String getDataCollection() {
+ public String getDataCollection()
+ {
return dataCollection;
}
- public XMLDataStorage getDataStorage() {
+ public XMLDataStorage getDataStorage()
+ {
return dataStorage;
}
@@ -179,43 +180,46 @@
// ------------------------------------------------------------- private
class
- class ExtendedExistHTTPDataStorage extends ExistHTTPDataStorage {
+ class ExtendedExistHTTPDataStorage extends ExistHTTPDataStorage
+ {
- public ExtendedExistHTTPDataStorage() {
+ public ExtendedExistHTTPDataStorage()
+ {
super();
}
- public String getXQueryStringResult(
- String xquery,
- String collection,
- DataCredential credential,
- Element request) throws PerfSONARException {
+ public String getXQueryStringResult(String xquery, String
collection, DataCredential credential,
+ Element request) throws
PerfSONARException
+ {
try {
- HTTPResult httpResult =
- httpAccess.sendXQueryPOSTRequest(
- collection,
- xquery,
- credential.getUsername(),
- credential.getPassword(),
-
org.perfsonar.base2.service.storage.xml.exist.ExistDbHTTPAccess.FIRST,
-
org.perfsonar.base2.service.storage.xml.exist.ExistDbHTTPAccess.ALL_RESULTS);
+ HTTPResult httpResult =
httpAccess.sendXQueryPOSTRequest(collection, xquery, credential.getUsername(),
+
credential.getPassword(),
+
org.perfsonar.base2.service.storage.xml
+
.exist.ExistDbHTTPAccess.FIRST,
+
org.perfsonar.base2.service.storage.xml
+
.exist.ExistDbHTTPAccess.ALL_RESULTS);
InputStream is = httpResult.getResponse();
BufferedReader reader = new BufferedReader(new
InputStreamReader(is));
StringBuffer sb = new StringBuffer();
int c;
- while((c = reader.read()) != -1) sb.append((char)c);
+ while ((c = reader.read()) != -1) {
+ sb.append((char) c);
+ }
reader.close();
String result = sb.toString();
result = extractXMLTag(result, "exist:result");
sb = new StringBuffer();
- String type = (request.getAttribute("type") == null? "":
request.getAttribute("type").replaceFirst("Request", "Response"));
- sb.append("<nmwg:message type=\"").append(type).append("\"
xmlns:nmwg=\"http://ggf.org/ns/nmwg/base/2.0/\"
xmlns=\"http://ggf.org/ns/nmwg/base/2.0/\">");
+ String type = (request.getAttribute("type") == null
+ ? ""
+ :
request.getAttribute("type").replaceFirst("Request", "Response"));
+ sb.append("<nmwg:message type=\"").append(type).append(
+ "\" xmlns:nmwg=\"http://ggf.org/ns/nmwg/base/2.0/\"
xmlns=\"http://ggf.org/ns/nmwg/base/2.0/\">");
sb.append(result);
sb.append("</nmwg:message>");
@@ -224,35 +228,39 @@
return result;
} catch (Exception ex) {
- throw new PerfSONARException(
- "error.common.storage.xmldb.open",
- "XQuery by HTTP failed. "
- + "Could not connect to eXist via pure http, "
- + " nested exception was: "
- + ex.getClass()+" : "+ex.getMessage());
+ throw new
PerfSONARException("error.common.storage.xmldb.open",
+ "XQuery by HTTP failed. " +
"Could not connect to eXist via pure http, "
+ + " nested exception was: "
+ ex.getClass() + " : " + ex.getMessage());
}
}
- protected String extractXMLTag(String str, String tag) {
+ protected String extractXMLTag(String str, String tag)
+ {
- //trim from blank spaces
+ //trim from blank spaces
str = str.trim();
//find starting tag
- int indexStartTag1 = str.indexOf("<"+tag);
- if (indexStartTag1==-1) return null;
+ int indexStartTag1 = str.indexOf("<" + tag);
+ if (indexStartTag1 == -1) {
+ return null;
+ }
//find end of starting tag
int indexStartTag2 = str.indexOf(">", indexStartTag1);
- if (indexStartTag2==-1) return null;
+ if (indexStartTag2 == -1) {
+ return null;
+ }
//find closing tag
- int indexEndTag1 = str.indexOf("</"+tag, indexStartTag2);
- if (indexEndTag1==-1) return null;
+ int indexEndTag1 = str.indexOf("</" + tag, indexStartTag2);
+ if (indexEndTag1 == -1) {
+ return null;
+ }
- String substr = str.substring(indexStartTag2+1, indexEndTag1);
+ String substr = str.substring(indexStartTag2 + 1, indexEndTag1);
return substr;
}
@@ -261,5 +269,4 @@
} //ExtendedExistHTTPDataStorage
-
} //ExistMetadataStorageDAOImpl
Modified:
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/exist/QueryGeneratorManager.java
===================================================================
---
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/exist/QueryGeneratorManager.java
2012-10-22 15:38:39 UTC (rev 6031)
+++
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/exist/QueryGeneratorManager.java
2012-11-19 07:56:19 UTC (rev 6032)
@@ -11,23 +11,19 @@
import org.perfsonar.base2.xml.nmwg.Metadata;
import
org.perfsonar.service.measurementArchive.rrdType.storage.exist.query.QueryGenerator;
-
-/**
- * $Id: QueryGeneratorManager.java 4684 2008-11-03 13:07:33Z roman $
- */
-public class QueryGeneratorManager extends Component {
-
-
+public class QueryGeneratorManager extends Component
+{
// ----------------------------------------------------------- Variables
- protected static final Logger logger =
LoggerFactory.getLogger(QueryGeneratorManager.class);
+ protected static final Logger LOGGER =
LoggerFactory.getLogger(QueryGeneratorManager.class);
// -------------------------------------------------------------
constructor
- public QueryGeneratorManager() {
+ public QueryGeneratorManager()
+ {
super();
}
@@ -35,61 +31,59 @@
// ------------------------------------------------------------- methods
- public void run()throws PerfSONARException {
+ public void run() throws PerfSONARException
+ {
}
- public void init() throws PerfSONARException {
+ public void init() throws PerfSONARException
+ {
}
- public void destroy() throws PerfSONARException {
+ public void destroy() throws PerfSONARException
+ {
}
- public String getQuery(Element queryElement)
- throws PerfSONARException {
+ public String getQuery(Element queryElement) throws PerfSONARException
+ {
- QueryGenerator queryGenerator =
- getQueryGenerator(queryElement);
+ QueryGenerator queryGenerator = getQueryGenerator(queryElement);
String query = queryGenerator.getQuery(queryElement);
- logger.debug(query);
+ LOGGER.debug(query);
return query;
}
- protected QueryGenerator getQueryGenerator(Element queryElement)
- throws PerfSONARException {
+ protected QueryGenerator getQueryGenerator(Element queryElement) throws
PerfSONARException
+ {
- if (!(queryElement instanceof Message))
- throw new PerfSONARException(
- "parse",
- "Object [" + queryElement.getClass() + "] is not a valid
Message ["
- + Message.class
- + "] element.");
+ if (!(queryElement instanceof Message)) {
+ throw new PerfSONARException("parse", "Object [" +
queryElement.getClass() + "] is not a valid Message ["
+ + Message.class + "] element.");
+ }
- String eventType = getEventType((Message)queryElement);
+ String eventType = getEventType((Message) queryElement);
String className = this.getOption(eventType).getValue();
QueryGenerator queryGenerator = null;
try {
queryGenerator = (QueryGenerator)
Class.forName(className).newInstance();
} catch (Exception ex) {
- logger.warn("can not create an object of " + className +
"class");
- throw new PerfSONARException(
- "object_creation_exception",
- "can not create an object of "
- + className + "class");
+ LOGGER.warn("can not create an object of " + className +
"class");
+ throw new PerfSONARException("object_creation_exception",
+ "can not create an object of " +
className + "class");
}
return queryGenerator;
}
- protected String getEventType(Message request)
- throws PerfSONARException {
+ protected String getEventType(Message request) throws PerfSONARException
+ {
String eventType = null;
for (Metadata m : request.getMetadataCollection()) {
@@ -98,27 +92,23 @@
eventType = m.getFirstEventType().getEventType().trim();
} catch (Exception ex) {
- logger.warn("can not find correct eventType in metadata
element");
- throw new PerfSONARException(
- "query_exception",
- "can not find correct eventType in metadata
element");
+ LOGGER.warn("can not find correct eventType in metadata
element");
+ throw new PerfSONARException("query_exception", "can not
find correct eventType in metadata element");
}
- if (eventType != null) break;
+ if (eventType != null) {
+ break;
+ }
}
- if (request.getMetadataCollection().size() == 0) {
- logger.warn("can not find any metadatas with a valid content");
- throw new PerfSONARException(
- "query_exception",
- "can not find any metadatas with a valid content");
+ if (request.getMetadataCollection().isEmpty()) {
+ LOGGER.warn("can not find any metadatas with a valid content");
+ throw new PerfSONARException("query_exception", "can not find
any metadatas with a valid content");
}
if (eventType == null) {
- logger.warn("can not find correct eventType in metadata
element");
- throw new PerfSONARException(
- "query_exception",
- "can not find eventType in metadata element");
+ LOGGER.warn("can not find correct eventType in metadata
element");
+ throw new PerfSONARException("query_exception", "can not find
eventType in metadata element");
}
return eventType;
Modified:
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/exist/query/DiscardsQueryGenerator.java
===================================================================
---
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/exist/query/DiscardsQueryGenerator.java
2012-10-22 15:38:39 UTC (rev 6031)
+++
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/exist/query/DiscardsQueryGenerator.java
2012-11-19 07:56:19 UTC (rev 6032)
@@ -3,36 +3,36 @@
import org.perfsonar.base2.xml.Element;
import org.perfsonar.base2.service.exceptions.PerfSONARException;
-/**
- * $Id$
- */
-public class DiscardsQueryGenerator extends InterfaceBasedQueryGenerator {
+public class DiscardsQueryGenerator extends InterfaceBasedQueryGenerator
+{
// ------------------------------------------------------------- fields
- public final static String DECLARE_DISCARDS_NAMESPACE =
- "declare namespace
discards='http://ggf.org/ns/nmwg/characteristic/discards/2.0/'; \n";
+ public static final String DECLARE_DISCARDS_NAMESPACE =
+ "declare namespace discards='http://ggf" +
".org/ns/nmwg/characteristic/discards/2.0/'; \n";
// -------------------------------------------------------------
constructor
- public DiscardsQueryGenerator() {
+ public DiscardsQueryGenerator()
+ {
super();
- DECLARE_CHARACTERISTIC_NAMESPACE = DECLARE_DISCARDS_NAMESPACE;
+ declareCharacteristicNamespace = DECLARE_DISCARDS_NAMESPACE;
}
// ------------------------------------------------------------- methods
- public String getQuery (Element queryElement) throws PerfSONARException {
+ public String getQuery(Element queryElement) throws PerfSONARException
+ {
return getQuery(queryElement, "discards");
}
-} //DiscardsQueryGenerator
\ No newline at end of file
+} //DiscardsQueryGenerator
Modified:
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/exist/query/ErrorsQueryGenerator.java
===================================================================
---
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/exist/query/ErrorsQueryGenerator.java
2012-10-22 15:38:39 UTC (rev 6031)
+++
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/exist/query/ErrorsQueryGenerator.java
2012-11-19 07:56:19 UTC (rev 6032)
@@ -3,36 +3,36 @@
import org.perfsonar.base2.xml.Element;
import org.perfsonar.base2.service.exceptions.PerfSONARException;
-/**
- * $Id$
- */
-public class ErrorsQueryGenerator extends InterfaceBasedQueryGenerator {
+public class ErrorsQueryGenerator extends InterfaceBasedQueryGenerator
+{
// ------------------------------------------------------------- fields
- public final static String DECLARE_ERRORS_NAMESPACE =
- "declare namespace
errors='http://ggf.org/ns/nmwg/characteristic/errors/2.0/'; \n";
+ public static final String DECLARE_ERRORS_NAMESPACE =
+ "declare namespace errors='http://ggf" +
".org/ns/nmwg/characteristic/errors/2.0/'; \n";
// -------------------------------------------------------------
constructor
- public ErrorsQueryGenerator() {
+ public ErrorsQueryGenerator()
+ {
super();
- DECLARE_CHARACTERISTIC_NAMESPACE = DECLARE_ERRORS_NAMESPACE;
+ declareCharacteristicNamespace = DECLARE_ERRORS_NAMESPACE;
}
// ------------------------------------------------------------- methods
- public String getQuery (Element queryElement) throws PerfSONARException {
+ public String getQuery(Element queryElement) throws PerfSONARException
+ {
return getQuery(queryElement, "errors");
}
-} //ErrorsQueryGenerator
\ No newline at end of file
+} //ErrorsQueryGenerator
Modified:
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/exist/query/InterfaceBasedQueryGenerator.java
===================================================================
---
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/exist/query/InterfaceBasedQueryGenerator.java
2012-10-22 15:38:39 UTC (rev 6031)
+++
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/exist/query/InterfaceBasedQueryGenerator.java
2012-11-19 07:56:19 UTC (rev 6032)
@@ -8,213 +8,250 @@
import org.perfsonar.base2.xml.nmwg.Parameters;
import org.perfsonar.base2.service.exceptions.PerfSONARException;
-/**
- * $Id$
- */
-public abstract class InterfaceBasedQueryGenerator implements QueryGenerator
{
+public abstract class InterfaceBasedQueryGenerator implements QueryGenerator
+{
// ------------------------------------------------------------- class
const
- public final static String DECLARE_NMWGT_NAMESPACE =
- "declare namespace nmwgt='http://ggf.org/ns/nmwg/topology/2.0/'; \n";
+ public static final String DECLARE_NMWGT_NAMESPACE =
+ "declare namespace nmwgt='http://ggf.org/ns/nmwg/topology/2" +
".0/'; \n";
- protected String DECLARE_CHARACTERISTIC_NAMESPACE = "";
+ protected String declareCharacteristicNamespace = "";
// ------------------------------------------------------------- methods
- public String getQuery(Element queryElement, String nsPrefix) throws
PerfSONARException {
+ public String getQuery(Element queryElement, String nsPrefix) throws
PerfSONARException
+ {
Message message = (Message) queryElement;
- String eventType = null;
- String keyword = null;
- String keywordType = null;
+ String eventType = null;
+ String keyword = null;
+ String keywordType = null;
- String ipAddress = null;
- String hostName = null;
- String ifName = null;
- String ifDescription = null;
- String ifAddress = null;
- String ifAddressType = null;
- String ifIndex = null;
- String type = null;
- String direction = null;
+ String ipAddress = null;
+ String hostName = null;
+ String ifName = null;
+ String ifDescription = null;
+ String ifAddress = null;
+ String ifAddressType = null;
+ String ifIndex = null;
+ String type = null;
+ String direction = null;
String classOfService = null;
- String capacity = null;
+ String capacity = null;
- Metadata metadata =
- message.getMetadataCollection().iterator().next();
+ Metadata metadata =
message.getMetadataCollection().iterator().next();
eventType = metadata.getFirstEventType().getEventType().trim();
Parameters parameters = metadata.getParameters();
Parameter keywordParameter = null;
- if (parameters != null)
+ if (parameters != null) {
keywordParameter = parameters.getFirstParameter("keyword");
+ }
String keywordQueryPart = "";
if (keywordParameter != null) {
keyword = keywordParameter.getText();
- if (!keyword.trim().equals(""))
- keywordQueryPart = " and
$i/nmwg:parameters/nmwg:parameter[(functx:trim(text())='"+ keyword +"' and
functx:trim(@name)='keyword') or (functx:trim(@value)='" + keyword + "' and
functx:trim(@name)='keyword')] ";
+ if (!keyword.trim().isEmpty()) {
+ keywordQueryPart = " and
$i/nmwg:parameters/nmwg:parameter[(functx:trim(text())='" + keyword
+ + "' and functx:trim(@name)='keyword') or
(functx:trim(@value)='" + keyword
+ + "' and functx:trim(@name)='keyword')] ";
+ }
}
Subject subject = metadata.getSubject();
if (subject != null) {
Element interf = subject.getFirstChild("interface");
if (interf != null) {
- ipAddress = (interf.getFirstChild("ipAddress") !=
null ? interf.getFirstChild("ipAddress").getText().trim() : null);
- hostName = (interf.getFirstChild("hostName") !=
null ? interf.getFirstChild("hostName").getText().trim() : null);
- ifName = (interf.getFirstChild("ifName") !=
null ? interf.getFirstChild("ifName").getText().trim() : null);
- ifDescription = (interf.getFirstChild("ifDescription") !=
null ? interf.getFirstChild("ifDescription").getText().trim() : null);
- ifAddress = (interf.getFirstChild("ifAddress") !=
null ? interf.getFirstChild("ifAddress").getText().trim() : null);
- ifIndex = (interf.getFirstChild("ifIndex") !=
null ? interf.getFirstChild("ifIndex").getText().trim() : null);
- type = (interf.getFirstChild("type") !=
null ? interf.getFirstChild("type").getText().trim() : null);
- direction = (interf.getFirstChild("direction") !=
null ? interf.getFirstChild("direction").getText().trim() : null);
- classOfService = (interf.getFirstChild("classOfService") !=
null ? interf.getFirstChild("classOfService").getText().trim() : null);
- capacity = (interf.getFirstChild("capacity") !=
null ? interf.getFirstChild("capacity").getText().trim() : null);
+ ipAddress = (interf.getFirstChild("ipAddress") != null ?
interf.getFirstChild(
+ "ipAddress").getText().trim() : null);
+ hostName = (interf.getFirstChild("hostName") != null
+ ?
interf.getFirstChild("hostName").getText().trim()
+ : null);
+ ifName = (interf.getFirstChild("ifName") != null
+ ? interf.getFirstChild("ifName").getText().trim()
+ : null);
+ ifDescription = (interf.getFirstChild("ifDescription") !=
null ? interf.getFirstChild(
+ "ifDescription").getText().trim() : null);
+ ifAddress = (interf.getFirstChild("ifAddress") != null ?
interf.getFirstChild(
+ "ifAddress").getText().trim() : null);
+ ifIndex = (interf.getFirstChild("ifIndex") != null
+ ? interf.getFirstChild("ifIndex").getText().trim()
+ : null);
+ type = (interf.getFirstChild("type") != null ?
interf.getFirstChild("type").getText().trim() : null);
+ direction = (interf.getFirstChild("direction") != null ?
interf.getFirstChild(
+ "direction").getText().trim() : null);
+ classOfService = (interf.getFirstChild("classOfService") !=
null ? interf.getFirstChild(
+ "classOfService").getText().trim() : null);
+ capacity = (interf.getFirstChild("capacity") != null
+ ?
interf.getFirstChild("capacity").getText().trim()
+ : null);
try {
- ifAddressType =
(!interf.getFirstChild("ifAddress").getAttribute("type").trim().equals("") ?
interf.getFirstChild("ifAddress").getAttribute("type").trim(): null);
+ ifAddressType =
(!interf.getFirstChild("ifAddress").getAttribute("type").trim().isEmpty()
+ ?
interf.getFirstChild("ifAddress").getAttribute("type").trim()
+ : null);
} catch (Exception ex) {
- ifAddressType = null;
+ ifAddressType = null;
}
} else {
- throw new PerfSONARException(
- "query_exception",
- "no interface element in metadata element");
+ throw new PerfSONARException("query_exception", "no
interface element in metadata element");
}
} else {
- throw new PerfSONARException(
- "query_exception",
- "no subject element in metadata element");
+ throw new PerfSONARException("query_exception", "no subject
element in metadata element");
}
// fetching all metadata
- if (ipAddress == null &&
- hostName == null &&
- ifName == null &&
- ifDescription == null &&
- ifAddress == null &&
- ifIndex == null &&
- type == null &&
- direction == null &&
- classOfService == null &&
- capacity == null &&
- keywordParameter == null) {
+ if (ipAddress == null
+ && hostName == null
+ && ifName == null
+ && ifDescription == null
+ && ifAddress == null
+ && ifIndex == null
+ && type == null
+ && direction == null
+ && classOfService == null
+ && capacity == null
+ && keywordParameter == null) {
String query =
- "let $res :=
\n"
- + " for $i in //nmwg:metadata
\n"
- + " where
\n"
- + "
$i/nmwg:parameters/nmwg:parameter[(functx:trim(text())='" + eventType + "'
and functx:trim(@name)='supportedEventType') \n"
- + " or (functx:trim(@value)='" + eventType + "' and
functx:trim(@name)='supportedEventType')] \n"
- + " or
\n"
- + " $i/nmwg:eventType[functx:trim(text())='" +
eventType + "']
\n"
- + " return $i
\n"
- + "\n"
- + "let $datas :=
\n"
- + "
//nmwg:data/nmwg:key/nmwg:parameters/nmwg:parameter[functx:trim(@name)='eventType'
and (functx:trim(text())='" + eventType + "' or functx:trim(@value)='" +
eventType + "')]/parent::*/parent::*/parent::* \n"
- + "\n"
- + "return ($res, $datas) \n";
+ "let $res :=
"
+ + " \n"
+ + " for $i in //nmwg:metadata
"
+ + " \n"
+ + " where
"
+ + " \n"
+ + "
$i/nmwg:parameters/nmwg:parameter[(functx:trim(text())='" + eventType
+ + "' and functx:trim(@name)='supportedEventType')
\n" + " or (functx:trim(@value)='"
+ + eventType + "' and
functx:trim(@name)='supportedEventType')] \n"
+ + " or
"
+ + " \n" + "
$i/nmwg:eventType[functx:trim(text())='"
+ + eventType + "']
\n"
+ + " return $i
"
+ + " \n" + "\n"
+ + "let $datas :=
"
+ + " \n"
+ + "
//nmwg:data/nmwg:key/nmwg:parameters/nmwg:parameter[functx:trim(@name)='eventType'
and "
+ + "(functx:trim(text())='" + eventType + "' or
functx:trim(@value)='" + eventType
+ + "')]/parent::*/parent::*/parent::* \n" + "\n" +
"return ($res, $datas) \n";
- return DECLARE_NMWG_NAMESPACE
- + DECLARE_TRIM_FUNC
- + query;
+ return DECLARE_NMWG_NAMESPACE + DECLARE_TRIM_FUNC + query;
}
-
String query =
- " let $res := \n"
- + " for $i in //nmwg:metadata \n"
- + " where 1 \n";
+ " let $res := \n" + " for $i in
//nmwg:metadata \n"
+ + " where 1 \n";
- if (eventType != null)
- query += "and
(($i/nmwg:parameters/nmwg:parameter[(functx:trim(text())='" + eventType + "'
and functx:trim(@name)='supportedEventType') "
- + "or
(functx:trim(@value)='" + eventType + "' and
functx:trim(@name)='supportedEventType')]) "
- + "or "
- + "($i/nmwg:eventType[functx:trim(text())='" +
eventType + "'])"
- + ") "
- + keywordQueryPart;
+ if (eventType != null) {
+ query += "and
(($i/nmwg:parameters/nmwg:parameter[(functx:trim(text())='" + eventType
+ + "' and functx:trim(@name)='supportedEventType') " + "or
(functx:trim(@value)='" + eventType
+ + "' and functx:trim(@name)='supportedEventType')]) " + "or "
+ + "($i/nmwg:eventType[functx:trim(text())='" + eventType +
"'])" + ") " + keywordQueryPart;
+ }
/*
-------------------------------------------------------------------------*/
if (ipAddress != null) {
- if (ipAddress.equals(""))
+ if (ipAddress.isEmpty()) {
throw new PerfSONARException("query_exception", " wrong
ipAddress");
- query += "and $i/" + nsPrefix +
":subject/nmwgt:interface/nmwgt:ipAddress[functx:trim(text())='" + ipAddress
+ "'] ";
+ }
+ query += "and $i/" + nsPrefix +
":subject/nmwgt:interface/nmwgt:ipAddress[functx:trim(text())='" + ipAddress
+ + "'] ";
}
if (hostName != null) {
- if (hostName.equals(""))
+ if (hostName.isEmpty()) {
throw new PerfSONARException("query_exception", "wrong
hostName");
- query += "and $i/" + nsPrefix +
":subject/nmwgt:interface/nmwgt:hostName[functx:trim(text())='" + hostName +
"'] ";
+ }
+ query += "and $i/" + nsPrefix +
":subject/nmwgt:interface/nmwgt:hostName[functx:trim(text())='" + hostName
+ + "'] ";
}
if (ifName != null) {
- if (ifName.equals(""))
+ if (ifName.isEmpty()) {
throw new PerfSONARException("query_exception", "wrong
ifName");
- query += "and $i/" + nsPrefix +
":subject/nmwgt:interface/nmwgt:ifName[functx:trim(text())='" + ifName + "']
";
+ }
+ query +=
+ "and $i/" + nsPrefix +
":subject/nmwgt:interface/nmwgt:ifName[functx:trim(text())='" + ifName + "']
";
}
if (ifDescription != null) {
- if (ifDescription.equals(""))
+ if (ifDescription.isEmpty()) {
throw new PerfSONARException("query_exception", "wrong
ifDescription");
- query += "and $i/" + nsPrefix +
":subject/nmwgt:interface/nmwgt:ifDescription[functx:trim(text())='" +
ifDescription + "'] ";
+ }
+ query += "and $i/" + nsPrefix +
":subject/nmwgt:interface/nmwgt:ifDescription[functx:trim(text())='"
+ + ifDescription + "'] ";
}
if (ifAddress != null) {
- if (ifAddress.equals("") && ifAddressType == null)
+ if (ifAddress.isEmpty() && ifAddressType == null) {
throw new PerfSONARException("query_exception", "wrong
ifAddress");
- if (!ifAddress.equals(""))
- query += "and $i/" + nsPrefix +
":subject/nmwgt:interface/nmwgt:ifAddress[functx:trim(text())='" + ifAddress
+ "'] ";
+ }
+ if (!ifAddress.isEmpty()) {
+ query +=
+ "and $i/" + nsPrefix +
":subject/nmwgt:interface/nmwgt:ifAddress[functx:trim(text())='" + ifAddress
+ + "'] ";
+ }
}
if (ifIndex != null) {
- if (ifIndex.equals(""))
+ if (ifIndex.isEmpty()) {
throw new PerfSONARException("query_exception", "wrong
ifIndex");
- query += "and $i/" + nsPrefix +
":subject/nmwgt:interface/nmwgt:ifIndex[functx:trim(text())='" + ifIndex +
"'] ";
+ }
+ query +=
+ "and $i/" + nsPrefix +
":subject/nmwgt:interface/nmwgt:ifIndex[functx:trim(text())='" + ifIndex +
"'] ";
}
if (type != null) {
- if (type.equals(""))
+ if (type.isEmpty()) {
throw new PerfSONARException("query_exception", "wrong
type");
+ }
query += "and $i/" + nsPrefix +
":subject/nmwgt:interface/nmwgt:type[functx:trim(text())='" + type + "'] ";
}
if (direction != null) {
- if (direction.equals(""))
+ if (direction.isEmpty()) {
throw new PerfSONARException("query_exception", "wrong
direction");
- query += "and $i/"+ nsPrefix +
":subject/nmwgt:interface/nmwgt:direction[functx:trim(text())='" + direction
+ "'] ";
+ }
+ query += "and $i/" + nsPrefix +
":subject/nmwgt:interface/nmwgt:direction[functx:trim(text())='" + direction
+ + "'] ";
}
if (classOfService != null) {
- if (classOfService.equals(""))
+ if (classOfService.isEmpty()) {
throw new PerfSONARException("query_exception", "wrong
classOfService");
- query += "and $i/" + nsPrefix +
":subject/nmwgt:interface/nmwgt:classOfService[functx:trim(text())='" +
classOfService + "'] ";
+ }
+ query += "and $i/" + nsPrefix +
":subject/nmwgt:interface/nmwgt:classOfService[functx:trim(text())='"
+ + classOfService + "'] ";
}
if (capacity != null) {
- if (capacity.equals(""))
+ if (capacity.isEmpty()) {
throw new PerfSONARException("query_exception", "wrong
capacity");
- query += "and $i/" + nsPrefix +
":subject/nmwgt:interface/nmwgt:capacity[functx:trim(text())='" + capacity +
"'] ";
+ }
+ query += "and $i/" + nsPrefix +
":subject/nmwgt:interface/nmwgt:capacity[functx:trim(text())='" + capacity
+ + "'] ";
}
- if (ifAddressType != null)
- query += "and $i/" + nsPrefix +
":subject/nmwgt:interface/nmwgt:ifAddress[functx:trim(@type)='" +
ifAddressType + "'] ";
+ if (ifAddressType != null) {
+ query +=
+ "and $i/" + nsPrefix +
":subject/nmwgt:interface/nmwgt:ifAddress[functx:trim(@type)='" +
ifAddressType
+ + "'] ";
+ }
/*
-------------------------------------------------------------------------*/
- query += "\n"
- + " return $i \n"
+ query += "\n" + " return $i
\n"
+ " \n"
+ " let $metaids := \n"
+ " for $j in $res \n"
@@ -229,10 +266,7 @@
+ " return ($res, $datas) \n";
- query = DECLARE_NMWG_NAMESPACE
- + DECLARE_CHARACTERISTIC_NAMESPACE
- + DECLARE_NMWGT_NAMESPACE
- + DECLARE_TRIM_FUNC
+ query = DECLARE_NMWG_NAMESPACE + declareCharacteristicNamespace +
DECLARE_NMWGT_NAMESPACE + DECLARE_TRIM_FUNC
+ query;
@@ -244,4 +278,4 @@
}
-} //InterfaceBasedQueryGenerator
\ No newline at end of file
+} //InterfaceBasedQueryGenerator
Modified:
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/exist/query/QueryGenerator.java
===================================================================
---
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/exist/query/QueryGenerator.java
2012-10-22 15:38:39 UTC (rev 6031)
+++
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/exist/query/QueryGenerator.java
2012-11-19 07:56:19 UTC (rev 6032)
@@ -3,26 +3,19 @@
import org.perfsonar.base2.xml.Element;
import org.perfsonar.base2.service.exceptions.PerfSONARException;
-/**
- * $Id: QueryGenerator.java 4684 2008-11-03 13:07:33Z roman $
- */
-public interface QueryGenerator {
-
-
- public final static String DECLARE_NMWG_NAMESPACE =
+public interface QueryGenerator
+{
+ String DECLARE_NMWG_NAMESPACE =
"declare namespace nmwg='http://ggf.org/ns/nmwg/base/2.0/'; \n";
- public final static String DECLARE_NMWGR_NAMESPACE =
- "declare namespace nmwgr='http://ggf.org/ns/nmwg/result/2.0/'; \n";
+ String DECLARE_NMWGR_NAMESPACE =
+ "declare namespace nmwgr='http://ggf.org/ns/nmwg/result/2" + ".0/';
\n";
- public final static String DECLARE_TRIM_FUNC = "\n"
- + "declare namespace functx = 'http://www.functx.com';\n"
- + "declare function functx:trim \n"
- + " ( $arg as xs:string? ) as xs:string { \n"
- + " replace(replace($arg,'\\s+$',''),'^\\s+','') \n"
- + "}; \n\n";
+ String DECLARE_TRIM_FUNC = "\n" + "declare namespace functx =
'http://www.functx.com';\n"
+ + "declare function functx:trim \n"
+ + " ( $arg as xs:string? ) as xs:string { \n"
+ + " replace(replace($arg,'\\s+$',''),'^\\s+','') \n"
+ + "}; \n\n";
- public String getQuery (Element queryElement) throws PerfSONARException;
-
-
-} //QueryGenerator
\ No newline at end of file
+ String getQuery(Element queryElement) throws PerfSONARException;
+} //QueryGenerator
Modified:
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/exist/query/RandomFetchTestQueryGenerator.java
===================================================================
---
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/exist/query/RandomFetchTestQueryGenerator.java
2012-10-22 15:38:39 UTC (rev 6031)
+++
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/exist/query/RandomFetchTestQueryGenerator.java
2012-11-19 07:56:19 UTC (rev 6032)
@@ -3,17 +3,10 @@
import org.perfsonar.base2.xml.Element;
import org.perfsonar.base2.service.exceptions.PerfSONARException;
-/**
- * $Id$
- */
-public class RandomFetchTestQueryGenerator implements QueryGenerator {
-
-
- public String getQuery(Element queryElement) throws PerfSONARException {
-
+public class RandomFetchTestQueryGenerator implements QueryGenerator
+{
+ public String getQuery(Element queryElement) throws PerfSONARException
+ {
return "//*:data[1]";
-
}
-
-
-} //RandomFetchTestQueryGenerator
\ No newline at end of file
+} //RandomFetchTestQueryGenerator
Modified:
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/exist/query/SNMPQueryGenerator.java
===================================================================
---
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/exist/query/SNMPQueryGenerator.java
2012-10-22 15:38:39 UTC (rev 6031)
+++
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/exist/query/SNMPQueryGenerator.java
2012-11-19 07:56:19 UTC (rev 6032)
@@ -3,35 +3,31 @@
import org.perfsonar.base2.xml.Element;
import org.perfsonar.base2.service.exceptions.PerfSONARException;
-/**
- * $Id$
- */
-public class SNMPQueryGenerator extends InterfaceBasedQueryGenerator {
-
-
+public class SNMPQueryGenerator extends InterfaceBasedQueryGenerator
+{
// ------------------------------------------------------------- fields
- public final static String DECLARE_NETUTIL_NAMESPACE = "";
+ public static final String DECLARE_NETUTIL_NAMESPACE = "";
// -------------------------------------------------------------
constructor
- public SNMPQueryGenerator() {
+ public SNMPQueryGenerator()
+ {
super();
- DECLARE_CHARACTERISTIC_NAMESPACE = DECLARE_NETUTIL_NAMESPACE;
+ declareCharacteristicNamespace = DECLARE_NETUTIL_NAMESPACE;
}
// ------------------------------------------------------------- methods
- public String getQuery(Element queryElement) throws PerfSONARException {
+ public String getQuery(Element queryElement) throws PerfSONARException
+ {
return getQuery(queryElement, "*");
}
-
-
-} //SNMPQueryGenerator
\ No newline at end of file
+} //SNMPQueryGenerator
Modified:
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/exist/query/UtilizationQueryGenerator.java
===================================================================
---
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/exist/query/UtilizationQueryGenerator.java
2012-10-22 15:38:39 UTC (rev 6031)
+++
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/exist/query/UtilizationQueryGenerator.java
2012-11-19 07:56:19 UTC (rev 6032)
@@ -3,36 +3,34 @@
import org.perfsonar.base2.xml.Element;
import org.perfsonar.base2.service.exceptions.PerfSONARException;
-/**
- * $Id$
- */
-public class UtilizationQueryGenerator extends InterfaceBasedQueryGenerator {
-
-
+public class UtilizationQueryGenerator extends InterfaceBasedQueryGenerator
+{
// ------------------------------------------------------------- fields
- public final static String DECLARE_NETUTIL_NAMESPACE =
- "declare namespace
netutil='http://ggf.org/ns/nmwg/characteristic/utilization/2.0/'; \n";
+ public static final String DECLARE_NETUTIL_NAMESPACE =
+ "declare namespace netutil='http://ggf" +
".org/ns/nmwg/characteristic/utilization/2.0/'; \n";
// -------------------------------------------------------------
constructor
- public UtilizationQueryGenerator() {
+ public UtilizationQueryGenerator()
+ {
super();
- DECLARE_CHARACTERISTIC_NAMESPACE = DECLARE_NETUTIL_NAMESPACE;
+ declareCharacteristicNamespace = DECLARE_NETUTIL_NAMESPACE;
}
// ------------------------------------------------------------- methods
- public String getQuery (Element queryElement) throws PerfSONARException {
+ public String getQuery(Element queryElement) throws PerfSONARException
+ {
return getQuery(queryElement, "netutil");
}
-} //UtilizationQueryGenerator
\ No newline at end of file
+} //UtilizationQueryGenerator
Modified:
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/exist/query/XmlDbAccessTestQueryGenerator.java
===================================================================
---
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/exist/query/XmlDbAccessTestQueryGenerator.java
2012-10-22 15:38:39 UTC (rev 6031)
+++
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/exist/query/XmlDbAccessTestQueryGenerator.java
2012-11-19 07:56:19 UTC (rev 6032)
@@ -3,25 +3,13 @@
import org.perfsonar.base2.xml.Element;
import org.perfsonar.base2.service.exceptions.PerfSONARException;
-/**
- * $Id$
- */
-public class XmlDbAccessTestQueryGenerator implements QueryGenerator {
-
-
- public String getQuery(Element queryElement) throws PerfSONARException {
-
- String query = DECLARE_NMWG_NAMESPACE
- + DECLARE_NMWGR_NAMESPACE
- + "let $version := system:get-version() \n"
- + "return \n"
- + " <nmwg:data> \n"
- + " <nmwgr:datum>Xml Database ver. {$version} is
accessible.</nmwgr:datum> \n"
- + " </nmwg:data> \n";
-
- return query;
-
+public class XmlDbAccessTestQueryGenerator implements QueryGenerator
+{
+ public String getQuery(Element queryElement) throws PerfSONARException
+ {
+ return
+ DECLARE_NMWG_NAMESPACE + DECLARE_NMWGR_NAMESPACE + "let $version
:= system:get-version() \n" + "return \n"
+ + " <nmwg:data> \n" + " <nmwgr:datum>Xml Database ver.
{$version} is accessible.</nmwgr:datum> \n"
+ + " </nmwg:data> \n";
}
-
-
-} //XmlDbAccessTestQueryGenerator
\ No newline at end of file
+} //XmlDbAccessTestQueryGenerator
Modified:
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/exist/query/XmlDbContentTestQueryGenerator.java
===================================================================
---
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/exist/query/XmlDbContentTestQueryGenerator.java
2012-10-22 15:38:39 UTC (rev 6031)
+++
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/exist/query/XmlDbContentTestQueryGenerator.java
2012-11-19 07:56:19 UTC (rev 6032)
@@ -3,27 +3,14 @@
import org.perfsonar.base2.xml.Element;
import org.perfsonar.base2.service.exceptions.PerfSONARException;
-/**
- * $Id$
- */
-public class XmlDbContentTestQueryGenerator implements QueryGenerator {
-
-
- public String getQuery(Element queryElement) throws PerfSONARException {
-
- String query = DECLARE_NMWG_NAMESPACE
- + DECLARE_NMWGR_NAMESPACE
- + "let $metadatas : = count(//nmwg:metadata) \n"
- + "let $datas : = count(//nmwg:data) \n"
- + "let $elements : = $metadatas + $datas \n"
- + "return \n"
- + " <nmwg:data> \n"
- + " <nmwgr:datum>Number of all metadata and data
elements in the xml database is {$elements}.</nmwgr:datum> \n"
- + " </nmwg:data> \n";
-
- return query;
-
+public class XmlDbContentTestQueryGenerator implements QueryGenerator
+{
+ public String getQuery(Element queryElement) throws PerfSONARException
+ {
+ return DECLARE_NMWG_NAMESPACE + DECLARE_NMWGR_NAMESPACE + "let
$metadatas : = count(//nmwg:metadata) \n"
+ + "let $datas : = count(//nmwg:data) \n" + "let $elements : =
$metadatas + $datas \n" + "return \n"
+ + " <nmwg:data> \n"
+ + " <nmwgr:datum>Number of all metadata and data elements in
the xml database is {$elements}"
+ + ".</nmwgr:datum> \n" + " </nmwg:data> \n";
}
-
-
-} //XmlDbContentTestQueryGenerator
\ No newline at end of file
+} //XmlDbContentTestQueryGenerator
Modified:
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/persistence/MetadaKeyResponse.java
===================================================================
---
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/persistence/MetadaKeyResponse.java
2012-10-22 15:38:39 UTC (rev 6031)
+++
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/persistence/MetadaKeyResponse.java
2012-11-19 07:56:19 UTC (rev 6032)
@@ -8,143 +8,165 @@
import
org.perfsonar.service.measurementArchive.rrdType.storage.persistence.entity.Interfaces;
/**
- * This class is used to genereate text result of NWMG response for
MetadataKeyRequest
- * @author Piotr Pikusa
<
+ * This class is used to genereate text result of NWMG response for
MetadataKeyRequest.
*
+ * @author Piotr Pikusa
<>
*/
-public class MetadaKeyResponse {
+public class MetadaKeyResponse
+{
+ private static final Logger LOGGER =
LoggerFactory.getLogger(MetadaKeyResponse.class);
- private static final Logger logger =
LoggerFactory.getLogger(MetadaKeyResponse.class);
-
- private final String EVENT_TYPE_UTIL =
"http://ggf.org/ns/nmwg/characteristic/utilization/2.0/";
- private final String EVENT_TYPE_ERRORS =
"http://ggf.org/ns/nmwg/characteristic/errors/2.0/";
- private final String EVENT_TYPE_DISCARDS =
"http://ggf.org/ns/nmwg/characteristic/discards/2.0/";
-
-
- public String fetchMetadataMessage(Iterator<Interfaces> ifIterator)
throws PerfSONARException {
-
- StringBuilder sb = new StringBuilder();
-
- Interfaces intf;
- String eol = System.getProperty("line.separator");
-
- if(!ifIterator.hasNext()){
- return "<nmwg:metadata id=\"resultCodeMetadata\"> " +
eol +
-
"<nmwg:eventType>warning.ma.metadata_configuration</nmwg:eventType>" + eol +
- "</nmwg:metadata>" + eol +
- "<nmwg:data
id=\"resultDescriptionData_for_resultCodeMetadata\"
metadataIdRef=\"resultCodeMetadata\">" + eol +
- "<nmwgr:datum
xmlns:nmwgr=\"http://ggf.org/ns/nmwg/result/2.0/\">MetadataConfigurationStorageManager.fetch:
No metadata in the metadata configuration</nmwgr:datum>" + eol +
- "</nmwg:data>" + eol;
- }
- while(ifIterator.hasNext()){
- intf = ifIterator.next();
- sb.append(fetchMetadataRowNmwg(intf));
- sb.append(fetchDataRowNmwg(intf));
- }
-
- return sb.toString();
-
- }
-
-
- public String fetchMetadataRowNmwg(Interfaces intf) throws
PerfSONARException {
- String subject = "";
-
- if(EVENT_TYPE_UTIL.startsWith(intf.getEventType().trim()))
- subject = "netutil";
- else
if(EVENT_TYPE_ERRORS.startsWith(intf.getEventType().trim()))
- subject = "errors";
- else
if(EVENT_TYPE_DISCARDS.startsWith(intf.getEventType().trim()))
- subject = "discards";
- else{
- throw new PerfSONARException("query_exception",
"EventType: " + intf.getEventType() + " is incorrect");
- }
-
- StringBuilder metadata = new StringBuilder();
-
- try {
- metadata.append("<nmwg:metadata
xmlns:nmwg=\"http://ggf.org/ns/nmwg/base/2.0/\"
id=\"").append(intf.getMetadataId()).append("\">").append("\n");
- metadata.append("<").append(subject).append(":subject
xmlns:").append(subject).append("=\"").append(intf.getEventType()).append("/\"
id=\"").append(intf.getSubjId()).append("\">").append("\n");
- metadata.append(
- "<nmwgt:interface
xmlns:nmwgt=\"http://ggf.org/ns/nmwg/topology/2.0/\">"
- + "\n");
-
metadata.append("<nmwgt:hostName>").append(intf.getHostName()).append("</nmwgt:hostName>").append("\n");
- //ifAddresType is optional
- if(intf.getIfAddressType() == null)
- intf.setIfAddressType("");
- metadata.append("<nmwgt:ifAddress
type=\"").append(intf.getIfAddressType()).append("\">").append(intf.getIfAddress()).append("</nmwgt:ifAddress>").append("\n");
-
metadata.append("<nmwgt:ifName>").append(intf.getIfName()).append("</nmwgt:ifName>").append("\n");
-
metadata.append("<nmwgt:ifDescription>").append(intf.getIfDescription()).append("</nmwgt:ifDescription>").append("\n");
-
metadata.append("<nmwgt:direction>").append(intf.getDirection()).append("</nmwgt:direction>").append("\n");
-
metadata.append("<nmwgt:capacity>").append(intf.getCapacity()).append("</nmwgt:capacity>").append("\n");
- metadata.append("<nmwgt:authRealm></nmwgt:authRealm>"
+ "\n");
- metadata.append("</nmwgt:interface>" + "\n");
-
metadata.append("</").append(subject).append(":subject>").append("\n");
-
metadata.append("<nmwg:eventType>").append(intf.getEventType()).append("</nmwg:eventType>").append("\n");
+ private static final String EVENT_TYPE_UTIL =
"http://ggf.org/ns/nmwg/characteristic/utilization/2.0/";
+ private static final String EVENT_TYPE_ERRORS =
"http://ggf.org/ns/nmwg/characteristic/errors/2.0/";
+ private static final String EVENT_TYPE_DISCARDS =
"http://ggf.org/ns/nmwg/characteristic/discards/2.0/";
- if(intf.getKeyword() != null &&
!intf.getKeyword().trim().equals("")){
- metadata.append("<parameters
id=\"params1\">\n");
- metadata.append("<parameter
name=\"keyword\">").append(intf.getKeyword()).append("</parameter>");
- metadata.append("</parameters>");
- }
- metadata.append("</nmwg:metadata>");
-
-
- } catch (Exception e) {
- logger.error("can not find correct parameter in
database");
- throw new PerfSONARException("response_exception",
- e.getMessage());
- }
+ public String fetchMetadataMessage(Iterator<Interfaces> ifIterator)
throws PerfSONARException
+ {
- return metadata.toString();
- }
-
+ StringBuilder sb = new StringBuilder();
- public String fetchDataRowNmwg(Interfaces intf) throws
PerfSONARException {
-
- StringBuilder sb = new StringBuilder();
-
- try {
- sb.append("<nmwg:data
xmlns:nmwg=\"http://ggf.org/ns/nmwg/base/2.0/\"
id=\"data").append(intf.getMetadataId()).append("\"
metadataIdRef=\"").append(intf.getMetadataId()).append("\">").append("\n");
- sb.append("<nmwg:key>" + "\n");
- sb.append("<nmwg:parameters>"+ "\n");
- sb.append("<nmwg:parameter
name=\"file\">").append(intf.getFile().trim()).append("</nmwg:parameter>").append("\n");
- sb.append("<nmwg:parameter
name=\"dataSource\">").append(intf.getDataSource().trim()).append("</nmwg:parameter>").append("\n");
- sb.append("<nmwg:parameter
name=\"valueUnits\">").append(intf.getValueUnits().trim()).append("</nmwg:parameter>").append("\n");
- sb.append("<nmwg:parameter
name=\"eventType\">").append(intf.getEventType().trim()).append("</nmwg:parameter>").append("\n");
-
- } catch (Exception e) {
+ Interfaces intf;
+ String eol = System.getProperty("line.separator");
- logger.error("can not find correct parameter in adata
element");
- throw new PerfSONARException("response_exception",
- e.getMessage());
- }
-
- //Optional parameters of RRD file
- if(intf.getDataSource() == null)
- intf.setDataSource("");
- sb.append("<nmwg:parameter
name=\"dataSourceStep\">").append(intf.getDataSource().trim()).append("</nmwg:parameter>").append("\n");
- if(intf.getDataSourceType() == null)
- intf.setDataSourceType("");
- sb.append("<nmwg:parameter
name=\"dataSourceType\">").append(intf.getDataSourceType().trim()).append("</nmwg:parameter>").append("\n");
- if(intf.getEventType() == null)
- intf.setEventType("");
- sb.append("<nmwg:parameter
name=\"dataSourceHeartbeat\">").append(intf.getEventType().trim()).append("</nmwg:parameter>").append("\n");
- if(intf.getDataSourceMinValue() == null)
- intf.setDataSourceMinValue("");
- sb.append("<nmwg:parameter
name=\"dataSourceMinValue\">").append(intf.getDataSourceMinValue().trim()).append("</nmwg:parameter>").append("\n");
- if(intf.getDataSourceMaxValue() == null)
- intf.setDataSourceMaxValue("");
- sb.append("<nmwg:parameter
name=\"dataSourceMaxValue\">").append(intf.getDataSourceMaxValue().trim()).append("</nmwg:parameter>").append("\n");
+ if (!ifIterator.hasNext()) {
+ return "<nmwg:metadata id=\"resultCodeMetadata\"> " + eol
+ +
"<nmwg:eventType>warning.ma.metadata_configuration</nmwg:eventType>" + eol
+ + "</nmwg:metadata>" + eol
+ + "<nmwg:data
id=\"resultDescriptionData_for_resultCodeMetadata\" "
+ + "metadataIdRef=\"resultCodeMetadata\">" + eol
+ + "<nmwgr:datum
xmlns:nmwgr=\"http://ggf.org/ns/nmwg/result/2"
+ + ".0/\">MetadataConfigurationStorageManager"
+ + ".fetch: No metadata in the metadata
configuration</nmwgr:datum>" + eol
+ + "</nmwg:data>" + eol;
+ }
+ while (ifIterator.hasNext()) {
+ intf = ifIterator.next();
+ sb.append(fetchMetadataRowNmwg(intf));
+ sb.append(fetchDataRowNmwg(intf));
+ }
- sb.append("</nmwg:parameters>"+ "\n");
- sb.append("</nmwg:key>" + "\n");
- sb.append("</nmwg:data>"+ "\n");
-
- return sb.toString();
- }
+ return sb.toString();
+ }
+ public String fetchMetadataRowNmwg(Interfaces intf) throws
PerfSONARException
+ {
+ String subject = "";
+
+ if (EVENT_TYPE_UTIL.startsWith(intf.getEventType().trim())) {
+ subject = "netutil";
+ } else if (EVENT_TYPE_ERRORS.startsWith(intf.getEventType().trim()))
{
+ subject = "errors";
+ } else if
(EVENT_TYPE_DISCARDS.startsWith(intf.getEventType().trim())) {
+ subject = "discards";
+ } else {
+ throw new PerfSONARException("query_exception", "EventType: " +
intf.getEventType() + " is incorrect");
+ }
+
+ StringBuilder metadata = new StringBuilder();
+
+ try {
+ metadata.append("<nmwg:metadata
xmlns:nmwg=\"http://ggf.org/ns/nmwg/base/2.0/\" id=\"").append(
+ intf.getMetadataId()).append("\">").append("\n");
+ metadata.append("<").append(subject).append(":subject
xmlns:").append(subject).append("=\"").append(
+ intf.getEventType()).append("/\"
id=\"").append(intf.getSubjId()).append("\">").append("\n");
+ metadata.append("<nmwgt:interface
xmlns:nmwgt=\"http://ggf.org/ns/nmwg/topology/2.0/\">" + "\n");
+
metadata.append("<nmwgt:hostName>").append(intf.getHostName()).append("</nmwgt:hostName>").append("\n");
+ //ifAddresType is optional
+ if (intf.getIfAddressType() == null) {
+ intf.setIfAddressType("");
+ }
+ metadata.append("<nmwgt:ifAddress
type=\"").append(intf.getIfAddressType()).append("\">").append(
+
intf.getIfAddress()).append("</nmwgt:ifAddress>").append("\n");
+
metadata.append("<nmwgt:ifName>").append(intf.getIfName()).append("</nmwgt:ifName>").append("\n");
+
metadata.append("<nmwgt:ifDescription>").append(intf.getIfDescription()).append(
+ "</nmwgt:ifDescription>").append("\n");
+
metadata.append("<nmwgt:direction>").append(intf.getDirection()).append("</nmwgt:direction>").append("\n");
+
metadata.append("<nmwgt:capacity>").append(intf.getCapacity()).append("</nmwgt:capacity>").append("\n");
+ metadata.append("<nmwgt:authRealm></nmwgt:authRealm>" + "\n");
+ metadata.append("</nmwgt:interface>" + "\n");
+
metadata.append("</").append(subject).append(":subject>").append("\n");
+
metadata.append("<nmwg:eventType>").append(intf.getEventType()).append("</nmwg:eventType>").append("\n");
+
+ if (intf.getKeyword() != null &&
!intf.getKeyword().trim().isEmpty()) {
+ metadata.append("<parameters id=\"params1\">\n");
+ metadata.append("<parameter
name=\"keyword\">").append(intf.getKeyword()).append("</parameter>");
+ metadata.append("</parameters>");
+ }
+ metadata.append("</nmwg:metadata>");
+
+
+ } catch (Exception e) {
+
+ LOGGER.error("can not find correct parameter in database");
+ throw new PerfSONARException("response_exception",
e.getMessage());
+ }
+
+ return metadata.toString();
+ }
+
+
+ public String fetchDataRowNmwg(Interfaces intf) throws PerfSONARException
+ {
+
+ StringBuilder sb = new StringBuilder();
+
+ try {
+ sb.append("<nmwg:data
xmlns:nmwg=\"http://ggf.org/ns/nmwg/base/2.0/\" id=\"data").append(
+ intf.getMetadataId()).append("\"
metadataIdRef=\"").append(intf.getMetadataId()).append("\">").append(
+ "\n");
+ sb.append("<nmwg:key>" + "\n");
+ sb.append("<nmwg:parameters>" + "\n");
+ sb.append("<nmwg:parameter
name=\"file\">").append(intf.getFile().trim()).append(
+ "</nmwg:parameter>").append("\n");
+ sb.append("<nmwg:parameter
name=\"dataSource\">").append(intf.getDataSource().trim()).append(
+ "</nmwg:parameter>").append("\n");
+ sb.append("<nmwg:parameter
name=\"valueUnits\">").append(intf.getValueUnits().trim()).append(
+ "</nmwg:parameter>").append("\n");
+ sb.append("<nmwg:parameter
name=\"eventType\">").append(intf.getEventType().trim()).append(
+ "</nmwg:parameter>").append("\n");
+
+ } catch (Exception e) {
+
+ LOGGER.error("can not find correct parameter in adata element");
+ throw new PerfSONARException("response_exception",
e.getMessage());
+ }
+
+ //Optional parameters of RRD file
+ if (intf.getDataSource() == null) {
+ intf.setDataSource("");
+ }
+ sb.append("<nmwg:parameter
name=\"dataSourceStep\">").append(intf.getDataSource().trim()).append(
+ "</nmwg:parameter>").append("\n");
+ if (intf.getDataSourceType() == null) {
+ intf.setDataSourceType("");
+ }
+ sb.append("<nmwg:parameter
name=\"dataSourceType\">").append(intf.getDataSourceType().trim()).append(
+ "</nmwg:parameter>").append("\n");
+ if (intf.getEventType() == null) {
+ intf.setEventType("");
+ }
+ sb.append("<nmwg:parameter
name=\"dataSourceHeartbeat\">").append(intf.getEventType().trim()).append(
+ "</nmwg:parameter>").append("\n");
+ if (intf.getDataSourceMinValue() == null) {
+ intf.setDataSourceMinValue("");
+ }
+ sb.append("<nmwg:parameter
name=\"dataSourceMinValue\">").append(intf.getDataSourceMinValue().trim()).append(
+ "</nmwg:parameter>").append("\n");
+ if (intf.getDataSourceMaxValue() == null) {
+ intf.setDataSourceMaxValue("");
+ }
+ sb.append("<nmwg:parameter
name=\"dataSourceMaxValue\">").append(intf.getDataSourceMaxValue().trim()).append(
+ "</nmwg:parameter>").append("\n");
+
+ sb.append("</nmwg:parameters>" + "\n");
+ sb.append("</nmwg:key>" + "\n");
+ sb.append("</nmwg:data>" + "\n");
+
+ return sb.toString();
+ }
+
+
}
Modified:
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/persistence/SetupDataKeyResponse.java
===================================================================
---
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/persistence/SetupDataKeyResponse.java
2012-10-22 15:38:39 UTC (rev 6031)
+++
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/persistence/SetupDataKeyResponse.java
2012-11-19 07:56:19 UTC (rev 6032)
@@ -19,119 +19,123 @@
/**
- * This class is used to genereate response for SetupDataaKeyRequest
including Metadata objects
- * @author Piotr Pikusa
<
+ * This class is used to genereate response for SetupDataaKeyRequest
including Metadata objects.
*
+ * @author Piotr Pikusa
<>
*/
-public class SetupDataKeyResponse {
+public class SetupDataKeyResponse
+{
+ private static final String NAMESPACE_UTIL =
"http://ggf.org/ns/nmwg/characteristic/utilization/2.0/";
+ private static final String NAMESPACE_ERRORS =
"http://ggf.org/ns/nmwg/characteristic/errors/2.0/";
+ private static final String NAMESPACE_DISCARDS =
"http://ggf.org/ns/nmwg/characteristic/discards/2.0/";
- private final String NAMESPACE_UTIL =
"http://ggf.org/ns/nmwg/characteristic/utilization/2.0/";
- private final String NAMESPACE_ERRORS =
"http://ggf.org/ns/nmwg/characteristic/errors/2.0/";
- private final String NAMESPACE_DISCARDS =
"http://ggf.org/ns/nmwg/characteristic/discards/2.0/";
-
- protected static final Logger logger =
LoggerFactory.getLogger(SetupDataKeyResponse.class);
+ protected static final Logger LOGGER =
LoggerFactory.getLogger(SetupDataKeyResponse.class);
-
- public Collection<Element> fetchElements(Iterator iterator) throws
PerfSONARException{
- Collection<Element> result = new ArrayList<Element>();
-
- while (iterator.hasNext()) {
- Interfaces intf= (Interfaces) iterator.next();
- Metadata m = fetchMetadata(intf);
- result.add(m);
- result.add(fetchData(intf, m.getId()));
- }
- return result;
- }
- private Data fetchData(Interfaces intf, String id) {
- Data d = new Data();
-
- Key k = new Key();
- Parameters params = new Parameters();
- params.addParameter(getParameter("file", intf.getFile()));
- params.addParameter(getParameter("dataSource",
intf.getDataSource()));
- params.addParameter(getParameter("valueUnits",
intf.getValueUnits()));
- params.addParameter(getParameter("dataSourceStep",
intf.getDataSourceStep()));
- params.addParameter(getParameter("dataSourceType",
intf.getDataSourceType()));
- params.addParameter(getParameter("dataSourceHeartbeat",
intf.getDataSourceHeartbeat()));
- params.addParameter(getParameter("dataSourceMinValue",
intf.getDataSourceMinValue()));
- params.addParameter(getParameter("dataSourceMaxValue",
intf.getDataSourceMaxValue()));
- params.addParameter(getParameter(("eventType"),
intf.getEventType()));
- k.setParameters(params);
- d.setKey(k);
- d.setId(String.valueOf(intf.getMetadataId()));
- d.setMetadataIdRef(id);
-
- return d;
- }
-
- private Parameter getParameter(String name, String value){
- Parameter p = new Parameter();
- //p.setParameter(name, value);
-
-
- p.addAttribute("name", name);
- p.setText(value);
- return p;
- }
-
- private Subject getSubject(Interfaces intf) throws PerfSONARException{
- String uri = "";
- String perfix = "";
-
- if(NAMESPACE_UTIL.startsWith(intf.getEventType())){
- uri = NAMESPACE_UTIL;
- perfix = "netutil";
- }else
if(NAMESPACE_ERRORS.startsWith(intf.getEventType().trim())){
- uri = NAMESPACE_ERRORS;
- perfix = "errors";
- }
-
- else
if(NAMESPACE_DISCARDS.startsWith(intf.getEventType().trim())){
- uri = NAMESPACE_DISCARDS;
- perfix = "discards";
- }
- else{
- throw new PerfSONARException("query_exception", "In
database eventType: " + intf.getEventType() + " is incorrect");
- }
-
- Subject s = new Subject();
- s.setDoGenerateId(true);
- s.setNamespaceUri(uri);
- s.setNamespacePrefix(perfix);
-
- return s;
- }
+ public Collection<Element> fetchElements(Iterator iterator) throws
PerfSONARException
+ {
+ Collection<Element> result = new ArrayList<Element>();
- private Element createElement(String name, String value){
- Element e = new Element(name,"nmwgt"
,"http://ggf.org/ns/nmwg/topology/2.0/");
- e.setText(value);
- return e;
- }
-
- private Metadata fetchMetadata(Interfaces intf) throws
PerfSONARException{
-
- Element interf = new Element("interface","nmwgt"
,"http://ggf.org/ns/nmwg/topology/2.0/");
- Element ifAddress = createElement("ifAddress",
intf.getIfAddress());
- ifAddress.addAttribute("type", intf.getIfAddressType());
- interf.addChild(ifAddress);
- interf.addChild(createElement("hostName",
intf.getHostName()));
- interf.addChild(createElement("ifName", intf.getIfName()));
- interf.addChild(createElement("ifDescription",
intf.getIfDescription()));
- interf.addChild(createElement("direction",
intf.getDirection()));
- interf.addChild(createElement("capacity",
intf.getCapacity()));
-
- Subject s = getSubject(intf);
- s.addChild(interf);
- s.setId(interf.getId());
- Metadata m = new Metadata();
- m.setSubject(s);
-
- //m.addChild(interf);
- m.setEventType(new EventType(intf.getEventType(), "nmwg"));
- m.setId(interf.getId());
-
- return m;
- }
+ while (iterator.hasNext()) {
+ Interfaces intf = (Interfaces) iterator.next();
+ Metadata m = fetchMetadata(intf);
+ result.add(m);
+ result.add(fetchData(intf, m.getId()));
+ }
+ return result;
+ }
+
+ private Data fetchData(Interfaces intf, String id)
+ {
+ Data d = new Data();
+
+ Key k = new Key();
+ Parameters params = new Parameters();
+ params.addParameter(getParameter("file", intf.getFile()));
+ params.addParameter(getParameter("dataSource",
intf.getDataSource()));
+ params.addParameter(getParameter("valueUnits",
intf.getValueUnits()));
+ params.addParameter(getParameter("dataSourceStep",
intf.getDataSourceStep()));
+ params.addParameter(getParameter("dataSourceType",
intf.getDataSourceType()));
+ params.addParameter(getParameter("dataSourceHeartbeat",
intf.getDataSourceHeartbeat()));
+ params.addParameter(getParameter("dataSourceMinValue",
intf.getDataSourceMinValue()));
+ params.addParameter(getParameter("dataSourceMaxValue",
intf.getDataSourceMaxValue()));
+ params.addParameter(getParameter(("eventType"),
intf.getEventType()));
+ k.setParameters(params);
+ d.setKey(k);
+ d.setId(String.valueOf(intf.getMetadataId()));
+ d.setMetadataIdRef(id);
+
+ return d;
+ }
+
+ private Parameter getParameter(String name, String value)
+ {
+ Parameter p = new Parameter();
+ //p.setParameter(name, value);
+
+
+ p.addAttribute("name", name);
+ p.setText(value);
+ return p;
+ }
+
+ private Subject getSubject(Interfaces intf) throws PerfSONARException
+ {
+ String uri = "";
+ String perfix = "";
+
+ if (NAMESPACE_UTIL.startsWith(intf.getEventType())) {
+ uri = NAMESPACE_UTIL;
+ perfix = "netutil";
+ } else if (NAMESPACE_ERRORS.startsWith(intf.getEventType().trim())) {
+ uri = NAMESPACE_ERRORS;
+ perfix = "errors";
+ } else if
(NAMESPACE_DISCARDS.startsWith(intf.getEventType().trim())) {
+ uri = NAMESPACE_DISCARDS;
+ perfix = "discards";
+ } else {
+ throw new PerfSONARException("query_exception",
+ "In database eventType: " +
intf.getEventType() + " is incorrect");
+ }
+
+ Subject s = new Subject();
+ s.setDoGenerateId(true);
+ s.setNamespaceUri(uri);
+ s.setNamespacePrefix(perfix);
+
+ return s;
+ }
+
+ private Element createElement(String name, String value)
+ {
+ Element e = new Element(name, "nmwgt",
"http://ggf.org/ns/nmwg/topology/2.0/");
+ e.setText(value);
+ return e;
+ }
+
+ private Metadata fetchMetadata(Interfaces intf) throws PerfSONARException
+ {
+
+ Element interf = new Element("interface", "nmwgt",
"http://ggf.org/ns/nmwg/topology/2.0/");
+ Element ifAddress = createElement("ifAddress", intf.getIfAddress());
+ ifAddress.addAttribute("type", intf.getIfAddressType());
+ interf.addChild(ifAddress);
+ interf.addChild(createElement("hostName", intf.getHostName()));
+ interf.addChild(createElement("ifName", intf.getIfName()));
+ interf.addChild(createElement("ifDescription",
intf.getIfDescription()));
+ interf.addChild(createElement("direction", intf.getDirection()));
+ interf.addChild(createElement("capacity", intf.getCapacity()));
+
+ Subject s = getSubject(intf);
+ s.addChild(interf);
+ s.setId(interf.getId());
+ Metadata m = new Metadata();
+ m.setSubject(s);
+
+ //m.addChild(interf);
+ m.setEventType(new EventType(intf.getEventType(), "nmwg"));
+ m.setId(interf.getId());
+
+ return m;
+ }
}
Modified:
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/persistence/entity/Interfaces.java
===================================================================
---
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/persistence/entity/Interfaces.java
2012-10-22 15:38:39 UTC (rev 6031)
+++
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/persistence/entity/Interfaces.java
2012-11-19 07:56:19 UTC (rev 6032)
@@ -2,7 +2,6 @@
import javax.persistence.Column;
import javax.persistence.Entity;
-import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedNativeQuery;
import javax.persistence.Table;
@@ -10,426 +9,509 @@
@Entity
-@Table(name="interfaces")
+@Table(name
= "interfaces")
@NamedNativeQuery(name = Interfaces.ALL, query = "select * from interfaces
m", resultClass = Interfaces.class)
-public class Interfaces {
+public class Interfaces
+{
+ public static final String ALL = "allInterfaces";
+ public static final String TABLE = "interfaces m";
- public static final String ALL = "allInterfaces";
- public static final String TABLE = "interfaces m";
+ private static final int PRIME = 31;
- @Id @GeneratedValue
- private int metadataId;
+ @Id
+ @GeneratedValue
+ private int metadataId;
- @Column(length=20, nullable=false)
- private String subjId;
+ @Column(length = 20, nullable = false)
+ private String subjId;
- @Column(length=20, nullable=false)
- private String hostName;
+ @Column(length = 20, nullable = false)
+ private String hostName;
- @Column(length=20, nullable=false)
- private String ifAddress;
+ @Column(length = 20, nullable = false)
+ private String ifAddress;
- @Column(length=4, nullable=false)
- private String ifAddressType;
+ @Column(length = 4, nullable = false)
+ private String ifAddressType;
- @Column(length=100, nullable=false)
- private String ifName;
+ @Column(length = 100, nullable = false)
+ private String ifName;
- @Column(length=255, nullable=false)
- private String ifDescription;
+ @Column(length = 255, nullable = false)
+ private String ifDescription;
- @Column(length=20, nullable=false)
- private String direction;
+ @Column(length = 20, nullable = false)
+ private String direction;
- @Column(length=20, nullable=false)
- private String capacity;
+ @Column(length = 20, nullable = false)
+ private String capacity;
- @Column(length=100, nullable=false)
- private String keyword;
+ @Column(length = 100, nullable = false)
+ private String keyword;
- @Column(length=100, nullable=false)
- private String file;
+ @Column(length = 100, nullable = false)
+ private String file;
- @Column(length=20, nullable=false)
- private String dataSource;
+ @Column(length = 20, nullable = false)
+ private String dataSource;
- @Column(length=20, nullable=false)
- private String valueUnits;
+ @Column(length = 20, nullable = false)
+ private String valueUnits;
- @Column(length=100, nullable=false)
- private String eventType;
+ @Column(length = 100, nullable = false)
+ private String eventType;
- @Column(length=20)
- private String dataSourceStep;
+ @Column(length = 20)
+ private String dataSourceStep;
- @Column(length=20)
+ @Column(length = 20)
private String dataSourceType;
- @Column(length=20)
+ @Column(length = 20)
private String dataSourceHeartbeat;
- @Column(length=20)
+ @Column(length = 20)
private String dataSourceMinValue;
- @Column(length=20)
+ @Column(length = 20)
private String dataSourceMaxValue;
-
- public Interfaces() {
- }
-
- /**
- * @param metadataId
- * @param subjId
- * @param hostNam
- * @param ifAddress
- * @param ifDescription
- * @param direction
- * @param capacity
- * @param file
- * @param dataSource
- * @param valueUnits
- * @param eventType
- * @param dataSourceStep
- * @param dataSourceType
- * @param dataSourceMinValue
- * @param dataSourceMaxValue
- */
- public Interfaces(final int metadataId, final String subjId, final
String hostNam, final String ifName,
- final String ifAddress,final String ifAddressType ,
final String ifDescription,
+
+ public Interfaces()
+ {
+ }
+
+ /**
+ * @param metadataId
+ * @param subjId
+ * @param hostNam
+ * @param ifAddress
+ * @param ifDescription
+ * @param direction
+ * @param capacity
+ * @param file
+ * @param dataSource
+ * @param valueUnits
+ * @param eventType
+ * @param dataSourceStep
+ * @param dataSourceType
+ * @param dataSourceMinValue
+ * @param dataSourceMaxValue
+ */
+ public Interfaces(final int metadataId, final String subjId, final
String hostNam, final String ifName,
+ final String ifAddress, final String ifAddressType,
final String ifDescription,
final String direction, final String capacity, final
String keyword, final String file,
final String dataSource, final String valueUnits,
final String eventType,
final String dataSourceStep, final String
dataSourceType, final String dataSourceHeartbeat,
- final String dataSourceMinValue, final String
dataSourceMaxValue) {
- this.metadataId = metadataId;
- this.subjId = subjId;
- this.hostName = hostNam;
- this.ifAddress = ifAddress;
- this.ifAddressType = ifAddressType;
- this.ifName = ifName;
- this.ifDescription = ifDescription;
- this.direction = direction;
- this.capacity = capacity;
- this.keyword = keyword;
- this.file = file;
- this.dataSource = dataSource;
- this.valueUnits = valueUnits;
- this.eventType = eventType;
- this.dataSourceStep = dataSourceStep;
- this.dataSourceType = dataSourceType;
- this.dataSourceHeartbeat = dataSourceHeartbeat;
- this.dataSourceMinValue = dataSourceMinValue;
- this.dataSourceMaxValue = dataSourceMaxValue;
- }
+ final String dataSourceMinValue, final String
dataSourceMaxValue)
+ {
+ this.metadataId = metadataId;
+ this.subjId = subjId;
+ this.hostName = hostNam;
+ this.ifAddress = ifAddress;
+ this.ifAddressType = ifAddressType;
+ this.ifName = ifName;
+ this.ifDescription = ifDescription;
+ this.direction = direction;
+ this.capacity = capacity;
+ this.keyword = keyword;
+ this.file = file;
+ this.dataSource = dataSource;
+ this.valueUnits = valueUnits;
+ this.eventType = eventType;
+ this.dataSourceStep = dataSourceStep;
+ this.dataSourceType = dataSourceType;
+ this.dataSourceHeartbeat = dataSourceHeartbeat;
+ this.dataSourceMinValue = dataSourceMinValue;
+ this.dataSourceMaxValue = dataSourceMaxValue;
+ }
-
- public String getKeyword() {
- return keyword;
- }
- public void setKeyword(String keyword) {
- this.keyword = keyword;
- }
+ public String getKeyword()
+ {
+ return keyword;
+ }
- public String getCapacity() {
- return capacity;
- }
+ public void setKeyword(String keyword)
+ {
+ this.keyword = keyword;
+ }
+ public String getCapacity()
+ {
+ return capacity;
+ }
- public void setCapacity(String capacity) {
- this.capacity = capacity;
- }
+ public void setCapacity(String capacity)
+ {
+ this.capacity = capacity;
+ }
- public String getDataSource() {
- return dataSource;
- }
+ public String getDataSource()
+ {
+ return dataSource;
+ }
- public void setDataSource(String dataSource) {
- this.dataSource = dataSource;
- }
+ public void setDataSource(String dataSource)
+ {
+ this.dataSource = dataSource;
+ }
- public String getDataSourceMaxValue() {
- return dataSourceMaxValue;
- }
+ public String getDataSourceMaxValue()
+ {
+ return dataSourceMaxValue;
+ }
- public void setDataSourceMaxValue(String dataSourceMaxValue) {
- this.dataSourceMaxValue = dataSourceMaxValue;
- }
+ public void setDataSourceMaxValue(String dataSourceMaxValue)
+ {
+ this.dataSourceMaxValue = dataSourceMaxValue;
+ }
- public String getDataSourceMinValue() {
- return dataSourceMinValue;
- }
- public String getDataSourceHeartbeat() {
- return dataSourceHeartbeat;
- }
+ public String getDataSourceMinValue()
+ {
+ return dataSourceMinValue;
+ }
- public void setDataSourceHeartbeat(String dataSourceHeartbeat) {
- this.dataSourceHeartbeat = dataSourceHeartbeat;
- }
+ public String getDataSourceHeartbeat()
+ {
+ return dataSourceHeartbeat;
+ }
- public void setHostName(String hostName) {
- this.hostName = hostName;
- }
-
-
- public void setDataSourceMinValue(String dataSourceMinValue) {
- this.dataSourceMinValue = dataSourceMinValue;
- }
+ public void setDataSourceHeartbeat(String dataSourceHeartbeat)
+ {
+ this.dataSourceHeartbeat = dataSourceHeartbeat;
+ }
+ public void setHostName(String hostName)
+ {
+ this.hostName = hostName;
+ }
- public String getDataSourceStep() {
- return dataSourceStep;
- }
+ public void setDataSourceMinValue(String dataSourceMinValue)
+ {
+ this.dataSourceMinValue = dataSourceMinValue;
+ }
- public void setDataSourceStep(String dataSourceStep) {
- this.dataSourceStep = dataSourceStep;
- }
+ public String getDataSourceStep()
+ {
+ return dataSourceStep;
+ }
- public String getDataSourceType() {
- return dataSourceType;
- }
+ public void setDataSourceStep(String dataSourceStep)
+ {
+ this.dataSourceStep = dataSourceStep;
+ }
- public void setDataSourceType(String dataSourceType) {
- this.dataSourceType = dataSourceType;
- }
+ public String getDataSourceType()
+ {
+ return dataSourceType;
+ }
- public String getDirection() {
- return direction;
- }
+ public void setDataSourceType(String dataSourceType)
+ {
+ this.dataSourceType = dataSourceType;
+ }
- public void setDirection(String direction) {
- this.direction = direction;
- }
+ public String getDirection()
+ {
+ return direction;
+ }
- public String getEventType() {
- return eventType;
- }
+ public void setDirection(String direction)
+ {
+ this.direction = direction;
+ }
- public void setEventType(String eventType) {
- this.eventType = eventType;
- }
+ public String getEventType()
+ {
+ return eventType;
+ }
- public String getFile() {
- return file;
- }
+ public void setEventType(String eventType)
+ {
+ this.eventType = eventType;
+ }
- public void setFile(String file) {
- this.file = file;
- }
+ public String getFile()
+ {
+ return file;
+ }
- public String getHostName() {
- return hostName;
- }
+ public void setFile(String file)
+ {
+ this.file = file;
+ }
- public void setHostNam(String hostName) {
- this.hostName = hostName;
- }
- public String getIfName() {
- return ifName;
- }
+ public String getHostName()
+ {
+ return hostName;
+ }
- public void setIfName(String ifName) {
- this.ifName = ifName;
- }
-
- public String getIfAddress() {
- return ifAddress;
- }
+ public void setHostNam(String hostName)
+ {
+ this.hostName = hostName;
+ }
- public String getIfAddressType() {
- return ifAddressType;
- }
+ public String getIfName()
+ {
+ return ifName;
+ }
- public void setIfAddress(String ifAddress) {
- this.ifAddress = ifAddress;
- }
+ public void setIfName(String ifName)
+ {
+ this.ifName = ifName;
+ }
-
- public void setIfAddressType(String ifAddressType) {
- this.ifAddressType = ifAddressType;
- }
- public String getIfDescription() {
- return ifDescription;
- }
+ public String getIfAddress()
+ {
+ return ifAddress;
+ }
+ public String getIfAddressType()
+ {
+ return ifAddressType;
+ }
- public void setIfDescription(String ifDescription) {
- this.ifDescription = ifDescription;
- }
+ public void setIfAddress(String ifAddress)
+ {
+ this.ifAddress = ifAddress;
+ }
- public int getMetadataId() {
- return metadataId;
- }
+ public void setIfAddressType(String ifAddressType)
+ {
+ this.ifAddressType = ifAddressType;
+ }
- public String getSubjId() {
- return subjId;
- }
+ public String getIfDescription()
+ {
+ return ifDescription;
+ }
- public void setSubjId(String subjId) {
- this.subjId = subjId;
- }
+ public void setIfDescription(String ifDescription)
+ {
+ this.ifDescription = ifDescription;
+ }
- public String getValueUnits() {
- return valueUnits;
- }
+ public int getMetadataId()
+ {
+ return metadataId;
+ }
+ public String getSubjId()
+ {
+ return subjId;
+ }
- public void setValueUnits(String valueUnits) {
- this.valueUnits = valueUnits;
- }
+ public void setSubjId(String subjId)
+ {
+ this.subjId = subjId;
+ }
- @Override
- public int hashCode() {
- final int PRIME = 31;
- int result = metadataId;
- result = PRIME * result + ((capacity == null) ? 0 :
capacity.hashCode());
- result = PRIME * result + ((keyword == null) ? 0 :
keyword.hashCode());
- result = PRIME * result + ((dataSource == null) ? 0 :
dataSource.hashCode());
- result = PRIME * result + ((dataSourceMaxValue == null) ? 0 :
dataSourceMaxValue.hashCode());
- result = PRIME * result + ((dataSourceMinValue == null) ? 0 :
dataSourceMinValue.hashCode());
- result = PRIME * result + ((dataSourceHeartbeat == null) ? 0
: dataSourceHeartbeat.hashCode());
- result = PRIME * result + ((dataSourceStep == null) ? 0 :
dataSourceStep.hashCode());
- result = PRIME * result + ((dataSourceType == null) ? 0 :
dataSourceType.hashCode());
- result = PRIME * result + ((direction == null) ? 0 :
direction.hashCode());
- result = PRIME * result + ((eventType == null) ? 0 :
eventType.hashCode());
- result = PRIME * result + ((file == null) ? 0 :
file.hashCode());
- result = PRIME * result + ((hostName == null) ? 0 :
hostName.hashCode());
- result = PRIME * result + ((ifName == null) ? 0 :
ifName.hashCode());
- result = PRIME * result + ((ifAddress == null) ? 0 :
ifAddress.hashCode());
- result = PRIME * result + ((ifAddressType == null) ? 0 :
ifAddressType.hashCode());
- result = PRIME * result + ((ifDescription == null) ? 0 :
ifDescription.hashCode());
- result = PRIME * result + ((subjId == null) ? 0 :
subjId.hashCode());
- result = PRIME * result + ((valueUnits == null) ? 0 :
valueUnits.hashCode());
- return result;
- }
+ public String getValueUnits()
+ {
+ return valueUnits;
+ }
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- final Interfaces other = (Interfaces) obj;
- if (capacity == null) {
- if (other.capacity != null)
- return false;
- } else if (!capacity.equals(other.capacity))
- return false;
- if (keyword == null) {
- if (other.keyword != null)
- return false;
- } else if (!keyword.equals(other.keyword))
- return false;
- if (dataSource == null) {
- if (other.dataSource != null)
- return false;
- } else if (!dataSource.equals(other.dataSource))
- return false;
- if (dataSourceMaxValue == null) {
- if (other.dataSourceMaxValue != null)
- return false;
- } else if
(!dataSourceMaxValue.equals(other.dataSourceMaxValue))
- return false;
- if (dataSourceMinValue == null) {
- if (other.dataSourceMinValue != null)
- return false;
- } else if
(!dataSourceMinValue.equals(other.dataSourceMinValue))
- return false;
- if (dataSourceHeartbeat == null) {
- if (other.dataSourceHeartbeat != null)
- return false;
- } else if
(!dataSourceHeartbeat.equals(other.dataSourceHeartbeat))
- return false;
- if (dataSourceStep == null) {
- if (other.dataSourceStep != null)
- return false;
- } else if (!dataSourceStep.equals(other.dataSourceStep))
- return false;
- if (dataSourceType == null) {
- if (other.dataSourceType != null)
- return false;
- } else if (!dataSourceType.equals(other.dataSourceType))
- return false;
- if (direction == null) {
- if (other.direction != null)
- return false;
- } else if (!direction.equals(other.direction))
- return false;
- if (eventType == null) {
- if (other.eventType != null)
- return false;
- } else if (!eventType.equals(other.eventType))
- return false;
- if (file == null) {
- if (other.file != null)
- return false;
- } else if (!file.equals(other.file))
- return false;
- if (hostName == null) {
- if (other.hostName != null)
- return false;
- } else if (!hostName.equals(other.hostName))
- return false;
- if (ifName == null) {
- if (other.ifName != null)
- return false;
- } else if (!ifName.equals(other.ifName))
- return false;
- if (ifAddress == null) {
- if (other.ifAddress != null)
- return false;
- } else if (!ifAddress.equals(other.ifAddress))
- return false;
- if (ifAddressType == null) {
- if (other.ifAddressType != null)
- return false;
- } else if (!ifAddressType.equals(other.ifAddressType))
- return false;
- if (ifDescription == null) {
- if (other.ifDescription != null)
- return false;
- } else if (!ifDescription.equals(other.ifDescription))
- return false;
- if (metadataId != other.metadataId) {
+
+ public void setValueUnits(String valueUnits)
+ {
+ this.valueUnits = valueUnits;
+ }
+
+
+ @Override
+ public int hashCode()
+ {
+ int result = metadataId;
+ result = PRIME * result + ((capacity == null) ? 0 :
capacity.hashCode());
+ result = PRIME * result + ((keyword == null) ? 0 :
keyword.hashCode());
+ result = PRIME * result + ((dataSource == null) ? 0 :
dataSource.hashCode());
+ result = PRIME * result + ((dataSourceMaxValue == null) ? 0 :
dataSourceMaxValue.hashCode());
+ result = PRIME * result + ((dataSourceMinValue == null) ? 0 :
dataSourceMinValue.hashCode());
+ result = PRIME * result + ((dataSourceHeartbeat == null) ? 0 :
dataSourceHeartbeat.hashCode());
+ result = PRIME * result + ((dataSourceStep == null) ? 0 :
dataSourceStep.hashCode());
+ result = PRIME * result + ((dataSourceType == null) ? 0 :
dataSourceType.hashCode());
+ result = PRIME * result + ((direction == null) ? 0 :
direction.hashCode());
+ result = PRIME * result + ((eventType == null) ? 0 :
eventType.hashCode());
+ result = PRIME * result + ((file == null) ? 0 : file.hashCode());
+ result = PRIME * result + ((hostName == null) ? 0 :
hostName.hashCode());
+ result = PRIME * result + ((ifName == null) ? 0 : ifName.hashCode());
+ result = PRIME * result + ((ifAddress == null) ? 0 :
ifAddress.hashCode());
+ result = PRIME * result + ((ifAddressType == null) ? 0 :
ifAddressType.hashCode());
+ result = PRIME * result + ((ifDescription == null) ? 0 :
ifDescription.hashCode());
+ result = PRIME * result + ((subjId == null) ? 0 : subjId.hashCode());
+ result = PRIME * result + ((valueUnits == null) ? 0 :
valueUnits.hashCode());
+ return result;
+ }
+
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
return false;
}
- if (subjId == null) {
- if (other.subjId != null)
- return false;
- } else if (!subjId.equals(other.subjId))
- return false;
- if (valueUnits == null) {
- if (other.valueUnits != null)
- return false;
- } else if (!valueUnits.equals(other.valueUnits))
- return false;
- return true;
- }
-
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ final Interfaces other = (Interfaces) obj;
+ if (capacity == null) {
+ if (other.capacity != null) {
+ return false;
+ }
+ } else if (!capacity.equals(other.capacity)) {
+ return false;
+ }
+ if (keyword == null) {
+ if (other.keyword != null) {
+ return false;
+ }
+ } else if (!keyword.equals(other.keyword)) {
+ return false;
+ }
+ if (dataSource == null) {
+ if (other.dataSource != null) {
+ return false;
+ }
+ } else if (!dataSource.equals(other.dataSource)) {
+ return false;
+ }
+ if (dataSourceMaxValue == null) {
+ if (other.dataSourceMaxValue != null) {
+ return false;
+ }
+ } else if (!dataSourceMaxValue.equals(other.dataSourceMaxValue)) {
+ return false;
+ }
+ if (dataSourceMinValue == null) {
+ if (other.dataSourceMinValue != null) {
+ return false;
+ }
+ } else if (!dataSourceMinValue.equals(other.dataSourceMinValue)) {
+ return false;
+ }
+ if (dataSourceHeartbeat == null) {
+ if (other.dataSourceHeartbeat != null) {
+ return false;
+ }
+ } else if (!dataSourceHeartbeat.equals(other.dataSourceHeartbeat)) {
+ return false;
+ }
+ if (dataSourceStep == null) {
+ if (other.dataSourceStep != null) {
+ return false;
+ }
+ } else if (!dataSourceStep.equals(other.dataSourceStep)) {
+ return false;
+ }
+ if (dataSourceType == null) {
+ if (other.dataSourceType != null) {
+ return false;
+ }
+ } else if (!dataSourceType.equals(other.dataSourceType)) {
+ return false;
+ }
+ if (direction == null) {
+ if (other.direction != null) {
+ return false;
+ }
+ } else if (!direction.equals(other.direction)) {
+ return false;
+ }
+ if (eventType == null) {
+ if (other.eventType != null) {
+ return false;
+ }
+ } else if (!eventType.equals(other.eventType)) {
+ return false;
+ }
+ if (file == null) {
+ if (other.file != null) {
+ return false;
+ }
+ } else if (!file.equals(other.file)) {
+ return false;
+ }
+ if (hostName == null) {
+ if (other.hostName != null) {
+ return false;
+ }
+ } else if (!hostName.equals(other.hostName)) {
+ return false;
+ }
+ if (ifName == null) {
+ if (other.ifName != null) {
+ return false;
+ }
+ } else if (!ifName.equals(other.ifName)) {
+ return false;
+ }
+ if (ifAddress == null) {
+ if (other.ifAddress != null) {
+ return false;
+ }
+ } else if (!ifAddress.equals(other.ifAddress)) {
+ return false;
+ }
+ if (ifAddressType == null) {
+ if (other.ifAddressType != null) {
+ return false;
+ }
+ } else if (!ifAddressType.equals(other.ifAddressType)) {
+ return false;
+ }
+ if (ifDescription == null) {
+ if (other.ifDescription != null) {
+ return false;
+ }
+ } else if (!ifDescription.equals(other.ifDescription)) {
+ return false;
+ }
+ if (metadataId != other.metadataId) {
+ return false;
+ }
+ if (subjId == null) {
+ if (other.subjId != null) {
+ return false;
+ }
+ } else if (!subjId.equals(other.subjId)) {
+ return false;
+ }
+ if (valueUnits == null) {
+ if (other.valueUnits != null) {
+ return false;
+ }
+ } else if (!valueUnits.equals(other.valueUnits)) {
+ return false;
+ }
+ return true;
+ }
+
}
Modified:
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/rrd/DiscardsResponseGenerator.java
===================================================================
---
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/rrd/DiscardsResponseGenerator.java
2012-10-22 15:38:39 UTC (rev 6031)
+++
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/rrd/DiscardsResponseGenerator.java
2012-11-19 07:56:19 UTC (rev 6032)
@@ -4,25 +4,20 @@
import org.perfsonar.base2.xml.Element;
import org.perfsonar.base2.xml.nmwg.Data;
-/**
- * $Id: DiscardsResponseGenerator.java 4684 2010-03-18 17:00:33Z pikusa $
- */
-public class DiscardsResponseGenerator implements ResponseGenerator {
-
-
- public Data getResponse(Rrd.FetchData fetchData,
- int dsNum,
- int rrdRows,
- String valueUnits)
- throws PerfSONARException {
-
+public class DiscardsResponseGenerator implements ResponseGenerator
+{
+ public Data getResponse(Rrd.FetchData fetchData, int dsNum, int rrdRows,
+ String valueUnits) throws PerfSONARException
+ {
Data data = new Data();
try {
for (int i = 0; i < rrdRows; i++) {
- if (i + 1 == rrdRows) break;
+ if (i + 1 == rrdRows) {
+ break;
+ }
Element datum = new Element();
datum.setName("datum");
@@ -32,24 +27,21 @@
datum.addAttribute("timeValue",
Long.toString(fetchData.getTimestamp(i + 1)));
datum.addAttribute("timeType", "unix");
datum.addAttribute("value",
Double.toString(fetchData.getValue(i, dsNum)));
- if (valueUnits != null) datum.addAttribute("valueUnits",
valueUnits);
+ if (valueUnits != null) {
+ datum.addAttribute("valueUnits", valueUnits);
+ }
data.addChild(datum);
}
} catch (Exception ex) {
- throw new PerfSONARException(
- "rrd_file_exception",
- ex.toString());
+ throw new PerfSONARException("rrd_file_exception",
ex.toString());
}
//DEBUG
//System.out.println(rows+" rows read");
return data;
-
}
-
-
-}
+}
Modified:
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/rrd/ErrorsResponseGenerator.java
===================================================================
---
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/rrd/ErrorsResponseGenerator.java
2012-10-22 15:38:39 UTC (rev 6031)
+++
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/rrd/ErrorsResponseGenerator.java
2012-11-19 07:56:19 UTC (rev 6032)
@@ -4,17 +4,13 @@
import org.perfsonar.base2.xml.Element;
import org.perfsonar.base2.xml.nmwg.Data;
-/**
- * $Id: ErrorsResponseGenerator.java 4684 2010-03-18 17:01:33Z pikusa $
- */
-public class ErrorsResponseGenerator implements ResponseGenerator {
+public class ErrorsResponseGenerator implements ResponseGenerator
+{
- public Data getResponse(Rrd.FetchData fetchData,
- int dsNum,
- int rrdRows,
- String valueUnits)
- throws PerfSONARException {
+ public Data getResponse(Rrd.FetchData fetchData, int dsNum, int rrdRows,
+ String valueUnits) throws PerfSONARException
+ {
Data data = new Data();
@@ -22,7 +18,9 @@
for (int i = 0; i < rrdRows; i++) {
- if (i + 1 == rrdRows) break;
+ if (i + 1 == rrdRows) {
+ break;
+ }
Element datum = new Element();
datum.setName("datum");
@@ -32,16 +30,16 @@
datum.addAttribute("timeValue",
Long.toString(fetchData.getTimestamp(i + 1)));
datum.addAttribute("timeType", "unix");
datum.addAttribute("value",
Double.toString(fetchData.getValue(i, dsNum)));
- if (valueUnits != null) datum.addAttribute("valueUnits",
valueUnits);
+ if (valueUnits != null) {
+ datum.addAttribute("valueUnits", valueUnits);
+ }
data.addChild(datum);
}
} catch (Exception ex) {
- throw new PerfSONARException(
- "rrd_file_exception",
- ex.toString());
+ throw new PerfSONARException("rrd_file_exception",
ex.toString());
}
//DEBUG
@@ -52,4 +50,4 @@
}
-}
+}
Modified:
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/rrd/GenericResponseGenerator.java
===================================================================
---
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/rrd/GenericResponseGenerator.java
2012-10-22 15:38:39 UTC (rev 6031)
+++
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/rrd/GenericResponseGenerator.java
2012-11-19 07:56:19 UTC (rev 6032)
@@ -4,17 +4,13 @@
import org.perfsonar.base2.xml.Element;
import org.perfsonar.base2.xml.nmwg.Data;
-/**
- * $Id: GenericResponseGenerator.java 4684 2008-11-03 13:07:33Z roman $
- */
-public class GenericResponseGenerator implements ResponseGenerator {
+public class GenericResponseGenerator implements ResponseGenerator
+{
- public Data getResponse(Rrd.FetchData fetchData,
- int dsNum,
- int rrdRows,
- String valueUnits)
- throws PerfSONARException {
+ public Data getResponse(Rrd.FetchData fetchData, int dsNum, int rrdRows,
+ String valueUnits) throws PerfSONARException
+ {
Data data = new Data();
@@ -22,7 +18,9 @@
for (int i = 0; i < rrdRows; i++) {
- if (i + 1 == rrdRows) break;
+ if (i + 1 == rrdRows) {
+ break;
+ }
Element datum = new Element();
datum.setName("datum");
@@ -38,9 +36,7 @@
}
} catch (Exception ex) {
- throw new PerfSONARException(
- "rrd_file_exception",
- ex.toString());
+ throw new PerfSONARException("rrd_file_exception",
ex.toString());
}
//DEBUG
@@ -51,4 +47,4 @@
}
-} //GenericResponseGenerator
\ No newline at end of file
+} //GenericResponseGenerator
Modified:
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/rrd/RRDDataStorageDAOImpl.java
===================================================================
---
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/rrd/RRDDataStorageDAOImpl.java
2012-10-22 15:38:39 UTC (rev 6031)
+++
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/rrd/RRDDataStorageDAOImpl.java
2012-11-19 07:56:19 UTC (rev 6032)
@@ -14,10 +14,8 @@
import static
org.perfsonar.service.measurementArchive.rrdType.storage.rrd.Rrd.FetchData;
-/**
- * $Id: RRDDataStorageDAOImpl.java 4684 2008-11-03 13:07:33Z roman $
- */
-public class RRDDataStorageDAOImpl extends Component implements
DataStorageDAO {
+public class RRDDataStorageDAOImpl extends Component implements
DataStorageDAO
+{
// -------------------------------------------------------------
@@ -25,39 +23,40 @@
public static final String CONSOLIDATION_AVERAGE = "AVERAGE";
- public static final String CONSOLIDATION_MIN = "MIN";
+ public static final String CONSOLIDATION_MIN = "MIN";
- public static final String CONSOLIDATION_MAX = "MAX";
+ public static final String CONSOLIDATION_MAX = "MAX";
- public static final String CONSOLIDATION_LAST = "LAST";
+ public static final String CONSOLIDATION_LAST = "LAST";
/**
- * Default value for the consolidation.
+ * Default value for the consolidation.
*
- * @see Consolidation
+ * @see Consolidation
*/
public static final String DEFAULT_CONSOLIDATION = CONSOLIDATION_AVERAGE;
/**
- * Default value for the resolution.
+ * Default value for the resolution.
*/
public static final int DEFAULT_RESOLUTION = 300;
/**
- * Default value for start time parameter.
- * Negative numbers are relative to the current time.
+ * Default value for start time parameter.
+ * Negative numbers are relative to the current time.
*/
public static final long DEFAULT_START = -86400;
/**
- * Default value for end time parameter.
+ * Default value for end time parameter.
*/
public static final long DEFAULT_END = -1;
// -------------------------------------------------------------
constructor
- public RRDDataStorageDAOImpl() throws PerfSONARException {
+ public RRDDataStorageDAOImpl() throws PerfSONARException
+ {
super();
}
@@ -65,168 +64,215 @@
// ------------------------------------------------------------- methods
- public void run() throws PerfSONARException {
+ public void run() throws PerfSONARException
+ {
}
- public void init() throws PerfSONARException {
+ public void init() throws PerfSONARException
+ {
}
- public void destroy() throws PerfSONARException {
+ public void destroy() throws PerfSONARException
+ {
}
- public Data fetch(Element request) throws PerfSONARException {
- return rrdFetch((Message)request);
+ public Data fetch(Element request) throws PerfSONARException
+ {
+ return rrdFetch((Message) request);
}
- public void store(Element request) throws PerfSONARException {
- throw new PerfSONARException(
- "storing_not_supported",
- "Can not store data.");
+ public void store(Element request) throws PerfSONARException
+ {
+ throw new PerfSONARException("storing_not_supported", "Can not store
data.");
}
- protected Data rrdFetch(Message request) throws PerfSONARException {
-
+ protected Data rrdFetch(Message request) throws PerfSONARException
+ {
Data rrdData = null;
Metadata metadata =
request.getMetadataCollection().iterator().next();
Key key = metadata.getKey();
- if (key == null)
- throw new PerfSONARException (
- "query_exception",
- "There is no key.");
+ if (key == null) {
+ throw new PerfSONARException("query_exception", "There is no
key.");
+ }
- if (key.getParametersMap().size() == 0)
- throw new PerfSONARException (
- "query_exception",
- "Key element does not contain parameters elements.");
+ if (key.getParametersMap().isEmpty()) {
+ throw new PerfSONARException("query_exception", "Key element
does not contain parameters elements.");
+ }
// -------------- select parameter elements
- Parameters selectParameters =
key.getParameters("http://ggf.org/ns/nmwg/ops/select/2.0/");
+ Parameters selectParameters =
key.getParameters("http://ggf.org/ns/nmwg/ops/select/2.0/");
Parameter startTimeParameter = null;
- Parameter endTimeParameter = null;
- String startTime = null;
- String endTime = null;
+ Parameter endTimeParameter = null;
+ String startTimeValue = null;
+ String endTimeValue = null;
- try { startTimeParameter =
selectParameters.getFirstParameter("startTime"); } catch (Exception ex) {}
- try { endTimeParameter =
selectParameters.getFirstParameter("endTime"); } catch (Exception ex) {}
- startTime = TimeDateUtil.getUnixTime(startTimeParameter);
- endTime = TimeDateUtil.getUnixTime(endTimeParameter);
- String consolidationFunction = null;
- String resolution = null;
+ try {
+ startTimeParameter =
selectParameters.getFirstParameter("startTime");
+ } catch (Exception ex) {
+ }
+ try {
+ endTimeParameter = selectParameters.getFirstParameter("endTime");
+ } catch (Exception ex) {
+ }
+ startTimeValue = TimeDateUtil.getUnixTime(startTimeParameter);
+ endTimeValue = TimeDateUtil.getUnixTime(endTimeParameter);
+ String consolidationFunctionValue = null;
+ String resolutionValue = null;
- try { consolidationFunction =
selectParameters.getFirstParameterValue("consolidationFunction"); } catch
(Exception ex) {}
- try { resolution =
selectParameters.getFirstParameterValue("resolution"); } catch (Exception ex)
{}
+ try {
+ consolidationFunctionValue =
selectParameters.getFirstParameterValue("consolidationFunction");
+ } catch (Exception ex) {
+ }
+ try {
+ resolutionValue =
selectParameters.getFirstParameterValue("resolution");
+ } catch (Exception ex) {
+ }
// -------------- nmwg parameter elements
- Parameters nmwgParameters =
key.getParameters("http://ggf.org/ns/nmwg/base/2.0/");
+ Parameters nmwgParameters =
key.getParameters("http://ggf.org/ns/nmwg/base/2.0/");
- String file = null;
- String dataSource = null;
- String valueUnits = null;
- String eventType = null;
- String dataSourceStep = null;
- String dataSourceType = null;
+ String file = null;
+ String dataSource = null;
+ String valueUnits = null;
+ String eventType = null;
+ String dataSourceStep = null;
+ String dataSourceType = null;
String dataSourceHeartbeat = null;
- String dataSourceMinValue = null;
- String dataSourceMaxValue = null;
+ String dataSourceMinValue = null;
+ String dataSourceMaxValue = null;
- try { file = nmwgParameters.getFirstParameterValue("file"); }
catch (Exception ex) {}
- try { dataSource =
nmwgParameters.getFirstParameterValue("dataSource"); } catch (Exception ex) {}
- try { valueUnits =
nmwgParameters.getFirstParameterValue("valueUnits"); } catch (Exception ex) {}
- try { eventType =
nmwgParameters.getFirstParameterValue("eventType"); } catch (Exception ex) {}
- if (eventType.trim().equals("")) eventType = null;
+ try {
+ file = nmwgParameters.getFirstParameterValue("file");
+ } catch (Exception ex) {
+ }
+ try {
+ dataSource = nmwgParameters.getFirstParameterValue("dataSource");
+ } catch (Exception ex) {
+ }
+ try {
+ valueUnits = nmwgParameters.getFirstParameterValue("valueUnits");
+ } catch (Exception ex) {
+ }
+ try {
+ eventType = nmwgParameters.getFirstParameterValue("eventType");
+ } catch (Exception ex) {
+ }
+ if (eventType.trim().isEmpty()) {
+ eventType = null;
+ }
- try { dataSourceStep =
nmwgParameters.getFirstParameterValue("dataSourceStep"); } catch (Exception
ex) {}
- try { dataSourceType =
nmwgParameters.getFirstParameterValue("dataSourceType"); } catch (Exception
ex) {}
- try { dataSourceHeartbeat =
nmwgParameters.getFirstParameterValue("dataSourceHeartbeat"); } catch
(Exception ex) {}
- try { dataSourceMinValue =
nmwgParameters.getFirstParameterValue("dataSourceMinValue"); } catch
(Exception ex) {}
- try { dataSourceMaxValue =
nmwgParameters.getFirstParameterValue("dataSourceMaxValue"); } catch
(Exception ex) {}
+ try {
+ dataSourceStep =
nmwgParameters.getFirstParameterValue("dataSourceStep");
+ } catch (Exception ex) {
+ }
+ try {
+ dataSourceType =
nmwgParameters.getFirstParameterValue("dataSourceType");
+ } catch (Exception ex) {
+ }
+ try {
+ dataSourceHeartbeat =
nmwgParameters.getFirstParameterValue("dataSourceHeartbeat");
+ } catch (Exception ex) {
+ }
+ try {
+ dataSourceMinValue =
nmwgParameters.getFirstParameterValue("dataSourceMinValue");
+ } catch (Exception ex) {
+ }
+ try {
+ dataSourceMaxValue =
nmwgParameters.getFirstParameterValue("dataSourceMaxValue");
+ } catch (Exception ex) {
+ }
- long _startTime = DEFAULT_START;
- long _endTime = DEFAULT_END;
- String _consolidationFunction = DEFAULT_CONSOLIDATION;
- int _resolution = DEFAULT_RESOLUTION;
+ long startTime = DEFAULT_START;
+ long endTime = DEFAULT_END;
+ String consolidationFunction = DEFAULT_CONSOLIDATION;
+ int resolution = DEFAULT_RESOLUTION;
- try { _startTime = Long.parseLong(startTime); } catch (Exception ex)
{
+ try {
+ startTime = Long.parseLong(startTimeValue);
+ } catch (Exception ex) {
}
- try { _endTime = Long.parseLong(endTime); } catch (Exception ex) {
+ try {
+ endTime = Long.parseLong(endTimeValue);
+ } catch (Exception ex) {
}
- try { _resolution = Integer.parseInt(resolution); } catch
(Exception ex) {
+ try {
+ resolution = Integer.parseInt(resolutionValue);
+ } catch (Exception ex) {
}
try {
- if ( consolidationFunction.equals(CONSOLIDATION_AVERAGE) ||
- consolidationFunction.equals(CONSOLIDATION_MIN) ||
- consolidationFunction.equals(CONSOLIDATION_MAX) ||
- consolidationFunction.equals(CONSOLIDATION_LAST) )
+ if (consolidationFunctionValue.equals(CONSOLIDATION_AVERAGE)
+ || consolidationFunctionValue.equals(CONSOLIDATION_MIN)
+ || consolidationFunctionValue.equals(CONSOLIDATION_MAX)
+ || consolidationFunctionValue.equals(CONSOLIDATION_LAST))
+ {
+ consolidationFunction = consolidationFunctionValue;
+ }
- _consolidationFunction = consolidationFunction;
-
} catch (Exception ex) {
}
try {
- FetchData fdata = Rrd.fetch(
- file,
- _consolidationFunction,
- _startTime,
- _endTime,
- _resolution);
+ FetchData fdata = Rrd.fetch(file, consolidationFunction,
startTime, endTime, resolution);
rrdData = getRRDColumn(fdata, dataSource, valueUnits, eventType);
Parameters parameters = new Parameters();
- if (dataSourceStep != null)
- if (!dataSourceStep.trim().equals(""))
+ if (dataSourceStep != null) {
+ if (!dataSourceStep.trim().isEmpty()) {
parameters.addChild(nmwgParameters.getFirstParameter("dataSourceStep"));
+ }
+ }
- if (dataSourceType != null)
- if (!dataSourceType.trim().equals(""))
+ if (dataSourceType != null) {
+ if (!dataSourceType.trim().isEmpty()) {
parameters.addChild(nmwgParameters.getFirstParameter("dataSourceType"));
+ }
+ }
- if (dataSourceHeartbeat != null)
- if (!dataSourceHeartbeat.trim().equals(""))
+ if (dataSourceHeartbeat != null) {
+ if (!dataSourceHeartbeat.trim().isEmpty()) {
parameters.addChild(nmwgParameters.getFirstParameter("dataSourceHeartbeat"));
+ }
+ }
- if (dataSourceMinValue != null)
- if (!dataSourceMinValue.trim().equals(""))
+ if (dataSourceMinValue != null) {
+ if (!dataSourceMinValue.trim().isEmpty()) {
parameters.addChild(nmwgParameters.getFirstParameter("dataSourceMinValue"));
+ }
+ }
- if (dataSourceMaxValue != null)
- if (!dataSourceMaxValue.trim().equals(""))
+ if (dataSourceMaxValue != null) {
+ if (!dataSourceMaxValue.trim().isEmpty()) {
parameters.addChild(nmwgParameters.getFirstParameter("dataSourceMaxValue"));
+ }
+ }
rrdData.addChild(parameters);
-
} catch (RrdException e) {
logger.error("Cannot retrieve data from RRD: {}",
e.getMessage());
- throw new PerfSONARException("rrd_exception",
- "Cannot retrieve data from RRD: " + e.getMessage(), e);
+ throw new PerfSONARException("rrd_exception", "Cannot retrieve
data from RRD: " + e.getMessage(), e);
} catch (UnsatisfiedLinkError e) {
logger.error("Cannot retrieve data from RRD: {}",
e.getMessage());
- throw new PerfSONARException("rrd_exception",
- "Cannot retrieve data from RRD: " + e.getMessage(), e);
-
+ throw new PerfSONARException("rrd_exception", "Cannot retrieve
data from RRD: " + e.getMessage(), e);
}
return rrdData;
-
}
- private Data getRRDColumn(FetchData fetchData,
- String dataSource,
- String valueUnits,
- String eventType)
- throws PerfSONARException {
+ private Data getRRDColumn(FetchData fetchData, String dataSource, String
valueUnits,
+ String eventType) throws PerfSONARException
+ {
int rows = fetchData.getRowCount();
int cols = fetchData.getColCount();
@@ -234,7 +280,9 @@
//which data source? (-1 = unknown)
int ds = -1;
for (int i = 0; (i < cols) && (ds == -1); i++) {
- if (fetchData.getColName(i).equalsIgnoreCase(dataSource)) ds = i;
+ if (fetchData.getColName(i).equalsIgnoreCase(dataSource)) {
+ ds = i;
+ }
}
//DEBUG
@@ -258,30 +306,25 @@
} else {
- throw new PerfSONARException(
- "rrd_file_exception",
- "No " + dataSource + " column/data source in RRD file");
+ throw new PerfSONARException("rrd_file_exception", "No " +
dataSource + " column/data source in RRD file");
}
}
- protected ResponseGenerator getResponseGenerator(String eventType)
- throws PerfSONARException {
+ protected ResponseGenerator getResponseGenerator(String eventType)
throws PerfSONARException
+ {
String responseGeneratorClassName = getOption("eventType::" +
eventType).getValue();
ResponseGenerator responseGenerator = null;
try {
- responseGenerator =
- (ResponseGenerator)
Class.forName(responseGeneratorClassName).newInstance();
+ responseGenerator = (ResponseGenerator)
Class.forName(responseGeneratorClassName).newInstance();
} catch (Exception ex) {
logger.warn("can not create an object of " + className +
"class");
- throw new PerfSONARException(
- "object_creation_exception",
- "can not create an object of "
- + className + "class");
+ throw new PerfSONARException("object_creation_exception",
+ "can not create an object of " +
className + "class");
}
return responseGenerator;
Modified:
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/rrd/ResponseGenerator.java
===================================================================
---
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/rrd/ResponseGenerator.java
2012-10-22 15:38:39 UTC (rev 6031)
+++
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/rrd/ResponseGenerator.java
2012-11-19 07:56:19 UTC (rev 6032)
@@ -3,17 +3,8 @@
import org.perfsonar.base2.service.exceptions.PerfSONARException;
import org.perfsonar.base2.xml.nmwg.Data;
-/**
- * $Id: ResponseGenerator.java 4684 2008-11-03 13:07:33Z roman $
- */
-public interface ResponseGenerator {
-
-
- public Data getResponse(Rrd.FetchData fetchData,
- int dsNum,
- int rrdRows,
- String valueUnits)
- throws PerfSONARException;
-
-
-} //ResponseGenerator
\ No newline at end of file
+public interface ResponseGenerator
+{
+ Data getResponse(Rrd.FetchData fetchData, int dsNum, int rrdRows,
+ String valueUnits) throws PerfSONARException;
+} //ResponseGenerator
Modified:
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/rrd/Rrd.java
===================================================================
---
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/rrd/Rrd.java
2012-10-22 15:38:39 UTC (rev 6031)
+++
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/rrd/Rrd.java
2012-11-19 07:56:19 UTC (rev 6032)
@@ -6,64 +6,55 @@
/**
* Rrd wrapper around librrd.
- *
+ * <p/>
* In contrast RrdLibrary, this class provides a more Java like API.
*/
-public class Rrd
+public final class Rrd
{
- public static final String FETCH = "fetch";
- public static final String START = "--start";
- public static final String END = "--end";
+ public static final String FETCH = "fetch";
+ public static final String START = "--start";
+ public static final String END = "--end";
public static final String RESOLUTION = "--resolution";
- private Rrd() {
+ private Rrd()
+ {
}
- public static FetchData fetch(
- String filename,
- String consolidationFunction,
- long start,
- long end,
- int resolution) throws RrdException
+ public static FetchData fetch(String filename, String
consolidationFunction, long start, long end,
+ int resolution) throws RrdException
{
- return fetch(FETCH, filename, consolidationFunction,
- START, String.valueOf(start), END, String.valueOf(end),
- RESOLUTION, String.valueOf(resolution));
+ return fetch(FETCH, filename, consolidationFunction, START,
String.valueOf(start), END, String.valueOf(end),
+ RESOLUTION, String.valueOf(resolution));
}
- public static synchronized FetchData fetch(String... args)
- throws RrdException
+ public static synchronized FetchData fetch(String... args) throws
RrdException
{
RrdLibrary rrd = RrdLibrary.INSTANCE;
RrdLibrary.time_t start = new RrdLibrary.time_t();
RrdLibrary.time_t end = new RrdLibrary.time_t();
NativeLongByReference step = new NativeLongByReference();
- NativeLongByReference ds_cnt = new NativeLongByReference();
- PointerByReference ds_namv = new PointerByReference();
+ NativeLongByReference dsCnt = new NativeLongByReference();
+ PointerByReference dsNamv = new PointerByReference();
PointerByReference data = new PointerByReference();
- int err = rrd.rrd_fetch(args.length, args,
- start, end, step, ds_cnt,
- ds_namv, data);
+ int err = rrd.rrd_fetch(args.length, args, start, end, step, dsCnt,
dsNamv, data);
if (err != 0) {
throw new RrdException(err, rrd.rrd_get_error());
}
- int columns = ds_cnt.getValue().intValue();
+ int columns = dsCnt.getValue().intValue();
int rows = (int) ((end.value - start.value) /
step.getValue().longValue() + 1);
try {
- return new FetchData(
- start.value, end.value,
- step.getValue().longValue(),
- ds_namv.getValue().getStringArray(0, columns),
- data.getValue().getDoubleArray(0, columns * rows));
+ return new FetchData(start.value, end.value,
step.getValue().longValue(),
+ dsNamv.getValue().getStringArray(0,
columns),
+ data.getValue().getDoubleArray(0, columns *
rows));
} finally {
- for (Pointer p: ds_namv.getValue().getPointerArray(0, columns)) {
+ for (Pointer p : dsNamv.getValue().getPointerArray(0, columns)) {
rrd.rrd_freemem(p);
}
- rrd.rrd_freemem(ds_namv.getValue());
+ rrd.rrd_freemem(dsNamv.getValue());
rrd.rrd_freemem(data.getValue());
}
}
@@ -85,11 +76,12 @@
*
* To read this data use the following methods:<p>
* <ul>
- *
<li>{@link
#getRowCount() <b>getRowCount()</b>} to find the number of rows
- *
<li>{@link
#getColCount() <b>getColCount()</b>} to find the number of <u>data</u>
columns
- *
<li>{@link
#getColName(int) <b>getColName()</b>} to find the name of the i-th
<u>data</u> column (zero based)
- *
<li>{@link
#getTimestamp(int) <b>getTimestamp(i)</b>} to find the timestamp of the i-th
row (zero based)
- *
<li>{@link
#getValue(int,int) <b>getValue(i, j)</b>} to find the value of the j-th
<u>data</u> column on the i-th row
+ *
<li>{@link
#getRowCount() <b>getRowCount()</b>} to find the number of rows
+ *
<li>{@link
#getColCount() <b>getColCount()</b>} to find the number of <em>data</em>
columns
+ *
<li>{@link
#getColName(int) <b>getColName()</b>} to find the name of the i-th
<em>data</em> column (zero based)
+ *
<li>{@link
#getTimestamp(int) <b>getTimestamp(i)</b>} to find the timestamp of the i-th
row (zero based)
+ *
<li>{@link
#getValue(int, int) <b>getValue(i, j)</b>} to find the value of the j-th
<em>data</em> column on the
+ * i-th row
* </ul> <p>
*
* Example:<p>
@@ -106,9 +98,9 @@
* }
* </pre>
*
- * @author Sasa Markovic<br><a
href="mailto:"></a><p>
+ * @author Sasa Markovic<br><a
href="mailto:"></a>
*/
- public static class FetchData
+ public static final class FetchData
{
private final String[] dsNames;
private final long tStart, tEnd, step;
@@ -117,24 +109,25 @@
private final int rowCount;
private final int colCount;
- private FetchData(long tStart, long tEnd, long step,
- String[] dsNames, double[] values)
+ private FetchData(long tStart, long tEnd, long step, String[]
dsNames, double[] values)
{
this.dsNames = dsNames;
this.tStart = tStart;
this.tEnd = tEnd;
this.step = step;
this.values = values;
- rowCount = (int)((tEnd - tStart) / step + 1);
+ rowCount = (int) ((tEnd - tStart) / step + 1);
colCount = dsNames.length;
}
/**
* Returns timestamp of the given row.
+ *
* @param row Zero-based row number
* @return timestamp of the given row
*/
- public long getTimestamp(int row) {
+ public long getTimestamp(int row)
+ {
return tStart + row * step;
}
@@ -145,32 +138,39 @@
* @param col Zero based data column number.
* @return value from the RRD database for the given row and column.
*/
- public double getValue(int row, int col) {
+ public double getValue(int row, int col)
+ {
return values[row * colCount + col];
}
/**
- * Returns column (data source) name for the given column number
+ * Returns column (data source) name for the given column number.
+ *
* @param col Zero-based column number.
* @return Column (data source) name
*/
- public String getColName(int col) {
+ public String getColName(int col)
+ {
return dsNames[col];
}
/**
* Returns number of columns (data sources) generated by
{@link
Rrd#fetch(String) <b>Rrd.fetch()</b>} method.
+ *
* @return Number of columns
*/
- public int getColCount() {
+ public int getColCount()
+ {
return colCount;
}
/**
* Returns number of rows generated by
{@link
Rrd#fetch(String) <b>Rrd.fetch()</b>} method.
+ *
* @return Number of rows
*/
- public int getRowCount() {
+ public int getRowCount()
+ {
return rowCount;
}
}
Modified:
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/rrd/RrdException.java
===================================================================
---
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/rrd/RrdException.java
2012-10-22 15:38:39 UTC (rev 6031)
+++
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/rrd/RrdException.java
2012-11-19 07:56:19 UTC (rev 6032)
@@ -1,23 +1,26 @@
package org.perfsonar.service.measurementArchive.rrdType.storage.rrd;
/**
- * Exception thrown when an RRD call fails.
+ * Exception thrown when an RRD call fails.
*/
public class RrdException extends Exception
{
private final int err;
- public RrdException(int err, String message) {
+ public RrdException(int err, String message)
+ {
super(message);
this.err = err;
}
- public RrdException(int err, String message, Throwable cause) {
+ public RrdException(int err, String message, Throwable cause)
+ {
super(message, cause);
this.err = err;
}
- public int getErrorCode() {
+ public int getErrorCode()
+ {
return err;
}
}
Modified:
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/rrd/RrdLibrary.java
===================================================================
---
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/rrd/RrdLibrary.java
2012-10-22 15:38:39 UTC (rev 6031)
+++
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/rrd/RrdLibrary.java
2012-11-19 07:56:19 UTC (rev 6032)
@@ -13,27 +13,33 @@
*/
public interface RrdLibrary extends Library
{
+ // CHECKSTYLE_OFF: ALL
public static final String JNA_LIBRARY_NAME = "rrd";
public static final NativeLibrary JNA_NATIVE_LIB =
NativeLibrary.getInstance(RrdLibrary.JNA_LIBRARY_NAME);
- public static final RrdLibrary INSTANCE =
(RrdLibrary)Native.loadLibrary(RrdLibrary.JNA_LIBRARY_NAME, RrdLibrary.class);
+ public static final RrdLibrary INSTANCE = (RrdLibrary)
Native.loadLibrary(RrdLibrary.JNA_LIBRARY_NAME,
+
RrdLibrary.class);
- int rrd_fetch(int argc, String[] argv,
- RrdLibrary.time_t start, RrdLibrary.time_t end,
- NativeLongByReference step, NativeLongByReference ds_cnt,
- PointerByReference ds_namv,
+ int rrd_fetch(int argc, String[] argv, RrdLibrary.time_t start,
RrdLibrary.time_t end,
+ NativeLongByReference step, NativeLongByReference ds_cnt,
PointerByReference ds_namv,
PointerByReference data);
String rrd_get_error();
- void rrd_freemem(Pointer mem);
+ void rrd_freemem(Pointer mem);
- public static class time_t extends Structure {
+ public static class time_t extends Structure
+ {
public int value;
- public time_t() {}
+ public time_t()
+ {
+ }
- public time_t(int value) {
+ public time_t(int value)
+ {
this.value = value;
}
}
+
+ // CHECKSTYLE_ON: ALL
}
Modified:
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/rrd/TimeDateUtil.java
===================================================================
---
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/rrd/TimeDateUtil.java
2012-10-22 15:38:39 UTC (rev 6031)
+++
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/rrd/TimeDateUtil.java
2012-11-19 07:56:19 UTC (rev 6032)
@@ -9,50 +9,56 @@
import org.perfsonar.base2.service.exceptions.PerfSONARException;
+import java.util.concurrent.TimeUnit;
-public class TimeDateUtil {
+public final class TimeDateUtil
+{
+ private TimeDateUtil()
+ {
+ }
/**
- * Returns unix time value.
- *
- * ISO format:
- *
- * datetime = time | date-opt-time
- * time = 'T' time-element [offset]
- * date-opt-time = date-element ['T' [time-element] [offset]]
- * date-element = std-date-element | ord-date-element |
week-date-element
- * std-date-element = yyyy ['-' MM ['-' dd]]
- * ord-date-element = yyyy ['-' DDD]
- * week-date-element = xxxx '-W' ww ['-' e]
- * time-element = HH [minute-element] | [fraction]
- * minute-element = ':' mm [second-element] | [fraction]
- * second-element = ':' ss [fraction]
- * fraction = ('.' | ',') digit+
- * offset = 'Z' | (('+' | '-') HH [':' mm [':' ss [('.' |
',') SSS]]])
- *
- *
+ * Returns unix time value.
+ * <p/>
+ * ISO format:
+ * <p/>
+ * datetime = time | date-opt-time
+ * time = 'T' time-element [offset]
+ * date-opt-time = date-element ['T' [time-element] [offset]]
+ * date-element = std-date-element | ord-date-element |
week-date-element
+ * std-date-element = yyyy ['-' MM ['-' dd]]
+ * ord-date-element = yyyy ['-' DDD]
+ * week-date-element = xxxx '-W' ww ['-' e]
+ * time-element = HH [minute-element] | [fraction]
+ * minute-element = ':' mm [second-element] | [fraction]
+ * second-element = ':' ss [fraction]
+ * fraction = ('.' | ',') digit+
+ * offset = 'Z' | (('+' | '-') HH [':' mm [':' ss [('.' |
',') SSS]]])
*/
- public static String getUnixTime(Parameter timeParemeter)
- throws PerfSONARException {
+ public static String getUnixTime(Parameter timeParemeter) throws
PerfSONARException
+ {
- if (timeParemeter == null)
+ if (timeParemeter == null) {
return null;
+ }
- String unixTime = _getUnixTime(timeParemeter);
- if (unixTime == null)
+ String unixTime = internalGetUnixTime(timeParemeter);
+ if (unixTime == null) {
unixTime = timeParemeter.getText();
+ }
return unixTime;
}
+ private static String internalGetUnixTime(Parameter timeParemeter)
throws PerfSONARException
+ {
- protected static String _getUnixTime(Parameter timeParemeter)
- throws PerfSONARException {
-
Element time = timeParemeter.getFirstChild("time");
- if (time == null) return null;
+ if (time == null) {
+ return null;
+ }
String unixTimeString = "";
@@ -63,27 +69,25 @@
} else if (time.getAttribute("type").trim().equalsIgnoreCase("iso"))
{
String isoTimeString = time.getText();
- if (isoTimeString.trim().equals(""))
+ if (isoTimeString.trim().isEmpty()) {
isoTimeString = time.getAttribute("value");
+ }
try {
DateTimeFormatter dtf = ISODateTimeFormat.dateTimeParser();
DateTime dt = dtf.parseDateTime(isoTimeString);
- unixTimeString = Long.toString(dt.getMillis()/1000);
+ unixTimeString =
Long.toString(TimeUnit.MILLISECONDS.toSeconds(dt.getMillis()));
} catch (Exception ex) {
- throw new PerfSONARException(
- "time_parameter_exception",
- "ISO time coversion is wrong; "
- + ex.toString());
+ throw new PerfSONARException("time_parameter_exception",
+ "ISO time coversion is wrong; "
+ ex.toString());
}
} else {
- throw new PerfSONARException(
- "time_parameter_exception",
- "Time type " + time.getAttribute("type") + "is not
supported");
+ throw new PerfSONARException("time_parameter_exception",
+ "Time type " +
time.getAttribute("type") + "is not supported");
}
Modified:
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/rrd/UtilizationResponseGenerator.java
===================================================================
---
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/rrd/UtilizationResponseGenerator.java
2012-10-22 15:38:39 UTC (rev 6031)
+++
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/rrd/UtilizationResponseGenerator.java
2012-11-19 07:56:19 UTC (rev 6032)
@@ -4,25 +4,20 @@
import org.perfsonar.base2.xml.Element;
import org.perfsonar.base2.xml.nmwg.Data;
-/**
- * $Id: UtilizationResponseGenerator.java 4684 2008-11-03 13:07:33Z roman $
- */
-public class UtilizationResponseGenerator implements ResponseGenerator {
-
-
- public Data getResponse(Rrd.FetchData fetchData,
- int dsNum,
- int rrdRows,
- String valueUnits)
- throws PerfSONARException {
-
+public class UtilizationResponseGenerator implements ResponseGenerator
+{
+ public Data getResponse(Rrd.FetchData fetchData, int dsNum, int rrdRows,
+ String valueUnits) throws PerfSONARException
+ {
Data data = new Data();
try {
for (int i = 0; i < rrdRows; i++) {
- if (i + 1 == rrdRows) break;
+ if (i + 1 == rrdRows) {
+ break;
+ }
Element datum = new Element();
datum.setName("datum");
@@ -32,16 +27,16 @@
datum.addAttribute("timeValue",
Long.toString(fetchData.getTimestamp(i + 1)));
datum.addAttribute("timeType", "unix");
datum.addAttribute("value",
Double.toString(fetchData.getValue(i, dsNum)));
- if (valueUnits != null) datum.addAttribute("valueUnits",
valueUnits);
+ if (valueUnits != null) {
+ datum.addAttribute("valueUnits", valueUnits);
+ }
data.addChild(datum);
}
} catch (Exception ex) {
- throw new PerfSONARException(
- "rrd_file_exception",
- ex.toString());
+ throw new PerfSONARException("rrd_file_exception",
ex.toString());
}
//DEBUG
@@ -52,4 +47,4 @@
}
-} //UtilizationResponseGenerator
\ No newline at end of file
+} //UtilizationResponseGenerator
Modified:
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/sql/MysqlMetadataStorageDAOImpl.java
===================================================================
---
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/sql/MysqlMetadataStorageDAOImpl.java
2012-10-22 15:38:39 UTC (rev 6031)
+++
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/sql/MysqlMetadataStorageDAOImpl.java
2012-11-19 07:56:19 UTC (rev 6032)
@@ -28,165 +28,166 @@
{
public static final String PERSISTENCE_UNIT_NAME =
"org.perfsonar.service.measurementArchive.rrdType.storage.sql";
protected EntityManager em;
- protected final QueryGenerator qg = new QueryGenerator();
+ protected final QueryGenerator qg = new QueryGenerator();
private EntityManagerFactory entityManagerFactory;
@Override
- public void destroy() throws PerfSONARException
+ public void destroy() throws PerfSONARException
{
- em.close();
+ em.close();
entityManagerFactory.close();
- }
+ }
- @Override
- public void init() throws PerfSONARException
+ @Override
+ public void init() throws PerfSONARException
{
- Component configuration =
ConfigurationManager.getInstance().getConfiguration().getAuxiliaryComponent(MetadataStorageDAOFactory.METADATA_STORAGE_DAO_NAME);
- String DB_URI = configuration.getOption("uri").getValue();
- String SCHEMA = configuration.getOption("schema").getValue();
- String USERNAME = configuration.getOption("username").getValue();
- String PASSWORD = configuration.getOption("password").getValue();
-
- if (!DB_URI.endsWith("/")) {
- DB_URI = DB_URI + "/";
+ Component configuration =
ConfigurationManager.getInstance().getConfiguration().getAuxiliaryComponent(
+ MetadataStorageDAOFactory.METADATA_STORAGE_DAO_NAME);
+ String dbUri = configuration.getOption("uri").getValue();
+ String schema = configuration.getOption("schema").getValue();
+ String username = configuration.getOption("username").getValue();
+ String password = configuration.getOption("password").getValue();
+
+ if (!dbUri.endsWith("/")) {
+ dbUri = dbUri + "/";
}
try {
Map<String, Object> jpaConfig = new HashMap<String, Object>();
jpaConfig.put("javax.persistence.jdbc.driver",
"com.mysql.jdbc.Driver");
- jpaConfig.put("javax.persistence.jdbc.url", DB_URI + SCHEMA);
- jpaConfig.put("javax.persistence.jdbc.user", USERNAME);
- jpaConfig.put("javax.persistence.jdbc.password", PASSWORD);
- entityManagerFactory =
-
Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME, jpaConfig);
+ jpaConfig.put("javax.persistence.jdbc.url", dbUri + schema);
+ jpaConfig.put("javax.persistence.jdbc.user", username);
+ jpaConfig.put("javax.persistence.jdbc.password", password);
+ entityManagerFactory =
Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME, jpaConfig);
em = entityManagerFactory.createEntityManager();
- } catch (RuntimeException e){
- throw new PerfSONARException("Persistence
initialization failed: " + e.getMessage(), e);
- }
- }
+ } catch (RuntimeException e) {
+ throw new PerfSONARException("Persistence initialization failed:
" + e.getMessage(), e);
+ }
+ }
- @Override
- public void run() throws PerfSONARException {
- // TODO Auto-generated method stub
-
- }
+ @Override
+ public void run() throws PerfSONARException
+ {
+ // TODO Auto-generated method stub
- @Override
- public Collection<Element> fetch(Element request) throws
PerfSONARException {
- // TODO Auto-generated method stub
- long t1 = System.currentTimeMillis();
- checkMetadataCorectness((Message)request);
-
- if (!(request instanceof Message)){
- throw new PerfSONARException(
- "parse",
- "Object [" + request.getClass() + "] is not a valid Message
["
- + Message.class
- + "] element.");
- }
-
- Message message = (Message)request;
- SetupDataKeyResponse sdkr = new SetupDataKeyResponse();
-
- Collection<Element> result = new ArrayList<Element>();
- for (Metadata metadata : message.getMetadataCollection()) {
- Query query = qg.getQuery(em, metadata,
Interfaces.TABLE);
- result =
sdkr.fetchElements(query.getResultList().iterator());
- }
-
- long t2 = System.currentTimeMillis();
- logger.info("TIME of Fetch: " + (t2 - t1));
-
- return result;
- }
+ }
- /**
- *
- * @return String with the response message (in NMWG format) of
MetadataKeyRequest
- * @throws PerfSONARException
- */
- public String rawFetch() throws PerfSONARException{
-
-
- List<Interfaces> resultList =
(List<Interfaces>)em.createNamedQuery(Interfaces.ALL).getResultList();
- MetadaKeyResponse mKRR = new MetadaKeyResponse();
-
- return mKRR.fetchMetadataMessage(resultList.iterator());
- }
-
- @Override
- public String rawFetch(Element request) throws PerfSONARException {
-
- long t1 = System.currentTimeMillis();
- checkMetadataCorectness((Message)request);
- Metadata metadata =
((Message)request).getMetadataCollection().iterator().next();
-
- Query query = qg.getQuery(em, metadata, Interfaces.TABLE);
-
- MetadaKeyResponse mKRR = new MetadaKeyResponse();
- String result =
mKRR.fetchMetadataMessage(query.getResultList().iterator());
-
- long t2 = System.currentTimeMillis();
- logger.info("TIME of rawFetch: " + (t2 - t1));
-
- return result;
-
- }
+ @Override
+ public Collection<Element> fetch(Element request) throws
PerfSONARException
+ {
+ // TODO Auto-generated method stub
+ long t1 = System.currentTimeMillis();
+ checkMetadataCorectness((Message) request);
- @Override
- public void remove(Element request) throws PerfSONARException {
- // TODO Auto-generated method stub
-
- }
+ if (!(request instanceof Message)) {
+ throw new PerfSONARException("parse",
+ "Object [" + request.getClass() +
"] is not a valid Message [" + Message.class
+ + "] element.");
+ }
- @Override
- public void store(Element request) throws PerfSONARException {
- // TODO Auto-generated method stub
-
- }
+ Message message = (Message) request;
+ SetupDataKeyResponse sdkr = new SetupDataKeyResponse();
- @Override
- public void update(Element request) throws PerfSONARException {
- // TODO Auto-generated method stub
-
- }
-
-
- private void checkMetadataCorectness(Message request) throws
PerfSONARException {
-
- if (request.getMetadataCollection().size() == 0) {
- logger.warn("can not find any metadatas with a valid
content");
- throw new PerfSONARException("query_exception",
- "can not find any metadatas with a
valid content");
- }
-
- String eventType = null;
- for (Metadata m : request.getMetadataCollection()) {
+ Collection<Element> result = new ArrayList<Element>();
+ for (Metadata metadata : message.getMetadataCollection()) {
+ Query query = qg.getQuery(em, metadata, Interfaces.TABLE);
+ result = sdkr.fetchElements(query.getResultList().iterator());
+ }
- try {
- eventType =
m.getFirstEventType().getEventType().trim();
- } catch (Exception ex) {
+ long t2 = System.currentTimeMillis();
+ logger.info("TIME of Fetch: " + (t2 - t1));
- logger.warn("can not find correct eventType
in metadata element");
- throw new
PerfSONARException("query_exception",
- "can not find correct
eventType in metadata element");
- }
- if (eventType != null)
- break;
+ return result;
+ }
- }
-
+ /**
+ * @return String with the response message (in NMWG format) of
MetadataKeyRequest
+ * @throws PerfSONARException
+ */
+ public String rawFetch() throws PerfSONARException
+ {
- if (eventType == null || eventType.equals("")) {
- logger.warn("can not find correct eventType in
metadata element");
- throw new PerfSONARException("query_exception",
- "can not find eventType in metadata
element");
- }
-
- }
+ List<Interfaces> resultList = (List<Interfaces>)
em.createNamedQuery(Interfaces.ALL).getResultList();
+ MetadaKeyResponse mKRR = new MetadaKeyResponse();
+ return mKRR.fetchMetadataMessage(resultList.iterator());
+ }
-
-
+ @Override
+ public String rawFetch(Element request) throws PerfSONARException
+ {
+
+ long t1 = System.currentTimeMillis();
+ checkMetadataCorectness((Message) request);
+ Metadata metadata = ((Message)
request).getMetadataCollection().iterator().next();
+
+ Query query = qg.getQuery(em, metadata, Interfaces.TABLE);
+
+ MetadaKeyResponse mKRR = new MetadaKeyResponse();
+ String result =
mKRR.fetchMetadataMessage(query.getResultList().iterator());
+
+ long t2 = System.currentTimeMillis();
+ logger.info("TIME of rawFetch: " + (t2 - t1));
+
+ return result;
+
+ }
+
+ @Override
+ public void remove(Element request) throws PerfSONARException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void store(Element request) throws PerfSONARException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void update(Element request) throws PerfSONARException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+
+ private void checkMetadataCorectness(Message request) throws
PerfSONARException
+ {
+
+ if (request.getMetadataCollection().isEmpty()) {
+ logger.warn("can not find any metadatas with a valid content");
+ throw new PerfSONARException("query_exception", "can not find
any metadatas with a valid content");
+ }
+
+ String eventType = null;
+ for (Metadata m : request.getMetadataCollection()) {
+
+ try {
+ eventType = m.getFirstEventType().getEventType().trim();
+ } catch (Exception ex) {
+
+ logger.warn("can not find correct eventType in metadata
element");
+ throw new PerfSONARException("query_exception", "can not
find correct eventType in metadata element");
+ }
+ if (eventType != null) {
+ break;
+ }
+
+ }
+
+
+ if (eventType == null || eventType.isEmpty()) {
+ logger.warn("can not find correct eventType in metadata
element");
+ throw new PerfSONARException("query_exception", "can not find
eventType in metadata element");
+ }
+
+
+ }
+
+
}
Modified:
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/sql/query/QueryGenerator.java
===================================================================
---
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/sql/query/QueryGenerator.java
2012-10-22 15:38:39 UTC (rev 6031)
+++
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/sql/query/QueryGenerator.java
2012-11-19 07:56:19 UTC (rev 6032)
@@ -18,101 +18,111 @@
/**
- *
* @author Piotr Pikusa
()
- *
*/
-public class QueryGenerator {
-
- protected static final Logger logger =
LoggerFactory.getLogger(QueryGeneratorManager.class);
-
-
- public Query getQuery(EntityManager em, Metadata metadata, String
tableName) throws PerfSONARException{
-
- Map<String, String>parametersMap =
getParametersMap(metadata, tableName);
- logger.info("QUERY: " + parametersMap.get("query"));
-
-
- Query query =
em.createNativeQuery(parametersMap.get("query"), Interfaces.class);
- for (String parameter : parametersMap.keySet()) {
- if(!parameter.equals("query"))
- query.setParameter(parameter,
parametersMap.get(parameter));
- }
-
- return query;
- }
-
-
- /**
- * Method gets map with all the parameters needed to create query
object of Query class. It also includes a native sql query under
- * the "query" key.
- * @param metadata
- * @param tableName
- * @return
- * @throws PerfSONARException
- */
- public Map<String, String> getParametersMap(Metadata metadata, String
tableName) throws PerfSONARException{
-
- Map<String, String> resultMap = new HashMap<String, String>();
-
- String keyword = null;
-
- String ifAddress = null;
- String hostName = null;
- String ifName = null;
- String ifDescription = null;
- String ifAddressType = null;
- String ifIndex = null;
- String type = null;
- String direction = null;
+public class QueryGenerator
+{
+ protected static final Logger LOGGER =
LoggerFactory.getLogger(QueryGeneratorManager.class);
+
+ public Query getQuery(EntityManager em, Metadata metadata, String
tableName) throws PerfSONARException
+ {
+ Map<String, String> parametersMap = getParametersMap(metadata,
tableName);
+ LOGGER.info("QUERY: " + parametersMap.get("query"));
+
+ Query query = em.createNativeQuery(parametersMap.get("query"),
Interfaces.class);
+ for (String parameter : parametersMap.keySet()) {
+ if (!parameter.equals("query")) {
+ query.setParameter(parameter, parametersMap.get(parameter));
+ }
+ }
+
+ return query;
+ }
+
+
+ /**
+ * Method gets map with all the parameters needed to create query object
of Query class. It also includes a
+ * native sql query under
+ * the "query" key.
+ *
+ * @param metadata
+ * @param tableName
+ * @return
+ * @throws PerfSONARException
+ */
+ public Map<String, String> getParametersMap(Metadata metadata, String
tableName) throws PerfSONARException
+ {
+
+ Map<String, String> resultMap = new HashMap<String, String>();
+
+ String keyword = null;
+
+ String ifAddress = null;
+ String hostName = null;
+ String ifName = null;
+ String ifDescription = null;
+ String ifAddressType = null;
+ String ifIndex = null;
+ String type = null;
+ String direction = null;
String classOfService = null;
- String capacity = null;
+ String capacity = null;
-
+
if (metadata.getSubject() != null) {
Element interf =
metadata.getSubject().getFirstChild("interface");
-
+
if (interf != null) {
- ifAddress = (interf.getFirstChild("ifAddress") !=
null ? interf.getFirstChild("ifAddress").getText().trim() : null);
- hostName = (interf.getFirstChild("hostName") !=
null ? interf.getFirstChild("hostName").getText().trim() : null);
- ifName = (interf.getFirstChild("ifName") !=
null ? interf.getFirstChild("ifName").getText().trim() : null);
- ifDescription = (interf.getFirstChild("ifDescription") !=
null ? interf.getFirstChild("ifDescription").getText().trim() : null);
- ifIndex = (interf.getFirstChild("ifIndex") !=
null ? interf.getFirstChild("ifIndex").getText().trim() : null);
- type = (interf.getFirstChild("type") !=
null ? interf.getFirstChild("type").getText().trim() : null);
- direction = (interf.getFirstChild("direction") !=
null ? interf.getFirstChild("direction").getText().trim() : null);
- classOfService = (interf.getFirstChild("classOfService") !=
null ? interf.getFirstChild("classOfService").getText().trim() : null);
- capacity = (interf.getFirstChild("capacity") !=
null ? interf.getFirstChild("capacity").getText().trim() : null);
+ ifAddress = (interf.getFirstChild("ifAddress") != null ?
interf.getFirstChild(
+ "ifAddress").getText().trim() : null);
+ hostName = (interf.getFirstChild("hostName") != null
+ ?
interf.getFirstChild("hostName").getText().trim()
+ : null);
+ ifName = (interf.getFirstChild("ifName") != null
+ ? interf.getFirstChild("ifName").getText().trim()
+ : null);
+ ifDescription = (interf.getFirstChild("ifDescription") !=
null ? interf.getFirstChild(
+ "ifDescription").getText().trim() : null);
+ ifIndex = (interf.getFirstChild("ifIndex") != null
+ ? interf.getFirstChild("ifIndex").getText().trim()
+ : null);
+ type = (interf.getFirstChild("type") != null ?
interf.getFirstChild("type").getText().trim() : null);
+ direction = (interf.getFirstChild("direction") != null ?
interf.getFirstChild(
+ "direction").getText().trim() : null);
+ classOfService = (interf.getFirstChild("classOfService") !=
null ? interf.getFirstChild(
+ "classOfService").getText().trim() : null);
+ capacity = (interf.getFirstChild("capacity") != null
+ ?
interf.getFirstChild("capacity").getText().trim()
+ : null);
try {
- ifAddressType =
(!interf.getFirstChild("ifAddress").getAttribute("type").trim().equals("") ?
interf.getFirstChild("ifAddress").getAttribute("type").trim(): null);
+ ifAddressType =
(!interf.getFirstChild("ifAddress").getAttribute("type").trim().isEmpty()
+ ?
interf.getFirstChild("ifAddress").getAttribute("type").trim()
+ : null);
} catch (Exception ex) {
- ifAddressType = null;
+ ifAddressType = null;
}
} else {
- throw new PerfSONARException(
- "query_exception",
- "no interface element in metadata element");
+ throw new PerfSONARException("query_exception", "no
interface element in metadata element");
}
} else {
- throw new PerfSONARException(
- "query_exception",
- "no subject element in metadata element");
+ throw new PerfSONARException("query_exception", "no subject
element in metadata element");
}
-
+
keyword = getKeyword(metadata.getParameters());
resultMap.put("eventType",
getEventType(metadata.getFirstEventType()));
- if (ifAddress != null ||
- hostName != null ||
- ifName != null ||
- ifDescription != null ||
- ifAddress != null ||
- ifAddressType != null ||
- direction != null ||
- classOfService != null ||
- capacity != null ||
- keyword != null) {
-
- resultMap.put("hostName", hostName);
+ if (ifAddress != null
+ || hostName != null
+ || ifName != null
+ || ifDescription != null
+ || ifAddress != null
+ || ifAddressType != null
+ || direction != null
+ || classOfService != null
+ || capacity != null
+ || keyword != null) {
+
+ resultMap.put("hostName", hostName);
resultMap.put("ifAddress", ifAddress);
resultMap.put("ifAddressType", ifAddressType);
resultMap.put("ifName", ifName);
@@ -121,68 +131,76 @@
//resultMap.put("type", type);
resultMap.put("direction", direction);
resultMap.put("capacity", capacity);
- resultMap.put("keyword",keyword);
+ resultMap.put("keyword", keyword);
resultMap = querySelectWithCriteria(resultMap);
}
-
+
return buildQuery(resultMap, tableName);
-
- }
-
- /**
- * Build native query
- * @param parametersMap the map with gathered parameters for the
query (the pair: name of the parameter and its value)
- * @param tableName - the name of table from which the data is
retreived
- * @return Under the key "query" it stores the value of the query.
Other keys are named with the parameters of query and store their values.
- */
- protected Map<String, String> buildQuery(Map<String, String>
parametersMap, String tableName){
-
- StringBuilder sb = new StringBuilder();
- sb.append("select * from ").append(tableName).append(" where
");
-
- int i = 1;
- for (String key : parametersMap.keySet()) {
- if(i++ < parametersMap.size()){
- sb.append(key).append(" =
:").append(key).append(" AND ");
- }
- else{
- sb.append(key).append(" =
:").append(key).append(" ");
- }
- }
-
- parametersMap.put("query", sb.toString());
- return parametersMap;
- }
-
-
- protected Map<String, String> querySelectWithCriteria(Map<String,
String> parametersMap) throws PerfSONARException{
-
- if (parametersMap.get("ifAddress") != null) {
- if (parametersMap.get("ifAddress").equals(""))
- throw new PerfSONARException("query_exception", " wrong
ifAddress");
- }else{
- parametersMap.remove("ifAddress");
+
+ }
+
+ /**
+ * Build native query.
+ *
+ * @param parametersMap the map with gathered parameters for the query
(the pair: name of the parameter and its
+ * value)
+ * @param tableName - the name of table from which the data is
retreived
+ * @return Under the key "query" it stores the value of the query. Other
keys are named with the parameters of
+ * query and store their values.
+ */
+ protected Map<String, String> buildQuery(Map<String, String>
parametersMap, String tableName)
+ {
+
+ StringBuilder sb = new StringBuilder();
+ sb.append("select * from ").append(tableName).append(" where ");
+
+ int i = 1;
+ for (String key : parametersMap.keySet()) {
+ if (i++ < parametersMap.size()) {
+ sb.append(key).append(" = :").append(key).append(" AND ");
+ } else {
+ sb.append(key).append(" = :").append(key).append(" ");
+ }
}
+ parametersMap.put("query", sb.toString());
+ return parametersMap;
+ }
+
+
+ protected Map<String, String> querySelectWithCriteria(Map<String,
String> parametersMap) throws PerfSONARException
+ {
+
+ if (parametersMap.get("ifAddress") != null) {
+ if (parametersMap.get("ifAddress").isEmpty()) {
+ throw new PerfSONARException("query_exception", " wrong
ifAddress");
+ }
+ } else {
+ parametersMap.remove("ifAddress");
+ }
+
if (parametersMap.get("hostName") != null) {
- if (parametersMap.get("hostName").equals(""))
+ if (parametersMap.get("hostName").isEmpty()) {
throw new PerfSONARException("query_exception", "wrong
hostName");
- }else{
- parametersMap.remove("hostName");
+ }
+ } else {
+ parametersMap.remove("hostName");
}
if (parametersMap.get("ifName") != null) {
- if (parametersMap.get("ifName").equals(""))
+ if (parametersMap.get("ifName").isEmpty()) {
throw new PerfSONARException("query_exception", "wrong
ifName");
- }else{
- parametersMap.remove("ifName");
+ }
+ } else {
+ parametersMap.remove("ifName");
}
if (parametersMap.get("ifDescription") != null) {
- if (parametersMap.get("ifDescription").equals(""))
+ if (parametersMap.get("ifDescription").isEmpty()) {
throw new PerfSONARException("query_exception", "wrong
ifDescription");
- }else{
- parametersMap.remove("ifDescription");
+ }
+ } else {
+ parametersMap.remove("ifDescription");
}
@@ -191,7 +209,7 @@
if (parametersMap.get("ifIndex").equals(""))
throw new PerfSONARException("query_exception", "wrong
ifIndex");
}else{
- parametersMap.remove("ifIndex");
+ parametersMap.remove("ifIndex");
}
*/
@@ -200,79 +218,84 @@
if (parametersMap.get("type").equals(""))
throw new PerfSONARException("query_exception", "wrong
type");
}else{
- parametersMap.remove("type");
+ parametersMap.remove("type");
}*/
if (parametersMap.get("direction") != null) {
- if (parametersMap.get("direction").equals(""))
+ if (parametersMap.get("direction").isEmpty()) {
throw new PerfSONARException("query_exception", "wrong
direction");
- }else{
- parametersMap.remove("direction");
- }
+ }
+ } else {
+ parametersMap.remove("direction");
+ }
if (parametersMap.get("capacity") != null) {
- if (parametersMap.get("capacity").equals(""))
+ if (parametersMap.get("capacity").isEmpty()) {
throw new PerfSONARException("query_exception", "wrong
capacity");
- }else{
- parametersMap.remove("capacity");
+ }
+ } else {
+ parametersMap.remove("capacity");
}
- if (parametersMap.get("ifAddressType") == null){
- parametersMap.remove("ifAddressType");
+ if (parametersMap.get("ifAddressType") == null) {
+ parametersMap.remove("ifAddressType");
}
-
- if (parametersMap.get("keyword") == null){
- parametersMap.remove("keyword");
+
+ if (parametersMap.get("keyword") == null) {
+ parametersMap.remove("keyword");
}
-
+
return parametersMap;
-
- }
-
- /**
- * Returns the value of <parameter name="keyword"> tag
- * @param parameters
- * @return keyword value string
- */
- protected String getKeyword(Parameters parameters){
- if (parameters != null){
- logger.info("parameters not null");
- if(parameters.getFirstParameter("keyword") != null){
- logger.info("keyword not null:"+
parameters.getFirstParameter("keyword").getText());
-
return(parameters.getFirstParameter("keyword").getText());
- }
-
- }
-
- return null;
- }
-
- /**
- * Returns string of given eventType
- * @param eventType
- * @return eventType url
- * @throws PerfSONARException when eventType is null or equals ""
- */
- protected String getEventType(EventType eventType) throws
PerfSONARException{
+ }
- String et = "";
- try{
- et = eventType.getEventType().trim();
- }catch(Exception e){
- logger.warn("can not find eventType in metadata
element");
- throw new PerfSONARException("query_exception", "can
not find eventType in metadata element");
-
- }
-
- if (et == null || et.equals("")) {
- logger.warn("can not find any eventType in metadata
element");
- throw new PerfSONARException("query_exception",
- "can not find any eventType in
metadata element");
- }
- logger.info("EventType: " + et);
- return et;
- }
-
+ /**
+ * Returns the value of <parameter name="keyword"> tag.
+ *
+ * @param parameters
+ * @return keyword value string
+ */
+ protected String getKeyword(Parameters parameters)
+ {
+ if (parameters != null) {
+ LOGGER.info("parameters not null");
+ if (parameters.getFirstParameter("keyword") != null) {
+ LOGGER.info("keyword not null:" +
parameters.getFirstParameter("keyword").getText());
+ return (parameters.getFirstParameter("keyword").getText());
+ }
+
+ }
+
+ return null;
+ }
+
+ /**
+ * Returns string of given eventType.
+ *
+ * @param eventType
+ * @return eventType url
+ * @throws PerfSONARException when eventType is null or equals ""
+ */
+ protected String getEventType(EventType eventType) throws
PerfSONARException
+ {
+
+ String et = "";
+ try {
+ et = eventType.getEventType().trim();
+ } catch (Exception e) {
+ LOGGER.warn("can not find eventType in metadata element");
+ throw new PerfSONARException("query_exception", "can not find
eventType in metadata element");
+
+ }
+
+ if (et == null || et.isEmpty()) {
+ LOGGER.warn("can not find any eventType in metadata element");
+ throw new PerfSONARException("query_exception", "can not find
any eventType in metadata element");
+ }
+
+ LOGGER.info("EventType: " + et);
+ return et;
+ }
+
}
Modified:
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/temp/ConnectionTester.java
===================================================================
---
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/temp/ConnectionTester.java
2012-10-22 15:38:39 UTC (rev 6031)
+++
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/temp/ConnectionTester.java
2012-11-19 07:56:19 UTC (rev 6032)
@@ -6,94 +6,92 @@
import java.sql.SQLException;
import java.sql.Statement;
-public class ConnectionTester {
- public Connection conn;
+public class ConnectionTester
+{
+ private Connection conn;
private final String url;
private final String userName;
private final String password;
-
- public ConnectionTester(){
+
+ public ConnectionTester()
+ {
url = "jdbc:mysql://localhost:3306/rrd_sql_test600";
userName = "root";
password = "@jawpcss$";
}
-
- public String connect()
+
+ public Connection getConnection()
{
+ return conn;
+ }
+
+ public String connect()
+ {
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
- }
- catch (InstantiationException e) {
+ } catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
- return "error";
- }
- catch (IllegalAccessException e) {
+ return "error";
+ } catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
- }
- catch (ClassNotFoundException e) {
+ } catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
-
+
try {
conn = DriverManager.getConnection(url, userName, password);
-
+
System.out.println("Connected");
+ } catch (SQLException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ return e.toString();
}
- catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- return e.toString();
- }
return "ok";
}
-
-
-
-
- public String getTable()
+
+
+ public String getTable()
{
connect();
Statement statement;
ResultSet rs;
- String wynik="";
-
+ String wynik = "";
+
try {
statement = conn.createStatement();
conn.createStatement();
rs = statement.executeQuery("SELECT * FROM metadata");
-
+
wynik = rs.getRow() + " ";
-
+
rs.next();
wynik = wynik + rs.getString(10) + " ";
rs.next();
- wynik = wynik+ rs.getString(1);
- // conn.close();
- }
- catch (SQLException e) {
+ wynik = wynik + rs.getString(1);
+ // conn.close();
+ } catch (SQLException e) {
// TODO Auto-generated catch block
System.err.println(e.toString());
}
-
+
return wynik;
}
-
-
-
-
-
- public static void main(String[] args) {
- //ConnectionTester ct = new ConnectionTester();
- //ct.connect();
- Long one = System.currentTimeMillis();
- FetchData fd = new FetchData();
- fd.fetchMetadataMessage();
- Long two = System.currentTimeMillis();
- System.out.println((two - one) + "\n " + fd.MetadataContent);
- }
-
+
+
+ public static void main(String[] args)
+ {
+ //ConnectionTester ct = new ConnectionTester();
+ //ct.connect();
+ Long one = System.currentTimeMillis();
+ FetchData fd = new FetchData();
+ fd.fetchMetadataMessage();
+ Long two = System.currentTimeMillis();
+ System.out.println((two - one) + "\n " + fd.getMetadataContent());
+ }
+
}
Deleted:
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/temp/Data.java
===================================================================
---
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/temp/Data.java
2012-10-22 15:38:39 UTC (rev 6031)
+++
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/temp/Data.java
2012-11-19 07:56:19 UTC (rev 6032)
@@ -1,15 +0,0 @@
-package org.perfsonar.service.temp;
-
-public class Data {
- String dataId = "";
- String metadataIdRef = "";
- String p_file = "";
- String p_dataSource = "";
- String p_valueUnits = "";
- String p_eventType = "";
- String p_dataSourceStep = "";
- String p_dataSourceType = "";
- String p_dataSourceHeartbeat = "";
- String p_dataSourceMinValue = "";
- String p_dataSourceMaxValue = "";
-}
Modified:
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/temp/FetchData.java
===================================================================
---
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/temp/FetchData.java
2012-10-22 15:38:39 UTC (rev 6031)
+++
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/temp/FetchData.java
2012-11-19 07:56:19 UTC (rev 6032)
@@ -7,182 +7,279 @@
import java.util.ArrayList;
import java.util.List;
-public class FetchData {
+public class FetchData
+{
+ private final ConnectionTester ct = new ConnectionTester();
+ private String resultXML = ""; // tutaj bedziemy budowac wynikowy xml
message
+ private final List<Metadata> metadataList = new ArrayList<Metadata>();
- final ConnectionTester ct = new ConnectionTester();
- String resultXML = ""; // tutaj bedziemy budowac wynikowy xml message
- final List<Metadata> metadataList = new ArrayList<Metadata>();
- List<Data> adataList = new ArrayList<Data>();
-
- List<String> metadataStringList = new ArrayList<String>();
- List<String> dataStringList = new ArrayList<String>();
-
- Statement statement;
- public String MetadataContent;
- public final Connection conn;
+ private List<String> metadataStringList = new ArrayList<String>();
+ private List<String> dataStringList = new ArrayList<String>();
- public FetchData() {
- ct.connect();
- conn = ct.conn;
-
- }
+ private Statement statement;
- public void fetchMetadataMessage() {
- ResultSet rs;
- MetadataContent = "<nmwg:message type=\"MetadataKeyResponse\"
xmlns:nmwg=\"http://ggf.org/ns/nmwg/base/2.0/\"
xmlns=\"http://ggf.org/ns/nmwg/base/2.0/\">\n";
- StringBuilder sb = new StringBuilder();
- sb.append(MetadataContent);
- String metadataS = "";
- String dataS = "";
+ private String metadataContent;
+ private final Connection conn;
- try {
- statement = conn.createStatement();
+ public FetchData()
+ {
+ ct.connect();
+ conn = ct.getConnection();
+ }
- //Metadata
- rs = statement.executeQuery("SELECT * FROM metadata");
- while (!rs.isLast()) {
- rs.next();
- sb.append(fetchMetadataRowNmwg(rs));
-
//metadataStringList.add(fetchMetadataRowNmwg(rs));
- }
-
-
- //data
- rs = statement.executeQuery("SELECT * FROM data");
- while (!rs.isLast()) {
- rs.next();
- sb.append(fetchDataRowNmwg(rs));
- //dataStringList.add(fetchDataRowNmwg(rs));
- }
-
- /*
- for (Iterator iterator =
metadataStringList.iterator(); iterator.hasNext();) {
- String m = (String) iterator.next();
- MetadataContent = MetadataContent.concat(m);
- }
- */
-
- String s = sb.toString();
- sb.append("</nmwg:message>") ;
- MetadataContent = sb.toString();
- conn.close();
- } catch (SQLException e) {
+ public String getMetadataContent()
+ {
+ return metadataContent;
+ }
- System.err.println(e.toString());
- }
-
-
- }
+ public Connection getConn()
+ {
+ return conn;
+ }
- public void fetchMetadataRows() {
- ResultSet rs;
+ public void fetchMetadataMessage()
+ {
+ ResultSet rs;
+ metadataContent = "<nmwg:message type=\"MetadataKeyResponse\"
xmlns:nmwg=\"http://ggf.org/ns/nmwg/base/2.0/\""
+ + " xmlns=\"http://ggf.org/ns/nmwg/base/2.0/\">\n";
+ StringBuilder sb = new StringBuilder();
+ sb.append(metadataContent);
+ String metadataS = "";
+ String dataS = "";
- try {
- statement = conn.createStatement();
- conn.createStatement();
- rs = statement.executeQuery("SELECT * FROM metadata");
+ try {
+ statement = conn.createStatement();
- while (!rs.isLast()) {
- rs.next();
- metadataList.add(fetchMetadataRow(rs));
- }
+ //Metadata
+ rs = statement.executeQuery("SELECT * FROM metadata");
+ while (!rs.isLast()) {
+ rs.next();
+ sb.append(fetchMetadataRowNmwg(rs));
+ //metadataStringList.add(fetchMetadataRowNmwg(rs));
+ }
- // conn.close();
- } catch (SQLException e) {
- System.err.println(e.toString());
- }
+ //data
+ rs = statement.executeQuery("SELECT * FROM data");
+ while (!rs.isLast()) {
+ rs.next();
+ sb.append(fetchDataRowNmwg(rs));
+ //dataStringList.add(fetchDataRowNmwg(rs));
+ }
- }
+ /*
+ for (Iterator iterator = metadataStringList.iterator();
iterator.hasNext();) {
+ String m = (String) iterator.next();
+ metadataContent = metadataContent.concat(m);
+ }
+ */
- public Metadata fetchMetadataRow(ResultSet rs) {
- Metadata m = new Metadata();
+ String s = sb.toString();
+ sb.append("</nmwg:message>");
+ metadataContent = sb.toString();
+ conn.close();
+ } catch (SQLException e) {
- try {
- m.metaId = rs.getString("metadata_id");
- m.subjId = rs.getString("subj_id");
- m.hostName = rs.getString("hostName");
- m.ifAddress = rs.getString("ifAddress");
- m.ifDescription = rs.getString("ifDescription");
- m.direction = rs.getString("direction");
- m.capacity = rs.getString("capacity");
+ System.err.println(e.toString());
+ }
- // conn.close();
- } catch (SQLException e) {
- System.err.println(e.toString());
- }
+ }
- return m;
- }
+ public void fetchMetadataRows()
+ {
+ ResultSet rs;
- public String fetchMetadataRowNmwg(ResultSet rs) {
- String metadata ="";
- try {
- metadata = "<nmwg:metadata
xmlns:nmwg=\"http://ggf.org/ns/nmwg/base/2.0/\" id=\""
- + rs.getString("metadata_id") + "\">"
+ "\n";
- metadata = metadata.concat(
- "<netutil:subject
xmlns:netutil=\"http://ggf.org/ns/nmwg/characteristic/utilization/2.0/\"
id=\""
- + rs.getString("subj_id") + "\">" +
"\n");
- metadata = metadata.concat(
- "<nmwgt:interface
xmlns:nmwgt=\"http://ggf.org/ns/nmwg/topology/2.0/\">"
- + "\n");
- metadata = metadata.concat("<nmwgt:hostName>" +
rs.getString("hostName")
- + "</nmwgt:hostName>" + "\n");
- metadata = metadata.concat("<nmwgt:ifAddress
type=\"ipv4\">"
- + rs.getString("ifAddress") +
"</nmwgt:ifAddress>" + "\n");
- metadata = metadata.concat(
-
"<nmwgt:ifName>TenGigabitEthernet1/1</nmwgt:ifName>"
- + "\n");
- metadata = metadata.concat("<nmwgt:ifDescription>"
- + rs.getString("ifDescription") +
"</nmwgt:ifDescription>"
- + "\n");
- metadata = metadata.concat("<nmwgt:direction>"
- + rs.getString("direction") +
"</nmwgt:direction>" + "\n");
- metadata = metadata.concat("<nmwgt:capacity>" +
rs.getString("capacity")
- + "</nmwgt:capacity>" + "\n");
- metadata =
metadata.concat("<nmwgt:authRealm></nmwgt:authRealm>" + "\n");
- metadata = metadata.concat("</nmwgt:interface>" +
"\n");
- metadata = metadata.concat("</netutil:subject>" +
"\n");
- metadata = metadata.concat(
-
"<nmwg:eventType>http://ggf.org/ns/nmwg/characteristic/utilization/2.0</nmwg:eventType>"
- + "\n");
- metadata = metadata.concat("</nmwg:metadata>");
- } catch (SQLException e) {
+ try {
+ statement = conn.createStatement();
+ conn.createStatement();
+ rs = statement.executeQuery("SELECT * FROM metadata");
- System.err.println(e.toString());
- }
+ while (!rs.isLast()) {
+ rs.next();
+ metadataList.add(fetchMetadataRow(rs));
+ }
- return metadata;
- }
-
-
-
- public String fetchDataRowNmwg(ResultSet rs) {
- String data ="";
- StringBuilder sb = new StringBuilder();
- try {
- sb.append("<nmwg:data
xmlns:nmwg=\"http://ggf.org/ns/nmwg/base/2.0/\"
id=\"").append(rs.getString("data_id")).append("\"
metadataIdRef=\"").append(rs.getString("metadataIdRef")).append("\">").append("\n");
- sb.append("<nmwg:key>" + "\n");
- sb.append("<nmwg:parameters>"+ "\n");
- sb.append("<nmwg:parameter
name=\"file\">").append(rs.getString("p_file")).append("</nmwg:parameter>").append("\n");
- sb.append("<nmwg:parameter
name=\"dataSource\">").append(rs.getString("p_dataSource")).append("</nmwg:parameter>").append("\n");
- sb.append("<nmwg:parameter
name=\"valueUnits\">").append(rs.getString("p_valueUnits")).append("</nmwg:parameter>").append("\n");
- sb.append("<nmwg:parameter
name=\"eventType\">").append(rs.getString("p_eventType")).append("</nmwg:parameter>").append("\n");
- sb.append("<nmwg:parameter
name=\"dataSourceStep\">").append(rs.getString("p_dataSourceStep")).append("</nmwg:parameter>").append("\n");
- sb.append("<nmwg:parameter
name=\"dataSourceType\">").append(rs.getString("p_dataSourceType")).append("</nmwg:parameter>").append("\n");
- sb.append("<nmwg:parameter
name=\"dataSourceMinValue\">").append(rs.getString("p_dataSourceMinValue")).append("</nmwg:parameter>").append("\n");
- sb.append("<nmwg:parameter
name=\"dataSourceMaxValue\">").append(rs.getString("p_dataSourceMaxValue")).append("</nmwg:parameter>").append("\n");
- sb.append("</nmwg:parameters>"+ "\n");
- sb.append("</nmwg:key>" + "\n");
- sb.append("</nmwg:data>"+ "\n");
-
- } catch (SQLException e) {
+ // conn.close();
+ } catch (SQLException e) {
- System.err.println(e.toString());
- }
- return sb.toString();
- }
+ System.err.println(e.toString());
+ }
+ }
+ public Metadata fetchMetadataRow(ResultSet rs)
+ {
+ Metadata m = new Metadata();
+
+ try {
+ m.setMetaId(rs.getString("metadata_id"));
+ m.setSubjId(rs.getString("subj_id"));
+ m.setHostName(rs.getString("hostName"));
+ m.setIfAddress(rs.getString("ifAddress"));
+ m.setIfDescription(rs.getString("ifDescription"));
+ m.setDirection(rs.getString("direction"));
+ m.setCapacity(rs.getString("capacity"));
+
+ // conn.close();
+ } catch (SQLException e) {
+
+ System.err.println(e.toString());
+ }
+
+ return m;
+ }
+
+ public String fetchMetadataRowNmwg(ResultSet rs)
+ {
+ String metadata = "";
+ try {
+ metadata =
+ "<nmwg:metadata
xmlns:nmwg=\"http://ggf.org/ns/nmwg/base/2.0/\" id=\"" +
rs.getString("metadata_id")
+ + "\">" + "\n";
+ metadata = metadata.concat(
+ "<netutil:subject
xmlns:netutil=\"http://ggf.org/ns/nmwg/characteristic/utilization/2.0/\"
id=\""
+ + rs.getString("subj_id") + "\">" + "\n");
+ metadata = metadata.concat("<nmwgt:interface
xmlns:nmwgt=\"http://ggf.org/ns/nmwg/topology/2.0/\">" + "\n");
+ metadata = metadata.concat("<nmwgt:hostName>" +
rs.getString("hostName") + "</nmwgt:hostName>" + "\n");
+ metadata = metadata.concat(
+ "<nmwgt:ifAddress type=\"ipv4\">" +
rs.getString("ifAddress") + "</nmwgt:ifAddress>" + "\n");
+ metadata =
metadata.concat("<nmwgt:ifName>TenGigabitEthernet1/1</nmwgt:ifName>" + "\n");
+ metadata = metadata.concat(
+ "<nmwgt:ifDescription>" + rs.getString("ifDescription") +
"</nmwgt:ifDescription>" + "\n");
+ metadata = metadata.concat("<nmwgt:direction>" +
rs.getString("direction") + "</nmwgt:direction>" + "\n");
+ metadata = metadata.concat("<nmwgt:capacity>" +
rs.getString("capacity") + "</nmwgt:capacity>" + "\n");
+ metadata = metadata.concat("<nmwgt:authRealm></nmwgt:authRealm>"
+ "\n");
+ metadata = metadata.concat("</nmwgt:interface>" + "\n");
+ metadata = metadata.concat("</netutil:subject>" + "\n");
+ metadata = metadata.concat(
+
"<nmwg:eventType>http://ggf.org/ns/nmwg/characteristic/utilization/2.0</nmwg:eventType>"
+ "\n");
+ metadata = metadata.concat("</nmwg:metadata>");
+ } catch (SQLException e) {
+
+ System.err.println(e.toString());
+ }
+
+ return metadata;
+ }
+
+
+ public String fetchDataRowNmwg(ResultSet rs)
+ {
+ String data = "";
+ StringBuilder sb = new StringBuilder();
+ try {
+ sb.append("<nmwg:data
xmlns:nmwg=\"http://ggf.org/ns/nmwg/base/2.0/\" id=\"").append(
+ rs.getString("data_id")).append("\"
metadataIdRef=\"").append(rs.getString("metadataIdRef")).append(
+ "\">").append("\n");
+ sb.append("<nmwg:key>" + "\n");
+ sb.append("<nmwg:parameters>" + "\n");
+ sb.append("<nmwg:parameter
name=\"file\">").append(rs.getString("p_file")).append(
+ "</nmwg:parameter>").append("\n");
+ sb.append("<nmwg:parameter
name=\"dataSource\">").append(rs.getString("p_dataSource")).append(
+ "</nmwg:parameter>").append("\n");
+ sb.append("<nmwg:parameter
name=\"valueUnits\">").append(rs.getString("p_valueUnits")).append(
+ "</nmwg:parameter>").append("\n");
+ sb.append("<nmwg:parameter
name=\"eventType\">").append(rs.getString("p_eventType")).append(
+ "</nmwg:parameter>").append("\n");
+ sb.append("<nmwg:parameter
name=\"dataSourceStep\">").append(rs.getString("p_dataSourceStep")).append(
+ "</nmwg:parameter>").append("\n");
+ sb.append("<nmwg:parameter
name=\"dataSourceType\">").append(rs.getString("p_dataSourceType")).append(
+ "</nmwg:parameter>").append("\n");
+ sb.append("<nmwg:parameter name=\"dataSourceMinValue\">").append(
+
rs.getString("p_dataSourceMinValue")).append("</nmwg:parameter>").append("\n");
+ sb.append("<nmwg:parameter name=\"dataSourceMaxValue\">").append(
+
rs.getString("p_dataSourceMaxValue")).append("</nmwg:parameter>").append("\n");
+ sb.append("</nmwg:parameters>" + "\n");
+ sb.append("</nmwg:key>" + "\n");
+ sb.append("</nmwg:data>" + "\n");
+
+ } catch (SQLException e) {
+
+ System.err.println(e.toString());
+ }
+ return sb.toString();
+ }
+
+
+ private static class Metadata
+ {
+ private String metaId = "";
+ private String subjId = "";
+ private String hostName = "";
+ private String ifAddress = "";
+ private String ifDescription = "";
+ private String direction = "";
+ private String capacity = "";
+
+ public String getMetaId()
+ {
+ return metaId;
+ }
+
+ public void setMetaId(String metaId)
+ {
+ this.metaId = metaId;
+ }
+
+ public String getSubjId()
+ {
+ return subjId;
+ }
+
+ public void setSubjId(String subjId)
+ {
+ this.subjId = subjId;
+ }
+
+ public String getHostName()
+ {
+ return hostName;
+ }
+
+ public void setHostName(String hostName)
+ {
+ this.hostName = hostName;
+ }
+
+ public String getIfAddress()
+ {
+ return ifAddress;
+ }
+
+ public void setIfAddress(String ifAddress)
+ {
+ this.ifAddress = ifAddress;
+ }
+
+ public String getIfDescription()
+ {
+ return ifDescription;
+ }
+
+ public void setIfDescription(String ifDescription)
+ {
+ this.ifDescription = ifDescription;
+ }
+
+ public String getDirection()
+ {
+ return direction;
+ }
+
+ public void setDirection(String direction)
+ {
+ this.direction = direction;
+ }
+
+ public String getCapacity()
+ {
+ return capacity;
+ }
+
+ public void setCapacity(String capacity)
+ {
+ this.capacity = capacity;
+ }
+ }
}
Deleted:
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/temp/Metadata.java
===================================================================
---
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/temp/Metadata.java
2012-10-22 15:38:39 UTC (rev 6031)
+++
trunk/perfsonar-java-rrd-ma-SQL_backend/src/main/java/org/perfsonar/service/temp/Metadata.java
2012-11-19 07:56:19 UTC (rev 6032)
@@ -1,13 +0,0 @@
-package org.perfsonar.service.temp;
-
-public class Metadata {
-
- String metaId ="";
- String subjId = "";
- String hostName ="";
- String ifAddress ="";
- String ifDescription ="";
- String direction ="";
- String capacity ="";
-
-}
- [pS-dev] [GEANT/SA2/ps-java-services] r6032 - in trunk/perfsonar-java-rrd-ma-SQL_backend: . src sr c/checkstyle src/main/java/org/perfsonar/service src/main/ java/org/perfsonar/service/measurementArchive/rrdType src/ main/java/org/perfsonar/service/measurementArchive/rrdType /storage src/main/java/org/perfsonar/service/measurementAr chive/rrdType/storage/exist src/main/java/org/perfsonar/se rvice/measurementArchive/rrdType/storage/exist/query src/m ain/java/org/perfsonar/service/measurementArchive/rrdType/ storage/persistence src/main/java/org/perfsonar/service/me asurementArchive/rrdType/storage/persistence/entity src/ma in/java/org/perfsonar/service/measurementArchive/rrdType/s torage/rrd src/main/java/org/perfsonar/service/measurement Archive/rrdType/storage/sql src/main/java/org/perfsonar/se rvice/measurementArchive/rrdType/storage/sql/query src/mai n/java/org/perfsonar/service/temp, svn-noreply, 11/19/2012
Archive powered by MHonArc 2.6.16.