Skip to content

Commit 330b0bc

Browse files
committed
Remove discovery-file plugin
In elastic#33241 we moved the file-based discovery functionality to core Elasticsearch, but preserved the `discovery-file` plugin, and support for the existing location of the `unicast_hosts.txt` file, for BWC reasons. This commit completes the removal of this plugin.
1 parent 47859e5 commit 330b0bc

File tree

9 files changed

+19
-280
lines changed

9 files changed

+19
-280
lines changed

docs/reference/migration/migrate_7_0/plugins.asciidoc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,12 @@ See {plugins}/repository-gcs-client.html#repository-gcs-client[Google Cloud Stor
2222
==== Analysis Plugin changes
2323

2424
* The misspelled helper method `requriesAnalysisSettings(AnalyzerProvider<T> provider)` has been
25-
renamed to `requiresAnalysisSettings`
25+
renamed to `requiresAnalysisSettings`
26+
27+
==== File-based discovery plugin
28+
29+
* This plugin has been removed since its functionality is now part of
30+
Elasticsearch and requires no plugin. The location of the hosts file has moved
31+
from `$ES_PATH_CONF/file-discovery/unicast_hosts.txt` to
32+
`$ES_PATH_CONF/unicast_hosts.txt`. See <<file-based-hosts-provider, the
33+
file-based hosts provider documentation>> for further information.

plugins/discovery-file/build.gradle

Lines changed: 0 additions & 61 deletions
This file was deleted.

plugins/discovery-file/config/discovery-file/unicast_hosts.txt

Lines changed: 0 additions & 20 deletions
This file was deleted.

plugins/discovery-file/src/main/java/org/elasticsearch/discovery/file/FileBasedDiscoveryPlugin.java

Lines changed: 0 additions & 51 deletions
This file was deleted.

plugins/discovery-file/src/test/java/org/elasticsearch/discovery/file/FileBasedDiscoveryClientYamlTestSuiteIT.java

Lines changed: 0 additions & 40 deletions
This file was deleted.

plugins/discovery-file/src/test/java/org/elasticsearch/discovery/file/FileBasedDiscoveryPluginDeprecationTests.java

Lines changed: 0 additions & 32 deletions
This file was deleted.

plugins/discovery-file/src/test/resources/rest-api-spec/test/discovery_file/10_basic.yml

Lines changed: 0 additions & 13 deletions
This file was deleted.

server/src/main/java/org/elasticsearch/discovery/zen/FileBasedUnicastHostsProvider.java

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,40 +49,28 @@ public class FileBasedUnicastHostsProvider extends AbstractComponent implements
4949
public static final String UNICAST_HOSTS_FILE = "unicast_hosts.txt";
5050

5151
private final Path unicastHostsFilePath;
52-
private final Path legacyUnicastHostsFilePath;
5352

5453
public FileBasedUnicastHostsProvider(Settings settings, Path configFile) {
5554
super(settings);
5655
this.unicastHostsFilePath = configFile.resolve(UNICAST_HOSTS_FILE);
57-
this.legacyUnicastHostsFilePath = configFile.resolve("discovery-file").resolve(UNICAST_HOSTS_FILE);
5856
}
5957

6058
private List<String> getHostsList() {
6159
if (Files.exists(unicastHostsFilePath)) {
62-
return readFileContents(unicastHostsFilePath);
63-
}
64-
65-
if (Files.exists(legacyUnicastHostsFilePath)) {
66-
deprecationLogger.deprecated("Found dynamic hosts list at [{}] but this path is deprecated. This list should be at [{}] " +
67-
"instead. Support for the deprecated path will be removed in future.", legacyUnicastHostsFilePath, unicastHostsFilePath);
68-
return readFileContents(legacyUnicastHostsFilePath);
60+
try (Stream<String> lines = Files.lines(unicastHostsFilePath)) {
61+
return lines.filter(line -> line.startsWith("#") == false) // lines starting with `#` are comments
62+
.collect(Collectors.toList());
63+
} catch (IOException e) {
64+
logger.warn(() -> new ParameterizedMessage("failed to read file [{}]", unicastHostsFilePath), e);
65+
return Collections.emptyList();
66+
}
6967
}
7068

7169
logger.warn("expected, but did not find, a dynamic hosts list at [{}]", unicastHostsFilePath);
7270

7371
return Collections.emptyList();
7472
}
7573

