Skip to content

Commit 4282fa1

Browse files
authored
Refactor the download_database_on_pipeline_creation checks (#115421) (#115461)
1 parent c43736f commit 4282fa1

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

modules/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/GeoIpDownloaderTaskExecutor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,14 +309,14 @@ private static boolean hasAtLeastOneGeoipProcessor(Map<String, Object> processor
309309
{
310310
final Map<String, Object> processorConfig = (Map<String, Object>) processor.get(GEOIP_TYPE);
311311
if (processorConfig != null) {
312-
return downloadDatabaseOnPipelineCreation(GEOIP_TYPE, processorConfig, null) == downloadDatabaseOnPipelineCreation;
312+
return downloadDatabaseOnPipelineCreation(processorConfig) == downloadDatabaseOnPipelineCreation;
313313
}
314314
}
315315

316316
{
317317
final Map<String, Object> processorConfig = (Map<String, Object>) processor.get(IP_LOCATION_TYPE);
318318
if (processorConfig != null) {
319-
return downloadDatabaseOnPipelineCreation(IP_LOCATION_TYPE, processorConfig, null) == downloadDatabaseOnPipelineCreation;
319+
return downloadDatabaseOnPipelineCreation(processorConfig) == downloadDatabaseOnPipelineCreation;
320320
}
321321
}
322322

modules/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/GeoIpProcessor.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,8 @@ public Processor create(
238238
boolean ignoreMissing = readBooleanProperty(type, processorTag, config, "ignore_missing", false);
239239
boolean firstOnly = readBooleanProperty(type, processorTag, config, "first_only", true);
240240

241-
// Validating the download_database_on_pipeline_creation even if the result
242-
// is not used directly by the factory.
243-
downloadDatabaseOnPipelineCreation(type, config, processorTag);
241+
// validate (and consume) the download_database_on_pipeline_creation property even though the result is not used by the factory
242+
readBooleanProperty(type, processorTag, config, "download_database_on_pipeline_creation", true);
244243

245244
// noop, should be removed in 9.0
246245
Object value = config.remove("fallback_to_default_databases");
@@ -319,8 +318,15 @@ public Processor create(
319318
);
320319
}
321320

322-
public static boolean downloadDatabaseOnPipelineCreation(String type, Map<String, Object> config, String processorTag) {
323-
return readBooleanProperty(type, processorTag, config, "download_database_on_pipeline_creation", true);
321+
/**
322+
* Get the value of the "download_database_on_pipeline_creation" property from a processor's config map.
323+
* <p>
324+
* As with the actual property definition, the default value of the property is 'true'. Unlike the actual
325+
* property definition, this method doesn't consume (that is, <code>config.remove</code>) the property from
326+
* the config map.
327+
*/
328+
public static boolean downloadDatabaseOnPipelineCreation(Map<String, Object> config) {
329+
return (boolean) config.getOrDefault("download_database_on_pipeline_creation", true);
324330
}
325331
}
326332

0 commit comments

Comments
 (0)