org.elasticsearch.action.admin.cluster.state.ClusterStateRequest Java Examples

The following examples show how to use org.elasticsearch.action.admin.cluster.state.ClusterStateRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GetAliasesIndicesRequestBuilder.java    From elasticshell with Apache License 2.0 6 votes vote down vote up
@Override
protected XContentBuilder toXContent(ClusterStateRequest request, ClusterStateResponse response, XContentBuilder builder) throws IOException {
    MetaData metaData = response.getState().metaData();
    builder.startObject();
    for (IndexMetaData indexMetaData : metaData) {
        builder.startObject(indexMetaData.index(), XContentBuilder.FieldCaseConversion.NONE);
        builder.startObject("aliases");
        for (AliasMetaData alias : indexMetaData.aliases().values()) {
            AliasMetaData.Builder.toXContent(alias, builder, ToXContent.EMPTY_PARAMS);
        }
        builder.endObject();
        builder.endObject();
    }
    builder.endObject();
    return builder;
}
 
Example #2
Source File: GetSettingsRequestBuilder.java    From elasticshell with Apache License 2.0 6 votes vote down vote up
@Override
protected XContentBuilder toXContent(ClusterStateRequest request, ClusterStateResponse response, XContentBuilder builder) throws IOException {
    MetaData metaData = response.getState().metaData();

    if (metaData.indices().isEmpty()) {
        return builder.startObject().endObject();
    }

    builder.startObject();
    for (IndexMetaData indexMetaData : metaData) {
        builder.startObject(indexMetaData.index(), XContentBuilder.FieldCaseConversion.NONE);
        builder.startObject("settings");
        for (Map.Entry<String, String> entry : indexMetaData.settings().getAsMap().entrySet()) {
            builder.field(entry.getKey(), entry.getValue());
        }
        builder.endObject();
        builder.endObject();
    }
    builder.endObject();
    return builder;
}
 
Example #3
Source File: AbstractClient.java    From elasticshell with Apache License 2.0 6 votes vote down vote up
public JsonOutput availableNodes() throws Exception {
    ClusterStateResponse response = this.client.admin().cluster().state(new ClusterStateRequest()
            .filterBlocks(true).filterNodes(false).filterMetaData(true)
            .filterRoutingTable(true)).actionGet();

    XContentBuilder builder = JsonXContent.contentBuilder();
    builder.startObject();
    for (DiscoveryNode discoveryNode : response.getState().nodes()) {
        builder.startObject(discoveryNode.id());
        builder.field("name", discoveryNode.name());
        builder.endObject();
    }
    builder.endObject();

    return stringToJson.stringToJson(builder.string());
}
 
Example #4
Source File: RestClusterGetSettingsAction.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
    ClusterStateRequest clusterStateRequest = Requests.clusterStateRequest()
            .routingTable(false)
            .nodes(false);
    clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
    client.admin().cluster().state(clusterStateRequest, new RestBuilderListener<ClusterStateResponse>(channel) {
        @Override
        public RestResponse buildResponse(ClusterStateResponse response, XContentBuilder builder) throws Exception {
            builder.startObject();

            builder.startObject("persistent");
            response.getState().metaData().persistentSettings().toXContent(builder, request);
            builder.endObject();

            builder.startObject("transient");
            response.getState().metaData().transientSettings().toXContent(builder, request);
            builder.endObject();

            builder.endObject();

            return new BytesRestResponse(RestStatus.OK, builder);
        }
    });
}
 
