|
@@ -11,8 +11,10 @@ import org.elasticsearch.action.ActionRequest;
|
|
|
import org.elasticsearch.action.ActionRequestValidationException;
|
|
|
import org.elasticsearch.action.ActionResponse;
|
|
|
import org.elasticsearch.action.ActionType;
|
|
|
+import org.elasticsearch.cluster.metadata.MetadataCreateIndexService;
|
|
|
import org.elasticsearch.common.io.stream.StreamInput;
|
|
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
|
|
+import org.elasticsearch.indices.InvalidIndexNameException;
|
|
|
import org.elasticsearch.xcontent.ConstructingObjectParser;
|
|
|
import org.elasticsearch.xcontent.ParseField;
|
|
|
import org.elasticsearch.xcontent.ToXContentObject;
|
|
@@ -26,7 +28,9 @@ import java.io.IOException;
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
|
|
|
+import static org.elasticsearch.action.ValidateActions.addValidationError;
|
|
|
import static org.elasticsearch.xcontent.ConstructingObjectParser.constructorArg;
|
|
|
+import static org.elasticsearch.xcontent.ConstructingObjectParser.optionalConstructorArg;
|
|
|
|
|
|
public class ListConnectorAction {
|
|
|
|
|
@@ -38,54 +42,88 @@ public class ListConnectorAction {
|
|
|
public static class Request extends ActionRequest implements ToXContentObject {
|
|
|
|
|
|
private final PageParams pageParams;
|
|
|
+ private final List<String> indexNames;
|
|
|
+ private final List<String> connectorNames;
|
|
|
|
|
|
private static final ParseField PAGE_PARAMS_FIELD = new ParseField("pageParams");
|
|
|
+ private static final ParseField INDEX_NAMES_FIELD = new ParseField("index_names");
|
|
|
+ private static final ParseField NAMES_FIELD = new ParseField("names");
|
|
|
|
|
|
public Request(StreamInput in) throws IOException {
|
|
|
super(in);
|
|
|
this.pageParams = new PageParams(in);
|
|
|
+ this.indexNames = in.readOptionalStringCollectionAsList();
|
|
|
+ this.connectorNames = in.readOptionalStringCollectionAsList();
|
|
|
}
|
|
|
|
|
|
- public Request(PageParams pageParams) {
|
|
|
+ public Request(PageParams pageParams, List<String> indexNames, List<String> connectorNames) {
|
|
|
this.pageParams = pageParams;
|
|
|
+ this.indexNames = indexNames;
|
|
|
+ this.connectorNames = connectorNames;
|
|
|
}
|
|
|
|
|
|
public PageParams getPageParams() {
|
|
|
return pageParams;
|
|
|
}
|
|
|
|
|
|
+ public List<String> getIndexNames() {
|
|
|
+ return indexNames;
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<String> getConnectorNames() {
|
|
|
+ return connectorNames;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public ActionRequestValidationException validate() {
|
|
|
+ ActionRequestValidationException validationException = null;
|
|
|
// Pagination validation is done as part of PageParams constructor
|
|
|
- return null;
|
|
|
+
|
|
|
+ if (indexNames != null && indexNames.isEmpty() == false) {
|
|
|
+ for (String indexName : indexNames) {
|
|
|
+ try {
|
|
|
+ MetadataCreateIndexService.validateIndexOrAliasName(indexName, InvalidIndexNameException::new);
|
|
|
+ } catch (InvalidIndexNameException e) {
|
|
|
+ validationException = addValidationError(e.toString(), validationException);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return validationException;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void writeTo(StreamOutput out) throws IOException {
|
|
|
super.writeTo(out);
|
|
|
pageParams.writeTo(out);
|
|
|
+ out.writeOptionalStringCollection(indexNames);
|
|
|
+ out.writeOptionalStringCollection(connectorNames);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public boolean equals(Object o) {
|
|
|
if (this == o) return true;
|
|
|
if (o == null || getClass() != o.getClass()) return false;
|
|
|
- ListConnectorAction.Request that = (ListConnectorAction.Request) o;
|
|
|
- return Objects.equals(pageParams, that.pageParams);
|
|
|
+ ListConnectorAction.Request request = (ListConnectorAction.Request) o;
|
|
|
+ return Objects.equals(pageParams, request.pageParams)
|
|
|
+ && Objects.equals(indexNames, request.indexNames)
|
|
|
+ && Objects.equals(connectorNames, request.connectorNames);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public int hashCode() {
|
|
|
- return Objects.hash(pageParams);
|
|
|
+ return Objects.hash(pageParams, indexNames, connectorNames);
|
|
|
}
|
|
|
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
private static final ConstructingObjectParser<ListConnectorAction.Request, String> PARSER = new ConstructingObjectParser<>(
|
|
|
"list_connector_request",
|
|
|
- p -> new ListConnectorAction.Request((PageParams) p[0])
|
|
|
+ p -> new ListConnectorAction.Request((PageParams) p[0], (List<String>) p[1], (List<String>) p[2])
|
|
|
);
|
|
|
|
|
|
static {
|
|
|
PARSER.declareObject(constructorArg(), (p, c) -> PageParams.fromXContent(p), PAGE_PARAMS_FIELD);
|
|
|
+ PARSER.declareStringArray(optionalConstructorArg(), INDEX_NAMES_FIELD);
|
|
|
+ PARSER.declareStringArray(optionalConstructorArg(), NAMES_FIELD);
|
|
|
}
|
|
|
|
|
|
public static ListConnectorAction.Request parse(XContentParser parser) {
|
|
@@ -95,7 +133,11 @@ public class ListConnectorAction {
|
|
|
@Override
|
|
|
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
|
|
builder.startObject();
|
|
|
- builder.field(PAGE_PARAMS_FIELD.getPreferredName(), pageParams);
|
|
|
+ {
|
|
|
+ builder.field(PAGE_PARAMS_FIELD.getPreferredName(), pageParams);
|
|
|
+ builder.field(INDEX_NAMES_FIELD.getPreferredName(), indexNames);
|
|
|
+ builder.field(NAMES_FIELD.getPreferredName(), connectorNames);
|
|
|
+ }
|
|
|
builder.endObject();
|
|
|
return builder;
|
|
|
}
|