Skip to content

Remove fromXContent from IndexUpgradeInfoResponse #35934

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

Merged
Merged
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 @@ -9,54 +9,18 @@
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;

import java.io.IOException;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg;

public class IndexUpgradeInfoResponse extends ActionResponse implements ToXContentObject {

private static final ParseField INDICES = new ParseField("indices");
private static final ParseField ACTION_REQUIRED = new ParseField("action_required");

private static final ConstructingObjectParser<IndexUpgradeInfoResponse, String> PARSER =
new ConstructingObjectParser<>("IndexUpgradeInfoResponse",
true,
(a, c) -> {
@SuppressWarnings("unchecked")
Map<String, Object> map = (Map<String, Object>)a[0];
Map<String, UpgradeActionRequired> actionsRequired = map.entrySet().stream()
.filter(e -> {
if (e.getValue() instanceof Map == false) {
return false;
}
@SuppressWarnings("unchecked")
Map<String, Object> value =(Map<String, Object>)e.getValue();
return value.containsKey(ACTION_REQUIRED.getPreferredName());
})
.collect(Collectors.toMap(
Map.Entry::getKey,
e -> {
@SuppressWarnings("unchecked")
Map<String, Object> value = (Map<String, Object>) e.getValue();
return UpgradeActionRequired.fromString((String)value.get(ACTION_REQUIRED.getPreferredName()));
}
));
return new IndexUpgradeInfoResponse(actionsRequired);
});

static {
PARSER.declareObject(constructorArg(), (p, c) -> p.map(), INDICES);
}


private Map<String, UpgradeActionRequired> actions;

public IndexUpgradeInfoResponse() {
Expand Down Expand Up @@ -113,8 +77,4 @@ public boolean equals(Object o) {
public int hashCode() {
return Objects.hash(actions);
}

public static IndexUpgradeInfoResponse fromXContent(XContentParser parser) {
return PARSER.apply(parser, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.protocol.AbstractHlrcStreamableXContentTestCase;

import java.io.IOException;
import java.util.AbstractMap;
import java.util.HashMap;
import java.util.Iterator;
Expand All @@ -19,12 +18,7 @@ public class IndexUpgradeInfoResponseTests extends
AbstractHlrcStreamableXContentTestCase<IndexUpgradeInfoResponse, org.elasticsearch.client.migration.IndexUpgradeInfoResponse> {

@Override
protected IndexUpgradeInfoResponse doParseInstance(XContentParser parser) {
return IndexUpgradeInfoResponse.fromXContent(parser);
}

@Override
public org.elasticsearch.client.migration.IndexUpgradeInfoResponse doHlrcParseInstance(XContentParser parser) throws IOException {
public org.elasticsearch.client.migration.IndexUpgradeInfoResponse doHlrcParseInstance(XContentParser parser) {
return org.elasticsearch.client.migration.IndexUpgradeInfoResponse.fromXContent(parser);
}

Expand Down