Example #5
Source File: RestSegmentsAction.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
protected void doRequest(final RestRequest request, final RestChannel channel, final Client client) {
    final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));

    final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
    clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
    clusterStateRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterStateRequest.masterNodeTimeout()));
    clusterStateRequest.clear().nodes(true).routingTable(true).indices(indices);

    client.admin().cluster().state(clusterStateRequest, new RestActionListener<ClusterStateResponse>(channel) {
        @Override
        public void processResponse(final ClusterStateResponse clusterStateResponse) {
            final IndicesSegmentsRequest indicesSegmentsRequest = new IndicesSegmentsRequest();
            indicesSegmentsRequest.indices(indices);
            client.admin().indices().segments(indicesSegmentsRequest, new RestResponseListener<IndicesSegmentResponse>(channel) {
                @Override
                public RestResponse buildResponse(final IndicesSegmentResponse indicesSegmentResponse) throws Exception {
                    final Map<String, IndexSegments> indicesSegments = indicesSegmentResponse.getIndices();
                    Table tab = buildTable(request, clusterStateResponse, indicesSegments);
                    return RestTable.buildResponse(tab, channel);
                }
            });
        }
    });
}
 
Example #6
Source File: RestShardsAction.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public void doRequest(final RestRequest request, final RestChannel channel, final Client client) {
    final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
    final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
    clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
    clusterStateRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterStateRequest.masterNodeTimeout()));
    clusterStateRequest.clear().nodes(true).metaData(true).routingTable(true).indices(indices);
    client.admin().cluster().state(clusterStateRequest, new RestActionListener<ClusterStateResponse>(channel) {
        @Override
        public void processResponse(final ClusterStateResponse clusterStateResponse) {
            IndicesStatsRequest indicesStatsRequest = new IndicesStatsRequest(indices);
            indicesStatsRequest.all();
            client.admin().indices().stats(indicesStatsRequest, new RestResponseListener<IndicesStatsResponse>(channel) {
                @Override
                public RestResponse buildResponse(IndicesStatsResponse indicesStatsResponse) throws Exception {
                    return RestTable.buildResponse(buildTable(request, clusterStateResponse, indicesStatsResponse), channel);
                }
            });
        }
    });
}
 
Example #7
Source File: TransportListStoresAction.java    From elasticsearch-learning-to-rank with Apache License 2.0 6 votes vote down vote up
@Override
protected void masterOperation(ListStoresActionRequest request, ClusterState state,
                               ActionListener<ListStoresActionResponse> listener) throws Exception {
    String[] names = indexNameExpressionResolver.concreteIndexNames(state,
            new ClusterStateRequest().indices(IndexFeatureStore.DEFAULT_STORE, IndexFeatureStore.STORE_PREFIX + "*"));
    final MultiSearchRequestBuilder req = client.prepareMultiSearch();
    final List<Tuple<String, Integer>> versions = new ArrayList<>();
    Stream.of(names)
            .filter(IndexFeatureStore::isIndexStore)
            .map((s) -> clusterService.state().metaData().getIndices().get(s))
            .filter(Objects::nonNull)
            .filter((im) -> STORE_VERSION_PROP.exists(im.getSettings()))
            .forEach((m) -> {
                req.add(countSearchRequest(m));
                versions.add(tuple(m.getIndex().getName(),STORE_VERSION_PROP.get(m.getSettings())));
            });
    if (versions.isEmpty()) {
        listener.onResponse(new ListStoresActionResponse(Collections.emptyList()));
    } else {
        req.execute(wrap((r) -> listener.onResponse(toResponse(r, versions)), listener::onFailure));
    }
}
 
Example #8
Source File: RestPluginsAction.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public void doRequest(final RestRequest request, final RestChannel channel, final Client client) {
    final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
    clusterStateRequest.clear().nodes(true);
    clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
    clusterStateRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterStateRequest.masterNodeTimeout()));

    client.admin().cluster().state(clusterStateRequest, new RestActionListener<ClusterStateResponse>(channel) {
        @Override
        public void processResponse(final ClusterStateResponse clusterStateResponse) throws Exception {
            NodesInfoRequest nodesInfoRequest = new NodesInfoRequest();
            nodesInfoRequest.clear().plugins(true);
            client.admin().cluster().nodesInfo(nodesInfoRequest, new RestResponseListener<NodesInfoResponse>(channel) {
                @Override
                public RestResponse buildResponse(final NodesInfoResponse nodesInfoResponse) throws Exception {
                    return RestTable.buildResponse(buildTable(request, clusterStateResponse, nodesInfoResponse), channel);
                }
            });
        }
    });
}
 
