Skip to content

Commit 21a25d6

Browse files
HLRC XPack Protocol clean up: Licence, Misc (#34469)
Relates #34451 (cherry picked from commit 423d085)
1 parent cbfa396 commit 21a25d6

28 files changed

+172
-548
lines changed

client/rest-high-level/src/main/java/org/elasticsearch/client/LicenseClient.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@
3434
import org.elasticsearch.common.xcontent.XContentFactory;
3535
import org.elasticsearch.common.xcontent.XContentParser;
3636
import org.elasticsearch.common.xcontent.XContentType;
37-
import org.elasticsearch.protocol.xpack.license.DeleteLicenseRequest;
38-
import org.elasticsearch.protocol.xpack.license.GetLicenseRequest;
39-
import org.elasticsearch.protocol.xpack.license.GetLicenseResponse;
40-
import org.elasticsearch.protocol.xpack.license.PutLicenseRequest;
41-
import org.elasticsearch.protocol.xpack.license.PutLicenseResponse;
37+
import org.elasticsearch.client.license.DeleteLicenseRequest;
38+
import org.elasticsearch.client.license.GetLicenseRequest;
39+
import org.elasticsearch.client.license.GetLicenseResponse;
40+
import org.elasticsearch.client.license.PutLicenseRequest;
41+
import org.elasticsearch.client.license.PutLicenseResponse;
4242

4343
import java.io.IOException;
4444
import java.io.InputStream;

client/rest-high-level/src/main/java/org/elasticsearch/client/LicenseRequestConverters.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
import org.apache.http.client.methods.HttpPut;
2626
import org.elasticsearch.client.license.StartTrialRequest;
2727
import org.elasticsearch.client.license.StartBasicRequest;
28-
import org.elasticsearch.protocol.xpack.license.DeleteLicenseRequest;
29-
import org.elasticsearch.protocol.xpack.license.GetLicenseRequest;
30-
import org.elasticsearch.protocol.xpack.license.PutLicenseRequest;
28+
import org.elasticsearch.client.license.DeleteLicenseRequest;
29+
import org.elasticsearch.client.license.GetLicenseRequest;
30+
import org.elasticsearch.client.license.PutLicenseRequest;
3131

3232
public class LicenseRequestConverters {
3333
static Request putLicense(PutLicenseRequest putLicenseRequest) {
@@ -47,7 +47,7 @@ static Request getLicense(GetLicenseRequest getLicenseRequest) {
4747
String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_xpack", "license").build();
4848
Request request = new Request(HttpGet.METHOD_NAME, endpoint);
4949
RequestConverters.Params parameters = new RequestConverters.Params(request);
50-
parameters.withLocal(getLicenseRequest.local());
50+
parameters.withLocal(getLicenseRequest.isLocal());
5151
return request;
5252
}
5353

client/rest-high-level/src/main/java/org/elasticsearch/client/XPackClient.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
package org.elasticsearch.client;
2121

2222
import org.elasticsearch.action.ActionListener;
23-
import org.elasticsearch.protocol.xpack.XPackInfoRequest;
24-
import org.elasticsearch.protocol.xpack.XPackInfoResponse;
25-
import org.elasticsearch.protocol.xpack.XPackUsageRequest;
26-
import org.elasticsearch.protocol.xpack.XPackUsageResponse;
23+
import org.elasticsearch.client.xpack.XPackInfoRequest;
24+
import org.elasticsearch.client.xpack.XPackInfoResponse;
25+
import org.elasticsearch.client.xpack.XPackUsageRequest;
26+
import org.elasticsearch.client.xpack.XPackUsageResponse;
2727

2828
import java.io.IOException;
2929

client/rest-high-level/src/main/java/org/elasticsearch/client/XPackRequestConverters.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
package org.elasticsearch.client;
2121

2222
import org.apache.http.client.methods.HttpGet;
23-
import org.elasticsearch.protocol.xpack.XPackInfoRequest;
24-
import org.elasticsearch.protocol.xpack.XPackUsageRequest;
23+
import org.elasticsearch.client.xpack.XPackInfoRequest;
24+
import org.elasticsearch.client.xpack.XPackUsageRequest;
2525

2626
import java.util.EnumSet;
2727
import java.util.Locale;

x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/common/ProtocolUtils.java renamed to client/rest-high-level/src/main/java/org/elasticsearch/client/common/ProtocolUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* under the License.
1818
*/
1919

20-
package org.elasticsearch.protocol.xpack.common;
20+
package org.elasticsearch.client.common;
2121

2222
import java.util.Arrays;
2323
import java.util.Map;

x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/license/DeleteLicenseRequest.java renamed to client/rest-high-level/src/main/java/org/elasticsearch/client/license/DeleteLicenseRequest.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,10 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19-
package org.elasticsearch.protocol.xpack.license;
19+
package org.elasticsearch.client.license;
2020

21-
import org.elasticsearch.action.ActionRequestValidationException;
22-
import org.elasticsearch.action.support.master.AcknowledgedRequest;
21+
import org.elasticsearch.client.TimedRequest;
2322

23+
public class DeleteLicenseRequest extends TimedRequest {
2424

25-
public class DeleteLicenseRequest extends AcknowledgedRequest<DeleteLicenseRequest> {
26-
27-
@Override
28-
public ActionRequestValidationException validate() {
29-
return null;
30-
}
3125
}

x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/license/GetLicenseRequest.java renamed to client/rest-high-level/src/main/java/org/elasticsearch/client/license/GetLicenseRequest.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,23 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19-
package org.elasticsearch.protocol.xpack.license;
19+
package org.elasticsearch.client.license;
2020

21-
import org.elasticsearch.action.ActionRequestValidationException;
22-
import org.elasticsearch.action.support.master.MasterNodeReadRequest;
21+
import org.elasticsearch.client.Validatable;
2322

2423

25-
public class GetLicenseRequest extends MasterNodeReadRequest<GetLicenseRequest> {
24+
public class GetLicenseRequest implements Validatable {
25+
26+
protected boolean local = false;
2627

2728
public GetLicenseRequest() {
2829
}
2930

30-
@Override
31-
public ActionRequestValidationException validate() {
32-
return null;
31+
public boolean isLocal() {
32+
return local;
33+
}
34+
35+
public void setLocal(boolean local) {
36+
this.local = local;
3337
}
3438
}

x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/license/GetLicenseResponse.java renamed to client/rest-high-level/src/main/java/org/elasticsearch/client/license/GetLicenseResponse.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19-
package org.elasticsearch.protocol.xpack.license;
19+
package org.elasticsearch.client.license;
2020

21-
import org.elasticsearch.action.ActionResponse;
22-
23-
public class GetLicenseResponse extends ActionResponse {
21+
public class GetLicenseResponse {
2422

2523
private String license;
2624

x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/license/LicenseStatus.java renamed to client/rest-high-level/src/main/java/org/elasticsearch/client/license/LicenseStatus.java

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,12 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19-
package org.elasticsearch.protocol.xpack.license;
20-
21-
import java.io.IOException;
22-
23-
import org.elasticsearch.common.io.stream.StreamInput;
24-
import org.elasticsearch.common.io.stream.StreamOutput;
25-
import org.elasticsearch.common.io.stream.Writeable;
19+
package org.elasticsearch.client.license;
2620

2721
/**
2822
* Status of an X-Pack license.
2923
*/
30-
public enum LicenseStatus implements Writeable {
24+
public enum LicenseStatus {
3125

3226
ACTIVE("active"),
3327
INVALID("invalid"),
@@ -43,15 +37,6 @@ public String label() {
4337
return label;
4438
}
4539

46-
@Override
47-
public void writeTo(StreamOutput out) throws IOException {
48-
out.writeString(label);
49-
}
50-
51-
public static LicenseStatus readFrom(StreamInput in) throws IOException {
52-
return fromString(in.readString());
53-
}
54-
5540
public static LicenseStatus fromString(String value) {
5641
switch (value) {
5742
case "active":

x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/license/LicensesStatus.java renamed to client/rest-high-level/src/main/java/org/elasticsearch/client/license/LicensesStatus.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19-
package org.elasticsearch.protocol.xpack.license;
19+
package org.elasticsearch.client.license;
2020

2121
import java.util.Locale;
2222

x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/license/PutLicenseRequest.java renamed to client/rest-high-level/src/main/java/org/elasticsearch/client/license/PutLicenseRequest.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,16 @@
1717
* under the License.
1818
*/
1919

20-
package org.elasticsearch.protocol.xpack.license;
20+
package org.elasticsearch.client.license;
2121

22-
import org.elasticsearch.action.ActionRequestValidationException;
23-
import org.elasticsearch.action.support.master.AcknowledgedRequest;
22+
import org.elasticsearch.client.TimedRequest;
2423

25-
public class PutLicenseRequest extends AcknowledgedRequest<PutLicenseRequest> {
24+
public class PutLicenseRequest extends TimedRequest {
2625

2726
private String licenseDefinition;
2827
private boolean acknowledge = false;
2928

3029
public PutLicenseRequest() {
31-
32-
}
33-
34-
@Override
35-
public ActionRequestValidationException validate() {
36-
return null;
3730
}
3831

3932
public void setLicenseDefinition(String licenseDefinition) {

x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/license/PutLicenseResponse.java renamed to client/rest-high-level/src/main/java/org/elasticsearch/client/license/PutLicenseResponse.java

Lines changed: 9 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,14 @@
1717
* under the License.
1818
*/
1919

20-
package org.elasticsearch.protocol.xpack.license;
20+
package org.elasticsearch.client.license;
2121

22-
import org.elasticsearch.action.support.master.AcknowledgedResponse;
2322
import org.elasticsearch.common.ParseField;
24-
import org.elasticsearch.common.Strings;
2523
import org.elasticsearch.common.collect.Tuple;
26-
import org.elasticsearch.common.io.stream.StreamInput;
27-
import org.elasticsearch.common.io.stream.StreamOutput;
2824
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
29-
import org.elasticsearch.common.xcontent.XContentBuilder;
3025
import org.elasticsearch.common.xcontent.XContentParseException;
3126
import org.elasticsearch.common.xcontent.XContentParser;
32-
import org.elasticsearch.protocol.xpack.common.ProtocolUtils;
27+
import org.elasticsearch.client.common.ProtocolUtils;
3328

3429
import java.io.IOException;
3530
import java.util.ArrayList;
@@ -42,7 +37,7 @@
4237
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg;
4338
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.optionalConstructorArg;
4439

45-
public class PutLicenseResponse extends AcknowledgedResponse {
40+
public final class PutLicenseResponse {
4641

4742
private static final ConstructingObjectParser<PutLicenseResponse, Void> PARSER = new ConstructingObjectParser<>(
4843
"put_license_response", true, (a, v) -> {
@@ -97,6 +92,7 @@ public class PutLicenseResponse extends AcknowledgedResponse {
9792
new ParseField("acknowledge"));
9893
}
9994

95+
private boolean acknowledged;
10096
private LicensesStatus status;
10197
private Map<String, String[]> acknowledgeMessages;
10298
private String acknowledgeHeader;
@@ -110,12 +106,16 @@ public PutLicenseResponse(boolean acknowledged, LicensesStatus status) {
110106

111107
public PutLicenseResponse(boolean acknowledged, LicensesStatus status, String acknowledgeHeader,
112108
Map<String, String[]> acknowledgeMessages) {
113-
super(acknowledged);
109+
this.acknowledged = acknowledged;
114110
this.status = status;
115111
this.acknowledgeHeader = acknowledgeHeader;
116112
this.acknowledgeMessages = acknowledgeMessages;
117113
}
118114

115+
public boolean isAcknowledged() {
116+
return acknowledged;
117+
}
118+
119119
public LicensesStatus status() {
120120
return status;
121121
}
@@ -128,62 +128,6 @@ public String acknowledgeHeader() {
128128
return acknowledgeHeader;
129129
}
130130

131-
@Override
132-
public void readFrom(StreamInput in) throws IOException {
133-
super.readFrom(in);
134-
status = LicensesStatus.fromId(in.readVInt());
135-
acknowledgeHeader = in.readOptionalString();
136-
int size = in.readVInt();
137-
Map<String, String[]> acknowledgeMessages = new HashMap<>(size);
138-
for (int i = 0; i < size; i++) {
139-
String feature = in.readString();
140-
int nMessages = in.readVInt();
141-
String[] messages = new String[nMessages];
142-
for (int j = 0; j < nMessages; j++) {
143-
messages[j] = in.readString();
144-
}
145-
acknowledgeMessages.put(feature, messages);
146-
}
147-
this.acknowledgeMessages = acknowledgeMessages;
148-
}
149-
150-
@Override
151-
public void writeTo(StreamOutput out) throws IOException {
152-
super.writeTo(out);
153-
out.writeVInt(status.id());
154-
out.writeOptionalString(acknowledgeHeader);
155-
out.writeVInt(acknowledgeMessages.size());
156-
for (Map.Entry<String, String[]> entry : acknowledgeMessages.entrySet()) {
157-
out.writeString(entry.getKey());
158-
out.writeVInt(entry.getValue().length);
159-
for (String message : entry.getValue()) {
160-
out.writeString(message);
161-
}
162-
}
163-
}
164-
165-
@Override
166-
protected void addCustomFields(XContentBuilder builder, Params params) throws IOException {
167-
builder.field("license_status", status.toString());
168-
if (!acknowledgeMessages.isEmpty()) {
169-
builder.startObject("acknowledge");
170-
builder.field("message", acknowledgeHeader);
171-
for (Map.Entry<String, String[]> entry : acknowledgeMessages.entrySet()) {
172-
builder.startArray(entry.getKey());
173-
for (String message : entry.getValue()) {
174-
builder.value(message);
175-
}
176-
builder.endArray();
177-
}
178-
builder.endObject();
179-
}
180-
}
181-
182-
@Override
183-
public String toString() {
184-
return Strings.toString(this, true, true);
185-
}
186-
187131
public static PutLicenseResponse fromXContent(XContentParser parser) throws IOException {
188132
return PARSER.parse(parser, null);
189133
}
@@ -205,5 +149,4 @@ public int hashCode() {
205149
return Objects.hash(super.hashCode(), status, ProtocolUtils.hashCode(acknowledgeMessages), acknowledgeHeader);
206150
}
207151

208-
209152
}

x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/license/package-info.java renamed to client/rest-high-level/src/main/java/org/elasticsearch/client/license/package-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@
2121
* Request and Response objects for the default distribution's License
2222
* APIs.
2323
*/
24-
package org.elasticsearch.protocol.xpack.license;
24+
package org.elasticsearch.client.license;

x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/XPackInfoRequest.java renamed to client/rest-high-level/src/main/java/org/elasticsearch/client/xpack/XPackInfoRequest.java

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,17 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19-
package org.elasticsearch.protocol.xpack;
19+
package org.elasticsearch.client.xpack;
2020

21-
import org.elasticsearch.action.ActionRequest;
22-
import org.elasticsearch.action.ActionRequestValidationException;
23-
import org.elasticsearch.common.io.stream.StreamInput;
24-
import org.elasticsearch.common.io.stream.StreamOutput;
21+
import org.elasticsearch.client.Validatable;
2522

26-
import java.io.IOException;
2723
import java.util.EnumSet;
2824
import java.util.Locale;
2925

3026
/**
3127
* Fetch information about X-Pack from the cluster.
3228
*/
33-
public class XPackInfoRequest extends ActionRequest {
29+
public class XPackInfoRequest implements Validatable {
3430

3531
public enum Category {
3632
BUILD, LICENSE, FEATURES;
@@ -72,28 +68,4 @@ public EnumSet<Category> getCategories() {
7268
return categories;
7369
}
7470

75-
@Override
76-
public ActionRequestValidationException validate() {
77-
return null;
78-
}
79-
80-
@Override
81-
public void readFrom(StreamInput in) throws IOException {
82-
this.verbose = in.readBoolean();
83-
EnumSet<Category> categories = EnumSet.noneOf(Category.class);
84-
int size = in.readVInt();
85-
for (int i = 0; i < size; i++) {
86-
categories.add(Category.valueOf(in.readString()));
87-
}
88-
this.categories = categories;
89-
}
90-
91-
@Override
92-
public void writeTo(StreamOutput out) throws IOException {
93-
out.writeBoolean(verbose);
94-
out.writeVInt(categories.size());
95-
for (Category category : categories) {
96-
out.writeString(category.name());
97-
}
98-
}
9971
}

0 commit comments

Comments
 (0)