Skip to Content.
Sympa Menu

perfsonar-dev - [pS-dev] [GEANT/SA2/ps-java-services] r5817 - in trunk/perfsonar-java-rrd-sql-ma/src/main/java/org/perfs onar/service/measurementArchive/rrdType/storage: . sql sql/query

Subject: perfsonar development work

List archive

[pS-dev] [GEANT/SA2/ps-java-services] r5817 - in trunk/perfsonar-java-rrd-sql-ma/src/main/java/org/perfs onar/service/measurementArchive/rrdType/storage: . sql sql/query


Chronological Thread 
  • From:
  • To:
  • Subject: [pS-dev] [GEANT/SA2/ps-java-services] r5817 - in trunk/perfsonar-java-rrd-sql-ma/src/main/java/org/perfs onar/service/measurementArchive/rrdType/storage: . sql sql/query
  • Date: Fri, 29 Jul 2011 15:43:28 +0100

Author: psnc.pikusa
Date: 2011-07-29 15:43:27 +0100 (Fri, 29 Jul 2011)
New Revision: 5817

Added:

trunk/perfsonar-java-rrd-sql-ma/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/sql/

trunk/perfsonar-java-rrd-sql-ma/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/sql/query/

trunk/perfsonar-java-rrd-sql-ma/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/sql/query/QueryGenerator.java
Log:
New QueryGenerator related to backend transition

Added:
trunk/perfsonar-java-rrd-sql-ma/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/sql/query/QueryGenerator.java
===================================================================
---
trunk/perfsonar-java-rrd-sql-ma/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/sql/query/QueryGenerator.java
(rev 0)
+++
trunk/perfsonar-java-rrd-sql-ma/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/sql/query/QueryGenerator.java
2011-07-29 14:43:27 UTC (rev 5817)
@@ -0,0 +1,248 @@
+package org.perfsonar.service.measurementArchive.rrdType.storage.sql.query;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.perfsonar.base2.xml.nmwg.EventType;
+import org.apache.log4j.Logger;
+import org.perfsonar.base2.service.exceptions.PerfSONARException;
+import org.perfsonar.base2.xml.Element;
+import org.perfsonar.base2.xml.nmwg.Metadata;
+import org.perfsonar.base2.xml.nmwg.Parameters;
+import
org.perfsonar.service.measurementArchive.rrdType.storage.exist.QueryGeneratorManager;
+
+
+/**
+ *
+ * @author Piotr Pikusa
()
+ *
+ */
+public class QueryGenerator {
+
+ protected static final Logger logger =
Logger.getLogger(QueryGeneratorManager.class.getName());
+
+
+ public Map<String, String> getQuery(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; //TODO dodac to do tabeli!
+ String ifIndex = null;
+ String type = null;
+ String direction = null;
+ String classOfService = 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);
+ try {
+ ifAddressType =
(!interf.getFirstChild("ifAddress").getAttribute("type").trim().equals("") ?
interf.getFirstChild("ifAddress").getAttribute("type").trim(): null);
+ } catch (Exception ex) {
+ ifAddressType = null;
+ }
+ } else {
+ throw new PerfSONARException(
+ "query_exception",
+ "no interface element in metadata element");
+ }
+ } else {
+ 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 ||
+ ifIndex != null ||
+ type != 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);
+ resultMap.put("ifDescription", ifDescription);
+ resultMap.put("ifIndex", ifIndex);
+ resultMap.put("type", type);
+ resultMap.put("direction", direction);
+ resultMap.put("capacity", capacity);
+ 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){
+
+ StringBuffer sb = new StringBuffer();
+ sb.append("select * from " + tableName + " where ");
+
+ int i = 1;
+ for (String key : parametersMap.keySet()) {
+ if(i++ < parametersMap.size()){
+ sb.append(key + " = :" + key + " AND ");
+ }
+ else{
+ sb.append(key + " = :" + key + " ");
+ }
+ }
+
+ 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");
+ }
+
+ if (parametersMap.get("hostName") != null) {
+ if (parametersMap.get("hostName").equals(""))
+ throw new PerfSONARException("query_exception", "wrong
hostName");
+ }else{
+ parametersMap.remove("hostName");
+ }
+
+ if (parametersMap.get("ifName") != null) {
+ if (parametersMap.get("ifName").equals(""))
+ throw new PerfSONARException("query_exception", "wrong
ifName");
+ }else{
+ parametersMap.remove("ifName");
+ }
+
+ if (parametersMap.get("ifDescription") != null) {
+ if (parametersMap.get("ifDescription").equals(""))
+ throw new PerfSONARException("query_exception", "wrong
ifDescription");
+ }else{
+ parametersMap.remove("ifDescription");
+ }
+
+
+ if (parametersMap.get("ifIndex") != null) {
+ if (parametersMap.get("ifIndex").equals(""))
+ throw new PerfSONARException("query_exception", "wrong
ifIndex");
+ }else{
+ parametersMap.remove("ifIndex");
+ }
+
+ if (parametersMap.get("type") != null) {
+ if (parametersMap.get("type").equals(""))
+ throw new PerfSONARException("query_exception", "wrong
type");
+ }else{
+ parametersMap.remove("type");
+ }
+
+ if (parametersMap.get("direction") != null) {
+ if (parametersMap.get("direction").equals(""))
+ throw new PerfSONARException("query_exception", "wrong
direction");
+ }else{
+ parametersMap.remove("direction");
+ }
+
+ if (parametersMap.get("capacity") != null) {
+ if (parametersMap.get("capacity").equals(""))
+ throw new PerfSONARException("query_exception", "wrong
capacity");
+ }else{
+ parametersMap.remove("capacity");
+ }
+
+ if (parametersMap.get("ifAddressType") == null){
+ parametersMap.remove("ifAddressType");
+ }
+
+ 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;
+ }
+
+}



  • [pS-dev] [GEANT/SA2/ps-java-services] r5817 - in trunk/perfsonar-java-rrd-sql-ma/src/main/java/org/perfs onar/service/measurementArchive/rrdType/storage: . sql sql/query, svn-noreply, 07/29/2011

Archive powered by MHonArc 2.6.16.

Top of Page