Skip to content

Commit

Permalink
Add logic to fetch previousClusterUUID
Browse files Browse the repository at this point in the history
Signed-off-by: Sooraj Sinha <soosinha@amazon.com>
  • Loading branch information
soosinha committed Sep 7, 2023
1 parent 3f18e0c commit 660675c
Show file tree
Hide file tree
Showing 5 changed files with 300 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class ClusterMetadataManifest implements Writeable, ToXContentFragment {
private static final ParseField NODE_ID_FIELD = new ParseField("node_id");
private static final ParseField COMMITTED_FIELD = new ParseField("committed");
private static final ParseField INDICES_FIELD = new ParseField("indices");
private static final ParseField PREVIOUS_CLUSTER_UUID = new ParseField("previous_cluster_uuid");

private static long term(Object[] fields) {
return (long) fields[0];
Expand Down Expand Up @@ -74,6 +75,10 @@ private static List<UploadedIndexMetadata> indices(Object[] fields) {
return (List<UploadedIndexMetadata>) fields[7];
}

private static String previousClusterUUID(Object[] fields) {
return (String) fields[8];
}

private static final ConstructingObjectParser<ClusterMetadataManifest, Void> PARSER = new ConstructingObjectParser<>(
"cluster_metadata_manifest",
fields -> new ClusterMetadataManifest(
Expand All @@ -84,7 +89,8 @@ private static List<UploadedIndexMetadata> indices(Object[] fields) {
opensearchVersion(fields),
nodeId(fields),
committed(fields),
indices(fields)
indices(fields),
previousClusterUUID(fields)
)
);

Expand All @@ -101,6 +107,7 @@ private static List<UploadedIndexMetadata> indices(Object[] fields) {
(p, c) -> UploadedIndexMetadata.fromXContent(p),
INDICES_FIELD
);
PARSER.declareString(ConstructingObjectParser.constructorArg(), PREVIOUS_CLUSTER_UUID);
}

private final List<UploadedIndexMetadata> indices;
Expand All @@ -111,6 +118,7 @@ private static List<UploadedIndexMetadata> indices(Object[] fields) {
private final Version opensearchVersion;
private final String nodeId;
private final boolean committed;
private final String previousClusterUUID;

public List<UploadedIndexMetadata> getIndices() {
return indices;
Expand Down Expand Up @@ -144,6 +152,10 @@ public boolean isCommitted() {
return committed;
}

public String getPreviousClusterUUID() {
return previousClusterUUID;
}

public ClusterMetadataManifest(
long clusterTerm,
long version,
Expand All @@ -152,7 +164,8 @@ public ClusterMetadataManifest(
Version opensearchVersion,
String nodeId,
boolean committed,
List<UploadedIndexMetadata> indices
List<UploadedIndexMetadata> indices,
String previousClusterUUID
) {
this.clusterTerm = clusterTerm;
this.stateVersion = version;
Expand All @@ -162,6 +175,7 @@ public ClusterMetadataManifest(
this.nodeId = nodeId;
this.committed = committed;
this.indices = Collections.unmodifiableList(indices);
this.previousClusterUUID = previousClusterUUID;
}

public ClusterMetadataManifest(StreamInput in) throws IOException {
Expand All @@ -173,6 +187,7 @@ public ClusterMetadataManifest(StreamInput in) throws IOException {
this.nodeId = in.readString();
this.committed = in.readBoolean();
this.indices = Collections.unmodifiableList(in.readList(UploadedIndexMetadata::new));
this.previousClusterUUID = in.readString();
}

public static Builder builder() {
Expand All @@ -199,6 +214,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
}
}
builder.endArray();
builder.field(PREVIOUS_CLUSTER_UUID.getPreferredName(), getPreviousClusterUUID());
return builder;
}

Expand All @@ -212,6 +228,7 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeString(nodeId);
out.writeBoolean(committed);
out.writeCollection(indices);
out.writeString(previousClusterUUID);
}

@Override
Expand All @@ -230,12 +247,23 @@ public boolean equals(Object o) {
&& Objects.equals(stateUUID, that.stateUUID)
&& Objects.equals(opensearchVersion, that.opensearchVersion)
&& Objects.equals(nodeId, that.nodeId)
&& Objects.equals(committed, that.committed);
&& Objects.equals(committed, that.committed)
&& Objects.equals(previousClusterUUID, that.previousClusterUUID);
}

@Override
public int hashCode() {
return Objects.hash(indices, clusterTerm, stateVersion, clusterUUID, stateUUID, opensearchVersion, nodeId, committed);
return Objects.hash(
indices,
clusterTerm,
stateVersion,
clusterUUID,
stateUUID,
opensearchVersion,
nodeId,
committed,
previousClusterUUID
);
}

@Override
Expand All @@ -261,6 +289,7 @@ public static class Builder {
private String stateUUID;
private Version opensearchVersion;
private String nodeId;
private String previousClusterUUID;
private boolean committed;

public Builder indices(List<UploadedIndexMetadata> indices) {
Expand Down Expand Up @@ -307,6 +336,11 @@ public List<UploadedIndexMetadata> getIndices() {
return indices;
}

public Builder previousClusterUUID(String previousClusterUUID) {
this.previousClusterUUID = previousClusterUUID;
return this;
}

public Builder() {
indices = new ArrayList<>();
}
Expand All @@ -320,6 +354,7 @@ public Builder(ClusterMetadataManifest manifest) {
this.nodeId = manifest.nodeId;
this.committed = manifest.committed;
this.indices = new ArrayList<>(manifest.indices);
this.previousClusterUUID = manifest.previousClusterUUID;
}

public ClusterMetadataManifest build() {
Expand All @@ -331,7 +366,8 @@ public ClusterMetadataManifest build() {
opensearchVersion,
nodeId,
committed,
indices
indices,
previousClusterUUID
);
}

Expand Down
Loading

0 comments on commit 660675c

Please sign in to comment.