Skip to content

Commit

Permalink
refactor to routes
Browse files Browse the repository at this point in the history
  • Loading branch information
jaymode committed Feb 6, 2020
1 parent 263e2d2 commit 171e368
Show file tree
Hide file tree
Showing 317 changed files with 1,365 additions and 2,233 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,17 @@
import org.elasticsearch.action.update.UpdateResponse;
import org.elasticsearch.client.Requests;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.collect.MapBuilder;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.BytesRestResponse;
import org.elasticsearch.rest.RestChannel;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.RestRequest.Method;
import org.elasticsearch.rest.RestResponse;
import org.elasticsearch.rest.action.RestBuilderListener;

import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import static java.util.Arrays.asList;
import static java.util.Collections.unmodifiableList;
Expand All @@ -52,11 +48,12 @@
public class RestNoopBulkAction extends BaseRestHandler {

@Override
public Map<String, List<Method>> handledMethodsAndPaths() {
return Collections.unmodifiableMap(MapBuilder.<String, List<Method>>newMapBuilder()
.put("/_noop_bulk", unmodifiableList(asList(POST, PUT)))
.put("/{index}/_noop_bulk", unmodifiableList(asList(POST, PUT)))
.map());
public List<Route> handledRoutes() {
return unmodifiableList(asList(
new Route("/_noop_bulk", POST),
new Route("/_noop_bulk", PUT),
new Route("/{index}/_noop_bulk", POST),
new Route("/{index}/_noop_bulk", PUT)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,11 @@

import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.collect.MapBuilder;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.RestRequest.Method;
import org.elasticsearch.rest.action.RestStatusToXContentListener;

import java.util.Collections;
import java.util.List;
import java.util.Map;

import static java.util.Arrays.asList;
import static java.util.Collections.unmodifiableList;
Expand All @@ -38,11 +34,12 @@
public class RestNoopSearchAction extends BaseRestHandler {

@Override
public Map<String, List<Method>> handledMethodsAndPaths() {
return Collections.unmodifiableMap(MapBuilder.<String, List<Method>>newMapBuilder()
.put("/_noop_search", unmodifiableList(asList(GET, POST)))
.put("/{index}/_noop_search", unmodifiableList(asList(GET, POST)))
.map());
public List<Route> handledRoutes() {
return unmodifiableList(asList(
new Route("/_noop_search", GET),
new Route("/_noop_search", POST),
new Route("/{index}/_noop_search", GET),
new Route("/{index}/_noop_search", POST)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.RestRequest.Method;
import org.elasticsearch.rest.action.RestToXContentListener;
import org.elasticsearch.tasks.Task;
import org.elasticsearch.transport.TransportService;
Expand All @@ -43,7 +42,6 @@
import java.util.Map;

import static java.util.Collections.singletonList;
import static java.util.Collections.singletonMap;
import static org.elasticsearch.ingest.common.IngestCommonPlugin.GROK_PATTERNS;
import static org.elasticsearch.rest.RestRequest.Method.GET;

Expand Down Expand Up @@ -121,8 +119,8 @@ protected void doExecute(Task task, Request request, ActionListener<Response> li
public static class RestAction extends BaseRestHandler {

@Override
public Map<String, List<Method>> handledMethodsAndPaths() {
return singletonMap("/_ingest/processor/grok", singletonList(GET));
public List<Route> handledRoutes() {
return singletonList(new Route("/_ingest/processor/grok", GET));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@
package org.elasticsearch.script.mustache;

import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.collect.MapBuilder;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.RestRequest.Method;
import org.elasticsearch.rest.action.RestToXContentListener;
import org.elasticsearch.rest.action.search.RestMultiSearchAction;
import org.elasticsearch.rest.action.search.RestSearchAction;
Expand All @@ -33,7 +31,6 @@
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import static java.util.Arrays.asList;
Expand All @@ -60,11 +57,12 @@ public RestMultiSearchTemplateAction(Settings settings) {
}

@Override
public Map<String, List<Method>> handledMethodsAndPaths() {
return Collections.unmodifiableMap(MapBuilder.<String, List<Method>>newMapBuilder()
.put("/_msearch/template", unmodifiableList(asList(GET, POST)))
.put("/{index}/_msearch/template", unmodifiableList(asList(GET, POST)))
.map());
public List<Route> handledRoutes() {
return unmodifiableList(asList(
new Route("/_msearch/template", GET),
new Route("/_msearch/template", POST),
new Route("/{index}/_msearch/template", GET),
new Route("/{index}/_msearch/template", POST)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,14 @@
package org.elasticsearch.script.mustache;

import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.collect.MapBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.RestRequest.Method;
import org.elasticsearch.rest.action.RestToXContentListener;
import org.elasticsearch.script.ScriptType;

import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import static java.util.Arrays.asList;
import static java.util.Collections.unmodifiableList;
Expand All @@ -41,11 +37,12 @@
public class RestRenderSearchTemplateAction extends BaseRestHandler {

@Override
public Map<String, List<Method>> handledMethodsAndPaths() {
return Collections.unmodifiableMap(MapBuilder.<String, List<Method>>newMapBuilder()
.put("/_render/template", unmodifiableList(asList(GET, POST)))
.put("/_render/template/{id}", unmodifiableList(asList(GET, POST)))
.map());
public List<Route> handledRoutes() {
return unmodifiableList(asList(
new Route("/_render/template", GET),
new Route("/_render/template", POST),
new Route("/_render/template/{id}", GET),
new Route("/_render/template/{id}", POST)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@

import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.collect.MapBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.RestRequest.Method;
import org.elasticsearch.rest.action.RestStatusToXContentListener;
import org.elasticsearch.rest.action.search.RestSearchAction;

Expand All @@ -34,7 +32,6 @@
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import static java.util.Arrays.asList;
Expand All @@ -52,11 +49,12 @@ public class RestSearchTemplateAction extends BaseRestHandler {
}

@Override
public Map<String, List<Method>> handledMethodsAndPaths() {
return Collections.unmodifiableMap(MapBuilder.<String, List<Method>>newMapBuilder()
.put("/_search/template", unmodifiableList(asList(GET, POST)))
.put("/{index}/_search/template", unmodifiableList(asList(GET, POST)))
.map());
public List<Route> handledRoutes() {
return unmodifiableList(asList(
new Route("/_search/template", GET),
new Route("/_search/template", POST),
new Route("/{index}/_search/template", GET),
new Route("/{index}/_search/template", POST)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.elasticsearch.painless.lookup.PainlessLookup;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.RestRequest.Method;
import org.elasticsearch.rest.action.RestToXContentListener;
import org.elasticsearch.script.ScriptContext;
import org.elasticsearch.tasks.Task;
Expand All @@ -53,7 +52,6 @@
import java.util.stream.Collectors;

import static java.util.Collections.singletonList;
import static java.util.Collections.singletonMap;
import static org.elasticsearch.rest.RestRequest.Method.GET;

/**
Expand Down Expand Up @@ -197,8 +195,8 @@ protected void doExecute(Task task, Request request, ActionListener<Response> li
public static class RestAction extends BaseRestHandler {

@Override
public Map<String, List<Method>> handledMethodsAndPaths() {
return singletonMap("/_scripts/painless/_context", singletonList(GET));
public List<Route> handledRoutes() {
return singletonList(new Route("/_scripts/painless/_context", GET));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
import org.elasticsearch.indices.IndicesService;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.RestRequest.Method;
import org.elasticsearch.rest.action.RestToXContentListener;
import org.elasticsearch.script.FilterScript;
import org.elasticsearch.script.ScoreScript;
Expand All @@ -86,7 +85,6 @@
import java.util.Objects;

import static java.util.Arrays.asList;
import static java.util.Collections.singletonMap;
import static java.util.Collections.unmodifiableList;
import static org.elasticsearch.action.ValidateActions.addValidationError;
import static org.elasticsearch.rest.RestRequest.Method.GET;
Expand Down Expand Up @@ -569,8 +567,10 @@ private static Response prepareRamIndex(Request request,
public static class RestAction extends BaseRestHandler {

@Override
public Map<String, List<Method>> handledMethodsAndPaths() {
return singletonMap("/_scripts/painless/_execute", unmodifiableList(asList(GET, POST)));
public List<Route> handledRoutes() {
return unmodifiableList(asList(
new Route("/_scripts/painless/_execute", GET),
new Route("/_scripts/painless/_execute", POST)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,13 @@
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.collect.MapBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.RestRequest.Method;
import org.elasticsearch.rest.action.RestToXContentListener;

import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import static java.util.Arrays.asList;
import static java.util.Collections.unmodifiableList;
Expand Down Expand Up @@ -97,11 +93,12 @@ public class RestRankEvalAction extends BaseRestHandler {
public static String ENDPOINT = "_rank_eval";

@Override
public Map<String, List<Method>> handledMethodsAndPaths() {
return Collections.unmodifiableMap(MapBuilder.<String, List<Method>>newMapBuilder()
.put("/" + ENDPOINT, unmodifiableList(asList(GET, POST)))
.put("/{index}/" + ENDPOINT, unmodifiableList(asList(GET, POST)))
.map());
public List<Route> handledRoutes() {
return unmodifiableList(asList(
new Route("/" + ENDPOINT, GET),
new Route("/" + ENDPOINT, POST),
new Route("/{index}/" + ENDPOINT, GET),
new Route("/{index}/" + ENDPOINT, POST)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.RestRequest.Method;

import java.io.IOException;
import java.util.HashMap;
Expand All @@ -30,7 +29,6 @@
import java.util.function.Consumer;

import static java.util.Collections.singletonList;
import static java.util.Collections.singletonMap;
import static org.elasticsearch.rest.RestRequest.Method.POST;

public class RestDeleteByQueryAction extends AbstractBulkByQueryRestHandler<DeleteByQueryRequest, DeleteByQueryAction> {
Expand All @@ -40,8 +38,8 @@ public RestDeleteByQueryAction() {
}

@Override
public Map<String, List<Method>> handledMethodsAndPaths() {
return singletonMap("/{index}/_delete_by_query", singletonList(POST));
public List<Route> handledRoutes() {
return singletonList(new Route("/{index}/_delete_by_query", POST));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,11 @@
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.RestRequest.Method;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import static java.util.Collections.singletonList;
import static java.util.Collections.singletonMap;
import static org.elasticsearch.common.unit.TimeValue.parseTimeValue;
import static org.elasticsearch.rest.RestRequest.Method.POST;

Expand All @@ -43,8 +40,8 @@ public RestReindexAction() {
}

@Override
public Map<String, List<Method>> handledMethodsAndPaths() {
return singletonMap("/_reindex", singletonList(POST));
public List<Route> handledRoutes() {
return singletonList(new Route("/_reindex", POST));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,15 @@

import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.cluster.node.DiscoveryNodes;
import org.elasticsearch.common.collect.MapBuilder;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.RestRequest.Method;
import org.elasticsearch.tasks.TaskId;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.Supplier;

import static java.util.Collections.singletonList;
import static java.util.Arrays.asList;
import static java.util.Collections.unmodifiableList;
import static org.elasticsearch.rest.RestRequest.Method.POST;
import static org.elasticsearch.rest.action.admin.cluster.RestListTasksAction.listTasksResponseListener;

Expand All @@ -44,12 +41,11 @@ public RestRethrottleAction(Supplier<DiscoveryNodes> nodesInCluster) {
}

@Override
public Map<String, List<Method>> handledMethodsAndPaths() {
return Collections.unmodifiableMap(MapBuilder.<String, List<Method>>newMapBuilder()
.put("/_update_by_query/{taskId}/_rethrottle", singletonList(POST))
.put("/_delete_by_query/{taskId}/_rethrottle", singletonList(POST))
.put("/_reindex/{taskId}/_rethrottle", singletonList(POST))
.map());
public List<Route> handledRoutes() {
return unmodifiableList(asList(
new Route("/_update_by_query/{taskId}/_rethrottle", POST),
new Route("/_delete_by_query/{taskId}/_rethrottle", POST),
new Route("/_reindex/{taskId}/_rethrottle", POST)));
}

@Override
Expand Down
Loading

0 comments on commit 171e368

Please sign in to comment.