Trim whitespace when loading configuration

This commit is contained in:
bryanwongsz 2020-12-22 10:15:52 +08:00
parent cd61052422
commit 39783473ea
15 changed files with 30 additions and 68 deletions

View File

@ -35,8 +35,8 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import static io.airlift.configuration.ConfigurationLoader.loadPropertiesFrom;
import static io.hetu.core.plugin.hana.TestHanaConstants.TEST_PROPERTY_FILE_PATH;
import static io.prestosql.util.PropertiesUtil.loadProperties;
public final class TestingHanaServer
{
@ -107,7 +107,7 @@ public final class TestingHanaServer
{
File file = new File(TEST_PROPERTY_FILE_PATH);
try {
Map<String, String> properties = new HashMap<>(loadProperties(file));
Map<String, String> properties = new HashMap<>(loadPropertiesFrom(file.getPath()));
LOG.info("test-hana properties: %s", properties);
String connectionUrl = properties.get("connection.url");

View File

@ -29,8 +29,8 @@ import java.sql.Statement;
import java.util.HashMap;
import java.util.Map;
import static io.airlift.configuration.ConfigurationLoader.loadPropertiesFrom;
import static io.hetu.core.plugin.oracle.TestOracleConstants.ORACLE_UT_CONFIG_FILE_PATH;
import static io.prestosql.util.PropertiesUtil.loadProperties;
import static java.lang.String.format;
/**
@ -57,7 +57,7 @@ public class TestingOracleServer
File file = new File(ORACLE_UT_CONFIG_FILE_PATH);
try {
Map<String, String> properties = new HashMap<>(loadProperties(file));
Map<String, String> properties = new HashMap<>(loadPropertiesFrom(file.getPath()));
connectionUrl = properties.get("connection.url");
user = properties.get("connection.user");
passWd = properties.get("connection.password");

View File

@ -49,9 +49,9 @@ import java.util.concurrent.locks.Lock;
import java.util.stream.Collectors;
import static io.airlift.concurrent.Threads.daemonThreadsNamed;
import static io.airlift.configuration.ConfigurationLoader.loadPropertiesFrom;
import static io.prestosql.spi.StandardErrorCode.GENERIC_INTERNAL_ERROR;
import static io.prestosql.spi.StandardErrorCode.GENERIC_USER_ERROR;
import static io.prestosql.util.PropertiesUtil.loadProperties;
import static java.util.Objects.requireNonNull;
import static java.util.concurrent.Executors.newFixedThreadPool;
@ -146,7 +146,7 @@ public class DynamicCatalogStore
// create connection, will load catalog from local disk to catalog manager.
CatalogFilePath catalogPath = new CatalogFilePath(dynamicCatalogConfig.getCatalogConfigurationDir(), catalogName);
File propertiesFile = catalogPath.getPropertiesPath().toFile();
Map<String, String> properties = new HashMap<>(loadProperties(propertiesFile));
Map<String, String> properties = new HashMap<>(loadPropertiesFrom(propertiesFile.getPath()));
catalogStoreUtil.decryptEncryptedProperties(catalogName, properties);
properties.remove(CATALOG_NAME);
connectorManager.createConnection(catalogName, catalogInfo.getConnectorName(), ImmutableMap.copyOf(properties));

View File

@ -33,7 +33,7 @@ import java.util.concurrent.atomic.AtomicReference;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.base.Strings.isNullOrEmpty;
import static io.prestosql.util.PropertiesUtil.loadProperties;
import static io.airlift.configuration.ConfigurationLoader.loadPropertiesFrom;
import static java.util.Objects.requireNonNull;
public class EventListenerManager
@ -58,7 +58,7 @@ public class EventListenerManager
throws Exception
{
if (EVENT_LISTENER_CONFIGURATION.exists()) {
Map<String, String> properties = new HashMap<>(loadProperties(EVENT_LISTENER_CONFIGURATION));
Map<String, String> properties = new HashMap<>(loadPropertiesFrom(EVENT_LISTENER_CONFIGURATION.getPath()));
String eventListenerName = properties.remove(EVENT_LISTENER_PROPERTY_NAME);
checkArgument(!isNullOrEmpty(eventListenerName),

View File

@ -61,8 +61,8 @@ import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.base.Strings.isNullOrEmpty;
import static io.airlift.concurrent.Threads.daemonThreadsNamed;
import static io.airlift.configuration.ConfigurationLoader.loadPropertiesFrom;
import static io.prestosql.spi.StandardErrorCode.QUERY_REJECTED;
import static io.prestosql.util.PropertiesUtil.loadProperties;
import static java.lang.String.format;
import static java.util.Objects.requireNonNull;
import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor;
@ -157,7 +157,7 @@ public final class InternalResourceGroupManager<C>
throws Exception
{
if (RESOURCE_GROUPS_CONFIGURATION.exists()) {
Map<String, String> properties = new HashMap<>(loadProperties(RESOURCE_GROUPS_CONFIGURATION));
Map<String, String> properties = new HashMap<>(loadPropertiesFrom(RESOURCE_GROUPS_CONFIGURATION.getPath()));
String configurationManagerName = properties.remove(CONFIGURATION_MANAGER_PROPERTY_NAME);
checkArgument(!isNullOrEmpty(configurationManagerName),

View File

@ -32,8 +32,8 @@ import java.util.concurrent.atomic.AtomicBoolean;
import static com.google.common.base.MoreObjects.firstNonNull;
import static com.google.common.base.Preconditions.checkState;
import static io.airlift.configuration.ConfigurationLoader.loadPropertiesFrom;
import static io.prestosql.catalog.CatalogFilePath.getCatalogBasePath;
import static io.prestosql.util.PropertiesUtil.loadProperties;
public class StaticCatalogStore
{
@ -95,7 +95,7 @@ public class StaticCatalogStore
log.info("-- Loading catalog %s --", file);
Map<String, String> properties = new HashMap<>(loadProperties(file));
Map<String, String> properties = new HashMap<>(loadPropertiesFrom(file.getPath()));
catalogStoreUtil.decryptEncryptedProperties(catalogName, properties);
String connectorName = properties.remove("connector.name");

View File

@ -29,7 +29,7 @@ import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import static com.google.common.base.Preconditions.checkState;
import static io.prestosql.util.PropertiesUtil.loadProperties;
import static io.airlift.configuration.ConfigurationLoader.loadPropertiesFrom;
import static java.lang.String.format;
import static java.util.Objects.requireNonNull;
@ -69,7 +69,7 @@ public class HetuMetaStoreManager
LOG.info("-- Loading Hetu Metastore --");
if (HETUMETASTORE_CONFIG_FILE.exists()) {
// load configuration
Map<String, String> config = new HashMap<>(loadProperties(HETUMETASTORE_CONFIG_FILE));
Map<String, String> config = new HashMap<>(loadPropertiesFrom(HETUMETASTORE_CONFIG_FILE.getPath()));
// create hetu metastore
hetuMetastoreType = config.getOrDefault(HETU_METASTORE_TYPE_PROPERTY_NAME, HETU_METASTORE_TYPE_DEFAULT_VALUE);
config.remove(HETU_METASTORE_TYPE_PROPERTY_NAME);

View File

@ -54,8 +54,8 @@ import java.util.concurrent.atomic.AtomicReference;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.base.Strings.isNullOrEmpty;
import static io.airlift.configuration.ConfigurationLoader.loadPropertiesFrom;
import static io.prestosql.spi.StandardErrorCode.SERVER_STARTING_UP;
import static io.prestosql.util.PropertiesUtil.loadProperties;
import static java.lang.String.format;
import static java.util.Objects.requireNonNull;
@ -113,7 +113,7 @@ public class AccessControlManager
throws Exception
{
if (ACCESS_CONTROL_CONFIGURATION.exists()) {
Map<String, String> properties = new HashMap<>(loadProperties(ACCESS_CONTROL_CONFIGURATION));
Map<String, String> properties = new HashMap<>(loadPropertiesFrom(ACCESS_CONTROL_CONFIGURATION.getPath()));
String accessControlName = properties.remove(ACCESS_CONTROL_PROPERTY_NAME);
checkArgument(!isNullOrEmpty(accessControlName),

View File

@ -44,8 +44,8 @@ import java.util.stream.Collectors;
import static com.google.common.base.Preconditions.checkState;
import static io.airlift.concurrent.Threads.daemonThreadsNamed;
import static io.airlift.configuration.ConfigurationLoader.loadPropertiesFrom;
import static io.prestosql.spi.StandardErrorCode.SEED_STORE_FAILURE;
import static io.prestosql.util.PropertiesUtil.loadProperties;
import static java.lang.String.format;
import static java.util.Objects.requireNonNull;
import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor;
@ -328,7 +328,7 @@ public class SeedStoreManager
// load state store config if exist
if (stateStoreConfig.exists()) {
Map<String, String> stateStoreProperties = new HashMap<>(loadProperties(stateStoreConfig));
Map<String, String> stateStoreProperties = new HashMap<>(loadPropertiesFrom(stateStoreConfig.getPath()));
filesystemProfile = stateStoreProperties.getOrDefault(StateStoreConstants.HAZELCAST_DISCOVERY_TCPIP_PROFILE, filesystemProfile);
// for now, seed store is started only if tcp-ip mode enabled and tcp-ip.seeds is not set
String discoveryMode = stateStoreProperties.get(StateStoreConstants.DISCOVERY_MODE_PROPERTY_NAME);
@ -338,7 +338,7 @@ public class SeedStoreManager
// load seed store config if exist
if (seedStoreConfig.exists()) {
Map<String, String> seedStoreProperties = new HashMap<>(loadProperties(seedStoreConfig));
Map<String, String> seedStoreProperties = new HashMap<>(loadPropertiesFrom(seedStoreConfig.getPath()));
properties.putAll(seedStoreProperties);
seedStoreType = properties.getOrDefault(SEED_STORE_TYPE_PROPERTY_NAME, seedStoreType);
filesystemProfile = properties.getOrDefault(SEED_STORE_FILESYSTEM_PROFILE, filesystemProfile);

View File

@ -35,7 +35,7 @@ import java.util.concurrent.atomic.AtomicReference;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
import static io.prestosql.util.PropertiesUtil.loadProperties;
import static io.airlift.configuration.ConfigurationLoader.loadPropertiesFrom;
public class SessionPropertyDefaults
{
@ -67,7 +67,7 @@ public class SessionPropertyDefaults
return;
}
Map<String, String> propertyMap = new HashMap<>(loadProperties(SESSION_PROPERTY_CONFIGURATION));
Map<String, String> propertyMap = new HashMap<>(loadPropertiesFrom(SESSION_PROPERTY_CONFIGURATION.getPath()));
log.info("-- Loading session property configuration manager --");

View File

@ -29,7 +29,7 @@ import java.util.concurrent.atomic.AtomicReference;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.base.Strings.isNullOrEmpty;
import static io.prestosql.util.PropertiesUtil.loadProperties;
import static io.airlift.configuration.ConfigurationLoader.loadPropertiesFrom;
import static java.util.Objects.requireNonNull;
public class PasswordAuthenticatorManager
@ -62,7 +62,7 @@ public class PasswordAuthenticatorManager
}
File configFileLocation = CONFIG_FILE.getAbsoluteFile();
Map<String, String> properties = new HashMap<>(loadProperties(configFileLocation));
Map<String, String> properties = new HashMap<>(loadPropertiesFrom(configFileLocation.getPath()));
String name = properties.remove(NAME_PROPERTY);
checkArgument(!isNullOrEmpty(name),

View File

@ -42,6 +42,7 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.stream.Collectors;
import static io.airlift.configuration.ConfigurationLoader.loadPropertiesFrom;
import static io.prestosql.spi.StandardErrorCode.STATE_STORE_FAILURE;
import static io.prestosql.statestore.StateStoreConstants.DEFAULT_HAZELCAST_DISCOVERY_PORT;
import static io.prestosql.statestore.StateStoreConstants.HAZELCAST;
@ -50,7 +51,6 @@ import static io.prestosql.statestore.StateStoreConstants.HAZELCAST_DISCOVERY_TC
import static io.prestosql.statestore.StateStoreConstants.STATE_STORE_CLUSTER_PROPERTY_NAME;
import static io.prestosql.statestore.StateStoreConstants.STATE_STORE_CONFIGURATION_PATH;
import static io.prestosql.statestore.StateStoreConstants.STATE_STORE_TYPE_PROPERTY_NAME;
import static io.prestosql.util.PropertiesUtil.loadProperties;
import static java.util.Objects.requireNonNull;
/**
@ -106,7 +106,7 @@ public class EmbeddedStateStoreLauncher
}
if (STATE_STORE_LAUNCHER_CONFIGURATION.exists()) {
Map<String, String> properties = new HashMap<>(loadProperties(STATE_STORE_LAUNCHER_CONFIGURATION));
Map<String, String> properties = new HashMap<>(loadPropertiesFrom(STATE_STORE_LAUNCHER_CONFIGURATION.getPath()));
Set<String> staticSeeds = getStateStoreStaticSeeds(properties);
if (staticSeeds.size() > 0) {
launchStateStore(staticSeeds, properties);

View File

@ -30,11 +30,11 @@ import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import static com.google.common.base.Preconditions.checkState;
import static io.airlift.configuration.ConfigurationLoader.loadPropertiesFrom;
import static io.prestosql.spi.StandardErrorCode.STATE_STORE_FAILURE;
import static io.prestosql.statestore.StateStoreConstants.STATE_STORE_CONFIGURATION_PATH;
import static io.prestosql.statestore.StateStoreConstants.STATE_STORE_NAME_PROPERTY_NAME;
import static io.prestosql.statestore.StateStoreConstants.STATE_STORE_TYPE_PROPERTY_NAME;
import static io.prestosql.util.PropertiesUtil.loadProperties;
import static java.lang.String.format;
import static java.util.Objects.requireNonNull;
@ -74,7 +74,7 @@ public class LocalStateStoreProvider
throws Exception
{
if (STATE_STORE_CONFIGURATION.exists()) {
Map<String, String> properties = new HashMap<>(loadProperties(STATE_STORE_CONFIGURATION));
Map<String, String> properties = new HashMap<>(loadPropertiesFrom(STATE_STORE_CONFIGURATION.getPath()));
String stateStoreType = properties.remove(STATE_STORE_TYPE_PROPERTY_NAME);
setStateStore(stateStoreType, properties);
createStateCollections();

View File

@ -1,38 +0,0 @@
/*
* Licensed 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 io.prestosql.util;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
import java.util.Properties;
import static com.google.common.collect.Maps.fromProperties;
public final class PropertiesUtil
{
private PropertiesUtil() {}
public static Map<String, String> loadProperties(File file)
throws IOException
{
Properties properties = new Properties();
try (InputStream in = new FileInputStream(file)) {
properties.load(in);
}
return fromProperties(properties);
}
}

View File

@ -33,7 +33,7 @@ import java.util.Properties;
import java.util.UUID;
import static com.google.common.collect.Maps.fromProperties;
import static io.prestosql.util.PropertiesUtil.loadProperties;
import static io.airlift.configuration.ConfigurationLoader.loadPropertiesFrom;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
@ -115,8 +115,8 @@ public class TestCatalogStore
private boolean isPropertiesEqual(Path first, Path second)
throws IOException
{
Map<String, String> firstProperties = loadProperties(first.toFile());
Map<String, String> secondProperties = loadProperties(second.toFile());
Map<String, String> firstProperties = loadPropertiesFrom(first.toFile().getPath());
Map<String, String> secondProperties = loadPropertiesFrom(second.toFile().getPath());
if (!difference(secondProperties, firstProperties).isEmpty()) {
return false;
}