You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ji...@apache.org on 2019/08/27 07:58:22 UTC

[incubator-iotdb] branch log_tool updated: add additional functionalities

This is an automated email from the ASF dual-hosted git repository.

jiangtian pushed a commit to branch log_tool
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git


The following commit(s) were added to refs/heads/log_tool by this push:
     new b176ded  add additional functionalities
b176ded is described below

commit b176dedc34055cbbe69d35627e42b2d82a765fe1
Author: jt <jt...@163.com>
AuthorDate: Tue Aug 27 15:48:30 2019 +0800

    add additional functionalities
---
 example/tsfile/pom.xml                             | 51 +++++++++----------
 .../apache/iotdb/db/tools/logvisual/LogFilter.java |  4 ++
 .../db/tools/logvisual/VisualizationPlan.java      | 17 ++++++-
 .../db/tools/logvisual/conf/PropertyKeys.java      |  2 +-
 .../iotdb/db/tools/logvisual/gui/PlanBox.java      | 59 +++++++++++++++++++---
 .../db/tools/logvisual/gui/PlanDetailPanel.java    | 17 +++++++
 6 files changed, 114 insertions(+), 36 deletions(-)

diff --git a/example/tsfile/pom.xml b/example/tsfile/pom.xml
index 1dab0e0..0ae2822 100644
--- a/example/tsfile/pom.xml
+++ b/example/tsfile/pom.xml
@@ -19,32 +19,31 @@
     under the License.
 
 -->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-  <modelVersion>4.0.0</modelVersion>
-  <parent>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.iotdb</groupId>
+        <artifactId>iotdb-examples</artifactId>
+        <version>0.9.0-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
     <groupId>org.apache.iotdb</groupId>
-    <artifactId>iotdb-examples</artifactId>
+    <artifactId>tsfile-example</artifactId>
     <version>0.9.0-SNAPSHOT</version>
-    <relativePath>../pom.xml</relativePath>
-  </parent>
-  <groupId>org.apache.iotdb</groupId>
-  <artifactId>tsfile-example</artifactId>
-  <version>0.9.0-SNAPSHOT</version>
-  <name>tsfile-example</name>
-  <!-- FIXME change it to the project's website -->
-  <url>http://www.example.com</url>
-  <dependencies>
-    <dependency>
-      <groupId>junit</groupId>
-      <artifactId>junit</artifactId>
-      <version>4.11</version>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.iotdb</groupId>
-      <artifactId>tsfile</artifactId>
-      <version>0.9.0-SNAPSHOT</version>
-    </dependency>
-  </dependencies>
+    <name>tsfile-example</name>
+    <!-- FIXME change it to the project's website -->
+    <url>http://www.example.com</url>
+    <dependencies>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.11</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.iotdb</groupId>
+            <artifactId>tsfile</artifactId>
+            <version>0.9.0-SNAPSHOT</version>
+        </dependency>
+    </dependencies>
 </project>