Example #9
Source File: RestImportActionTest.java    From elasticsearch-inout-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testMappings() {
    esSetup.execute(createIndex("index1"));
    String path = getClass().getResource("/importdata/import_9").getPath();
    executeImportRequest("{\"directory\": \"" + path + "\", \"mappings\": true}");

    ClusterStateRequest clusterStateRequest = Requests.clusterStateRequest().filteredIndices("index1");
    ImmutableMap<String, MappingMetaData> mappings = ImmutableMap.copyOf(
        esSetup.client().admin().cluster().state(clusterStateRequest).actionGet().getState().metaData().index("index1").getMappings());
    assertEquals("{\"1\":{\"_timestamp\":{\"enabled\":true,\"store\":true},\"_ttl\":{\"enabled\":true,\"default\":86400000},\"properties\":{\"name\":{\"type\":\"string\",\"store\":true}}}}",
            mappings.get("1").source().toString());
}
 
Example #10
Source File: MainAndStaticFileHandler.java    From crate with Apache License 2.0 5 votes vote down vote up
private CompletableFuture<FullHttpResponse> serveJSON(HttpMethod method, ByteBufAllocator alloc) {
    var requestClusterState = new ClusterStateRequest()
        .blocks(true)
        .metaData(false)
        .nodes(false)
        .local(true);
    FutureActionListener<ClusterStateResponse, ClusterStateResponse> listener = new FutureActionListener<>(x -> x);
    client.executeLocally(ClusterStateAction.INSTANCE, requestClusterState, listener);
    return listener.thenApply(resp -> clusterStateRespToHttpResponse(method, resp, alloc, nodeName));
}
 
Example #11
Source File: ClusterStateRequestBuilder.java    From elasticshell with Apache License 2.0 5 votes vote down vote up
@Override
protected XContentBuilder toXContent(ClusterStateRequest request, ClusterStateResponse response, XContentBuilder builder) throws IOException {
    builder.startObject();
    builder.field(Fields.CLUSTER_NAME, response.getClusterName().value());
    response.getState().settingsFilter(new SettingsFilter(ImmutableSettings.settingsBuilder().build())).toXContent(builder, ToXContent.EMPTY_PARAMS);
    builder.endObject();
    return builder;
}
 
Example #12
Source File: RestImportActionTest.java    From elasticsearch-inout-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testSettings() {
    String path = getClass().getResource("/importdata/import_9").getPath();
    executeImportRequest("{\"directory\": \"" + path + "\", \"settings\": true}");

    ClusterStateRequest clusterStateRequest = Requests.clusterStateRequest().filteredIndices("index1");
    IndexMetaData stats = esSetup.client().admin().cluster().state(clusterStateRequest).actionGet().getState().metaData().index("index1");
    assertEquals(2, stats.numberOfShards());
    assertEquals(1, stats.numberOfReplicas());
}
 
Example #13
Source File: RestRestoreActionTest.java    From elasticsearch-inout-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Restore previously dumped data from the default location
 */
