Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose the indices names in every action relates to if applicable #6933

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
eddb909
Internal: expose the indices names every action relates to if applicable
javanna Jul 20, 2014
59e7ad3
made IndicesRelatedRequestHelper a static inner class within IndicesR…
javanna Jul 21, 2014
18e62a8
renamed relatedIndices method to requestedIndices
javanna Jul 21, 2014
4f631f7
switched to IllegalStateException in case a put warmer doesn't contai…
javanna Jul 21, 2014
85b8ec1
use an assert instead of exception if a write request within a bulk r…
javanna Jul 21, 2014
fcee5fe
added asserts to state that the single index should never be null for…
javanna Jul 21, 2014
f11567b
make sure NPE is never thrown when setting indices(null) to IndicesAl…
javanna Jul 21, 2014
d644e02
make sure null index is not accepted by MoreLikeThisRequest#requested…
javanna Jul 21, 2014
51641be
used Strings.EMPTY_ARRAY whenever possible
javanna Jul 21, 2014
870b8ea
switched requestedIndices return type from String[] to Set<String>, i…
javanna Jul 21, 2014
e81cbdd
switched to ImmutableSet for requestedIndices signature
javanna Jul 21, 2014
fbe463d
aligned requestedIndices to validate for open/close index, delete ind…
javanna Jul 22, 2014
ec73bba
Renamed IndicesRelatedRequest to IndicesRequest and reused indices me…
javanna Jul 23, 2014
4298a8d
Addressed composite action by adding CompositeIndicesRequest interface
javanna Jul 23, 2014
dbe435b
Added indices options to IndicesRequest interface, to express the dif…
javanna Jul 23, 2014
912dac3
clarified what we do in MoreLikeThisRequest, also fixed behaviour
javanna Jul 24, 2014
efa44aa
improved PutWarmerRequest error message
javanna Jul 24, 2014
56d6fef
used Item#indicesOptions in MultiGet
javanna Jul 24, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,34 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.elasticsearch.action;

import java.util.List;

/**
* Needs to be implemented by all {@link org.elasticsearch.action.ActionRequest} subclasses that are composed of
* multiple subrequests which relate to one or more indices. Allows to retrieve those subrequests.
*/
public interface CompositeIndicesRequest {

/**
* Returns the subrequests that a composite request is composed of
*/
List<? extends IndicesRequest> subRequests();
}
40 changes: 40 additions & 0 deletions src/main/java/org/elasticsearch/action/IndicesRequest.java
@@ -0,0 +1,40 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.elasticsearch.action;

import org.elasticsearch.action.support.IndicesOptions;

/**
* Needs to be implemented by all {@link org.elasticsearch.action.ActionRequest} subclasses that relate to
* one or more indices. Allows to retrieve which indices the action relates to.
*/
public interface IndicesRequest {

/**
* Returns the array of indices that the action relates to
*/
String[] indices();

/**
* Returns the indices options used to resolve indices. They tell for instance whether a single index is
* accepted, whether an empty array will be converted to _all, and how wildcards will be expanded if needed.
*/
IndicesOptions indicesOptions();
}
Expand Up @@ -20,6 +20,8 @@
package org.elasticsearch.action.admin.cluster.health;

