Skip to Content.
Sympa Menu

perfsonar-dev - perfsonar: r2809 - in branches/perfsonarui/src/org/perfsonar/perfsonarui: flowsa flowsa/panels test test/flowsa

Subject: perfsonar development work

List archive

perfsonar: r2809 - in branches/perfsonarui/src/org/perfsonar/perfsonarui: flowsa flowsa/panels test test/flowsa


Chronological Thread 
  • From:
  • To:
  • Subject: perfsonar: r2809 - in branches/perfsonarui/src/org/perfsonar/perfsonarui: flowsa flowsa/panels test test/flowsa
  • Date: Wed, 12 Sep 2007 04:44:47 -0400

Author: michael.bischoff
Date: 2007-09-12 04:44:47 -0400 (Wed, 12 Sep 2007)
New Revision: 2809

Added:
branches/perfsonarui/src/org/perfsonar/perfsonarui/test/flowsa/

branches/perfsonarui/src/org/perfsonar/perfsonarui/test/flowsa/RequestTest.java
Modified:
branches/perfsonarui/src/org/perfsonar/perfsonarui/flowsa/FlowSAModel.java

branches/perfsonarui/src/org/perfsonar/perfsonarui/flowsa/FlowSARequest.java

branches/perfsonarui/src/org/perfsonar/perfsonarui/flowsa/FlowSAUserData.java

branches/perfsonarui/src/org/perfsonar/perfsonarui/flowsa/panels/MomentOptionsPanel.java

branches/perfsonarui/src/org/perfsonar/perfsonarui/flowsa/panels/QueryResultPanel.java

branches/perfsonarui/src/org/perfsonar/perfsonarui/flowsa/panels/RouterOptionsPanel.java
Log:


Modified:
branches/perfsonarui/src/org/perfsonar/perfsonarui/flowsa/FlowSAModel.java
===================================================================
---
branches/perfsonarui/src/org/perfsonar/perfsonarui/flowsa/FlowSAModel.java
2007-09-12 08:19:26 UTC (rev 2808)
+++
branches/perfsonarui/src/org/perfsonar/perfsonarui/flowsa/FlowSAModel.java
2007-09-12 08:44:47 UTC (rev 2809)
@@ -42,6 +42,7 @@
public class FlowSAModel extends PerfsonarModel {

private static final PerfsonarSchema PERFSONAR_SCHEMA = new
PerfsonarSchema("flowsa");
+
private final MainOptionsPanel mainOptionsPanel = new
MainOptionsPanel();
private final MomentOptionsPanel momentOptionsPanel = new
MomentOptionsPanel();
private final RouterOptionsPanel routerOptionsPanel = new
RouterOptionsPanel();
@@ -57,7 +58,7 @@
}