@Test
public void testRestoreDumpedData() {

    deleteDefaultDir();

    setUpSecondNode();
    // create sample data
    esSetup.execute(deleteAll(), createIndex("users").withSettings(
            fromClassPath("essetup/settings/test_a.json")).withMapping("d",
                    fromClassPath("essetup/mappings/test_a.json")));
    esSetup.execute(index("users", "d", "1").withSource("{\"name\": \"item1\"}"));
    esSetup.execute(index("users", "d", "2").withSource("{\"name\": \"item2\"}"));
    esSetup2.client().admin().cluster().prepareHealth().setWaitForGreenStatus().
        setWaitForNodes("2").setWaitForRelocatingShards(0).execute().actionGet();

    // dump data and recreate empty index
    executeDumpRequest("");

    // delete all
    esSetup.execute(deleteAll());
    esSetup.client().admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet();

    // run restore without pyload relative directory
    ImportResponse response = executeRestoreRequest("");
    List<Map<String, Object>> imports = getImports(response);
    assertEquals(2, imports.size());

    assertTrue(existsWithField("1", "name", "item1", "users", "d"));
    assertTrue(existsWithField("2", "name", "item2", "users", "d"));

    ClusterStateRequest clusterStateRequest = Requests.clusterStateRequest().filteredIndices("users");
    IndexMetaData metaData = esSetup.client().admin().cluster().state(clusterStateRequest).actionGet().getState().metaData().index("users");
    assertEquals("{\"d\":{\"properties\":{\"name\":{\"type\":\"string\",\"index\":\"not_analyzed\",\"store\":true,\"omit_norms\":true,\"index_options\":\"docs\"}}}}",
            metaData.mappings().get("d").source().toString());
    assertEquals(2, metaData.numberOfShards());
    assertEquals(0, metaData.numberOfReplicas());
}
 
Example #14
Source File: Importer.java    From elasticsearch-inout-plugin with Apache License 2.0 5 votes vote down vote up
private ImmutableMap<String, IndexMetaData> getIndexMetaData(Set<String> indexes) {
    ClusterStateRequest clusterStateRequest = Requests.clusterStateRequest()
            .filterRoutingTable(true)
            .filterNodes(true)
            .filteredIndices(indexes.toArray(new String[indexes.size()]));
    clusterStateRequest.listenerThreaded(false);
    ClusterStateResponse response = client.admin().cluster().state(clusterStateRequest).actionGet();
    return ImmutableMap.copyOf(response.getState().metaData().indices());
}
 
Example #15
Source File: CassandraRiverIntegrationTest.java    From cassandra-river with Apache License 2.0 5 votes vote down vote up
@BeforeMethod
public void beforeMethod() throws IOException {
    //removes data from elasticsearch (both registered river if existing and imported data)
    String[] indices = esClient.admin().cluster().state(new ClusterStateRequest().local(true))
            .actionGet().getState().getMetaData().getConcreteAllIndices();
    esClient.admin().indices().prepareDelete(indices).execute().actionGet();
}
 
Example #16
Source File: RestThreadPoolAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void doRequest(final RestRequest request, final RestChannel channel, final Client client) {
    final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
    clusterStateRequest.clear().nodes(true);
    clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
    clusterStateRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterStateRequest.masterNodeTimeout()));

    client.admin().cluster().state(clusterStateRequest, new RestActionListener<ClusterStateResponse>(channel) {
        @Override
        public void processResponse(final ClusterStateResponse clusterStateResponse) {
            NodesInfoRequest nodesInfoRequest = new NodesInfoRequest();
            nodesInfoRequest.clear().process(true).threadPool(true);
            client.admin().cluster().nodesInfo(nodesInfoRequest, new RestActionListener<NodesInfoResponse>(channel) {
                @Override
                public void processResponse(final NodesInfoResponse nodesInfoResponse) {
                    NodesStatsRequest nodesStatsRequest = new NodesStatsRequest();
                    nodesStatsRequest.clear().threadPool(true);
                    client.admin().cluster().nodesStats(nodesStatsRequest, new RestResponseListener<NodesStatsResponse>(channel) {
                        @Override
                        public RestResponse buildResponse(NodesStatsResponse nodesStatsResponse) throws Exception {
                            return RestTable.buildResponse(buildTable(request, clusterStateResponse, nodesInfoResponse, nodesStatsResponse), channel);
                        }
                    });
                }
            });
        }
    });
}
 
