Search in sources :

Example 46 with ClusterStateResponse

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 {
        }
    };
}
Also used : LivenessResponse(org.elasticsearch.action.admin.cluster.node.liveness.LivenessResponse) ClusterState(org.elasticsearch.cluster.ClusterState) TransportRequest(org.elasticsearch.transport.TransportRequest) ConnectTransportException(org.elasticsearch.transport.ConnectTransportException) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) TransportResponseHandler(org.elasticsearch.transport.TransportResponseHandler) TransportRequestOptions(org.elasticsearch.transport.TransportRequestOptions) ConnectTransportException(org.elasticsearch.transport.ConnectTransportException) TransportException(org.elasticsearch.transport.TransportException)

Example 47 with ClusterStateResponse

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));
}
Also used : ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse)

Example 48 with ClusterStateResponse

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));
}
Also used : ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse)

Example 49 with ClusterStateResponse

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);
}
Also used : RoutingNode(org.elasticsearch.cluster.routing.RoutingNode) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) MoveAllocationCommand(org.elasticsearch.cluster.routing.allocation.command.MoveAllocationCommand) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting)

Example 50 with ClusterStateResponse

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();
}
Also used : ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse)

Aggregations

ClusterStateResponse (org.elasticsearch.action.admin.cluster.state.ClusterStateResponse)64 Settings (org.elasticsearch.common.settings.Settings)25 ClusterStateRequest (org.elasticsearch.action.admin.cluster.state.ClusterStateRequest)21 ClusterHealthResponse (org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse)13 NodeClient (org.elasticsearch.client.node.NodeClient)12 RestController (org.elasticsearch.rest.RestController)12 RestRequest (org.elasticsearch.rest.RestRequest)12 RestResponse (org.elasticsearch.rest.RestResponse)12 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)11 ClusterState (org.elasticsearch.cluster.ClusterState)10 Table (org.elasticsearch.common.Table)10 GET (org.elasticsearch.rest.RestRequest.Method.GET)10 RestResponseListener (org.elasticsearch.rest.action.RestResponseListener)10 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)9 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)8 RestActionListener (org.elasticsearch.rest.action.RestActionListener)8 Strings (org.elasticsearch.common.Strings)7 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 MetaData (org.elasticsearch.cluster.metadata.MetaData)6