Remove version read/write logic in Verify Response (#30879)
Since master will always communicate with a >=6.4 node, the logic for checking if the node is 6.4 and conditionally reading and writing based on that can be removed from master. This logic will stay in 6.x as it is the bridge to the cleaner response in master. This also unmutes the failing test due to this bwc change. Closes #30807
This commit is contained in:
parent
3960a7a310
commit
d826cb36c3
|
@ -51,9 +51,6 @@ setup:
|
|||
|
||||
---
|
||||
"Verify created repository":
|
||||
- skip:
|
||||
version: "all"
|
||||
reason: AwaitsFix for https://github.com/elastic/elasticsearch/issues/30807
|
||||
- do:
|
||||
snapshot.verify_repository:
|
||||
repository: test_repo_get_2
|
||||
|
|
|
@ -73,7 +73,7 @@ public class TransportVerifyRepositoryAction extends TransportMasterNodeAction<V
|
|||
if (verifyResponse.failed()) {
|
||||
listener.onFailure(new RepositoryVerificationException(request.name(), verifyResponse.failureDescription()));
|
||||
} else {
|
||||
listener.onResponse(new VerifyRepositoryResponse(clusterService.getClusterName(), verifyResponse.nodes()));
|
||||
listener.onResponse(new VerifyRepositoryResponse(verifyResponse.nodes()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,16 +19,13 @@
|
|||
|
||||
package org.elasticsearch.action.admin.cluster.repositories.verify;
|
||||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.action.ActionResponse;
|
||||
import org.elasticsearch.cluster.ClusterName;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.io.stream.Writeable;
|
||||
import org.elasticsearch.common.transport.TransportAddress;
|
||||
import org.elasticsearch.common.xcontent.ObjectParser;
|
||||
import org.elasticsearch.common.xcontent.ToXContentObject;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
|
@ -36,7 +33,6 @@ import org.elasticsearch.common.xcontent.XContentParser;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -92,20 +88,6 @@ public class VerifyRepositoryResponse extends ActionResponse implements ToXConte
|
|||
return builder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Temporary method that allows turning a {@link NodeView} into a {@link DiscoveryNode}. This representation will never be used in
|
||||
* practice, because in >= 6.4 a consumer of the response will only be able to retrieve a representation of {@link NodeView}
|
||||
* objects.
|
||||
*
|
||||
* Effectively this will be used to hold the state of the object in 6.x so there is no need to have 2 backing objects that
|
||||
* represent the state of the Response. In practice these will always be read by a consumer as a NodeView, but it eases the
|
||||
* transition to master which will not contain any representation of a {@link DiscoveryNode}.
|
||||
*/
|
||||
DiscoveryNode convertToDiscoveryNode() {
|
||||
return new DiscoveryNode(name, nodeId, "", "", "", new TransportAddress(TransportAddress.META_ADDRESS, 0),
|
||||
Collections.emptyMap(), Collections.emptySet(), Version.CURRENT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
|
@ -125,10 +107,7 @@ public class VerifyRepositoryResponse extends ActionResponse implements ToXConte
|
|||
}
|
||||
}
|
||||
|
||||
private List<DiscoveryNode> nodes;
|
||||
|
||||
private ClusterName clusterName;
|
||||
|
||||
private List<NodeView> nodes;
|
||||
|
||||
private static final ObjectParser<VerifyRepositoryResponse, Void> PARSER =
|
||||
new ObjectParser<>(VerifyRepositoryResponse.class.getName(), VerifyRepositoryResponse::new);
|
||||
|
@ -139,43 +118,28 @@ public class VerifyRepositoryResponse extends ActionResponse implements ToXConte
|
|||
VerifyRepositoryResponse() {
|
||||
}
|
||||
|
||||
public VerifyRepositoryResponse(ClusterName clusterName, DiscoveryNode[] nodes) {
|
||||
this.clusterName = clusterName;
|
||||
this.nodes = Arrays.asList(nodes);
|
||||
public VerifyRepositoryResponse(DiscoveryNode[] nodes) {
|
||||
this.nodes = Arrays.stream(nodes).map(dn -> new NodeView(dn.getId(), dn.getName())).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFrom(StreamInput in) throws IOException {
|
||||
super.readFrom(in);
|
||||
if (in.getVersion().onOrAfter(Version.V_6_4_0)) {
|
||||
this.nodes = in.readList(NodeView::new).stream().map(n -> n.convertToDiscoveryNode()).collect(Collectors.toList());
|
||||
} else {
|
||||
clusterName = new ClusterName(in);
|
||||
this.nodes = in.readList(DiscoveryNode::new);
|
||||
}
|
||||
this.nodes = in.readList(NodeView::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
super.writeTo(out);
|
||||
if (out.getVersion().onOrAfter(Version.V_6_4_0)) {
|
||||
out.writeList(getNodes());
|
||||
} else {
|
||||
clusterName.writeTo(out);
|
||||
out.writeList(nodes);
|
||||
}
|
||||
out.writeList(nodes);
|
||||
}
|
||||
|
||||
public List<NodeView> getNodes() {
|
||||
return nodes.stream().map(dn -> new NodeView(dn.getId(), dn.getName())).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public ClusterName getClusterName() {
|
||||
return clusterName;
|
||||
return nodes;
|
||||
}
|
||||
|
||||
protected void setNodes(List<NodeView> nodes) {
|
||||
this.nodes = nodes.stream().map(n -> n.convertToDiscoveryNode()).collect(Collectors.toList());
|
||||
this.nodes = nodes;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -184,12 +148,8 @@ public class VerifyRepositoryResponse extends ActionResponse implements ToXConte
|
|||
{
|
||||
builder.startObject(NODES);
|
||||
{
|
||||
for (DiscoveryNode node : nodes) {
|
||||
builder.startObject(node.getId());
|
||||
{
|
||||
builder.field(NAME, node.getName());
|
||||
}
|
||||
builder.endObject();
|
||||
for (NodeView node : nodes) {
|
||||
node.toXContent(builder, params);
|
||||
}
|
||||
}
|
||||
builder.endObject();
|
||||
|
|
|
@ -40,7 +40,6 @@ import java.util.List;
|
|||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertThrows;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.either;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
|
||||
|
|
Loading…
Reference in New Issue