Example #17
Source File: RestNodesAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void doRequest(final RestRequest request, final RestChannel channel, final Client client) {
    final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
    clusterStateRequest.clear().nodes(true);
    clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
    clusterStateRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterStateRequest.masterNodeTimeout()));

    client.admin().cluster().state(clusterStateRequest, new RestActionListener<ClusterStateResponse>(channel) {
        @Override
        public void processResponse(final ClusterStateResponse clusterStateResponse) {
            NodesInfoRequest nodesInfoRequest = new NodesInfoRequest();
            nodesInfoRequest.clear().jvm(true).os(true).process(true);
            client.admin().cluster().nodesInfo(nodesInfoRequest, new RestActionListener<NodesInfoResponse>(channel) {
                @Override
                public void processResponse(final NodesInfoResponse nodesInfoResponse) {
                    NodesStatsRequest nodesStatsRequest = new NodesStatsRequest();
                    nodesStatsRequest.clear().jvm(true).os(true).fs(true).indices(true).process(true).script(true);
                    client.admin().cluster().nodesStats(nodesStatsRequest, new RestResponseListener<NodesStatsResponse>(channel) {
                        @Override
                        public RestResponse buildResponse(NodesStatsResponse nodesStatsResponse) throws Exception {
                            return RestTable.buildResponse(buildTable(request, clusterStateResponse, nodesInfoResponse, nodesStatsResponse), channel);
                        }
                    });
                }
            });
        }
    });
}
 
Example #18
Source File: RestNodeAttrsAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void doRequest(final RestRequest request, final RestChannel channel, final Client client) {
    final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
    clusterStateRequest.clear().nodes(true);
    clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
    clusterStateRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterStateRequest.masterNodeTimeout()));

    client.admin().cluster().state(clusterStateRequest, new RestActionListener<ClusterStateResponse>(channel) {
        @Override
        public void processResponse(final ClusterStateResponse clusterStateResponse) {
            NodesInfoRequest nodesInfoRequest = new NodesInfoRequest();
            nodesInfoRequest.clear().jvm(false).os(false).process(true);
            client.admin().cluster().nodesInfo(nodesInfoRequest, new RestActionListener<NodesInfoResponse>(channel) {
                @Override
                public void processResponse(final NodesInfoResponse nodesInfoResponse) {
                    NodesStatsRequest nodesStatsRequest = new NodesStatsRequest();
                    nodesStatsRequest.clear().jvm(false).os(false).fs(false).indices(false).process(false);
                    client.admin().cluster().nodesStats(nodesStatsRequest, new RestResponseListener<NodesStatsResponse>(channel) {
                        @Override
                        public RestResponse buildResponse(NodesStatsResponse nodesStatsResponse) throws Exception {
                            return RestTable.buildResponse(buildTable(request, clusterStateResponse, nodesInfoResponse, nodesStatsResponse), channel);
                        }
                    });
                }
            });
        }
    });
}
 
