
org.apache.flink.util.GlobalConfigUtil Maven / Gradle / Ivy
/*
* 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.flink.util;
import org.apache.flink.configuration.ConfigConstants;
import org.apache.flink.configuration.GlobalConfiguration;
import java.io.File;
/**
* A utility class of the global configration.
*/
public class GlobalConfigUtil {
// configuration dir parameters
private static final String CONFIG_DIRECTORY_FALLBACK_1 = "../conf";
private static final String CONFIG_DIRECTORY_FALLBACK_2 = "conf";
/**
* Gets the directory of the global configuration from the current environment.
*
* @return a valid configuration directory if it can be found, otherwise a {@link RuntimeException} is thrown.
*/
public static String getValidConfigurationDirectoryFromEnv() {
String configDir = getConfigurationDirectoryFromEnv();
if (configDir == null) {
throw new RuntimeException("The configuration directory was not specified. " +
"Please specify the directory containing the configuration file through the '" +
ConfigConstants.ENV_FLINK_CONF_DIR + "' environment variable.");
}
return configDir;
}
/**
* Gets the directory of the global configuration from the current environment.
*
* @return a valid configuration directory if it can be found. Otherwise {@code null} is returned or a
* {@link RuntimeException} is thrown (when the directory specified by {@link ConfigConstants#ENV_FLINK_CONF_DIR}
* environment variable does not exist.
*/
public static String getConfigurationDirectoryFromEnv() {
String location = System.getenv(ConfigConstants.ENV_FLINK_CONF_DIR);
if (location != null) {
if (!new File(location).exists()) {
throw new RuntimeException("The configuration directory '" + location + "', specified in the '" +
ConfigConstants.ENV_FLINK_CONF_DIR + "' environment variable, does not exist.");
}
} else if (new File(getFlinkConfFile(CONFIG_DIRECTORY_FALLBACK_1)).exists()) {
location = CONFIG_DIRECTORY_FALLBACK_1;
} else if (new File(getFlinkConfFile(CONFIG_DIRECTORY_FALLBACK_2)).exists()) {
location = CONFIG_DIRECTORY_FALLBACK_2;
}
return (location != null) ? new File(location).getAbsolutePath() : null;
}
private static String getFlinkConfFile(String path) {
return path + File.separatorChar + GlobalConfiguration.FLINK_CONF_FILENAME;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy