Search in sources :

Example 6 with IndicesOptions

use of org.elasticsearch.action.support.IndicesOptions in project elasticsearch by elastic.

the class IndicesOptionsIntegrationIT method testWildcardBehaviourSnapshotRestore.

public void testWildcardBehaviourSnapshotRestore() throws Exception {
    createIndex("foobar");
    ensureGreen("foobar");
    waitForRelocation();
    PutRepositoryResponse putRepositoryResponse = client().admin().cluster().preparePutRepository("dummy-repo").setType("fs").setSettings(Settings.builder().put("location", randomRepoPath())).get();
    assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true));
    client().admin().cluster().prepareCreateSnapshot("dummy-repo", "snap1").setWaitForCompletion(true).get();
    IndicesOptions options = IndicesOptions.fromOptions(false, false, true, false);
    verify(snapshot("snap2", "foo*", "bar*").setIndicesOptions(options), true);
    verify(restore("snap1", "foo*", "bar*").setIndicesOptions(options), true);
    options = IndicesOptions.strictExpandOpen();
    verify(snapshot("snap2", "foo*", "bar*").setIndicesOptions(options), false);
    verify(restore("snap2", "foo*", "bar*").setIndicesOptions(options), false);
    assertAcked(prepareCreate("barbaz"));
    //TODO: temporary work-around for #5531
    ensureGreen("barbaz");
    waitForRelocation();
    options = IndicesOptions.fromOptions(false, false, true, false);
    verify(snapshot("snap3", "foo*", "bar*").setIndicesOptions(options), false);
    verify(restore("snap3", "foo*", "bar*").setIndicesOptions(options), false);
    options = IndicesOptions.fromOptions(false, false, true, false);
    verify(snapshot("snap4", "foo*", "baz*").setIndicesOptions(options), true);
    verify(restore("snap3", "foo*", "baz*").setIndicesOptions(options), true);
}
Also used : PutRepositoryResponse(org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse) IndicesOptions(org.elasticsearch.action.support.IndicesOptions)

Example 7 with IndicesOptions

use of org.elasticsearch.action.support.IndicesOptions in project elasticsearch by elastic.

the class ClusterStateRequestTests method testSerialization.

public void testSerialization() throws Exception {
    int iterations = randomIntBetween(5, 20);
    for (int i = 0; i < iterations; i++) {
        IndicesOptions indicesOptions = IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean());
        ClusterStateRequest clusterStateRequest = new ClusterStateRequest().routingTable(randomBoolean()).metaData(randomBoolean()).nodes(randomBoolean()).blocks(randomBoolean()).indices("testindex", "testindex2").indicesOptions(indicesOptions);
        Version testVersion = VersionUtils.randomVersionBetween(random(), Version.CURRENT.minimumCompatibilityVersion(), Version.CURRENT);
        BytesStreamOutput output = new BytesStreamOutput();
        output.setVersion(testVersion);
        clusterStateRequest.writeTo(output);
        StreamInput streamInput = output.bytes().streamInput();
        streamInput.setVersion(testVersion);
        ClusterStateRequest deserializedCSRequest = new ClusterStateRequest();
        deserializedCSRequest.readFrom(streamInput);
        assertThat(deserializedCSRequest.routingTable(), equalTo(clusterStateRequest.routingTable()));
        assertThat(deserializedCSRequest.metaData(), equalTo(clusterStateRequest.metaData()));
        assertThat(deserializedCSRequest.nodes(), equalTo(clusterStateRequest.nodes()));
        assertThat(deserializedCSRequest.blocks(), equalTo(clusterStateRequest.blocks()));
        assertThat(deserializedCSRequest.indices(), equalTo(clusterStateRequest.indices()));
        assertOptionsMatch(deserializedCSRequest.indicesOptions(), clusterStateRequest.indicesOptions());
    }
}
Also used : Version(org.elasticsearch.Version) StreamInput(org.elasticsearch.common.io.stream.StreamInput) IndicesOptions(org.elasticsearch.action.support.IndicesOptions) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput)

Example 8 with IndicesOptions

use of org.elasticsearch.action.support.IndicesOptions in project elasticsearch by elastic.

