// Path: src/main/java/org/elasticsearch/action/trainmodel/TrainModelRequestBuilder.java
// public class TrainModelRequestBuilder extends ActionRequestBuilder<TrainModelRequest, TrainModelResponse,
//         TrainModelRequestBuilder> {
// 
//     public TrainModelRequestBuilder(ElasticsearchClient client) {
//         super(client, TrainModelAction.INSTANCE, new TrainModelRequest());
//     }
// 
//     public TrainModelRequestBuilder source(BytesReference source) throws IOException {
//         request.source(source);
//         return this;
//     }
// 
//     @Override
//     public void execute(ActionListener<TrainModelResponse> listener) {
//         client.execute(TrainModelAction.INSTANCE, request, listener);
//     }
// 
//     public TrainModelRequestBuilder setModelId(String id) {
//         request.setModelId(id);
//         return this;
//     }
// 
//     public TrainModelRequestBuilder setModelType(String modelType) {
//         request.setModelType(modelType);
//         return this;
//     }
// 
//     public TrainModelRequestBuilder addFields(ModelInputField ... inputFields) {
//         List<ModelInputField> newFields = new ArrayList<>();
//         if (request.getFields() == null) {
//             newFields.addAll(request.getFields());
//         }
//         for (ModelInputField modelInputField : inputFields) {
//             newFields.add(modelInputField);
//         }
//         request.setFields(Collections.unmodifiableList(newFields));
//         return this;
//     }
// 
//     public TrainModelRequestBuilder addFields(String ... inputFields) {
//         List<ModelInputField> newFields = new ArrayList<>();
//         if (request.getFields() == null) {
//             newFields.addAll(request.getFields());
//         }
//         for (String modelInputField : inputFields) {
//             newFields.add(new ModelInputField(modelInputField));
//         }
//         request.setFields(Collections.unmodifiableList(newFields));
//         return this;
//     }
// 
//     public TrainModelRequestBuilder setTargetField(ModelTargetField targetField) {
//         request.setTargetField(targetField);
//         return this;
//     }
// 
//     public TrainModelRequestBuilder setTargetField(String targetField) {
//         request.setTargetField(new ModelTargetField(targetField));
//         return this;
//     }
// 
//     public TrainModelRequestBuilder setSettings(Settings settings) {
//         request.setModelSettings(settings);
//         return this;
//     }
// 
//     public TrainModelRequestBuilder setTrainingSet(DataSet dataSet) {
//         request.setTrainingSet(dataSet);
//         return this;
//     }
// 
//     public TrainModelRequestBuilder setTestingSet(DataSet dataSet) {
//         request.setTestingSet(dataSet);
//         return this;
//     }
// 
// }
// 
// Path: src/main/java/org/elasticsearch/action/trainmodel/TrainModelResponse.java
// public class TrainModelResponse extends ActionResponse implements ToXContent {
// 
//     @Nullable
//     private String id;
// 
//     @Nullable
//     private String model;
// 
//     public TrainModelResponse() {
// 
//     }
// 
//     public String getId() {
//         return id;
//     }
// 
// 
//     public String getModel() {
//         return model;
//     }
// 
//     public void setId(String id) {
//         this.id = id;
//     }
// 
//     public void setModel(String model) {
//         this.model = model;
//     }
// 
//     @Override
//     public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
//         if (id != null) {
//             builder.field("id", id);
//         }
//         if (model != null) {
//             builder.field("model", model);
//         }
//         return builder;
//     }
// 
//     @Override
//     public void readFrom(StreamInput in) throws IOException {
//         super.readFrom(in);
//         id = in.readOptionalString();
//         model = in.readOptionalString();
//     }
// 
//     @Override
//     public void writeTo(StreamOutput out) throws IOException {
//         super.writeTo(out);
//         out.writeOptionalString(id);
//         out.writeOptionalString(model);
//     }
// }


import org.elasticsearch.rest.RestResponse;
import org.elasticsearch.rest.action.RestBuilderListener;
import java.io.IOException;
import static org.elasticsearch.rest.RestRequest.Method.POST;
import static org.elasticsearch.rest.RestStatus.OK;
import org.elasticsearch.action.trainmodel.TrainModelRequestBuilder;
import org.elasticsearch.action.trainmodel.TrainModelResponse;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.BytesRestResponse;
import org.elasticsearch.rest.RestChannel;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;
/*
 * 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.rest.action.trainmodel;




/**
 *
 */
public class RestTrainModelAction extends BaseRestHandler {

    @Inject
    public RestTrainModelAction(Settings settings, RestController controller) {
        super(settings);
        controller.registerHandler(POST, "_train_model", this);
    }

