From 14fcb40dc053be2ffe85d757181f71728d9bc35e Mon Sep 17 00:00:00 2001 From: Daniel Widdis Date: Tue, 5 Mar 2024 20:49:45 -0800 Subject: [PATCH] Include more common code from other BWCs Signed-off-by: Daniel Widdis --- build.gradle | 2 +- ...FlowFrameworkBackwardsCompatibilityIT.java | 80 +++++++++++++++---- 2 files changed, 66 insertions(+), 16 deletions(-) diff --git a/build.gradle b/build.gradle index 8c75cf867..fd696370f 100644 --- a/build.gradle +++ b/build.gradle @@ -30,7 +30,7 @@ buildscript { bwcOpenSearchFFDownload = 'https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/' + bwcVersionShort + '/latest/linux/x64/tar/builds/' + 'opensearch/plugins/opensearch-flow-framework-' + bwcVersion + '.zip' baseName = "ffBwcCluster" - bwcFilePath = "src/test/resources/org/opensearch/flowframework/bwc/" + bwcFilePath = "src/test/resources/bwc/" bwcFlowFrameworkPath = bwcFilePath + "flow-framework/" } diff --git a/src/test/java/org/opensearch/flowframework/bwc/FlowFrameworkBackwardsCompatibilityIT.java b/src/test/java/org/opensearch/flowframework/bwc/FlowFrameworkBackwardsCompatibilityIT.java index b0907599b..d082a5c08 100644 --- a/src/test/java/org/opensearch/flowframework/bwc/FlowFrameworkBackwardsCompatibilityIT.java +++ b/src/test/java/org/opensearch/flowframework/bwc/FlowFrameworkBackwardsCompatibilityIT.java @@ -23,12 +23,16 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.List; +import java.util.Map; +import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.stream.Collectors; public class FlowFrameworkBackwardsCompatibilityIT extends OpenSearchRestTestCase { private static final ClusterType CLUSTER_TYPE = ClusterType.parse(System.getProperty("tests.rest.bwcsuite")); + private static final String CLUSTER_NAME = System.getProperty("tests.clustername"); @Override @Before @@ -51,6 +55,21 @@ private void setupSettings() throws IOException { assertEquals(200, response.getStatusLine().getStatusCode()); } + @Override + protected final boolean preserveIndicesUponCompletion() { + return true; + } + + @Override + protected final boolean preserveReposUponCompletion() { + return true; + } + + @Override + protected boolean preserveTemplatesUponCompletion() { + return true; + } + @Override protected final Settings restClientSettings() { return Settings.builder() @@ -81,25 +100,56 @@ public static ClusterType parse(String value) { } } - public void testTemplateTimestamps() throws Exception { - String workflowId = createNoopTemplate(); - Template t = getTemplate(workflowId); + @SuppressWarnings("unchecked") + public void testBackwardsCompatibility() throws Exception { + String uri = getUri(); + Map> responseMap = (Map>) getAsMap(uri).get("nodes"); + for (Map response : responseMap.values()) { + List> plugins = (List>) response.get("plugins"); + Set pluginNames = plugins.stream().map(map -> map.get("name")).collect(Collectors.toSet()); + String workflowId = createNoopTemplate(); + Template t = getTemplate(workflowId); + switch (CLUSTER_TYPE) { + case OLD: + assertTrue(pluginNames.contains("opensearch-flow-framework")); + // mapping for 2.12 does not include time stamps + assertNull(t.createdTime()); + assertNull(t.lastUpdatedTime()); + break; + case MIXED: + assertTrue(pluginNames.contains("opensearch-flow-framework")); + // Time stamps may or may not be null depending on whether index has been accessed by new version node + // So just test that the template parses + assertEquals("test", t.name()); + break; + case UPGRADED: + assertTrue(pluginNames.contains("opensearch-flow-framework")); + // mapping for 2.13+ includes time stamps + assertNotNull(t.createdTime()); + assertNotNull(t.lastUpdatedTime()); + break; + } + break; + } + } + + private String getUri() { switch (CLUSTER_TYPE) { case OLD: - // mapping for 2.12 does not include time stamps - assertNull(t.createdTime()); - assertNull(t.lastUpdatedTime()); - break; + return "_nodes/" + CLUSTER_NAME + "-0/plugins"; case MIXED: - // Time stamps may or may not be null depending on whether index has been accessed by new version node - // So just test that the template parses - assertEquals("test", t.name()); - break; + String round = System.getProperty("tests.rest.bwcsuite_round"); + if (round.equals("second")) { + return "_nodes/" + CLUSTER_NAME + "-1/plugins"; + } else if (round.equals("third")) { + return "_nodes/" + CLUSTER_NAME + "-2/plugins"; + } else { + return "_nodes/" + CLUSTER_NAME + "-0/plugins"; + } case UPGRADED: - // mapping for 2.13+ includes time stamps - assertNotNull(t.createdTime()); - assertNotNull(t.lastUpdatedTime()); - break; + return "_nodes/plugins"; + default: + throw new AssertionError("unknown cluster type: " + CLUSTER_TYPE); } }