Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom toXContent implementations #13833

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import org.opensearch.core.xcontent.XContentParser.Token;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.function.Consumer;

Expand Down Expand Up @@ -178,4 +180,14 @@ public static <T> void parseTypedKeysObject(XContentParser parser, String delimi
throw new ParsingException(parser.getTokenLocation(), "Failed to parse object: empty key");
}
}

public static List<String> parseStringList(XContentParser parser) throws IOException {
List<String> valueList = new ArrayList<>();
ensureExpectedToken(Token.START_ARRAY, parser.currentToken(), parser);
while (parser.nextToken() != Token.END_ARRAY) {
ensureExpectedToken(Token.VALUE_STRING, parser.currentToken(), parser);
valueList.add(parser.text());
}
return valueList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@

import org.opensearch.LegacyESVersion;
import org.opensearch.Version;
import org.opensearch.cluster.metadata.Metadata;
import org.opensearch.core.common.Strings;
import org.opensearch.core.common.io.stream.StreamInput;
import org.opensearch.core.common.io.stream.StreamOutput;
import org.opensearch.core.common.io.stream.Writeable;
import org.opensearch.core.xcontent.MediaTypeRegistry;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.core.xcontent.XContentParser;
import org.opensearch.core.xcontent.XContentParserUtils;
import org.opensearch.repositories.RepositoryOperation;

import java.io.IOException;
Expand Down Expand Up @@ -101,13 +104,47 @@
builder.startObject();
{
builder.field("repository", entry.repository);
if (params.param(Metadata.CONTEXT_MODE_PARAM, Metadata.CONTEXT_MODE_API).equals(Metadata.CONTEXT_MODE_GATEWAY)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about the BWC for this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default when we are using toXContent API mode is passed, we only pass Gateway when we are saving cluster state as persisted state in remote. So, by default I am putting the params as API and only adding extra fields if the mode is Gateway mode which is only used in our use case.

builder.field("repository_state_id", entry.repositoryStateId);

Check warning on line 108 in server/src/main/java/org/opensearch/cluster/RepositoryCleanupInProgress.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/cluster/RepositoryCleanupInProgress.java#L108

Added line #L108 was not covered by tests
} // else we don't serialize it
}
builder.endObject();
}
builder.endArray();
return builder;
}

public static RepositoryCleanupInProgress fromXContent(XContentParser parser) throws IOException {
if (parser.currentToken() == null) {
parser.nextToken();

Check warning on line 119 in server/src/main/java/org/opensearch/cluster/RepositoryCleanupInProgress.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/cluster/RepositoryCleanupInProgress.java#L119

Added line #L119 was not covered by tests
}
XContentParserUtils.ensureFieldName(parser, parser.currentToken(), TYPE);
parser.nextToken();
XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_ARRAY, parser.currentToken(), parser);
List<Entry> entries = new ArrayList<>();

Check warning on line 124 in server/src/main/java/org/opensearch/cluster/RepositoryCleanupInProgress.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/cluster/RepositoryCleanupInProgress.java#L121-L124

Added lines #L121 - L124 were not covered by tests
while (parser.nextToken() != XContentParser.Token.END_ARRAY) {
XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser);
String repository = null;
long repositoryStateId = -1L;

Check warning on line 128 in server/src/main/java/org/opensearch/cluster/RepositoryCleanupInProgress.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/cluster/RepositoryCleanupInProgress.java#L126-L128

