This is an automated email from the ASF dual-hosted git repository.
pdallig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/zeppelin.git
The following commit(s) were added to refs/heads/master by this push:
new 5ebd0fe623 [ZEPPELIN-5730] Support time unit setting in zeppelin conf.
(#4368)
5ebd0fe623 is described below
commit 5ebd0fe6231ec0b6d3576ee4ec3be14449fe5c2f
Author: Guanhua Li <[email protected]>
AuthorDate: Tue Jun 14 14:41:02 2022 +0800
[ZEPPELIN-5730] Support time unit setting in zeppelin conf. (#4368)
* [ZEPPELIN-5730] Support time unit setting in zeppelin conf.
* fix typos
---
conf/zeppelin-site.xml.template | 12 +++---
docs/setup/operation/configuration.md | 4 +-
.../zeppelin/conf/ZeppelinConfiguration.java | 28 +++++++++++++-
.../interpreter/launcher/InterpreterLauncher.java | 2 +-
.../lifecycle/TimeoutLifecycleManager.java | 4 +-
.../zeppelin/conf/ZeppelinConfigurationTest.java | 44 ++++++++++++++++++++++
.../interpreter/recovery/RecoveryUtils.java | 2 +-
.../launcher/StandardInterpreterLauncherTest.java | 2 +-
.../lifecycle/TimeoutLifecycleManagerTest.java | 2 +-
.../interpreter/remote/RemoteInterpreterTest.java | 2 +-
10 files changed, 86 insertions(+), 16 deletions(-)
diff --git a/conf/zeppelin-site.xml.template b/conf/zeppelin-site.xml.template
index dab1204387..fea2da568f 100755
--- a/conf/zeppelin-site.xml.template
+++ b/conf/zeppelin-site.xml.template
@@ -417,8 +417,8 @@
<property>
<name>zeppelin.interpreter.connect.timeout</name>
- <value>600000</value>
- <description>Interpreter process connect timeout in msec.</description>
+ <value>600s</value>
+ <description>Interpreter process connect timeout. Default time unit is
msec.</description>
</property>
<property>
@@ -569,14 +569,14 @@
<property>
<name>zeppelin.interpreter.lifecyclemanager.timeout.checkinterval</name>
- <value>60000</value>
- <description>Milliseconds of the interval to checking whether interpreter is
time out</description>
+ <value>1m</value>
+ <description>Interval to checking whether interpreter is time
out</description>
</property>
<property>
<name>zeppelin.interpreter.lifecyclemanager.timeout.threshold</name>
- <value>3600000</value>
- <description>Milliseconds of the interpreter timeout threshold, by default
it is 1 hour</description>
+ <value>1h</value>
+ <description>Interpreter timeout threshold, by default it is 1
hour</description>
</property>
-->
diff --git a/docs/setup/operation/configuration.md
b/docs/setup/operation/configuration.md
index 6527974834..9af7923503 100644
--- a/docs/setup/operation/configuration.md
+++ b/docs/setup/operation/configuration.md
@@ -340,8 +340,8 @@ Sources descending by priority:
<tr>
<td><h6 class="properties">ZEPPELIN_INTERPRETER_CONNECT_TIMEOUT</h6></td>
<td><h6 class="properties">zeppelin.interpreter.connect.timeout</h6></td>
- <td>600000</td>
- <td>Interpreter process connect timeout in msec.</td>
+ <td>600s</td>
+ <td>Interpreter process connect timeout. Default time unit is msec</td>
</tr>
<tr>
<td><h6 class="properties">ZEPPELIN_DEP_LOCALREPO</h6></td>
diff --git
a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/conf/ZeppelinConfiguration.java
b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/conf/ZeppelinConfiguration.java
index 6b97a1d64c..19c4de4b54 100644
---
a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/conf/ZeppelinConfiguration.java
+++
b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/conf/ZeppelinConfiguration.java
@@ -23,6 +23,8 @@ import java.io.FileWriter;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
+import java.time.Duration;
+import java.time.format.DateTimeParseException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
@@ -248,6 +250,20 @@ public class ZeppelinConfiguration {
return getLongValue(propertyName, defaultValue);
}
+ /**
+ * This method is to support time unit like `1s`, `2m`, `3h`.
+ *
+ * @param {ConfVars} c . Noteļ¼The type of default value of `ConfVars c`
should be long.
+ * @return {long} Milliseconds
+ */
+ public long getTime(ConfVars c) {
+ try {
+ return timeUnitToMill(getString(c.name(), c.getVarName(), ""));
+ } catch (Exception e) {
+ return getLong(c);
+ }
+ }
+
public float getFloat(ConfVars c) {
return getFloat(c.name(), c.getVarName(), c.getFloatValue());
}
@@ -940,7 +956,7 @@ public class ZeppelinConfiguration {
ZEPPELIN_INTERPRETER_LOCALREPO("zeppelin.interpreter.localRepo",
"local-repo"),
ZEPPELIN_INTERPRETER_DEP_MVNREPO("zeppelin.interpreter.dep.mvnRepo",
"https://repo1.maven.org/maven2/"),
-
ZEPPELIN_INTERPRETER_CONNECT_TIMEOUT("zeppelin.interpreter.connect.timeout",
600000),
+
ZEPPELIN_INTERPRETER_CONNECT_TIMEOUT("zeppelin.interpreter.connect.timeout",
600000L),
ZEPPELIN_INTERPRETER_CONNECTION_POOL_SIZE("zeppelin.interpreter.connection.poolsize",
100),
ZEPPELIN_INTERPRETER_GROUP_DEFAULT("zeppelin.interpreter.group.default",
"spark"),
ZEPPELIN_INTERPRETER_OUTPUT_LIMIT("zeppelin.interpreter.output.limit",
1024 * 100),
@@ -1184,4 +1200,14 @@ public class ZeppelinConfiguration {
return booleanValue;
}
}
+
+ public static long timeUnitToMill(String timeStrWithUnit) {
+ // If `timeStrWithUnit` doesn't include time unit,
+ // `Duration.parse` would fail to parse and throw Exception.
+ if (timeStrWithUnit.endsWith("ms")) {
+ return Long.parseLong(timeStrWithUnit.substring(0,
timeStrWithUnit.length() - 2));
+ }
+ return Duration.parse("PT" + timeStrWithUnit).toMillis();
+ }
+
}
diff --git
a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/launcher/InterpreterLauncher.java
b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/launcher/InterpreterLauncher.java
index 4a569cadbc..2e7b0d6565 100644
---
a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/launcher/InterpreterLauncher.java
+++
b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/launcher/InterpreterLauncher.java
@@ -55,7 +55,7 @@ public abstract class InterpreterLauncher {
*/
protected int getConnectTimeout() {
int connectTimeout =
-
zConf.getInt(ZeppelinConfiguration.ConfVars.ZEPPELIN_INTERPRETER_CONNECT_TIMEOUT);
+ (int)
zConf.getTime(ZeppelinConfiguration.ConfVars.ZEPPELIN_INTERPRETER_CONNECT_TIMEOUT);
if (properties != null && properties.containsKey(
ZeppelinConfiguration.ConfVars.ZEPPELIN_INTERPRETER_CONNECT_TIMEOUT.getVarName()))
{
connectTimeout = Integer.parseInt(properties.getProperty(
diff --git
a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/lifecycle/TimeoutLifecycleManager.java
b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/lifecycle/TimeoutLifecycleManager.java
index dd4eaf9114..e6bb97c7b0 100644
---
a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/lifecycle/TimeoutLifecycleManager.java
+++
b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/lifecycle/TimeoutLifecycleManager.java
@@ -46,9 +46,9 @@ public class TimeoutLifecycleManager extends LifecycleManager
{
public TimeoutLifecycleManager(ZeppelinConfiguration zConf,
RemoteInterpreterServer
remoteInterpreterServer) {
super(zConf, remoteInterpreterServer);
- long checkInterval = zConf.getLong(ZeppelinConfiguration.ConfVars
+ long checkInterval = zConf.getTime(ZeppelinConfiguration.ConfVars
.ZEPPELIN_INTERPRETER_LIFECYCLE_MANAGER_TIMEOUT_CHECK_INTERVAL);
- long timeoutThreshold = zConf.getLong(
+ long timeoutThreshold = zConf.getTime(
ZeppelinConfiguration.ConfVars.ZEPPELIN_INTERPRETER_LIFECYCLE_MANAGER_TIMEOUT_THRESHOLD);
ScheduledExecutorService checkScheduler = ExecutorFactory.singleton()
.createOrGetScheduled("TimeoutLifecycleManager", 1);
diff --git
a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/conf/ZeppelinConfigurationTest.java
b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/conf/ZeppelinConfigurationTest.java
new file mode 100644
index 0000000000..c72dc3070a
--- /dev/null
+++
b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/conf/ZeppelinConfigurationTest.java
@@ -0,0 +1,44 @@
+/*
+ * 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.zeppelin.conf;
+
+import org.junit.Test;
+
+import java.time.format.DateTimeParseException;
+
+import static org.junit.Assert.*;
+
+public class ZeppelinConfigurationTest {
+
+ @Test
+ public void testTimeUnitToMill() {
+ assertEquals(10L, ZeppelinConfiguration.timeUnitToMill("10ms"));
+ assertEquals(2000L, ZeppelinConfiguration.timeUnitToMill("2s"));
+ assertEquals(60000L, ZeppelinConfiguration.timeUnitToMill("1m"));
+ assertEquals(3600000L, ZeppelinConfiguration.timeUnitToMill("1h"));
+ }
+
+ @Test(expected = DateTimeParseException.class)
+ public void testTimeUnitToMill_WithoutUnit_1() {
+ assertEquals(DateTimeParseException.class,
ZeppelinConfiguration.timeUnitToMill("60000"));
+ }
+
+ @Test(expected = DateTimeParseException.class)
+ public void testTimeUnitToMill_WithoutUnit_2() {
+ assertEquals(DateTimeParseException.class,
ZeppelinConfiguration.timeUnitToMill("0"));
+ }
+}
diff --git
a/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/recovery/RecoveryUtils.java
b/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/recovery/RecoveryUtils.java
index 544f49b31b..b8d38a5345 100644
---
a/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/recovery/RecoveryUtils.java
+++
b/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/recovery/RecoveryUtils.java
@@ -77,7 +77,7 @@ public class RecoveryUtils {
ZeppelinConfiguration zConf) {
int connectTimeout =
-
zConf.getInt(ZeppelinConfiguration.ConfVars.ZEPPELIN_INTERPRETER_CONNECT_TIMEOUT);
+ (int)
zConf.getTime(ZeppelinConfiguration.ConfVars.ZEPPELIN_INTERPRETER_CONNECT_TIMEOUT);
Properties interpreterProperties =
interpreterSettingManager.getByName(interpreterSettingName).getJavaProperties();
int connectionPoolSize =
Integer.parseInt(interpreterProperties.getProperty(
ZEPPELIN_INTERPRETER_CONNECTION_POOL_SIZE.getVarName(),
diff --git
a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/launcher/StandardInterpreterLauncherTest.java
b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/launcher/StandardInterpreterLauncherTest.java
index 8e695f36e4..7321fe4269 100644
---
a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/launcher/StandardInterpreterLauncherTest.java
+++
b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/launcher/StandardInterpreterLauncherTest.java
@@ -53,7 +53,7 @@ public class StandardInterpreterLauncherTest {
assertEquals("name", interpreterProcess.getInterpreterSettingName());
assertEquals(".//interpreter/groupName",
interpreterProcess.getInterpreterDir());
assertEquals(".//local-repo/groupId",
interpreterProcess.getLocalRepoDir());
-
assertEquals(ZeppelinConfiguration.ConfVars.ZEPPELIN_INTERPRETER_CONNECT_TIMEOUT.getIntValue(),
+
assertEquals(ZeppelinConfiguration.ConfVars.ZEPPELIN_INTERPRETER_CONNECT_TIMEOUT.getLongValue(),
interpreterProcess.getConnectTimeout());
assertEquals(zConf.getInterpreterRemoteRunnerPath(),
interpreterProcess.getInterpreterRunner());
assertTrue(interpreterProcess.getEnv().size() >= 2);
diff --git
a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/lifecycle/TimeoutLifecycleManagerTest.java
b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/lifecycle/TimeoutLifecycleManagerTest.java
index e31a6f6d3f..bbc0cee8a0 100644
---
a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/lifecycle/TimeoutLifecycleManagerTest.java
+++
b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/lifecycle/TimeoutLifecycleManagerTest.java
@@ -45,7 +45,7 @@ public class TimeoutLifecycleManagerTest extends
AbstractInterpreterTest {
zConf.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_INTERPRETER_LIFECYCLE_MANAGER_CLASS.getVarName(),
TimeoutLifecycleManager.class.getName());
zConf.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_INTERPRETER_LIFECYCLE_MANAGER_TIMEOUT_CHECK_INTERVAL.getVarName(),
"1000");
-
zConf.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_INTERPRETER_LIFECYCLE_MANAGER_TIMEOUT_THRESHOLD.getVarName(),
"10000");
+
zConf.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_INTERPRETER_LIFECYCLE_MANAGER_TIMEOUT_THRESHOLD.getVarName(),
"10s");
super.setUp();
}
diff --git
a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterTest.java
b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterTest.java
index e6f1783e9b..ef999d0798 100644
---
a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterTest.java
+++
b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterTest.java
@@ -438,7 +438,7 @@ public class RemoteInterpreterTest extends
AbstractInterpreterTest {
try {
System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_INTERPRETER_REMOTE_RUNNER.getVarName(),
zeppelinHome.getAbsolutePath() +
"/zeppelin-zengine/src/test/resources/bin/interpreter_timeout.sh");
-
System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_INTERPRETER_CONNECT_TIMEOUT.getVarName(),
"10000");
+
System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_INTERPRETER_CONNECT_TIMEOUT.getVarName(),
"10s");
final Interpreter interpreter1 =
interpreterSetting.getInterpreter("user1", note1Id, "sleep");
final InterpreterContext context1 = createDummyInterpreterContext();
// run this dummy interpret method first to launch the
RemoteInterpreterProcess to avoid the