|
@@ -0,0 +1,113 @@
|
|
|
+/*
|
|
|
+ * Licensed to Elasticsearch 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.protocol.xpack.ml;
|
|
|
+
|
|
|
+import org.elasticsearch.action.ActionRequest;
|
|
|
+import org.elasticsearch.action.ActionRequestValidationException;
|
|
|
+import org.elasticsearch.common.ParseField;
|
|
|
+import org.elasticsearch.common.Strings;
|
|
|
+import org.elasticsearch.common.unit.TimeValue;
|
|
|
+import org.elasticsearch.common.xcontent.ConstructingObjectParser;
|
|
|
+import org.elasticsearch.common.xcontent.ToXContent;
|
|
|
+import org.elasticsearch.common.xcontent.ToXContentObject;
|
|
|
+import org.elasticsearch.common.xcontent.XContentBuilder;
|
|
|
+import org.elasticsearch.common.xcontent.XContentParser;
|
|
|
+import org.elasticsearch.protocol.xpack.ml.job.config.Job;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.Objects;
|
|
|
+
|
|
|
+public class OpenJobRequest extends ActionRequest implements ToXContentObject {
|
|
|
+
|
|
|
+ public static final ParseField TIMEOUT = new ParseField("timeout");
|
|
|
+ public static final ConstructingObjectParser<OpenJobRequest, Void> PARSER = new ConstructingObjectParser<>(
|
|
|
+ "open_job_request", true, a -> new OpenJobRequest((String) a[0]));
|
|
|
+
|
|
|
+ static {
|
|
|
+ PARSER.declareString(ConstructingObjectParser.constructorArg(), Job.ID);
|
|
|
+ PARSER.declareString((request, val) -> request.setTimeout(TimeValue.parseTimeValue(val, TIMEOUT.getPreferredName())), TIMEOUT);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static OpenJobRequest fromXContent(XContentParser parser) throws IOException {
|
|
|
+ return PARSER.parse(parser, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ private String jobId;
|
|
|
+ private TimeValue timeout;
|
|
|
+
|
|
|
+ public OpenJobRequest(String jobId) {
|
|
|
+ this.jobId = Objects.requireNonNull(jobId, "[job_id] must not be null");
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getJobId() {
|
|
|
+ return jobId;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setJobId(String jobId) {
|
|
|
+ this.jobId = Objects.requireNonNull(jobId, "[job_id] must not be null");
|
|
|
+ }
|
|
|
+
|
|
|
+ public TimeValue getTimeout() {
|
|
|
+ return timeout;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setTimeout(TimeValue timeout) {
|
|
|
+ this.timeout = timeout;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ActionRequestValidationException validate() {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException {
|
|
|
+ builder.startObject();
|
|
|
+ builder.field(Job.ID.getPreferredName(), jobId);
|
|
|
+ if (timeout != null) {
|
|
|
+ builder.field(TIMEOUT.getPreferredName(), timeout.getStringRep());
|
|
|
+ }
|
|
|
+ builder.endObject();
|
|
|
+ return builder;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String toString() {
|
|
|
+ return Strings.toString(this);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int hashCode() {
|
|
|
+ return Objects.hash(jobId, timeout);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean equals(Object other) {
|
|
|
+ if (this == other) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (other == null || getClass() != other.getClass()) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ OpenJobRequest that = (OpenJobRequest) other;
|
|
|
+ return Objects.equals(jobId, that.jobId) && Objects.equals(timeout, that.timeout);
|
|
|
+ }
|
|
|
+}
|