Skip to content

Commit

Permalink
Make componentPrefix optional for backward compatibility
Browse files Browse the repository at this point in the history
Signed-off-by: Sooraj Sinha <soosinha@amazon.com>
  • Loading branch information
soosinha committed Jul 8, 2024
1 parent ed1d852 commit 5303ebc
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,7 @@ private static String componentPrefix(Object[] fields) {
PARSER.declareString(ConstructingObjectParser.constructorArg(), INDEX_NAME_FIELD);
PARSER.declareString(ConstructingObjectParser.constructorArg(), INDEX_UUID_FIELD);
PARSER.declareString(ConstructingObjectParser.constructorArg(), UPLOADED_FILENAME_FIELD);
PARSER.declareString(ConstructingObjectParser.constructorArg(), COMPONENT_PREFIX_FIELD);
PARSER.declareString(ConstructingObjectParser.optionalConstructorArg(), COMPONENT_PREFIX_FIELD);
}

static final String COMPONENT_PREFIX = "index--";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,25 @@ public void testUploadedIndexMetadataSerializationEqualsHashCode() {
);
}

public void testUploadedIndexMetadataWithoutComponentPrefix() throws IOException {
final UploadedIndexMetadata originalUploadedIndexMetadata = new UploadedIndexMetadataV1(
"test-index",
"test-index-uuid",
"test_file_name"
);
final XContentBuilder builder = JsonXContent.contentBuilder();
builder.startObject();
originalUploadedIndexMetadata.toXContent(builder, ToXContent.EMPTY_PARAMS);
builder.endObject();

try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) {
final UploadedIndexMetadata fromXContentUploadedIndexMetadata = UploadedIndexMetadata.fromXContent(parser);
assertEquals(originalUploadedIndexMetadata.getIndexName(), fromXContentUploadedIndexMetadata.getIndexName());
assertEquals(originalUploadedIndexMetadata.getIndexUUID(), fromXContentUploadedIndexMetadata.getIndexUUID());
assertEquals(originalUploadedIndexMetadata.getUploadedFilename(), fromXContentUploadedIndexMetadata.getUploadedFilename());
}
}

private UploadedIndexMetadata randomlyChangingUploadedIndexMetadata(UploadedIndexMetadata uploadedIndexMetadata) {
switch (randomInt(2)) {
case 0:
Expand All @@ -642,4 +661,18 @@ private UploadedIndexMetadata randomlyChangingUploadedIndexMetadata(UploadedInde
}
return uploadedIndexMetadata;
}

private static class UploadedIndexMetadataV1 extends UploadedIndexMetadata {

public UploadedIndexMetadataV1(String indexName, String indexUUID, String uploadedFileName) {
super(indexName, indexUUID, uploadedFileName);
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
return builder.field("index_name", getIndexName())
.field("index_uuid", getIndexUUID())
.field("uploaded_filename", getUploadedFilePath());
}
}
}

0 comments on commit 5303ebc

Please sign in to comment.