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

Remove version read/write logic in Verify Response #30879

Merged
merged 9 commits into from
May 31, 2018
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void onResponse(RepositoriesService.VerifyResponse verifyResponse) {
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()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,19 @@

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;

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;
Expand Down Expand Up @@ -91,20 +87,6 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
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) {
Expand All @@ -124,47 +106,29 @@ public int hashCode() {
}
}

private List<DiscoveryNode> nodes;

private ClusterName clusterName;

private List<NodeView> nodes;

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);
}
}

public List<NodeView> getNodes() {
return nodes.stream().map(dn -> new NodeView(dn.getId(), dn.getName())).collect(Collectors.toList());
out.writeList(nodes());
}

public ClusterName getClusterName() {
return clusterName;
public List<NodeView> nodes() {
Copy link
Member

Choose a reason for hiding this comment

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

I think you should keep the method named the same in 6.x and master. Also we said we'd prefer to go with getters and setters rather than the bare names for these things. As much as I personally like the names better, we said getters and setters.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

heh, i def forgot to mod this in 6.x, and i can make that its own PR. But if we prefer get/set then, im +1 to that as well.. I didnt know we had a strong pref toward get/set, I actually thought it was the opposite, even tho we had a lot more get/set in the codebase. Regardless, sync'ing w/ whats in 6.x is super important imho.

return nodes;
}

@Override
Expand All @@ -173,12 +137,8 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
{
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void testVerifyRepositoryWithBlocks() {
try {
setClusterReadOnly(true);
VerifyRepositoryResponse response = client().admin().cluster().prepareVerifyRepository("test-repo-blocks").execute().actionGet();
assertThat(response.getNodes().size(), equalTo(cluster().numDataAndMasterNodes()));
assertThat(response.nodes().size(), equalTo(cluster().numDataAndMasterNodes()));
} finally {
setClusterReadOnly(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ protected void setUpRepository() throws Exception {

logger.info("--> verify the repository");
VerifyRepositoryResponse verifyResponse = client().admin().cluster().prepareVerifyRepository(REPOSITORY_NAME).get();
assertThat(verifyResponse.getNodes().size(), equalTo(cluster().numDataAndMasterNodes()));
assertThat(verifyResponse.nodes().size(), equalTo(cluster().numDataAndMasterNodes()));

logger.info("--> create a snapshot");
CreateSnapshotResponse snapshotResponse = client().admin().cluster().prepareCreateSnapshot(REPOSITORY_NAME, SNAPSHOT_NAME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
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;

Expand All @@ -61,7 +60,7 @@ public void testRepositoryCreation() throws Exception {
logger.info("--> verify the repository");
int numberOfFiles = FileSystemUtils.files(location).length;
VerifyRepositoryResponse verifyRepositoryResponse = client.admin().cluster().prepareVerifyRepository("test-repo-1").get();
assertThat(verifyRepositoryResponse.getNodes().size(), equalTo(cluster().numDataAndMasterNodes()));
assertThat(verifyRepositoryResponse.nodes().size(), equalTo(cluster().numDataAndMasterNodes()));

logger.info("--> verify that we didn't leave any files as a result of verification");
assertThat(FileSystemUtils.files(location).length, equalTo(numberOfFiles));
Expand Down