    @Override
    protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
// Path: src/main/java/org/elasticsearch/action/trainmodel/TrainModelRequestBuilder.java
// public class TrainModelRequestBuilder extends ActionRequestBuilder<TrainModelRequest, TrainModelResponse,
//         TrainModelRequestBuilder> {
// 
//     public TrainModelRequestBuilder(ElasticsearchClient client) {
//         super(client, TrainModelAction.INSTANCE, new TrainModelRequest());
//     }
// 
//     public TrainModelRequestBuilder source(BytesReference source) throws IOException {
//         request.source(source);
//         return this;
//     }
// 
//     @Override
//     public void execute(ActionListener<TrainModelResponse> listener) {
//         client.execute(TrainModelAction.INSTANCE, request, listener);
//     }
// 
//     public TrainModelRequestBuilder setModelId(String id) {
//         request.setModelId(id);
//         return this;
//     }
// 
//     public TrainModelRequestBuilder setModelType(String modelType) {
//         request.setModelType(modelType);
//         return this;
//     }
// 
//     public TrainModelRequestBuilder addFields(ModelInputField ... inputFields) {
//         List<ModelInputField> newFields = new ArrayList<>();
//         if (request.getFields() == null) {
//             newFields.addAll(request.getFields());
//         }
//         for (ModelInputField modelInputField : inputFields) {
//             newFields.add(modelInputField);
//         }
//         request.setFields(Collections.unmodifiableList(newFields));
//         return this;
//     }
// 
//     public TrainModelRequestBuilder addFields(String ... inputFields) {
//         List<ModelInputField> newFields = new ArrayList<>();
//         if (request.getFields() == null) {
//             newFields.addAll(request.getFields());
//         }
//         for (String modelInputField : inputFields) {
//             newFields.add(new ModelInputField(modelInputField));
//         }
//         request.setFields(Collections.unmodifiableList(newFields));
//         return this;
//     }
// 
//     public TrainModelRequestBuilder setTargetField(ModelTargetField targetField) {
//         request.setTargetField(targetField);
//         return this;
//     }
// 
//     public TrainModelRequestBuilder setTargetField(String targetField) {
//         request.setTargetField(new ModelTargetField(targetField));
//         return this;
//     }
// 
//     public TrainModelRequestBuilder setSettings(Settings settings) {
//         request.setModelSettings(settings);
//         return this;
//     }
// 
//     public TrainModelRequestBuilder setTrainingSet(DataSet dataSet) {
//         request.setTrainingSet(dataSet);
//         return this;
//     }
// 
//     public TrainModelRequestBuilder setTestingSet(DataSet dataSet) {
//         request.setTestingSet(dataSet);
//         return this;
//     }
// 
// }
// 
// Path: src/main/java/org/elasticsearch/action/trainmodel/TrainModelResponse.java
// public class TrainModelResponse extends ActionResponse implements ToXContent {
// 
//     @Nullable
//     private String id;
// 
//     @Nullable
//     private String model;
// 
//     public TrainModelResponse() {
// 
//     }
// 
//     public String getId() {
//         return id;
//     }
// 
// 
//     public String getModel() {
//         return model;
//     }
// 
//     public void setId(String id) {
//         this.id = id;
//     }
// 
//     public void setModel(String model) {
//         this.model = model;
//     }
// 
//     @Override
//     public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
//         if (id != null) {
//             builder.field("id", id);
//         }
//         if (model != null) {
//             builder.field("model", model);
//         }
//         return builder;
//     }
// 
//     @Override
//     public void readFrom(StreamInput in) throws IOException {
//         super.readFrom(in);
//         id = in.readOptionalString();
//         model = in.readOptionalString();
//     }
// 
//     @Override
//     public void writeTo(StreamOutput out) throws IOException {
//         super.writeTo(out);
//         out.writeOptionalString(id);
//         out.writeOptionalString(model);
//     }
// }


// Path: src/main/java/org/elasticsearch/rest/action/trainmodel/RestTrainModelAction.java
import org.elasticsearch.rest.RestResponse;
import org.elasticsearch.rest.action.RestBuilderListener;
import java.io.IOException;
import static org.elasticsearch.rest.RestRequest.Method.POST;
import static org.elasticsearch.rest.RestStatus.OK;
import org.elasticsearch.action.trainmodel.TrainModelRequestBuilder;
import org.elasticsearch.action.trainmodel.TrainModelResponse;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.BytesRestResponse;
import org.elasticsearch.rest.RestChannel;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;

/*
 * 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.rest.action.trainmodel;




/**
 *
 */
public class RestTrainModelAction extends BaseRestHandler {

    @Inject
    public RestTrainModelAction(Settings settings, RestController controller) {
        super(settings);
        controller.registerHandler(POST, "_train_model", this);
    }

    @Override
    protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
        TrainModelRequestBuilder trainModelRequestBuilder = new TrainModelRequestBuilder(client);