Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Shivansh Arora <[email protected]>
  • Loading branch information
shiv0408 committed Feb 19, 2024
1 parent d0875f9 commit f6a2431
Show file tree
Hide file tree
Showing 5 changed files with 406 additions and 164 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,11 @@ private static class MetadataDiff implements Diff<Metadata> {
persistentSettings = after.persistentSettings;
hashesOfConsistentSettings = after.hashesOfConsistentSettings.diff(before.hashesOfConsistentSettings);
indices = DiffableUtils.diff(before.indices, after.indices, DiffableUtils.getStringKeySerializer());
templates = DiffableUtils.diff(before.templates.getTemplates(), after.templates.getTemplates(), DiffableUtils.getStringKeySerializer());
templates = DiffableUtils.diff(
before.templates.getTemplates(),
after.templates.getTemplates(),
DiffableUtils.getStringKeySerializer()
);
customs = DiffableUtils.diff(before.customs, after.customs, DiffableUtils.getStringKeySerializer(), CUSTOM_VALUE_SERIALIZER);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
package org.opensearch.cluster.metadata;

import org.opensearch.cluster.AbstractDiffable;
import org.opensearch.cluster.coordination.CoordinationMetadata;
import org.opensearch.common.annotation.PublicApi;
import org.opensearch.common.settings.Settings;
import org.opensearch.core.common.io.stream.StreamOutput;
import org.opensearch.core.xcontent.ToXContentFragment;
import org.opensearch.core.xcontent.XContentBuilder;
Expand Down Expand Up @@ -66,7 +63,7 @@ public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

TemplatesMetadata that = (TemplatesMetadata) o;
TemplatesMetadata that = (TemplatesMetadata) o;

return Objects.equals(templates, that.templates);
}
Expand Down Expand Up @@ -111,11 +108,11 @@ public TemplatesMetadata build() {
}

public static void toXContent(TemplatesMetadata templates, XContentBuilder builder, Params params) throws IOException {
// builder.startObject("templates-metadata");
for(IndexTemplateMetadata cursor : templates.getTemplates().values()) {
// builder.startObject("templates-metadata");
for (IndexTemplateMetadata cursor : templates.getTemplates().values()) {
IndexTemplateMetadata.Builder.toXContentWithTypes(cursor, builder, params);
}
// builder.endObject();
// builder.endObject();
}

public static TemplatesMetadata fromXContent(XContentParser parser) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,26 @@ private static void declareParser(ConstructingObjectParser<ClusterMetadataManife
parser.declareString(ConstructingObjectParser.constructorArg(), GLOBAL_METADATA_FIELD);
} else if (codec_version == CODEC_V2) {
parser.declareInt(ConstructingObjectParser.constructorArg(), CODEC_VERSION_FIELD);
parser.declareNamedObject(ConstructingObjectParser.constructorArg(), UploadedMetadataAttribute.PARSER, UPLOADED_COORDINATOR_METADATA);
parser.declareNamedObject(ConstructingObjectParser.constructorArg(), UploadedMetadataAttribute.PARSER, UPLOADED_SETTINGS_METADATA);
parser.declareNamedObject(ConstructingObjectParser.constructorArg(), UploadedMetadataAttribute.PARSER, UPLOADED_TEMPLATES_METADATA);
parser.declareNamedObjects(ConstructingObjectParser.constructorArg(), UploadedMetadataAttribute.PARSER, UPLOADED_CUSTOM_METADATA);
parser.declareNamedObject(
ConstructingObjectParser.optionalConstructorArg(),
UploadedMetadataAttribute.PARSER,
UPLOADED_COORDINATOR_METADATA
);
parser.declareNamedObject(
ConstructingObjectParser.optionalConstructorArg(),
UploadedMetadataAttribute.PARSER,
UPLOADED_SETTINGS_METADATA
);
parser.declareNamedObject(
ConstructingObjectParser.optionalConstructorArg(),
UploadedMetadataAttribute.PARSER,
UPLOADED_TEMPLATES_METADATA
);
parser.declareNamedObjects(
ConstructingObjectParser.constructorArg(),
UploadedMetadataAttribute.PARSER,
UPLOADED_CUSTOM_METADATA
);
}
}

Expand Down Expand Up @@ -300,7 +316,10 @@ public Map<String, UploadedMetadataAttribute> getCustomMetadataMap() {
}

