diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClientBuilder.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClientBuilder.java deleted file mode 100644 index 7109329da8198..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClientBuilder.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client; - -import org.elasticsearch.core.CheckedConsumer; -import org.elasticsearch.xcontent.NamedXContentRegistry; - -import java.io.IOException; -import java.util.Collections; -import java.util.List; - -/** - * Helper to build a {@link RestHighLevelClient}, allowing setting the low-level client that - * should be used as well as whether API compatibility should be used. - * @deprecated The High Level Rest Client is deprecated in favor of the - * - * Elasticsearch Java API Client - */ -@Deprecated(since = "7.16.0", forRemoval = true) -@SuppressWarnings("removal") -public class RestHighLevelClientBuilder { - private final RestClient restClient; - private CheckedConsumer closeHandler = RestClient::close; - private List namedXContentEntries = Collections.emptyList(); - private Boolean apiCompatibilityMode = null; - - public RestHighLevelClientBuilder(RestClient restClient) { - this.restClient = restClient; - } - - public RestHighLevelClientBuilder closeHandler(CheckedConsumer closeHandler) { - this.closeHandler = closeHandler; - return this; - } - - public RestHighLevelClientBuilder namedXContentEntries(List namedXContentEntries) { - this.namedXContentEntries = namedXContentEntries; - return this; - } - - public RestHighLevelClientBuilder setApiCompatibilityMode(Boolean enabled) { - this.apiCompatibilityMode = enabled; - return this; - } - - public RestHighLevelClient build() { - return new RestHighLevelClient(this.restClient, this.closeHandler, this.namedXContentEntries, this.apiCompatibilityMode); - } -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/SnapshotRequestConverters.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/SnapshotRequestConverters.java deleted file mode 100644 index 37e40fcd10a8b..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/SnapshotRequestConverters.java +++ /dev/null @@ -1,195 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client; - -import org.apache.http.client.methods.HttpDelete; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.client.methods.HttpPut; -import org.elasticsearch.action.admin.cluster.repositories.cleanup.CleanupRepositoryRequest; -import org.elasticsearch.action.admin.cluster.repositories.delete.DeleteRepositoryRequest; -import org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesRequest; -import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequest; -import org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryRequest; -import org.elasticsearch.action.admin.cluster.snapshots.clone.CloneSnapshotRequest; -import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest; -import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotRequest; -import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest; -import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest; -import org.elasticsearch.action.admin.cluster.snapshots.status.SnapshotsStatusRequest; -import org.elasticsearch.common.Strings; - -import java.io.IOException; - -final class SnapshotRequestConverters { - - private SnapshotRequestConverters() {} - - static Request getRepositories(GetRepositoriesRequest getRepositoriesRequest) { - String[] repositories = getRepositoriesRequest.repositories() == null ? Strings.EMPTY_ARRAY : getRepositoriesRequest.repositories(); - String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_snapshot") - .addCommaSeparatedPathParts(repositories) - .build(); - Request request = new Request(HttpGet.METHOD_NAME, endpoint); - - RequestConverters.Params parameters = new RequestConverters.Params(); - parameters.withMasterTimeout(getRepositoriesRequest.masterNodeTimeout()); - parameters.withLocal(getRepositoriesRequest.local()); - request.addParameters(parameters.asMap()); - return request; - } - - static Request createRepository(PutRepositoryRequest putRepositoryRequest) throws IOException { - String endpoint = new RequestConverters.EndpointBuilder().addPathPart("_snapshot").addPathPart(putRepositoryRequest.name()).build(); - Request request = new Request(HttpPut.METHOD_NAME, endpoint); - - RequestConverters.Params parameters = new RequestConverters.Params(); - parameters.withMasterTimeout(putRepositoryRequest.masterNodeTimeout()); - parameters.withTimeout(putRepositoryRequest.timeout()); - if (putRepositoryRequest.verify() == false) { - parameters.putParam("verify", "false"); - } - request.addParameters(parameters.asMap()); - request.setEntity(RequestConverters.createEntity(putRepositoryRequest, RequestConverters.REQUEST_BODY_CONTENT_TYPE)); - return request; - } - - static Request deleteRepository(DeleteRepositoryRequest deleteRepositoryRequest) { - String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_snapshot") - .addPathPart(deleteRepositoryRequest.name()) - .build(); - Request request = new Request(HttpDelete.METHOD_NAME, endpoint); - - RequestConverters.Params parameters = new RequestConverters.Params(); - parameters.withMasterTimeout(deleteRepositoryRequest.masterNodeTimeout()); - parameters.withTimeout(deleteRepositoryRequest.timeout()); - request.addParameters(parameters.asMap()); - return request; - } - - static Request verifyRepository(VerifyRepositoryRequest verifyRepositoryRequest) { - String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_snapshot") - .addPathPart(verifyRepositoryRequest.name()) - .addPathPartAsIs("_verify") - .build(); - Request request = new Request(HttpPost.METHOD_NAME, endpoint); - - RequestConverters.Params parameters = new RequestConverters.Params(); - parameters.withMasterTimeout(verifyRepositoryRequest.masterNodeTimeout()); - parameters.withTimeout(verifyRepositoryRequest.timeout()); - request.addParameters(parameters.asMap()); - return request; - } - - static Request cleanupRepository(CleanupRepositoryRequest cleanupRepositoryRequest) { - String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_snapshot") - .addPathPart(cleanupRepositoryRequest.name()) - .addPathPartAsIs("_cleanup") - .build(); - Request request = new Request(HttpPost.METHOD_NAME, endpoint); - - RequestConverters.Params parameters = new RequestConverters.Params(); - parameters.withMasterTimeout(cleanupRepositoryRequest.masterNodeTimeout()); - parameters.withTimeout(cleanupRepositoryRequest.timeout()); - request.addParameters(parameters.asMap()); - return request; - } - - static Request createSnapshot(CreateSnapshotRequest createSnapshotRequest) throws IOException { - String endpoint = new RequestConverters.EndpointBuilder().addPathPart("_snapshot") - .addPathPart(createSnapshotRequest.repository()) - .addPathPart(createSnapshotRequest.snapshot()) - .build(); - Request request = new Request(HttpPut.METHOD_NAME, endpoint); - RequestConverters.Params params = new RequestConverters.Params(); - params.withMasterTimeout(createSnapshotRequest.masterNodeTimeout()); - params.withWaitForCompletion(createSnapshotRequest.waitForCompletion()); - request.addParameters(params.asMap()); - request.setEntity(RequestConverters.createEntity(createSnapshotRequest, RequestConverters.REQUEST_BODY_CONTENT_TYPE)); - return request; - } - - static Request cloneSnapshot(CloneSnapshotRequest cloneSnapshotRequest) throws IOException { - String endpoint = new RequestConverters.EndpointBuilder().addPathPart("_snapshot") - .addPathPart(cloneSnapshotRequest.repository()) - .addPathPart(cloneSnapshotRequest.source()) - .addPathPart("_clone") - .addPathPart(cloneSnapshotRequest.target()) - .build(); - Request request = new Request(HttpPut.METHOD_NAME, endpoint); - RequestConverters.Params params = new RequestConverters.Params(); - params.withMasterTimeout(cloneSnapshotRequest.masterNodeTimeout()); - request.addParameters(params.asMap()); - request.setEntity(RequestConverters.createEntity(cloneSnapshotRequest, RequestConverters.REQUEST_BODY_CONTENT_TYPE)); - return request; - } - - static Request getSnapshots(GetSnapshotsRequest getSnapshotsRequest) { - RequestConverters.EndpointBuilder endpointBuilder = new RequestConverters.EndpointBuilder().addPathPartAsIs("_snapshot") - .addCommaSeparatedPathParts(getSnapshotsRequest.repositories()); - String endpoint; - if (getSnapshotsRequest.snapshots().length == 0) { - endpoint = endpointBuilder.addPathPart("_all").build(); - } else { - endpoint = endpointBuilder.addCommaSeparatedPathParts(getSnapshotsRequest.snapshots()).build(); - } - - Request request = new Request(HttpGet.METHOD_NAME, endpoint); - - RequestConverters.Params parameters = new RequestConverters.Params(); - parameters.withMasterTimeout(getSnapshotsRequest.masterNodeTimeout()); - parameters.putParam("ignore_unavailable", Boolean.toString(getSnapshotsRequest.ignoreUnavailable())); - parameters.putParam("verbose", Boolean.toString(getSnapshotsRequest.verbose())); - request.addParameters(parameters.asMap()); - return request; - } - - static Request snapshotsStatus(SnapshotsStatusRequest snapshotsStatusRequest) { - String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_snapshot") - .addPathPart(snapshotsStatusRequest.repository()) - .addCommaSeparatedPathParts(snapshotsStatusRequest.snapshots()) - .addPathPartAsIs("_status") - .build(); - Request request = new Request(HttpGet.METHOD_NAME, endpoint); - - RequestConverters.Params parameters = new RequestConverters.Params(); - parameters.withMasterTimeout(snapshotsStatusRequest.masterNodeTimeout()); - parameters.withIgnoreUnavailable(snapshotsStatusRequest.ignoreUnavailable()); - request.addParameters(parameters.asMap()); - return request; - } - - static Request restoreSnapshot(RestoreSnapshotRequest restoreSnapshotRequest) throws IOException { - String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_snapshot") - .addPathPart(restoreSnapshotRequest.repository()) - .addPathPart(restoreSnapshotRequest.snapshot()) - .addPathPartAsIs("_restore") - .build(); - Request request = new Request(HttpPost.METHOD_NAME, endpoint); - RequestConverters.Params parameters = new RequestConverters.Params(); - parameters.withMasterTimeout(restoreSnapshotRequest.masterNodeTimeout()); - parameters.withWaitForCompletion(restoreSnapshotRequest.waitForCompletion()); - request.addParameters(parameters.asMap()); - request.setEntity(RequestConverters.createEntity(restoreSnapshotRequest, RequestConverters.REQUEST_BODY_CONTENT_TYPE)); - return request; - } - - static Request deleteSnapshot(DeleteSnapshotRequest deleteSnapshotRequest) { - String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_snapshot") - .addPathPart(deleteSnapshotRequest.repository()) - .addCommaSeparatedPathParts(deleteSnapshotRequest.snapshots()) - .build(); - Request request = new Request(HttpDelete.METHOD_NAME, endpoint); - - RequestConverters.Params parameters = new RequestConverters.Params(); - parameters.withMasterTimeout(deleteSnapshotRequest.masterNodeTimeout()); - request.addParameters(parameters.asMap()); - return request; - } -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/XPackRequestConverters.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/XPackRequestConverters.java deleted file mode 100644 index d5605d2211fcf..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/XPackRequestConverters.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client; - -import org.apache.http.client.methods.HttpGet; -import org.elasticsearch.client.xpack.XPackInfoRequest; -import org.elasticsearch.client.xpack.XPackUsageRequest; - -import java.util.EnumSet; -import java.util.Locale; -import java.util.stream.Collectors; - -final class XPackRequestConverters { - - private XPackRequestConverters() {} - - static Request info(XPackInfoRequest infoRequest) { - Request request = new Request(HttpGet.METHOD_NAME, "/_xpack"); - if (false == infoRequest.isVerbose()) { - request.addParameter("human", "false"); - } - if (false == infoRequest.getCategories().equals(EnumSet.allOf(XPackInfoRequest.Category.class))) { - request.addParameter( - "categories", - infoRequest.getCategories().stream().map(c -> c.toString().toLowerCase(Locale.ROOT)).collect(Collectors.joining(",")) - ); - } - return request; - } - - static Request usage(XPackUsageRequest usageRequest) { - Request request = new Request(HttpGet.METHOD_NAME, "/_xpack/usage"); - RequestConverters.Params parameters = new RequestConverters.Params(); - parameters.withMasterTimeout(usageRequest.masterNodeTimeout()); - request.addParameters(parameters.asMap()); - return request; - } -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/common/ProtocolUtils.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/common/ProtocolUtils.java deleted file mode 100644 index 181cb983f1514..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/common/ProtocolUtils.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.common; - -import java.util.Arrays; -import java.util.Map; - -/** - * Common utilities used for XPack protocol classes - */ -public final class ProtocolUtils { - - /** - * Implements equals for a map of string arrays - * - * The map of string arrays is used in some XPack protocol classes but does't work with equal. - */ - public static boolean equals(Map a, Map b) { - if (a == null) { - return b == null; - } - if (b == null) { - return false; - } - if (a.size() != b.size()) { - return false; - } - for (Map.Entry entry : a.entrySet()) { - String[] val = entry.getValue(); - String key = entry.getKey(); - if (val == null) { - if (b.get(key) != null || b.containsKey(key) == false) { - return false; - } - } else { - if (Arrays.equals(val, b.get(key)) == false) { - return false; - } - } - } - return true; - } - - /** - * Implements hashCode for map of string arrays - * - * The map of string arrays does't work with hashCode. - */ - public static int hashCode(Map a) { - int hash = 0; - for (Map.Entry entry : a.entrySet()) - hash += Arrays.hashCode(entry.getValue()); - return hash; - } -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/common/TimeUtil.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/common/TimeUtil.java deleted file mode 100644 index 5971dea044daa..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/common/TimeUtil.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ -package org.elasticsearch.client.common; - -import org.elasticsearch.common.time.DateFormatters; -import org.elasticsearch.xcontent.XContentParser; - -import java.io.IOException; -import java.time.Instant; -import java.time.format.DateTimeFormatter; -import java.util.Date; - -public final class TimeUtil { - - /** - * Parse out a Date object given the current parser and field name. - * - * @param parser current XContentParser - * @param fieldName the field's preferred name (utilized in exception) - * @return parsed Date object - * @throws IOException from XContentParser - */ - public static Date parseTimeField(XContentParser parser, String fieldName) throws IOException { - if (parser.currentToken() == XContentParser.Token.VALUE_NUMBER) { - return new Date(parser.longValue()); - } else if (parser.currentToken() == XContentParser.Token.VALUE_STRING) { - return new Date(DateFormatters.from(DateTimeFormatter.ISO_INSTANT.parse(parser.text())).toInstant().toEpochMilli()); - } - throw new IllegalArgumentException("unexpected token [" + parser.currentToken() + "] for [" + fieldName + "]"); - } - - /** - * Parse out an Instant object given the current parser and field name. - * - * @param parser current XContentParser - * @param fieldName the field's preferred name (utilized in exception) - * @return parsed Instant object - * @throws IOException from XContentParser - */ - public static Instant parseTimeFieldToInstant(XContentParser parser, String fieldName) throws IOException { - if (parser.currentToken() == XContentParser.Token.VALUE_NUMBER) { - return Instant.ofEpochMilli(parser.longValue()); - } else if (parser.currentToken() == XContentParser.Token.VALUE_STRING) { - return DateFormatters.from(DateTimeFormatter.ISO_INSTANT.parse(parser.text())).toInstant(); - } - throw new IllegalArgumentException("unexpected token [" + parser.currentToken() + "] for [" + fieldName + "]"); - } - -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/common/XContentSource.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/common/XContentSource.java deleted file mode 100644 index e01e61fda5884..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/common/XContentSource.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.common; - -import org.elasticsearch.xcontent.ObjectPath; -import org.elasticsearch.xcontent.XContentParser; -import org.elasticsearch.xcontent.XContentUtils; - -import java.io.IOException; -import java.util.List; -import java.util.Map; - -/** - * Encapsulates the xcontent source - */ -public class XContentSource { - - private final Object data; - - /** - * Constructs a new XContentSource out of the given parser - */ - public XContentSource(XContentParser parser) throws IOException { - this.data = XContentUtils.readValue(parser, parser.nextToken()); - } - - /** - * @return true if the top level value of the source is a map - */ - public boolean isMap() { - return data instanceof Map; - } - - /** - * @return The source as a map - */ - @SuppressWarnings("unchecked") - public Map getAsMap() { - return (Map) data; - } - - /** - * @return true if the top level value of the source is a list - */ - public boolean isList() { - return data instanceof List; - } - - /** - * @return The source as a list - */ - @SuppressWarnings("unchecked") - public List getAsList() { - return (List) data; - } - - /** - * Extracts a value identified by the given path in the source. - * - * @param path a dot notation path to the requested value - * @return The extracted value or {@code null} if no value is associated with the given path - */ - @SuppressWarnings("unchecked") - public T getValue(String path) { - return (T) ObjectPath.eval(path, data); - } - -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/xpack/XPackInfoRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/xpack/XPackInfoRequest.java deleted file mode 100644 index 42993e91da26b..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/xpack/XPackInfoRequest.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ -package org.elasticsearch.client.xpack; - -import org.elasticsearch.client.Validatable; - -import java.util.EnumSet; -import java.util.Locale; - -/** - * Fetch information about X-Pack from the cluster. - */ -public class XPackInfoRequest implements Validatable { - - public enum Category { - BUILD, - LICENSE, - FEATURES; - - public static EnumSet toSet(String... categories) { - EnumSet set = EnumSet.noneOf(Category.class); - for (String category : categories) { - switch (category) { - case "_all": - return EnumSet.allOf(Category.class); - case "_none": - return EnumSet.noneOf(Category.class); - default: - set.add(Category.valueOf(category.toUpperCase(Locale.ROOT))); - } - } - return set; - } - } - - private boolean verbose; - private EnumSet categories = EnumSet.noneOf(Category.class); - - public XPackInfoRequest() {} - - public void setVerbose(boolean verbose) { - this.verbose = verbose; - } - - public boolean isVerbose() { - return verbose; - } - - public void setCategories(EnumSet categories) { - this.categories = categories; - } - - public EnumSet getCategories() { - return categories; - } - -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/xpack/XPackInfoResponse.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/xpack/XPackInfoResponse.java deleted file mode 100644 index e95fcc205da5f..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/xpack/XPackInfoResponse.java +++ /dev/null @@ -1,408 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ -package org.elasticsearch.client.xpack; - -import org.elasticsearch.client.license.LicenseStatus; -import org.elasticsearch.common.util.Maps; -import org.elasticsearch.core.Nullable; -import org.elasticsearch.xcontent.ConstructingObjectParser; -import org.elasticsearch.xcontent.ObjectParser.ValueType; -import org.elasticsearch.xcontent.ParseField; -import org.elasticsearch.xcontent.XContentParser; - -import java.io.IOException; -import java.util.Collections; -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 static org.elasticsearch.xcontent.ConstructingObjectParser.constructorArg; -import static org.elasticsearch.xcontent.ConstructingObjectParser.optionalConstructorArg; - -public class XPackInfoResponse { - /** - * Value of the license's expiration time if it should never expire. - */ - public static final long BASIC_SELF_GENERATED_LICENSE_EXPIRATION_MILLIS = Long.MAX_VALUE - TimeUnit.HOURS.toMillis(24 * 365); - // TODO move this constant to License.java once we move License.java to the protocol jar - - @Nullable - private BuildInfo buildInfo; - @Nullable - private LicenseInfo licenseInfo; - @Nullable - private FeatureSetsInfo featureSetsInfo; - - public XPackInfoResponse() {} - - public XPackInfoResponse(@Nullable BuildInfo buildInfo, @Nullable LicenseInfo licenseInfo, @Nullable FeatureSetsInfo featureSetsInfo) { - this.buildInfo = buildInfo; - this.licenseInfo = licenseInfo; - this.featureSetsInfo = featureSetsInfo; - } - - /** - * @return The build info (incl. build hash and timestamp) - */ - public BuildInfo getBuildInfo() { - return buildInfo; - } - - /** - * @return The current license info (incl. UID, type/mode. status and expiry date). May return {@code null} when no - * license is currently installed. - */ - public LicenseInfo getLicenseInfo() { - return licenseInfo; - } - - /** - * @return The current status of the feature sets in X-Pack. Feature sets describe the features available/enabled in X-Pack. - */ - public FeatureSetsInfo getFeatureSetsInfo() { - return featureSetsInfo; - } - - @Override - public boolean equals(Object other) { - if (other == null || other.getClass() != getClass()) return false; - if (this == other) return true; - XPackInfoResponse rhs = (XPackInfoResponse) other; - return Objects.equals(buildInfo, rhs.buildInfo) - && Objects.equals(licenseInfo, rhs.licenseInfo) - && Objects.equals(featureSetsInfo, rhs.featureSetsInfo); - } - - @Override - public int hashCode() { - return Objects.hash(buildInfo, licenseInfo, featureSetsInfo); - } - - @Override - public String toString() { - return "XPackInfoResponse{" - + "buildInfo=" - + buildInfo - + ", licenseInfo=" - + licenseInfo - + ", featureSetsInfo=" - + featureSetsInfo - + '}'; - } - - private static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( - "xpack_info_response", - true, - (a, v) -> { - BuildInfo buildInfo = (BuildInfo) a[0]; - LicenseInfo licenseInfo = (LicenseInfo) a[1]; - @SuppressWarnings("unchecked") // This is how constructing object parser works - List featureSets = (List) a[2]; - FeatureSetsInfo featureSetsInfo = featureSets == null ? null : new FeatureSetsInfo(new HashSet<>(featureSets)); - return new XPackInfoResponse(buildInfo, licenseInfo, featureSetsInfo); - } - ); - static { - PARSER.declareObject(optionalConstructorArg(), BuildInfo.PARSER, new ParseField("build")); - /* - * licenseInfo is sort of "double optional" because it is - * optional but it can also be send as `null`. - */ - PARSER.declareField(optionalConstructorArg(), (p, v) -> { - if (p.currentToken() == XContentParser.Token.VALUE_NULL) { - return null; - } - return LicenseInfo.PARSER.parse(p, v); - }, new ParseField("license"), ValueType.OBJECT_OR_NULL); - PARSER.declareNamedObjects( - optionalConstructorArg(), - (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); - } - - public static class LicenseInfo { - private final String uid; - private final String type; - private final String mode; - private final LicenseStatus status; - private final long expiryDate; - - public LicenseInfo(String uid, String type, String mode, LicenseStatus status, long expiryDate) { - this.uid = uid; - this.type = type; - this.mode = mode; - this.status = status; - this.expiryDate = expiryDate; - } - - public String getUid() { - return uid; - } - - public String getType() { - return type; - } - - public String getMode() { - return mode; - } - - public long getExpiryDate() { - return expiryDate; - } - - public LicenseStatus getStatus() { - return status; - } - - @Override - public boolean equals(Object other) { - if (other == null || other.getClass() != getClass()) return false; - if (this == other) return true; - LicenseInfo rhs = (LicenseInfo) other; - return Objects.equals(uid, rhs.uid) - && Objects.equals(type, rhs.type) - && Objects.equals(mode, rhs.mode) - && Objects.equals(status, rhs.status) - && expiryDate == rhs.expiryDate; - } - - @Override - 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 PARSER = new ConstructingObjectParser<>( - "license_info", - true, - (a, v) -> { - String uid = (String) a[0]; - String type = (String) a[1]; - String mode = (String) a[2]; - LicenseStatus status = LicenseStatus.fromString((String) a[3]); - Long expiryDate = (Long) a[4]; - long primitiveExpiryDate = expiryDate == null ? BASIC_SELF_GENERATED_LICENSE_EXPIRATION_MILLIS : expiryDate; - return new LicenseInfo(uid, type, mode, status, primitiveExpiryDate); - } - ); - static { - PARSER.declareString(constructorArg(), new ParseField("uid")); - PARSER.declareString(constructorArg(), new ParseField("type")); - PARSER.declareString(constructorArg(), new ParseField("mode")); - PARSER.declareString(constructorArg(), new ParseField("status")); - PARSER.declareLong(optionalConstructorArg(), new ParseField("expiry_date_in_millis")); - } - } - - public static class BuildInfo { - private final String hash; - private final String timestamp; - - public BuildInfo(String hash, String timestamp) { - this.hash = hash; - this.timestamp = timestamp; - } - - public String getHash() { - return hash; - } - - public String getTimestamp() { - return timestamp; - } - - @Override - public boolean equals(Object other) { - if (other == null || other.getClass() != getClass()) return false; - if (this == other) return true; - BuildInfo rhs = (BuildInfo) other; - return Objects.equals(hash, rhs.hash) && Objects.equals(timestamp, rhs.timestamp); - } - - @Override - public int hashCode() { - return Objects.hash(hash, timestamp); - } - - @Override - public String toString() { - return "BuildInfo{" + "hash='" + hash + '\'' + ", timestamp='" + timestamp + '\'' + '}'; - } - - private static final ConstructingObjectParser 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")); - } - } - - public static class FeatureSetsInfo { - private final Map featureSets; - - public FeatureSetsInfo(Set featureSets) { - Map map = Maps.newMapWithExpectedSize(featureSets.size()); - for (FeatureSet featureSet : featureSets) { - map.put(featureSet.name, featureSet); - } - this.featureSets = Collections.unmodifiableMap(map); - } - - public Map getFeatureSets() { - return featureSets; - } - - @Override - public boolean equals(Object other) { - if (other == null || other.getClass() != getClass()) return false; - if (this == other) return true; - FeatureSetsInfo rhs = (FeatureSetsInfo) other; - return Objects.equals(featureSets, rhs.featureSets); - } - - @Override - public int hashCode() { - return Objects.hash(featureSets); - } - - @Override - public String toString() { - return "FeatureSetsInfo{" + "featureSets=" + featureSets + '}'; - } - - public static class FeatureSet { - private final String name; - @Nullable - private final String description; - private final boolean available; - private final boolean enabled; - @Nullable - private final Map nativeCodeInfo; - - public FeatureSet( - String name, - @Nullable String description, - boolean available, - boolean enabled, - @Nullable Map nativeCodeInfo - ) { - this.name = name; - this.description = description; - this.available = available; - this.enabled = enabled; - this.nativeCodeInfo = nativeCodeInfo; - } - - public String name() { - return name; - } - - public boolean available() { - return available; - } - - public boolean enabled() { - return enabled; - } - - /** - * Return native code info - * @deprecated Use ML info api to find native code info - */ - @Deprecated - @Nullable - public Map nativeCodeInfo() { - return nativeCodeInfo; - } - - @Override - public boolean equals(Object other) { - if (other == null || other.getClass() != getClass()) return false; - if (this == other) return true; - FeatureSet rhs = (FeatureSet) other; - return Objects.equals(name, rhs.name) - && Objects.equals(description, rhs.description) - && available == rhs.available - && enabled == rhs.enabled - && Objects.equals(nativeCodeInfo, rhs.nativeCodeInfo); - } - - @Override - 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 PARSER = new ConstructingObjectParser<>( - "feature_set", - true, - (a, name) -> { - String description = (String) a[0]; - boolean available = (Boolean) a[1]; - boolean enabled = (Boolean) a[2]; - @SuppressWarnings("unchecked") // Matches up with declaration below - Map nativeCodeInfo = (Map) a[3]; - return new FeatureSet(name, description, available, enabled, nativeCodeInfo); - } - ); - static { - PARSER.declareString(optionalConstructorArg(), new ParseField("description")); - PARSER.declareBoolean(constructorArg(), new ParseField("available")); - PARSER.declareBoolean(constructorArg(), new ParseField("enabled")); - PARSER.declareObject(optionalConstructorArg(), (p, name) -> p.map(), new ParseField("native_code_info")); - } - } - } -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/xpack/XPackUsageRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/xpack/XPackUsageRequest.java deleted file mode 100644 index 3fe8f967a028b..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/xpack/XPackUsageRequest.java +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ -package org.elasticsearch.client.xpack; - -import org.elasticsearch.client.TimedRequest; - -public class XPackUsageRequest extends TimedRequest { - -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/xpack/XPackUsageResponse.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/xpack/XPackUsageResponse.java deleted file mode 100644 index f26e0d203ac6d..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/xpack/XPackUsageResponse.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.xpack; - -import org.elasticsearch.xcontent.XContentParser; - -import java.io.IOException; -import java.util.Map; -import java.util.stream.Collectors; - -/** - * Response object from calling the xpack usage api. - * - * Usage information for each feature is accessible through {@link #getUsages()}. - */ -public class XPackUsageResponse { - - private final Map> usages; - - private XPackUsageResponse(Map> usages) { - this.usages = usages; - } - - @SuppressWarnings("unchecked") - private static Map castMap(Object value) { - return (Map) value; - } - - /** Return a map from feature name to usage information for that feature. */ - public Map> getUsages() { - return usages; - } - - public static XPackUsageResponse fromXContent(XContentParser parser) throws IOException { - Map rawMap = parser.map(); - Map> usages = rawMap.entrySet() - .stream() - .collect(Collectors.toMap(Map.Entry::getKey, e -> castMap(e.getValue()))); - return new XPackUsageResponse(usages); - } -}