Added lines #L126 - L128 were not covered by tests
while (parser.nextToken() != XContentParser.Token.END_OBJECT) {
XContentParserUtils.ensureExpectedToken(XContentParser.Token.FIELD_NAME, parser.currentToken(), parser);
String currentFieldName = parser.currentName();
parser.nextToken();

Check warning on line 132 in server/src/main/java/org/opensearch/cluster/RepositoryCleanupInProgress.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/cluster/RepositoryCleanupInProgress.java#L130-L132

Added lines #L130 - L132 were not covered by tests
if ("repository".equals(currentFieldName)) {
repository = parser.text();

Check warning on line 134 in server/src/main/java/org/opensearch/cluster/RepositoryCleanupInProgress.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/cluster/RepositoryCleanupInProgress.java#L134

Added line #L134 was not covered by tests
} else if ("repository_state_id".equals(currentFieldName)) {
// only XContent parsed with {@link Metadata.CONTEXT_MODE_GATEWAY} will have the repository state id and can be
// deserialized
repositoryStateId = parser.longValue();

Check warning on line 138 in server/src/main/java/org/opensearch/cluster/RepositoryCleanupInProgress.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/cluster/RepositoryCleanupInProgress.java#L138

Added line #L138 was not covered by tests
} else {
throw new IllegalArgumentException("unknown field [" + currentFieldName + "]");

Check warning on line 140 in server/src/main/java/org/opensearch/cluster/RepositoryCleanupInProgress.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/cluster/RepositoryCleanupInProgress.java#L140

Added line #L140 was not covered by tests
}
}
entries.add(new Entry(repository, repositoryStateId));
}
return new RepositoryCleanupInProgress(entries);

Check warning on line 145 in server/src/main/java/org/opensearch/cluster/RepositoryCleanupInProgress.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/cluster/RepositoryCleanupInProgress.java#L142-L145

Added lines #L142 - L145 were not covered by tests
}