/**
- * Constructor initialises this tab with the first avail endpoint.
+ * Constructor initializes this tab with the first avail endpoint.
* @see PerfsonarModel#PerfsonarModel(MAEndpointList)
* @param endpoints
*/
@@ -151,9 +152,9 @@
@Override
public PSUIAction createOptionsAction() {
return new SetOptionsAction(this) {
-
private static final long serialVersionUID = 1L;

+ @SuppressWarnings("synthetic-access")
@Override
protected void confirm(JComponent[] optionPanels) {

getUserData().setQuery(FlowSAUserData.QUERYTYPE,
mainOptionsPanel.getQueryType());
@@ -220,7 +221,7 @@
*/
@Override
public List<IPerfsonarSchema> getSupportedRequests() {
- ArrayList<IPerfsonarSchema> supported = new
ArrayList<IPerfsonarSchema>();
+ List<IPerfsonarSchema> supported = new
ArrayList<IPerfsonarSchema>();
supported.add(PERFSONAR_SCHEMA);
return supported;
}

Modified:
branches/perfsonarui/src/org/perfsonar/perfsonarui/flowsa/FlowSARequest.java
===================================================================
---
branches/perfsonarui/src/org/perfsonar/perfsonarui/flowsa/FlowSARequest.java
2007-09-12 08:19:26 UTC (rev 2808)
+++
branches/perfsonarui/src/org/perfsonar/perfsonarui/flowsa/FlowSARequest.java
2007-09-12 08:44:47 UTC (rev 2809)
@@ -9,13 +9,16 @@

import java.io.IOException;
import java.io.InputStream;
-import java.io.StringWriter;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.perfsonar.perfsonarui.AbstractMARequest;
+import org.perfsonar.perfsonarui.flowsa.FlowSAUserData.QueryType;
import org.perfsonar.perfsonarui.plugins.IPerfsonarResponse;
import org.perfsonar.perfsonarui.plugins.IUserData;
import org.perfsonar.perfsonarui.plugins.MAEndpoint;
@@ -26,38 +29,14 @@
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

-import com.sun.org.apache.xml.internal.serialize.OutputFormat;
-import com.sun.org.apache.xml.internal.serialize.XMLSerializer;
-
/**
* @author gijs
*
*/
public class FlowSARequest extends AbstractMARequest {

- /**
- * Generate a request and print it. For debugging purpose only.
- */
- public static void main(String[] args) {
-
- FlowSARequest request = new FlowSARequest();
-
- FlowSAUserData fakeUserData = new FlowSAUserData();
- fakeUserData.setQuery(FlowSAUserData.ROUTERS, "test arthur");
- fakeUserData.setQuery(FlowSAUserData.RAWAGGREGATION,
"aggregation rule");
- fakeUserData.setQuery(FlowSAUserData.RAWFILTER, "filter
rule");
- fakeUserData.setQuery(FlowSAUserData.RAWFIELDS,
"AddressFamily TimeFirstSeen MsecFirstSeen");
- fakeUserData.setQuery(FlowSAUserData.QUERYTYPE, "Raw");
-
- try {
- Document requestDocument =
request.createRequest(fakeUserData, "SetupDataRequest");
- request.logRequest(requestDocument);
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- }
-
+ private static final String ISO8601_PATTERN =
"yyyy-MM-dd'T'HH:mm:ssZ";
+
public FlowSARequest() {
super();
}
@@ -74,20 +53,23 @@
*/
@Override
public Document createRequest(IUserData data, String messageType)
throws Exception {
- String type = data.getQuery(FlowSAUserData.QUERYTYPE);
+ String typeString = data.getQuery(FlowSAUserData.QUERYTYPE);

- if (type.equals("Raw")) {
- logger.debug("Creating raw request.");
- return createRawRequest(data);
- } else if (type.equals("Top")) {
- logger.debug("Creating top request.");
- return createTopRequest(data);
- } else if (type.equals("Statistical")) {
- logger.debug("Creating statistics request.");
- return createStatRequest(data);
- } else {
- logger.error("Querytype not supported: " + type +
".");
- return null;
+ QueryType type = QueryType.get(typeString);
+
+ switch (type) {
+ case RAW:
+ logger.debug("Creating raw request.");
+ return createRawRequest(data);
+ case TOP:
+ logger.debug("Creating top request.");
+ return createTopRequest(data);
+ case STATISTICAL:
+ logger.debug("Creating statistics request.");
+ return createStatRequest(data);
+ default:
+ logger.error("Querytype not supported: " +
type + ".");
+ return null;
}
}

@@ -96,39 +78,19 @@
* @return
* @throws Exception
*/
- protected Document createRawRequest(IUserData data) throws Exception {
+ protected Document createRawRequest(IUserData data) {
String inputFile =
"org/perfsonar/perfsonarui/flowsa/requestTemplates/raw.xml";
Document request = parseXmlFile(inputFile);

replaceGenericParameters(request, data);
+ replaceFilterAndAggregationRule(request, data);
+ addParameters(request, data);

- // replace filter rule & aggregationRule rule
- NodeList paraNodes =
request.getElementsByTagName("nmwg:parameter");
- for (int j = 0; j < paraNodes.getLength(); j++) {
- Element paraNode = (Element) paraNodes.item(j);
- String nameAttr = paraNode.getAttribute("name");
- if (nameAttr.equals("aggregationRule")) {
-
paraNode.getFirstChild().setTextContent(data.getQuery(FlowSAUserData.RAWAGGREGATION));
- } else if (nameAttr.equals("filterRule")) {
-
paraNode.getFirstChild().setTextContent(data.getQuery(FlowSAUserData.RAWFILTER));
- }
- }
-
- // add fields parameters
- Node parameters =
request.getElementsByTagName("flow:parameters").item(0);
- for (String field :
data.getQuery(FlowSAUserData.RAWFIELDS).split(" ")) {
- Element fieldNode =
request.createElementNS("http://ggf.org/ns/nmwg/base/2.0/";, "parameter");
- fieldNode.setAttribute("name", "showField" + field);
- parameters.appendChild(fieldNode);
- }
-
request.normalize();
- logRequest(request);
-
return request;
}

- protected Document createStatRequest(IUserData data) throws
ParserConfigurationException, SAXException, IOException {
+ protected Document createStatRequest(IUserData data) {
String inputFile =
"org/perfsonar/perfsonarui/flowsa/requestTemplates/stat.xml";
Document request = parseXmlFile(inputFile);
replaceGenericParameters(request, data);
@@ -138,11 +100,8 @@
/**
* @param data
* @return
- * @throws ParserConfigurationException
- * @throws SAXException
- * @throws IOException
*/
- protected Document createTopRequest(IUserData data) throws
ParserConfigurationException, SAXException, IOException {
+ protected Document createTopRequest(IUserData data) {
String inputFile =
"org/perfsonar/perfsonarui/flowsa/requestTemplates/top.xml";

Document request = parseXmlFile(inputFile);
@@ -198,27 +157,6 @@
return null;
}

- /**
- * Logs a request / document
- * @param request the request to be logged
- */
- public void logRequest(Document request) {
- // serialize for debugging
- StringWriter sw = new StringWriter();
- OutputFormat format = new OutputFormat(request);
- format.setLineWidth(65);
- format.setIndenting(true);
- format.setIndent(2);
-
- XMLSerializer output = new XMLSerializer(sw, format);
- try {
- output.serialize(request);
- } catch (IOException e) {
- e.printStackTrace();
- }
- logger.debug(sw.getBuffer());
- }
-
/* (non-Javadoc)
* @see
org.perfsonar.perfsonarui.plugins.IPerfsonarRequest#process(org.perfsonar.perfsonarui.plugins.IUserData,
org.w3c.dom.Document, org.perfsonar.perfsonarui.plugins.IPerfsonarResponse)
*/
@@ -226,26 +164,34 @@
logger.debug(response);
}

- /**
- * @param request
- * @param data
- */
- private void replaceGenericParameters(Document request, IUserData
data) {
- // change start moment, end moment
+ private void replaceFilterAndAggregationRule(Document request,
+ IUserData data) {
NodeList paraNodes =
request.getElementsByTagName("nmwg:parameter");
for (int j = 0; j < paraNodes.getLength(); j++) {
Element paraNode = (Element) paraNodes.item(j);
String nameAttr = paraNode.getAttribute("name");
- if (nameAttr.equals("startTime")) {
- Element startNode = (Element)
paraNode.getElementsByTagName("nmtm:time").item(0);
- startNode.setAttribute("value",
data.getStartTime());
- } else if (nameAttr.equals("endTime")) {
- Element endNode = (Element)
paraNode.getElementsByTagName("nmtm:time").item(0);
- endNode.setAttribute("value",
data.getEndTime());
-
+ if (nameAttr.equals("aggregationRule")) {
+
paraNode.getFirstChild().setTextContent(data.getQuery(FlowSAUserData.RAWAGGREGATION));
+ } else if (nameAttr.equals("filterRule")) {
+
paraNode.getFirstChild().setTextContent(data.getQuery(FlowSAUserData.RAWFILTER));
}
}
+ }

+ /**
+ * @param request
+ * @param data
+ */
+ private void replaceGenericParameters(Document request, IUserData
data) {
+ try {
+ replaceSubjectTimeRange(request, data);
+ } catch (ParseException e) {
+ logger.fatal("internal error can't parse UNIXtime");
+ }
+ replaceRouters(request, data);
+ }
+
+ private void replaceRouters(Document request, IUserData data) {
Node network =
request.getElementsByTagName("nmwgtopo3:network").item(0);
// remove example routers
while (network.getChildNodes().getLength() > 0) {
@@ -266,6 +212,33 @@
}
}

+ private void replaceSubjectTimeRange(Document request, IUserData data)
+ throws ParseException {
+ NodeList paraNodes =
request.getElementsByTagName("nmwg:parameter");
+ for (int j = 0; j < paraNodes.getLength(); j++) {
+ Element paraNode = (Element) paraNodes.item(j);
+ String nameAttr = paraNode.getAttribute("name");
+ DateFormat UNIXtime = new
SimpleDateFormat("sssssssssssssssssss");
+ DateFormat ISO8601 = new
SimpleDateFormat(ISO8601_PATTERN);
+ if (nameAttr.equals("startTime")) {
+ Element startNode = (Element)
paraNode.getElementsByTagName("nmtm:time").item(0);
+ startNode.setAttribute("value",
ISO8601.format(UNIXtime.parse(data.getStartTime())));
+ } else if (nameAttr.equals("endTime")) {
+ Element endNode = (Element)
paraNode.getElementsByTagName("nmtm:time").item(0);
+ endNode.setAttribute("value",
ISO8601.format(UNIXtime.parse(data.getEndTime())));
+ }
+ }
+ }
+
+ private void addParameters(Document request, IUserData data) {
+ Node parameters =
request.getElementsByTagName("flow:parameters").item(0);
+ for (String field :
data.getQuery(FlowSAUserData.RAWFIELDS).split(" ")) {
+ Element fieldNode =
request.createElementNS("http://ggf.org/ns/nmwg/base/2.0/";, "parameter");
+ fieldNode.setAttribute("name", "showField" + field);
+ parameters.appendChild(fieldNode);
+ }
+ }
+
/**
* Converts a String into a document.
* @param inputFile
@@ -280,11 +253,11 @@
DocumentBuilder builder =
factory.newDocumentBuilder();
return builder.parse(stream);
} catch (SAXException e) {
- e.printStackTrace();
+ logger.error("cannot parse template", e);
} catch (IOException e) {
- e.printStackTrace();
+ logger.error("cannot parse template", e);
} catch (ParserConfigurationException e) {
- e.printStackTrace();
+ logger.error("cannot parse template", e);
}
return null;
}

Modified:
branches/perfsonarui/src/org/perfsonar/perfsonarui/flowsa/FlowSAUserData.java
===================================================================
---
branches/perfsonarui/src/org/perfsonar/perfsonarui/flowsa/FlowSAUserData.java
2007-09-12 08:19:26 UTC (rev 2808)
+++
branches/perfsonarui/src/org/perfsonar/perfsonarui/flowsa/FlowSAUserData.java
2007-09-12 08:44:47 UTC (rev 2809)
@@ -7,6 +7,8 @@

package org.perfsonar.perfsonarui.flowsa;

+import static java.util.Calendar.SECOND;
+
import java.util.Calendar;

import org.perfsonar.perfsonarui.AbstractUserData;
@@ -33,17 +35,46 @@
public final static String TOPFILTER = "Top Filter rule";
public final static String TOPAGGREGATION = "Top Aggregation rule";

+ public enum QueryType {
+ RAW("Raw"),
+ STATISTICAL("Statistical"),
+ TOP("Top");
+
+ private String stringValue;
+
+ QueryType(String stringValue) {
+ this.stringValue = stringValue;
+ }
+
+ @Override
+ public String toString() {
+ return stringValue;
+ }
+
+ public static QueryType get(String value) {
+ for(QueryType type : values()) {
+ if(type.stringValue.equals(value)) {
+ return type;
+ }
+ }
+ return null;
+ }
+ }
+
/**
- * Default no arg constructor
+ * Default no-arg constructor
*/
public FlowSAUserData() {
super();
+ setDefaults();
+ }

- // default settings
+ protected void setDefaults() {
setQuery(FlowSAUserData.QUERYTYPE, "Raw");
- long now = Calendar.getInstance().getTimeInMillis() / 1000;
- setQuery(FlowSAUserData.STARTMOMENT, String.valueOf(now -
60));
- setQuery(FlowSAUserData.ENDMOMENT, String.valueOf(now));
+ Calendar now = Calendar.getInstance();
+ setQuery(FlowSAUserData.ENDMOMENT,
String.valueOf(now.getTime().getTime()));
+ now.roll(SECOND, -60);
+ setQuery(FlowSAUserData.STARTMOMENT,
String.valueOf(now.getTime().getTime()));
}

}

Modified:
branches/perfsonarui/src/org/perfsonar/perfsonarui/flowsa/panels/MomentOptionsPanel.java
===================================================================
---
branches/perfsonarui/src/org/perfsonar/perfsonarui/flowsa/panels/MomentOptionsPanel.java
2007-09-12 08:19:26 UTC (rev 2808)
+++
branches/perfsonarui/src/org/perfsonar/perfsonarui/flowsa/panels/MomentOptionsPanel.java
2007-09-12 08:44:47 UTC (rev 2809)
@@ -7,6 +7,8 @@

package org.perfsonar.perfsonarui.flowsa.panels;

+import static java.util.Calendar.SECOND;
+
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Calendar;
@@ -47,12 +49,16 @@

private static int[] histories = { 1, 2, 5, 10, 30, 60, 120 };

- private String startMoment = String.valueOf(getNow() - 60);
- private String endMoment = String.valueOf(getNow());
+ private String startMoment;
+ private String endMoment;

public MomentOptionsPanel() {
addWidgets();
updateMoments();
+ Calendar now = Calendar.getInstance();
+ endMoment = String.valueOf(now.getTime().getTime());
+ now.roll(SECOND, -60);
+ startMoment = String.valueOf(now.getTime().getTime());
}

@Override
@@ -61,7 +67,7 @@
}

public String getStartMoment() {
- return this.startMoment;
+ return startMoment;
}

private void updateMoments() {
@@ -79,11 +85,10 @@

public void actionPerformed(ActionEvent e) {
int history = presetSelectComboBox.getSelectedIndex();
- long diff = histories[history] * 60;
+ long diff = histories[history] * 600000;
this.startMoment = String.valueOf(getNow() - diff);
this.endMoment = String.valueOf(getNow());
this.updateMoments();
-
}

private void addWidgets() {
@@ -312,8 +317,6 @@

org.jdesktop.layout.GroupLayout layout = new
org.jdesktop.layout.GroupLayout(this);
this.setLayout(layout);
- //
this.setBorder(javax.swing.BorderFactory.createTitledBorder("Start
- // moment"));

layout.setHorizontalGroup(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(

layout.createSequentialGroup().add(StartMomentPanel,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,

org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)

Modified:
branches/perfsonarui/src/org/perfsonar/perfsonarui/flowsa/panels/QueryResultPanel.java
===================================================================
---
branches/perfsonarui/src/org/perfsonar/perfsonarui/flowsa/panels/QueryResultPanel.java
2007-09-12 08:19:26 UTC (rev 2808)
+++
branches/perfsonarui/src/org/perfsonar/perfsonarui/flowsa/panels/QueryResultPanel.java
2007-09-12 08:44:47 UTC (rev 2809)
@@ -12,33 +12,27 @@
public class QueryResultPanel extends PluginMainPanel implements Observer {

private static final long serialVersionUID = 1L;
-
- public QueryResultPanel(Component parentFrame, IPerfsonarTab model,
- org.perfsonar.perfsonarui.flowsa.FlowSAUserData
userData) {
- super(parentFrame, model);
-
+ protected final CardLayout myLayout = new CardLayout();
+ protected final FlowSAUserData userData;
+
+ public QueryResultPanel(Component parentFrame, IPerfsonarTab model,
FlowSAUserData userData) {
+ super(parentFrame, model, null);
+ setLayout(myLayout);
+ this.userData = userData;
userData.addObserver(this);
+ myLayout.show(this, "Raw");
}

@Override
- protected void addWidgets() {
- RawPanel rawPanel = new RawPanel(parentFrame, model);
- StatPanel statPanel = new StatPanel(parentFrame, model);
- TopPanel topPanel = new TopPanel(parentFrame, model);
- CardLayout cardLayout = new CardLayout();
-
- this.setLayout(cardLayout);
- this.add(rawPanel, "Raw");
- this.add(statPanel, "Statistical");
- this.add(topPanel, "Top");
- cardLayout.show(this, "Raw");
-
+ protected void addWidgets() {
+ this.add(new RawPanel(parentFrame, model), "Raw");
+ this.add(new StatPanel(parentFrame, model), "Statistical");
+ this.add(new TopPanel(parentFrame, model), "Top");
}

public void update(Observable o, Object arg) {
- // cardLayout.show(this, "top");
- String qt = ((FlowSAUserData)
o).getQuery(FlowSAUserData.QUERYTYPE);
- ((CardLayout) this.getLayout()).show(this, qt);
+ String queryType =
userData.getQuery(FlowSAUserData.QUERYTYPE);
+ myLayout.show(this, queryType);
}

}

Modified:
branches/perfsonarui/src/org/perfsonar/perfsonarui/flowsa/panels/RouterOptionsPanel.java
===================================================================
---
branches/perfsonarui/src/org/perfsonar/perfsonarui/flowsa/panels/RouterOptionsPanel.java
2007-09-12 08:19:26 UTC (rev 2808)
+++
branches/perfsonarui/src/org/perfsonar/perfsonarui/flowsa/panels/RouterOptionsPanel.java
2007-09-12 08:44:47 UTC (rev 2809)
@@ -22,7 +22,7 @@

routerList.setModel(new javax.swing.AbstractListModel() {
private static final long serialVersionUID = 1L;
- String[] strings = { "test","Arthur", "Zaphod",
"Ford", "Trillian" };
+ String[] strings = {
"xsr01.asd001a.surf.net","Arthur", "Zaphod", "Ford", "Trillian" };

public Object getElementAt(int i) {
return strings[i];

Added:
branches/perfsonarui/src/org/perfsonar/perfsonarui/test/flowsa/RequestTest.java



  • perfsonar: r2809 - in branches/perfsonarui/src/org/perfsonar/perfsonarui: flowsa flowsa/panels test test/flowsa, svnlog, 09/12/2007

Archive powered by MHonArc 2.6.16.

Top of Page