This is an automated email from the ASF dual-hosted git repository. xiangfu pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/pinot.git
The following commit(s) were added to refs/heads/master by this push: new 05a7f28b73 don't snapshot environment in ConfigUtils (#8548) 05a7f28b73 is described below commit 05a7f28b7316a35b171637c3be836345e4ebbe74 Author: Richard Startin <rich...@startree.ai> AuthorDate: Fri Apr 15 10:20:58 2022 +0100 don't snapshot environment in ConfigUtils (#8548) --- .../org/apache/pinot/spi/config/ConfigUtils.java | 10 +++++--- .../org/apache/pinot/spi/config/Environment.java | 30 ---------------------- .../apache/pinot/spi/config/ConfigUtilsTest.java | 2 +- 3 files changed, 7 insertions(+), 35 deletions(-) diff --git a/pinot-spi/src/main/java/org/apache/pinot/spi/config/ConfigUtils.java b/pinot-spi/src/main/java/org/apache/pinot/spi/config/ConfigUtils.java index a4f34a49fe..5bd637411b 100644 --- a/pinot-spi/src/main/java/org/apache/pinot/spi/config/ConfigUtils.java +++ b/pinot-spi/src/main/java/org/apache/pinot/spi/config/ConfigUtils.java @@ -32,13 +32,15 @@ public class ConfigUtils { private ConfigUtils() { } + private static final Map<String, String> ENVIRONMENT_VARIABLES = System.getenv(); + /** * Apply environment variables to any given BaseJsonConfig. * * @return Config with environment variable applied. */ public static <T extends BaseJsonConfig> T applyConfigWithEnvVariables(T config) { - return applyConfigWithEnvVariables(System::getenv, config); + return applyConfigWithEnvVariables(ENVIRONMENT_VARIABLES, config); } /** @@ -46,7 +48,7 @@ public class ConfigUtils { * * @return Config with environment variable applied. */ - public static <T extends BaseJsonConfig> T applyConfigWithEnvVariables(Environment environment, T config) { + public static <T extends BaseJsonConfig> T applyConfigWithEnvVariables(Map<String, String> environment, T config) { JsonNode jsonNode; try { jsonNode = applyConfigWithEnvVariables(environment, config.toJsonNode()); @@ -63,7 +65,7 @@ public class ConfigUtils { } } - private static JsonNode applyConfigWithEnvVariables(Environment environment, JsonNode jsonNode) { + private static JsonNode applyConfigWithEnvVariables(Map<String, String> environment, JsonNode jsonNode) { final JsonNodeType nodeType = jsonNode.getNodeType(); switch (nodeType) { case OBJECT: @@ -89,7 +91,7 @@ public class ConfigUtils { if (field.startsWith("${") && field.endsWith("}")) { String[] envVarSplits = field.substring(2, field.length() - 1).split(":", 2); String envVarKey = envVarSplits[0]; - String value = environment.getVariable(envVarKey); + String value = environment.get(envVarKey); if (value != null) { return JsonNodeFactory.instance.textNode(value); } else if (envVarSplits.length > 1) { diff --git a/pinot-spi/src/main/java/org/apache/pinot/spi/config/Environment.java b/pinot-spi/src/main/java/org/apache/pinot/spi/config/Environment.java deleted file mode 100644 index efd9eb1908..0000000000 --- a/pinot-spi/src/main/java/org/apache/pinot/spi/config/Environment.java +++ /dev/null @@ -1,30 +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.pinot.spi.config; - -/** - * Encapsulates environment variables so they can be overridden for testing purposes. - */ -public interface Environment { - /** - * @param name the name of the environment variable - * @return an environment variable or null if not set - */ - String getVariable(String name); -} diff --git a/pinot-spi/src/test/java/org/apache/pinot/spi/config/ConfigUtilsTest.java b/pinot-spi/src/test/java/org/apache/pinot/spi/config/ConfigUtilsTest.java index 9220cfd425..d2d8f650a1 100644 --- a/pinot-spi/src/test/java/org/apache/pinot/spi/config/ConfigUtilsTest.java +++ b/pinot-spi/src/test/java/org/apache/pinot/spi/config/ConfigUtilsTest.java @@ -91,7 +91,7 @@ public class ConfigUtilsTest { ImmutableMap.of("LOAD_MODE", "MMAP", "AWS_ACCESS_KEY", "default_aws_access_key", "AWS_SECRET_KEY", "default_aws_secret_key"); - indexingConfig = ConfigUtils.applyConfigWithEnvVariables(environment::get, indexingConfig); + indexingConfig = ConfigUtils.applyConfigWithEnvVariables(environment, indexingConfig); assertEquals(indexingConfig.getLoadMode(), "MMAP"); assertTrue(indexingConfig.isAggregateMetrics()); assertEquals(indexingConfig.getInvertedIndexColumns(), invertedIndexColumns); --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org