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

jackietien pushed a commit to branch TriggerTest
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/TriggerTest by this push:
     new 5b686eaed6 fix some bugs
5b686eaed6 is described below

commit 5b686eaed6732dd76ade55633fa949ff99a90c0b
Author: JackieTien97 <[email protected]>
AuthorDate: Mon Sep 26 15:55:11 2022 +0800

    fix some bugs
---
 .../iotdb/confignode/conf/ConfigNodeConfig.java    |   1 +
 .../confignode/conf/ConfigNodeDescriptor.java      |   2 +
 .../iotdb/confignode/persistence/TriggerInfo.java  |   6 +
 .../confignode1conf/iotdb-confignode.properties    |   5 +-
 example/trigger/pom.xml                            |   2 +-
 .../org/apache/iotdb/trigger/AlertingExample.java  | 108 ---------------
 .../org/apache/iotdb/trigger/SimpleTrigger.java    |  38 ++++++
 .../org/apache/iotdb/trigger/TriggerExample.java   | 147 ---------------------
 .../datanode1conf/iotdb-datanode.properties        |   3 +-
 9 files changed, 53 insertions(+), 259 deletions(-)

diff --git 
a/confignode/src/main/java/org/apache/iotdb/confignode/conf/ConfigNodeConfig.java
 
