Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,27 @@
*/
package org.elasticsearch.client.xpack;

import org.elasticsearch.client.license.LicenseStatus;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
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.client.license.LicenseStatus;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg;
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.optionalConstructorArg;

public class XPackInfoResponse implements ToXContentObject {
public class XPackInfoResponse {
/**
* Value of the license's expiration time if it should never expire.
*/
Expand Down Expand Up @@ -102,7 +96,11 @@ public int hashCode() {

@Override
public String toString() {
return Strings.toString(this, true, false);
return "XPackInfoResponse{" +
"buildInfo=" + buildInfo +
", licenseInfo=" + licenseInfo +
", featureSetsInfo=" + featureSetsInfo +
'}';
}

private static final ConstructingObjectParser<XPackInfoResponse, Void> PARSER = new ConstructingObjectParser<>(
Expand Down Expand Up @@ -131,41 +129,12 @@ public String toString() {
(p, c, name) -> FeatureSetsInfo.FeatureSet.PARSER.parse(p, name),
new ParseField("features"));
}

public static XPackInfoResponse fromXContent(XContentParser parser) throws IOException {
return PARSER.parse(parser, null);
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();

if (buildInfo != null) {
builder.field("build", buildInfo, params);
}

EnumSet<XPackInfoRequest.Category> categories = XPackInfoRequest.Category
.toSet(Strings.splitStringByCommaToArray(params.param("categories", "_all")));
if (licenseInfo != null) {
builder.field("license", licenseInfo, params);
} else if (categories.contains(XPackInfoRequest.Category.LICENSE)) {
// if the user requested the license info, and there is no license, we should send
// back an explicit null value (indicating there is no license). This is different
// than not adding the license info at all
builder.nullField("license");
}

if (featureSetsInfo != null) {
builder.field("features", featureSetsInfo, params);
}

if (params.paramAsBoolean("human", true)) {
builder.field("tagline", "You know, for X");
}

return builder.endObject();
}

public static class LicenseInfo implements ToXContentObject {
public static class LicenseInfo {
private final String uid;
private final String type;
private final String mode;
Expand Down Expand Up @@ -217,6 +186,17 @@ public int hashCode() {
return Objects.hash(uid, type, mode, status, expiryDate);
}

@Override
public String toString() {
return "LicenseInfo{" +
"uid='" + uid + '\'' +
", type='" + type + '\'' +
", mode='" + mode + '\'' +
", status=" + status +
", expiryDate=" + expiryDate +
'}';
}

private static final ConstructingObjectParser<LicenseInfo, Void> PARSER = new ConstructingObjectParser<>(
"license_info", true, (a, v) -> {
String uid = (String) a[0];
Expand All @@ -234,22 +214,9 @@ public int hashCode() {
PARSER.declareString(constructorArg(), new ParseField("status"));
PARSER.declareLong(optionalConstructorArg(), new ParseField("expiry_date_in_millis"));
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject()
.field("uid", uid)
.field("type", type)
.field("mode", mode)
.field("status", status.label());
if (expiryDate != BASIC_SELF_GENERATED_LICENSE_EXPIRATION_MILLIS) {
builder.timeField("expiry_date_in_millis", "expiry_date", expiryDate);
}
return builder.endObject();
}
}

public static class BuildInfo implements ToXContentObject {
public static class BuildInfo {
private final String hash;
private final String timestamp;

Expand Down Expand Up @@ -280,23 +247,23 @@ public int hashCode() {
return Objects.hash(hash, timestamp);
}

@Override
public String toString() {
return "BuildInfo{" +
"hash='" + hash + '\'' +
", timestamp='" + timestamp + '\'' +
'}';
}

private static final ConstructingObjectParser<BuildInfo, Void> PARSER = new ConstructingObjectParser<>(
"build_info", true, (a, v) -> new BuildInfo((String) a[0], (String) a[1]));
static {
PARSER.declareString(constructorArg(), new ParseField("hash"));
PARSER.declareString(constructorArg(), new ParseField("date"));
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
return builder.startObject()
.field("hash", hash)
.field("date", timestamp)
.endObject();
}
}

public static class FeatureSetsInfo implements ToXContentObject {
public static class FeatureSetsInfo {
private final Map<String, FeatureSet> featureSets;

public FeatureSetsInfo(Set<FeatureSet> featureSets) {
Expand Down Expand Up @@ -325,16 +292,13 @@ public int hashCode() {
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
List<String> names = new ArrayList<>(this.featureSets.keySet()).stream().sorted().collect(Collectors.toList());
for (String name : names) {
builder.field(name, featureSets.get(name), params);
}
return builder.endObject();
public String toString() {
return "FeatureSetsInfo{" +
"featureSets=" + featureSets +
'}';
}

public static class FeatureSet implements ToXContentObject {
public static class FeatureSet {
private final String name;
@Nullable private final String description;
private final boolean available;
Expand Down Expand Up @@ -389,6 +353,17 @@ public int hashCode() {
return Objects.hash(name, description, available, enabled, nativeCodeInfo);
}

@Override
public String toString() {
return "FeatureSet{" +
"name='" + name + '\'' +
", description='" + description + '\'' +
", available=" + available +
", enabled=" + enabled +
", nativeCodeInfo=" + nativeCodeInfo +
'}';
}

private static final ConstructingObjectParser<FeatureSet, String> PARSER = new ConstructingObjectParser<>(
"feature_set", true, (a, name) -> {
String description = (String) a[0];
Expand All @@ -404,20 +379,6 @@ public int hashCode() {
PARSER.declareBoolean(constructorArg(), new ParseField("enabled"));
PARSER.declareObject(optionalConstructorArg(), (p, name) -> p.map(), new ParseField("native_code_info"));
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
if (description != null) {
builder.field("description", description);
}
builder.field("available", available);
builder.field("enabled", enabled);
if (nativeCodeInfo != null) {
builder.field("native_code_info", nativeCodeInfo);
}
return builder.endObject();
}
}
}
}

This file was deleted.

Loading