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/incubator-iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new 4c224bc - Made it possible to load the config from the classpath
(#1661)
4c224bc is described below
commit 4c224bc291e5ebcebc41e57d6ba38e8a1da100d2
Author: Christofer Dutz <[email protected]>
AuthorDate: Mon Aug 31 15:51:53 2020 +0200
- Made it possible to load the config from the classpath (#1661)
* - Made it possible to load the config from the classpath
---
pom.xml | 5 ++
.../org/apache/iotdb/db/conf/IoTDBDescriptor.java | 53 ++++++++++++++--------
2 files changed, 40 insertions(+), 18 deletions(-)
diff --git a/pom.xml b/pom.xml
index 8a97954..77d1255 100644
--- a/pom.xml
+++ b/pom.xml
@@ -256,6 +256,11 @@
<version>1.2.17</version>
</dependency>
<dependency>
+ <groupId>net.jpountz.lz4</groupId>
+ <artifactId>lz4</artifactId>
+ <version>1.3.0</version>
+ </dependency>
+ <dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>${jetty.version}</version>
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 1ad30bd..7c35a1f 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
@@ -19,10 +19,10 @@
package org.apache.iotdb.db.conf;
import java.io.File;
-import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
+import java.net.MalformedURLException;
import java.net.URL;
import java.time.ZoneId;
import java.util.Properties;
@@ -89,17 +89,19 @@ public class IoTDBDescriptor {
return true;
}
- public String getPropsUrl() {
- String url = System.getProperty(IoTDBConstant.IOTDB_CONF, null);
- if (url == null) {
- url = System.getProperty(IoTDBConstant.IOTDB_HOME, null);
- if (url != null) {
- url = url + File.separatorChar + "conf" + File.separatorChar +
IoTDBConfig.CONFIG_NAME;
+ public URL getPropsUrl() {
+ // Check if a config-directory was specified first.
+ String urlString = System.getProperty(IoTDBConstant.IOTDB_CONF, null);
+ // If it wasn't, check if a home directory was provided (This usually
contains a config)
+ if (urlString == null) {
+ urlString = System.getProperty(IoTDBConstant.IOTDB_HOME, null);
+ if (urlString != null) {
+ urlString = urlString + File.separatorChar + "conf" +
File.separatorChar + IoTDBConfig.CONFIG_NAME;
} else {
+ // If this too wasn't provided, try to find a default config in the
root of the classpath.
URL uri = IoTDBConfig.class.getResource("/" + IoTDBConfig.CONFIG_NAME);
if (uri != null) {
- url = uri.getPath();
- return url;
+ return uri;
}
logger.warn(
"Cannot find IOTDB_HOME or IOTDB_CONF environment variable when
loading "
@@ -109,22 +111,35 @@ public class IoTDBDescriptor {
conf.updatePath();
return null;
}
- } else {
- url += (File.separatorChar + IoTDBConfig.CONFIG_NAME);
}
- return url;
+ // If a config location was provided, but it doesn't end with a properties
file,
+ // append the default location.
+ else if(!urlString.endsWith(".properties")) {
+ urlString += (File.separatorChar + IoTDBConfig.CONFIG_NAME);
+ }
+ // If the url doesn't contain a ":" it's provided as a normal path.
+ // So we need to add the prefix "file:" to make it a real URL.
+ if(!urlString.contains(":")) {
+ urlString = "file:" + urlString;
+ }
+ try {
+ return new URL(urlString);
+ } catch (MalformedURLException e) {
+ return null;
+ }
}
/**
* load an property file and set TsfileDBConfig variables.
*/
private void loadProps() {
- String url = getPropsUrl();
- if (url == null) {
+ URL url = getPropsUrl();
+ if(url == null) {
+ logger.warn("Couldn't load the configuration from any of the known
sources.");
return;
}
- try (InputStream inputStream = new FileInputStream(new File(url))) {
+ try (InputStream inputStream = url.openStream()) {
logger.info("Start to read config file {}", url);
Properties properties = new Properties();
@@ -660,11 +675,13 @@ public class IoTDBDescriptor {
}
public void loadHotModifiedProps() throws QueryProcessException {
- String url = getPropsUrl();
- if (url == null) {
+ URL url = getPropsUrl();
+ if(url == null) {
+ logger.warn("Couldn't load the configuration from any of the known
sources.");
return;
}
- try (InputStream inputStream = new FileInputStream(new File(url))) {
+
+ try (InputStream inputStream = url.openStream()) {
logger.info("Start to reload config file {}", url);
Properties properties = new Properties();
properties.load(inputStream);