Example #19
Source File: RestClusterStateAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
    final ClusterStateRequest clusterStateRequest = Requests.clusterStateRequest();
    clusterStateRequest.indicesOptions(IndicesOptions.fromRequest(request, clusterStateRequest.indicesOptions()));
    clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
    clusterStateRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterStateRequest.masterNodeTimeout()));

    final String[] indices = Strings.splitStringByCommaToArray(request.param("indices", "_all"));
    boolean isAllIndicesOnly = indices.length == 1 && "_all".equals(indices[0]);
    if (!isAllIndicesOnly) {
        clusterStateRequest.indices(indices);
    }

    if (request.hasParam("metric")) {
        EnumSet<ClusterState.Metric> metrics = ClusterState.Metric.parseString(request.param("metric"), true);
        // do not ask for what we do not need.
        clusterStateRequest.nodes(metrics.contains(ClusterState.Metric.NODES) || metrics.contains(ClusterState.Metric.MASTER_NODE));
        //there is no distinction in Java api between routing_table and routing_nodes, it's the same info set over the wire, one single flag to ask for it
        clusterStateRequest.routingTable(metrics.contains(ClusterState.Metric.ROUTING_TABLE) || metrics.contains(ClusterState.Metric.ROUTING_NODES));
        clusterStateRequest.metaData(metrics.contains(ClusterState.Metric.METADATA));
        clusterStateRequest.blocks(metrics.contains(ClusterState.Metric.BLOCKS));
        clusterStateRequest.customs(metrics.contains(ClusterState.Metric.CUSTOMS));
    }
    settingsFilter.addFilterSettingParams(request);

    client.admin().cluster().state(clusterStateRequest, new RestBuilderListener<ClusterStateResponse>(channel) {
        @Override
        public RestResponse buildResponse(ClusterStateResponse response, XContentBuilder builder) throws Exception {
            builder.startObject();
            builder.field(Fields.CLUSTER_NAME, response.getClusterName().value());
            response.getState().toXContent(builder, request);
            builder.endObject();
            return new BytesRestResponse(RestStatus.OK, builder);
        }
    });
}
 
Example #20
Source File: RestGetIndicesAliasesAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
    final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
    final String[] aliases = Strings.splitStringByCommaToArray(request.param("name"));

    ClusterStateRequest clusterStateRequest = Requests.clusterStateRequest()
            .routingTable(false)
            .nodes(false)
            .indices(indices);
    clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));

    client.admin().cluster().state(clusterStateRequest, new RestBuilderListener<ClusterStateResponse>(channel) {
        @Override
        public RestResponse buildResponse(ClusterStateResponse response, XContentBuilder builder) throws Exception {
            MetaData metaData = response.getState().metaData();
            builder.startObject();

            final boolean isAllAliasesRequested = isAllOrWildcard(aliases);
            for (IndexMetaData indexMetaData : metaData) {
                builder.startObject(indexMetaData.getIndex(), XContentBuilder.FieldCaseConversion.NONE);
                builder.startObject("aliases");

                for (ObjectCursor<AliasMetaData> cursor : indexMetaData.getAliases().values()) {
                    if (isAllAliasesRequested || Regex.simpleMatch(aliases, cursor.value.alias())) {
                        AliasMetaData.Builder.toXContent(cursor.value, builder, ToXContent.EMPTY_PARAMS);
                    }
                }

                builder.endObject();
                builder.endObject();
            }

            builder.endObject();
            return new BytesRestResponse(OK, builder);
        }
    });
}
 
Example #21
Source File: RestMasterAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void doRequest(final RestRequest request, final RestChannel channel, final Client client) {
    final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
    clusterStateRequest.clear().nodes(true);
    clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
    clusterStateRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterStateRequest.masterNodeTimeout()));

    client.admin().cluster().state(clusterStateRequest, new RestResponseListener<ClusterStateResponse>(channel) {
        @Override
        public RestResponse buildResponse(final ClusterStateResponse clusterStateResponse) throws Exception {
            return RestTable.buildResponse(buildTable(request, clusterStateResponse), channel);
        }
    });
}
 
