Skip to content

Commit

Permalink
HLRC XPack Protocol clean up: Licence, Misc (#34469)
Browse files Browse the repository at this point in the history
Relates #34451
  • Loading branch information
vladimirdolzhenko authored Oct 19, 2018
1 parent 67652b5 commit 423d085
Show file tree
Hide file tree
Showing 28 changed files with 175 additions and 558 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
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) {
Expand All @@ -47,7 +47,7 @@ static Request getLicense(GetLicenseRequest getLicenseRequest) {
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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -43,15 +37,6 @@ public String label() {
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":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -42,7 +37,7 @@
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) -> {
Expand Down Expand Up @@ -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;
Expand All @@ -110,12 +106,16 @@ public PutLicenseResponse(boolean acknowledged, LicensesStatus status) {

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;
}
Expand All @@ -128,62 +128,6 @@ public String acknowledgeHeader() {
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);
}
Expand All @@ -205,5 +149,4 @@ public int hashCode() {
return Objects.hash(super.hashCode(), status, ProtocolUtils.hashCode(acknowledgeMessages), acknowledgeHeader);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -72,28 +68,4 @@ public EnumSet<Category> getCategories() {
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());
}
}
}
Loading

0 comments on commit 423d085

Please sign in to comment.