Skip to content

Commit

Permalink
Handle segment replication stats returning strings in some versions
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Farr <tsfarr@amazon.com>
  • Loading branch information
Xtansia committed Dec 20, 2024
1 parent b9d3335 commit a979a81
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.util.function.Function;
import javax.annotation.Generated;
import javax.annotation.Nonnull;
import org.opensearch.client.json.JsonData;
import org.opensearch.client.json.JsonpDeserializable;
import org.opensearch.client.json.JsonpDeserializer;
import org.opensearch.client.json.JsonpMapper;
Expand All @@ -61,11 +62,14 @@ public class SegmentReplicationStats
PlainJsonSerializable,
ToCopyableBuilder<SegmentReplicationStats.Builder, SegmentReplicationStats> {

private final long maxBytesBehind;
@Nonnull
private final JsonData maxBytesBehind;

private final long maxReplicationLag;
@Nonnull
private final JsonData maxReplicationLag;

private final long totalBytesBehind;
@Nonnull
private final JsonData totalBytesBehind;

// ---------------------------------------------------------------------------------------------

Expand All @@ -82,21 +86,24 @@ public static SegmentReplicationStats of(Function<SegmentReplicationStats.Builde
/**
* Required - API name: {@code max_bytes_behind}
*/
public final long maxBytesBehind() {
@Nonnull
public final JsonData maxBytesBehind() {
return this.maxBytesBehind;
}

/**
* Required - API name: {@code max_replication_lag}
*/
public final long maxReplicationLag() {
@Nonnull
public final JsonData maxReplicationLag() {
return this.maxReplicationLag;
}

/**
* Required - API name: {@code total_bytes_behind}
*/
public final long totalBytesBehind() {
@Nonnull
public final JsonData totalBytesBehind() {
return this.totalBytesBehind;
}

Expand All @@ -112,13 +119,13 @@ public void serialize(JsonGenerator generator, JsonpMapper mapper) {

protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
generator.writeKey("max_bytes_behind");
generator.write(this.maxBytesBehind);
this.maxBytesBehind.serialize(generator, mapper);

generator.writeKey("max_replication_lag");
generator.write(this.maxReplicationLag);
this.maxReplicationLag.serialize(generator, mapper);

generator.writeKey("total_bytes_behind");
generator.write(this.totalBytesBehind);
this.totalBytesBehind.serialize(generator, mapper);
}

// ---------------------------------------------------------------------------------------------
Expand All @@ -138,9 +145,9 @@ public static Builder builder() {
* Builder for {@link SegmentReplicationStats}.
*/
public static class Builder extends ObjectBuilderBase implements CopyableBuilder<Builder, SegmentReplicationStats> {
private Long maxBytesBehind;
private Long maxReplicationLag;
private Long totalBytesBehind;
private JsonData maxBytesBehind;
private JsonData maxReplicationLag;
private JsonData totalBytesBehind;

public Builder() {}

Expand All @@ -166,7 +173,7 @@ public Builder copy() {
* Required - API name: {@code max_bytes_behind}
*/
@Nonnull
public final Builder maxBytesBehind(long value) {
public final Builder maxBytesBehind(JsonData value) {
this.maxBytesBehind = value;
return this;
}
Expand All @@ -175,7 +182,7 @@ public final Builder maxBytesBehind(long value) {
* Required - API name: {@code max_replication_lag}
*/
@Nonnull
public final Builder maxReplicationLag(long value) {
public final Builder maxReplicationLag(JsonData value) {
this.maxReplicationLag = value;
return this;
}
Expand All @@ -184,7 +191,7 @@ public final Builder maxReplicationLag(long value) {
* Required - API name: {@code total_bytes_behind}
*/
@Nonnull
public final Builder totalBytesBehind(long value) {
public final Builder totalBytesBehind(JsonData value) {
this.totalBytesBehind = value;
return this;
}
Expand Down Expand Up @@ -214,17 +221,17 @@ public SegmentReplicationStats build() {
);

protected static void setupSegmentReplicationStatsDeserializer(ObjectDeserializer<SegmentReplicationStats.Builder> op) {
op.add(Builder::maxBytesBehind, JsonpDeserializer.longDeserializer(), "max_bytes_behind");
op.add(Builder::maxReplicationLag, JsonpDeserializer.longDeserializer(), "max_replication_lag");
op.add(Builder::totalBytesBehind, JsonpDeserializer.longDeserializer(), "total_bytes_behind");
op.add(Builder::maxBytesBehind, JsonData._DESERIALIZER, "max_bytes_behind");
op.add(Builder::maxReplicationLag, JsonData._DESERIALIZER, "max_replication_lag");
op.add(Builder::totalBytesBehind, JsonData._DESERIALIZER, "total_bytes_behind");
}

@Override
public int hashCode() {
int result = 17;
result = 31 * result + Long.hashCode(this.maxBytesBehind);
result = 31 * result + Long.hashCode(this.maxReplicationLag);
result = 31 * result + Long.hashCode(this.totalBytesBehind);
result = 31 * result + this.maxBytesBehind.hashCode();
result = 31 * result + this.maxReplicationLag.hashCode();
result = 31 * result + this.totalBytesBehind.hashCode();
return result;
}

Expand All @@ -233,8 +240,8 @@ public boolean equals(Object o) {
if (this == o) return true;
if (o == null || this.getClass() != o.getClass()) return false;
SegmentReplicationStats other = (SegmentReplicationStats) o;
return this.maxBytesBehind == other.maxBytesBehind
&& this.maxReplicationLag == other.maxReplicationLag
&& this.totalBytesBehind == other.totalBytesBehind;
return this.maxBytesBehind.equals(other.maxBytesBehind)
&& this.maxReplicationLag.equals(other.maxReplicationLag)
&& this.totalBytesBehind.equals(other.totalBytesBehind);
}
}
40 changes: 28 additions & 12 deletions java-codegen/opensearch-openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33906,18 +33906,34 @@ components:
- dfs_query_then_fetch
- query_then_fetch
_common___SegmentReplicationStats:
type: object
properties:
max_bytes_behind:
$ref: '#/components/schemas/_common___ByteCount'
max_replication_lag:
$ref: '#/components/schemas/_common___ByteCount'
total_bytes_behind:
$ref: '#/components/schemas/_common___ByteCount'
required:
- max_bytes_behind
- max_replication_lag
- total_bytes_behind
oneOf:
- x-version-added: 2.10.0
x-version-removed: 2.12.0
type: object
properties:
max_bytes_behind:
$ref: '#/components/schemas/_common___HumanReadableByteCount'
max_replication_lag:
$ref: '#/components/schemas/_common___Duration'
total_bytes_behind:
$ref: '#/components/schemas/_common___HumanReadableByteCount'
required:
- max_bytes_behind
- max_replication_lag
- total_bytes_behind
- x-version-added: 2.12.0
type: object
properties:
max_bytes_behind:
$ref: '#/components/schemas/_common___ByteCount'
max_replication_lag:
$ref: '#/components/schemas/_common___DurationValueUnitMillis'
total_bytes_behind:
$ref: '#/components/schemas/_common___ByteCount'
required:
- max_bytes_behind
- max_replication_lag
- total_bytes_behind
_common___SegmentsStats:
type: object
properties:
Expand Down

0 comments on commit a979a81

Please sign in to comment.