Example #22
Source File: RolloverTests.java    From anomaly-detection with Apache License 2.0 4 votes vote down vote up
@Override
public void setUp() throws Exception {
    super.setUp();
    Client client = mock(Client.class);
    indicesClient = mock(IndicesAdminClient.class);
    AdminClient adminClient = mock(AdminClient.class);
    clusterService = mock(ClusterService.class);
    ClusterSettings clusterSettings = new ClusterSettings(
        Settings.EMPTY,
        Collections
            .unmodifiableSet(
                new HashSet<>(
                    Arrays
                        .asList(
                            AnomalyDetectorSettings.AD_RESULT_HISTORY_MAX_DOCS,
                            AnomalyDetectorSettings.AD_RESULT_HISTORY_ROLLOVER_PERIOD,
                            AnomalyDetectorSettings.AD_RESULT_HISTORY_RETENTION_PERIOD
                        )
                )
            )
    );

    clusterName = new ClusterName("test");

    when(clusterService.getClusterSettings()).thenReturn(clusterSettings);

    ThreadPool threadPool = mock(ThreadPool.class);
    Settings settings = Settings.EMPTY;
    when(client.admin()).thenReturn(adminClient);
    when(adminClient.indices()).thenReturn(indicesClient);

    adIndices = new AnomalyDetectionIndices(client, clusterService, threadPool, settings);

    clusterAdminClient = mock(ClusterAdminClient.class);
    when(adminClient.cluster()).thenReturn(clusterAdminClient);

    doAnswer(invocation -> {
        ClusterStateRequest clusterStateRequest = invocation.getArgument(0);
        assertEquals(AnomalyDetectionIndices.ALL_AD_RESULTS_INDEX_PATTERN, clusterStateRequest.indices()[0]);
        @SuppressWarnings("unchecked")
        ActionListener<ClusterStateResponse> listener = (ActionListener<ClusterStateResponse>) invocation.getArgument(1);
        listener.onResponse(new ClusterStateResponse(clusterName, clusterState, true));
        return null;
    }).when(clusterAdminClient).state(any(), any());
}
 
Example #23
Source File: AbstractClient.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
public ActionFuture<ClusterStateResponse> state(final ClusterStateRequest request) {
    return execute(ClusterStateAction.INSTANCE, request);
}
 
Example #24
Source File: ClusterStateRequestBuilder.java    From elasticshell with Apache License 2.0 4 votes vote down vote up
@Override
protected ActionFuture<ClusterStateResponse> doExecute(ClusterStateRequest request) {
    return client.admin().cluster().state(request);
}
 
Example #25
Source File: ClusterStateRequestBuilder.java    From elasticshell with Apache License 2.0 4 votes vote down vote up
public ClusterStateRequestBuilder(Client client, JsonToString<JsonInput> jsonToString, StringToJson<JsonOutput> stringToJson) {
    super(client, new ClusterStateRequest(), jsonToString, stringToJson);
}
 
Example #26
Source File: GetClusterSettingsRequestBuilder.java    From elasticshell with Apache License 2.0 4 votes vote down vote up
@Override
protected ActionFuture<ClusterStateResponse> doExecute(ClusterStateRequest request) {
    return client.admin().cluster().state(request);
}
 
Example #27
Source File: GetClusterSettingsRequestBuilder.java    From elasticshell with Apache License 2.0 4 votes vote down vote up
public GetClusterSettingsRequestBuilder(Client client, JsonToString<JsonInput> jsonToString, StringToJson<JsonOutput> stringToJson) {
    super(client, new ClusterStateRequest(), jsonToString, stringToJson);
    this.request.listenerThreaded(false).filterRoutingTable(true).filterNodes(true);
}
 
Example #28
Source File: GetAliasesIndicesRequestBuilder.java    From elasticshell with Apache License 2.0 4 votes vote down vote up
@Override
protected ActionFuture<ClusterStateResponse> doExecute(ClusterStateRequest request) {
    return client.admin().cluster().state(request);
}
 
Example #29
Source File: GetAliasesIndicesRequestBuilder.java    From elasticshell with Apache License 2.0 4 votes vote down vote up
public GetAliasesIndicesRequestBuilder(Client client, JsonToString<JsonInput> jsonToString, StringToJson<JsonOutput> stringToJson) {
    super(client, new ClusterStateRequest(), jsonToString, stringToJson);
    this.request.filterRoutingTable(true).filterNodes(true).listenerThreaded(false);
}
 
Example #30
Source File: AbstractClient.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public ActionFuture<ClusterStateResponse> state(final ClusterStateRequest request) {
    return execute(ClusterStateAction.INSTANCE, request);
}