b/confignode/src/main/java/org/apache/iotdb/confignode/conf/ConfigNodeConfig.java
index 25b51266a3..6fc1526b27 100644
--- 
a/confignode/src/main/java/org/apache/iotdb/confignode/conf/ConfigNodeConfig.java
+++ 
b/confignode/src/main/java/org/apache/iotdb/confignode/conf/ConfigNodeConfig.java
@@ -173,6 +173,7 @@ public class ConfigNodeConfig {
     extLibDir = addHomeDir(extLibDir);
     udfLibDir = addHomeDir(udfLibDir);
     temporaryLibDir = addHomeDir(temporaryLibDir);
+    triggerLibDir = addHomeDir(triggerLibDir);
   }
 
   private String addHomeDir(String dir) {
diff --git 
a/confignode/src/main/java/org/apache/iotdb/confignode/conf/ConfigNodeDescriptor.java
 
b/confignode/src/main/java/org/apache/iotdb/confignode/conf/ConfigNodeDescriptor.java
index c4e81b121f..8ea4df2c49 100644
--- 
a/confignode/src/main/java/org/apache/iotdb/confignode/conf/ConfigNodeDescriptor.java
+++ 
b/confignode/src/main/java/org/apache/iotdb/confignode/conf/ConfigNodeDescriptor.java
@@ -202,6 +202,8 @@ public class ConfigNodeDescriptor {
       conf.setTemporaryLibDir(
           properties.getProperty("temporary_lib_dir", 
conf.getTemporaryLibDir()));
 
+      conf.setTriggerLibDir(properties.getProperty("trigger_lib_dir", 
conf.getTriggerLibDir()));
+
       conf.setTimePartitionInterval(
           Long.parseLong(
               properties.getProperty(
diff --git 
a/confignode/src/main/java/org/apache/iotdb/confignode/persistence/TriggerInfo.java
 
b/confignode/src/main/java/org/apache/iotdb/confignode/persistence/TriggerInfo.java
index 449ef63997..e30364410d 100644
--- 
a/confignode/src/main/java/org/apache/iotdb/confignode/persistence/TriggerInfo.java
+++ 
b/confignode/src/main/java/org/apache/iotdb/confignode/persistence/TriggerInfo.java
@@ -20,6 +20,7 @@
 package org.apache.iotdb.confignode.persistence;
 
 import org.apache.iotdb.common.rpc.thrift.TSStatus;
+import org.apache.iotdb.commons.exception.StartupException;
 import org.apache.iotdb.commons.snapshot.SnapshotProcessor;
 import org.apache.iotdb.commons.trigger.TriggerInformation;
 import org.apache.iotdb.commons.trigger.TriggerTable;
@@ -64,6 +65,11 @@ public class TriggerInfo implements SnapshotProcessor {
     triggerExecutableManager =
         TriggerExecutableManager.setupAndGetInstance(
             CONFIG_NODE_CONF.getTemporaryLibDir(), 
CONFIG_NODE_CONF.getTriggerLibDir());
+    try {
+      triggerExecutableManager.start();
+    } catch (StartupException e) {
+      throw new RuntimeException(e);
+    }
   }
 
   public void acquireTriggerTableLock() {
diff --git 
a/confignode/src/test/resources/confignode1conf/iotdb-confignode.properties 
b/confignode/src/test/resources/confignode1conf/iotdb-confignode.properties
index 888d0a6ec1..00cf4f6792 100644
--- a/confignode/src/test/resources/confignode1conf/iotdb-confignode.properties
+++ b/confignode/src/test/resources/confignode1conf/iotdb-confignode.properties
@@ -24,9 +24,10 @@ consensus_port=22278
 target_config_nodes=127.0.0.1:22277
 
data_region_consensus_protocol_class=org.apache.iotdb.consensus.multileader.MultiLeaderConsensus
 
schema_region_consensus_protocol_class=org.apache.iotdb.consensus.ratis.RatisConsensus
-schema_replication_factor=3
-data_replication_factor=3
+schema_replication_factor=1
+data_replication_factor=1
 system_dir=target/confignode1/system
 data_dirs=target/confignode1/data
 consensus_dir=target/confignode1/consensus
+trigger_lib_dir=target/confignode1/ext/trigger
 proc_wal_dir=target/confignode1/proc
\ No newline at end of file
diff --git a/example/trigger/pom.xml b/example/trigger/pom.xml
index d4c96f98da..8cbd3b5559 100644
--- a/example/trigger/pom.xml
+++ b/example/trigger/pom.xml
@@ -31,7 +31,7 @@
     <dependencies>
         <dependency>
             <groupId>org.apache.iotdb</groupId>
-            <artifactId>iotdb-server</artifactId>
+            <artifactId>trigger-api</artifactId>
             <version>0.14.0-SNAPSHOT</version>
             <scope>provided</scope>
         </dependency>
diff --git 
a/example/trigger/src/main/java/org/apache/iotdb/trigger/AlertingExample.java 
b/example/trigger/src/main/java/org/apache/iotdb/trigger/AlertingExample.java
deleted file mode 100644
index c9bb2b663d..0000000000
--- 
a/example/trigger/src/main/java/org/apache/iotdb/trigger/AlertingExample.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.iotdb.trigger;
-
-import org.apache.iotdb.commons.path.PartialPath;
-import org.apache.iotdb.db.engine.trigger.api.Trigger;
-import 
org.apache.iotdb.db.engine.trigger.sink.alertmanager.AlertManagerConfiguration;
-import org.apache.iotdb.db.engine.trigger.sink.alertmanager.AlertManagerEvent;
-import 
org.apache.iotdb.db.engine.trigger.sink.alertmanager.AlertManagerHandler;
-import org.apache.iotdb.trigger.api.TriggerAttributes;
-
-import java.io.IOException;
-import java.util.HashMap;
-
-public class AlertingExample implements Trigger {
-
-  private final AlertManagerHandler alertManagerHandler = new 
AlertManagerHandler();
-
-  private final AlertManagerConfiguration alertManagerConfiguration =
-      new AlertManagerConfiguration("http://127.0.0.1:9093/api/v2/alerts";);
-
-  private String alertname;
-
-  private final HashMap<String, String> labels = new HashMap<>();
-
-  private final HashMap<String, String> annotations = new HashMap<>();
-
-  @Override
-  public void onCreate(TriggerAttributes attributes) throws Exception {
-    alertManagerHandler.open(alertManagerConfiguration);
-
-    alertname = "alert_test";
-
-    labels.put("series", "root.ln.wf01.wt01.temperature");
-    labels.put("value", "");
-    labels.put("severity", "");
-
-    annotations.put("summary", "high temperature");
-    annotations.put("description", "{{.alertname}}: {{.series}} is 
{{.value}}");
-  }
-
-  @Override
-  public void onDrop() throws IOException {
-    alertManagerHandler.close();
-  }
-
-  @Override
-  public void onStart() {
-    alertManagerHandler.open(alertManagerConfiguration);
-  }
-
-  @Override
-  public void onStop() throws Exception {
-    alertManagerHandler.close();
-  }
-
-  @Override
-  public Double fire(long timestamp, Double value, PartialPath path) throws 
Exception {
-    if (value > 100.0) {
-      labels.put("value", String.valueOf(value));
-      labels.put("severity", "critical");
-      AlertManagerEvent alertManagerEvent = new AlertManagerEvent(alertname, 
labels, annotations);
-      alertManagerHandler.onEvent(alertManagerEvent);
-    } else if (value > 50.0) {
-      labels.put("value", String.valueOf(value));
-      labels.put("severity", "warning");
-      AlertManagerEvent alertManagerEvent = new AlertManagerEvent(alertname, 
labels, annotations);
-      alertManagerHandler.onEvent(alertManagerEvent);
-    }
-
-    return value;
-  }
-
-  @Override
-  public double[] fire(long[] timestamps, double[] values, PartialPath path) 
throws Exception {
-    for (double value : values) {
-      if (value > 100.0) {
-        labels.put("value", String.valueOf(value));
-        labels.put("severity", "critical");
-        AlertManagerEvent alertManagerEvent = new AlertManagerEvent(alertname, 
labels, annotations);
-        alertManagerHandler.onEvent(alertManagerEvent);
-      } else if (value > 50.0) {
-        labels.put("value", String.valueOf(value));
-        labels.put("severity", "warning");
-        AlertManagerEvent alertManagerEvent = new AlertManagerEvent(alertname, 
labels, annotations);
-        alertManagerHandler.onEvent(alertManagerEvent);
-      }
-    }
-    return values;
-  }
-}
diff --git 
a/example/trigger/src/main/java/org/apache/iotdb/trigger/SimpleTrigger.java 
b/example/trigger/src/main/java/org/apache/iotdb/trigger/SimpleTrigger.java
new file mode 100644
index 0000000000..a3c797d41e
--- /dev/null
+++ b/example/trigger/src/main/java/org/apache/iotdb/trigger/SimpleTrigger.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iotdb.trigger;
+
+import org.apache.iotdb.trigger.api.Trigger;
+import org.apache.iotdb.tsfile.write.record.Tablet;
+
+import java.util.Arrays;
+
+public class SimpleTrigger implements Trigger {
+
+  @Override
+  public boolean fire(Tablet tablet) {
+    System.out.println("receive a tablet, device name is " + tablet.deviceId);
+    System.out.println("measurements are: ");
+    tablet
+        .getSchemas()
+        .forEach(measurementSchema -> 
System.out.println(measurementSchema.getMeasurementId()));
+    System.out.println("time are: " + Arrays.toString(tablet.timestamps));
+    return true;
+  }
+}
diff --git 
a/example/trigger/src/main/java/org/apache/iotdb/trigger/TriggerExample.java 
b/example/trigger/src/main/java/org/apache/iotdb/trigger/TriggerExample.java
deleted file mode 100644
index a41346ecc3..0000000000
--- a/example/trigger/src/main/java/org/apache/iotdb/trigger/TriggerExample.java
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.iotdb.trigger;
-
-import org.apache.iotdb.commons.path.PartialPath;
-import org.apache.iotdb.db.engine.trigger.api.Trigger;
-import org.apache.iotdb.db.engine.trigger.sink.local.LocalIoTDBConfiguration;
-import org.apache.iotdb.db.engine.trigger.sink.local.LocalIoTDBEvent;
-import org.apache.iotdb.db.engine.trigger.sink.local.LocalIoTDBHandler;
-import org.apache.iotdb.db.engine.trigger.sink.mqtt.MQTTConfiguration;
-import org.apache.iotdb.db.engine.trigger.sink.mqtt.MQTTEvent;
-import org.apache.iotdb.db.engine.trigger.sink.mqtt.MQTTHandler;
-import 
org.apache.iotdb.db.utils.windowing.configuration.SlidingSizeWindowConfiguration;
-import 
org.apache.iotdb.db.utils.windowing.handler.SlidingSizeWindowEvaluationHandler;
-import org.apache.iotdb.trigger.api.TriggerAttributes;
-import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
-
-import org.fusesource.mqtt.client.QoS;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class TriggerExample implements Trigger {
-
-  private static final Logger LOGGER = 
LoggerFactory.getLogger(TriggerExample.class);
-
-  private static final String TARGET_DEVICE = "root.alerting";
-
-  private final LocalIoTDBHandler localIoTDBHandler = new LocalIoTDBHandler();
-  private final MQTTHandler mqttHandler = new MQTTHandler();
-
-  // This field is required when the target MQTT server is current IoTDB.
-  // When IoTDB restarts, the registered triggers will be restored before 
starting the MQTT service.
-  // For this trigger, if openSinkHandlers() is called in onCreate(), IoTDB 
server will be stuck
-  // in openSinkHandlers when recovering, because it can't connect to the MQTT 
server (not started
-  // yet).
-  // See IOTDB-2274 for more detail.
-  private volatile boolean isSinksOpenedAfterCreation = false;
-
-  private SlidingSizeWindowEvaluationHandler windowEvaluationHandler;
-
-  @Override
-  public void onCreate(TriggerAttributes attributes) throws Exception {
-    LOGGER.info("onCreate(TriggerAttributes attributes)");
-
-    double lo = attributes.getDouble("lo");
-    double hi = attributes.getDouble("hi");
-
-    windowEvaluationHandler =
-        new SlidingSizeWindowEvaluationHandler(
-            new SlidingSizeWindowConfiguration(TSDataType.DOUBLE, 5, 5),
-            window -> {
-              double avg = 0;
-              for (int i = 0; i < window.size(); ++i) {
-                avg += window.getDouble(i);
-              }
-              avg /= window.size();
-
-              if (avg < lo || hi < avg) {
-                localIoTDBHandler.onEvent(new 
LocalIoTDBEvent(window.getTime(0), avg));
-                mqttHandler.onEvent(
-                    new MQTTEvent("test", QoS.EXACTLY_ONCE, false, 
window.getTime(0), avg));
-              }
-            });
-  }
-
-  @Override
-  public void onDrop() throws Exception {
-    LOGGER.info("onDrop()");
-    closeSinkHandlers();
-  }
-
-  @Override
-  public void onStart() throws Exception {
-    LOGGER.info("onStart()");
-    openSinkHandlers();
-  }
-
-  @Override
-  public void onStop() throws Exception {
-    LOGGER.info("onStop()");
-    closeSinkHandlers();
-  }
-
-  @Override
-  public Double fire(long timestamp, Double value, PartialPath path) throws 
Exception {
-    tryOpenSinksFirstOnFire();
-    windowEvaluationHandler.collect(timestamp, value);
-    return value;
-  }
-
-  @Override
-  public double[] fire(long[] timestamps, double[] values, PartialPath path) 
throws Exception {
-    tryOpenSinksFirstOnFire();
-    for (int i = 0; i < timestamps.length; ++i) {
-      windowEvaluationHandler.collect(timestamps[i], values[i]);
-    }
-    return values;
-  }
-
-  // See IOTDB-2274 for more detail.
-  private void tryOpenSinksFirstOnFire() throws Exception {
-    if (!isSinksOpenedAfterCreation) {
-      synchronized (this) {
-        if (!isSinksOpenedAfterCreation) {
-          openSinkHandlers();
-          isSinksOpenedAfterCreation = true;
-        }
-      }
-    }
-  }
-
-  private void openSinkHandlers() throws Exception {
-    localIoTDBHandler.open(
-        new LocalIoTDBConfiguration(
-            TARGET_DEVICE, new String[] {"local"}, new TSDataType[] 
{TSDataType.DOUBLE}));
-    mqttHandler.open(
-        new MQTTConfiguration(
-            "127.0.0.1",
-            1883,
-            "root",
-            "root",
-            new PartialPath(TARGET_DEVICE),
-            new String[] {"remote"}));
-  }
-
-  private void closeSinkHandlers() throws Exception {
-    localIoTDBHandler.close();
-    mqttHandler.close();
-  }
-}
diff --git a/server/src/test/resources/datanode1conf/iotdb-datanode.properties 
b/server/src/test/resources/datanode1conf/iotdb-datanode.properties
index ad13e4a1d9..f26d613df6 100644
--- a/server/src/test/resources/datanode1conf/iotdb-datanode.properties
+++ b/server/src/test/resources/datanode1conf/iotdb-datanode.properties
@@ -32,8 +32,9 @@ system_dir=target/datanode1/system
 data_dirs=target/datanode1/data
 wal_dirs=target/datanode1/wal
 index_root_dir=target/datanode1/data/index
-udf_root_dir=target/datanode1/ext
+udf_root_dir=target/datanode1/ext/udf
 tracing_dir=target/datanode1/data/tracing
 consensus_dir=target/datanode1/consensus
+trigger_root_dir=target/datanode1/ext/trigger
 sync_dir=target/datanode1/sync
 timestamp_precision=ms

Reply via email to