Skip to content

Commit

Permalink
Added javadocs
Browse files Browse the repository at this point in the history
Signed-off-by: Shivansh Arora <[email protected]>
  • Loading branch information
shiv0408 committed Feb 20, 2024
1 parent 5d6a0ad commit 279dbbe
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
import java.util.Map;
import java.util.Objects;

/**
* Metadata for legacy templates
*
* @opensearch.internal
*/
public class TemplatesMetadata extends AbstractDiffable<TemplatesMetadata> implements ToXContentFragment {
public static TemplatesMetadata EMPTY_METADATA = builder().build();
private final Map<String, IndexTemplateMetadata> templates;
Expand Down Expand Up @@ -73,6 +78,11 @@ public int hashCode() {
return templates != null ? templates.hashCode() : 0;
}

/**
* Builder for the templates metadata
*
* @opensearch.api
*/
public static class Builder {
private final Map<String, IndexTemplateMetadata> templates;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ private static void declareParser(ConstructingObjectParser<ClusterMetadataManife
UPLOADED_TEMPLATES_METADATA
);
parser.declareNamedObjects(
ConstructingObjectParser.constructorArg(),
ConstructingObjectParser.optionalConstructorArg(),
UploadedMetadataAttribute.PARSER,
UPLOADED_CUSTOM_METADATA
);
Expand Down Expand Up @@ -732,9 +732,22 @@ public ClusterMetadataManifest build() {

}

public static interface UploadedMetadata {
/**
* Interface representing uploaded metadata
*/
public interface UploadedMetadata {
/**
* Gets the component or part of the system this upload belongs to.
*
* @return A string identifying the component
*/
String getComponent();

/**
* Gets the name of the file that was uploaded
*
* @return The name of the uploaded file as a string
*/
String getUploadedFilename();
}

Expand Down Expand Up @@ -855,6 +868,11 @@ public static UploadedIndexMetadata fromXContent(XContentParser parser) throws I
}
}

/**
* Metadata for uploaded metadata attribute
*
* @opensearch.internal
*/
public static class UploadedMetadataAttribute implements UploadedMetadata, Writeable, ToXContentFragment {
private static final ParseField UPLOADED_FILENAME_FIELD = new ParseField("uploaded_filename");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -575,14 +575,14 @@ private UploadedMetadataResults writeMetadataInParallel(
throw exception;
}
UploadedMetadataResults response = new UploadedMetadataResults();
for (Map.Entry<String, ClusterMetadataManifest.UploadedMetadata> entry : results.entrySet()) {
final String name = entry.getKey();
final ClusterMetadataManifest.UploadedMetadata uploadedMetadata = entry.getValue();
results.forEach((name, uploadedMetadata) -> {
if (uploadedMetadata.getClass().equals(UploadedIndexMetadata.class)) {
response.uploadedIndexMetadata.add((UploadedIndexMetadata) uploadedMetadata);
} else if (uploadedMetadata.getComponent().contains(CUSTOM_METADATA)) {
// component name for custom metadata will look like custom__<metadata-attribute>
response.uploadedCustomMetadataMap.put(name.split(DELIMITER)[1], (UploadedMetadataAttribute) uploadedMetadata);
String custom = name.split(DELIMITER)[1];
response.uploadedCustomMetadataMap.put(custom,
new UploadedMetadataAttribute(custom, uploadedMetadata.getUploadedFilename()));
} else if (COORDINATION_METADATA.equals(uploadedMetadata.getComponent())) {
response.uploadedCoordinationMetadata = (UploadedMetadataAttribute) uploadedMetadata;
} else if (SETTING_METADATA.equals(uploadedMetadata.getComponent())) {
Expand All @@ -592,7 +592,7 @@ private UploadedMetadataResults writeMetadataInParallel(
} else {
throw new IllegalStateException("Unexpected metadata component " + uploadedMetadata.getComponent());
}
}
});
return response;
}

Expand Down Expand Up @@ -957,7 +957,7 @@ private static String globalMetadataFileName(Metadata metadata) {
}

private static String metadataAttributeFileName(String componentPrefix, Long metadataVersion) {
// 123456789012_test-cluster/cluster-state/dsgYj10Nkso7/global-metadata/settings__<inverted_metadata_version>__<inverted__timestamp>__<codec_version>
// 123456789012_test-cluster/cluster-state/dsgYj10Nkso7/global-metadata/<componentPrefix>__<inverted_metadata_version>__<inverted__timestamp>__<codec_version>
return String.join(
DELIMITER,
componentPrefix,
Expand Down Expand Up @@ -1081,10 +1081,8 @@ private Metadata getGlobalMetadata(String clusterName, String clusterUUID, Clust
builder.coordinationMetadata(coordinationMetadata);
builder.persistentSettings(settingsMetadata);
builder.templates(templatesMetadata);
clusterMetadataManifest.getCustomMetadataMap().forEach((key, value) -> {
String custom = key.split(DELIMITER)[1];
builder.putCustom(custom, getCustomsMetadata(clusterName, clusterUUID, value.getUploadedFilename(), custom));
});
clusterMetadataManifest.getCustomMetadataMap().forEach((key, value) ->
builder.putCustom(key, getCustomsMetadata(clusterName, clusterUUID, value.getUploadedFilename(), key)));
return builder.build();
} else {
return Metadata.EMPTY_METADATA;
Expand All @@ -1099,7 +1097,7 @@ private Metadata getGlobalMetadata(String clusterName, String clusterUUID, Clust

private CoordinationMetadata getCoordinationMetadata(String clusterName, String clusterUUID, String coordinationMetadataFileName) {
try {
// Fetch Coordintaion metadata
// Fetch Coordination metadata
if (coordinationMetadataFileName != null) {
String[] splitPath = coordinationMetadataFileName.split("/");
return COORDINATION_METADATA_FORMAT.read(
Expand Down

0 comments on commit 279dbbe

Please sign in to comment.