use of org.elasticsearch.action.admin.cluster.state.ClusterStateResponse in project elasticsearch by elastic.
the class FailAndRetryMockTransport method getConnection.
@Override
public Connection getConnection(DiscoveryNode node) {
return new Connection() {
@Override
public DiscoveryNode getNode() {
return node;
}
@Override
public void sendRequest(long requestId, String action, TransportRequest request, TransportRequestOptions options) throws IOException, TransportException {
//we make sure that nodes get added to the connected ones when calling addTransportAddress, by returning proper nodes info
if (connectMode) {
if (TransportLivenessAction.NAME.equals(action)) {
TransportResponseHandler transportResponseHandler = transportServiceAdapter.onResponseReceived(requestId);
transportResponseHandler.handleResponse(new LivenessResponse(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY), node));
} else if (ClusterStateAction.NAME.equals(action)) {
TransportResponseHandler transportResponseHandler = transportServiceAdapter.onResponseReceived(requestId);
ClusterState clusterState = getMockClusterState(node);
transportResponseHandler.handleResponse(new ClusterStateResponse(clusterName, clusterState, 0L));
} else {
throw new UnsupportedOperationException("Mock transport does not understand action " + action);
}
return;
}
//once nodes are connected we'll just return errors for each sendRequest call
triedNodes.add(node);
if (random.nextInt(100) > 10) {
connectTransportExceptions.incrementAndGet();
throw new ConnectTransportException(node, "node not available");
} else {
if (random.nextBoolean()) {
failures.incrementAndGet();
//throw whatever exception that is not a subclass of ConnectTransportException
throw new IllegalStateException();
} else {
TransportResponseHandler transportResponseHandler = transportServiceAdapter.onResponseReceived(requestId);
if (random.nextBoolean()) {
successes.incrementAndGet();
transportResponseHandler.handleResponse(newResponse());
} else {
failures.incrementAndGet();
transportResponseHandler.handleException(new TransportException("transport exception"));
}
}
}
}
@Override
public void close() throws IOException {
}
};
}
use of org.elasticsearch.action.admin.cluster.state.ClusterStateResponse in project elasticsearch by elastic.
the class SimpleClusterStateIT method testRoutingTable.
public void testRoutingTable() throws Exception {
ClusterStateResponse clusterStateResponseUnfiltered = client().admin().cluster().prepareState().clear().setRoutingTable(true).get();
assertThat(clusterStateResponseUnfiltered.getState().routingTable().hasIndex("foo"), is(true));
assertThat(clusterStateResponseUnfiltered.getState().routingTable().hasIndex("fuu"), is(true));
assertThat(clusterStateResponseUnfiltered.getState().routingTable().hasIndex("baz"), is(true));
assertThat(clusterStateResponseUnfiltered.getState().routingTable().hasIndex("non-existent"), is(false));
ClusterStateResponse clusterStateResponse = client().admin().cluster().prepareState().clear().get();
assertThat(clusterStateResponse.getState().routingTable().hasIndex("foo"), is(false));
assertThat(clusterStateResponse.getState().routingTable().hasIndex("fuu"), is(false));
assertThat(clusterStateResponse.getState().routingTable().hasIndex("baz"), is(false));
assertThat(clusterStateResponse.getState().routingTable().hasIndex("non-existent"), is(false));
}
use of org.elasticsearch.action.admin.cluster.state.ClusterStateResponse in project elasticsearch by elastic.
the class SimpleClusterStateIT method testMetadata.
public void testMetadata() throws Exception {
ClusterStateResponse clusterStateResponseUnfiltered = client().admin().cluster().prepareState().clear().setMetaData(true).get();
assertThat(clusterStateResponseUnfiltered.getState().metaData().indices().size(), is(3));
ClusterStateResponse clusterStateResponse = client().admin().cluster().prepareState().clear().get();
assertThat(clusterStateResponse.getState().metaData().indices().size(), is(0));
}
use of org.elasticsearch.action.admin.cluster.state.ClusterStateResponse in project elasticsearch by elastic.
the class AckIT method getAllocationCommand.
private MoveAllocationCommand getAllocationCommand() {
String fromNodeId = null;
String toNodeId = null;
ShardRouting shardToBeMoved = null;
ClusterStateResponse clusterStateResponse = client().admin().cluster().prepareState().get();
for (RoutingNode routingNode : clusterStateResponse.getState().getRoutingNodes()) {
if (routingNode.node().isDataNode()) {
if (fromNodeId == null && routingNode.numberOfOwningShards() > 0) {
fromNodeId = routingNode.nodeId();
shardToBeMoved = routingNode.copyShards().get(randomInt(routingNode.size() - 1));
} else {
toNodeId = routingNode.nodeId();
}
if (toNodeId != null && fromNodeId != null) {
break;
}
}
}
assertNotNull(fromNodeId);
assertNotNull(toNodeId);
assertNotNull(shardToBeMoved);
logger.info("==> going to move shard [{}] from [{}] to [{}]", shardToBeMoved, fromNodeId, toNodeId);
return new MoveAllocationCommand(shardToBeMoved.getIndexName(), shardToBeMoved.id(), fromNodeId, toNodeId);
}
use of org.elasticsearch.action.admin.cluster.state.ClusterStateResponse in project elasticsearch by elastic.
the class SimpleIndexStateIT method testFastCloseAfterCreateContinuesCreateAfterOpen.
public void testFastCloseAfterCreateContinuesCreateAfterOpen() {
logger.info("--> creating test index that cannot be allocated");
client().admin().indices().prepareCreate("test").setWaitForActiveShards(ActiveShardCount.NONE).setSettings(Settings.builder().put("index.routing.allocation.include.tag", "no_such_node").build()).get();
ClusterHealthResponse health = client().admin().cluster().prepareHealth("test").setWaitForNodes(">=2").get();
assertThat(health.isTimedOut(), equalTo(false));
assertThat(health.getStatus(), equalTo(ClusterHealthStatus.RED));
client().admin().indices().prepareClose("test").get();
logger.info("--> updating test index settings to allow allocation");
client().admin().indices().prepareUpdateSettings("test").setSettings(Settings.builder().put("index.routing.allocation.include.tag", "").build()).get();
client().admin().indices().prepareOpen("test").get();
logger.info("--> waiting for green status");
ensureGreen();
NumShards numShards = getNumShards("test");
ClusterStateResponse stateResponse = client().admin().cluster().prepareState().get();
assertThat(stateResponse.getState().metaData().index("test").getState(), equalTo(IndexMetaData.State.OPEN));
assertThat(stateResponse.getState().routingTable().index("test").shards().size(), equalTo(numShards.numPrimaries));
assertEquals(stateResponse.getState().routingTable().index("test").shardsWithState(ShardRoutingState.STARTED).size(), numShards.totalNumShards);
logger.info("--> indexing a simple document");
client().prepareIndex("test", "type1", "1").setSource("field1", "value1").get();
}
Aggregations