Skip to content

Commit

Permalink
Don't use AcknowledgedResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
DaveCTurner committed Nov 6, 2018
1 parent 3ee0174 commit 759ad07
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
package org.elasticsearch.action.admin.cluster.bootstrap;

import org.elasticsearch.action.Action;
import org.elasticsearch.action.support.master.AcknowledgedResponse;

public class BootstrapClusterAction extends Action<AcknowledgedResponse> {
public class BootstrapClusterAction extends Action<BootstrapClusterResponse> {
public static final BootstrapClusterAction INSTANCE = new BootstrapClusterAction();
public static final String NAME = "cluster:admin/bootstrap_cluster";

Expand All @@ -30,7 +29,7 @@ private BootstrapClusterAction() {
}

@Override
public AcknowledgedResponse newResponse() {
return new AcknowledgedResponse();
public BootstrapClusterResponse newResponse() {
throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.action.admin.cluster.bootstrap;

import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;

import java.io.IOException;

/**
* Response to a {@link BootstrapClusterRequest} indicating that the cluster has been successfully bootstrapped.
*/
public class BootstrapClusterResponse extends ActionResponse {
private final boolean alreadyBootstrapped;

public BootstrapClusterResponse(boolean alreadyBootstrapped) {
this.alreadyBootstrapped = alreadyBootstrapped;
}

public BootstrapClusterResponse(StreamInput in) throws IOException {
super(in);
alreadyBootstrapped = in.readBoolean();
}

/**
* @return whether this node already knew that the cluster had been bootstrapped when handling this request.
*/
public boolean getAlreadyBootstrapped() {
return alreadyBootstrapped;
}

@Override
public void readFrom(StreamInput in) throws IOException {
throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeBoolean(alreadyBootstrapped);
}

@Override
public String toString() {
return "BootstrapClusterResponse{" +
"alreadyBootstrapped=" + alreadyBootstrapped +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.action.support.HandledTransportAction;
import org.elasticsearch.action.support.TransportAction;
import org.elasticsearch.action.support.master.AcknowledgedResponse;
import org.elasticsearch.cluster.coordination.Coordinator;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.Nullable;
Expand All @@ -33,7 +31,7 @@
import org.elasticsearch.tasks.Task;
import org.elasticsearch.transport.TransportService;

public class TransportBootstrapClusterAction extends HandledTransportAction<BootstrapClusterRequest, AcknowledgedResponse> {
public class TransportBootstrapClusterAction extends HandledTransportAction<BootstrapClusterRequest, BootstrapClusterResponse> {

@Nullable // TODO make this not nullable
private final Coordinator coordinator;
Expand All @@ -52,7 +50,7 @@ public TransportBootstrapClusterAction(Settings settings, ActionFilters actionFi
}

@Override
protected void doExecute(Task task, BootstrapClusterRequest request, ActionListener<AcknowledgedResponse> listener) {
protected void doExecute(Task task, BootstrapClusterRequest request, ActionListener<BootstrapClusterResponse> listener) {
if (coordinator == null) { // TODO remove when not nullable
throw new IllegalStateException("cluster bootstrapping is not supported by this discovery type");
}
Expand All @@ -67,7 +65,8 @@ protected void doExecute(Task task, BootstrapClusterRequest request, ActionListe
@Override
public void run() {
try {
listener.onResponse(new AcknowledgedResponse(coordinator.setInitialConfiguration(request.getBootstrapConfiguration())));
listener.onResponse(new BootstrapClusterResponse(
coordinator.setInitialConfiguration(request.getBootstrapConfiguration()) == false));
} catch (Exception e) {
listener.onFailure(e);
}
Expand All @@ -79,5 +78,4 @@ public String toString() {
}
});
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.action.admin.cluster.bootstrap;

import org.elasticsearch.test.ESTestCase;

import java.io.IOException;

import static org.hamcrest.Matchers.equalTo;

public class BootstrapClusterResponseTest extends ESTestCase {
public void testSerialization() throws IOException {
final BootstrapClusterResponse original = new BootstrapClusterResponse(randomBoolean());
final BootstrapClusterResponse deserialized = copyWriteable(original, writableRegistry(), BootstrapClusterResponse::new);
assertThat(deserialized.getAlreadyBootstrapped(), equalTo(original.getAlreadyBootstrapped()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.elasticsearch.Version;
import org.elasticsearch.action.admin.cluster.bootstrap.BootstrapConfiguration.NodeDescription;
import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.action.support.master.AcknowledgedResponse;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.ESAllocationTestCase;
Expand Down Expand Up @@ -83,7 +82,7 @@ public void testHandlesNonstandardDiscoveryImplementation() throws InterruptedEx
final CountDownLatch countDownLatch = new CountDownLatch(1);
transportService.sendRequest(discoveryNode, BootstrapClusterAction.NAME, exampleRequest(), new ResponseHandler() {
@Override
public void handleResponse(AcknowledgedResponse response) {
public void handleResponse(BootstrapClusterResponse response) {
throw new AssertionError("should not be called");
}

Expand Down Expand Up @@ -123,7 +122,7 @@ public void testFailsOnNonMasterEligibleNodes() throws InterruptedException {
final CountDownLatch countDownLatch = new CountDownLatch(1);
transportService.sendRequest(discoveryNode, BootstrapClusterAction.NAME, exampleRequest(), new ResponseHandler() {
@Override
public void handleResponse(AcknowledgedResponse response) {
public void handleResponse(BootstrapClusterResponse response) {
throw new AssertionError("should not be called");
}

Expand Down Expand Up @@ -170,8 +169,8 @@ public void testSetsInitialConfiguration() throws InterruptedException {
final CountDownLatch countDownLatch = new CountDownLatch(1);
transportService.sendRequest(discoveryNode, BootstrapClusterAction.NAME, request, new ResponseHandler() {
@Override
public void handleResponse(AcknowledgedResponse response) {
assertTrue(response.isAcknowledged());
public void handleResponse(BootstrapClusterResponse response) {
assertFalse(response.getAlreadyBootstrapped());
countDownLatch.countDown();
}

Expand All @@ -190,8 +189,8 @@ public void handleException(TransportException exp) {
final CountDownLatch countDownLatch = new CountDownLatch(1);
transportService.sendRequest(discoveryNode, BootstrapClusterAction.NAME, request, new ResponseHandler() {
@Override
public void handleResponse(AcknowledgedResponse response) {
assertFalse(response.isAcknowledged());
public void handleResponse(BootstrapClusterResponse response) {
assertTrue(response.getAlreadyBootstrapped());
countDownLatch.countDown();
}

Expand All @@ -207,17 +206,15 @@ public void handleException(TransportException exp) {
threadPool.shutdown();
}

private abstract class ResponseHandler implements TransportResponseHandler<AcknowledgedResponse> {
private abstract class ResponseHandler implements TransportResponseHandler<BootstrapClusterResponse> {
@Override
public String executor() {
return Names.SAME;
}

@Override
public AcknowledgedResponse read(StreamInput in) throws IOException {
AcknowledgedResponse acknowledgedResponse = new AcknowledgedResponse();
acknowledgedResponse.readFrom(in);
return acknowledgedResponse;
public BootstrapClusterResponse read(StreamInput in) throws IOException {
return new BootstrapClusterResponse(in);
}
}
}

0 comments on commit 759ad07

Please sign in to comment.