Merge pull request #15181 from martijnvg/ingest_geoip_only_read_mmdb_files

[Ingest] The geoip processor should only try to read *.mmdb files from the geoip config directory
This commit is contained in:
Tal Levy 2015-12-03 12:17:09 -08:00
commit ffa8998f36
1 changed files with 3 additions and 5 deletions

View File

@ -35,15 +35,12 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.nio.file.*;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.*;
import java.util.stream.Stream;
import static org.elasticsearch.ingest.processor.ConfigurationUtils.readList;
import static org.elasticsearch.ingest.processor.ConfigurationUtils.readOptionalList;
import static org.elasticsearch.ingest.processor.ConfigurationUtils.readStringProperty;
@ -231,11 +228,12 @@ public final class GeoIpProcessor implements Processor {
try (Stream<Path> databaseFiles = Files.list(geoIpConfigDirectory)) {
Map<String, DatabaseReader> databaseReaders = new HashMap<>();
PathMatcher pathMatcher = geoIpConfigDirectory.getFileSystem().getPathMatcher("glob:**.mmdb");
// Use iterator instead of forEach otherwise IOException needs to be caught twice...
Iterator<Path> iterator = databaseFiles.iterator();
while (iterator.hasNext()) {
Path databasePath = iterator.next();
if (Files.isRegularFile(databasePath)) {
if (Files.isRegularFile(databasePath) && pathMatcher.matches(databasePath)) {
try (InputStream inputStream = Files.newInputStream(databasePath, StandardOpenOption.READ)) {
databaseReaders.put(databasePath.getFileName().toString(), new DatabaseReader.Builder(inputStream).build());
}