66package org .elasticsearch .protocol .xpack .license ;
77
88import org .elasticsearch .action .support .master .AcknowledgedResponse ;
9- import org .elasticsearch .common .ParseField ;
109import org .elasticsearch .common .Strings ;
11- import org .elasticsearch .common .collect .Tuple ;
1210import org .elasticsearch .common .io .stream .StreamInput ;
1311import org .elasticsearch .common .io .stream .StreamOutput ;
14- import org .elasticsearch .common .xcontent .ConstructingObjectParser ;
1512import org .elasticsearch .common .xcontent .XContentBuilder ;
16- import org .elasticsearch .common .xcontent .XContentParseException ;
17- import org .elasticsearch .common .xcontent .XContentParser ;
1813import org .elasticsearch .protocol .xpack .common .ProtocolUtils ;
1914
2015import java .io .IOException ;
21- import java .util .ArrayList ;
2216import java .util .Collections ;
2317import java .util .HashMap ;
24- import java .util .List ;
2518import java .util .Map ;
2619import java .util .Objects ;
2720
28- import static org .elasticsearch .common .xcontent .ConstructingObjectParser .constructorArg ;
29- import static org .elasticsearch .common .xcontent .ConstructingObjectParser .optionalConstructorArg ;
30-
3121public class PutLicenseResponse extends AcknowledgedResponse {
3222
33- private static final ConstructingObjectParser <PutLicenseResponse , Void > PARSER = new ConstructingObjectParser <>(
34- "put_license_response" , true , (a , v ) -> {
35- boolean acknowledged = (Boolean ) a [0 ];
36- LicensesStatus licensesStatus = LicensesStatus .fromString ((String ) a [1 ]);
37- @ SuppressWarnings ("unchecked" ) Tuple <String , Map <String , String []>> acknowledgements = (Tuple <String , Map <String , String []>>) a [2 ];
38- if (acknowledgements == null ) {
39- return new PutLicenseResponse (acknowledged , licensesStatus );
40- } else {
41- return new PutLicenseResponse (acknowledged , licensesStatus , acknowledgements .v1 (), acknowledgements .v2 ());
42- }
43-
44- });
45-
46- static {
47- PARSER .declareBoolean (constructorArg (), new ParseField ("acknowledged" ));
48- PARSER .declareString (constructorArg (), new ParseField ("license_status" ));
49- PARSER .declareObject (optionalConstructorArg (), (parser , v ) -> {
50- Map <String , String []> acknowledgeMessages = new HashMap <>();
51- String message = null ;
52- XContentParser .Token token ;
53- String currentFieldName = null ;
54- while ((token = parser .nextToken ()) != XContentParser .Token .END_OBJECT ) {
55- if (token == XContentParser .Token .FIELD_NAME ) {
56- currentFieldName = parser .currentName ();
57- } else {
58- if (currentFieldName == null ) {
59- throw new XContentParseException (parser .getTokenLocation (), "expected message header or acknowledgement" );
60- }
61- if ("message" .equals (currentFieldName )) {
62- if (token != XContentParser .Token .VALUE_STRING ) {
63- throw new XContentParseException (parser .getTokenLocation (), "unexpected message header type" );
64- }
65- message = parser .text ();
66- } else {
67- if (token != XContentParser .Token .START_ARRAY ) {
68- throw new XContentParseException (parser .getTokenLocation (), "unexpected acknowledgement type" );
69- }
70- List <String > acknowledgeMessagesList = new ArrayList <>();
71- while ((token = parser .nextToken ()) != XContentParser .Token .END_ARRAY ) {
72- if (token != XContentParser .Token .VALUE_STRING ) {
73- throw new XContentParseException (parser .getTokenLocation (), "unexpected acknowledgement text" );
74- }
75- acknowledgeMessagesList .add (parser .text ());
76- }
77- acknowledgeMessages .put (currentFieldName , acknowledgeMessagesList .toArray (new String [0 ]));
78- }
79- }
80- }
81- return new Tuple <>(message , acknowledgeMessages );
82- },
83- new ParseField ("acknowledge" ));
84- }
85-
8623 private LicensesStatus status ;
8724 private Map <String , String []> acknowledgeMessages ;
8825 private String acknowledgeHeader ;
@@ -170,10 +107,6 @@ public String toString() {
170107 return Strings .toString (this , true , true );
171108 }
172109
173- public static PutLicenseResponse fromXContent (XContentParser parser ) throws IOException {
174- return PARSER .parse (parser , null );
175- }
176-
177110 @ Override
178111 public boolean equals (Object o ) {
179112 if (this == o ) return true ;
@@ -190,6 +123,4 @@ public boolean equals(Object o) {
190123 public int hashCode () {
191124 return Objects .hash (super .hashCode (), status , ProtocolUtils .hashCode (acknowledgeMessages ), acknowledgeHeader );
192125 }
193-
194-
195126}
0 commit comments