the class OriginalIndicesTests method randomOriginalIndices.

private static OriginalIndices randomOriginalIndices() {
    int numIndices = randomInt(10);
    String[] indices = new String[numIndices];
    for (int j = 0; j < indices.length; j++) {
        indices[j] = randomAsciiOfLength(randomIntBetween(1, 10));
    }
    IndicesOptions indicesOptions = randomFrom(indicesOptionsValues);
    return new OriginalIndices(indices, indicesOptions);
}
Also used : IndicesOptions(org.elasticsearch.action.support.IndicesOptions)

Example 9 with IndicesOptions

use of org.elasticsearch.action.support.IndicesOptions in project elasticsearch by elastic.

the class RestSyncedFlushAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    IndicesOptions indicesOptions = IndicesOptions.fromRequest(request, IndicesOptions.lenientExpandOpen());
    SyncedFlushRequest syncedFlushRequest = new SyncedFlushRequest(Strings.splitStringByCommaToArray(request.param("index")));
    syncedFlushRequest.indicesOptions(indicesOptions);
    return channel -> client.admin().indices().syncedFlush(syncedFlushRequest, new RestBuilderListener<SyncedFlushResponse>(channel) {

        @Override
        public RestResponse buildResponse(SyncedFlushResponse results, XContentBuilder builder) throws Exception {
            builder.startObject();
            results.toXContent(builder, request);
            builder.endObject();
            return new BytesRestResponse(results.restStatus(), builder);
        }
    });
}
Also used : SyncedFlushRequest(org.elasticsearch.action.admin.indices.flush.SyncedFlushRequest) BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) GET(org.elasticsearch.rest.RestRequest.Method.GET) RestResponse(org.elasticsearch.rest.RestResponse) RestBuilderListener(org.elasticsearch.rest.action.RestBuilderListener) IOException(java.io.IOException) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) RestController(org.elasticsearch.rest.RestController) Strings(org.elasticsearch.common.Strings) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) POST(org.elasticsearch.rest.RestRequest.Method.POST) Settings(org.elasticsearch.common.settings.Settings) IndicesOptions(org.elasticsearch.action.support.IndicesOptions) RestRequest(org.elasticsearch.rest.RestRequest) SyncedFlushResponse(org.elasticsearch.action.admin.indices.flush.SyncedFlushResponse) NodeClient(org.elasticsearch.client.node.NodeClient) RestResponse(org.elasticsearch.rest.RestResponse) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) SyncedFlushResponse(org.elasticsearch.action.admin.indices.flush.SyncedFlushResponse) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) IndicesOptions(org.elasticsearch.action.support.IndicesOptions) SyncedFlushRequest(org.elasticsearch.action.admin.indices.flush.SyncedFlushRequest) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) IOException(java.io.IOException)

Example 10 with IndicesOptions

use of org.elasticsearch.action.support.IndicesOptions in project elasticsearch by elastic.

the class RestIndicesAction method doCatRequest.

