Skip to content

Commit

Permalink
Ensure remote connection established and
Browse files Browse the repository at this point in the history
clean remote connection prior to leader cluster restart

Relates to #37681
  • Loading branch information
martijnvg committed Feb 26, 2019
1 parent 51551b7 commit c2a29da
Showing 1 changed file with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@

package org.elasticsearch.xpack.ccr;

import org.elasticsearch.action.admin.cluster.remote.RemoteInfoAction;
import org.elasticsearch.action.admin.cluster.remote.RemoteInfoRequest;
import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.transport.RemoteConnectionInfo;
import org.elasticsearch.transport.TransportService;
import org.elasticsearch.xpack.CcrIntegTestCase;
import org.elasticsearch.xpack.core.ccr.action.PutFollowAction;

import java.util.List;
import java.util.Locale;

import static java.util.Collections.singletonMap;
Expand Down Expand Up @@ -66,6 +70,7 @@ public void testFollowIndex() throws Exception {
equalTo(firstBatchNumDocs + secondBatchNumDocs));
});

cleanRemoteCluster();
getLeaderCluster().fullRestart();
ensureLeaderGreen("index1");
// Remote connection needs to be re-configured, because all the nodes in leader cluster have been restarted:
Expand All @@ -82,12 +87,31 @@ public void testFollowIndex() throws Exception {
});
}

private void setupRemoteCluster() {
private void setupRemoteCluster() throws Exception {
ClusterUpdateSettingsRequest updateSettingsRequest = new ClusterUpdateSettingsRequest();
String masterNode = getLeaderCluster().getMasterName();
String address = getLeaderCluster().getInstance(TransportService.class, masterNode).boundAddress().publishAddress().toString();
updateSettingsRequest.persistentSettings(Settings.builder().put("cluster.remote.leader_cluster.seeds", address));
assertAcked(followerClient().admin().cluster().updateSettings(updateSettingsRequest).actionGet());

assertBusy(() -> {
List<RemoteConnectionInfo> infos =
followerClient().execute(RemoteInfoAction.INSTANCE, new RemoteInfoRequest()).get().getInfos();
assertThat(infos.size(), equalTo(1));
assertThat(infos.get(0).getNumNodesConnected(), equalTo(1));
});
}

private void cleanRemoteCluster() throws Exception {
ClusterUpdateSettingsRequest updateSettingsRequest = new ClusterUpdateSettingsRequest();
updateSettingsRequest.persistentSettings(Settings.builder().put("cluster.remote.leader_cluster.seeds", (String) null));
assertAcked(followerClient().admin().cluster().updateSettings(updateSettingsRequest).actionGet());

assertBusy(() -> {
List<RemoteConnectionInfo> infos =
followerClient().execute(RemoteInfoAction.INSTANCE, new RemoteInfoRequest()).get().getInfos();
assertThat(infos.size(), equalTo(0));
});
}

}

0 comments on commit c2a29da

Please sign in to comment.