Skip to content

Commit 05253e6

Browse files
committed
HLRC: request/response homogeneity and JavaDoc improvements (#33133)
1 parent b149864 commit 05253e6

File tree

9 files changed

+89
-49
lines changed

9 files changed

+89
-49
lines changed

x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/ml/CloseJobRequest.java

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
import java.util.List;
3636
import java.util.Objects;
3737

38+
/**
39+
* Request to close Machine Learning Jobs
40+
*/
3841
public class CloseJobRequest extends ActionRequest implements ToXContentObject {
3942

4043
public static final ParseField JOB_ID = new ParseField("job_id");
@@ -98,49 +101,44 @@ public List<String> getJobIds() {
98101
return jobIds;
99102
}
100103

101-
/**
102-
* How long to wait for the close request to complete before timing out.
103-
*
104-
* Default: 30 minutes
105-
*/
106104
public TimeValue getTimeout() {
107105
return timeout;
108106
}
109107

110108
/**
111-
* {@link CloseJobRequest#getTimeout()}
109+
* How long to wait for the close request to complete before timing out.
110+
*
111+
* @param timeout Default value: 30 minutes
112112
*/
113113
public void setTimeout(TimeValue timeout) {
114114
this.timeout = timeout;
115115
}
116116

117-
/**
118-
* Should the closing be forced.
119-
*
120-
* Use to close a failed job, or to forcefully close a job which has not responded to its initial close request.
121-
*/
122117
public Boolean isForce() {
123118
return force;
124119
}
125120

126121
/**
127-
* {@link CloseJobRequest#isForce()}
122+
* Should the closing be forced.
123+
*
124+
* Use to close a failed job, or to forcefully close a job which has not responded to its initial close request.
125+
*
126+
* @param force When {@code true} forcefully close the job. Defaults to {@code false}
128127
*/
129128
public void setForce(boolean force) {
130129
this.force = force;
131130
}
132131

133-
/**
134-
* Whether to ignore if a wildcard expression matches no jobs.
135-
*
136-
* This includes `_all` string or when no jobs have been specified
137-
*/
138132
public Boolean isAllowNoJobs() {
139133
return this.allowNoJobs;
140134
}
141135

142136
/**
143-
* {@link CloseJobRequest#isAllowNoJobs()}
137+
* Whether to ignore if a wildcard expression matches no jobs.
138+
*
139+
* This includes `_all` string or when no jobs have been specified
140+
*
141+
* @param allowNoJobs When {@code true} ignore if wildcard or `_all` matches no jobs. Defaults to {@code true}
144142
*/
145143
public void setAllowNoJobs(boolean allowNoJobs) {
146144
this.allowNoJobs = allowNoJobs;

x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/ml/CloseJobResponse.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,30 @@
2020

2121
import org.elasticsearch.action.ActionResponse;
2222
import org.elasticsearch.common.ParseField;
23-
import org.elasticsearch.common.xcontent.ObjectParser;
23+
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
2424
import org.elasticsearch.common.xcontent.ToXContentObject;
2525
import org.elasticsearch.common.xcontent.XContentBuilder;
2626
import org.elasticsearch.common.xcontent.XContentParser;
2727

2828
import java.io.IOException;
2929
import java.util.Objects;
3030

31+
/**
32+
* Response indicating if the Job(s) closed or not
33+
*/
3134
public class CloseJobResponse extends ActionResponse implements ToXContentObject {
3235

3336
private static final ParseField CLOSED = new ParseField("closed");
3437

35-
public static final ObjectParser<CloseJobResponse, Void> PARSER =
36-
new ObjectParser<>("close_job_response", true, CloseJobResponse::new);
38+
public static final ConstructingObjectParser<CloseJobResponse, Void> PARSER =
39+
new ConstructingObjectParser<>("close_job_response", true, (a) -> new CloseJobResponse((Boolean)a[0]));
3740

3841
static {
39-
PARSER.declareBoolean(CloseJobResponse::setClosed, CLOSED);
42+
PARSER.declareBoolean(ConstructingObjectParser.constructorArg(), CLOSED);
4043
}
4144

4245
private boolean closed;
4346

44-
CloseJobResponse() {
45-
}
46-
4747
public CloseJobResponse(boolean closed) {
4848
this.closed = closed;
4949
}
@@ -52,14 +52,14 @@ public static CloseJobResponse fromXContent(XContentParser parser) throws IOExce
5252
return PARSER.parse(parser, null);
5353
}
5454

55+
/**
56+
* Has the job closed or not
57+
* @return boolean value indicating the job closed status
58+
*/
5559
public boolean isClosed() {
5660
return closed;
5761
}
5862

59-
public void setClosed(boolean closed) {
60-
this.closed = closed;
61-
}
62-
6363
@Override
6464
public boolean equals(Object other) {
6565
if (this == other) {

x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/ml/DeleteJobRequest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323

2424
import java.util.Objects;
2525

26+
/**
27+
* Request to delete a Machine Learning Job via its ID
28+
*/
2629
public class DeleteJobRequest extends ActionRequest {
2730

2831
private String jobId;
@@ -36,6 +39,10 @@ public String getJobId() {
3639
return jobId;
3740
}
3841

42+
/**
43+
* The jobId which to delete
44+
* @param jobId unique jobId to delete, must not be null
45+
*/
3946
public void setJobId(String jobId) {
4047
this.jobId = Objects.requireNonNull(jobId, "[job_id] must not be null");
4148
}
@@ -44,6 +51,12 @@ public boolean isForce() {
4451
return force;
4552
}
4653

54+
/**
55+
* Used to forcefully delete an opened job.
56+
* This method is quicker than closing and deleting the job.
57+
*
58+
* @param force When {@code true} forcefully delete an opened job. Defaults to {@code false}
59+
*/
4760
public void setForce(boolean force) {
4861
this.force = force;
4962
}

x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/ml/DeleteJobResponse.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
import java.io.IOException;
2525
import java.util.Objects;
2626

27+
/**
28+
* Response acknowledging the Machine Learning Job request
29+
*/
2730
public class DeleteJobResponse extends AcknowledgedResponse {
2831

2932
public DeleteJobResponse(boolean acknowledged) {

x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/ml/GetJobRequest.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,20 +87,15 @@ public List<String> getJobIds() {
8787
return jobIds;
8888
}
8989

90-
9190
/**
92-
* See {@link GetJobRequest#isAllowNoJobs()}
93-
* @param allowNoJobs
91+
* Whether to ignore if a wildcard expression matches no jobs.
92+
*
93+
* @param allowNoJobs If this is {@code false}, then an error is returned when a wildcard (or `_all`) does not match any jobs
9494
*/
9595
public void setAllowNoJobs(boolean allowNoJobs) {
9696
this.allowNoJobs = allowNoJobs;
9797
}
9898

99-
/**
100-
* Whether to ignore if a wildcard expression matches no jobs.
101-
*
102-
* If this is `false`, then an error is returned when a wildcard (or `_all`) does not match any jobs
103-
*/
10499
public Boolean isAllowNoJobs() {
105100
return allowNoJobs;
106101
}

x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/ml/OpenJobRequest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
import java.io.IOException;
3434
import java.util.Objects;
3535

36+
/**
37+
* Request to open a Machine Learning Job
38+
*/
3639
public class OpenJobRequest extends ActionRequest implements ToXContentObject {
3740

3841
public static final ParseField TIMEOUT = new ParseField("timeout");
@@ -51,6 +54,11 @@ public static OpenJobRequest fromXContent(XContentParser parser) throws IOExcept
5154
private String jobId;
5255
private TimeValue timeout;
5356

57+
/**
58+
* Create a new request with the desired jobId
59+
*
60+
* @param jobId unique jobId, must not be null
61+
*/
5462
public OpenJobRequest(String jobId) {
5563
this.jobId = Objects.requireNonNull(jobId, "[job_id] must not be null");
5664
}
@@ -59,6 +67,11 @@ public String getJobId() {
5967
return jobId;
6068
}
6169

70+
/**
71+
* The jobId to open
72+
*
73+
* @param jobId unique jobId, must not be null
74+
*/
6275
public void setJobId(String jobId) {
6376
this.jobId = Objects.requireNonNull(jobId, "[job_id] must not be null");
6477
}
@@ -67,6 +80,11 @@ public TimeValue getTimeout() {
6780
return timeout;
6881
}
6982

83+
/**
84+
* How long to wait for job to open before timing out the request
85+
*
86+
* @param timeout default value of 30 minutes
87+
*/
7088
public void setTimeout(TimeValue timeout) {
7189
this.timeout = timeout;
7290
}

x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/ml/OpenJobResponse.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,45 +20,47 @@
2020

2121
import org.elasticsearch.action.ActionResponse;
2222
import org.elasticsearch.common.ParseField;
23-
import org.elasticsearch.common.xcontent.ObjectParser;
23+
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
2424
import org.elasticsearch.common.xcontent.ToXContentObject;
2525
import org.elasticsearch.common.xcontent.XContentBuilder;
2626
import org.elasticsearch.common.xcontent.XContentParser;
2727

2828
import java.io.IOException;
2929
import java.util.Objects;
3030

31+
/**
32+
* Response indicating if the Machine Learning Job is now opened or not
33+
*/
3134
public class OpenJobResponse extends ActionResponse implements ToXContentObject {
3235

3336
private static final ParseField OPENED = new ParseField("opened");
3437

35-
public static final ObjectParser<OpenJobResponse, Void> PARSER = new ObjectParser<>("open_job_response", true, OpenJobResponse::new);
38+
public static final ConstructingObjectParser<OpenJobResponse, Void> PARSER =
39+
new ConstructingObjectParser<>("open_job_response", true, (a) -> new OpenJobResponse((Boolean)a[0]));
3640

3741
static {
38-
PARSER.declareBoolean(OpenJobResponse::setOpened, OPENED);
42+
PARSER.declareBoolean(ConstructingObjectParser.constructorArg(), OPENED);
3943
}
4044

4145
private boolean opened;
4246

43-
OpenJobResponse() {
44-
}
45-
46-
public OpenJobResponse(boolean opened) {
47+
OpenJobResponse(boolean opened) {
4748
this.opened = opened;
4849
}
4950

5051
public static OpenJobResponse fromXContent(XContentParser parser) throws IOException {
5152
return PARSER.parse(parser, null);
5253
}
5354

55+
/**
56+
* Has the job opened or not
57+
*
58+
* @return boolean value indicating the job opened status
59+
*/
5460
public boolean isOpened() {
5561
return opened;
5662
}
5763

58-
public void setOpened(boolean opened) {
59-
this.opened = opened;
60-
}
61-
6264
@Override
6365
public boolean equals(Object other) {
6466
if (this == other) {

x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/ml/PutJobRequest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,18 @@
2828
import java.io.IOException;
2929
import java.util.Objects;
3030

31+
/**
32+
* Request to create a new Machine Learning Job given a {@link Job} configuration
33+
*/
3134
public class PutJobRequest extends ActionRequest implements ToXContentObject {
3235

3336
private final Job job;
3437

38+
/**
39+
* Construct a new PutJobRequest
40+
*
41+
* @param job a {@link Job} configuration to create
42+
*/
3543
public PutJobRequest(Job job) {
3644
this.job = job;
3745
}

x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/ml/PutJobResponse.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
import java.io.IOException;
2828
import java.util.Objects;
2929

30+
/**
31+
* Response containing the newly created {@link Job}
32+
*/
3033
public class PutJobResponse implements ToXContentObject {
3134

3235
private Job job;
@@ -35,7 +38,7 @@ public static PutJobResponse fromXContent(XContentParser parser) throws IOExcept
3538
return new PutJobResponse(Job.PARSER.parse(parser, null).build());
3639
}
3740

38-
public PutJobResponse(Job job) {
41+
PutJobResponse(Job job) {
3942
this.job = job;
4043
}
4144

0 commit comments

Comments
 (0)