-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[ZEPPELIN-6406] Integrate interpreter config key constants #5184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hyunw9
wants to merge
2
commits into
apache:master
Choose a base branch
from
hyunw9:ZEPPELIN-6406
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
zeppelin-common/src/main/java/org/apache/zeppelin/common/ConfigTimeUtils.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| /* | ||
| * 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.common; | ||
|
|
||
| import java.time.Duration; | ||
|
|
||
| /** | ||
| * Utility for parsing time values from configuration strings. | ||
| * Consolidates the logic previously duplicated in | ||
| * {@code ZeppelinConfiguration.timeUnitToMill()} and | ||
| * {@code TimeoutLifecycleManager.parseTimeValue()}. | ||
| */ | ||
| public final class ConfigTimeUtils { | ||
| private ConfigTimeUtils() {} | ||
|
|
||
| /** | ||
| * Parses a configuration time string to milliseconds. | ||
| * | ||
| * <p>Supported formats: | ||
| * <ul> | ||
| * <li>Plain integer: treated as milliseconds (e.g. {@code "60000"})</li> | ||
| * <li>{@code "ms"} suffix: parsed as milliseconds (e.g. {@code "500ms"})</li> | ||
| * <li>ISO 8601 duration component: H, M, S or combinations (e.g. {@code "1H"}, {@code "30M"}, | ||
| * {@code "1H30M"})</li> | ||
| * </ul> | ||
| * | ||
| * @param value the time string from a configuration property | ||
| * @return the equivalent duration in milliseconds | ||
| * @throws IllegalArgumentException if {@code value} is null or empty | ||
| * @throws java.time.format.DateTimeParseException if the value is not a recognised format | ||
| */ | ||
| public static long parseTimeValueToMillis(String value) { | ||
| if (value == null || value.trim().isEmpty()) { | ||
| throw new IllegalArgumentException("Time value must not be null or empty"); | ||
| } | ||
| try { | ||
| return Long.parseLong(value); | ||
| } catch (NumberFormatException e) { | ||
| if (value.endsWith("ms")) { | ||
| return Long.parseLong(value.substring(0, value.length() - 2)); | ||
| } | ||
| return Duration.parse("PT" + value).toMillis(); | ||
| } | ||
| } | ||
| } |
40 changes: 40 additions & 0 deletions
40
zeppelin-common/src/main/java/org/apache/zeppelin/common/InterpreterConfigKeys.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| /* | ||
| * 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.common; | ||
|
|
||
| /** | ||
| * Canonical string constants for interpreter-related configuration keys. | ||
| * Use these instead of plain string literals to catch typos at compile time. | ||
| */ | ||
| public final class InterpreterConfigKeys { | ||
| private InterpreterConfigKeys() {} | ||
|
|
||
| public static final String INTERPRETER_CONNECTION_POOL_SIZE = | ||
| "zeppelin.interpreter.connection.poolsize"; | ||
| public static final String INTERPRETER_LIFECYCLE_MANAGER_CLASS = | ||
| "zeppelin.interpreter.lifecyclemanager.class"; | ||
| public static final String INTERPRETER_LIFECYCLE_MANAGER_TIMEOUT_CHECK_INTERVAL = | ||
| "zeppelin.interpreter.lifecyclemanager.timeout.checkinterval"; | ||
| public static final String INTERPRETER_LIFECYCLE_MANAGER_TIMEOUT_THRESHOLD = | ||
| "zeppelin.interpreter.lifecyclemanager.timeout.threshold"; | ||
| public static final String PROXY_URL = "zeppelin.proxy.url"; | ||
| public static final String PROXY_USER = "zeppelin.proxy.user"; | ||
| public static final String PROXY_PASSWORD = "zeppelin.proxy.password"; | ||
| public static final String INTERPRETER_DEP_MVNREPO = "zeppelin.interpreter.dep.mvnRepo"; | ||
| public static final String SCHEDULER_THREADPOOL_SIZE = "zeppelin.scheduler.threadpool.size"; | ||
| } |
84 changes: 84 additions & 0 deletions
84
zeppelin-common/src/test/java/org/apache/zeppelin/common/ConfigTimeUtilsTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| /* | ||
| * 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.common; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
|
||
| class ConfigTimeUtilsTest { | ||
|
|
||
| @Test | ||
| void plainNumberReturnedAsMillis() { | ||
| assertEquals(60000L, ConfigTimeUtils.parseTimeValueToMillis("60000")); | ||
| } | ||
|
|
||
| @Test | ||
| void msSuffixParsed() { | ||
| assertEquals(500L, ConfigTimeUtils.parseTimeValueToMillis("500ms")); | ||
| } | ||
|
|
||
| @Test | ||
| void hourUnitParsed() { | ||
| assertEquals(3600000L, ConfigTimeUtils.parseTimeValueToMillis("1H")); | ||
| } | ||
|
|
||
| @Test | ||
| void minuteUnitParsed() { | ||
| assertEquals(1800000L, ConfigTimeUtils.parseTimeValueToMillis("30M")); | ||
| } | ||
|
|
||
| @Test | ||
| void secondUnitParsed() { | ||
| assertEquals(10000L, ConfigTimeUtils.parseTimeValueToMillis("10S")); | ||
| } | ||
|
|
||
| @Test | ||
| void compoundDurationParsed() { | ||
| assertEquals(5400000L, ConfigTimeUtils.parseTimeValueToMillis("1H30M")); | ||
| } | ||
|
|
||
| @Test | ||
| void defaultCheckIntervalCompatible() { | ||
| assertEquals(60000L, ConfigTimeUtils.parseTimeValueToMillis("60000")); | ||
| } | ||
|
|
||
| @Test | ||
| void defaultThresholdCompatible() { | ||
| assertEquals(3600000L, ConfigTimeUtils.parseTimeValueToMillis("3600000")); | ||
| } | ||
|
|
||
| @Test | ||
| void nullInputThrows() { | ||
| assertThrows(IllegalArgumentException.class, | ||
| () -> ConfigTimeUtils.parseTimeValueToMillis(null)); | ||
| } | ||
|
|
||
| @Test | ||
| void emptyInputThrows() { | ||
| assertThrows(IllegalArgumentException.class, | ||
| () -> ConfigTimeUtils.parseTimeValueToMillis("")); | ||
| } | ||
|
|
||
| @Test | ||
| void invalidFormatThrows() { | ||
| assertThrows(Exception.class, | ||
| () -> ConfigTimeUtils.parseTimeValueToMillis("abc")); | ||
| } | ||
| } |
76 changes: 76 additions & 0 deletions
76
zeppelin-common/src/test/java/org/apache/zeppelin/common/InterpreterConfigKeysTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| /* | ||
| * 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.common; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
|
||
| class InterpreterConfigKeysTest { | ||
|
|
||
| @Test | ||
| void interpreterConnectionPoolSizeKey() { | ||
| assertEquals("zeppelin.interpreter.connection.poolsize", | ||
| InterpreterConfigKeys.INTERPRETER_CONNECTION_POOL_SIZE); | ||
| } | ||
|
|
||
| @Test | ||
| void interpreterLifecycleManagerClassKey() { | ||
| assertEquals("zeppelin.interpreter.lifecyclemanager.class", | ||
| InterpreterConfigKeys.INTERPRETER_LIFECYCLE_MANAGER_CLASS); | ||
| } | ||
|
|
||
| @Test | ||
| void interpreterLifecycleManagerTimeoutCheckIntervalKey() { | ||
| assertEquals("zeppelin.interpreter.lifecyclemanager.timeout.checkinterval", | ||
| InterpreterConfigKeys.INTERPRETER_LIFECYCLE_MANAGER_TIMEOUT_CHECK_INTERVAL); | ||
| } | ||
|
|
||
| @Test | ||
| void interpreterLifecycleManagerTimeoutThresholdKey() { | ||
| assertEquals("zeppelin.interpreter.lifecyclemanager.timeout.threshold", | ||
| InterpreterConfigKeys.INTERPRETER_LIFECYCLE_MANAGER_TIMEOUT_THRESHOLD); | ||
| } | ||
|
|
||
| @Test | ||
| void proxyUrlKey() { | ||
| assertEquals("zeppelin.proxy.url", InterpreterConfigKeys.PROXY_URL); | ||
| } | ||
|
|
||
| @Test | ||
| void proxyUserKey() { | ||
| assertEquals("zeppelin.proxy.user", InterpreterConfigKeys.PROXY_USER); | ||
| } | ||
|
|
||
| @Test | ||
| void proxyPasswordKey() { | ||
| assertEquals("zeppelin.proxy.password", InterpreterConfigKeys.PROXY_PASSWORD); | ||
| } | ||
|
|
||
| @Test | ||
| void interpreterDepMvnRepoKey() { | ||
| assertEquals("zeppelin.interpreter.dep.mvnRepo", | ||
| InterpreterConfigKeys.INTERPRETER_DEP_MVNREPO); | ||
| } | ||
|
|
||
| @Test | ||
| void schedulerThreadpoolSizeKey() { | ||
| assertEquals("zeppelin.scheduler.threadpool.size", | ||
| InterpreterConfigKeys.SCHEDULER_THREADPOOL_SIZE); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.