76-
private List<String> readFileContents(Path path) {
77-
try (Stream<String> lines = Files.lines(path)) {
78-
return lines.filter(line -> line.startsWith("#") == false) // lines starting with `#` are comments
79-
.collect(Collectors.toList());
80-
} catch (IOException e) {
81-
logger.warn(() -> new ParameterizedMessage("failed to read file [{}]", unicastHostsFilePath), e);
82-
return Collections.emptyList();
83-
}
84-
}
85-
8674
@Override
8775
public List<TransportAddress> buildDynamicHosts(HostsResolver hostsResolver) {
8876
final List<TransportAddress> transportAddresses = hostsResolver.resolveHosts(getHostsList(), 1);

server/src/test/java/org/elasticsearch/discovery/zen/FileBasedUnicastHostsProviderTests.java

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,9 @@
5252

5353
public class FileBasedUnicastHostsProviderTests extends ESTestCase {
5454

55-
private boolean legacyLocation;
5655
private ThreadPool threadPool;
5756
private ExecutorService executorService;
5857
private MockTransportService transportService;
59-
private Path configPath;
6058

6159
@Before
6260
public void setUp() throws Exception {
@@ -108,24 +106,12 @@ public void testBuildDynamicNodes() throws Exception {
108106
assertEquals(9300, nodes.get(2).getPort());
109107
}
110108

111-
public void testBuildDynamicNodesLegacyLocation() throws Exception {
112-
legacyLocation = true;
113-
testBuildDynamicNodes();
114-
assertDeprecatedLocationWarning();
115-
}
116-
117109
public void testEmptyUnicastHostsFile() throws Exception {
118110
final List<String> hostEntries = Collections.emptyList();
119111
final List<TransportAddress> addresses = setupAndRunHostProvider(hostEntries);
120112
assertEquals(0, addresses.size());
121113
}
122114

123-
public void testEmptyUnicastHostsFileLegacyLocation() throws Exception {
124-
legacyLocation = true;
125-
testEmptyUnicastHostsFile();
126-
assertDeprecatedLocationWarning();
127-
}
128-
129115
public void testUnicastHostsDoesNotExist() {
130116
final Settings settings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()).build();
131117
final FileBasedUnicastHostsProvider provider = new FileBasedUnicastHostsProvider(settings, createTempDir().toAbsolutePath());
@@ -141,12 +127,6 @@ public void testInvalidHostEntries() throws Exception {
141127
assertEquals(0, addresses.size());
142128
}
143129

144-
public void testInvalidHostEntriesLegacyLocation() throws Exception {
145-
legacyLocation = true;
146-
testInvalidHostEntries();
147-
assertDeprecatedLocationWarning();
148-
}
149-
150130
public void testSomeInvalidHostEntries() throws Exception {
151131
final List<String> hostEntries = Arrays.asList("192.168.0.1:9300:9300", "192.168.0.1:9301");
152132
final List<TransportAddress> addresses = setupAndRunHostProvider(hostEntries);
@@ -155,41 +135,21 @@ public void testSomeInvalidHostEntries() throws Exception {
155135
assertEquals(9301, addresses.get(0).getPort());
156136
}
157137

158-
public void testSomeInvalidHostEntriesLegacyLocation() throws Exception {
159-
legacyLocation = true;
160-
testSomeInvalidHostEntries();
161-
assertDeprecatedLocationWarning();
162-
}
163-
164138
// sets up the config dir, writes to the unicast hosts file in the config dir,
165139
// and then runs the file-based unicast host provider to get the list of discovery nodes
166140
private List<TransportAddress> setupAndRunHostProvider(final List<String> hostEntries) throws IOException {
167141
final Path homeDir = createTempDir();
168142
final Settings settings = Settings.builder()
169143
.put(Environment.PATH_HOME_SETTING.getKey(), homeDir)
170144
.build();
171-
if (randomBoolean()) {
172-
configPath = homeDir.resolve("config");
173-
} else {
174-
configPath = createTempDir();
175-
}
176-
final Path discoveryFilePath = legacyLocation ? configPath.resolve("discovery-file") : configPath;
177-
Files.createDirectories(discoveryFilePath);
178-
final Path unicastHostsPath = discoveryFilePath.resolve(UNICAST_HOSTS_FILE);
179-
try (BufferedWriter writer = Files.newBufferedWriter(unicastHostsPath)) {
145+
final Path configPath = randomBoolean() ? homeDir.resolve("config") : createTempDir();
146+
Files.createDirectories(configPath);
147+
try (BufferedWriter writer = Files.newBufferedWriter(configPath.resolve(UNICAST_HOSTS_FILE))) {
180148
writer.write(String.join("\n", hostEntries));
181149
}
182150

183151
return new FileBasedUnicastHostsProvider(settings, configPath).buildDynamicHosts((hosts, limitPortCounts) ->
184152
UnicastZenPing.resolveHostsLists(executorService, logger, hosts, limitPortCounts, transportService,
185153
TimeValue.timeValueSeconds(10)));
186154
}
187-
188-
private void assertDeprecatedLocationWarning() {
189-
assertWarnings("Found dynamic hosts list at [" +
190-
configPath.resolve("discovery-file").resolve(UNICAST_HOSTS_FILE) +
191-
"] but this path is deprecated. This list should be at [" +
192-
configPath.resolve(UNICAST_HOSTS_FILE) +
193-
"] instead. Support for the deprecated path will be removed in future.");
194-
}
195155
}

0 commit comments

Comments
 (0)