@Override
public String toString() {
return Strings.toString(MediaTypeRegistry.JSON, this);
Expand Down
195 changes: 164 additions & 31 deletions server/src/main/java/org/opensearch/cluster/RestoreInProgress.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,22 @@

import org.opensearch.Version;
import org.opensearch.cluster.ClusterState.Custom;
import org.opensearch.cluster.metadata.Metadata;
import org.opensearch.common.annotation.PublicApi;
import org.opensearch.core.common.io.stream.StreamInput;
import org.opensearch.core.common.io.stream.StreamOutput;
import org.opensearch.core.common.io.stream.Writeable;
import org.opensearch.core.index.shard.ShardId;
import org.opensearch.core.xcontent.ToXContent;
import org.opensearch.core.xcontent.ToXContentFragment;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.core.xcontent.XContentParser;
import org.opensearch.core.xcontent.XContentParserUtils;
import org.opensearch.snapshots.Snapshot;
import org.opensearch.snapshots.SnapshotId;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
Expand All @@ -52,6 +58,8 @@
import java.util.Objects;
import java.util.UUID;

import static org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken;

/**
* Meta data about restore processes that are currently executing
*
Expand Down Expand Up @@ -144,7 +152,7 @@
* @opensearch.api
*/
@PublicApi(since = "1.0.0")
public static class Entry {
public static class Entry implements ToXContentFragment {
private final String uuid;
private final State state;
private final Snapshot snapshot;
Expand Down Expand Up @@ -236,6 +244,144 @@
public int hashCode() {
return Objects.hash(uuid, snapshot, state, indices, shards);
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
boolean isGatewayXContent = params.param(Metadata.CONTEXT_MODE_PARAM, Metadata.CONTEXT_MODE_API)
.equals(Metadata.CONTEXT_MODE_GATEWAY);
builder.startObject();
builder.field("snapshot", snapshot().getSnapshotId().getName());
builder.field("repository", snapshot().getRepository());
builder.field("state", state());

Check warning on line 255 in server/src/main/java/org/opensearch/cluster/RestoreInProgress.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/cluster/RestoreInProgress.java#L250-L255

Added lines #L250 - L255 were not covered by tests
if (isGatewayXContent) {
builder.field("snapshot_uuid", snapshot().getSnapshotId().getUUID());
builder.field("uuid", uuid());

Check warning on line 258 in server/src/main/java/org/opensearch/cluster/RestoreInProgress.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/cluster/RestoreInProgress.java#L257-L258

Added lines #L257 - L258 were not covered by tests
}
builder.startArray("indices");

Check warning on line 260 in server/src/main/java/org/opensearch/cluster/RestoreInProgress.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/cluster/RestoreInProgress.java#L260

Added line #L260 was not covered by tests
{
for (String index : indices()) {
builder.value(index);
}

Check warning on line 264 in server/src/main/java/org/opensearch/cluster/RestoreInProgress.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/cluster/RestoreInProgress.java#L263-L264

Added lines #L263 - L264 were not covered by tests
}
builder.endArray();
builder.startArray("shards");

Check warning on line 267 in server/src/main/java/org/opensearch/cluster/RestoreInProgress.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/cluster/RestoreInProgress.java#L266-L267

Added lines #L266 - L267 were not covered by tests
{
for (final Map.Entry<ShardId, ShardRestoreStatus> shardEntry : shards.entrySet()) {
ShardId shardId = shardEntry.getKey();
ShardRestoreStatus status = shardEntry.getValue();
builder.startObject();

Check warning on line 272 in server/src/main/java/org/opensearch/cluster/RestoreInProgress.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/cluster/RestoreInProgress.java#L270-L272

Added lines #L270 - L272 were not covered by tests
{
builder.field("index", shardId.getIndex());
builder.field("shard", shardId.getId());
builder.field("state", status.state());

Check warning on line 276 in server/src/main/java/org/opensearch/cluster/RestoreInProgress.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/cluster/RestoreInProgress.java#L274-L276

Added lines #L274 - L276 were not covered by tests
if (isGatewayXContent) {
builder.field("index_uuid", shardId.getIndex().getUUID());

Check warning on line 278 in server/src/main/java/org/opensearch/cluster/RestoreInProgress.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/cluster/RestoreInProgress.java#L278

Added line #L278 was not covered by tests
if (status.nodeId() != null) builder.field("node_id", status.nodeId());
if (status.reason() != null) builder.field("reason", status.reason());
}
}
builder.endObject();
}

Check warning on line 284 in server/src/main/java/org/opensearch/cluster/RestoreInProgress.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/cluster/RestoreInProgress.java#L283-L284

Added lines #L283 - L284 were not covered by tests
}

builder.endArray();
builder.endObject();
return builder;

Check warning on line 289 in server/src/main/java/org/opensearch/cluster/RestoreInProgress.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/cluster/RestoreInProgress.java#L287-L289

Added lines #L287 - L289 were not covered by tests
}

public static Entry fromXContent(XContentParser parser) throws IOException {
if (parser.currentToken() == null) {
parser.nextToken();

Check warning on line 294 in server/src/main/java/org/opensearch/cluster/RestoreInProgress.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/cluster/RestoreInProgress.java#L294

Added line #L294 was not covered by tests
}
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.currentToken(), parser);
String snapshotName = null;
String snapshotRepository = null;
String snapshotUUID = null;
int state = -1;
String uuid = null;
List<String> indices = new ArrayList<>();
Map<ShardId, ShardRestoreStatus> shards = new HashMap<>();

Check warning on line 303 in server/src/main/java/org/opensearch/cluster/RestoreInProgress.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/cluster/RestoreInProgress.java#L296-L303

Added lines #L296 - L303 were not covered by tests
while (parser.nextToken() != XContentParser.Token.END_OBJECT) {
ensureExpectedToken(XContentParser.Token.FIELD_NAME, parser.currentToken(), parser);
String currentFieldName = parser.currentName();
parser.nextToken();

Check warning on line 307 in server/src/main/java/org/opensearch/cluster/RestoreInProgress.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/cluster/RestoreInProgress.java#L305-L307

Added lines #L305 - L307 were not covered by tests
switch (currentFieldName) {
case "snapshot":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could be made constant.

snapshotName = parser.text();
break;

Check warning on line 311 in server/src/main/java/org/opensearch/cluster/RestoreInProgress.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/cluster/RestoreInProgress.java#L310-L311

Added lines #L310 - L311 were not covered by tests
case "repository":
snapshotRepository = parser.text();
break;

Check warning on line 314 in server/src/main/java/org/opensearch/cluster/RestoreInProgress.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/cluster/RestoreInProgress.java#L313-L314

Added lines #L313 - L314 were not covered by tests
case "state":
state = parser.intValue();
break;

Check warning on line 317 in server/src/main/java/org/opensearch/cluster/RestoreInProgress.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/cluster/RestoreInProgress.java#L316-L317

Added lines #L316 - L317 were not covered by tests
case "snapshot_uuid":
snapshotUUID = parser.text();
break;

Check warning on line 320 in server/src/main/java/org/opensearch/cluster/RestoreInProgress.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/cluster/RestoreInProgress.java#L319-L320

Added lines #L319 - L320 were not covered by tests
case "uuid":
uuid = parser.text();
break;

Check warning on line 323 in server/src/main/java/org/opensearch/cluster/RestoreInProgress.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/cluster/RestoreInProgress.java#L322-L323

Added lines #L322 - L323 were not covered by tests
case "indices":
ensureExpectedToken(XContentParser.Token.START_ARRAY, parser.currentToken(), parser);

Check warning on line 325 in server/src/main/java/org/opensearch/cluster/RestoreInProgress.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/cluster/RestoreInProgress.java#L325

Added line #L325 was not covered by tests
while (parser.nextToken() != XContentParser.Token.END_ARRAY) {
indices.add(parser.text());

Check warning on line 327 in server/src/main/java/org/opensearch/cluster/RestoreInProgress.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/cluster/RestoreInProgress.java#L327

Added line #L327 was not covered by tests
}
break;
case "shards":
ensureExpectedToken(XContentParser.Token.START_ARRAY, parser.currentToken(), parser);

Check warning on line 331 in server/src/main/java/org/opensearch/cluster/RestoreInProgress.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/cluster/RestoreInProgress.java#L331

Added line #L331 was not covered by tests
while (parser.nextToken() != XContentParser.Token.END_ARRAY) {
String indexName = null;
String indexUUID = null;
int shardId = -1;
int restoreState = -1;
String nodeId = null;
String reason = null;
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.currentToken(), parser);

Check warning on line 339 in server/src/main/java/org/opensearch/cluster/RestoreInProgress.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/cluster/RestoreInProgress.java#L333-L339

Added lines #L333 - L339 were not covered by tests
while (parser.nextToken() != XContentParser.Token.END_OBJECT) {
ensureExpectedToken(XContentParser.Token.FIELD_NAME, parser.currentToken(), parser);
String currentShardFieldName = parser.currentName();
parser.nextToken();

Check warning on line 343 in server/src/main/java/org/opensearch/cluster/RestoreInProgress.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/cluster/RestoreInProgress.java#L341-L343

Added lines #L341 - L343 were not covered by tests
switch (currentShardFieldName) {
case "index":
indexName = parser.text();
break;

Check warning on line 347 in server/src/main/java/org/opensearch/cluster/RestoreInProgress.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/cluster/RestoreInProgress.java#L346-L347

Added lines #L346 - L347 were not covered by tests
case "shard":
shardId = parser.intValue();
break;

Check warning on line 350 in server/src/main/java/org/opensearch/cluster/RestoreInProgress.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/cluster/RestoreInProgress.java#L349-L350

Added lines #L349 - L350 were not covered by tests
case "state":
restoreState = parser.intValue();
break;

Check warning on line 353 in server/src/main/java/org/opensearch/cluster/RestoreInProgress.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/cluster/RestoreInProgress.java#L352-L353

Added lines #L352 - L353 were not covered by tests
case "index_uuid":
indexUUID = parser.text();
break;

Check warning on line 356 in server/src/main/java/org/opensearch/cluster/RestoreInProgress.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/cluster/RestoreInProgress.java#L355-L356

Added lines #L355 - L356 were not covered by tests
case "node_id":
nodeId = parser.text();
break;

Check warning on line 359 in server/src/main/java/org/opensearch/cluster/RestoreInProgress.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/cluster/RestoreInProgress.java#L358-L359

Added lines #L358 - L359 were not covered by tests
case "reason":
reason = parser.text();
break;

Check warning on line 362 in server/src/main/java/org/opensearch/cluster/RestoreInProgress.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/cluster/RestoreInProgress.java#L361-L362

Added lines #L361 - L362 were not covered by tests
default:
throw new IllegalArgumentException("unknown field [" + currentFieldName + "]");

Check warning on line 364 in server/src/main/java/org/opensearch/cluster/RestoreInProgress.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/cluster/RestoreInProgress.java#L364

Added line #L364 was not covered by tests
}
}
shards.put(

Check warning on line 367 in server/src/main/java/org/opensearch/cluster/RestoreInProgress.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/cluster/RestoreInProgress.java#L366-L367

Added lines #L366 - L367 were not covered by tests
new ShardId(indexName, indexUUID, shardId),
new ShardRestoreStatus(nodeId, State.fromValue((byte) restoreState), reason)

Check warning on line 369 in server/src/main/java/org/opensearch/cluster/RestoreInProgress.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/cluster/RestoreInProgress.java#L369

Added line #L369 was not covered by tests
);
}

Check warning on line 371 in server/src/main/java/org/opensearch/cluster/RestoreInProgress.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/cluster/RestoreInProgress.java#L371

Added line #L371 was not covered by tests
break;
default:
throw new IllegalArgumentException("unknown field [" + currentFieldName + "]");

Check warning on line 374 in server/src/main/java/org/opensearch/cluster/RestoreInProgress.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/cluster/RestoreInProgress.java#L374

Added line #L374 was not covered by tests
}
}
return new Entry(

Check warning on line 377 in server/src/main/java/org/opensearch/cluster/RestoreInProgress.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/cluster/RestoreInProgress.java#L376-L377

Added lines #L376 - L377 were not covered by tests
uuid,
new Snapshot(snapshotRepository, new SnapshotId(snapshotName, snapshotUUID)),
State.fromValue((byte) state),

Check warning on line 380 in server/src/main/java/org/opensearch/cluster/RestoreInProgress.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/cluster/RestoreInProgress.java#L380

Added line #L380 was not covered by tests
indices,
shards
);
}
}

