Skip to content

Commit

Permalink
Include more common code from other BWCs
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Widdis <widdis@gmail.com>
  • Loading branch information
dbwiddis committed Mar 6, 2024
1 parent c422b06 commit 14fcb40
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 16 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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<String, Map<String, Object>> responseMap = (Map<String, Map<String, Object>>) getAsMap(uri).get("nodes");
for (Map<String, Object> response : responseMap.values()) {
List<Map<String, Object>> plugins = (List<Map<String, Object>>) response.get("plugins");
Set<Object> 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);
}
}

Expand Down

0 comments on commit 14fcb40

Please sign in to comment.