perfsonar-dev - [pS-dev] [GEANT/SA2/ps-java-services] r5819 - trunk/perfsonar-java-rrd-sql-ma/src/main/java/org/perfsona r/service/measurementArchive/rrdType/storage/persistence
Subject: perfsonar development work
List archive
[pS-dev] [GEANT/SA2/ps-java-services] r5819 - trunk/perfsonar-java-rrd-sql-ma/src/main/java/org/perfsona r/service/measurementArchive/rrdType/storage/persistence
Chronological Thread
- From:
- To:
- Subject: [pS-dev] [GEANT/SA2/ps-java-services] r5819 - trunk/perfsonar-java-rrd-sql-ma/src/main/java/org/perfsona r/service/measurementArchive/rrdType/storage/persistence
- Date: Fri, 29 Jul 2011 15:46:34 +0100
Author: psnc.pikusa
Date: 2011-07-29 15:46:34 +0100 (Fri, 29 Jul 2011)
New Revision: 5819
Added:
trunk/perfsonar-java-rrd-sql-ma/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/persistence/MetadaKeyRequestResponse.java
Log:
NEw Response Generator related to backend changes
Added:
trunk/perfsonar-java-rrd-sql-ma/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/persistence/MetadaKeyRequestResponse.java
===================================================================
---
trunk/perfsonar-java-rrd-sql-ma/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/persistence/MetadaKeyRequestResponse.java
(rev 0)
+++
trunk/perfsonar-java-rrd-sql-ma/src/main/java/org/perfsonar/service/measurementArchive/rrdType/storage/persistence/MetadaKeyRequestResponse.java
2011-07-29 14:46:34 UTC (rev 5819)
@@ -0,0 +1,147 @@
+package org.perfsonar.service.measurementArchive.rrdType.storage.persistence;
+
+import java.util.Iterator;
+
+import org.apache.log4j.Logger;
+import org.perfsonar.base2.service.exceptions.PerfSONARException;
+import
org.perfsonar.service.measurementArchive.rrdType.storage.exist.ExistMetadataStorageDAOImpl;
+import
org.perfsonar.service.measurementArchive.rrdType.storage.persistence.entity.Interfaces;
+
+public class MetadaKeyRequestResponse {
+
+ private static final Logger logger =
Logger.getLogger(MetadaKeyRequestResponse.class.getName());
+
+ 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 {
+
+ StringBuffer sb = new StringBuffer();
+
+ Interfaces intf;
+
+ while(ifIterator.hasNext()){
+ intf = ifIterator.next();
+ sb.append(fetchMetadataRowNmwg(intf));
+ sb.append(fetchDataRowNmwg(intf));
+ }
+ return sb.toString();
+
+ }
+
+ //TODO dodac keyword
+ 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");
+ }
+
+ StringBuffer metadata = new StringBuffer();
+
+ try {
+ metadata.append("<nmwg:metadata
xmlns:nmwg=\"http://ggf.org/ns/nmwg/base/2.0/\" id=\""
+ + intf.getMetadataId() + "\">" +
"\n");
+ metadata.append(
+ "<"+subject+":subject
xmlns:"+subject+"=\""+intf.getEventType()+"/\" id=\""
+ + intf.getSubjId() + "\">" + "\n");
+ metadata.append(
+ "<nmwgt:interface
xmlns:nmwgt=\"http://ggf.org/ns/nmwg/topology/2.0/\">"
+ + "\n");
+ metadata.append("<nmwgt:hostName>" +
intf.getHostName()
+ + "</nmwgt:hostName>" + "\n");
+ //ifAddresType is optional
+ if(intf.getIfAddressType() == null)
+ intf.setIfAddressType("");
+ metadata.append("<nmwgt:ifAddress
type=\""+intf.getIfAddressType()+"\">"
+ + intf.getIfAddress() +
"</nmwgt:ifAddress>" + "\n");
+ metadata.append(
+
"<nmwgt:ifName>TenGigabitEthernet1/1</nmwgt:ifName>"
+ + "\n");
+ metadata.append("<nmwgt:ifDescription>"
+ + intf.getIfDescription() +
"</nmwgt:ifDescription>"
+ + "\n");
+ metadata.append("<nmwgt:direction>"
+ + intf.getDirection() +
"</nmwgt:direction>" + "\n");
+ metadata.append("<nmwgt:capacity>" +
intf.getCapacity()
+ + "</nmwgt:capacity>" + "\n");
+ metadata.append("<nmwgt:authRealm></nmwgt:authRealm>"
+ "\n");
+ metadata.append("</nmwgt:interface>" + "\n");
+ metadata.append("</"+subject+":subject>" + "\n");
+ metadata.append(
+
"<nmwg:eventType>"+intf.getEventType()+"</nmwg:eventType>"
+ + "\n");
+
+ if(intf.getKeyword() != null &&
!intf.getKeyword().trim().equals("")){
+ metadata.append("<parameters
id=\"params1\">\n");
+ metadata.append("<parameter
name=\"keyword\">"+intf.getKeyword()+"</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 {
+
+ StringBuffer sb = new StringBuffer();
+
+ try {
+ sb.append( "<nmwg:data
xmlns:nmwg=\"http://ggf.org/ns/nmwg/base/2.0/\"
id=\"data"+intf.getMetadataId().trim() + "\" metadataIdRef=\"" +
intf.getMetadataId().trim() +"\">" + "\n");
+ sb.append("<nmwg:key>" + "\n");
+ sb.append("<nmwg:parameters>"+ "\n");
+ sb.append("<nmwg:parameter name=\"file\">"+
intf.getFile().trim()+ "</nmwg:parameter>" + "\n");
+ sb.append("<nmwg:parameter name=\"dataSource\">"+
intf.getDataSource().trim()+"</nmwg:parameter>"+ "\n");
+ sb.append("<nmwg:parameter name=\"valueUnits\">"+
intf.getValueUnits().trim()+"</nmwg:parameter>" + "\n");
+ sb.append("<nmwg:parameter name=\"eventType\">"+
intf.getEventType().trim() +"</nmwg:parameter>"+ "\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\">"+
intf.getDataSource().trim()+"</nmwg:parameter>"+ "\n");
+ if(intf.getDataSourceType() == null)
+ intf.setDataSourceType("");
+ sb.append("<nmwg:parameter name=\"dataSourceType\">"+
intf.getDataSourceType().trim()+"</nmwg:parameter>" + "\n");
+ if(intf.getEventType() == null)
+ intf.setEventType("");
+ sb.append("<nmwg:parameter name=\"dataSourceHeartbeat\">"+
intf.getEventType().trim() +"</nmwg:parameter>"+ "\n");
+ if(intf.getDataSourceMinValue() == null)
+ intf.setDataSourceMinValue("");
+ sb.append("<nmwg:parameter name=\"dataSourceMinValue\">"+
intf.getDataSourceMinValue().trim()+"</nmwg:parameter>" + "\n");
+ if(intf.getDataSourceMaxValue() == null)
+ intf.setDataSourceMaxValue("");
+ sb.append("<nmwg:parameter
name=\"dataSourceMaxValue\">"+intf.getDataSourceMaxValue().trim()+"</nmwg:parameter>"
+ "\n");
+
+ sb.append("</nmwg:parameters>"+ "\n");
+ sb.append("</nmwg:key>" + "\n");
+ sb.append("</nmwg:data>"+ "\n");
+
+ return sb.toString();
+ }
+
+
+
+}
- [pS-dev] [GEANT/SA2/ps-java-services] r5819 - trunk/perfsonar-java-rrd-sql-ma/src/main/java/org/perfsona r/service/measurementArchive/rrdType/storage/persistence, svn-noreply, 07/29/2011
Archive powered by MHonArc 2.6.16.