public boolean hasMetadataAttributesFiles() {
return uploadedCoordinationMetadata != null || uploadedSettingsMetadata != null || uploadedTemplatesMetadata != null || !uploadedCustomMetadataMap.isEmpty();
return uploadedCoordinationMetadata != null
|| uploadedSettingsMetadata != null
|| uploadedTemplatesMetadata != null
|| !uploadedCustomMetadataMap.isEmpty();
}

public ClusterMetadataManifest(
Expand Down Expand Up @@ -370,7 +389,9 @@ public ClusterMetadataManifest(
this.uploadedCoordinationMetadata = uploadedCoordinationMetadata;
this.uploadedSettingsMetadata = uploadedSettingsMetadata;
this.uploadedTemplatesMetadata = uploadedTemplatesMetadata;
this.uploadedCustomMetadataMap = Collections.unmodifiableMap(uploadedCustomMetadataMap != null ? uploadedCustomMetadataMap : new HashMap<>());
this.uploadedCustomMetadataMap = Collections.unmodifiableMap(
uploadedCustomMetadataMap != null ? uploadedCustomMetadataMap : new HashMap<>()
);
}

public ClusterMetadataManifest(StreamInput in) throws IOException {
Expand All @@ -389,7 +410,9 @@ public ClusterMetadataManifest(StreamInput in) throws IOException {
this.uploadedCoordinationMetadata = new UploadedMetadataAttribute(in);
this.uploadedSettingsMetadata = new UploadedMetadataAttribute(in);
this.uploadedTemplatesMetadata = new UploadedMetadataAttribute(in);
this.uploadedCustomMetadataMap = Collections.unmodifiableMap(in.readMap(StreamInput::readString, UploadedMetadataAttribute::new));
this.uploadedCustomMetadataMap = Collections.unmodifiableMap(
in.readMap(StreamInput::readString, UploadedMetadataAttribute::new)
);
this.globalMetadataFileName = null;
} else if (in.getVersion().onOrAfter(Version.V_2_12_0)) {
this.codecVersion = in.readInt();
Expand Down Expand Up @@ -436,17 +459,23 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
builder.field(CLUSTER_UUID_COMMITTED.getPreferredName(), isClusterUUIDCommitted());
if (onOrAfterCodecVersion(CODEC_V2)) {
builder.field(CODEC_VERSION_FIELD.getPreferredName(), getCodecVersion());
builder.startObject(UPLOADED_COORDINATOR_METADATA.getPreferredName());
getCoordinationMetadata().toXContent(builder, params);
builder.endObject();
builder.startObject(UPLOADED_SETTINGS_METADATA.getPreferredName());
getSettingsMetadata().toXContent(builder, params);
builder.endObject();
builder.startObject(UPLOADED_TEMPLATES_METADATA.getPreferredName());
getTemplatesMetadata().toXContent(builder, params);
builder.endObject();
if (getCoordinationMetadata() != null) {
builder.startObject(UPLOADED_COORDINATOR_METADATA.getPreferredName());
getCoordinationMetadata().toXContent(builder, params);
builder.endObject();
}
if (getSettingsMetadata() != null) {
builder.startObject(UPLOADED_SETTINGS_METADATA.getPreferredName());
getSettingsMetadata().toXContent(builder, params);
builder.endObject();
}
if (getTemplatesMetadata() != null) {
builder.startObject(UPLOADED_TEMPLATES_METADATA.getPreferredName());
getTemplatesMetadata().toXContent(builder, params);
builder.endObject();
}
builder.startObject(UPLOADED_CUSTOM_METADATA.getPreferredName());
for (UploadedMetadataAttribute attribute: getCustomMetadataMap().values()) {
for (UploadedMetadataAttribute attribute : getCustomMetadataMap().values()) {
attribute.toXContent(builder, params);
}
builder.endObject();
Expand Down Expand Up @@ -705,6 +734,7 @@ public ClusterMetadataManifest build() {

public static interface UploadedMetadata {
String getComponent();

String getUploadedFilename();
}

Expand Down Expand Up @@ -888,10 +918,14 @@ public static UploadedMetadataAttribute fromXContent(XContentParser parser) thro

@Override
public String toString() {
return "UploadedMetadataAttribute{" +
"attributeName='" + attributeName + '\'' +
", uploadedFilename='" + uploadedFilename + '\'' +
'}';
return "UploadedMetadataAttribute{"
+ "attributeName='"
+ attributeName
+ '\''
+ ", uploadedFilename='"
+ uploadedFilename
+ '\''
+ '}';
}
}
}
Loading

0 comments on commit f6a2431

Please sign in to comment.