Skip to content

Commit

Permalink
Added three new index alias related apis.
Browse files Browse the repository at this point in the history
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
martijnvg committed May 23, 2013
1 parent 841c2d1 commit ffdebe9
Show file tree
Hide file tree
Showing 15 changed files with 1,059 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/main/java/org/elasticsearch/action/ActionModule.java
Expand Up @@ -42,6 +42,8 @@
import org.elasticsearch.action.admin.cluster.state.TransportClusterStateAction;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesAction;
import org.elasticsearch.action.admin.indices.alias.TransportIndicesAliasesAction;
import org.elasticsearch.action.admin.indices.alias.get.IndicesGetAliasesAction;
import org.elasticsearch.action.admin.indices.alias.get.TransportIndicesGetAliasesAction;
import org.elasticsearch.action.admin.indices.analyze.AnalyzeAction;
import org.elasticsearch.action.admin.indices.analyze.TransportAnalyzeAction;
import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheAction;
Expand Down Expand Up @@ -201,6 +203,7 @@ protected void configure() {
registerAction(ClearIndicesCacheAction.INSTANCE, TransportClearIndicesCacheAction.class);
registerAction(PutWarmerAction.INSTANCE, TransportPutWarmerAction.class);
registerAction(DeleteWarmerAction.INSTANCE, TransportDeleteWarmerAction.class);
registerAction(IndicesGetAliasesAction.INSTANCE, TransportIndicesGetAliasesAction.class);

registerAction(IndexAction.INSTANCE, TransportIndexAction.class);
registerAction(GetAction.INSTANCE, TransportGetAction.class);
Expand Down
@@ -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();
}
}
@@ -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());
}
}
@@ -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);
}

}
@@ -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);
}
}
}
}
@@ -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);
}

}

0 comments on commit ffdebe9

Please sign in to comment.