parent
67652b5355
commit
423d085bed
|
@ -34,11 +34,11 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
|
|||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.protocol.xpack.license.DeleteLicenseRequest;
|
||||
import org.elasticsearch.protocol.xpack.license.GetLicenseRequest;
|
||||
import org.elasticsearch.protocol.xpack.license.GetLicenseResponse;
|
||||
import org.elasticsearch.protocol.xpack.license.PutLicenseRequest;
|
||||
import org.elasticsearch.protocol.xpack.license.PutLicenseResponse;
|
||||
import org.elasticsearch.client.license.DeleteLicenseRequest;
|
||||
import org.elasticsearch.client.license.GetLicenseRequest;
|
||||
import org.elasticsearch.client.license.GetLicenseResponse;
|
||||
import org.elasticsearch.client.license.PutLicenseRequest;
|
||||
import org.elasticsearch.client.license.PutLicenseResponse;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
|
|
@ -25,9 +25,9 @@ import org.apache.http.client.methods.HttpPost;
|
|||
import org.apache.http.client.methods.HttpPut;
|
||||
import org.elasticsearch.client.license.StartTrialRequest;
|
||||
import org.elasticsearch.client.license.StartBasicRequest;
|
||||
import org.elasticsearch.protocol.xpack.license.DeleteLicenseRequest;
|
||||
import org.elasticsearch.protocol.xpack.license.GetLicenseRequest;
|
||||
import org.elasticsearch.protocol.xpack.license.PutLicenseRequest;
|
||||
import org.elasticsearch.client.license.DeleteLicenseRequest;
|
||||
import org.elasticsearch.client.license.GetLicenseRequest;
|
||||
import org.elasticsearch.client.license.PutLicenseRequest;
|
||||
|
||||
public class LicenseRequestConverters {
|
||||
static Request putLicense(PutLicenseRequest putLicenseRequest) {
|
||||
|
@ -47,7 +47,7 @@ public class LicenseRequestConverters {
|
|||
String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_xpack", "license").build();
|
||||
Request request = new Request(HttpGet.METHOD_NAME, endpoint);
|
||||
RequestConverters.Params parameters = new RequestConverters.Params(request);
|
||||
parameters.withLocal(getLicenseRequest.local());
|
||||
parameters.withLocal(getLicenseRequest.isLocal());
|
||||
return request;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,10 +20,10 @@
|
|||
package org.elasticsearch.client;
|
||||
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.protocol.xpack.XPackInfoRequest;
|
||||
import org.elasticsearch.protocol.xpack.XPackInfoResponse;
|
||||
import org.elasticsearch.protocol.xpack.XPackUsageRequest;
|
||||
import org.elasticsearch.protocol.xpack.XPackUsageResponse;
|
||||
import org.elasticsearch.client.xpack.XPackInfoRequest;
|
||||
import org.elasticsearch.client.xpack.XPackInfoResponse;
|
||||
import org.elasticsearch.client.xpack.XPackUsageRequest;
|
||||
import org.elasticsearch.client.xpack.XPackUsageResponse;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
|
|
@ -20,8 +20,8 @@
|
|||
package org.elasticsearch.client;
|
||||
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.elasticsearch.protocol.xpack.XPackInfoRequest;
|
||||
import org.elasticsearch.protocol.xpack.XPackUsageRequest;
|
||||
import org.elasticsearch.client.xpack.XPackInfoRequest;
|
||||
import org.elasticsearch.client.xpack.XPackUsageRequest;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.Locale;
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.protocol.xpack.common;
|
||||
package org.elasticsearch.client.common;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
|
@ -16,16 +16,10 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.elasticsearch.protocol.xpack.license;
|
||||
package org.elasticsearch.client.license;
|
||||
|
||||
import org.elasticsearch.action.ActionRequestValidationException;
|
||||
import org.elasticsearch.action.support.master.AcknowledgedRequest;
|
||||
import org.elasticsearch.client.TimedRequest;
|
||||
|
||||
public class DeleteLicenseRequest extends TimedRequest {
|
||||
|
||||
public class DeleteLicenseRequest extends AcknowledgedRequest<DeleteLicenseRequest> {
|
||||
|
||||
@Override
|
||||
public ActionRequestValidationException validate() {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -16,16 +16,23 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.elasticsearch.protocol.xpack;
|
||||
package org.elasticsearch.client.license;
|
||||
|
||||
import org.elasticsearch.action.ActionRequestValidationException;
|
||||
import org.elasticsearch.action.support.master.MasterNodeRequest;
|
||||
import org.elasticsearch.client.Validatable;
|
||||
|
||||
public class XPackUsageRequest extends MasterNodeRequest<XPackUsageRequest> {
|
||||
|
||||
@Override
|
||||
public ActionRequestValidationException validate() {
|
||||
return null;
|
||||
public class GetLicenseRequest implements Validatable {
|
||||
|
||||
protected boolean local = false;
|
||||
|
||||
public GetLicenseRequest() {
|
||||
}
|
||||
|
||||
public boolean isLocal() {
|
||||
return local;
|
||||
}
|
||||
|
||||
public void setLocal(boolean local) {
|
||||
this.local = local;
|
||||
}
|
||||
}
|
|
@ -16,11 +16,9 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.elasticsearch.protocol.xpack.license;
|
||||
package org.elasticsearch.client.license;
|
||||
|
||||
import org.elasticsearch.action.ActionResponse;
|
||||
|
||||
public class GetLicenseResponse extends ActionResponse {
|
||||
public class GetLicenseResponse {
|
||||
|
||||
private String license;
|
||||
|
|
@ -16,18 +16,12 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.elasticsearch.protocol.xpack.license;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.io.stream.Writeable;
|
||||
package org.elasticsearch.client.license;
|
||||
|
||||
/**
|
||||
* Status of an X-Pack license.
|
||||
*/
|
||||
public enum LicenseStatus implements Writeable {
|
||||
public enum LicenseStatus {
|
||||
|
||||
ACTIVE("active"),
|
||||
INVALID("invalid"),
|
||||
|
@ -43,15 +37,6 @@ public enum LicenseStatus implements Writeable {
|
|||
return label;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
out.writeString(label);
|
||||
}
|
||||
|
||||
public static LicenseStatus readFrom(StreamInput in) throws IOException {
|
||||
return fromString(in.readString());
|
||||
}
|
||||
|
||||
public static LicenseStatus fromString(String value) {
|
||||
switch (value) {
|
||||
case "active":
|
|
@ -16,7 +16,7 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.elasticsearch.protocol.xpack.license;
|
||||
package org.elasticsearch.client.license;
|
||||
|
||||
import java.util.Locale;
|
||||
|
|
@ -17,23 +17,16 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.protocol.xpack.license;
|
||||
package org.elasticsearch.client.license;
|
||||
|
||||
import org.elasticsearch.action.ActionRequestValidationException;
|
||||
import org.elasticsearch.action.support.master.AcknowledgedRequest;
|
||||
import org.elasticsearch.client.TimedRequest;
|
||||
|
||||
public class PutLicenseRequest extends AcknowledgedRequest<PutLicenseRequest> {
|
||||
public class PutLicenseRequest extends TimedRequest {
|
||||
|
||||
private String licenseDefinition;
|
||||
private boolean acknowledge = false;
|
||||
|
||||
public PutLicenseRequest() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionRequestValidationException validate() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setLicenseDefinition(String licenseDefinition) {
|
|
@ -17,19 +17,14 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.protocol.xpack.license;
|
||||
package org.elasticsearch.client.license;
|
||||
|
||||
import org.elasticsearch.action.support.master.AcknowledgedResponse;
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.collect.Tuple;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParseException;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.protocol.xpack.common.ProtocolUtils;
|
||||
import org.elasticsearch.client.common.ProtocolUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
@ -42,7 +37,7 @@ import java.util.Objects;
|
|||
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg;
|
||||
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.optionalConstructorArg;
|
||||
|
||||
public class PutLicenseResponse extends AcknowledgedResponse {
|
||||
public final class PutLicenseResponse {
|
||||
|
||||
private static final ConstructingObjectParser<PutLicenseResponse, Void> PARSER = new ConstructingObjectParser<>(
|
||||
"put_license_response", true, (a, v) -> {
|
||||
|
@ -97,6 +92,7 @@ public class PutLicenseResponse extends AcknowledgedResponse {
|
|||
new ParseField("acknowledge"));
|
||||
}
|
||||
|
||||
private boolean acknowledged;
|
||||
private LicensesStatus status;
|
||||
private Map<String, String[]> acknowledgeMessages;
|
||||
private String acknowledgeHeader;
|
||||
|
@ -110,12 +106,16 @@ public class PutLicenseResponse extends AcknowledgedResponse {
|
|||
|
||||
public PutLicenseResponse(boolean acknowledged, LicensesStatus status, String acknowledgeHeader,
|
||||
Map<String, String[]> acknowledgeMessages) {
|
||||
super(acknowledged);
|
||||
this.acknowledged = acknowledged;
|
||||
this.status = status;
|
||||
this.acknowledgeHeader = acknowledgeHeader;
|
||||
this.acknowledgeMessages = acknowledgeMessages;
|
||||
}
|
||||
|
||||
public boolean isAcknowledged() {
|
||||
return acknowledged;
|
||||
}
|
||||
|
||||
public LicensesStatus status() {
|
||||
return status;
|
||||
}
|
||||
|
@ -128,62 +128,6 @@ public class PutLicenseResponse extends AcknowledgedResponse {
|
|||
return acknowledgeHeader;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFrom(StreamInput in) throws IOException {
|
||||
super.readFrom(in);
|
||||
status = LicensesStatus.fromId(in.readVInt());
|
||||
acknowledgeHeader = in.readOptionalString();
|
||||
int size = in.readVInt();
|
||||
Map<String, String[]> acknowledgeMessages = new HashMap<>(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
String feature = in.readString();
|
||||
int nMessages = in.readVInt();
|
||||
String[] messages = new String[nMessages];
|
||||
for (int j = 0; j < nMessages; j++) {
|
||||
messages[j] = in.readString();
|
||||
}
|
||||
acknowledgeMessages.put(feature, messages);
|
||||
}
|
||||
this.acknowledgeMessages = acknowledgeMessages;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
super.writeTo(out);
|
||||
out.writeVInt(status.id());
|
||||
out.writeOptionalString(acknowledgeHeader);
|
||||
out.writeVInt(acknowledgeMessages.size());
|
||||
for (Map.Entry<String, String[]> entry : acknowledgeMessages.entrySet()) {
|
||||
out.writeString(entry.getKey());
|
||||
out.writeVInt(entry.getValue().length);
|
||||
for (String message : entry.getValue()) {
|
||||
out.writeString(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addCustomFields(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.field("license_status", status.toString());
|
||||
if (!acknowledgeMessages.isEmpty()) {
|
||||
builder.startObject("acknowledge");
|
||||
builder.field("message", acknowledgeHeader);
|
||||
for (Map.Entry<String, String[]> entry : acknowledgeMessages.entrySet()) {
|
||||
builder.startArray(entry.getKey());
|
||||
for (String message : entry.getValue()) {
|
||||
builder.value(message);
|
||||
}
|
||||
builder.endArray();
|
||||
}
|
||||
builder.endObject();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Strings.toString(this, true, true);
|
||||
}
|
||||
|
||||
public static PutLicenseResponse fromXContent(XContentParser parser) throws IOException {
|
||||
return PARSER.parse(parser, null);
|
||||
}
|
||||
|
@ -205,5 +149,4 @@ public class PutLicenseResponse extends AcknowledgedResponse {
|
|||
return Objects.hash(super.hashCode(), status, ProtocolUtils.hashCode(acknowledgeMessages), acknowledgeHeader);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -21,4 +21,4 @@
|
|||
* Request and Response objects for the default distribution's License
|
||||
* APIs.
|
||||
*/
|
||||
package org.elasticsearch.protocol.xpack.license;
|
||||
package org.elasticsearch.client.license;
|
|
@ -16,21 +16,17 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.elasticsearch.protocol.xpack;
|
||||
package org.elasticsearch.client.xpack;
|
||||
|
||||
import org.elasticsearch.action.ActionRequest;
|
||||
import org.elasticsearch.action.ActionRequestValidationException;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.client.Validatable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Fetch information about X-Pack from the cluster.
|
||||
*/
|
||||
public class XPackInfoRequest extends ActionRequest {
|
||||
public class XPackInfoRequest implements Validatable {
|
||||
|
||||
public enum Category {
|
||||
BUILD, LICENSE, FEATURES;
|
||||
|
@ -72,28 +68,4 @@ public class XPackInfoRequest extends ActionRequest {
|
|||
return categories;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionRequestValidationException validate() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFrom(StreamInput in) throws IOException {
|
||||
this.verbose = in.readBoolean();
|
||||
EnumSet<Category> categories = EnumSet.noneOf(Category.class);
|
||||
int size = in.readVInt();
|
||||
for (int i = 0; i < size; i++) {
|
||||
categories.add(Category.valueOf(in.readString()));
|
||||
}
|
||||
this.categories = categories;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
out.writeBoolean(verbose);
|
||||
out.writeVInt(categories.size());
|
||||
for (Category category : categories) {
|
||||
out.writeString(category.name());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,9 +16,8 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.elasticsearch.protocol.xpack;
|
||||
package org.elasticsearch.client.xpack;
|
||||
|
||||
import org.elasticsearch.action.ActionResponse;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.Strings;
|
||||
|
@ -30,7 +29,7 @@ import org.elasticsearch.common.xcontent.ObjectParser.ValueType;
|
|||
import org.elasticsearch.common.xcontent.ToXContentObject;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.protocol.xpack.license.LicenseStatus;
|
||||
import org.elasticsearch.client.license.LicenseStatus;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
@ -48,7 +47,7 @@ import java.util.stream.Collectors;
|
|||
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg;
|
||||
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.optionalConstructorArg;
|
||||
|
||||
public class XPackInfoResponse extends ActionResponse implements ToXContentObject {
|
||||
public class XPackInfoResponse implements ToXContentObject {
|
||||
/**
|
||||
* Value of the license's expiration time if it should never expire.
|
||||
*/
|
||||
|
@ -89,21 +88,6 @@ public class XPackInfoResponse extends ActionResponse implements ToXContentObjec
|
|||
return featureSetsInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
super.writeTo(out);
|
||||
out.writeOptionalWriteable(buildInfo);
|
||||
out.writeOptionalWriteable(licenseInfo);
|
||||
out.writeOptionalWriteable(featureSetsInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFrom(StreamInput in) throws IOException {
|
||||
this.buildInfo = in.readOptionalWriteable(BuildInfo::new);
|
||||
this.licenseInfo = in.readOptionalWriteable(LicenseInfo::new);
|
||||
this.featureSetsInfo = in.readOptionalWriteable(FeatureSetsInfo::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (other == null || other.getClass() != getClass()) return false;
|
||||
|
@ -184,7 +168,7 @@ public class XPackInfoResponse extends ActionResponse implements ToXContentObjec
|
|||
return builder.endObject();
|
||||
}
|
||||
|
||||
public static class LicenseInfo implements ToXContentObject, Writeable {
|
||||
public static class LicenseInfo implements ToXContentObject {
|
||||
private final String uid;
|
||||
private final String type;
|
||||
private final String mode;
|
||||
|
@ -199,19 +183,6 @@ public class XPackInfoResponse extends ActionResponse implements ToXContentObjec
|
|||
this.expiryDate = expiryDate;
|
||||
}
|
||||
|
||||
public LicenseInfo(StreamInput in) throws IOException {
|
||||
this(in.readString(), in.readString(), in.readString(), LicenseStatus.readFrom(in), in.readLong());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
out.writeString(uid);
|
||||
out.writeString(type);
|
||||
out.writeString(mode);
|
||||
status.writeTo(out);
|
||||
out.writeLong(expiryDate);
|
||||
}
|
||||
|
||||
public String getUid() {
|
||||
return uid;
|
||||
}
|
|
@ -16,15 +16,10 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.elasticsearch.protocol.xpack.license;
|
||||
package org.elasticsearch.client.xpack;
|
||||
|
||||
import java.io.IOException;
|
||||
import org.elasticsearch.client.TimedRequest;
|
||||
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
public class XPackUsageRequest extends TimedRequest {
|
||||
|
||||
public class LicenseStatusTests extends ESTestCase {
|
||||
public void testSerialization() throws IOException {
|
||||
LicenseStatus status = randomFrom(LicenseStatus.values());
|
||||
assertSame(status, copyWriteable(status, writableRegistry(), LicenseStatus::readFrom));
|
||||
}
|
||||
}
|
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.protocol.xpack;
|
||||
package org.elasticsearch.client.xpack;
|
||||
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
|
@ -20,15 +20,21 @@
|
|||
package org.elasticsearch.client;
|
||||
|
||||
import org.elasticsearch.Build;
|
||||
import org.elasticsearch.action.support.master.AcknowledgedResponse;
|
||||
import org.elasticsearch.client.license.DeleteLicenseRequest;
|
||||
import org.elasticsearch.client.license.GetLicenseRequest;
|
||||
import org.elasticsearch.client.license.GetLicenseResponse;
|
||||
import org.elasticsearch.client.license.LicensesStatus;
|
||||
import org.elasticsearch.client.license.PutLicenseRequest;
|
||||
import org.elasticsearch.client.license.PutLicenseResponse;
|
||||
import org.elasticsearch.client.license.StartBasicRequest;
|
||||
import org.elasticsearch.client.license.StartBasicResponse;
|
||||
import org.elasticsearch.client.license.StartTrialRequest;
|
||||
import org.elasticsearch.client.license.StartTrialResponse;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.collect.MapBuilder;
|
||||
import org.elasticsearch.protocol.xpack.license.LicensesStatus;
|
||||
import org.elasticsearch.protocol.xpack.license.PutLicenseRequest;
|
||||
import org.elasticsearch.protocol.xpack.license.PutLicenseResponse;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.junit.After;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
|
@ -39,6 +45,7 @@ import java.util.Map;
|
|||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||
import static org.hamcrest.CoreMatchers.nullValue;
|
||||
import static org.hamcrest.Matchers.isEmptyOrNullString;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
|
@ -165,4 +172,30 @@ public class LicenseIT extends ESRestHighLevelClientTestCase {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void testGetLicense() throws Exception {
|
||||
final GetLicenseRequest request = new GetLicenseRequest();
|
||||
final GetLicenseResponse response = highLevelClient().license().getLicense(request, RequestOptions.DEFAULT);
|
||||
final String licenseDefinition = response.getLicenseDefinition();
|
||||
assertThat(licenseDefinition, notNullValue());
|
||||
|
||||
final XContentParser parser = createParser(JsonXContent.jsonXContent, licenseDefinition);
|
||||
final Map<String, Object> map = parser.map();
|
||||
assertThat(map.containsKey("license"), equalTo(true));
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
final Map<String, Object> license = (Map<String, Object>) map.get("license");
|
||||
assertThat(license.get("status"), equalTo("active"));
|
||||
assertThat(license.get("type"), equalTo("trial"));
|
||||
}
|
||||
|
||||
public void testPutLicense() throws Exception {
|
||||
putTrialLicense();
|
||||
}
|
||||
|
||||
public void testDeleteLicense() throws Exception {
|
||||
final DeleteLicenseRequest request = new DeleteLicenseRequest();
|
||||
final AcknowledgedResponse response = highLevelClient().license().deleteLicense(request, RequestOptions.DEFAULT);
|
||||
assertThat(response.isAcknowledged(), equalTo(true));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,12 @@ import org.apache.http.client.methods.HttpPost;
|
|||
import org.elasticsearch.client.license.StartTrialRequest;
|
||||
import org.elasticsearch.action.support.master.AcknowledgedRequest;
|
||||
import org.elasticsearch.client.license.StartBasicRequest;
|
||||
import org.apache.http.client.methods.HttpDelete;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpPut;
|
||||
import org.elasticsearch.client.license.DeleteLicenseRequest;
|
||||
import org.elasticsearch.client.license.GetLicenseRequest;
|
||||
import org.elasticsearch.client.license.PutLicenseRequest;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
@ -37,6 +43,53 @@ import static org.hamcrest.CoreMatchers.is;
|
|||
|
||||
public class LicenseRequestConvertersTests extends ESTestCase {
|
||||
|
||||
public void testGetLicense() {
|
||||
final boolean local = randomBoolean();
|
||||
final GetLicenseRequest getLicenseRequest = new GetLicenseRequest();
|
||||
getLicenseRequest.setLocal(local);
|
||||
final Map<String, String> expectedParams = new HashMap<>();
|
||||
if (local) {
|
||||
expectedParams.put("local", Boolean.TRUE.toString());
|
||||
}
|
||||
|
||||
Request request = LicenseRequestConverters.getLicense(getLicenseRequest);
|
||||
assertThat(request.getMethod(), equalTo(HttpGet.METHOD_NAME));
|
||||
assertThat(request.getEndpoint(), equalTo("/_xpack/license"));
|
||||
assertThat(request.getParameters(), equalTo(expectedParams));
|
||||
assertThat(request.getEntity(), is(nullValue()));
|
||||
}
|
||||
|
||||
public void testPutLicense() {
|
||||
final boolean acknowledge = randomBoolean();
|
||||
final PutLicenseRequest putLicenseRequest = new PutLicenseRequest();
|
||||
putLicenseRequest.setAcknowledge(acknowledge);
|
||||
final Map<String, String> expectedParams = new HashMap<>();
|
||||
if (acknowledge) {
|
||||
expectedParams.put("acknowledge", Boolean.TRUE.toString());
|
||||
}
|
||||
setRandomTimeout(putLicenseRequest, AcknowledgedRequest.DEFAULT_ACK_TIMEOUT, expectedParams);
|
||||
setRandomMasterTimeout(putLicenseRequest, expectedParams);
|
||||
|
||||
Request request = LicenseRequestConverters.putLicense(putLicenseRequest);
|
||||
assertThat(request.getMethod(), equalTo(HttpPut.METHOD_NAME));
|
||||
assertThat(request.getEndpoint(), equalTo("/_xpack/license"));
|
||||
assertThat(request.getParameters(), equalTo(expectedParams));
|
||||
assertThat(request.getEntity(), is(nullValue()));
|
||||
}
|
||||
|
||||
public void testDeleteLicense() {
|
||||
final DeleteLicenseRequest deleteLicenseRequest = new DeleteLicenseRequest();
|
||||
final Map<String, String> expectedParams = new HashMap<>();
|
||||
setRandomTimeout(deleteLicenseRequest, AcknowledgedRequest.DEFAULT_ACK_TIMEOUT, expectedParams);
|
||||
setRandomMasterTimeout(deleteLicenseRequest, expectedParams);
|
||||
|
||||
Request request = LicenseRequestConverters.deleteLicense(deleteLicenseRequest);
|
||||
assertThat(request.getMethod(), equalTo(HttpDelete.METHOD_NAME));
|
||||
assertThat(request.getEndpoint(), equalTo("/_xpack/license"));
|
||||
assertThat(request.getParameters(), equalTo(expectedParams));
|
||||
assertThat(request.getEntity(), is(nullValue()));
|
||||
}
|
||||
|
||||
public void testStartTrial() {
|
||||
final boolean acknowledge = randomBoolean();
|
||||
final String licenseType = randomBoolean()
|
||||
|
|
|
@ -21,10 +21,10 @@ package org.elasticsearch.client;
|
|||
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.elasticsearch.action.main.MainResponse;
|
||||
import org.elasticsearch.protocol.xpack.XPackInfoRequest;
|
||||
import org.elasticsearch.protocol.xpack.XPackInfoResponse;
|
||||
import org.elasticsearch.protocol.xpack.XPackInfoResponse.FeatureSetsInfo.FeatureSet;
|
||||
import org.elasticsearch.protocol.xpack.license.LicenseStatus;
|
||||
import org.elasticsearch.client.xpack.XPackInfoRequest;
|
||||
import org.elasticsearch.client.xpack.XPackInfoResponse;
|
||||
import org.elasticsearch.client.xpack.XPackInfoResponse.FeatureSetsInfo.FeatureSet;
|
||||
import org.elasticsearch.client.license.LicenseStatus;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.EnumSet;
|
||||
|
|
|
@ -20,9 +20,8 @@
|
|||
package org.elasticsearch.client;
|
||||
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.elasticsearch.protocol.xpack.XPackInfoRequest;
|
||||
import org.elasticsearch.client.xpack.XPackInfoRequest;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.junit.Assert;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
|
@ -55,9 +54,9 @@ public class XPackRequestConvertersTests extends ESTestCase {
|
|||
}
|
||||
|
||||
Request request = XPackRequestConverters.info(infoRequest);
|
||||
Assert.assertEquals(HttpGet.METHOD_NAME, request.getMethod());
|
||||
Assert.assertEquals("/_xpack", request.getEndpoint());
|
||||
Assert.assertNull(request.getEntity());
|
||||
Assert.assertEquals(expectedParams, request.getParameters());
|
||||
assertEquals(HttpGet.METHOD_NAME, request.getMethod());
|
||||
assertEquals("/_xpack", request.getEndpoint());
|
||||
assertNull(request.getEntity());
|
||||
assertEquals(expectedParams, request.getParameters());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.protocol.xpack.common;
|
||||
package org.elasticsearch.client.common;
|
||||
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
|
@ -31,14 +31,14 @@ import org.elasticsearch.client.license.StartTrialResponse;
|
|||
import org.elasticsearch.client.license.StartBasicRequest;
|
||||
import org.elasticsearch.client.license.StartBasicResponse;
|
||||
import org.elasticsearch.common.Booleans;
|
||||
import org.elasticsearch.protocol.xpack.license.DeleteLicenseRequest;
|
||||
import org.elasticsearch.protocol.xpack.license.GetLicenseRequest;
|
||||
import org.elasticsearch.protocol.xpack.license.GetLicenseResponse;
|
||||
import org.elasticsearch.protocol.xpack.license.LicensesStatus;
|
||||
import org.elasticsearch.protocol.xpack.license.PutLicenseRequest;
|
||||
import org.elasticsearch.protocol.xpack.license.PutLicenseResponse;
|
||||
import org.junit.After;
|
||||
import org.junit.BeforeClass;
|
||||
import org.elasticsearch.client.license.DeleteLicenseRequest;
|
||||
import org.elasticsearch.client.license.GetLicenseRequest;
|
||||
import org.elasticsearch.client.license.GetLicenseResponse;
|
||||
import org.elasticsearch.client.license.LicensesStatus;
|
||||
import org.elasticsearch.client.license.PutLicenseRequest;
|
||||
import org.elasticsearch.client.license.PutLicenseResponse;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
|
|
@ -30,13 +30,13 @@ import org.elasticsearch.client.RequestOptions;
|
|||
import org.elasticsearch.client.RestClient;
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
import org.elasticsearch.cluster.ClusterName;
|
||||
import org.elasticsearch.protocol.xpack.XPackInfoRequest;
|
||||
import org.elasticsearch.protocol.xpack.XPackInfoResponse;
|
||||
import org.elasticsearch.protocol.xpack.XPackInfoResponse.BuildInfo;
|
||||
import org.elasticsearch.protocol.xpack.XPackInfoResponse.FeatureSetsInfo;
|
||||
import org.elasticsearch.protocol.xpack.XPackInfoResponse.LicenseInfo;
|
||||
import org.elasticsearch.protocol.xpack.XPackUsageRequest;
|
||||
import org.elasticsearch.protocol.xpack.XPackUsageResponse;
|
||||
import org.elasticsearch.client.xpack.XPackInfoRequest;
|
||||
import org.elasticsearch.client.xpack.XPackInfoResponse;
|
||||
import org.elasticsearch.client.xpack.XPackInfoResponse.BuildInfo;
|
||||
import org.elasticsearch.client.xpack.XPackInfoResponse.FeatureSetsInfo;
|
||||
import org.elasticsearch.client.xpack.XPackInfoResponse.LicenseInfo;
|
||||
import org.elasticsearch.client.xpack.XPackUsageRequest;
|
||||
import org.elasticsearch.client.xpack.XPackUsageResponse;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.Instant;
|
||||
|
|
|
@ -21,7 +21,7 @@ package org.elasticsearch.client.license;
|
|||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.protocol.xpack.common.ProtocolUtils;
|
||||
import org.elasticsearch.client.common.ProtocolUtils;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
||||
import java.io.IOException;
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
/*
|
||||
* 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.protocol.xpack.license;
|
||||
|
||||
import org.elasticsearch.action.ActionRequestValidationException;
|
||||
import org.elasticsearch.action.support.master.MasterNodeReadRequest;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
public class GetLicenseRequest extends MasterNodeReadRequest<GetLicenseRequest> {
|
||||
|
||||
public GetLicenseRequest() {
|
||||
}
|
||||
|
||||
public GetLicenseRequest(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionRequestValidationException validate() {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,160 +0,0 @@
|
|||
/*
|
||||
* 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.protocol.xpack;
|
||||
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.protocol.xpack.XPackInfoResponse.BuildInfo;
|
||||
import org.elasticsearch.protocol.xpack.XPackInfoResponse.LicenseInfo;
|
||||
import org.elasticsearch.protocol.xpack.XPackInfoResponse.FeatureSetsInfo;
|
||||
import org.elasticsearch.protocol.xpack.XPackInfoResponse.FeatureSetsInfo.FeatureSet;
|
||||
import org.elasticsearch.protocol.xpack.license.LicenseStatus;
|
||||
import org.elasticsearch.test.AbstractStreamableXContentTestCase;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.io.IOException;
|
||||
|
||||
public class XPackInfoResponseTests extends AbstractStreamableXContentTestCase<XPackInfoResponse> {
|
||||
@Override
|
||||
protected XPackInfoResponse doParseInstance(XContentParser parser) throws IOException {
|
||||
return XPackInfoResponse.fromXContent(parser);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected XPackInfoResponse createBlankInstance() {
|
||||
return new XPackInfoResponse();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Predicate<String> getRandomFieldsExcludeFilter() {
|
||||
return path -> path.equals("features")
|
||||
|| (path.startsWith("features") && path.endsWith("native_code_info"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ToXContent.Params getToXContentParams() {
|
||||
Map<String, String> params = new HashMap<>();
|
||||
if (randomBoolean()) {
|
||||
params.put("human", randomBoolean() ? "true" : "false");
|
||||
}
|
||||
if (randomBoolean()) {
|
||||
params.put("categories", "_none");
|
||||
}
|
||||
return new ToXContent.MapParams(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected XPackInfoResponse createTestInstance() {
|
||||
return new XPackInfoResponse(
|
||||
randomBoolean() ? null : randomBuildInfo(),
|
||||
randomBoolean() ? null : randomLicenseInfo(),
|
||||
randomBoolean() ? null : randomFeatureSetsInfo());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected XPackInfoResponse mutateInstance(XPackInfoResponse response) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Function<XPackInfoResponse, XPackInfoResponse> mutator = randomFrom(
|
||||
r -> new XPackInfoResponse(
|
||||
mutateBuildInfo(r.getBuildInfo()),
|
||||
r.getLicenseInfo(),
|
||||
r.getFeatureSetsInfo()),
|
||||
r -> new XPackInfoResponse(
|
||||
r.getBuildInfo(),
|
||||
mutateLicenseInfo(r.getLicenseInfo()),
|
||||
r.getFeatureSetsInfo()),
|
||||
r -> new XPackInfoResponse(
|
||||
r.getBuildInfo(),
|
||||
r.getLicenseInfo(),
|
||||
mutateFeatureSetsInfo(r.getFeatureSetsInfo())));
|
||||
return mutator.apply(response);
|
||||
}
|
||||
|
||||
private BuildInfo randomBuildInfo() {
|
||||
return new BuildInfo(
|
||||
randomAlphaOfLength(10),
|
||||
randomAlphaOfLength(15));
|
||||
}
|
||||
|
||||
private BuildInfo mutateBuildInfo(BuildInfo buildInfo) {
|
||||
if (buildInfo == null) {
|
||||
return randomBuildInfo();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private LicenseInfo randomLicenseInfo() {
|
||||
return new LicenseInfo(
|
||||
randomAlphaOfLength(10),
|
||||
randomAlphaOfLength(4),
|
||||
randomAlphaOfLength(5),
|
||||
randomFrom(LicenseStatus.values()),
|
||||
randomLong());
|
||||
}
|
||||
|
||||
private LicenseInfo mutateLicenseInfo(LicenseInfo licenseInfo) {
|
||||
if (licenseInfo == null) {
|
||||
return randomLicenseInfo();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private FeatureSetsInfo randomFeatureSetsInfo() {
|
||||
int size = between(0, 10);
|
||||
Set<FeatureSet> featureSets = new HashSet<>(size);
|
||||
while (featureSets.size() < size) {
|
||||
featureSets.add(randomFeatureSet());
|
||||
}
|
||||
return new FeatureSetsInfo(featureSets);
|
||||
}
|
||||
|
||||
private FeatureSetsInfo mutateFeatureSetsInfo(FeatureSetsInfo featureSetsInfo) {
|
||||
if (featureSetsInfo == null) {
|
||||
return randomFeatureSetsInfo();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private FeatureSet randomFeatureSet() {
|
||||
return new FeatureSet(
|
||||
randomAlphaOfLength(5),
|
||||
randomBoolean() ? null : randomAlphaOfLength(20),
|
||||
randomBoolean(),
|
||||
randomBoolean(),
|
||||
randomNativeCodeInfo());
|
||||
}
|
||||
|
||||
private Map<String, Object> randomNativeCodeInfo() {
|
||||
if (randomBoolean()) {
|
||||
return null;
|
||||
}
|
||||
int size = between(0, 10);
|
||||
Map<String, Object> nativeCodeInfo = new HashMap<>(size);
|
||||
while (nativeCodeInfo.size() < size) {
|
||||
nativeCodeInfo.put(randomAlphaOfLength(5), randomAlphaOfLength(5));
|
||||
}
|
||||
return nativeCodeInfo;
|
||||
}
|
||||
}
|
|
@ -1,125 +0,0 @@
|
|||
/*
|
||||
* 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.protocol.xpack.license;
|
||||
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.test.AbstractStreamableXContentTestCase;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class PutLicenseResponseTests extends AbstractStreamableXContentTestCase<PutLicenseResponse> {
|
||||
|
||||
@Override
|
||||
protected boolean supportsUnknownFields() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Predicate<String> getRandomFieldsExcludeFilter() {
|
||||
// The structure of the response is such that unknown fields inside acknowledge cannot be supported since they
|
||||
// are treated as messages from new services
|
||||
return p -> p.startsWith("acknowledge");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PutLicenseResponse createTestInstance() {
|
||||
boolean acknowledged = randomBoolean();
|
||||
LicensesStatus status = randomFrom(LicensesStatus.VALID, LicensesStatus.INVALID, LicensesStatus.EXPIRED);
|
||||
String messageHeader;
|
||||
Map<String, String[]> ackMessages;
|
||||
if (randomBoolean()) {
|
||||
messageHeader = randomAlphaOfLength(10);
|
||||
ackMessages = randomAckMessages();
|
||||
} else {
|
||||
messageHeader = null;
|
||||
ackMessages = Collections.emptyMap();
|
||||
}
|
||||
|
||||
return new PutLicenseResponse(acknowledged, status, messageHeader, ackMessages);
|
||||
}
|
||||
|
||||
private static Map<String, String[]> randomAckMessages() {
|
||||
int nFeatures = randomIntBetween(1, 5);
|
||||
|
||||
Map<String, String[]> ackMessages = new HashMap<>();
|
||||
|
||||
for (int i = 0; i < nFeatures; i++) {
|
||||
String feature = randomAlphaOfLengthBetween(9, 15);
|
||||
int nMessages = randomIntBetween(1, 5);
|
||||
String[] messages = new String[nMessages];
|
||||
for (int j = 0; j < nMessages; j++) {
|
||||
messages[j] = randomAlphaOfLengthBetween(10, 30);
|
||||
}
|
||||
ackMessages.put(feature, messages);
|
||||
}
|
||||
|
||||
return ackMessages;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PutLicenseResponse doParseInstance(XContentParser parser) throws IOException {
|
||||
return PutLicenseResponse.fromXContent(parser);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PutLicenseResponse createBlankInstance() {
|
||||
return new PutLicenseResponse();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PutLicenseResponse mutateInstance(PutLicenseResponse response) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Function<PutLicenseResponse, PutLicenseResponse> mutator = randomFrom(
|
||||
r -> new PutLicenseResponse(
|
||||
r.isAcknowledged() == false,
|
||||
r.status(),
|
||||
r.acknowledgeHeader(),
|
||||
r.acknowledgeMessages()),
|
||||
r -> new PutLicenseResponse(
|
||||
r.isAcknowledged(),
|
||||
mutateStatus(r.status()),
|
||||
r.acknowledgeHeader(),
|
||||
r.acknowledgeMessages()),
|
||||
r -> {
|
||||
if (r.acknowledgeMessages().isEmpty()) {
|
||||
return new PutLicenseResponse(
|
||||
r.isAcknowledged(),
|
||||
r.status(),
|
||||
randomAlphaOfLength(10),
|
||||
randomAckMessages()
|
||||
);
|
||||
} else {
|
||||
return new PutLicenseResponse(r.isAcknowledged(), r.status());
|
||||
}
|
||||
}
|
||||
|
||||
);
|
||||
return mutator.apply(response);
|
||||
}
|
||||
|
||||
private LicensesStatus mutateStatus(LicensesStatus status) {
|
||||
return randomValueOtherThan(status, () -> randomFrom(LicensesStatus.values()));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue