public void testMultipleSettingsFileNotAllowed() throws IOException { InputStream yaml = getClass().getResourceAsStream("/config/elasticsearch.yaml"); InputStream properties = getClass().getResourceAsStream("/config/elasticsearch.properties"); Path home = createTempDir(); Path config = home.resolve("config"); Files.createDirectory(config); Files.copy(yaml, config.resolve("elasticsearch.yaml")); Files.copy(properties, config.resolve("elasticsearch.properties")); try { InternalSettingsPreparer.prepareEnvironment(Settings.builder() .put(baseEnvSettings) .build(), null); } catch (SettingsException e) { assertTrue(e.getMessage(), e.getMessage().contains("multiple settings files found with suffixes")); assertTrue(e.getMessage(), e.getMessage().contains(".yaml")); assertTrue(e.getMessage(), e.getMessage().contains(".properties")); } }
@Override protected Settings nodeSettings(int nodeOrdinal) { Settings.Builder settings = Settings.builder() .put(super.nodeSettings(nodeOrdinal)) .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()); // if explicit, just load it and don't load from env try { if (Strings.hasText(System.getProperty("tests.config"))) { try { settings.loadFromPath(PathUtils.get(System.getProperty("tests.config"))); } catch (IOException e) { throw new IllegalArgumentException("could not load aws tests config", e); } } else { throw new IllegalStateException("to run integration tests, you need to set -Dtests.thirdparty=true and -Dtests.config=/path/to/elasticsearch.yml"); } } catch (SettingsException exception) { throw new IllegalStateException("your test configuration file is incorrect: " + System.getProperty("tests.config"), exception); } return settings.build(); }
private static AzureStorageSettings getPrimary(List<AzureStorageSettings> settings) { if (settings.isEmpty()) { return null; } else if (settings.size() == 1) { // the only storage settings belong (implicitly) to the default primary storage AzureStorageSettings storage = settings.get(0); return new AzureStorageSettings(storage.getName(), storage.getAccount(), storage.getKey(), storage.getTimeout(), true); } else { AzureStorageSettings primary = null; for (AzureStorageSettings setting : settings) { if (setting.isActiveByDefault()) { if (primary == null) { primary = setting; } else { throw new SettingsException("Multiple default Azure data stores configured: [" + primary.getName() + "] and [" + setting.getName() + "]"); } } } if (primary == null) { throw new SettingsException("No default Azure data store configured"); } return primary; } }
public void testParseTwoSettingsTooManyDefaultSet() { Settings settings = Settings.builder() .put("cloud.azure.storage.azure1.account", "myaccount1") .put("cloud.azure.storage.azure1.key", "mykey1") .put("cloud.azure.storage.azure1.default", true) .put("cloud.azure.storage.azure2.account", "myaccount2") .put("cloud.azure.storage.azure2.key", "mykey2") .put("cloud.azure.storage.azure2.default", true) .build(); try { AzureStorageSettings.parse(settings); fail("Should have failed with a SettingsException (multiple default data stores)"); } catch (SettingsException ex) { assertEquals(ex.getMessage(), "Multiple default Azure data stores configured: [azure1] and [azure2]"); } }
/** * Read settings from file when running integration tests with ThirdParty annotation. * elasticsearch.yml file path has to be set with -Dtests.config=/path/to/elasticsearch.yml. * @return Settings from elasticsearch.yml integration test file (for 3rd party tests) */ public static Settings readSettingsFromFile() { Settings.Builder settings = Settings.builder(); // if explicit, just load it and don't load from env try { if (Strings.hasText(System.getProperty("tests.config"))) { try { settings.loadFromPath(PathUtils.get((System.getProperty("tests.config")))); } catch (IOException e) { throw new IllegalArgumentException("could not load azure tests config", e); } } else { throw new IllegalStateException("to run integration tests, you need to set -Dtests.thirdparty=true and " + "-Dtests.config=/path/to/elasticsearch.yml"); } } catch (SettingsException exception) { throw new IllegalStateException("your test configuration file is incorrect: " + System.getProperty("tests.config"), exception); } return settings.build(); }
@Override protected Settings nodeSettings(int nodeOrdinal) { Settings.Builder settings = Settings.builder() .put(super.nodeSettings(nodeOrdinal)) .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()) .put("cloud.aws.test.random", randomInt()) .put("cloud.aws.test.write_failures", 0.1) .put("cloud.aws.test.read_failures", 0.1); // if explicit, just load it and don't load from env try { if (Strings.hasText(System.getProperty("tests.config"))) { try { settings.loadFromPath(PathUtils.get(System.getProperty("tests.config"))); } catch (IOException e) { throw new IllegalArgumentException("could not load aws tests config", e); } } else { throw new IllegalStateException("to run integration tests, you need to set -Dtests.thirdparty=true and -Dtests.config=/path/to/elasticsearch.yml"); } } catch (SettingsException exception) { throw new IllegalStateException("your test configuration file is incorrect: " + System.getProperty("tests.config"), exception); } return settings.build(); }
/** * Validates a given blobs data path */ public void validateBlobsPath(File blobsPath) { if (blobsPath.exists()) { if (blobsPath.isFile()) { throw new SettingsException( String.format(Locale.ENGLISH, "blobs path '%s' is a file, must be a directory", blobsPath.getAbsolutePath())); } if (!blobsPath.canWrite()) { throw new SettingsException( String.format(Locale.ENGLISH, "blobs path '%s' is not writable", blobsPath.getAbsolutePath())); } } else { try { Files.createDirectories(blobsPath.toPath()); } catch (IOException e) { throw new SettingsException( String.format(Locale.ENGLISH, "blobs path '%s' could not be created", blobsPath.getAbsolutePath())); } } }
/** * Load settings from resource file * * @return * @throws Exception */ ImmutableSettings.Builder loadSettings() throws Exception { ImmutableSettings.Builder settings = ImmutableSettings.settingsBuilder(); // set default settings settings.put("client.transport.sniff", sniffing); if (clusterName != null) { settings.put("cluster.name", clusterName); } // load settings if (localConfig != null) { Logger.debug("Elasticsearch : Load settings from " + localConfig); try { settings.loadFromClasspath(localConfig); } catch (SettingsException settingsException) { Logger.error("Elasticsearch : Error when loading settings from " + localConfig); throw new Exception(settingsException); } } settings.build(); Logger.info("Elasticsearch : Settings " + settings.internalMap().toString()); return settings; }
protected void handleHighlightSettings(QuerySettings querySettings, SearchRequestBuilder srb) { if (querySettings.getQuery() != null && querySettings.isQueryHighlight()) { Map<String, Object> hf = configService.get(ConfigService.CFGNAME_SEARCH_FULLTEXT_HIGHLIGHT_FIELDS); if (hf != null && !hf.isEmpty()) { srb.setHighlighterPreTags("<span class='hlt'>"); srb.setHighlighterPostTags("</span>"); srb.setHighlighterEncoder("html"); for (String fieldName : hf.keySet()) { srb.addHighlightedField(fieldName, parseHighlightSettingIntParam(hf, fieldName, "fragment_size"), parseHighlightSettingIntParam(hf, fieldName, "number_of_fragments"), parseHighlightSettingIntParam(hf, fieldName, "fragment_offset")); } } else { throw new SettingsException( "Fulltext search highlight requested but not configured by DCP configuration document " + ConfigService.CFGNAME_SEARCH_FULLTEXT_HIGHLIGHT_FIELDS + ". Contact administrators please."); } } }
/** * Get configuration for one <code>dcp_content_type</code> from provider configuration. * * @param providerDef provider configuration structure * @param typeName name of <code>dcp_content_type</code> to get configuration for * @return type configuration or null if doesn't exist * @throws SettingsException for incorrect configuration structure */ @SuppressWarnings("unchecked") public static Map<String, Object> extractContentType(Map<String, Object> providerDef, String typeName) { try { Map<String, Object> types = (Map<String, Object>) providerDef.get(TYPE); if (types != null) { if (types.containsKey(typeName)) { return (Map<String, Object>) types.get(typeName); } } return null; } catch (ClassCastException e) { throw new SettingsException("Incorrect configuration for provider '" + providerDef.get(NAME) + "' when trying to find dcp_provider_type=" + typeName + ". Contact administrators please."); } }
/** * Get search subsystem index name from one <code>dcp_content_type</code> configuration structure. * * @param typeDef <code>dcp_content_type</code> configuration structure * @param typeName <code>dcp_content_type</code> name to be used for error messages * @return search index name */ @SuppressWarnings("unchecked") public static String extractIndexName(Map<String, Object> typeDef, String typeName) { try { String ret = null; if (typeDef.get(INDEX) != null) ret = (String) ((Map<String, Object>) typeDef.get(INDEX)).get(NAME); if (ret == null || ret.trim().isEmpty()) throw new SettingsException("Incorrect configuration of 'index.name' for dcp_provider_type='" + typeName + "'. SearchBackend index name is not defined. Contact administrators please."); return ret; } catch (ClassCastException e) { throw new SettingsException("Incorrect structure of 'index' configuration for dcp_provider_type='" + typeName + "'. Contact administrators please."); } }
/** * Get search subsystem type name from one <code>dcp_content_type</code> configuration structure. * * @param typeDef <code>dcp_content_type</code> configuration structure * @param typeName <code>dcp_content_type</code> name to be used for error messages * @return search type name */ @SuppressWarnings("unchecked") public static String extractIndexType(Map<String, Object> typeDef, String typeName) { try { String ret = null; if (typeDef.get(INDEX) != null) ret = (String) ((Map<String, Object>) typeDef.get(INDEX)).get(TYPE); if (ret == null || ret.trim().isEmpty()) throw new SettingsException("Incorrect configuration of 'index.type' for dcp_provider_type='" + typeName + "'. SearchBackend index type is not defined. Contact administrators please."); return ret; } catch (ClassCastException e) { throw new SettingsException("Incorrect structure of 'index' configuration for dcp_provider_type='" + typeName + "'. Contact administrators please."); } }
@Test public void extractAllContentTypes() { Map<String, Object> providerDef = new HashMap<String, Object>(); // case - type field not defined Assert.assertNull(ProviderService.extractAllContentTypes(providerDef)); Map<String, Object> types = new HashMap<String, Object>(); providerDef.put(ProviderService.TYPE, types); // case - type field defined Assert.assertEquals(types, ProviderService.extractAllContentTypes(providerDef)); // case - bad class of type field providerDef.put(ProviderService.TYPE, "baaad"); try { ProviderService.extractAllContentTypes(providerDef); Assert.fail("SettingsException expected"); } catch (SettingsException e) { // OK } }
/** * @param querySettings * @param srb */ protected void setSearchRequestHighlight(QuerySettings querySettings, SearchRequestBuilder srb) { if (querySettings.getQuery() != null && querySettings.isQueryHighlight()) { Map<String, Object> hf = configService.get(ConfigService.CFGNAME_SEARCH_FULLTEXT_HIGHLIGHT_FIELDS); if (hf != null && !hf.isEmpty()) { srb.setHighlighterPreTags("<span class='hlt'>"); srb.setHighlighterPostTags("</span>"); srb.setHighlighterEncoder("html"); for (String fieldName : hf.keySet()) { srb.addHighlightedField(fieldName, parseHighlightSettingIntParam(hf, fieldName, "fragment_size"), parseHighlightSettingIntParam(hf, fieldName, "number_of_fragments"), parseHighlightSettingIntParam(hf, fieldName, "fragment_offset")); } } else { throw new SettingsException("Fulltext search highlight requested but not configured by configuration document " + ConfigService.CFGNAME_SEARCH_FULLTEXT_HIGHLIGHT_FIELDS + "."); } } }
/** * Get configuration for one <code>sys_content_type</code> from provider configuration. * * @param providerDef provider configuration structure * @param typeName name of <code>sys_content_type</code> to get configuration for * @return type configuration or null if doesn't exist * @throws SettingsException for incorrect configuration structure */ @SuppressWarnings("unchecked") public static Map<String, Object> extractContentType(Map<String, Object> providerDef, String typeName) { try { Map<String, Object> types = (Map<String, Object>) providerDef.get(TYPE); if (types != null) { if (types.containsKey(typeName)) { return (Map<String, Object>) types.get(typeName); } } return null; } catch (ClassCastException e) { throw new SettingsException("Incorrect configuration for provider '" + providerDef.get(NAME) + "' when trying to find sys_provider_type=" + typeName + "."); } }
/** * Get search subsystem index name from one <code>sys_content_type</code> configuration structure. * * @param typeDef <code>sys_content_type</code> configuration structure * @param typeName <code>sys_content_type</code> name to be used for error messages * @return search index name */ @SuppressWarnings("unchecked") public static String extractIndexName(Map<String, Object> typeDef, String typeName) { try { String ret = null; if (typeDef.get(INDEX) != null) ret = (String) ((Map<String, Object>) typeDef.get(INDEX)).get(NAME); if (ret == null || ret.trim().isEmpty()) throw new SettingsException("Incorrect configuration of 'index.name' for sys_provider_type='" + typeName + "'. SearchBackend index name is not defined."); return ret; } catch (ClassCastException e) { throw new SettingsException("Incorrect structure of 'index' configuration for sys_provider_type='" + typeName + "'."); } }
/** * Get array of names of search indices in search subsystem used for searching values for given * <code>sys_content_type</code>. Array or string with indices name is get from * {@value ProviderService#SEARCH_INDICES} config value if exists, if not then main index name is used, see * {@link #extractIndexName(Map, String)}. * * @param typeDef <code>sys_content_type</code> configuration structure * @param typeName <code>sys_content_type</code> name to be used for error messages * @return search index name */ @SuppressWarnings("unchecked") public static String[] extractSearchIndices(Map<String, Object> typeDef, String typeName) { try { if (typeDef.get(INDEX) == null) { throw new SettingsException("Missing 'index' section in configuration for sys_provider_type='" + typeName + "'."); } Object val = ((Map<String, Object>) typeDef.get(INDEX)).get(SEARCH_INDICES); if (val == null) { return new String[] { extractIndexName(typeDef, typeName) }; } else { if (val instanceof String) { return new String[] { (String) val }; } else if (val instanceof List) { return (String[]) ((List<String>) val).toArray(new String[((List<String>) val).size()]); } else { throw new SettingsException("Incorrect configuration of 'index." + SEARCH_INDICES + "' for sys_provider_type='" + typeName + "'. Value must be string or array of strings."); } } } catch (ClassCastException e) { throw new SettingsException("Incorrect structure of 'index' configuration for sys_provider_type='" + typeName + "'."); } }
/** * Get search subsystem type name from one <code>sys_content_type</code> configuration structure. * * @param typeDef <code>sys_content_type</code> configuration structure * @param typeName <code>sys_content_type</code> name to be used for error messages * @return search type name */ @SuppressWarnings("unchecked") public static String extractIndexType(Map<String, Object> typeDef, String typeName) { try { String ret = null; if (typeDef.get(INDEX) != null) ret = (String) ((Map<String, Object>) typeDef.get(INDEX)).get(TYPE); if (ret == null || ret.trim().isEmpty()) throw new SettingsException("Incorrect configuration of 'index.type' for sys_provider_type='" + typeName + "'. SearchBackend index type is not defined."); return ret; } catch (ClassCastException e) { throw new SettingsException("Incorrect structure of 'index' configuration for sys_provider_type='" + typeName + "'."); } }
/** * Run defined content preprocessors on passed in content. * * @param preprocessors to run * @param content to run preprocessors on * @return list of warnings from preprocessors, may be null * @throws SettingsException if configuration is incorrect */ public Map<String, Object> runPreprocessors(List<StructuredContentPreprocessor> preprocessors, String id) throws SettingsException { Map<String, Object> content = new HashMap<>(); content.put(OUTKEY_INPUT_ID, id); if (preprocessors != null && !preprocessors.isEmpty()) { PreprocessChainContextImpl context = new PreprocessChainContextImpl(); for (StructuredContentPreprocessor preprocessor : preprocessors) { content = preprocessor.preprocessData(content, context); } if (context.warnings != null && !context.warnings.isEmpty()) content.put(OUTKEY_WARNINGS, context.warnings); } return content; }
/** * Get list of Strings from given key on given map. If it contains simple String then List is created with it. * {@link #safeList(List)} is used inside to filter list. * * @param map to get value from * @param key in map to get value from * @return list of strings or null. * @throws SettingsException if value in json map is invalid */ @SuppressWarnings("unchecked") public static List<String> getListOfStringsFromJsonMap(Map<String, Object> map, String key) throws SettingsException { if (map == null) return null; try { Object o = map.get(key); if (o instanceof String) { String v = StringUtils.trimToNull((String) o); if (v != null) { List<String> l = new ArrayList<>(); l.add(v); return l; } return null; } return safeList((List<String>) o); } catch (ClassCastException e) { throw new SettingsException("No String or Array of strings present in field '" + key); } }
@Override public Date extractDocumentUpdated(Map<String, Object> document) { Object val = XContentMapValues.extractValue(remoteDataFieldForUpdated, document); if (val == null) return null; if (!Utils.isSimpleValue(val)) throw new SettingsException("Remote data field '" + remoteDataFieldForUpdated + "' must provide simple value, but value is " + val); if (val instanceof Date) return (Date) val; try { return DateTimeUtils.parseDate( val.toString(), remoteDataFieldForUpdatedFormat ); } catch (IllegalArgumentException e1) { throw new SettingsException("Remote data field '" + remoteDataFieldForUpdated + "' is not reecognized: " + val); } }
@Override public boolean extractDocumentDeleted(Map<String, Object> document) { if (document == null || remoteDataFieldForDeleted == null) return false; Object val = XContentMapValues.extractValue(remoteDataFieldForDeleted, document); if (val == null) return false; if (!Utils.isSimpleValue(val)) throw new SettingsException("Remote data field '" + remoteDataFieldForDeleted + "' must provide simple value, but value is " + val); String v = null; if (val instanceof String) { v = (String) val; } else { v = val.toString(); } return v.equals(remoteDataValueForDeleted); }
private void validateConfigurationFieldsStructure(Map<String, Map<String, String>> value, String configFieldName) { for (String idxFieldName : value.keySet()) { if (Utils.isEmpty(idxFieldName)) { throw new SettingsException("Empty key found in '" + configFieldName + "' map."); } Map<String, String> fc = value.get(idxFieldName); if (Utils.isEmpty(fc.get(CONFIG_FIELDS_REMOTEFIELD))) { throw new SettingsException("'remote_field' is not defined in '" + configFieldName + "/" + idxFieldName + "'"); } String fil = fc.get(CONFIG_FIELDS_VALUEFILTER); if (fil != null && !filtersConfig.containsKey(fil)) { throw new SettingsException("Filter definition not found for filter name '" + fil + "' defined in '" + configFieldName + "/" + idxFieldName + "/value_filter'"); } } }
@SuppressWarnings("unchecked") private void preparePreprocessors(Map<String, Object> indexSettings, IDocumentIndexStructureBuilder indexStructureBuilder) { if (indexSettings != null) { List<Map<String, Object>> preproclist = (List<Map<String, Object>>) indexSettings.get("preprocessors"); if (preproclist != null && preproclist.size() > 0) { for (Map<String, Object> ppc : preproclist) { try { indexStructureBuilder.addDataPreprocessor(StructuredContentPreprocessorFactory.createPreprocessor(ppc, client)); } catch (IllegalArgumentException e) { throw new SettingsException(e.getMessage(), e); } } } } }
/** * Get url from configuration and validate it for format, and for presence. * * @param config to get URL from * @param cfgProperyName name of config property with URL * @param mandatory if URL is mandatory so validation is performed * @return url * @throws SettingsException in case of validation error */ protected static String getUrlFromConfig(Map<String, Object> config, String cfgProperyName, boolean mandatory) throws SettingsException { String url = null; if (config != null) url = Utils.trimToNull(XContentMapValues.nodeStringValue(config.get(cfgProperyName), null)); if (mandatory && url == null) { throw new SettingsException("remote/" + cfgProperyName + " element of configuration structure not found or empty"); } if (url != null) { try { new URL(url); } catch (MalformedURLException e) { throw new SettingsException("Parameter remote/" + cfgProperyName + " is malformed URL " + e.getMessage()); } } return url; }
@SuppressWarnings("unchecked") @Override public void init(IESIntegration esIntegration, Map<String, Object> config, boolean spaceListLoadingEnabled, IPwdLoader pwdLoader) { logger = esIntegration.createLogger(GetSitemapHtmlClient.class); urlGetSitemap = getUrlFromConfig(config, CFG_URL_GET_SITEMAP, true); try { htmlMapping = (Map<String, Map<String, Object>>) config.get(CFG_HTML_MAPPING); } catch (ClassCastException e) { throw new SettingsException("'remote/" + CFG_HTML_MAPPING + "' configuration section is invalid"); } if (spaceListLoadingEnabled) { throw new SettingsException( "Dynamic Spaces obtaining is not supported, use 'remote/spacesIndexed' to configure one space or static list"); } String remoteUsername = initHttpClient(logger, config, pwdLoader, urlGetSitemap); logger.info("Configured sitemap.xml HTML client for URL '{}', remote system user '{}'.", urlGetSitemap, remoteUsername != null ? remoteUsername : "Anonymous access"); }
/** * Select correct space indexer implementation based on {@link #spaceIndexingMode}. * * @param spaceKey to create indexer for * @param fullUpdateNecessary flag for indexer * @return indexer */ protected SpaceIndexerBase prepareSpaceIndexer(String spaceKey, boolean fullUpdateNecessary) { if (spaceIndexingMode == null) throw new SettingsException("undefined space indexing mode"); switch (spaceIndexingMode) { case SIMPLE: return new SpaceSimpleIndexer(spaceKey, remoteSystemClient, esIntegrationComponent, documentIndexStructureBuilder); case PAGINATION: return new SpacePaginatingIndexer(spaceKey, remoteSystemClient, esIntegrationComponent, documentIndexStructureBuilder); case UPDATE_TIMESTAMP: return new SpaceByLastUpdateTimestampIndexer(spaceKey, fullUpdateNecessary, remoteSystemClient, esIntegrationComponent, documentIndexStructureBuilder); default: throw new SettingsException("unsupported space indexing mode"); } }
/** * Read JSON file from classpath into Map of Map structure. * * @param filePath path inside jar/classpath pointing to JSON file to read * @return parsed JSON file * @throws SettingsException */ public static Map<String, Object> loadJSONFromJarPackagedFile(String filePath) throws SettingsException { XContentParser parser = null; try { parser = XContentFactory.xContent(XContentType.JSON).createParser(Utils.class.getResourceAsStream(filePath)); Map<String, Object> ret = parser.mapAndClose(); if (logger.isDebugEnabled()) logger.debug("jar packaged JSON file {} content is: {}", filePath, ret); return ret; } catch (IOException e) { throw new SettingsException(e.getMessage(), e); } finally { if (parser != null) parser.close(); } }
@Test public void parseConfiguration() { Assert.assertEquals(SpaceIndexingMode.SIMPLE, SpaceIndexingMode.parseConfiguration("simple")); Assert.assertEquals(SpaceIndexingMode.SIMPLE, SpaceIndexingMode.parseConfiguration("SIMPLE")); Assert.assertEquals(SpaceIndexingMode.PAGINATION, SpaceIndexingMode.parseConfiguration("pagination")); Assert.assertEquals(SpaceIndexingMode.PAGINATION, SpaceIndexingMode.parseConfiguration("Pagination")); Assert.assertEquals(SpaceIndexingMode.UPDATE_TIMESTAMP, SpaceIndexingMode.parseConfiguration("updatetimestamp")); Assert.assertEquals(SpaceIndexingMode.UPDATE_TIMESTAMP, SpaceIndexingMode.parseConfiguration("UpdateTimestamp")); Assert.assertNull(SpaceIndexingMode.parseConfiguration(null)); Assert.assertNull(SpaceIndexingMode.parseConfiguration(" ")); try { SpaceIndexingMode.parseConfiguration("nonsense"); Assert.fail("SettingsException must be thrown"); } catch (SettingsException e) { // OK } }
@Test public void parseConfiguration() { Assert.assertEquals(CommentIndexingMode.NONE, CommentIndexingMode.parseConfiguration("none")); Assert.assertEquals(CommentIndexingMode.NONE, CommentIndexingMode.parseConfiguration("None")); Assert.assertEquals(CommentIndexingMode.CHILD, CommentIndexingMode.parseConfiguration("child")); Assert.assertEquals(CommentIndexingMode.CHILD, CommentIndexingMode.parseConfiguration("Child")); Assert.assertEquals(CommentIndexingMode.STANDALONE, CommentIndexingMode.parseConfiguration("standalone")); Assert.assertEquals(CommentIndexingMode.STANDALONE, CommentIndexingMode.parseConfiguration("Standalone")); Assert.assertEquals(CommentIndexingMode.EMBEDDED, CommentIndexingMode.parseConfiguration("embedded")); Assert.assertEquals(CommentIndexingMode.EMBEDDED, CommentIndexingMode.parseConfiguration("Embedded")); Assert.assertEquals(CommentIndexingMode.NONE, CommentIndexingMode.parseConfiguration(null)); Assert.assertEquals(CommentIndexingMode.NONE, CommentIndexingMode.parseConfiguration(" ")); try { CommentIndexingMode.parseConfiguration("nonsense"); Assert.fail("SettingsException must be thrown"); } catch (SettingsException e) { // OK } }
public void testDuplicateKeysThrowsException() { assumeFalse("Test only makes sense if XContent parser doesn't have strict duplicate checks enabled", XContent.isStrictDuplicateDetectionEnabled()); final String json = "{\"foo\":\"bar\",\"foo\":\"baz\"}"; final SettingsException e = expectThrows(SettingsException.class, () -> Settings.builder().loadFromSource(json, XContentType.JSON).build()); assertEquals(e.getCause().getClass(), ElasticsearchParseException.class); assertThat( e.toString(), containsString("duplicate settings key [foo] " + "found at line number [1], " + "column number [20], " + "previous value [bar], " + "current value [baz]")); }
public void testDuplicateKeysThrowsException() { assumeFalse("Test only makes sense if XContent parser doesn't have strict duplicate checks enabled", XContent.isStrictDuplicateDetectionEnabled()); String yaml = "foo: bar\nfoo: baz"; SettingsException e = expectThrows(SettingsException.class, () -> { Settings.builder().loadFromSource(yaml, XContentType.YAML); }); assertEquals(e.getCause().getClass(), ElasticsearchParseException.class); String msg = e.getCause().getMessage(); assertTrue( msg, msg.contains("duplicate settings key [foo] found at line number [2], column number [6], " + "previous value [bar], current value [baz]")); }
public void testGarbageIsNotSwallowed() throws IOException { try { InputStream garbage = getClass().getResourceAsStream("/config/garbage/garbage.yml"); Path home = createTempDir(); Path config = home.resolve("config"); Files.createDirectory(config); Files.copy(garbage, config.resolve("elasticsearch.yml")); InternalSettingsPreparer.prepareEnvironment(Settings.builder() .put(baseEnvSettings) .build(), null); } catch (SettingsException e) { assertEquals("Failed to load settings from [elasticsearch.yml]", e.getMessage()); } }
public void testParseTwoSettingsNoDefault() { Settings settings = Settings.builder() .put("cloud.azure.storage.azure1.account", "myaccount1") .put("cloud.azure.storage.azure1.key", "mykey1") .put("cloud.azure.storage.azure2.account", "myaccount2") .put("cloud.azure.storage.azure2.key", "mykey2") .build(); try { AzureStorageSettings.parse(settings); fail("Should have failed with a SettingsException (no default data store)"); } catch (SettingsException ex) { assertEquals(ex.getMessage(), "No default Azure data store configured"); } }
static void loadConfig(Path file, Settings.Builder settingsBuilder) { try { settingsBuilder.loadFromPath(file); } catch (SettingsException | NoClassDefFoundError e) { // ignore } }
/** * A thread pool size can also be unbounded and is represented by -1, which is not supported by SizeValue (which only supports positive numbers) */ private SizeValue getAsSizeOrUnbounded(Settings settings, String setting, SizeValue defaultValue) throws SettingsException { if ("-1".equals(settings.get(setting))) { return null; } return parseSizeValue(settings.get(setting), defaultValue); }
private List<Path> getLexiconPaths(Path lexiconPath) { if (Files.isDirectory(lexiconPath, LinkOption.NOFOLLOW_LINKS)) { try { return Arrays.asList(FileSystemUtils.files(lexiconPath, p -> p.startsWith("words") && p.endsWith(".dic"))); } catch (IOException e) { log.error("load lexicon path: " + lexiconPath + " directory files have exception", e); throw new SettingsException("load lexicon path: " + lexiconPath + " directory files have exception", e); } } else { return Collections.singletonList(lexiconPath); } }
/** * Get configuration for all <code>dcp_content_type</code> from provider configuration. * * @param providerDef provider configuration structure * @return map with all type configurations or null if doesn't exist. Key in map is type name, value is type * configuration. * @throws SettingsException for incorrect configuration structure */ @SuppressWarnings("unchecked") public static Map<String, Map<String, Object>> extractAllContentTypes(Map<String, Object> providerDef) { try { Map<String, Map<String, Object>> types = (Map<String, Map<String, Object>>) providerDef.get(TYPE); return types; } catch (ClassCastException e) { throw new SettingsException("Incorrect configuration for provider '" + providerDef.get(NAME) + "' when trying to retrieve all dcp_provider_type configurations. Contact administrators please."); } }
/** * Get preprocessors configuration from one <code>dcp_content_type</code> configuration structure. * * @param typeDef <code>dcp_content_type</code> configuration structure * @param typeName <code>dcp_content_type</code> name to be used for error messages * @return list of preprocessor configurations */ @SuppressWarnings("unchecked") public static List<Map<String, Object>> extractPreprocessors(Map<String, Object> typeDef, String typeName) { try { return (List<Map<String, Object>>) typeDef.get(INPUT_PREPROCESSORS); } catch (ClassCastException e) { throw new SettingsException("Incorrect configuration of 'input_preprocessors' for dcp_provider_type=" + typeName + ". Contact administrators please."); } }