fix LocalExporter minimum version checks with non snapshot versions
The LocalExporter checks worked when using a snapshot version but did not work in a released version even though the template was the correct version. Original commit: elastic/x-pack-elasticsearch@581f54575b
This commit is contained in:
parent
7a61d435a5
commit
75c6772c13
|
@ -160,19 +160,21 @@ public class LocalExporter extends Exporter implements ClusterStateListener {
|
|||
}
|
||||
|
||||
boolean installedTemplateVersionIsSufficient(Version current, Version installed) {
|
||||
// null indicates couldn't parse the version from the installed template, this means it is probably too old or invalid...
|
||||
if (installed == null) {
|
||||
return false;
|
||||
}
|
||||
// ensure the template is not too old
|
||||
if (installed.before(MIN_SUPPORTED_TEMPLATE_VERSION)) {
|
||||
return false;
|
||||
}
|
||||
if (current.after(installed)) {
|
||||
return true;
|
||||
}
|
||||
if (current.equals(installed)) {
|
||||
return current.snapshot();
|
||||
}
|
||||
return false;
|
||||
|
||||
// We do not enforce that versions are equivalent to the current version as we may be in a rolling upgrade scenario
|
||||
// and until a master is elected with the new version, data nodes that have been upgraded will not be able to ship
|
||||
// data. This means that there is an implication that the new shippers will ship data correctly even with an old template.
|
||||
// There is also no upper bound and we rely on elasticsearch nodes not being able to connect to each other across major
|
||||
// versions
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean installedTemplateVersionMandatesAnUpdate(Version current, Version installed) {
|
||||
|
|
|
@ -250,6 +250,40 @@ public class LocalExporterTests extends MarvelIntegTestCase {
|
|||
awaitIndexExists(indexName);
|
||||
}
|
||||
|
||||
public void testInstalledTemplateVersionChecking() throws Exception {
|
||||
Exporter.Config config = new Exporter.Config("_name", Settings.EMPTY, Settings.builder()
|
||||
.put("type", "local").build());
|
||||
Client client = mock(Client.class);
|
||||
ClusterService clusterService = mock(ClusterService.class);
|
||||
boolean master = randomBoolean();
|
||||
DiscoveryNode localNode = mock(DiscoveryNode.class);
|
||||
when(localNode.masterNode()).thenReturn(master);
|
||||
when(clusterService.localNode()).thenReturn(localNode);
|
||||
RendererRegistry renderers = mock(RendererRegistry.class);
|
||||
LocalExporter exporter = new LocalExporter(config, client, clusterService, renderers);
|
||||
|
||||
assertTrue("current template version should always be sufficient", exporter.installedTemplateVersionIsSufficient(Version.CURRENT, Version.CURRENT));
|
||||
Version version = Version.fromId(Version.CURRENT.id + 1000000);
|
||||
assertTrue("future versions should be considered sufficient in case of a rolling upgrade scenario",
|
||||
exporter.installedTemplateVersionIsSufficient(Version.CURRENT, version));
|
||||
|
||||
// make sure we test at least one snapshot and non-snapshot
|
||||
String versionStr = "2.0.1";
|
||||
if (randomBoolean()) {
|
||||
versionStr += "-SNAPSHOT";
|
||||
}
|
||||
Version version1 = Version.fromString(versionStr);
|
||||
assertTrue("snapshots should not matter", exporter.installedTemplateVersionIsSufficient(version1, version1));
|
||||
|
||||
// test the minimum version
|
||||
assertTrue("minimum template version should always be sufficient", exporter.installedTemplateVersionIsSufficient(Version.CURRENT, Exporter.MIN_SUPPORTED_TEMPLATE_VERSION));
|
||||
|
||||
// test a version below the minimum version
|
||||
assertFalse("version below minimum should not be sufficient", exporter.installedTemplateVersionIsSufficient(Version.CURRENT, Version.V_2_0_0_beta1));
|
||||
|
||||
assertFalse("null version should not be sufficient", exporter.installedTemplateVersionIsSufficient(Version.CURRENT, null));
|
||||
}
|
||||
|
||||
private LocalExporter getLocalExporter(String name) throws Exception {
|
||||
final Exporter exporter = internalCluster().getInstance(Exporters.class).getExporter(name);
|
||||
assertThat(exporter, notNullValue());
|
||||
|
|
Loading…
Reference in New Issue