Skip to content

Commit 72ce7f2

Browse files
committed
Adjustments to match the changes of elastic#34117
1 parent 994869c commit 72ce7f2

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

x-pack/plugin/ml/log-config-creator/src/main/java/org/elasticsearch/xpack/ml/configcreator/LogConfigCreator.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import java.util.Arrays;
2525
import java.util.Collection;
2626
import java.util.Comparator;
27+
import java.util.concurrent.ScheduledExecutorService;
28+
import java.util.concurrent.ScheduledThreadPoolExecutor;
2729
import java.util.regex.Pattern;
2830
import java.util.stream.Collectors;
2931
import java.util.stream.Stream;
@@ -155,10 +157,11 @@ protected void execute(Terminal terminal, OptionSet options) throws Exception {
155157
throw new UserException(ExitCodes.USAGE, "[" + file + "] does not exist or is not a file");
156158
}
157159

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

x-pack/plugin/ml/log-config-creator/src/test/java/org/elasticsearch/xpack/ml/configcreator/LogConfigCreatorTests.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@
77

88
import org.elasticsearch.xpack.ml.filestructurefinder.FileStructureFinder;
99
import org.elasticsearch.xpack.ml.filestructurefinder.FileStructureFinderManager;
10+
import org.junit.After;
1011
import org.junit.Before;
1112

1213
import java.io.ByteArrayInputStream;
1314
import java.io.IOException;
1415
import java.nio.charset.StandardCharsets;
1516
import java.nio.file.Files;
1617
import java.nio.file.Path;
18+
import java.util.concurrent.ScheduledExecutorService;
19+
import java.util.concurrent.ScheduledThreadPoolExecutor;
1720

1821
public class LogConfigCreatorTests extends LogConfigCreatorTestCase {
1922

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

36+
private ScheduledExecutorService scheduler;
3337
private FileStructureFinderManager structureFinderManager;
3438
private LogConfigWriter logConfigWriter;
3539

3640
@Before
3741
public void setup() throws IOException {
38-
structureFinderManager = new FileStructureFinderManager();
42+
scheduler = new ScheduledThreadPoolExecutor(1);
43+
structureFinderManager = new FileStructureFinderManager(scheduler);
3944
logConfigWriter = new LogConfigWriter(TEST_TERMINAL, null, TEST_FILE_NAME, TEST_INDEX_NAME, TEST_TYPE,
4045
randomFrom(POSSIBLE_HOSTNAMES), randomFrom(POSSIBLE_HOSTNAMES), "UTC");
4146
}
4247

48+
@After
49+
public void shutdownScheduler() {
50+
scheduler.shutdown();
51+
}
52+
4353
public void testFindLogFileFormatGivenJson() throws Exception {
4454
Path outputDirectory = createTempDir();
4555

x-pack/plugin/ml/log-config-creator/src/test/java/org/elasticsearch/xpack/ml/configcreator/LogConfigWriterTests.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,36 @@
88
import org.elasticsearch.xpack.ml.filestructurefinder.FileStructureFinder;
99
import org.elasticsearch.xpack.ml.filestructurefinder.FileStructureFinderManager;
1010
import org.elasticsearch.xpack.ml.filestructurefinder.FileStructureUtils;
11+
import org.junit.After;
12+
import org.junit.Before;
1113

1214
import java.io.ByteArrayInputStream;
1315
import java.nio.charset.StandardCharsets;
1416
import java.util.Collections;
1517
import java.util.LinkedHashMap;
1618
import java.util.Locale;
1719
import java.util.Map;
20+
import java.util.concurrent.ScheduledExecutorService;
21+
import java.util.concurrent.ScheduledThreadPoolExecutor;
1822

1923
import static org.hamcrest.Matchers.containsString;
2024
import static org.hamcrest.Matchers.not;
2125

2226
public class LogConfigWriterTests extends LogConfigCreatorTestCase {
2327

24-
private FileStructureFinderManager structureFinderManager = new FileStructureFinderManager();
28+
private ScheduledExecutorService scheduler;
29+
private FileStructureFinderManager structureFinderManager;
30+
31+
@Before
32+
public void setup() {
33+
scheduler = new ScheduledThreadPoolExecutor(1);
34+
structureFinderManager = new FileStructureFinderManager(scheduler);
35+
}
36+
37+
@After
38+
public void shutdownScheduler() {
39+
scheduler.shutdown();
40+
}
2541

2642
public void testBestLogstashQuoteFor() {
2743
assertEquals("\"", LogConfigWriter.bestLogstashQuoteFor("normal"));

0 commit comments

Comments
 (0)