Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.commons.cli.Options;
import org.apache.solr.common.cloud.SolrZkClient;
import org.apache.solr.common.cloud.ZkMaintenanceUtils;
import org.apache.solr.common.util.EnvUtils;
import org.apache.solr.core.ConfigSetService;
import org.apache.solr.util.FileTypeMagicUtil;
import org.slf4j.Logger;
Expand Down Expand Up @@ -77,7 +78,7 @@ public String getUsage() {
public void runImpl(CommandLine cli) throws Exception {
String zkHost = CLIUtils.getZkHost(cli);

final String solrInstallDir = System.getProperty("solr.install.dir");
final String solrInstallDir = EnvUtils.getProperty("solr.install.dir");
Path solrInstallDirPath = Path.of(solrInstallDir);

String confName = cli.getOptionValue(CONF_NAME_OPTION);
Expand Down
5 changes: 3 additions & 2 deletions solr/core/src/java/org/apache/solr/cli/CreateTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.apache.solr.client.solrj.response.SystemInfoResponse;
import org.apache.solr.cloud.ZkConfigSetService;
import org.apache.solr.common.cloud.ZkStateReader;
import org.apache.solr.common.util.EnvUtils;
import org.apache.solr.core.ConfigSetService;

/** Supports create command in the bin/solr script. */
Expand Down Expand Up @@ -135,7 +136,7 @@ protected void createCore(CommandLine cli, SolrClient solrClient) throws Excepti
String coreName = cli.getOptionValue(COLLECTION_NAME_OPTION);
String solrUrl = CLIUtils.normalizeSolrUrl(cli);

final String solrInstallDir = System.getProperty("solr.install.dir");
final String solrInstallDir = EnvUtils.getProperty("solr.install.dir");
final String confDirName =
cli.getOptionValue(CONF_DIR_OPTION, DefaultValues.DEFAULT_CONFIG_SET);

Expand Down Expand Up @@ -217,7 +218,7 @@ protected void createCollection(CloudSolrClient cloudSolrClient, CommandLine cli
throws Exception {

String collectionName = cli.getOptionValue(COLLECTION_NAME_OPTION);
final String solrInstallDir = System.getProperty("solr.install.dir");
final String solrInstallDir = EnvUtils.getProperty("solr.install.dir");
String confName = cli.getOptionValue(CONF_NAME_OPTION);
String confDir = cli.getOptionValue(CONF_DIR_OPTION, DefaultValues.DEFAULT_CONFIG_SET);
Path solrInstallDirPath = Path.of(solrInstallDir);
Expand Down
5 changes: 3 additions & 2 deletions solr/core/src/java/org/apache/solr/cli/SolrCLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.request.ContentStreamUpdateRequest;
import org.apache.solr.common.util.ContentStreamBase;
import org.apache.solr.common.util.EnvUtils;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SuppressForbidden;
import org.apache.solr.util.configuration.SSLConfigurationsFactory;
Expand Down Expand Up @@ -143,7 +144,7 @@ public static CommandLine parseCmdLine(Tool tool, String[] args) throws IOExcept
argList.addAll(dashDList);

// for SSL support, try to accommodate relative paths set for SSL store props
String solrInstallDir = System.getProperty("solr.install.dir");
String solrInstallDir = EnvUtils.getProperty("solr.install.dir");
if (solrInstallDir != null) {
checkSslStoreSysProp(solrInstallDir, "keyStore");
checkSslStoreSysProp(solrInstallDir, "trustStore");
Expand All @@ -154,7 +155,7 @@ public static CommandLine parseCmdLine(Tool tool, String[] args) throws IOExcept

protected static void checkSslStoreSysProp(String solrInstallDir, String key) {
String sysProp = "javax.net.ssl." + key;
String keyStore = System.getProperty(sysProp);
String keyStore = EnvUtils.getProperty(sysProp);
if (keyStore == null) return;

Path keyStoreFile = Path.of(keyStore);
Expand Down
3 changes: 2 additions & 1 deletion solr/core/src/java/org/apache/solr/cli/ZkCpTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.apache.solr.common.SolrException;
import org.apache.solr.common.cloud.SolrZkClient;
import org.apache.solr.common.util.Compressor;
import org.apache.solr.common.util.EnvUtils;
import org.apache.solr.common.util.StrUtils;
import org.apache.solr.common.util.ZLibCompressor;
import org.apache.solr.core.NodeConfig;
Expand Down Expand Up @@ -154,7 +155,7 @@ public void runImpl(CommandLine cli) throws Exception {
if (dstIsZk) {
String solrHome = cli.getOptionValue(SOLR_HOME_OPTION);
if (StrUtils.isNullOrEmpty(solrHome)) {
solrHome = System.getProperty("solr.home");
solrHome = EnvUtils.getProperty("solr.home", EnvUtils.getProperty("solr.solr.home"));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The solr.solr.home thing was always a bit werid... But is a "thing". What prompted this change here?

}

if (solrHome != null) {
Expand Down
4 changes: 2 additions & 2 deletions solr/core/src/java/org/apache/solr/cloud/SolrZkServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void parseConfig() {
var zooCfgPath = Path.of(confHome).resolve("zoo.cfg");
if (!Files.exists(zooCfgPath)) {
log.info("Zookeeper configuration not found in {}, using built-in default", confHome);
String solrInstallDir = System.getProperty(CoreContainerProvider.SOLR_INSTALL_DIR);
String solrInstallDir = EnvUtils.getProperty(CoreContainerProvider.SOLR_INSTALL_DIR);
if (solrInstallDir == null) {
throw new SolrException(
SolrException.ErrorCode.SERVER_ERROR,
Expand Down Expand Up @@ -142,7 +142,7 @@ public void start() {
}

ensureZkMaxCnxnsConfigured();
if (System.getProperty(ZK_WHITELIST_PROPERTY) == null) {
if (EnvUtils.getProperty(ZK_WHITELIST_PROPERTY) == null) {
System.setProperty(ZK_WHITELIST_PROPERTY, "ruok, mntr, conf");
}
AtomicReference<Exception> zkException = new AtomicReference<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.solr.cluster.placement.plugins.RandomPlacementFactory;
import org.apache.solr.cluster.placement.plugins.SimplePlacementFactory;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.util.EnvUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -102,7 +103,7 @@ private void setDelegate(
/** Returns the default {@link PlacementPluginFactory} */
public static PlacementPluginFactory<?> getDefaultPlacementPluginFactory() {
// Use the default provided by system properties.
String defaultPluginId = System.getProperty(PLACEMENTPLUGIN_DEFAULT_SYSPROP);
String defaultPluginId = EnvUtils.getProperty(PLACEMENTPLUGIN_DEFAULT_SYSPROP);
if (defaultPluginId != null) {
log.info(
"Default replica placement plugin set in {} to {}",
Expand Down
6 changes: 3 additions & 3 deletions solr/core/src/java/org/apache/solr/core/ConfigSetService.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ private void bootstrapDefaultConf() throws IOException {
log.warn(
"The _default configset could not be uploaded. Please provide 'solr.configset.default.confdir' parameter that points to a configset {} {}",
"intended to be the default. Current 'solr.configset.default.confdir' value:",
System.getProperty(SOLR_CONFIGSET_DEFAULT_CONFDIR));
EnvUtils.getProperty(SOLR_CONFIGSET_DEFAULT_CONFDIR));
} else {
this.uploadConfig(ConfigSetsHandler.DEFAULT_CONFIGSET_NAME, configDirPath);
}
Expand Down Expand Up @@ -165,15 +165,15 @@ private void bootstrapConfDir(String confDir) throws IOException {
* @see ConfigSetService#SOLR_CONFIGSET_DEFAULT_CONFDIR
*/
public static Path getDefaultConfigDirPath() {
String confDir = System.getProperty(SOLR_CONFIGSET_DEFAULT_CONFDIR);
String confDir = EnvUtils.getProperty(SOLR_CONFIGSET_DEFAULT_CONFDIR);
if (confDir != null) {
Path path = Path.of(confDir);
if (Files.exists(path)) {
return path;
}
}

String installDir = System.getProperty(CoreContainerProvider.SOLR_INSTALL_DIR);
String installDir = EnvUtils.getProperty(CoreContainerProvider.SOLR_INSTALL_DIR);
if (installDir != null) {
Path subPath = Path.of("server", "solr", "configsets", "_default", "conf");
Path path = Path.of(installDir).resolve(subPath);
Expand Down
25 changes: 14 additions & 11 deletions solr/core/src/java/org/apache/solr/core/CoreContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ public JerseyAppHandlerCache getJerseyAppHandlerCache() {

private final ObjectCache objectCache = new ObjectCache();

public final NodeRoles nodeRoles = new NodeRoles(System.getProperty(NodeRoles.NODE_ROLES_PROP));
public final NodeRoles nodeRoles = new NodeRoles(EnvUtils.getProperty(NodeRoles.NODE_ROLES_PROP));

private final ExecutorService indexSearcherExecutor;

Expand Down Expand Up @@ -556,14 +556,17 @@ private synchronized void initializeAuthenticationPlugin(

if (pluginClassName != null) {
log.debug("Authentication plugin class obtained from security.json: {}", pluginClassName);
} else if (System.getProperty(AUTHENTICATION_PLUGIN_PROP) != null) {
pluginClassName = System.getProperty(AUTHENTICATION_PLUGIN_PROP);
log.debug(
"Authentication plugin class obtained from system property '{}': {}",
AUTHENTICATION_PLUGIN_PROP,
pluginClassName);
} else {
log.debug("No authentication plugin used.");
String authPluginProp = EnvUtils.getProperty(AUTHENTICATION_PLUGIN_PROP);
if (authPluginProp != null) {
pluginClassName = authPluginProp;
log.debug(
"Authentication plugin class obtained from system property '{}': {}",
AUTHENTICATION_PLUGIN_PROP,
pluginClassName);
} else {
log.debug("No authentication plugin used.");
}
}
SecurityPluginHolder<AuthenticationPlugin> old = authenticationPlugin;
SecurityPluginHolder<AuthenticationPlugin> authenticationPlugin = null;
Expand Down Expand Up @@ -1141,7 +1144,7 @@ private void warnUsersOfInsecureSettings() {
}

if (authenticationPlugin != null
&& StrUtils.isNullOrEmpty(System.getProperty("solr.jetty.https.port"))) {
&& StrUtils.isNullOrEmpty(EnvUtils.getProperty("solr.jetty.https.port"))) {
log.warn(
"Solr authentication is enabled, but SSL is off. Consider enabling SSL to protect user credentials and data with encryption.");
}
Expand Down Expand Up @@ -1768,7 +1771,7 @@ private SolrCore processCoreCreateException(

CoreInitFailedAction action =
CoreInitFailedAction.valueOf(
System.getProperty(CoreInitFailedAction.class.getSimpleName(), "none"));
EnvUtils.getProperty(CoreInitFailedAction.class.getSimpleName(), "none"));
log.debug("CorruptIndexException while creating core, will attempt to repair via {}", action);

switch (action) {
Expand Down Expand Up @@ -2500,7 +2503,7 @@ public void runAsync(Runnable r) {
}

public static void setWeakStringInterner() {
boolean enable = "true".equals(System.getProperty("solr.use.str.intern", "true"));
boolean enable = "true".equals(EnvUtils.getProperty("solr.use.str.intern", "true"));
if (!enable) return;
Interner<String> interner = Interner.newWeakInterner();
ClusterState.setStrInternerParser(
Expand Down
4 changes: 2 additions & 2 deletions solr/core/src/java/org/apache/solr/core/NodeConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ public Path getSolrDataHome() {
* @return path to install dir or null if solr.install.dir not set.
*/
public static Path getSolrInstallDir() {
String prop = System.getProperty(CoreContainerProvider.SOLR_INSTALL_DIR);
String prop = EnvUtils.getProperty(CoreContainerProvider.SOLR_INSTALL_DIR);
if (prop == null || prop.isBlank()) {
log.debug("solr.install.dir property not initialized.");
return null;
Expand Down Expand Up @@ -644,7 +644,7 @@ public NodeConfigBuilder(String nodeName, Path solrHome) {
this.solrHome = solrHome.toAbsolutePath();
this.coreRootDirectory = solrHome;
// always init from sysprop because <solrDataHome> config element may be missing
setSolrDataHome(System.getProperty(SolrXmlConfig.SOLR_DATA_HOME));
setSolrDataHome(EnvUtils.getProperty(SolrXmlConfig.SOLR_DATA_HOME));
setConfigSetBaseDirectory("configsets");
this.metricsConfig = new MetricsConfig.MetricsConfigBuilder().build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ static boolean shouldAutoConfigOTEL() {
*/
protected static String getConfig(String envName, Map<String, String> env) {
String sysName = envNameToSyspropName(envName);
String sysValue = System.getProperty(sysName);
String sysValue = EnvUtils.getProperty(sysName);
String envValue = env.get(envName);
return sysValue != null ? sysValue : envValue;
}
Expand Down
4 changes: 2 additions & 2 deletions solr/core/src/java/org/apache/solr/core/SolrXmlConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static Properties wrapAndSetZkHostFromSysPropIfNeeded(final Properties pr
}
// we always wrap if we might set a property -- never mutate the original props
final Properties results = (null == props ? new Properties() : new Properties(props));
final String sysprop = System.getProperty(ZK_HOST);
final String sysprop = EnvUtils.getProperty(ZK_HOST);
if (StrUtils.isNotNullOrEmpty(sysprop)) {
results.setProperty(ZK_HOST, sysprop);
}
Expand Down Expand Up @@ -179,7 +179,7 @@ public static NodeConfig fromFile(Path solrHome, Path configFile, Properties sub
"solr.xml does not exist in " + configFile.getParent() + " cannot start Solr");
}
log.info("solr.xml not found in SOLR_HOME, using built-in default");
String solrInstallDir = System.getProperty(CoreContainerProvider.SOLR_INSTALL_DIR);
String solrInstallDir = EnvUtils.getProperty(CoreContainerProvider.SOLR_INSTALL_DIR);
if (solrInstallDir == null) {
throw new SolrException(
SolrException.ErrorCode.SERVER_ERROR,
Expand Down
2 changes: 1 addition & 1 deletion solr/core/src/java/org/apache/solr/core/ZkContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public void initZooKeeper(final CoreContainer cc, CloudConfig config) {
new ZkController(cc, zookeeperHost, zkClientConnectTimeout, config);

if (zkRun) {
if (StrUtils.isNotNullOrEmpty(System.getProperty(HTTPS_PORT_PROP))) {
if (StrUtils.isNotNullOrEmpty(EnvUtils.getProperty(HTTPS_PORT_PROP))) {
// Embedded ZK and probably running with SSL
new ClusterProperties(zkController.getZkClient())
.setClusterProperty(ZkStateReader.URL_SCHEME, HTTPS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.regex.Pattern;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.cloud.ZkStateReader;
import org.apache.solr.common.util.EnvUtils;

/**
* It is possible to define an environment code when starting Solr, through
Expand Down Expand Up @@ -87,8 +88,8 @@ public static SolrEnvironment parse(String environmentString) {
*/
public static SolrEnvironment getFromSyspropOrClusterprop(ZkStateReader zkStateReader) {
String env = "unknown";
if (System.getProperty("solr.environment") != null) {
env = System.getProperty("solr.environment");
if (EnvUtils.getProperty("solr.environment") != null) {
env = EnvUtils.getProperty("solr.environment");
} else if (zkStateReader != null) {
env = zkStateReader.getClusterProperty("environment", "unknown");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,8 @@ private String initUrlScheme(NamedList<?> args, StringBuilder sb) {
if (isSolrSslEnabled != null) {
return isSolrSslEnabled ? "https" : "http";
}
String urlScheme = getParameter(args, INIT_URL_SCHEME, System.getProperty(INIT_URL_SCHEME), sb);
String urlScheme =
getParameter(args, INIT_URL_SCHEME, EnvUtils.getProperty(INIT_URL_SCHEME), sb);
if (urlScheme != null && urlScheme.endsWith("://")) {
urlScheme = urlScheme.replace("://", "");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,13 @@ private void init(ServletContext servletContext) {

logWelcomeBanner(extraProperties);

String muteConsole = System.getProperty(SOLR_LOG_MUTECONSOLE);
String muteConsole = EnvUtils.getProperty(SOLR_LOG_MUTECONSOLE);
if (muteConsole != null
&& !Arrays.asList("false", "0", "off", "no")
.contains(muteConsole.toLowerCase(Locale.ROOT))) {
StartupLoggingUtils.muteConsole();
}
String logLevel = System.getProperty(SOLR_LOG_LEVEL);
String logLevel = EnvUtils.getProperty(SOLR_LOG_LEVEL);
if (logLevel != null) {
log.info("Log level override, property solr.log.level={}", logLevel);
StartupLoggingUtils.changeLogLevel(logLevel);
Expand Down Expand Up @@ -208,7 +208,7 @@ private void logWelcomeBanner(Properties props) {
getSolrPort());
}
if (log.isInfoEnabled()) {
log.info("\\__ \\/ _ \\ | '_| Install dir: {}", System.getProperty(SOLR_INSTALL_DIR));
log.info("\\__ \\/ _ \\ | '_| Install dir: {}", EnvUtils.getProperty(SOLR_INSTALL_DIR));
}
if (log.isInfoEnabled()) {
log.info("|___/\\___/_|_| Start time: {}", Instant.now());
Expand Down Expand Up @@ -241,7 +241,7 @@ private void logWelcomeBanner(Properties props) {
"Solr typically starts with \"-XX:+CrashOnOutOfMemoryError\" that will crash on any OutOfMemoryError exception. "
+ "Unable to get the specific file due to an exception."
+ "The cause of the OOME will be logged in a crash file in the logs directory: %s",
System.getProperty("solr.logs.dir"));
EnvUtils.getProperty("solr.logs.dir"));
log.info(logMessage, e);
}
}
Expand Down Expand Up @@ -316,7 +316,7 @@ private static Path computeSolrHome(ServletContext servletContext) {
// Now try system property
final String prop = "solr.solr.home";
source = "system property: " + prop;
home = System.getProperty(prop);
home = EnvUtils.getProperty(prop);
}

if (null == home) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.Arrays;
import java.util.List;
import org.apache.commons.io.output.CloseShieldOutputStream;
import org.apache.solr.common.util.EnvUtils;
import org.apache.solr.core.SolrCore;

/**
Expand All @@ -40,8 +41,7 @@
public final class LoadAdminUiServlet extends HttpServlet {

// check system properties for whether the admin UI is disabled, default is false
private static final boolean uiEnabled =
Boolean.parseBoolean(System.getProperty("solr.ui.enabled", "true"));
private static final boolean uiEnabled = EnvUtils.getPropertyAsBool("solr.ui.enabled", true);
// list of comma separated URLs to inject into the CSP connect-src directive
public static final String SYSPROP_CSP_CONNECT_SRC_URLS = "solr.ui.headers.csp.connect-src.urls";

Expand Down Expand Up @@ -107,7 +107,7 @@ private String getSolrCorePackageSpecVersion() {
* concatenate them into a space-separated string that can be used in CSP connect-src directive
*/
private String generateCspConnectSrc() {
String cspURLs = System.getProperty(SYSPROP_CSP_CONNECT_SRC_URLS, "");
String cspURLs = EnvUtils.getProperty(SYSPROP_CSP_CONNECT_SRC_URLS, "");
List<String> props = new ArrayList<>(Arrays.asList(cspURLs.split(",")));
props.add("'self'");
return String.join(" ", props);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.Locale;
import java.util.Set;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.util.EnvUtils;

/** Utility class to guess the mime type of file based on its magic number. */
public class FileTypeMagicUtil implements ContentInfoUtil.ErrorCallBack {
Expand Down Expand Up @@ -194,7 +195,7 @@ public static boolean isFileForbiddenInConfigset(byte[] bytes) {
private static final Set<String> forbiddenTypes =
new HashSet<>(
Arrays.asList(
System.getProperty(
EnvUtils.getProperty(
"solr.configset.upload.mimetypes.forbidden",
"application/x-java-applet,application/zip,application/x-tar,text/x-shellscript")
.split(",")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,11 @@ public static String getLogLevelString() {
* "solr.logs.requestlog.enabled is set in solr/server/etc/jetty-requestlog.xml
*/
public static void checkRequestLogging() {
// EnvUtils doesn't work here.
// Note: "solr.logs.requestlog.enabled" is deliberately excluded from EnvUtils
// env var mapping (see EnvToSyspropMappings.properties), so Boolean.getBoolean
// is the correct way to read it (it only looks at system properties).
boolean requestLogEnabled = Boolean.getBoolean("solr.logs.requestlog.enabled");
String retainDays = System.getProperty("solr.logs.requestlog.retain.days");
String retainDays = EnvUtils.getProperty("solr.logs.requestlog.retain.days");
if (requestLogEnabled) {
if (retainDays == null) {
log.warn(
Expand Down
Loading
Loading