Skip to content

Commit

Permalink
Adjustments to match the changes of elastic#34117
Browse files Browse the repository at this point in the history
  • Loading branch information
droberts195 committed Sep 28, 2018
1 parent 994869c commit 72ce7f2
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand Down Expand Up @@ -155,10 +157,11 @@ protected void execute(Terminal terminal, OptionSet options) throws Exception {
throw new UserException(ExitCodes.USAGE, "[" + file + "] does not exist or is not a file");
}

ScheduledExecutorService scheduler = new ScheduledThreadPoolExecutor(1);
try {
LogConfigWriter logConfigWriter = new LogConfigWriter(terminal, filebeatModulePath,
file.toAbsolutePath().normalize().toString(), indexName, typeName, elasticsearchHost, logstashHost, timezone);
FileStructureFinderManager structureFinderManager = new FileStructureFinderManager();
FileStructureFinderManager structureFinderManager = new FileStructureFinderManager(scheduler);
FileStructureFinder structureFinder = structureFinderManager.findFileStructure(sampleLines, Files.newInputStream(file));
FileStructure structure = structureFinder.getStructure();
for (String reason : structure.getExplanation()) {
Expand All @@ -167,6 +170,8 @@ protected void execute(Terminal terminal, OptionSet options) throws Exception {
logConfigWriter.writeConfigs(structure, structureFinder.getSampleMessages(), outputDirectory);
} catch (IllegalArgumentException | IOException e) {
throw new UserException(ExitCodes.DATA_ERROR, "Cannot determine format of file [" + file + "]: " + e.getMessage());
} finally {
scheduler.shutdown();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@

import org.elasticsearch.xpack.ml.filestructurefinder.FileStructureFinder;
import org.elasticsearch.xpack.ml.filestructurefinder.FileStructureFinderManager;
import org.junit.After;
import org.junit.Before;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;

public class LogConfigCreatorTests extends LogConfigCreatorTestCase {

Expand All @@ -30,16 +33,23 @@ public class LogConfigCreatorTests extends LogConfigCreatorTestCase {
private static final String INDEX_MAPPINGS_CONSOLE = TEST_TYPE + "-index-mappings.console";
private static final String INDEX_MAPPINGS_SH = TEST_TYPE + "-index-mappings.sh";

private ScheduledExecutorService scheduler;
private FileStructureFinderManager structureFinderManager;
private LogConfigWriter logConfigWriter;

@Before
public void setup() throws IOException {
structureFinderManager = new FileStructureFinderManager();
scheduler = new ScheduledThreadPoolExecutor(1);
structureFinderManager = new FileStructureFinderManager(scheduler);
logConfigWriter = new LogConfigWriter(TEST_TERMINAL, null, TEST_FILE_NAME, TEST_INDEX_NAME, TEST_TYPE,
randomFrom(POSSIBLE_HOSTNAMES), randomFrom(POSSIBLE_HOSTNAMES), "UTC");
}

@After
public void shutdownScheduler() {
scheduler.shutdown();
}

public void testFindLogFileFormatGivenJson() throws Exception {
Path outputDirectory = createTempDir();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,36 @@
import org.elasticsearch.xpack.ml.filestructurefinder.FileStructureFinder;
import org.elasticsearch.xpack.ml.filestructurefinder.FileStructureFinderManager;
import org.elasticsearch.xpack.ml.filestructurefinder.FileStructureUtils;
import org.junit.After;
import org.junit.Before;

import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;

import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.not;

public class LogConfigWriterTests extends LogConfigCreatorTestCase {

private FileStructureFinderManager structureFinderManager = new FileStructureFinderManager();
private ScheduledExecutorService scheduler;
private FileStructureFinderManager structureFinderManager;

@Before
public void setup() {
scheduler = new ScheduledThreadPoolExecutor(1);
structureFinderManager = new FileStructureFinderManager(scheduler);
}

@After
public void shutdownScheduler() {
scheduler.shutdown();
}

public void testBestLogstashQuoteFor() {
assertEquals("\"", LogConfigWriter.bestLogstashQuoteFor("normal"));
Expand Down

0 comments on commit 72ce7f2

Please sign in to comment.