import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.IndicesRequest;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.action.support.master.MasterNodeReadOperationRequest;
import org.elasticsearch.common.Priority;
import org.elasticsearch.common.Strings;
Expand All @@ -35,7 +37,7 @@
/**
*
*/
public class ClusterHealthRequest extends MasterNodeReadOperationRequest<ClusterHealthRequest> {
public class ClusterHealthRequest extends MasterNodeReadOperationRequest<ClusterHealthRequest> implements IndicesRequest {

private String[] indices;
private TimeValue timeout = new TimeValue(30, TimeUnit.SECONDS);
Expand All @@ -52,6 +54,7 @@ public ClusterHealthRequest(String... indices) {
this.indices = indices;
}

@Override
public String[] indices() {
return indices;
}
Expand All @@ -61,6 +64,11 @@ public ClusterHealthRequest indices(String[] indices) {
return this;
}

@Override
public IndicesOptions indicesOptions() {
return IndicesOptions.lenientExpandOpen();
}

public TimeValue timeout() {
return timeout;
}
Expand Down
Expand Up @@ -217,7 +217,7 @@ private ClusterHealthResponse clusterHealth(ClusterHealthRequest request, Cluste
}
String[] concreteIndices;
try {
concreteIndices = clusterState.metaData().concreteIndices(IndicesOptions.lenientExpandOpen(), request.indices());
concreteIndices = clusterState.metaData().concreteIndices(request.indicesOptions(), request.indices());
} catch (IndexMissingException e) {
// one of the specified indices is not there - treat it as RED.
ClusterHealthResponse response = new ClusterHealthResponse(clusterName.value(), Strings.EMPTY_ARRAY, clusterState);
Expand Down
Expand Up @@ -21,6 +21,7 @@

import org.elasticsearch.ElasticsearchIllegalArgumentException;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.IndicesRequest;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.action.support.master.MasterNodeReadOperationRequest;
import org.elasticsearch.common.Nullable;
Expand All @@ -32,7 +33,7 @@

/**
*/
public class ClusterSearchShardsRequest extends MasterNodeReadOperationRequest<ClusterSearchShardsRequest> {
public class ClusterSearchShardsRequest extends MasterNodeReadOperationRequest<ClusterSearchShardsRequest> implements IndicesRequest {
private String[] indices;
@Nullable
private String routing;
Expand Down Expand Up @@ -74,10 +75,12 @@ public ClusterSearchShardsRequest indices(String... indices) {
/**
* The indices
*/
@Override
public String[] indices() {
return indices;
}

@Override
public IndicesOptions indicesOptions() {
return indicesOptions;
}
Expand Down
Expand Up @@ -22,6 +22,7 @@
import org.elasticsearch.ElasticsearchGenerationException;
import org.elasticsearch.ElasticsearchIllegalArgumentException;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.IndicesRequest;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.action.support.master.MasterNodeOperationRequest;
import org.elasticsearch.common.Strings;
Expand All @@ -42,9 +43,9 @@
import static org.elasticsearch.action.ValidateActions.addValidationError;
import static org.elasticsearch.common.Strings.EMPTY_ARRAY;
import static org.elasticsearch.common.Strings.hasLength;
import static org.elasticsearch.common.settings.ImmutableSettings.Builder.EMPTY_SETTINGS;
import static org.elasticsearch.common.settings.ImmutableSettings.readSettingsFromStream;
import static org.elasticsearch.common.settings.ImmutableSettings.writeSettingsToStream;
import static org.elasticsearch.common.settings.ImmutableSettings.Builder.EMPTY_SETTINGS;
import static org.elasticsearch.common.xcontent.support.XContentMapValues.nodeBooleanValue;

/**
Expand All @@ -61,7 +62,7 @@
* <li>must not contain invalid file name characters {@link org.elasticsearch.common.Strings#INVALID_FILENAME_CHARS} </li>
* </ul>
*/
public class CreateSnapshotRequest extends MasterNodeOperationRequest<CreateSnapshotRequest> {
public class CreateSnapshotRequest extends MasterNodeOperationRequest<CreateSnapshotRequest> implements IndicesRequest {

private String snapshot;

Expand Down Expand Up @@ -195,6 +196,7 @@ public CreateSnapshotRequest indices(List<String> indices) {
*
* @return list of indices
*/
@Override
public String[] indices() {
return indices;
}
Expand All @@ -204,6 +206,7 @@ public String[] indices() {
*
* @return the desired behaviour regarding indices options
*/
@Override
public IndicesOptions indicesOptions() {
return indicesOptions;
}
Expand Down
Expand Up @@ -21,6 +21,8 @@

import org.elasticsearch.Version;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.IndicesRequest;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.action.support.master.MasterNodeReadOperationRequest;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.stream.StreamInput;
Expand All @@ -31,7 +33,7 @@
/**
*
*/
public class ClusterStateRequest extends MasterNodeReadOperationRequest<ClusterStateRequest> {
public class ClusterStateRequest extends MasterNodeReadOperationRequest<ClusterStateRequest> implements IndicesRequest {

private boolean routingTable = true;
private boolean nodes = true;
Expand Down Expand Up @@ -101,6 +103,7 @@ public ClusterStateRequest blocks(boolean blocks) {
return this;
}

@Override
public String[] indices() {
return indices;
}
Expand All @@ -110,6 +113,11 @@ public ClusterStateRequest indices(String... indices) {
return this;
}

@Override
public IndicesOptions indicesOptions() {
return IndicesOptions.lenientExpandOpen();
}

@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
Expand Down
Expand Up @@ -22,7 +22,6 @@
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.action.support.master.TransportMasterNodeReadOperationAction;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterService;
Expand Down Expand Up @@ -99,7 +98,7 @@ protected void masterOperation(final ClusterStateRequest request, final ClusterS
}

if (request.indices().length > 0) {
String[] indices = currentState.metaData().concreteIndices(IndicesOptions.lenientExpandOpen(), request.indices());
String[] indices = currentState.metaData().concreteIndices(request.indicesOptions(), request.indices());
for (String filteredIndex : indices) {
IndexMetaData indexMetaData = currentState.metaData().index(filteredIndex);
if (indexMetaData != null) {
Expand Down
Expand Up @@ -22,7 +22,9 @@
import com.carrotsearch.hppc.cursors.ObjectCursor;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import org.elasticsearch.ElasticsearchIllegalArgumentException;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.IndicesRequest;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.action.support.master.AcknowledgedRequest;
import org.elasticsearch.cluster.metadata.AliasAction;
Expand All @@ -37,18 +39,15 @@
import org.elasticsearch.index.query.FilterBuilder;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.*;

import static org.elasticsearch.action.ValidateActions.addValidationError;
import static org.elasticsearch.cluster.metadata.AliasAction.readAliasAction;

/**
* A request to add/remove aliases for one or more indices.
*/
public class IndicesAliasesRequest extends AcknowledgedRequest<IndicesAliasesRequest> {
public class IndicesAliasesRequest extends AcknowledgedRequest<IndicesAliasesRequest> implements IndicesRequest {

private List<AliasActions> allAliasActions = Lists.newArrayList();

Expand Down Expand Up @@ -135,6 +134,9 @@ public AliasActions filter(String filter) {
}

public void indices(String... indices) {
if (indices == null) {
throw new ElasticsearchIllegalArgumentException("indices must not be null");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we should put a public static final String ALL_INDICES = "_all"; on IndicesRequest and mention it in the error message?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This request doesn't support empty or null values (both are rejected during validation), and will never expand to _all. This change is just to avoid an NPE in the following loop if one does request.indices(null). I don't think _all is related.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok fine

}
List<String> finalIndices = new ArrayList<>();
for (String index : indices) {
if (index != null) {
Expand Down Expand Up @@ -309,6 +311,17 @@ public ActionRequestValidationException validate() {
return validationException;
}

@Override
public String[] indices() {
List<String> indices = Lists.newArrayList();
for (AliasActions aliasActions : aliasActions()) {
if (!CollectionUtils.isEmpty(aliasActions.indices())) {
Collections.addAll(indices, aliasActions.indices);
}
}
return indices.toArray(new String[indices.size()]);
}

@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
Expand All @@ -329,6 +342,7 @@ public void writeTo(StreamOutput out) throws IOException {
writeTimeout(out);
}

@Override
public IndicesOptions indicesOptions() {
return indicesOptions;
}
Expand Down
Expand Up @@ -20,6 +20,7 @@

import org.elasticsearch.Version;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.IndicesRequest;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.action.support.master.MasterNodeReadOperationRequest;
import org.elasticsearch.common.Strings;
Expand All @@ -30,7 +31,7 @@

/**
*/
public class GetAliasesRequest extends MasterNodeReadOperationRequest<GetAliasesRequest> {
public class GetAliasesRequest extends MasterNodeReadOperationRequest<GetAliasesRequest> implements IndicesRequest {

private String[] indices = Strings.EMPTY_ARRAY;
private String[] aliases = Strings.EMPTY_ARRAY;
Expand Down Expand Up @@ -63,6 +64,7 @@ public GetAliasesRequest indicesOptions(IndicesOptions indicesOptions) {
return this;
}

@Override
public String[] indices() {
return indices;
}
Expand All @@ -71,6 +73,7 @@ public String[] aliases() {
return aliases;
}

@Override
public IndicesOptions indicesOptions() {
return indicesOptions;
}
Expand Down
Expand Up @@ -20,6 +20,8 @@

import org.elasticsearch.Version;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.IndicesRequest;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.action.support.single.custom.SingleCustomOperationRequest;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.Strings;
Expand All @@ -34,7 +36,7 @@
* A request to analyze a text associated with a specific index. Allow to provide
* the actual analyzer name to perform the analysis with.
*/
public class AnalyzeRequest extends SingleCustomOperationRequest<AnalyzeRequest> {
public class AnalyzeRequest extends SingleCustomOperationRequest<AnalyzeRequest> implements IndicesRequest {

private String index;

Expand Down Expand Up @@ -87,6 +89,19 @@ public String index() {
return this.index;
}

@Override
public String[] indices() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we also prevent null here too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's ok here as the index in the analyze api is optional

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok cool

if (index == null) {
return Strings.EMPTY_ARRAY;
}
return new String[]{index};
}

@Override
public IndicesOptions indicesOptions() {
return IndicesOptions.strictSingleIndexNoExpandForbidClosed();
}

public AnalyzeRequest analyzer(String analyzer) {
this.analyzer = analyzer;
return this;
Expand Down
Expand Up @@ -89,7 +89,7 @@ protected ClusterBlockException checkGlobalBlock(ClusterState state, AnalyzeRequ
@Override
protected ClusterBlockException checkRequestBlock(ClusterState state, AnalyzeRequest request) {
if (request.index() != null) {
request.index(state.metaData().concreteSingleIndex(request.index()));
request.index(state.metaData().concreteSingleIndex(request.index(), request.indicesOptions()));
return state.blocks().indexBlockedException(ClusterBlockLevel.READ, request.index());
}
return null;
Expand Down