/** A helper method for checking if all mandatory apps are present. */ private void checkMandatory() { String[] mandatoryApps = settings.getAsArray("apps.mandatory", null); if (mandatoryApps != null) { Set<String> missingApps = Sets.newHashSet(); for (String mandatoryApp : mandatoryApps) { boolean found = false; // do not check versions for (App app : apps.values()) { String appName = app.groupId() + ":" + app.artifactId(); if (mandatoryApp.startsWith(appName)) { found = true; } } if (!found && !missingApps.contains(mandatoryApp)) { missingApps.add(mandatoryApp); } } if (!missingApps.isEmpty()) { throw new ElasticSearchException( "Missing mandatory apps [" + Strings.collectionToDelimitedString(missingApps, ", ") + "]"); } } }
/** * Prepares the settings by gathering all elasticsearch system properties, optionally loading the * configuration settings, and then replacing all property placeholders. If a {@link Terminal} is * provided and configuration settings are loaded, settings with a value of <code>${prompt.text} * </code> or <code>${prompt.secret}</code> will result in a prompt for the setting to the user. * * @param input The custom settings to use. These are not overwritten by settings in the * configuration file. * @param terminal the Terminal to use for input/output * @return the {@link Settings} and {@link Environment} as a {@link Tuple} */ public static Environment prepareEnvironment(Settings input, Terminal terminal) { // just create enough settings to build the environment, to get the config dir Settings.Builder output = settingsBuilder(); initializeSettings(output, input, true); Environment environment = new Environment(output.build()); boolean settingsFileFound = false; Set<String> foundSuffixes = new HashSet<>(); for (String allowedSuffix : ALLOWED_SUFFIXES) { Path path = environment.configFile().resolve("elasticsearch" + allowedSuffix); if (Files.exists(path)) { if (!settingsFileFound) { output.loadFromPath(path); } settingsFileFound = true; foundSuffixes.add(allowedSuffix); } } if (foundSuffixes.size() > 1) { throw new SettingsException( "multiple settings files found with suffixes: " + Strings.collectionToDelimitedString(foundSuffixes, ",")); } // re-initialize settings now that the config file has been loaded // TODO: only re-initialize if a config file was actually loaded initializeSettings(output, input, false); finalizeSettings(output, terminal, environment.configFile()); environment = new Environment(output.build()); // we put back the path.logs so we can use it in the logging configuration file output.put( Environment.PATH_LOGS_SETTING.getKey(), cleanPath(environment.logsFile().toAbsolutePath().toString())); return new Environment(output.build()); }