forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP rest scaffolding for rename index API
- Loading branch information
Showing
4 changed files
with
171 additions
and
0 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
55 changes: 55 additions & 0 deletions
55
server/src/main/java/org/elasticsearch/index/rename/RenameIndexRequest.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,55 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
package org.elasticsearch.index.rename; | ||
|
||
import org.elasticsearch.action.ActionRequestValidationException; | ||
import org.elasticsearch.action.support.master.MasterNodeRequest; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
import org.elasticsearch.core.TimeValue; | ||
|
||
import java.io.IOException; | ||
|
||
public class RenameIndexRequest extends MasterNodeRequest<RenameIndexRequest> { | ||
private String index; | ||
private String newIndex; | ||
|
||
public RenameIndexRequest(TimeValue masterNodeTimeout, String index, String newIndex) { | ||
super(masterNodeTimeout); | ||
this.index = index; | ||
this.newIndex = newIndex; | ||
} | ||
|
||
public RenameIndexRequest(StreamInput in) throws IOException { | ||
super(in); | ||
this.index = in.readString(); | ||
this.newIndex = in.readString(); | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
// TODO: validate | ||
return null; | ||
} | ||
|
||
public String newIndex() { | ||
return newIndex; | ||
} | ||
|
||
public String index() { | ||
return index; | ||
} | ||
|
||
public void writeTo(StreamOutput out) throws IOException { | ||
super.writeTo(out); | ||
out.writeString(this.index); | ||
out.writeString(this.newIndex); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
server/src/main/java/org/elasticsearch/index/rename/TransportRenameIndexAction.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,65 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
package org.elasticsearch.index.rename; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.elasticsearch.action.ActionListener; | ||
import org.elasticsearch.action.ActionType; | ||
import org.elasticsearch.action.support.ActionFilters; | ||
import org.elasticsearch.action.support.master.AcknowledgedResponse; | ||
import org.elasticsearch.action.support.master.TransportMasterNodeAction; | ||
import org.elasticsearch.cluster.ClusterState; | ||
import org.elasticsearch.cluster.block.ClusterBlockException; | ||
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; | ||
import org.elasticsearch.cluster.service.ClusterService; | ||
import org.elasticsearch.common.util.concurrent.EsExecutors; | ||
import org.elasticsearch.injection.guice.Inject; | ||
import org.elasticsearch.tasks.Task; | ||
import org.elasticsearch.threadpool.ThreadPool; | ||
import org.elasticsearch.transport.TransportService; | ||
|
||
public class TransportRenameIndexAction extends TransportMasterNodeAction<RenameIndexRequest, AcknowledgedResponse> { | ||
public static final String NAME = "indices:admin/rename"; | ||
public static final ActionType<AcknowledgedResponse> TYPE = new ActionType<>(NAME); | ||
private static final Logger logger = LogManager.getLogger(TransportRenameIndexAction.class); | ||
|
||
@Inject | ||
protected TransportRenameIndexAction( | ||
TransportService transportService, | ||
ClusterService clusterService, | ||
ThreadPool threadPool, | ||
ActionFilters actionFilters, | ||
IndexNameExpressionResolver indexNameExpressionResolver | ||
) { | ||
super( | ||
NAME, | ||
transportService, | ||
clusterService, | ||
threadPool, | ||
actionFilters, | ||
RenameIndexRequest::new, | ||
indexNameExpressionResolver, | ||
AcknowledgedResponse::readFrom, | ||
EsExecutors.DIRECT_EXECUTOR_SERVICE | ||
); | ||
} | ||
|
||
@Override | ||
protected void masterOperation(Task task, RenameIndexRequest request, ClusterState state, ActionListener<AcknowledgedResponse> listener) | ||
throws Exception { | ||
|
||
} | ||
|
||
@Override | ||
protected ClusterBlockException checkBlock(RenameIndexRequest request, ClusterState state) { | ||
return null; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRenameIndexAction.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,47 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
package org.elasticsearch.rest.action.admin.indices; | ||
|
||
import org.elasticsearch.client.internal.node.NodeClient; | ||
import org.elasticsearch.index.rename.RenameIndexRequest; | ||
import org.elasticsearch.index.rename.TransportRenameIndexAction; | ||
import org.elasticsearch.rest.BaseRestHandler; | ||
import org.elasticsearch.rest.RestRequest; | ||
import org.elasticsearch.rest.action.RestToXContentListener; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
import static org.elasticsearch.rest.RestUtils.getMasterNodeTimeout; | ||
|
||
public class RestRenameIndexAction extends BaseRestHandler { | ||
@Override | ||
public String getName() { | ||
return "rename_index_action"; | ||
} | ||
|
||
@Override | ||
public List<Route> routes() { | ||
return List.of( | ||
new Route(RestRequest.Method.POST, "/_rename/{index}"), | ||
new Route(RestRequest.Method.POST, "/_rename/{index}/{newIndex}") | ||
); | ||
} | ||
|
||
@Override | ||
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { | ||
RenameIndexRequest renameRequest = new RenameIndexRequest( | ||
getMasterNodeTimeout(request), | ||
request.param("index"), | ||
request.param("newIndex", "bar") | ||
); | ||
return channel -> client.execute(TransportRenameIndexAction.TYPE, renameRequest, new RestToXContentListener<>(channel)); | ||
} | ||
} |