Skip to content

Commit

Permalink
[ML] Data Frame minor tidy ups (#40548)
Browse files Browse the repository at this point in the history
Remove Xlint-rawtypes option and remove unused request builders.
Not all requests need to implement ToXContent.
  • Loading branch information
davidkyle authored Mar 28, 2019
1 parent c03f2e6 commit 5b64c77
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 132 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@
package org.elasticsearch.xpack.core.dataframe.action;

import org.elasticsearch.action.Action;
import org.elasticsearch.action.ActionRequestBuilder;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.FailedNodeException;
import org.elasticsearch.action.TaskOperationFailure;
import org.elasticsearch.action.support.tasks.BaseTasksRequest;
import org.elasticsearch.action.support.tasks.BaseTasksResponse;
import org.elasticsearch.client.ElasticsearchClient;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.tasks.Task;
Expand All @@ -42,16 +39,13 @@ public Response newResponse() {
return new Response();
}

public static class Request extends BaseTasksRequest<Request> implements ToXContentFragment {
public static class Request extends BaseTasksRequest<Request> {
private String id;

public Request(String id) {
this.id = ExceptionsHelper.requireNonNull(id, DataFrameField.ID.getPreferredName());
}

private Request() {
}

public Request(StreamInput in) throws IOException {
super(in);
id = in.readString();
Expand All @@ -77,12 +71,6 @@ public ActionRequestValidationException validate() {
return null;
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.field(DataFrameField.ID.getPreferredName(), id);
return builder;
}

@Override
public int hashCode() {
return Objects.hash(id);
Expand All @@ -102,14 +90,6 @@ public boolean equals(Object obj) {
}
}

public static class RequestBuilder
extends ActionRequestBuilder<DeleteDataFrameTransformAction.Request, DeleteDataFrameTransformAction.Response> {

protected RequestBuilder(ElasticsearchClient client, DeleteDataFrameTransformAction action) {
super(client, action, new DeleteDataFrameTransformAction.Request());
}
}

public static class Response extends BaseTasksResponse implements Writeable, ToXContentObject {
private boolean acknowledged;
public Response(StreamInput in) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@

import org.apache.logging.log4j.LogManager;
import org.elasticsearch.action.Action;
import org.elasticsearch.action.ActionRequestBuilder;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.client.ElasticsearchClient;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.xpack.core.action.AbstractGetResourcesRequest;
Expand Down Expand Up @@ -48,7 +45,7 @@ public Response newResponse() {
return new Response();
}

public static class Request extends AbstractGetResourcesRequest implements ToXContent {
public static class Request extends AbstractGetResourcesRequest {

private static final int MAX_SIZE_RETURN = 1000;

Expand Down Expand Up @@ -78,25 +75,12 @@ public ActionRequestValidationException validate() {
return exception;
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.field(DataFrameField.ID.getPreferredName(), getResourceId());
return builder;
}

@Override
public String getResourceIdField() {
return DataFrameField.ID.getPreferredName();
}
}

public static class RequestBuilder extends ActionRequestBuilder<Request, Response> {

protected RequestBuilder(ElasticsearchClient client, GetDataFrameTransformsAction action) {
super(client, action, new Request());
}
}

public static class Response extends AbstractGetResourcesResponse<DataFrameTransformConfig> implements Writeable, ToXContentObject {

public static final String INVALID_TRANSFORMS_DEPRECATION_WARNING = "Found [{}] invalid transforms";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,16 @@
package org.elasticsearch.xpack.core.dataframe.action;

import org.elasticsearch.action.Action;
import org.elasticsearch.action.ActionRequestBuilder;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.FailedNodeException;
import org.elasticsearch.action.TaskOperationFailure;
import org.elasticsearch.action.support.tasks.BaseTasksRequest;
import org.elasticsearch.action.support.tasks.BaseTasksResponse;
import org.elasticsearch.client.ElasticsearchClient;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.tasks.Task;
Expand All @@ -44,7 +41,7 @@ public Response newResponse() {
return new Response();
}

public static class Request extends BaseTasksRequest<Request> implements ToXContent {
public static class Request extends BaseTasksRequest<Request> {
private String id;

public Request(String id) {
Expand All @@ -55,8 +52,6 @@ public Request(String id) {
}
}

private Request() {}

public Request(StreamInput in) throws IOException {
super(in);
id = in.readString();
Expand Down Expand Up @@ -87,12 +82,6 @@ public ActionRequestValidationException validate() {
return null;
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.field(DataFrameField.ID.getPreferredName(), id);
return builder;
}

@Override
public int hashCode() {
return Objects.hash(id);
Expand All @@ -111,13 +100,6 @@ public boolean equals(Object obj) {
}
}

public static class RequestBuilder extends ActionRequestBuilder<Request, Response> {

protected RequestBuilder(ElasticsearchClient client, GetDataFrameTransformsStatsAction action) {
super(client, action, new Request());
}
}

public static class Response extends BaseTasksResponse implements Writeable, ToXContentObject {
private List<DataFrameTransformStateAndStats> transformsStateAndStats;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.support.master.AcknowledgedRequest;
import org.elasticsearch.action.support.master.AcknowledgedResponse;
import org.elasticsearch.action.support.master.MasterNodeOperationRequestBuilder;
import org.elasticsearch.client.ElasticsearchClient;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.ToXContentObject;
Expand Down Expand Up @@ -100,13 +98,6 @@ public boolean equals(Object obj) {
}
}

public static class RequestBuilder extends MasterNodeOperationRequestBuilder<Request, Response, RequestBuilder> {

protected RequestBuilder(ElasticsearchClient client, PutDataFrameTransformAction action) {
super(client, action, new Request());
}
}

public static class Response extends AcknowledgedResponse {
public Response() {
super();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,12 @@
package org.elasticsearch.xpack.core.dataframe.action;

import org.elasticsearch.action.Action;
import org.elasticsearch.action.ActionRequestBuilder;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.support.master.AcknowledgedRequest;
import org.elasticsearch.action.support.tasks.BaseTasksResponse;
import org.elasticsearch.client.ElasticsearchClient;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.xpack.core.dataframe.DataFrameField;
Expand All @@ -39,7 +36,7 @@ public Response newResponse() {
return new Response();
}

public static class Request extends AcknowledgedRequest<Request> implements ToXContent {
public static class Request extends AcknowledgedRequest<Request> {

private String id;
private boolean force;
Expand Down Expand Up @@ -76,12 +73,6 @@ public ActionRequestValidationException validate() {
return null;
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.field(DataFrameField.ID.getPreferredName(), id);
return builder;
}

@Override
public int hashCode() {
return Objects.hash(id);
Expand All @@ -100,13 +91,6 @@ public boolean equals(Object obj) {
}
}

public static class RequestBuilder extends ActionRequestBuilder<Request, Response> {

protected RequestBuilder(ElasticsearchClient client, StartDataFrameTransformAction action) {
super(client, action, new Request());
}
}

public static class Response extends BaseTasksResponse implements Writeable, ToXContentObject {
private boolean started;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,12 @@
package org.elasticsearch.xpack.core.dataframe.action;

import org.elasticsearch.action.Action;
import org.elasticsearch.action.ActionRequestBuilder;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.support.tasks.BaseTasksRequest;
import org.elasticsearch.action.support.tasks.BaseTasksResponse;
import org.elasticsearch.client.ElasticsearchClient;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.xpack.core.dataframe.DataFrameField;
Expand All @@ -39,7 +36,7 @@ public Response newResponse() {
return new Response();
}

public static class Request extends BaseTasksRequest<Request> implements ToXContent {
public static class Request extends BaseTasksRequest<Request> {

private String id;

Expand Down Expand Up @@ -70,12 +67,6 @@ public ActionRequestValidationException validate() {
return null;
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.field(DataFrameField.ID.getPreferredName(), id);
return builder;
}

@Override
public int hashCode() {
return Objects.hash(id);
Expand All @@ -94,13 +85,6 @@ public boolean equals(Object obj) {
}
}

public static class RequestBuilder extends ActionRequestBuilder<Request, Response> {

protected RequestBuilder(ElasticsearchClient client, StartDataFrameTransformTaskAction action) {
super(client, action, new Request());
}
}

public static class Response extends BaseTasksResponse implements Writeable, ToXContentObject {
private boolean started;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@
package org.elasticsearch.xpack.core.dataframe.action;

import org.elasticsearch.action.Action;
import org.elasticsearch.action.ActionRequestBuilder;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.support.tasks.BaseTasksRequest;
import org.elasticsearch.action.support.tasks.BaseTasksResponse;
import org.elasticsearch.client.ElasticsearchClient;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.tasks.Task;
Expand Down Expand Up @@ -44,7 +41,7 @@ public Response newResponse() {
return new Response();
}

public static class Request extends BaseTasksRequest<Request> implements ToXContent {
public static class Request extends BaseTasksRequest<Request> {
private String id;
private final boolean waitForCompletion;
private final boolean force;
Expand Down Expand Up @@ -98,17 +95,6 @@ public ActionRequestValidationException validate() {
return null;
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.field(DataFrameField.ID.getPreferredName(), id);
builder.field(DataFrameField.WAIT_FOR_COMPLETION.getPreferredName(), waitForCompletion);
builder.field(DataFrameField.FORCE.getPreferredName(), force);
if (this.getTimeout() != null) {
builder.field(DataFrameField.TIMEOUT.getPreferredName(), this.getTimeout());
}
return builder;
}

@Override
public int hashCode() {
// the base class does not implement hashCode, therefore we need to hash timeout ourselves
Expand Down Expand Up @@ -144,13 +130,6 @@ public boolean match(Task task) {
}
}

public static class RequestBuilder extends ActionRequestBuilder<Request, Response> {

protected RequestBuilder(ElasticsearchClient client, StopDataFrameTransformAction action) {
super(client, action, new Request());
}
}

public static class Response extends BaseTasksResponse implements Writeable, ToXContentObject {

private boolean stopped;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

package org.elasticsearch.xpack.core.dataframe.action;

import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.test.AbstractWireSerializingTestCase;

public class StartDataFrameTransformTaskActionRequestTests extends
AbstractWireSerializingTestCase<StartDataFrameTransformTaskAction.Request> {
@Override
protected StartDataFrameTransformTaskAction.Request createTestInstance() {
return new StartDataFrameTransformTaskAction.Request(randomAlphaOfLength(4));
}

@Override
protected Writeable.Reader<StartDataFrameTransformTaskAction.Request> instanceReader() {
return StartDataFrameTransformTaskAction.Request::new;
}
}
Loading

0 comments on commit 5b64c77

Please sign in to comment.