You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by hx...@apache.org on 2021/01/21 00:25:05 UTC

[iotdb] branch master updated: IOTDB-1111 load configuration -global command do not support (#2526)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new b1e5c81  IOTDB-1111 load configuration -global command do not support (#2526)
b1e5c81 is described below

commit b1e5c81df55f9ea1b4110afa3ee5be360404461c
Author: wangchao316 <66...@users.noreply.github.com>
AuthorDate: Thu Jan 21 08:24:37 2021 +0800

    IOTDB-1111 load configuration -global command do not support (#2526)
---
 cluster/pom.xml                                    |  16 +++
 .../cluster/query/ClusterPhysicalGenerator.java    |  15 ++-
 .../iotdb/cluster/query/LoadConfigurationTest.java | 122 +++++++++++++++++++++
 .../org/apache/iotdb/db/conf/IoTDBDescriptor.java  |   4 +
 4 files changed, 151 insertions(+), 6 deletions(-)

diff --git a/cluster/pom.xml b/cluster/pom.xml
index 251c310..6d257d1 100644
--- a/cluster/pom.xml
+++ b/cluster/pom.xml
@@ -107,6 +107,22 @@
             <version>4.0.2</version>
             <scope>test</scope>
         </dependency>
+        <!-- for mocked test-->
+        <dependency>
+            <groupId>org.powermock</groupId>
+            <artifactId>powermock-core</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.powermock</groupId>
+            <artifactId>powermock-module-junit4</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.powermock</groupId>
+            <artifactId>powermock-api-mockito2</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
     <profiles>
         <profile>
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/query/ClusterPhysicalGenerator.java b/cluster/src/main/java/org/apache/iotdb/cluster/query/ClusterPhysicalGenerator.java
index 5e55d66..3578970 100644
--- a/cluster/src/main/java/org/apache/iotdb/cluster/query/ClusterPhysicalGenerator.java
+++ b/cluster/src/main/java/org/apache/iotdb/cluster/query/ClusterPhysicalGenerator.java
@@ -73,7 +73,6 @@ public class ClusterPhysicalGenerator extends PhysicalGenerator {
     return ((CMManager) IoTDB.metaManager).getMatchedDevices(path);
   }
 
-
   @Override
   protected PhysicalPlan generateLoadConfigurationPlan(LoadConfigurationOperatorType type)
       throws QueryProcessException {
@@ -81,19 +80,23 @@ public class ClusterPhysicalGenerator extends PhysicalGenerator {
       Properties[] properties = new Properties[2];
       properties[0] = new Properties();
       URL iotdbEnginePropertiesUrl = IoTDBDescriptor.getInstance().getPropsUrl();
-      try (InputStream inputStream = new FileInputStream(new File(iotdbEnginePropertiesUrl.toString()))) {
+      if (iotdbEnginePropertiesUrl == null) {
+        logger.error("Fail to find the engine config file");
+        throw new QueryProcessException("Fail to find config file");
+      }
+      try (InputStream inputStream = iotdbEnginePropertiesUrl.openStream()) {
         properties[0].load(inputStream);
       } catch (IOException e) {
-        logger.warn("Fail to find config file {}", iotdbEnginePropertiesUrl, e);
-        throw new QueryProcessException("Fail to find iotdb-engine config file.");
+        logger.error("Fail to read iotdb-engine config file {}", iotdbEnginePropertiesUrl, e);
+        throw new QueryProcessException("Fail to read iotdb-engine config file.");
       }
       String clusterPropertiesUrl = ClusterDescriptor.getInstance().getPropsUrl();
       properties[1] = new Properties();
       try (InputStream inputStream = new FileInputStream(new File(clusterPropertiesUrl))) {
         properties[1].load(inputStream);
       } catch (IOException e) {
-        logger.warn("Fail to find config file {}", clusterPropertiesUrl, e);
-        throw new QueryProcessException("Fail to find cluster config file.");
+        logger.error("Fail to read iotdb-cluster config file {}", clusterPropertiesUrl, e);
+        throw new QueryProcessException("Fail to read iotdb-cluster config file.");
       }
 
       return new LoadConfigurationPlan(LoadConfigurationPlanType.GLOBAL, properties);
diff --git a/cluster/src/test/java/org/apache/iotdb/cluster/query/LoadConfigurationTest.java b/cluster/src/test/java/org/apache/iotdb/cluster/query/LoadConfigurationTest.java
new file mode 100644
index 0000000..960b2b0
--- /dev/null
+++ b/cluster/src/test/java/org/apache/iotdb/cluster/query/LoadConfigurationTest.java
@@ -0,0 +1,122 @@
+/*
+ * 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.cluster.query;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.when;
+
+import org.apache.iotdb.cluster.config.ClusterDescriptor;
+import org.apache.iotdb.db.conf.IoTDBDescriptor;
+import org.apache.iotdb.db.constant.TestConstant;
+import org.apache.iotdb.db.exception.StorageEngineException;
+import org.apache.iotdb.db.exception.query.QueryProcessException;
+
+import org.apache.iotdb.db.qp.logical.sys.LoadConfigurationOperator;
+import org.apache.iotdb.db.qp.physical.sys.LoadConfigurationPlan;
+import org.apache.iotdb.db.qp.strategy.PhysicalGenerator;
+import org.apache.iotdb.tsfile.fileSystem.FSFactoryProducer;
+import org.apache.iotdb.tsfile.fileSystem.fsFactory.FSFactory;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PowerMockIgnore;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.net.URL;
+@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"})
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({IoTDBDescriptor.class,ClusterDescriptor.class})
+public class LoadConfigurationTest {
+
+  private static FSFactory fsFactory = FSFactoryProducer.getFSFactory();
+
+  private final static String ENGINE_PROPERTIES_FILE = TestConstant.BASE_OUTPUT_PATH.concat("LoadConfigurationTestEngineProperties");
+  private final static String CLUSTER_PROPERTIES_FILE = TestConstant.BASE_OUTPUT_PATH.concat("LoadConfigurationTestClusterProperties");
+
+  @Mock
+  private IoTDBDescriptor ioTDBDescriptor;
+
+  @Mock
+  private ClusterDescriptor clusterDescriptor;
+
+  @Before
+  public void setUp() throws Exception {
+    // init engine properties
+    File engineFile = fsFactory.getFile(ENGINE_PROPERTIES_FILE);
+    if (engineFile.exists()) {
+      Assert.assertTrue(engineFile.delete());
+    }
+    try (FileWriter fw = new FileWriter(engineFile)) {
+      fw.write("enable_metric_service=false");
+    }
+    ioTDBDescriptor = PowerMockito.mock(IoTDBDescriptor.class);
+    PowerMockito.mockStatic(IoTDBDescriptor.class);
+    PowerMockito.doReturn(ioTDBDescriptor).when(IoTDBDescriptor.class, "getInstance");
+    when(ioTDBDescriptor.getPropsUrl()).thenReturn(new URL("file:" + ENGINE_PROPERTIES_FILE));
+
+    //init cluster properties
+    File clusterFile = fsFactory.getFile(CLUSTER_PROPERTIES_FILE);
+    if (clusterFile.exists()) {
+      Assert.assertTrue(clusterFile.delete());
+    }
+    try (FileWriter fw = new FileWriter(clusterFile)) {
+      fw.write("cluster_rpc_ip=127.0.0.1");
+    }
+    clusterDescriptor = PowerMockito.mock(ClusterDescriptor.class);
+    PowerMockito.mockStatic(ClusterDescriptor.class);
+    PowerMockito.doReturn(clusterDescriptor).when(ClusterDescriptor.class, "getInstance");
+    when(clusterDescriptor.getPropsUrl()).thenReturn(CLUSTER_PROPERTIES_FILE);
+  }
+
+  @After
+  public void tearDown() throws IOException, StorageEngineException {
+    File engineFile = fsFactory.getFile(ENGINE_PROPERTIES_FILE);
+    if (engineFile.exists()) {
+      Assert.assertTrue(engineFile.delete());
+    }
+    File clusterFile = fsFactory.getFile(CLUSTER_PROPERTIES_FILE);
+    if (clusterFile.exists()) {
+      Assert.assertTrue(clusterFile.delete());
+    }
+  }
+
+  @Test
+  public void testLoadConfigurationGlobal() throws QueryProcessException {
+    PhysicalGenerator physicalGenerator = new ClusterPhysicalGenerator();
+    LoadConfigurationOperator loadConfigurationOperator = new LoadConfigurationOperator(
+        LoadConfigurationOperator.LoadConfigurationOperatorType.GLOBAL);
+
+    LoadConfigurationPlan loadConfigurationPlan = (LoadConfigurationPlan) physicalGenerator.transformToPhysicalPlan(loadConfigurationOperator, 0);
+    String metricProperties = (String) loadConfigurationPlan.getIoTDBProperties().get("enable_metric_service");
+    assertEquals("false", metricProperties);
+    String clusterIp = (String) loadConfigurationPlan.getClusterProperties().get("cluster_rpc_ip");
+    assertEquals("127.0.0.1", clusterIp);
+  }
+}
\ No newline at end of file
diff --git a/server/src/main/java/org/apache/iotdb/db/conf/IoTDBDescriptor.java b/server/src/main/java/org/apache/iotdb/db/conf/IoTDBDescriptor.java
index ef56f50..38a0693 100644
--- a/server/src/main/java/org/apache/iotdb/db/conf/IoTDBDescriptor.java
+++ b/server/src/main/java/org/apache/iotdb/db/conf/IoTDBDescriptor.java
@@ -90,6 +90,10 @@ public class IoTDBDescriptor {
     return true;
   }
 
+  /**
+   * get props url location
+   * @return url object if location exit, otherwise null.
+   */
   public URL getPropsUrl() {
     // Check if a config-directory was specified first.
     String urlString = System.getProperty(IoTDBConstant.IOTDB_CONF, null);