forked from opensearch-project/data-prepper
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds support for composable index templates (opensearch-project#2808)
Adds support for composable index templates. Resolves opensearch-project#1275. Update the OpenSearch sink integration test to skip the composable index template tests on older versions of OpenDistro. Updated the README.md with the new template_type feature. Signed-off-by: David Venable <[email protected]>
- Loading branch information
Showing
19 changed files
with
1,914 additions
and
873 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...st/java/org/opensearch/dataprepper/plugins/sink/opensearch/DeclaredOpenSearchVersion.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.plugins.sink.opensearch; | ||
|
||
import org.opensearch.Version; | ||
|
||
/** | ||
* An interface for letting the test declare what OpenSearch version is being | ||
* tested against. | ||
*/ | ||
class DeclaredOpenSearchVersion implements Comparable<DeclaredOpenSearchVersion> { | ||
private static final DeclaredOpenSearchVersion DEFAULT = new DeclaredOpenSearchVersion(Distribution.OPENSEARCH, "1.0.0"); | ||
public static final DeclaredOpenSearchVersion OPENDISTRO_1_9 = new DeclaredOpenSearchVersion(Distribution.OPENDISTRO, "1.9.0"); | ||
|
||
enum Distribution { | ||
OPENDISTRO, | ||
OPENSEARCH | ||
} | ||
|
||
private final Distribution distribution; | ||
private final String version; | ||
private final Version internalVersion; | ||
|
||
private DeclaredOpenSearchVersion(final Distribution distribution, final String version) { | ||
this.distribution = distribution; | ||
this.version = version; | ||
|
||
internalVersion = Version.fromString(version); | ||
} | ||
|
||
static DeclaredOpenSearchVersion parse(final String versionString) { | ||
if(versionString == null) { | ||
return DEFAULT; | ||
} | ||
|
||
final String[] parts = versionString.split(":"); | ||
|
||
if(parts.length != 2) { | ||
throw new IllegalArgumentException("Invalid version string provided."); | ||
} | ||
|
||
final Distribution distribution = Distribution.valueOf(parts[0].toUpperCase()); | ||
|
||
return new DeclaredOpenSearchVersion(distribution, parts[1]); | ||
} | ||
|
||
@Override | ||
public int compareTo(final DeclaredOpenSearchVersion other) { | ||
final int distributionCompareTo = distribution.compareTo(other.distribution); | ||
|
||
if(distributionCompareTo != 0) { | ||
return distributionCompareTo; | ||
} | ||
|
||
return internalVersion.compareTo(other.internalVersion); | ||
} | ||
|
||
Distribution getDistribution() { | ||
return distribution; | ||
} | ||
|
||
String getVersion() { | ||
return version; | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
...ava/org/opensearch/dataprepper/plugins/sink/opensearch/DeclaredOpenSearchVersionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.plugins.sink.opensearch; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.CsvSource; | ||
|
||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.hamcrest.CoreMatchers.notNullValue; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
class DeclaredOpenSearchVersionTest { | ||
@ParameterizedTest | ||
@CsvSource({ | ||
"opensearch:1.2.4,OPENSEARCH,1.2.4", | ||
"opensearch:1.3.9,OPENSEARCH,1.3.9", | ||
"opensearch:2.2.1,OPENSEARCH,2.2.1", | ||
"opensearch:2.6.0,OPENSEARCH,2.6.0", | ||
"opendistro:1.3.0,OPENDISTRO,1.3.0", | ||
"opendistro:1.13.3,OPENDISTRO,1.13.3" | ||
}) | ||
void parse_should_return_expected(final String versionString, final DeclaredOpenSearchVersion.Distribution expectedDistribution, final String expectedVersion) { | ||
final DeclaredOpenSearchVersion version = DeclaredOpenSearchVersion.parse(versionString); | ||
|
||
assertThat(version, notNullValue()); | ||
assertThat(version.getDistribution(), equalTo(expectedDistribution)); | ||
assertThat(version.getVersion(), equalTo(expectedVersion)); | ||
} | ||
|
||
@Test | ||
void parse_with_null_should_return_minimum_version() { | ||
final DeclaredOpenSearchVersion version = DeclaredOpenSearchVersion.parse(null); | ||
|
||
assertThat(version, notNullValue()); | ||
assertThat(version.getDistribution(), equalTo(DeclaredOpenSearchVersion.Distribution.OPENSEARCH)); | ||
assertThat(version.getVersion(), equalTo("1.0.0")); | ||
} | ||
|
||
@ParameterizedTest | ||
@CsvSource({ | ||
"opensearch:1.2.4,opensearch:1.2.4,0", | ||
"opendistro:1.13.3,opendistro:1.13.3,0", | ||
"opensearch:1.2.4,opensearch:1.2.3,1", | ||
"opensearch:1.2.3,opensearch:1.2.4,-1", | ||
"opensearch:2.6.0,opensearch:1.2.3,1", | ||
"opensearch:1.2.3,opensearch:2.6.0,-1", | ||
"opensearch:1.3.9,opendistro:1.13.3,1", | ||
"opendistro:1.13.3,opensearch:1.3.9,-1" | ||
}) | ||
void compareTo_returns_correct_value(final String versionStringToTest, final String otherVersionString, final int expectedCompareTo) { | ||
final DeclaredOpenSearchVersion objectUnderTest = DeclaredOpenSearchVersion.parse(versionStringToTest); | ||
final DeclaredOpenSearchVersion otherVersion = DeclaredOpenSearchVersion.parse(otherVersionString); | ||
|
||
assertThat(objectUnderTest.compareTo(otherVersion), equalTo(expectedCompareTo)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.