/**
Expand Down Expand Up @@ -495,46 +641,33 @@
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException {
builder.startArray("snapshots");
for (final Entry entry : entries.values()) {
toXContent(entry, builder);
toXContent(entry, builder, ToXContent.EMPTY_PARAMS);

Check warning on line 644 in server/src/main/java/org/opensearch/cluster/RestoreInProgress.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/cluster/RestoreInProgress.java#L644

Added line #L644 was not covered by tests
}
builder.endArray();
return builder;
}

public static RestoreInProgress fromXContent(XContentParser parser) throws IOException {
if (parser.currentToken() == null) {
parser.nextToken();

Check warning on line 652 in server/src/main/java/org/opensearch/cluster/RestoreInProgress.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/cluster/RestoreInProgress.java#L652

Added line #L652 was not covered by tests
}
final Map<String, Entry> entries = new HashMap<>();
XContentParserUtils.ensureFieldName(parser, parser.currentToken(), "snapshots");

Check warning on line 655 in server/src/main/java/org/opensearch/cluster/RestoreInProgress.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/cluster/RestoreInProgress.java#L654-L655

Added lines #L654 - L655 were not covered by tests
while (parser.nextToken() != XContentParser.Token.END_ARRAY) {
final Entry entry = Entry.fromXContent(parser);
entries.put(entry.uuid, entry);
}
return new RestoreInProgress(entries);

Check warning on line 660 in server/src/main/java/org/opensearch/cluster/RestoreInProgress.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/cluster/RestoreInProgress.java#L657-L660

Added lines #L657 - L660 were not covered by tests
}

/**
* Serializes single restore operation
*
* @param entry restore operation metadata
* @param builder XContent builder
* @param params
*/
public void toXContent(Entry entry, XContentBuilder builder) throws IOException {
builder.startObject();
builder.field("snapshot", entry.snapshot().getSnapshotId().getName());
builder.field("repository", entry.snapshot().getRepository());
builder.field("state", entry.state());
builder.startArray("indices");
{
for (String index : entry.indices()) {
builder.value(index);
}
}
builder.endArray();
builder.startArray("shards");
{
for (final Map.Entry<ShardId, ShardRestoreStatus> shardEntry : entry.shards.entrySet()) {
ShardId shardId = shardEntry.getKey();
ShardRestoreStatus status = shardEntry.getValue();
builder.startObject();
{
builder.field("index", shardId.getIndex());
builder.field("shard", shardId.getId());
builder.field("state", status.state());
}
builder.endObject();
}
}

builder.endArray();
builder.endObject();
public void toXContent(Entry entry, XContentBuilder builder, ToXContent.Params params) throws IOException {
entry.toXContent(builder, params);

Check warning on line 671 in server/src/main/java/org/opensearch/cluster/RestoreInProgress.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/cluster/RestoreInProgress.java#L671

Added line #L671 was not covered by tests
}
}
Loading
Loading