Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added three new index alias related apis.
Added apis to get specific index aliases based on filtering by alias name and index name: ``` curl -XGET 'localhost:9200/{index_or_alias}/_alias/{alias_name}' ``` Added delete index alias api for deleting a single index alias: ``` curl -XDELETE 'localhost:9200/{index}/_alias/{alias_name}' ``` Added create index alias api for adding a single index alias: ``` curl -XPUT 'localhost:9200/{index}/_alias/{alias_name}' curl -XPUT 'localhost:9200/{index}/_alias/{alias_name}' -d '{ "routing" : {routing}, "filter" : {filter} }' ``` Closes #3075 #3076 #3077
- Loading branch information
Showing
15 changed files
with
1,059 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/main/java/org/elasticsearch/action/admin/indices/alias/get/IndicesGetAliasesAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Licensed to ElasticSearch and Shay Banon 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.admin.indices.alias.get; | ||
|
||
import org.elasticsearch.action.admin.indices.IndicesAction; | ||
import org.elasticsearch.client.IndicesAdminClient; | ||
|
||
/** | ||
*/ | ||
public class IndicesGetAliasesAction extends IndicesAction<IndicesGetAliasesRequest, IndicesGetAliasesResponse, IndicesGetAliasesRequestBuilder> { | ||
|
||
public static final IndicesGetAliasesAction INSTANCE = new IndicesGetAliasesAction(); | ||
public static final String NAME = "indices/get/aliases"; | ||
|
||
private IndicesGetAliasesAction() { | ||
super(NAME); | ||
} | ||
|
||
@Override | ||
public IndicesGetAliasesRequestBuilder newRequestBuilder(IndicesAdminClient client) { | ||
return new IndicesGetAliasesRequestBuilder(client); | ||
} | ||
|
||
@Override | ||
public IndicesGetAliasesResponse newResponse() { | ||
return new IndicesGetAliasesResponse(); | ||
} | ||
} |
103 changes: 103 additions & 0 deletions
103
src/main/java/org/elasticsearch/action/admin/indices/alias/get/IndicesGetAliasesRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
* Licensed to ElasticSearch and Shay Banon 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.admin.indices.alias.get; | ||
|
||
import org.elasticsearch.action.ActionRequestValidationException; | ||
import org.elasticsearch.action.support.IgnoreIndices; | ||
import org.elasticsearch.action.support.master.MasterNodeOperationRequest; | ||
import org.elasticsearch.common.Strings; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.elasticsearch.action.ValidateActions.addValidationError; | ||
|
||
/** | ||
*/ | ||
public class IndicesGetAliasesRequest extends MasterNodeOperationRequest<IndicesGetAliasesRequest> { | ||
|
||
private String[] indices = Strings.EMPTY_ARRAY; | ||
private String[] aliases = Strings.EMPTY_ARRAY; | ||
|
||
private IgnoreIndices ignoreIndices = IgnoreIndices.NONE; | ||
|
||
public IndicesGetAliasesRequest(String[] aliases) { | ||
this.aliases = aliases; | ||
} | ||
|
||
public IndicesGetAliasesRequest(String alias) { | ||
this.aliases = new String[]{alias}; | ||
} | ||
|
||
IndicesGetAliasesRequest() { | ||
} | ||
|
||
public IndicesGetAliasesRequest indices(String... indices) { | ||
this.indices = indices; | ||
return this; | ||
} | ||
|
||
public IndicesGetAliasesRequest aliases(String... aliases) { | ||
this.aliases = aliases; | ||
return this; | ||
} | ||
|
||
public IndicesGetAliasesRequest ignoreIndices(IgnoreIndices ignoreIndices) { | ||
this.ignoreIndices = ignoreIndices; | ||
return this; | ||
} | ||
|
||
public String[] indices() { | ||
return indices; | ||
} | ||
|
||
public String[] aliases() { | ||
return aliases; | ||
} | ||
|
||
public IgnoreIndices ignoreIndices() { | ||
return ignoreIndices; | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
if (aliases.length == 0) { | ||
return addValidationError("No alias specified", null); | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
@Override | ||
public void readFrom(StreamInput in) throws IOException { | ||
super.readFrom(in); | ||
indices = in.readStringArray(); | ||
aliases = in.readStringArray(); | ||
ignoreIndices = IgnoreIndices.fromId(in.readByte()); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
super.writeTo(out); | ||
out.writeStringArray(indices); | ||
out.writeStringArray(aliases); | ||
out.writeByte(ignoreIndices.id()); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
...ava/org/elasticsearch/action/admin/indices/alias/get/IndicesGetAliasesRequestBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Licensed to ElasticSearch and Shay Banon 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.admin.indices.alias.get; | ||
|
||
import com.google.common.collect.ObjectArrays; | ||
import org.elasticsearch.action.ActionListener; | ||
import org.elasticsearch.action.support.master.MasterNodeOperationRequestBuilder; | ||
import org.elasticsearch.client.IndicesAdminClient; | ||
import org.elasticsearch.client.internal.InternalIndicesAdminClient; | ||
|
||
/** | ||
*/ | ||
public class IndicesGetAliasesRequestBuilder extends MasterNodeOperationRequestBuilder<IndicesGetAliasesRequest, IndicesGetAliasesResponse, IndicesGetAliasesRequestBuilder> { | ||
|
||
public IndicesGetAliasesRequestBuilder(IndicesAdminClient client, String... aliases) { | ||
super((InternalIndicesAdminClient)client, new IndicesGetAliasesRequest(aliases)); | ||
} | ||
|
||
public IndicesGetAliasesRequestBuilder setAliases(String... aliases) { | ||
request.aliases(aliases); | ||
return this; | ||
} | ||
|
||
public IndicesGetAliasesRequestBuilder addAliases(String... aliases) { | ||
request.aliases(ObjectArrays.concat(request.aliases(), aliases, String.class)); | ||
return this; | ||
} | ||
|
||
public IndicesGetAliasesRequestBuilder setIndices(String... indices) { | ||
request.indices(indices); | ||
return this; | ||
} | ||
|
||
public IndicesGetAliasesRequestBuilder addIndices(String... indices) { | ||
request.indices(ObjectArrays.concat(request.indices(), indices, String.class)); | ||
return this; | ||
} | ||
|
||
@Override | ||
protected void doExecute(ActionListener<IndicesGetAliasesResponse> listener) { | ||
((IndicesAdminClient) client).getAliases(request, listener); | ||
} | ||
|
||
} |
78 changes: 78 additions & 0 deletions
78
...main/java/org/elasticsearch/action/admin/indices/alias/get/IndicesGetAliasesResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Licensed to ElasticSearch and Shay Banon 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.admin.indices.alias.get; | ||
|
||
import org.elasticsearch.action.ActionResponse; | ||
import org.elasticsearch.cluster.metadata.AliasMetaData; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
*/ | ||
public class IndicesGetAliasesResponse extends ActionResponse { | ||
|
||
private Map<String, List<AliasMetaData>> aliases = new HashMap<String, List<AliasMetaData>>(); | ||
|
||
public IndicesGetAliasesResponse(Map<String, List<AliasMetaData>> aliases) { | ||
this.aliases = aliases; | ||
} | ||
|
||
IndicesGetAliasesResponse() { | ||
} | ||
|
||
|
||
public Map<String, List<AliasMetaData>> getAliases() { | ||
return aliases; | ||
} | ||
|
||
@Override | ||
public void readFrom(StreamInput in) throws IOException { | ||
super.readFrom(in); | ||
int size = in.readVInt(); | ||
for (int i = 0; i < size; i++) { | ||
String key = in.readString(); | ||
int valueSize = in.readVInt(); | ||
List<AliasMetaData> value = new ArrayList<AliasMetaData>(valueSize); | ||
for (int j = 0; j < valueSize; j++) { | ||
value.add(AliasMetaData.Builder.readFrom(in)); | ||
} | ||
aliases.put(key, value); | ||
} | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
super.writeTo(out); | ||
out.writeVInt(aliases.size()); | ||
for (Map.Entry<String, List<AliasMetaData>> entry : aliases.entrySet()) { | ||
out.writeString(entry.getKey()); | ||
out.writeVInt(entry.getValue().size()); | ||
for (AliasMetaData aliasMetaData : entry.getValue()) { | ||
AliasMetaData.Builder.writeTo(aliasMetaData, out); | ||
} | ||
} | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
...va/org/elasticsearch/action/admin/indices/alias/get/TransportIndicesGetAliasesAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Licensed to ElasticSearch and Shay Banon 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.admin.indices.alias.get; | ||
|
||
import org.elasticsearch.ElasticSearchException; | ||
import org.elasticsearch.action.support.master.TransportMasterNodeOperationAction; | ||
import org.elasticsearch.cluster.ClusterService; | ||
import org.elasticsearch.cluster.ClusterState; | ||
import org.elasticsearch.cluster.metadata.AliasMetaData; | ||
import org.elasticsearch.common.inject.Inject; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.indices.AliasMissingException; | ||
import org.elasticsearch.threadpool.ThreadPool; | ||
import org.elasticsearch.transport.TransportService; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
*/ | ||
public class TransportIndicesGetAliasesAction extends TransportMasterNodeOperationAction<IndicesGetAliasesRequest, IndicesGetAliasesResponse> { | ||
|
||
@Inject | ||
public TransportIndicesGetAliasesAction(Settings settings, TransportService transportService, ClusterService clusterService, ThreadPool threadPool) { | ||
super(settings, transportService, clusterService, threadPool); | ||
} | ||
|
||
@Override | ||
protected String transportAction() { | ||
return IndicesGetAliasesAction.NAME; | ||
} | ||
|
||
@Override | ||
protected String executor() { | ||
return ThreadPool.Names.MANAGEMENT; | ||
} | ||
|
||
@Override | ||
protected IndicesGetAliasesRequest newRequest() { | ||
return new IndicesGetAliasesRequest(); | ||
} | ||
|
||
@Override | ||
protected IndicesGetAliasesResponse newResponse() { | ||
return new IndicesGetAliasesResponse(); | ||
} | ||
|
||
@Override | ||
protected IndicesGetAliasesResponse masterOperation(IndicesGetAliasesRequest request, ClusterState state) throws ElasticSearchException { | ||
String[] concreteIndices = state.metaData().concreteIndices(request.indices(), request.ignoreIndices(), true); | ||
request.indices(concreteIndices); | ||
|
||
@SuppressWarnings("unchecked") // ImmutableList to List results incompatible type | ||
Map<String, List<AliasMetaData>> result = (Map) state.metaData().findAliases(request.aliases(), request.indices()); | ||
if (result.isEmpty()) { | ||
throw new AliasMissingException(request.aliases()); | ||
} | ||
return new IndicesGetAliasesResponse(result); | ||
} | ||
|
||
} |
Oops, something went wrong.