@Override
public RestChannelConsumer doCatRequest(final RestRequest request, final NodeClient client) {
    final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
    final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
    clusterStateRequest.clear().indices(indices).metaData(true);
    clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
    clusterStateRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterStateRequest.masterNodeTimeout()));
    final IndicesOptions strictExpandIndicesOptions = IndicesOptions.strictExpand();
    clusterStateRequest.indicesOptions(strictExpandIndicesOptions);
    return channel -> client.admin().cluster().state(clusterStateRequest, new RestActionListener<ClusterStateResponse>(channel) {

        @Override
        public void processResponse(final ClusterStateResponse clusterStateResponse) {
            final ClusterState state = clusterStateResponse.getState();
            final Index[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, strictExpandIndicesOptions, indices);
            assert concreteIndices.length == state.metaData().getIndices().size();
            ClusterHealthRequest clusterHealthRequest = Requests.clusterHealthRequest(indices);
            clusterHealthRequest.local(request.paramAsBoolean("local", clusterHealthRequest.local()));
            client.admin().cluster().health(clusterHealthRequest, new RestActionListener<ClusterHealthResponse>(channel) {

                @Override
                public void processResponse(final ClusterHealthResponse clusterHealthResponse) {
                    IndicesStatsRequest indicesStatsRequest = new IndicesStatsRequest();
                    indicesStatsRequest.indices(indices);
                    indicesStatsRequest.indicesOptions(strictExpandIndicesOptions);
                    indicesStatsRequest.all();
                    client.admin().indices().stats(indicesStatsRequest, new RestResponseListener<IndicesStatsResponse>(channel) {

                        @Override
                        public RestResponse buildResponse(IndicesStatsResponse indicesStatsResponse) throws Exception {
                            Table tab = buildTable(request, concreteIndices, clusterHealthResponse, indicesStatsResponse, state.metaData());
                            return RestTable.buildResponse(tab, channel);
                        }
                    });
                }
            });
        }
    });
}
Also used : MetaData(org.elasticsearch.cluster.metadata.MetaData) DateTimeZone(org.joda.time.DateTimeZone) Arrays(java.util.Arrays) GET(org.elasticsearch.rest.RestRequest.Method.GET) Table(org.elasticsearch.common.Table) IndexStats(org.elasticsearch.action.admin.indices.stats.IndexStats) Index(org.elasticsearch.index.Index) ClusterIndexHealth(org.elasticsearch.cluster.health.ClusterIndexHealth) Strings(org.elasticsearch.common.Strings) HashSet(java.util.HashSet) IndicesStatsResponse(org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse) ClusterState(org.elasticsearch.cluster.ClusterState) IndicesStatsRequest(org.elasticsearch.action.admin.indices.stats.IndicesStatsRequest) Settings(org.elasticsearch.common.settings.Settings) Locale(java.util.Locale) IndicesOptions(org.elasticsearch.action.support.IndicesOptions) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) Requests(org.elasticsearch.client.Requests) RestResponseListener(org.elasticsearch.rest.action.RestResponseListener) RestResponse(org.elasticsearch.rest.RestResponse) DateTime(org.joda.time.DateTime) Set(java.util.Set) ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) RestController(org.elasticsearch.rest.RestController) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) ClusterHealthRequest(org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) ClusterStateRequest(org.elasticsearch.action.admin.cluster.state.ClusterStateRequest) ClusterHealthStatus(org.elasticsearch.cluster.health.ClusterHealthStatus) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) Collections(java.util.Collections) RestActionListener(org.elasticsearch.rest.action.RestActionListener) ClusterState(org.elasticsearch.cluster.ClusterState) IndicesStatsResponse(org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse) Table(org.elasticsearch.common.Table) ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) ClusterHealthRequest(org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) RestResponse(org.elasticsearch.rest.RestResponse) ClusterStateRequest(org.elasticsearch.action.admin.cluster.state.ClusterStateRequest) RestActionListener(org.elasticsearch.rest.action.RestActionListener) IndicesOptions(org.elasticsearch.action.support.IndicesOptions) IndicesStatsRequest(org.elasticsearch.action.admin.indices.stats.IndicesStatsRequest)

Aggregations

IndicesOptions (org.elasticsearch.action.support.IndicesOptions)33 ClusterState (org.elasticsearch.cluster.ClusterState)10 ClusterName (org.elasticsearch.cluster.ClusterName)9 IndexNotFoundException (org.elasticsearch.index.IndexNotFoundException)9 Matchers.containsString (org.hamcrest.Matchers.containsString)9 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)4 SearchRequest (org.elasticsearch.action.search.SearchRequest)3 NodeClient (org.elasticsearch.client.node.NodeClient)3 Strings (org.elasticsearch.common.Strings)3 BytesReference (org.elasticsearch.common.bytes.BytesReference)3 Settings (org.elasticsearch.common.settings.Settings)3 RestController (org.elasticsearch.rest.RestController)3 RestRequest (org.elasticsearch.rest.RestRequest)3 GET (org.elasticsearch.rest.RestRequest.Method.GET)3 RestResponse (org.elasticsearch.rest.RestResponse)3 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 TestUtil.randomSimpleString (org.apache.lucene.util.TestUtil.randomSimpleString)2 PutRepositoryResponse (org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse)2 CreateSnapshotRequest (org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest)2