perfsonar-dev - [GEANT/SA2/ps-java-services] r5613 - in trunk/perfsonar-java-rrd-sql-ma/src/main/java/org/perfsonar/service: . temp
Subject: perfsonar development work
List archive
[GEANT/SA2/ps-java-services] r5613 - in trunk/perfsonar-java-rrd-sql-ma/src/main/java/org/perfsonar/service: . temp
Chronological Thread
- From:
- To:
- Subject: [GEANT/SA2/ps-java-services] r5613 - in trunk/perfsonar-java-rrd-sql-ma/src/main/java/org/perfsonar/service: . temp
- Date: Wed, 5 May 2010 14:59:02 +0100
Author: psnc.pikusa
Date: 2010-05-05 14:59:02 +0100 (Wed, 05 May 2010)
New Revision: 5613
Added:
trunk/perfsonar-java-rrd-sql-ma/src/main/java/org/perfsonar/service/temp/
trunk/perfsonar-java-rrd-sql-ma/src/main/java/org/perfsonar/service/temp/ConnectionTester.java
trunk/perfsonar-java-rrd-sql-ma/src/main/java/org/perfsonar/service/temp/Data.java
trunk/perfsonar-java-rrd-sql-ma/src/main/java/org/perfsonar/service/temp/FetchData.java
trunk/perfsonar-java-rrd-sql-ma/src/main/java/org/perfsonar/service/temp/Metadata.java
Log:
all new classes added
Added:
trunk/perfsonar-java-rrd-sql-ma/src/main/java/org/perfsonar/service/temp/ConnectionTester.java
===================================================================
---
trunk/perfsonar-java-rrd-sql-ma/src/main/java/org/perfsonar/service/temp/ConnectionTester.java
(rev 0)
+++
trunk/perfsonar-java-rrd-sql-ma/src/main/java/org/perfsonar/service/temp/ConnectionTester.java
2010-05-05 13:59:02 UTC (rev 5613)
@@ -0,0 +1,97 @@
+package org.perfsonar.service.temp;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+public class ConnectionTester {
+ public Connection conn;
+ private String url, userName, password;
+
+ public ConnectionTester(){
+ url = "jdbc:mysql://localhost:3306/rrd_sql_test600";
+ userName = "root";
+ password = "@jawpcss$";
+ }
+
+ public String connect()
+ {
+ try {
+ Class.forName("com.mysql.jdbc.Driver").newInstance();
+
+ }
+ catch (InstantiationException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ return "error";
+ }
+ catch (IllegalAccessException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ 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();
+ }
+ return "ok";
+ }
+
+
+
+
+ public String getTable()
+ {
+ connect();
+ Statement statement;
+ ResultSet rs;
+ 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) {
+ // 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);
+ }
+
+}
Added:
trunk/perfsonar-java-rrd-sql-ma/src/main/java/org/perfsonar/service/temp/Data.java
===================================================================
---
trunk/perfsonar-java-rrd-sql-ma/src/main/java/org/perfsonar/service/temp/Data.java
(rev 0)
+++
trunk/perfsonar-java-rrd-sql-ma/src/main/java/org/perfsonar/service/temp/Data.java
2010-05-05 13:59:02 UTC (rev 5613)
@@ -0,0 +1,15 @@
+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 = "";
+}
Added:
trunk/perfsonar-java-rrd-sql-ma/src/main/java/org/perfsonar/service/temp/FetchData.java
===================================================================
---
trunk/perfsonar-java-rrd-sql-ma/src/main/java/org/perfsonar/service/temp/FetchData.java
(rev 0)
+++
trunk/perfsonar-java-rrd-sql-ma/src/main/java/org/perfsonar/service/temp/FetchData.java
2010-05-05 13:59:02 UTC (rev 5613)
@@ -0,0 +1,189 @@
+package org.perfsonar.service.temp;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+public class FetchData {
+
+ ConnectionTester ct = new ConnectionTester();
+ String resultXML = ""; // tutaj bedziemy budowac wynikowy xml message
+ 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 Connection conn;
+
+ public FetchData() {
+ ct.connect();
+ conn = ct.conn;
+
+ }
+
+ 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";
+ StringBuffer sb = new StringBuffer();
+ sb.append(MetadataContent);
+ String metadataS = "";
+ String dataS = "";
+
+ try {
+ statement = conn.createStatement();
+
+ //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) {
+
+ System.err.println(e.toString());
+ }
+
+
+ }
+
+ public void fetchMetadataRows() {
+ ResultSet rs;
+
+ try {
+ statement = conn.createStatement();
+ conn.createStatement();
+ rs = statement.executeQuery("SELECT * FROM metadata");
+
+ while (!rs.isLast()) {
+ rs.next();
+ metadataList.add(fetchMetadataRow(rs));
+ }
+
+ // conn.close();
+ } catch (SQLException e) {
+
+ System.err.println(e.toString());
+ }
+
+ }
+
+ public Metadata fetchMetadataRow(ResultSet rs) {
+ Metadata m = new Metadata();
+
+ 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");
+
+ // 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 ="";
+ StringBuffer sb = new StringBuffer();
+ try {
+ sb.append( "<nmwg:data
xmlns:nmwg=\"http://ggf.org/ns/nmwg/base/2.0/\" id=\"" +
rs.getString("data_id") + "\" metadataIdRef=\"" +
rs.getString("metadataIdRef") +"\">" + "\n");
+ sb.append("<nmwg:key>" + "\n");
+ sb.append("<nmwg:parameters>"+ "\n");
+ sb.append("<nmwg:parameter
name=\"file\">"+rs.getString("p_file") + "</nmwg:parameter>" + "\n");
+ sb.append("<nmwg:parameter
name=\"dataSource\">"+rs.getString("p_dataSource")+"</nmwg:parameter>"+ "\n");
+ sb.append("<nmwg:parameter
name=\"valueUnits\">"+rs.getString("p_valueUnits")+"</nmwg:parameter>" +
"\n");
+ sb.append("<nmwg:parameter
name=\"eventType\">"+rs.getString("p_eventType")+"</nmwg:parameter>"+ "\n");
+ sb.append("<nmwg:parameter
name=\"dataSourceStep\">"+rs.getString("p_dataSourceStep")+"</nmwg:parameter>"+
"\n");
+ sb.append("<nmwg:parameter
name=\"dataSourceType\">"+rs.getString("p_dataSourceType")+"</nmwg:parameter>"
+ "\n");
+ sb.append("<nmwg:parameter
name=\"dataSourceMinValue\">"+rs.getString("p_dataSourceMinValue")+"</nmwg:parameter>"
+ "\n");
+ sb.append("<nmwg:parameter
name=\"dataSourceMaxValue\">"+rs.getString("p_dataSourceMaxValue")+"</nmwg:parameter>"
+ "\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();
+ }
+
+
+}
Added:
trunk/perfsonar-java-rrd-sql-ma/src/main/java/org/perfsonar/service/temp/Metadata.java
===================================================================
---
trunk/perfsonar-java-rrd-sql-ma/src/main/java/org/perfsonar/service/temp/Metadata.java
(rev 0)
+++
trunk/perfsonar-java-rrd-sql-ma/src/main/java/org/perfsonar/service/temp/Metadata.java
2010-05-05 13:59:02 UTC (rev 5613)
@@ -0,0 +1,13 @@
+package org.perfsonar.service.temp;
+
+public class Metadata {
+
+ String metaId ="";
+ String subjId = "";
+ String hostName ="";
+ String ifAddress ="";
+ String ifDescription ="";
+ String direction ="";
+ String capacity ="";
+
+}
- [GEANT/SA2/ps-java-services] r5613 - in trunk/perfsonar-java-rrd-sql-ma/src/main/java/org/perfsonar/service: . temp, svn-noreply, 05/05/2010
Archive powered by MHonArc 2.6.16.