diff --git a/server/src/main/java/org/apache/iotdb/db/tools/logvisual/LogFilter.java b/server/src/main/java/org/apache/iotdb/db/tools/logvisual/LogFilter.java
index 8b2456a..662ccde 100644
--- a/server/src/main/java/org/apache/iotdb/db/tools/logvisual/LogFilter.java
+++ b/server/src/main/java/org/apache/iotdb/db/tools/logvisual/LogFilter.java
@@ -24,6 +24,10 @@ public class LogFilter {
   private Date startDate = new Date(Long.MIN_VALUE);
   private Date endDate = new Date(Long.MAX_VALUE);
 
+  public LogFilter() {
+    minLevel = LogLevel.DEBUG;
+  }
+
   public LogFilter(Properties properties) throws IOException {
     minLevel = LogLevel.valueOf(properties.getProperty(MIN_LEVEL.getPropertyName(), minLevel.name()));
 
diff --git a/server/src/main/java/org/apache/iotdb/db/tools/logvisual/VisualizationPlan.java b/server/src/main/java/org/apache/iotdb/db/tools/logvisual/VisualizationPlan.java
index de2a43c..66f6643 100644
--- a/server/src/main/java/org/apache/iotdb/db/tools/logvisual/VisualizationPlan.java
+++ b/server/src/main/java/org/apache/iotdb/db/tools/logvisual/VisualizationPlan.java
@@ -41,6 +41,10 @@ public class VisualizationPlan {
 
   private String planFilePath;
 
+  public VisualizationPlan() {
+    logFilter = new LogFilter();
+  }
+
   VisualizationPlan(String planFilePath) throws IOException {
     this.planFilePath = planFilePath;
     Properties properties = new Properties();
@@ -138,6 +142,18 @@ public class VisualizationPlan {
     this.tagPositions = tagPositions;
   }
 
+  public void setLogFilter(LogFilter logFilter) {
+    this.logFilter = logFilter;
+  }
+
+  public void setPlanFilePath(String planFilePath) {
+    this.planFilePath = planFilePath;
+  }
+
+  public String getPlanFilePath() {
+    return planFilePath;
+  }
+
   enum PlanProperties {
     NAME("name"), CONTENT_PATTERN("content_pattern"), MEASUREMENT_POSITIONS(
         "measurement_positions"),
@@ -154,7 +170,6 @@ public class VisualizationPlan {
     }
   }
 
-
   @Override
   public String toString() {
     return name;
diff --git a/server/src/main/java/org/apache/iotdb/db/tools/logvisual/conf/PropertyKeys.java b/server/src/main/java/org/apache/iotdb/db/tools/logvisual/conf/PropertyKeys.java
index 33a42ac..593f65f 100644
--- a/server/src/main/java/org/apache/iotdb/db/tools/logvisual/conf/PropertyKeys.java
+++ b/server/src/main/java/org/apache/iotdb/db/tools/logvisual/conf/PropertyKeys.java
@@ -19,7 +19,7 @@
 
 package org.apache.iotdb.db.tools.logvisual.conf;
 
-public enum  PropertyKeys {
+public enum PropertyKeys {
   DEFAULT_PARSER_FILE_PATH("parser_properties_path"), DEFAULT_LOG_FILE_PATH
       ("log_path"), DEFAULT_PLAN_PATH("plans_path");
   private String key;
diff --git a/server/src/main/java/org/apache/iotdb/db/tools/logvisual/gui/PlanBox.java b/server/src/main/java/org/apache/iotdb/db/tools/logvisual/gui/PlanBox.java
index a52399c..3e381ea 100644
--- a/server/src/main/java/org/apache/iotdb/db/tools/logvisual/gui/PlanBox.java
+++ b/server/src/main/java/org/apache/iotdb/db/tools/logvisual/gui/PlanBox.java
@@ -20,13 +20,13 @@
 package org.apache.iotdb.db.tools.logvisual.gui;
 
 import java.awt.Dimension;
-import java.awt.ScrollPane;
 import java.awt.event.ActionEvent;
 import java.io.File;
 import java.io.IOException;
 import java.util.Collection;
 import java.util.List;
 import java.util.Map;
+import java.util.regex.Pattern;
 import javax.swing.Box;
 import javax.swing.BoxLayout;
 import javax.swing.DefaultListModel;
@@ -35,7 +35,6 @@ import javax.swing.JFileChooser;
 import javax.swing.JLabel;
 import javax.swing.JList;
 import javax.swing.JOptionPane;
-import javax.swing.JPanel;
 import javax.swing.JScrollPane;
 import javax.swing.ListSelectionModel;
 import javax.swing.event.ListSelectionEvent;
@@ -51,7 +50,9 @@ public class PlanBox extends Box{
   private JLabel panelName;
   private JButton loadPlanButton;
   private JButton executePlanButton;
-  private JButton savePlanButtion;
+  private JButton savePlanButton;
+  private JButton createPlanButton;
+  private JButton deletePlanButton;
   private JScrollPane scrollPane;
   private DefaultListModel<VisualizationPlan> planListModel;
   private JList planList;
@@ -73,11 +74,15 @@ public class PlanBox extends Box{
     panelName = new JLabel("Visualization plans");
     loadPlanButton = new JButton("Load plan");
     executePlanButton = new JButton("Execute plan");
-    savePlanButtion = new JButton("Save plan");
+    savePlanButton = new JButton("Save plan");
+    createPlanButton = new JButton("Create plan");
+    deletePlanButton = new JButton("Delete plan");
     panelName.setAlignmentX(CENTER_ALIGNMENT);
     loadPlanButton.setAlignmentX(CENTER_ALIGNMENT);
     executePlanButton.setAlignmentX(CENTER_ALIGNMENT);
-    savePlanButtion.setAlignmentX(CENTER_ALIGNMENT);
+    savePlanButton.setAlignmentX(CENTER_ALIGNMENT);
+    createPlanButton.setAlignmentX(CENTER_ALIGNMENT);
+    deletePlanButton.setAlignmentX(CENTER_ALIGNMENT);
 
     planListModel = new DefaultListModel<>();
     planList = new JList<>(planListModel);
@@ -90,9 +95,13 @@ public class PlanBox extends Box{
     vBox.add(panelName);
     vBox.add(loadPlanButton);
     vBox.add(Box.createVerticalStrut(5));
-    vBox.add(executePlanButton);
+    vBox.add(savePlanButton);
+    vBox.add(Box.createVerticalStrut(5));
+    vBox.add(createPlanButton);
+    vBox.add(Box.createVerticalStrut(5));
+    vBox.add(deletePlanButton);
     vBox.add(Box.createVerticalStrut(5));
-    vBox.add(savePlanButtion);
+    vBox.add(executePlanButton);
     vBox.add(Box.createGlue());
     add(vBox);
     setAlignmentY(0.5f);
@@ -104,7 +113,9 @@ public class PlanBox extends Box{
     planList.addListSelectionListener(this::onPlanSelectionChanged);
     loadPlanButton.addActionListener(this::onLoadPlanButtonClick);
     executePlanButton.addActionListener(this::onExecutePlanButtonClick);
-    savePlanButtion.addActionListener(this::onPlanSave);
+    savePlanButton.addActionListener(this::onPlanSave);
+    createPlanButton.addActionListener(this::onCreatePlan);
+    deletePlanButton.addActionListener(this::onDeletePlan);
 
     if (defaultPlanPath != null) {
       String[] defaultPaths = defaultPlanPath.split(";");
@@ -181,6 +192,38 @@ public class PlanBox extends Box{
     planDetailPanel.updatePlan();
   }
 
+  private void onCreatePlan(ActionEvent e) {
+    JFileChooser fileChooser = new JFileChooser();
+    int status = fileChooser.showOpenDialog(this);
+    if (status == JFileChooser.APPROVE_OPTION) {
+      File chosenFile = fileChooser.getSelectedFile();
+      VisualizationPlan plan = new VisualizationPlan();
+      plan.setPlanFilePath(chosenFile.getPath());
+      plan.setName(chosenFile.getName());
+      plan.setContentPattern(Pattern.compile(".*"));
+
+      planListModel.addElement(plan);
+      planList.setSelectedIndex(planListModel.getSize() - 1);
+      planDetailPanel.setPlan(plan);
+    }
+  }
+
+  private void onDeletePlan(ActionEvent e) {
+    VisualizationPlan plan = (VisualizationPlan) planList.getSelectedValue();
+    if (plan == null) {
+      return;
+    }
+
+    int status = JOptionPane.showConfirmDialog(this, "Do you really want to delete this plan? "
+        + "(Cannot be undone)", "confirm", JOptionPane.YES_NO_OPTION);
+    if (status == JOptionPane.YES_OPTION) {
+      File file = new File(plan.getPlanFilePath());
+      file.delete();
+      planListModel.removeElement(plan);
+      planDetailPanel.setPlan(null);
+    }
+  }
+
   public interface ExecutePlanCallback {
     void call(String planName, Map<String, JFreeChart> charts, Map<String,
         List<TimeSeriesStatistics>> statisticMap);
diff --git a/server/src/main/java/org/apache/iotdb/db/tools/logvisual/gui/PlanDetailPanel.java b/server/src/main/java/org/apache/iotdb/db/tools/logvisual/gui/PlanDetailPanel.java
index 7f0c80f..f932760 100644
--- a/server/src/main/java/org/apache/iotdb/db/tools/logvisual/gui/PlanDetailPanel.java
+++ b/server/src/main/java/org/apache/iotdb/db/tools/logvisual/gui/PlanDetailPanel.java
@@ -89,12 +89,29 @@ public class PlanDetailPanel extends JScrollPane {
     updateFields();
   }
 
+  private void resetFields() {
+    nameField.setText("");
+    patternField.setText("");
+    measurementsField.setText("");
+    legendsField.setText("");
+    tagField.setText("");
+    levelField.setText("");
+    threadNameField.setText("");
+    classNameField.setText("");
+    lineNumField.setText("");
+    datePatternField.setText("");
+    startDateField.setText("");
+    endDateField.setText("");
+  }
+
   private void updateFields() {
+    resetFields();
     if (plan == null) {
       return;
     }
     nameField.setText(plan.getName());
     patternField.setText(plan.getContentPattern().pattern());
+
     if (plan.getMeasurementPositions() != null) {
       measurementsField.setText(VisualUtils.intArrayToString(plan.getMeasurementPositions()));
     }