From 125958eb2c682b38aad512515774bda3d7548f60 Mon Sep 17 00:00:00 2001 From: Nick Knize Date: Sat, 30 Jan 2021 00:23:18 -0600 Subject: [PATCH] Remove the Elastic license file, all checks for this license and the license REST APIs. (#12) Co-authored-by: Rabi Panda Signed-off-by: Peter Nied --- build.gradle | 11 - ...nternalDistributionArchiveCheckPlugin.java | 70 +--- .../elastic-license-header.txt | 5 - .../elasticsearch/client/LicenseClient.java | 239 ----------- .../client/LicenseRequestConverters.java | 105 ----- .../client/RestHighLevelClient.java | 25 -- .../org/elasticsearch/client/XPackClient.java | 99 ----- .../client/XPackRequestConverters.java | 54 --- .../client/license/DeleteLicenseRequest.java | 25 -- .../license/GetBasicStatusResponse.java | 79 ---- .../client/license/GetLicenseRequest.java | 38 -- .../client/license/GetLicenseResponse.java | 36 -- .../license/GetTrialStatusResponse.java | 80 ---- .../client/license/LicenseStatus.java | 52 --- .../client/license/LicensesStatus.java | 68 ---- .../client/license/PutLicenseRequest.java | 47 --- .../client/license/PutLicenseResponse.java | 152 ------- .../client/license/StartBasicRequest.java | 38 -- .../client/license/StartBasicResponse.java | 156 ------- .../client/license/StartTrialRequest.java | 50 --- .../client/license/StartTrialResponse.java | 188 --------- .../client/license/package-info.java | 24 -- .../client/xpack/XPackInfoRequest.java | 71 ---- .../client/xpack/XPackInfoResponse.java | 384 ------------------ .../client/xpack/XPackUsageRequest.java | 25 -- .../client/xpack/XPackUsageResponse.java | 57 --- .../org/elasticsearch/client/LicenseIT.java | 213 ---------- .../client/LicenseRequestConvertersTests.java | 147 ------- .../client/XPackInfoResponseTests.java | 122 ------ .../client/XPackRequestConvertersTests.java | 62 --- .../LicensingDocumentationIT.java | 367 ----------------- .../license/GetBasicStatusResponseTests.java | 47 --- .../license/GetTrialStatusResponseTests.java | 47 --- .../client/license/LicenseStatusTests.java | 38 -- .../license/PutLicenseResponseTests.java | 89 ---- .../license/StartBasicResponseTests.java | 85 ---- distribution/archives/build.gradle | 2 +- distribution/build.gradle | 7 +- distribution/docker/build.gradle | 2 +- distribution/packages/build.gradle | 47 +-- gradle/ide.gradle | 7 - licenses/ELASTIC-LICENSE.txt | 223 ---------- 42 files changed, 13 insertions(+), 3670 deletions(-) delete mode 100644 buildSrc/src/main/resources/license-headers/elastic-license-header.txt delete mode 100644 client/rest-high-level/src/main/java/org/elasticsearch/client/LicenseClient.java delete mode 100644 client/rest-high-level/src/main/java/org/elasticsearch/client/LicenseRequestConverters.java delete mode 100644 client/rest-high-level/src/main/java/org/elasticsearch/client/XPackClient.java delete mode 100644 client/rest-high-level/src/main/java/org/elasticsearch/client/XPackRequestConverters.java delete mode 100644 client/rest-high-level/src/main/java/org/elasticsearch/client/license/DeleteLicenseRequest.java delete mode 100644 client/rest-high-level/src/main/java/org/elasticsearch/client/license/GetBasicStatusResponse.java delete mode 100644 client/rest-high-level/src/main/java/org/elasticsearch/client/license/GetLicenseRequest.java delete mode 100644 client/rest-high-level/src/main/java/org/elasticsearch/client/license/GetLicenseResponse.java delete mode 100644 client/rest-high-level/src/main/java/org/elasticsearch/client/license/GetTrialStatusResponse.java delete mode 100644 client/rest-high-level/src/main/java/org/elasticsearch/client/license/LicenseStatus.java delete mode 100644 client/rest-high-level/src/main/java/org/elasticsearch/client/license/LicensesStatus.java delete mode 100644 client/rest-high-level/src/main/java/org/elasticsearch/client/license/PutLicenseRequest.java delete mode 100644 client/rest-high-level/src/main/java/org/elasticsearch/client/license/PutLicenseResponse.java delete mode 100644 client/rest-high-level/src/main/java/org/elasticsearch/client/license/StartBasicRequest.java delete mode 100644 client/rest-high-level/src/main/java/org/elasticsearch/client/license/StartBasicResponse.java delete mode 100644 client/rest-high-level/src/main/java/org/elasticsearch/client/license/StartTrialRequest.java delete mode 100644 client/rest-high-level/src/main/java/org/elasticsearch/client/license/StartTrialResponse.java delete mode 100644 client/rest-high-level/src/main/java/org/elasticsearch/client/license/package-info.java delete mode 100644 client/rest-high-level/src/main/java/org/elasticsearch/client/xpack/XPackInfoRequest.java delete mode 100644 client/rest-high-level/src/main/java/org/elasticsearch/client/xpack/XPackInfoResponse.java delete mode 100644 client/rest-high-level/src/main/java/org/elasticsearch/client/xpack/XPackUsageRequest.java delete mode 100644 client/rest-high-level/src/main/java/org/elasticsearch/client/xpack/XPackUsageResponse.java delete mode 100644 client/rest-high-level/src/test/java/org/elasticsearch/client/LicenseIT.java delete mode 100644 client/rest-high-level/src/test/java/org/elasticsearch/client/LicenseRequestConvertersTests.java delete mode 100644 client/rest-high-level/src/test/java/org/elasticsearch/client/XPackInfoResponseTests.java delete mode 100644 client/rest-high-level/src/test/java/org/elasticsearch/client/XPackRequestConvertersTests.java delete mode 100644 client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/LicensingDocumentationIT.java delete mode 100644 client/rest-high-level/src/test/java/org/elasticsearch/client/license/GetBasicStatusResponseTests.java delete mode 100644 client/rest-high-level/src/test/java/org/elasticsearch/client/license/GetTrialStatusResponseTests.java delete mode 100644 client/rest-high-level/src/test/java/org/elasticsearch/client/license/LicenseStatusTests.java delete mode 100644 client/rest-high-level/src/test/java/org/elasticsearch/client/license/PutLicenseResponseTests.java delete mode 100644 client/rest-high-level/src/test/java/org/elasticsearch/client/license/StartBasicResponseTests.java delete mode 100644 licenses/ELASTIC-LICENSE.txt diff --git a/build.gradle b/build.gradle index e88c4d622e6..913af689268 100644 --- a/build.gradle +++ b/build.gradle @@ -55,14 +55,6 @@ allprojects { description = "Elasticsearch subproject ${project.path}" } -String licenseCommit -if (VersionProperties.elasticsearch.toString().endsWith('-SNAPSHOT')) { - licenseCommit = BuildParams.gitRevision ?: "master" // leniency for non git builds -} else { - licenseCommit = "v${version}" -} -String elasticLicenseUrl = "https://raw.githubusercontent.com/elastic/elasticsearch/${licenseCommit}/licenses/ELASTIC-LICENSE.txt" - configure(allprojects - project(':distribution:archives:integ-test-zip')) { project.pluginManager.withPlugin('nebula.maven-base-publish') { if (project.pluginManager.hasPlugin('elasticsearch.build') == false) { @@ -76,9 +68,6 @@ subprojects { project.ext.licenseName = 'The Apache Software License, Version 2.0' project.ext.licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt' - // But stick the Elastic license url in project.ext so we can get it if we need to switch to it - project.ext.elasticLicenseUrl = elasticLicenseUrl - // we only use maven publish to add tasks for pom generation plugins.withType(MavenPublishPlugin).whenPluginAdded { publishing { diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/internal/InternalDistributionArchiveCheckPlugin.java b/buildSrc/src/main/java/org/elasticsearch/gradle/internal/InternalDistributionArchiveCheckPlugin.java index e8016e162ad..623f3ce541b 100644 --- a/buildSrc/src/main/java/org/elasticsearch/gradle/internal/InternalDistributionArchiveCheckPlugin.java +++ b/buildSrc/src/main/java/org/elasticsearch/gradle/internal/InternalDistributionArchiveCheckPlugin.java @@ -72,18 +72,6 @@ public class InternalDistributionArchiveCheckPlugin implements Plugin { task.dependsOn(checkLicense); task.dependsOn(checkNotice); }); - - String projectName = project.getName(); - if (projectName.contains("oss") == false && (projectName.contains("zip") || projectName.contains("tar"))) { - project.getExtensions().add("licenseName", "Elastic License"); - project.getExtensions().add("licenseUrl", project.getExtensions().getExtraProperties().get("elasticLicenseUrl")); - TaskProvider checkMlCppNoticeTask = registerCheckMlCppNoticeTask( - project, - checkExtraction, - distributionArchiveCheckExtension - ); - checkTask.configure(task -> task.dependsOn(checkMlCppNoticeTask)); - } } private File calculateArchiveExtractionDir(Project project) { @@ -96,40 +84,6 @@ public class InternalDistributionArchiveCheckPlugin implements Plugin { return new File(project.getBuildDir(), "zip-extracted"); } - private static TaskProvider registerCheckMlCppNoticeTask( - Project project, - TaskProvider checkExtraction, - DistributionArchiveCheckExtension extension - ) { - TaskProvider checkMlCppNoticeTask = project.getTasks().register("checkMlCppNotice", task -> { - task.dependsOn(checkExtraction); - task.doLast(new Action() { - @Override - public void execute(Task task) { - // this is just a small sample from the C++ notices, - // the idea being that if we've added these lines we've probably added all the required lines - final List expectedLines = extension.expectedMlLicenses.get(); - final Path noticePath = checkExtraction.get() - .getDestinationDir() - .toPath() - .resolve("elasticsearch-" + VersionProperties.getElasticsearch() + "/modules/x-pack-ml/NOTICE.txt"); - final List actualLines; - try { - actualLines = Files.readAllLines(noticePath); - for (final String expectedLine : expectedLines) { - if (actualLines.contains(expectedLine) == false) { - throw new GradleException("expected [" + noticePath + " to contain [" + expectedLine + "] but it did not"); - } - } - } catch (IOException ioException) { - ioException.printStackTrace(); - } - } - }); - }); - return checkMlCppNoticeTask; - } - private TaskProvider registerCheckNoticeTask(Project project, TaskProvider checkExtraction) { return project.getTasks().register("checkNotice", task -> { task.dependsOn(checkExtraction); @@ -153,12 +107,7 @@ public class InternalDistributionArchiveCheckPlugin implements Plugin { task.doLast(new Action() { @Override public void execute(Task task) { - String licenseFilename = null; - if (project.getName().contains("oss-") || project.getName().equals("integ-test-zip")) { - licenseFilename = "APACHE-LICENSE-2.0.txt"; - } else { - licenseFilename = "ELASTIC-LICENSE.txt"; - } + String licenseFilename = "APACHE-LICENSE-2.0.txt"; final List licenseLines; try { licenseLines = Files.readAllLines(project.getRootDir().toPath().resolve("licenses/" + licenseFilename)); @@ -208,29 +157,12 @@ public class InternalDistributionArchiveCheckPlugin implements Plugin { } } - private static boolean toolExists(Project project) { - if (project.getName().contains("tar")) { - return tarExists(); - } else { - assert project.getName().contains("zip"); - return zipExists(); - } - } - private static void assertNoClassFile(File file) { if (file.getName().endsWith(".class")) { throw new GradleException("Detected class file in distribution ('" + file.getName() + "')"); } } - private static boolean zipExists() { - return new File("/bin/unzip").exists() || new File("/usr/bin/unzip").exists() || new File("/usr/local/bin/unzip").exists(); - } - - private static boolean tarExists() { - return new File("/bin/tar").exists() || new File("/usr/bin/tar").exists() || new File("/usr/local/bin/tar").exists(); - } - private Object distTaskOutput(TaskProvider buildDistTask) { return new Callable() { @Override diff --git a/buildSrc/src/main/resources/license-headers/elastic-license-header.txt b/buildSrc/src/main/resources/license-headers/elastic-license-header.txt deleted file mode 100644 index 30371a1ef54..00000000000 --- a/buildSrc/src/main/resources/license-headers/elastic-license-header.txt +++ /dev/null @@ -1,5 +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; - * you may not use this file except in compliance with the Elastic License. - */ \ No newline at end of file diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/LicenseClient.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/LicenseClient.java deleted file mode 100644 index e0db84e6b2b..00000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/LicenseClient.java +++ /dev/null @@ -1,239 +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.client; - -import org.apache.http.HttpEntity; -import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.support.master.AcknowledgedResponse; -import org.elasticsearch.client.license.StartTrialRequest; -import org.elasticsearch.client.license.StartTrialResponse; -import org.elasticsearch.client.license.StartBasicRequest; -import org.elasticsearch.client.license.StartBasicResponse; -import org.elasticsearch.client.license.GetBasicStatusResponse; -import org.elasticsearch.client.license.GetTrialStatusResponse; -import org.elasticsearch.common.Strings; -import org.elasticsearch.common.io.Streams; -import org.elasticsearch.common.xcontent.DeprecationHandler; -import org.elasticsearch.common.xcontent.NamedXContentRegistry; -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.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; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; - -import static java.util.Collections.emptySet; -import static java.util.Collections.singleton; - -/** - * A wrapper for the {@link RestHighLevelClient} that provides methods for - * accessing the Elastic License-related methods - *

- * See the - * X-Pack Licensing APIs on elastic.co for more information. - */ -public final class LicenseClient { - - private final RestHighLevelClient restHighLevelClient; - - LicenseClient(RestHighLevelClient restHighLevelClient) { - this.restHighLevelClient = restHighLevelClient; - } - - /** - * Updates license for the cluster. - * @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized - * @return the response - * @throws IOException in case there is a problem sending the request or parsing back the response - */ - public PutLicenseResponse putLicense(PutLicenseRequest request, RequestOptions options) throws IOException { - return restHighLevelClient.performRequestAndParseEntity(request, LicenseRequestConverters::putLicense, options, - PutLicenseResponse::fromXContent, emptySet()); - } - - /** - * Asynchronously updates license for the cluster. - * @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized - * @param listener the listener to be notified upon request completion - * @return cancellable that may be used to cancel the request - */ - public Cancellable putLicenseAsync(PutLicenseRequest request, RequestOptions options, ActionListener listener) { - return restHighLevelClient.performRequestAsyncAndParseEntity(request, LicenseRequestConverters::putLicense, options, - PutLicenseResponse::fromXContent, listener, emptySet()); - } - - /** - * Returns the current license for the cluster. - * @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized - * @return the response - * @throws IOException in case there is a problem sending the request or parsing back the response - */ - public GetLicenseResponse getLicense(GetLicenseRequest request, RequestOptions options) throws IOException { - return restHighLevelClient.performRequest(request, LicenseRequestConverters::getLicense, options, - response -> new GetLicenseResponse(convertResponseToJson(response)), emptySet()); - } - - /** - * Asynchronously returns the current license for the cluster cluster. - * @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized - * @param listener the listener to be notified upon request completion - * @return cancellable that may be used to cancel the request - */ - public Cancellable getLicenseAsync(GetLicenseRequest request, RequestOptions options, ActionListener listener) { - return restHighLevelClient.performRequestAsync(request, LicenseRequestConverters::getLicense, options, - response -> new GetLicenseResponse(convertResponseToJson(response)), listener, emptySet()); - } - - /** - * Deletes license from the cluster. - * @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized - * @return the response - * @throws IOException in case there is a problem sending the request or parsing back the response - */ - public AcknowledgedResponse deleteLicense(DeleteLicenseRequest request, RequestOptions options) throws IOException { - return restHighLevelClient.performRequestAndParseEntity(request, LicenseRequestConverters::deleteLicense, options, - AcknowledgedResponse::fromXContent, emptySet()); - } - - /** - * Asynchronously deletes license from the cluster. - * @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized - * @param listener the listener to be notified upon request completion - * @return cancellable that may be used to cancel the request - */ - public Cancellable deleteLicenseAsync(DeleteLicenseRequest request, RequestOptions options, - ActionListener listener) { - return restHighLevelClient.performRequestAsyncAndParseEntity(request, - LicenseRequestConverters::deleteLicense, options, - AcknowledgedResponse::fromXContent, listener, emptySet()); - } - - /** - * Starts a trial license on the cluster. - * @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized - * @return the response - * @throws IOException in case there is a problem sending the request or parsing back the response - */ - public StartTrialResponse startTrial(StartTrialRequest request, RequestOptions options) throws IOException { - return restHighLevelClient.performRequestAndParseEntity(request, LicenseRequestConverters::startTrial, options, - StartTrialResponse::fromXContent, singleton(403)); - } - - /** - * Asynchronously starts a trial license on the cluster. - * @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized - * @param listener the listener to be notified upon request completion - * @return cancellable that may be used to cancel the request - */ - public Cancellable startTrialAsync(StartTrialRequest request, - RequestOptions options, - ActionListener listener) { - - return restHighLevelClient.performRequestAsyncAndParseEntity(request, LicenseRequestConverters::startTrial, options, - StartTrialResponse::fromXContent, listener, singleton(403)); - } - - /** - * Initiates an indefinite basic license. - * @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized - * @return the response - * @throws IOException in case there is a problem sending the request or parsing back the response - */ - public StartBasicResponse startBasic(StartBasicRequest request, RequestOptions options) throws IOException { - return restHighLevelClient.performRequestAndParseEntity(request, LicenseRequestConverters::startBasic, options, - StartBasicResponse::fromXContent, emptySet()); - } - - /** - * Asynchronously initiates an indefinite basic license. - * @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized - * @param listener the listener to be notified upon request completion - * @return cancellable that may be used to cancel the request - */ - public Cancellable startBasicAsync(StartBasicRequest request, RequestOptions options, - ActionListener listener) { - return restHighLevelClient.performRequestAsyncAndParseEntity(request, LicenseRequestConverters::startBasic, options, - StartBasicResponse::fromXContent, listener, emptySet()); - } - - /** - * Retrieve the license trial status - * @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized - * @return the response - * @throws IOException in case there is a problem sending the request or parsing back the response - */ - public GetTrialStatusResponse getTrialStatus(RequestOptions options) throws IOException { - return restHighLevelClient.performRequestAndParseEntity(Validatable.EMPTY, - request -> LicenseRequestConverters.getLicenseTrialStatus(), options, GetTrialStatusResponse::fromXContent, emptySet()); - } - - /** - * Retrieve the license basic status - * @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized - * @return the response - * @throws IOException in case there is a problem sending the request or parsing back the response - */ - public GetBasicStatusResponse getBasicStatus(RequestOptions options) throws IOException { - return restHighLevelClient.performRequestAndParseEntity(Validatable.EMPTY, - request -> LicenseRequestConverters.getLicenseBasicStatus(), options, GetBasicStatusResponse::fromXContent, emptySet()); - } - - /** - * Converts an entire response into a json string - * - * This is useful for responses that we don't parse on the client side, but instead work as string - * such as in case of the license JSON - */ - static String convertResponseToJson(Response response) throws IOException { - HttpEntity entity = response.getEntity(); - if (entity == null) { - throw new IllegalStateException("Response body expected but not returned"); - } - if (entity.getContentType() == null) { - throw new IllegalStateException("Elasticsearch didn't return the [Content-Type] header, unable to parse response body"); - } - XContentType xContentType = XContentType.fromMediaTypeOrFormat(entity.getContentType().getValue()); - if (xContentType == null) { - throw new IllegalStateException("Unsupported Content-Type: " + entity.getContentType().getValue()); - } - if (xContentType == XContentType.JSON) { - // No changes is required - return Streams.copyToString(new InputStreamReader(response.getEntity().getContent(), StandardCharsets.UTF_8)); - } else { - // Need to convert into JSON - try (InputStream stream = response.getEntity().getContent(); - XContentParser parser = XContentFactory.xContent(xContentType).createParser(NamedXContentRegistry.EMPTY, - DeprecationHandler.THROW_UNSUPPORTED_OPERATION, stream)) { - parser.nextToken(); - XContentBuilder builder = XContentFactory.jsonBuilder(); - builder.copyCurrentStructure(parser); - return Strings.toString(builder); - } - } - } -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/LicenseRequestConverters.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/LicenseRequestConverters.java deleted file mode 100644 index ec5ae8e3a60..00000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/LicenseRequestConverters.java +++ /dev/null @@ -1,105 +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.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.client.license.StartTrialRequest; -import org.elasticsearch.client.license.StartBasicRequest; -import org.elasticsearch.client.license.DeleteLicenseRequest; -import org.elasticsearch.client.license.GetLicenseRequest; -import org.elasticsearch.client.license.PutLicenseRequest; - -final class LicenseRequestConverters { - - private LicenseRequestConverters() {} - - static Request putLicense(PutLicenseRequest putLicenseRequest) { - String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_license").build(); - Request request = new Request(HttpPut.METHOD_NAME, endpoint); - RequestConverters.Params parameters = new RequestConverters.Params(); - parameters.withTimeout(putLicenseRequest.timeout()); - parameters.withMasterTimeout(putLicenseRequest.masterNodeTimeout()); - if (putLicenseRequest.isAcknowledge()) { - parameters.putParam("acknowledge", "true"); - } - request.addParameters(parameters.asMap()); - request.setJsonEntity(putLicenseRequest.getLicenseDefinition()); - return request; - } - - static Request getLicense(GetLicenseRequest getLicenseRequest) { - String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_license").build(); - Request request = new Request(HttpGet.METHOD_NAME, endpoint); - RequestConverters.Params parameters = new RequestConverters.Params(); - parameters.withLocal(getLicenseRequest.isLocal()); - request.addParameters(parameters.asMap()); - return request; - } - - static Request deleteLicense(DeleteLicenseRequest deleteLicenseRequest) { - String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_license").build(); - Request request = new Request(HttpDelete.METHOD_NAME, endpoint); - RequestConverters.Params parameters = new RequestConverters.Params(); - parameters.withTimeout(deleteLicenseRequest.timeout()); - parameters.withMasterTimeout(deleteLicenseRequest.masterNodeTimeout()); - request.addParameters(parameters.asMap()); - return request; - } - - static Request startTrial(StartTrialRequest startTrialRequest) { - final String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_license", "start_trial").build(); - final Request request = new Request(HttpPost.METHOD_NAME, endpoint); - - RequestConverters.Params parameters = new RequestConverters.Params(); - parameters.putParam("acknowledge", Boolean.toString(startTrialRequest.isAcknowledge())); - if (startTrialRequest.getLicenseType() != null) { - parameters.putParam("type", startTrialRequest.getLicenseType()); - } - request.addParameters(parameters.asMap()); - return request; - } - - static Request startBasic(StartBasicRequest startBasicRequest) { - String endpoint = new RequestConverters.EndpointBuilder() - .addPathPartAsIs("_license", "start_basic") - .build(); - Request request = new Request(HttpPost.METHOD_NAME, endpoint); - RequestConverters.Params parameters = new RequestConverters.Params(); - parameters.withTimeout(startBasicRequest.timeout()); - parameters.withMasterTimeout(startBasicRequest.masterNodeTimeout()); - if (startBasicRequest.isAcknowledge()) { - parameters.putParam("acknowledge", "true"); - } - request.addParameters(parameters.asMap()); - return request; - } - - static Request getLicenseTrialStatus() { - return new Request(HttpGet.METHOD_NAME, "/_license/trial_status"); - } - - static Request getLicenseBasicStatus() { - return new Request(HttpGet.METHOD_NAME, "/_license/basic_status"); - } - -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java index 15322470a2b..6d786e71bc2 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java @@ -260,10 +260,8 @@ public class RestHighLevelClient implements Closeable { private final IngestClient ingestClient = new IngestClient(this); private final SnapshotClient snapshotClient = new SnapshotClient(this); private final TasksClient tasksClient = new TasksClient(this); - private final XPackClient xPackClient = new XPackClient(this); private final WatcherClient watcherClient = new WatcherClient(this); private final GraphClient graphClient = new GraphClient(this); - private final LicenseClient licenseClient = new LicenseClient(this); private final MigrationClient migrationClient = new MigrationClient(this); private final MachineLearningClient machineLearningClient = new MachineLearningClient(this); private final SecurityClient securityClient = new SecurityClient(this); @@ -372,19 +370,6 @@ public class RestHighLevelClient implements Closeable { return tasksClient; } - /** - * Provides methods for accessing the Elastic Licensed X-Pack Info - * and Usage APIs that are shipped with the default distribution of - * Elasticsearch. All of these APIs will 404 if run against the OSS - * distribution of Elasticsearch. - *

- * See the - * Info APIs on elastic.co for more information. - */ - public final XPackClient xpack() { - return xPackClient; - } - /** * Provides methods for accessing the Elastic Licensed Watcher APIs that * are shipped with the default distribution of Elasticsearch. All of @@ -405,16 +390,6 @@ public class RestHighLevelClient implements Closeable { */ public GraphClient graph() { return graphClient; } - /** - * Provides methods for accessing the Elastic Licensed Licensing APIs that - * are shipped with the default distribution of Elasticsearch. All of - * these APIs will 404 if run against the OSS distribution of Elasticsearch. - *

- * See the - * Licensing APIs on elastic.co for more information. - */ - public LicenseClient license() { return licenseClient; } - /** * A wrapper for the {@link RestHighLevelClient} that provides methods for * accessing the Elastic Index Lifecycle APIs. diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/XPackClient.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/XPackClient.java deleted file mode 100644 index cc020de92f6..00000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/XPackClient.java +++ /dev/null @@ -1,99 +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.client; - -import org.elasticsearch.action.ActionListener; -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; - -import static java.util.Collections.emptySet; - -/** - * A wrapper for the {@link RestHighLevelClient} that provides methods for - * accessing the Elastic Licensed X-Pack APIs that are shipped with the - * default distribution of Elasticsearch. All of these APIs will 404 if run - * against the OSS distribution of Elasticsearch. - *

- * See the - * REST APIs on elastic.co for more information. - */ -public final class XPackClient { - - private final RestHighLevelClient restHighLevelClient; - - XPackClient(RestHighLevelClient restHighLevelClient) { - this.restHighLevelClient = restHighLevelClient; - } - - /** - * Fetch information about X-Pack from the cluster. - * See - * the docs for more. - * @param request the request - * @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized - * @return the response - * @throws IOException in case there is a problem sending the request or parsing back the response - */ - public XPackInfoResponse info(XPackInfoRequest request, RequestOptions options) throws IOException { - return restHighLevelClient.performRequestAndParseEntity(request, XPackRequestConverters::info, options, - XPackInfoResponse::fromXContent, emptySet()); - } - - /** - * Asynchronously fetch information about X-Pack from the cluster. - * See - * the docs for more. - * @param request the request - * @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized - * @param listener the listener to be notified upon request completion - * @return cancellable that may be used to cancel the request - */ - public Cancellable infoAsync(XPackInfoRequest request, RequestOptions options, - ActionListener listener) { - return restHighLevelClient.performRequestAsyncAndParseEntity(request, XPackRequestConverters::info, options, - XPackInfoResponse::fromXContent, listener, emptySet()); - } - - /** - * Fetch usage information about X-Pack features from the cluster. - * @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized - * @return the response - * @throws IOException in case there is a problem sending the request or parsing back the response - */ - public XPackUsageResponse usage(XPackUsageRequest request, RequestOptions options) throws IOException { - return restHighLevelClient.performRequestAndParseEntity(request, XPackRequestConverters::usage, options, - XPackUsageResponse::fromXContent, emptySet()); - } - - /** - * Asynchronously fetch usage information about X-Pack features from the cluster. - * @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized - * @param listener the listener to be notified upon request completion - * @return cancellable that may be used to cancel the request - */ - public Cancellable usageAsync(XPackUsageRequest request, RequestOptions options, ActionListener listener) { - return restHighLevelClient.performRequestAsyncAndParseEntity(request, XPackRequestConverters::usage, options, - XPackUsageResponse::fromXContent, listener, emptySet()); - } -} 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 e4742e8c1cb..00000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/XPackRequestConverters.java +++ /dev/null @@ -1,54 +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.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/license/DeleteLicenseRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/license/DeleteLicenseRequest.java deleted file mode 100644 index a014b85c72c..00000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/license/DeleteLicenseRequest.java +++ /dev/null @@ -1,25 +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.client.license; - -import org.elasticsearch.client.TimedRequest; - -public class DeleteLicenseRequest extends TimedRequest { - -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/license/GetBasicStatusResponse.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/license/GetBasicStatusResponse.java deleted file mode 100644 index 436012e39a1..00000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/license/GetBasicStatusResponse.java +++ /dev/null @@ -1,79 +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.client.license; - -import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.xcontent.ConstructingObjectParser; -import org.elasticsearch.common.xcontent.ObjectParser; -import org.elasticsearch.common.xcontent.XContentParser; - -import java.util.Objects; - -import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg; - -/** - * Response class for license get basic status API - */ -public class GetBasicStatusResponse { - - private static final ParseField ELIGIBLE_TO_START_BASIC = new ParseField("eligible_to_start_basic"); - - private static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( - "get_basic_status_response", true, a -> new GetBasicStatusResponse((boolean) a[0])); - - static { - PARSER.declareField(constructorArg(), (parser, context) -> parser.booleanValue(), ELIGIBLE_TO_START_BASIC, - ObjectParser.ValueType.BOOLEAN); - } - - private final boolean eligibleToStartBasic; - - GetBasicStatusResponse(boolean eligibleToStartBasic) { - this.eligibleToStartBasic = eligibleToStartBasic; - } - - /** - * Returns whether the license is eligible to start basic or not - */ - public boolean isEligibleToStartBasic() { - return eligibleToStartBasic; - } - - public static GetBasicStatusResponse fromXContent(XContentParser parser) { - return PARSER.apply(parser, null); - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - GetBasicStatusResponse that = (GetBasicStatusResponse) o; - return eligibleToStartBasic == that.eligibleToStartBasic; - } - - @Override - public int hashCode() { - return Objects.hash(eligibleToStartBasic); - } -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/license/GetLicenseRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/license/GetLicenseRequest.java deleted file mode 100644 index bb0468fd9d5..00000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/license/GetLicenseRequest.java +++ /dev/null @@ -1,38 +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.client.license; - -import org.elasticsearch.client.Validatable; - - -public class GetLicenseRequest implements Validatable { - - protected boolean local = false; - - public GetLicenseRequest() { - } - - public boolean isLocal() { - return local; - } - - public void setLocal(boolean local) { - this.local = local; - } -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/license/GetLicenseResponse.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/license/GetLicenseResponse.java deleted file mode 100644 index 5afbaa2afa8..00000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/license/GetLicenseResponse.java +++ /dev/null @@ -1,36 +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.client.license; - -public class GetLicenseResponse { - - private String license; - - GetLicenseResponse() { - } - - public GetLicenseResponse(String license) { - this.license = license; - } - - public String getLicenseDefinition() { - return license; - } - -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/license/GetTrialStatusResponse.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/license/GetTrialStatusResponse.java deleted file mode 100644 index baefe806184..00000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/license/GetTrialStatusResponse.java +++ /dev/null @@ -1,80 +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.client.license; - -import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.xcontent.ConstructingObjectParser; -import org.elasticsearch.common.xcontent.ObjectParser; -import org.elasticsearch.common.xcontent.XContentParser; - -import java.util.Objects; - -import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg; - -/** - * Response class for license get trial status API - */ -public class GetTrialStatusResponse { - - private static final ParseField ELIGIBLE_TO_START_TRIAL = new ParseField("eligible_to_start_trial"); - - private static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( - "get_trial_status_response", true, a -> new GetTrialStatusResponse((boolean) a[0])); - - static { - PARSER.declareField(constructorArg(), (parser, context) -> parser.booleanValue(), ELIGIBLE_TO_START_TRIAL, - ObjectParser.ValueType.BOOLEAN); - } - - private final boolean eligibleToStartTrial; - - GetTrialStatusResponse(boolean eligibleToStartTrial) { - this.eligibleToStartTrial = eligibleToStartTrial; - } - - /** - * Returns whether the license is eligible to start trial or not - */ - public boolean isEligibleToStartTrial() { - return eligibleToStartTrial; - } - - public static GetTrialStatusResponse fromXContent(XContentParser parser) { - return PARSER.apply(parser, null); - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - GetTrialStatusResponse that = (GetTrialStatusResponse) o; - return eligibleToStartTrial == that.eligibleToStartTrial; - } - - @Override - public int hashCode() { - return Objects.hash(eligibleToStartTrial); - } - -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/license/LicenseStatus.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/license/LicenseStatus.java deleted file mode 100644 index 99751dcb6f2..00000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/license/LicenseStatus.java +++ /dev/null @@ -1,52 +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.client.license; - -/** - * Status of an X-Pack license. - */ -public enum LicenseStatus { - - ACTIVE("active"), - INVALID("invalid"), - EXPIRED("expired"); - - private final String label; - - LicenseStatus(String label) { - this.label = label; - } - - public String label() { - return label; - } - - public static LicenseStatus fromString(String value) { - switch (value) { - case "active": - return ACTIVE; - case "invalid": - return INVALID; - case "expired": - return EXPIRED; - default: - throw new IllegalArgumentException("unknown license status [" + value + "]"); - } - } -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/license/LicensesStatus.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/license/LicensesStatus.java deleted file mode 100644 index 7a2c48e9d49..00000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/license/LicensesStatus.java +++ /dev/null @@ -1,68 +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.client.license; - -import java.util.Locale; - -public enum LicensesStatus { - VALID((byte) 0), - INVALID((byte) 1), - EXPIRED((byte) 2); - - private final byte id; - - LicensesStatus(byte id) { - this.id = id; - } - - public int id() { - return id; - } - - public static LicensesStatus fromId(int id) { - if (id == 0) { - return VALID; - } else if (id == 1) { - return INVALID; - } else if (id == 2) { - return EXPIRED; - } else { - throw new IllegalStateException("no valid LicensesStatus for id=" + id); - } - } - - - @Override - public String toString() { - return this.name().toLowerCase(Locale.ROOT); - } - - public static LicensesStatus fromString(String value) { - switch (value) { - case "valid": - return VALID; - case "invalid": - return INVALID; - case "expired": - return EXPIRED; - default: - throw new IllegalArgumentException("unknown licenses status [" + value + "]"); - } - } -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/license/PutLicenseRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/license/PutLicenseRequest.java deleted file mode 100644 index 62b223458c5..00000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/license/PutLicenseRequest.java +++ /dev/null @@ -1,47 +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.client.license; - -import org.elasticsearch.client.TimedRequest; - -public class PutLicenseRequest extends TimedRequest { - - private String licenseDefinition; - private boolean acknowledge = false; - - public PutLicenseRequest() { - } - - public void setLicenseDefinition(String licenseDefinition) { - this.licenseDefinition = licenseDefinition; - } - - public String getLicenseDefinition() { - return licenseDefinition; - } - - public void setAcknowledge(boolean acknowledge) { - this.acknowledge = acknowledge; - } - - public boolean isAcknowledge() { - return acknowledge; - } -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/license/PutLicenseResponse.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/license/PutLicenseResponse.java deleted file mode 100644 index 107aec76f97..00000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/license/PutLicenseResponse.java +++ /dev/null @@ -1,152 +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.client.license; - -import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.collect.Tuple; -import org.elasticsearch.common.xcontent.ConstructingObjectParser; -import org.elasticsearch.common.xcontent.XContentParseException; -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.client.common.ProtocolUtils; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg; -import static org.elasticsearch.common.xcontent.ConstructingObjectParser.optionalConstructorArg; - -public final class PutLicenseResponse { - - private static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( - "put_license_response", true, (a, v) -> { - boolean acknowledged = (Boolean) a[0]; - LicensesStatus licensesStatus = LicensesStatus.fromString((String) a[1]); - @SuppressWarnings("unchecked") Tuple> acknowledgements = (Tuple>) a[2]; - if (acknowledgements == null) { - return new PutLicenseResponse(acknowledged, licensesStatus); - } else { - return new PutLicenseResponse(acknowledged, licensesStatus, acknowledgements.v1(), acknowledgements.v2()); - } - - }); - - static { - PARSER.declareBoolean(constructorArg(), new ParseField("acknowledged")); - PARSER.declareString(constructorArg(), new ParseField("license_status")); - PARSER.declareObject(optionalConstructorArg(), (parser, v) -> { - Map acknowledgeMessages = new HashMap<>(); - String message = null; - XContentParser.Token token; - String currentFieldName = null; - while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { - if (token == XContentParser.Token.FIELD_NAME) { - currentFieldName = parser.currentName(); - } else { - if (currentFieldName == null) { - throw new XContentParseException(parser.getTokenLocation(), "expected message header or acknowledgement"); - } - if ("message".equals(currentFieldName)) { - if (token != XContentParser.Token.VALUE_STRING) { - throw new XContentParseException(parser.getTokenLocation(), "unexpected message header type"); - } - message = parser.text(); - } else { - if (token != XContentParser.Token.START_ARRAY) { - throw new XContentParseException(parser.getTokenLocation(), "unexpected acknowledgement type"); - } - List acknowledgeMessagesList = new ArrayList<>(); - while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { - if (token != XContentParser.Token.VALUE_STRING) { - throw new XContentParseException(parser.getTokenLocation(), "unexpected acknowledgement text"); - } - acknowledgeMessagesList.add(parser.text()); - } - acknowledgeMessages.put(currentFieldName, acknowledgeMessagesList.toArray(new String[0])); - } - } - } - return new Tuple<>(message, acknowledgeMessages); - }, - new ParseField("acknowledge")); - } - - private boolean acknowledged; - private LicensesStatus status; - private Map acknowledgeMessages; - private String acknowledgeHeader; - - public PutLicenseResponse() { - } - - public PutLicenseResponse(boolean acknowledged, LicensesStatus status) { - this(acknowledged, status, null, Collections.emptyMap()); - } - - public PutLicenseResponse(boolean acknowledged, LicensesStatus status, String acknowledgeHeader, - Map acknowledgeMessages) { - this.acknowledged = acknowledged; - this.status = status; - this.acknowledgeHeader = acknowledgeHeader; - this.acknowledgeMessages = acknowledgeMessages; - } - - public boolean isAcknowledged() { - return acknowledged; - } - - public LicensesStatus status() { - return status; - } - - public Map acknowledgeMessages() { - return acknowledgeMessages; - } - - public String acknowledgeHeader() { - return acknowledgeHeader; - } - - public static PutLicenseResponse fromXContent(XContentParser parser) throws IOException { - return PARSER.parse(parser, null); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - if (!super.equals(o)) return false; - PutLicenseResponse that = (PutLicenseResponse) o; - - return status == that.status && - ProtocolUtils.equals(acknowledgeMessages, that.acknowledgeMessages) && - Objects.equals(acknowledgeHeader, that.acknowledgeHeader); - } - - @Override - public int hashCode() { - return Objects.hash(super.hashCode(), status, ProtocolUtils.hashCode(acknowledgeMessages), acknowledgeHeader); - } - -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/license/StartBasicRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/license/StartBasicRequest.java deleted file mode 100644 index 00a0cc421aa..00000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/license/StartBasicRequest.java +++ /dev/null @@ -1,38 +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.client.license; - -import org.elasticsearch.client.TimedRequest; - -public class StartBasicRequest extends TimedRequest { - private final boolean acknowledge; - - public StartBasicRequest() { - this(false); - } - - public StartBasicRequest(boolean acknowledge) { - this.acknowledge = acknowledge; - } - - public boolean isAcknowledge() { - return acknowledge; - } -} - diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/license/StartBasicResponse.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/license/StartBasicResponse.java deleted file mode 100644 index d51797a15b7..00000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/license/StartBasicResponse.java +++ /dev/null @@ -1,156 +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.client.license; - -import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.collect.Tuple; -import org.elasticsearch.common.xcontent.ConstructingObjectParser; -import org.elasticsearch.common.xcontent.XContentParseException; -import org.elasticsearch.common.xcontent.XContentParser; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg; -import static org.elasticsearch.common.xcontent.ConstructingObjectParser.optionalConstructorArg; -import static org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken; - -public class StartBasicResponse { - - private static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( - "start_basic_response", true, (a, v) -> { - boolean basicWasStarted = (Boolean) a[0]; - String errorMessage = (String) a[1]; - - if (basicWasStarted) { - return new StartBasicResponse(StartBasicResponse.Status.GENERATED_BASIC); - } - StartBasicResponse.Status status = StartBasicResponse.Status.fromErrorMessage(errorMessage); - @SuppressWarnings("unchecked") Tuple> acknowledgements = (Tuple>) a[2]; - return new StartBasicResponse(status, acknowledgements.v2(), acknowledgements.v1()); - }); - - static { - PARSER.declareBoolean(constructorArg(), new ParseField("basic_was_started")); - PARSER.declareString(optionalConstructorArg(), new ParseField("error_message")); - PARSER.declareObject(optionalConstructorArg(), (parser, v) -> { - Map acknowledgeMessages = new HashMap<>(); - String message = null; - XContentParser.Token token; - String currentFieldName = null; - while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { - if (token == XContentParser.Token.FIELD_NAME) { - currentFieldName = parser.currentName(); - } else { - if (currentFieldName == null) { - throw new XContentParseException(parser.getTokenLocation(), "expected message header or acknowledgement"); - } - if (new ParseField("message").getPreferredName().equals(currentFieldName)) { - ensureExpectedToken(XContentParser.Token.VALUE_STRING, token, parser); - message = parser.text(); - } else { - if (token != XContentParser.Token.START_ARRAY) { - throw new XContentParseException(parser.getTokenLocation(), "unexpected acknowledgement type"); - } - List acknowledgeMessagesList = new ArrayList<>(); - while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { - ensureExpectedToken(XContentParser.Token.VALUE_STRING, token, parser); - acknowledgeMessagesList.add(parser.text()); - } - acknowledgeMessages.put(currentFieldName, acknowledgeMessagesList.toArray(new String[0])); - } - } - } - return new Tuple<>(message, acknowledgeMessages); - }, new ParseField("acknowledge")); - } - - private Map acknowledgeMessages; - private String acknowledgeMessage; - - public enum Status { - GENERATED_BASIC(true, null), - ALREADY_USING_BASIC(false, "Operation failed: Current license is basic."), - NEED_ACKNOWLEDGEMENT(false, "Operation failed: Needs acknowledgement."); - - private final boolean isBasicStarted; - private final String errorMessage; - - Status(boolean isBasicStarted, String errorMessage) { - this.isBasicStarted = isBasicStarted; - this.errorMessage = errorMessage; - } - - static StartBasicResponse.Status fromErrorMessage(final String errorMessage) { - final StartBasicResponse.Status[] values = StartBasicResponse.Status.values(); - for (StartBasicResponse.Status status : values) { - if (Objects.equals(status.errorMessage, errorMessage)) { - return status; - } - } - throw new IllegalArgumentException("No status for error message ['" + errorMessage + "']"); - } - } - - private StartBasicResponse.Status status; - - private StartBasicResponse(StartBasicResponse.Status status) { - this(status, Collections.emptyMap(), null); - } - - private StartBasicResponse(StartBasicResponse.Status status, - Map acknowledgeMessages, String acknowledgeMessage) { - this.status = status; - this.acknowledgeMessages = acknowledgeMessages; - this.acknowledgeMessage = acknowledgeMessage; - } - - public Status getStatus() { - return status; - } - - public boolean isAcknowledged() { - return status != StartBasicResponse.Status.NEED_ACKNOWLEDGEMENT; - } - - public boolean isBasicStarted() { - return status.isBasicStarted; - } - - public String getErrorMessage() { - return status.errorMessage; - } - - public String getAcknowledgeMessage() { - return acknowledgeMessage; - } - - public Map getAcknowledgeMessages() { - return acknowledgeMessages; - } - - public static StartBasicResponse fromXContent(XContentParser parser) throws IOException { - return PARSER.parse(parser, null); - } -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/license/StartTrialRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/license/StartTrialRequest.java deleted file mode 100644 index 57858f8de05..00000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/license/StartTrialRequest.java +++ /dev/null @@ -1,50 +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.client.license; - -import org.elasticsearch.client.Validatable; -import org.elasticsearch.common.Nullable; - -public class StartTrialRequest implements Validatable { - - private final boolean acknowledge; - private final String licenseType; - - public StartTrialRequest() { - this(false); - } - - public StartTrialRequest(boolean acknowledge) { - this(acknowledge, null); - } - - public StartTrialRequest(boolean acknowledge, @Nullable String licenseType) { - this.acknowledge = acknowledge; - this.licenseType = licenseType; - } - - public boolean isAcknowledge() { - return acknowledge; - } - - public String getLicenseType() { - return licenseType; - } -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/license/StartTrialResponse.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/license/StartTrialResponse.java deleted file mode 100644 index 3b259960a3c..00000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/license/StartTrialResponse.java +++ /dev/null @@ -1,188 +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.client.license; - -import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.collect.Tuple; -import org.elasticsearch.common.xcontent.ConstructingObjectParser; -import org.elasticsearch.common.xcontent.XContentParseException; -import org.elasticsearch.common.xcontent.XContentParser; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg; -import static org.elasticsearch.common.xcontent.ConstructingObjectParser.optionalConstructorArg; - -public class StartTrialResponse { - - private static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( - "start_trial_response", - true, - (Object[] arguments, Void aVoid) -> { - final boolean acknowledged = (boolean) arguments[0]; - final boolean trialWasStarted = (boolean) arguments[1]; - final String licenseType = (String) arguments[2]; - final String errorMessage = (String) arguments[3]; - - @SuppressWarnings("unchecked") - final Tuple> acknowledgeDetails = (Tuple>) arguments[4]; - final String acknowledgeHeader; - final Map acknowledgeMessages; - - if (acknowledgeDetails != null) { - acknowledgeHeader = acknowledgeDetails.v1(); - acknowledgeMessages = acknowledgeDetails.v2(); - } else { - acknowledgeHeader = null; - acknowledgeMessages = null; - } - - return new StartTrialResponse(acknowledged, trialWasStarted, licenseType, errorMessage, acknowledgeHeader, - acknowledgeMessages); - } - ); - - static { - PARSER.declareBoolean(constructorArg(), new ParseField("acknowledged")); - PARSER.declareBoolean(constructorArg(), new ParseField("trial_was_started")); - PARSER.declareString(optionalConstructorArg(), new ParseField("type")); - PARSER.declareString(optionalConstructorArg(), new ParseField("error_message")); - // todo consolidate this parsing with the parsing in PutLicenseResponse - PARSER.declareObject(optionalConstructorArg(), (parser, aVoid) -> { - final Map acknowledgeMessages = new HashMap<>(); - String message = null; - - final Map parsedMap = parser.map(); - for (Map.Entry entry : parsedMap.entrySet()) { - if (entry.getKey().equals("message")) { - if (entry.getValue() instanceof String) { - message = (String) entry.getValue(); - } else { - throw new XContentParseException(parser.getTokenLocation(), "unexpected acknowledgement header type"); - } - } else { - if (entry.getValue() instanceof List) { - final List messageStrings = new ArrayList<>(); - @SuppressWarnings("unchecked") - final List messageObjects = (List) entry.getValue(); - for (Object messageObject : messageObjects) { - if (messageObject instanceof String) { - messageStrings.add((String) messageObject); - } else { - throw new XContentParseException(parser.getTokenLocation(), "expected text in acknowledgement message"); - } - } - - acknowledgeMessages.put(entry.getKey(), messageStrings.toArray(new String[messageStrings.size()])); - } else { - throw new XContentParseException(parser.getTokenLocation(), "unexpected acknowledgement message type"); - } - } - } - - if (message == null) { - throw new XContentParseException(parser.getTokenLocation(), "expected acknowledgement header"); - } - - return new Tuple<>(message, acknowledgeMessages); - - }, new ParseField("acknowledge")); - } - - public static StartTrialResponse fromXContent(XContentParser parser) throws IOException { - return PARSER.apply(parser, null); - } - - private final boolean acknowledged; - private final boolean trialWasStarted; - private final String licenseType; - private final String errorMessage; - private final String acknowledgeHeader; - private final Map acknowledgeMessages; - - public StartTrialResponse(boolean acknowledged, - boolean trialWasStarted, - String licenseType, - String errorMessage, - String acknowledgeHeader, - Map acknowledgeMessages) { - - this.acknowledged = acknowledged; - this.trialWasStarted = trialWasStarted; - this.licenseType = licenseType; - this.errorMessage = errorMessage; - this.acknowledgeHeader = acknowledgeHeader; - this.acknowledgeMessages = acknowledgeMessages; - } - - /** - * Returns true if the request that corresponds to this response acknowledged license changes that would occur as a result of starting - * a trial license - */ - public boolean isAcknowledged() { - return acknowledged; - } - - /** - * Returns true if a trial license was started as a result of the request corresponding to this response. Returns false if the cluster - * did not start a trial, or a trial had already been started before the corresponding request was made - */ - public boolean isTrialWasStarted() { - return trialWasStarted; - } - - /** - * If a trial license was started as a result of the request corresponding to this response (see {@link #isTrialWasStarted()}) then - * returns the type of license that was started on the cluster. Returns null otherwise - */ - public String getLicenseType() { - return licenseType; - } - - /** - * If a trial license was not started as a result of the request corresponding to this response (see {@link #isTrialWasStarted()} then - * returns a brief message explaining why the trial could not be started. Returns false otherwise - */ - public String getErrorMessage() { - return errorMessage; - } - - /** - * If the request corresponding to this response did not acknowledge licensing changes that would result from starting a trial license - * (see {@link #isAcknowledged()}), returns a message describing how the user must acknowledge licensing changes as a result of - * such a request. Returns null otherwise - */ - public String getAcknowledgeHeader() { - return acknowledgeHeader; - } - - /** - * If the request corresponding to this response did not acknowledge licensing changes that would result from starting a trial license - * (see {@link #isAcknowledged()}, returns a map. The map's keys are names of commercial Elasticsearch features, and their values are - * messages about how those features will be affected by licensing changes as a result of starting a trial license - */ - public Map getAcknowledgeMessages() { - return acknowledgeMessages; - } -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/license/package-info.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/license/package-info.java deleted file mode 100644 index ee0bd22c515..00000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/license/package-info.java +++ /dev/null @@ -1,24 +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. - */ - -/** - * Request and Response objects for the default distribution's License - * APIs. - */ -package org.elasticsearch.client.license; 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 6f018e07b5d..00000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/xpack/XPackInfoRequest.java +++ /dev/null @@ -1,71 +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.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 62f19570c6b..00000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/xpack/XPackInfoResponse.java +++ /dev/null @@ -1,384 +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.client.xpack; - -import org.elasticsearch.client.license.LicenseStatus; -import org.elasticsearch.common.Nullable; -import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.xcontent.ConstructingObjectParser; -import org.elasticsearch.common.xcontent.ObjectParser.ValueType; -import org.elasticsearch.common.xcontent.XContentParser; - -import java.io.IOException; -import java.util.Collections; -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 static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg; -import static org.elasticsearch.common.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 = new HashMap<>(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 9308a09de79..00000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/xpack/XPackUsageRequest.java +++ /dev/null @@ -1,25 +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.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 2f9c99cc65e..00000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/xpack/XPackUsageResponse.java +++ /dev/null @@ -1,57 +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.client.xpack; - -import org.elasticsearch.common.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); - } -} diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/LicenseIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/LicenseIT.java deleted file mode 100644 index 2b704b435aa..00000000000 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/LicenseIT.java +++ /dev/null @@ -1,213 +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.client; - -import org.elasticsearch.Build; -import org.elasticsearch.action.support.master.AcknowledgedResponse; -import org.elasticsearch.client.license.DeleteLicenseRequest; -import org.elasticsearch.client.license.GetBasicStatusResponse; -import org.elasticsearch.client.license.GetLicenseRequest; -import org.elasticsearch.client.license.GetLicenseResponse; -import org.elasticsearch.client.license.GetTrialStatusResponse; -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.common.xcontent.XContentParser; -import org.elasticsearch.common.xcontent.json.JsonXContent; -import org.junit.After; -import org.junit.BeforeClass; - -import java.io.IOException; -import java.util.Arrays; -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.empty; -import static org.hamcrest.Matchers.emptyOrNullString; -import static org.hamcrest.Matchers.not; - -public class LicenseIT extends ESRestHighLevelClientTestCase { - - /* - * todo there are some cases we can't test here because this gradle project starts the integ test cluster so that it'll generate - * a trial license at startup. we need to add a separate gradle project for the license-related tests so that we can start the - * integ test cluster without generating a trial license - */ - - @BeforeClass - public static void checkForSnapshot() { - assumeTrue("Trial license used to rollback is only valid when tested against snapshot/test builds", - Build.CURRENT.isSnapshot()); - } - - @After - public void rollbackToTrial() throws IOException { - putTrialLicense(); - } - - public void testStartTrial() throws Exception { - - // todo add case where we successfully start a trial - see note above - - // case where we don't acknowledge trial license conditions - { - final StartTrialRequest request = new StartTrialRequest(); - final StartTrialResponse response = highLevelClient().license().startTrial(request, RequestOptions.DEFAULT); - - assertThat(response.isAcknowledged(), equalTo(false)); - assertThat(response.isTrialWasStarted(), equalTo(false)); - assertThat(response.getLicenseType(), nullValue()); - assertThat(response.getErrorMessage(), equalTo("Operation failed: Needs acknowledgement.")); - assertThat(response.getAcknowledgeHeader(), containsString("This API initiates a free 30-day trial for all platinum features")); - assertNotEmptyAcknowledgeMessages(response.getAcknowledgeMessages()); - } - - // case where we acknowledge, but the trial is already started at cluster startup - { - final StartTrialRequest request = new StartTrialRequest(true); - final StartTrialResponse response = highLevelClient().license().startTrial(request, RequestOptions.DEFAULT); - - assertThat(response.isAcknowledged(), equalTo(true)); - assertThat(response.isTrialWasStarted(), equalTo(false)); - assertThat(response.getLicenseType(), nullValue()); - assertThat(response.getErrorMessage(), equalTo("Operation failed: Trial was already activated.")); - assertThat(response.getAcknowledgeHeader(), nullValue()); - assertThat(response.getAcknowledgeMessages(), nullValue()); - } - } - - public static void putTrialLicense() throws IOException { - assumeTrue("Trial license is only valid when tested against snapshot/test builds", - Build.CURRENT.isSnapshot()); - - // use a hard-coded trial license for 20 yrs to be able to roll back from another licenses - final String licenseDefinition = Strings.toString(jsonBuilder() - .startObject() - .field("licenses", Arrays.asList( - MapBuilder.newMapBuilder() - .put("uid", "96fc37c6-6fc9-43e2-a40d-73143850cd72") - .put("type", "trial") - // 2018-10-16 07:02:48 UTC - .put("issue_date_in_millis", "1539673368158") - // 2038-10-11 07:02:48 UTC, 20 yrs later - .put("expiry_date_in_millis", "2170393368158") - .put("max_nodes", "5") - .put("issued_to", "client_rest-high-level_integTestCluster") - .put("issuer", "elasticsearch") - .put("start_date_in_millis", "-1") - .put("signature", - "AAAABAAAAA3FXON9kGmNqmH+ASDWAAAAIAo5/x6hrsGh1GqqrJmy4qgmEC7gK0U4zQ6q5ZEMhm4jAAABAAcdKHL0BfM2uqTgT7BDuFxX5lb" - + "t/bHDVJ421Wwgm5p3IMbw/W13iiAHz0hhDziF7acJbc/y65L+BKGtVC1gSSHeLDHaAD66VrjKxfc7VbGyJIAYBOdujf0rheurmaD3IcNo" - + "/tWDjCdtTwrNziFkorsGcPadBP5Yc6csk3/Q74DlfiYweMBxLUfkBERwxwd5OQS6ujGvl/4bb8p5zXvOw8vMSaAXSXXnExP6lam+0934W" - + "0kHvU7IGk+fCUjOaiSWKSoE4TEcAtVNYj/oRoRtfQ1KQGpdCHxTHs1BimdZaG0nBHDsvhYlVVLSvHN6QzqsHWgFDG6JJxhtU872oTRSUHA=") - .immutableMap())) - .endObject()); - - final PutLicenseRequest request = new PutLicenseRequest(); - request.setAcknowledge(true); - request.setLicenseDefinition(licenseDefinition); - final PutLicenseResponse response = highLevelClient().license().putLicense(request, RequestOptions.DEFAULT); - assertThat(response.isAcknowledged(), equalTo(true)); - assertThat(response.status(), equalTo(LicensesStatus.VALID)); - } - - public void testStartBasic() throws Exception { - // we don't test the case where we successfully start a basic because the integ test cluster generates one on startup - // and we don't have a good way to prevent that / work around it in this test project - // case where we don't acknowledge basic license conditions - { - final StartBasicRequest request = new StartBasicRequest(); - final StartBasicResponse response = highLevelClient().license().startBasic(request, RequestOptions.DEFAULT); - assertThat(response.isAcknowledged(), equalTo(false)); - assertThat(response.isBasicStarted(), equalTo(false)); - assertThat(response.getErrorMessage(), equalTo("Operation failed: Needs acknowledgement.")); - assertThat(response.getAcknowledgeMessage(), - containsString("This license update requires acknowledgement. " + - "To acknowledge the license, please read the following messages and call /start_basic again")); - assertNotEmptyAcknowledgeMessages(response.getAcknowledgeMessages()); - } - // case where we acknowledge and the basic is started successfully - { - final StartBasicRequest request = new StartBasicRequest(true); - final StartBasicResponse response = highLevelClient().license().startBasic(request, RequestOptions.DEFAULT); - assertThat(response.isAcknowledged(), equalTo(true)); - assertThat(response.isBasicStarted(), equalTo(true)); - assertThat(response.getErrorMessage(), nullValue()); - assertThat(response.getAcknowledgeMessage(), nullValue()); - assertThat(response.getAcknowledgeMessages().size(), equalTo(0)); - } - } - - private static void assertNotEmptyAcknowledgeMessages(Map acknowledgeMessages) { - assertThat(acknowledgeMessages.entrySet(), not(empty())); - for (Map.Entry entry : acknowledgeMessages.entrySet()) { - assertThat(entry.getKey(), not(emptyOrNullString())); - for (String message : entry.getValue()) { - assertThat(message, not(emptyOrNullString())); - } - } - } - - 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 map = parser.map(); - assertThat(map.containsKey("license"), equalTo(true)); - - @SuppressWarnings("unchecked") - final Map license = (Map) 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)); - } - - public void testGetTrialStatus() throws IOException { - GetTrialStatusResponse trialStatus = highLevelClient().license().getTrialStatus(RequestOptions.DEFAULT); - assertFalse(trialStatus.isEligibleToStartTrial()); - } - - public void testGetBasicStatus() throws IOException { - GetBasicStatusResponse basicStatus = highLevelClient().license().getBasicStatus(RequestOptions.DEFAULT); - assertTrue(basicStatus.isEligibleToStartBasic()); - } -} diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/LicenseRequestConvertersTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/LicenseRequestConvertersTests.java deleted file mode 100644 index 16a3e55d132..00000000000 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/LicenseRequestConvertersTests.java +++ /dev/null @@ -1,147 +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.client; - -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; -import java.util.Map; - -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.nullValue; -import static org.elasticsearch.client.RequestConvertersTests.setRandomMasterTimeout; -import static org.elasticsearch.client.RequestConvertersTests.setRandomTimeout; -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 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("/_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 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("/_license")); - assertThat(request.getParameters(), equalTo(expectedParams)); - assertThat(request.getEntity(), is(nullValue())); - } - - public void testDeleteLicense() { - final DeleteLicenseRequest deleteLicenseRequest = new DeleteLicenseRequest(); - final Map 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("/_license")); - assertThat(request.getParameters(), equalTo(expectedParams)); - assertThat(request.getEntity(), is(nullValue())); - } - - public void testStartTrial() { - final boolean acknowledge = randomBoolean(); - final String licenseType = randomBoolean() - ? randomAlphaOfLengthBetween(3, 10) - : null; - - final Map expectedParams = new HashMap<>(); - expectedParams.put("acknowledge", Boolean.toString(acknowledge)); - if (licenseType != null) { - expectedParams.put("type", licenseType); - } - - final StartTrialRequest hlrcRequest = new StartTrialRequest(acknowledge, licenseType); - final Request restRequest = LicenseRequestConverters.startTrial(hlrcRequest); - - assertThat(restRequest.getMethod(), equalTo(HttpPost.METHOD_NAME)); - assertThat(restRequest.getEndpoint(), equalTo("/_license/start_trial")); - assertThat(restRequest.getParameters(), equalTo(expectedParams)); - assertThat(restRequest.getEntity(), nullValue()); - } - - public void testStartBasic() { - final boolean acknowledge = randomBoolean(); - StartBasicRequest startBasicRequest = new StartBasicRequest(acknowledge); - Map expectedParams = new HashMap<>(); - if (acknowledge) { - expectedParams.put("acknowledge", Boolean.TRUE.toString()); - } - - setRandomTimeout(startBasicRequest, AcknowledgedRequest.DEFAULT_ACK_TIMEOUT, expectedParams); - setRandomMasterTimeout(startBasicRequest, expectedParams); - Request request = LicenseRequestConverters.startBasic(startBasicRequest); - - assertThat(request.getMethod(), equalTo(HttpPost.METHOD_NAME)); - assertThat(request.getEndpoint(), equalTo("/_license/start_basic")); - assertThat(request.getParameters(), equalTo(expectedParams)); - assertThat(request.getEntity(), is(nullValue())); - } - - public void testGetLicenseTrialStatus() { - Request request = LicenseRequestConverters.getLicenseTrialStatus(); - assertEquals(HttpGet.METHOD_NAME, request.getMethod()); - assertEquals("/_license/trial_status", request.getEndpoint()); - assertEquals(request.getParameters().size(), 0); - assertNull(request.getEntity()); - } - - public void testGetLicenseBasicStatus() { - Request request = LicenseRequestConverters.getLicenseBasicStatus(); - assertEquals(HttpGet.METHOD_NAME, request.getMethod()); - assertEquals("/_license/basic_status", request.getEndpoint()); - assertEquals(request.getParameters().size(), 0); - assertNull(request.getEntity()); - } -} diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/XPackInfoResponseTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/XPackInfoResponseTests.java deleted file mode 100644 index 8f3c43945b4..00000000000 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/XPackInfoResponseTests.java +++ /dev/null @@ -1,122 +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.client; - -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.common.xcontent.XContentType; -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.FeatureSetsInfo.FeatureSet; -import org.elasticsearch.protocol.xpack.XPackInfoResponse.LicenseInfo; -import org.elasticsearch.protocol.xpack.license.LicenseStatus; - -import java.io.IOException; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.stream.Collectors; - -public class XPackInfoResponseTests extends AbstractResponseTestCase { - - private BuildInfo convertHlrcToInternal(org.elasticsearch.client.xpack.XPackInfoResponse.BuildInfo buildInfo) { - return buildInfo != null ? new BuildInfo(buildInfo.getHash(), buildInfo.getTimestamp()) : null; - } - - private LicenseInfo convertHlrcToInternal(org.elasticsearch.client.xpack.XPackInfoResponse.LicenseInfo licenseInfo) { - return licenseInfo != null - ? new LicenseInfo(licenseInfo.getUid(), licenseInfo.getType(), licenseInfo.getMode(), - licenseInfo.getStatus() != null ? LicenseStatus.valueOf(licenseInfo.getStatus().name()) : null, - licenseInfo.getExpiryDate()) - : null; - } - - private FeatureSetsInfo convertHlrcToInternal(org.elasticsearch.client.xpack.XPackInfoResponse.FeatureSetsInfo featureSetsInfo) { - return featureSetsInfo != null - ? new FeatureSetsInfo(featureSetsInfo.getFeatureSets().values().stream() - .map(fs -> new FeatureSet(fs.name(), fs.available(), fs.enabled(), fs.nativeCodeInfo())) - .collect(Collectors.toSet())) - : null; - } - - private BuildInfo randomBuildInfo() { - return new BuildInfo( - randomAlphaOfLength(10), - randomAlphaOfLength(15)); - } - - private LicenseInfo randomLicenseInfo() { - return new LicenseInfo( - randomAlphaOfLength(10), - randomAlphaOfLength(4), - randomAlphaOfLength(5), - randomFrom(LicenseStatus.values()), - randomLong()); - } - - private FeatureSetsInfo randomFeatureSetsInfo() { - int size = between(0, 10); - Set featureSets = new HashSet<>(size); - while (featureSets.size() < size) { - featureSets.add(randomFeatureSet()); - } - return new FeatureSetsInfo(featureSets); - } - - private FeatureSet randomFeatureSet() { - return new FeatureSet( - randomAlphaOfLength(5), - randomBoolean(), - randomBoolean(), - randomNativeCodeInfo()); - } - - private Map randomNativeCodeInfo() { - if (randomBoolean()) { - return null; - } - int size = between(0, 10); - Map nativeCodeInfo = new HashMap<>(size); - while (nativeCodeInfo.size() < size) { - nativeCodeInfo.put(randomAlphaOfLength(5), randomAlphaOfLength(5)); - } - return nativeCodeInfo; - } - - @Override - protected XPackInfoResponse createServerTestInstance(XContentType xContentType) { - return new XPackInfoResponse( - randomBoolean() ? null : randomBuildInfo(), - randomBoolean() ? null : randomLicenseInfo(), - randomBoolean() ? null : randomFeatureSetsInfo()); - } - - @Override - protected org.elasticsearch.client.xpack.XPackInfoResponse doParseToClientInstance(XContentParser parser) throws IOException { - return org.elasticsearch.client.xpack.XPackInfoResponse.fromXContent(parser); - } - - @Override - protected void assertInstances(XPackInfoResponse serverTestInstance, org.elasticsearch.client.xpack.XPackInfoResponse clientInstance) { - XPackInfoResponse serverInstance = new XPackInfoResponse(convertHlrcToInternal(clientInstance.getBuildInfo()), - convertHlrcToInternal(clientInstance.getLicenseInfo()), convertHlrcToInternal(clientInstance.getFeatureSetsInfo())); - assertEquals(serverTestInstance, serverInstance); - } -} diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/XPackRequestConvertersTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/XPackRequestConvertersTests.java deleted file mode 100644 index b5d4e1d496d..00000000000 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/XPackRequestConvertersTests.java +++ /dev/null @@ -1,62 +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.client; - -import org.apache.http.client.methods.HttpGet; -import org.elasticsearch.client.xpack.XPackInfoRequest; -import org.elasticsearch.test.ESTestCase; - -import java.util.EnumSet; -import java.util.HashMap; -import java.util.Map; - -public class XPackRequestConvertersTests extends ESTestCase { - - public void testXPackInfo() { - XPackInfoRequest infoRequest = new XPackInfoRequest(); - Map expectedParams = new HashMap<>(); - infoRequest.setVerbose(ESTestCase.randomBoolean()); - if (false == infoRequest.isVerbose()) { - expectedParams.put("human", "false"); - } - int option = ESTestCase.between(0, 2); - switch (option) { - case 0: - infoRequest.setCategories(EnumSet.allOf(XPackInfoRequest.Category.class)); - break; - case 1: - infoRequest.setCategories(EnumSet.of(XPackInfoRequest.Category.FEATURES)); - expectedParams.put("categories", "features"); - break; - case 2: - infoRequest.setCategories(EnumSet.of(XPackInfoRequest.Category.FEATURES, XPackInfoRequest.Category.BUILD)); - expectedParams.put("categories", "build,features"); - break; - default: - throw new IllegalArgumentException("invalid option [" + option + "]"); - } - - Request request = XPackRequestConverters.info(infoRequest); - assertEquals(HttpGet.METHOD_NAME, request.getMethod()); - assertEquals("/_xpack", request.getEndpoint()); - assertNull(request.getEntity()); - assertEquals(expectedParams, request.getParameters()); - } -} diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/LicensingDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/LicensingDocumentationIT.java deleted file mode 100644 index c181fca44c6..00000000000 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/LicensingDocumentationIT.java +++ /dev/null @@ -1,367 +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.client.documentation; - -import org.elasticsearch.Build; -import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.LatchedActionListener; -import org.elasticsearch.action.support.master.AcknowledgedResponse; -import org.elasticsearch.client.ESRestHighLevelClientTestCase; -import org.elasticsearch.client.RequestOptions; -import org.elasticsearch.client.RestHighLevelClient; -import org.elasticsearch.client.license.StartTrialRequest; -import org.elasticsearch.client.license.StartTrialResponse; -import org.elasticsearch.client.license.StartBasicRequest; -import org.elasticsearch.client.license.StartBasicResponse; -import org.elasticsearch.client.license.GetBasicStatusResponse; -import org.elasticsearch.client.license.GetTrialStatusResponse; -import org.elasticsearch.common.Booleans; -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; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -import static org.elasticsearch.client.LicenseIT.putTrialLicense; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.endsWith; -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.Matchers.not; -import static org.hamcrest.Matchers.nullValue; -import static org.hamcrest.Matchers.startsWith; -import static org.hamcrest.core.Is.is; - -/** - * Documentation for Licensing APIs in the high level java client. - * Code wrapped in {@code tag} and {@code end} tags is included in the docs. - */ -public class LicensingDocumentationIT extends ESRestHighLevelClientTestCase { - - @BeforeClass - public static void checkForSnapshot() { - assumeTrue("Trial license used to rollback is only valid when tested against snapshot/test builds", - Build.CURRENT.isSnapshot()); - } - - @After - public void rollbackToTrial() throws IOException { - putTrialLicense(); - } - - public void testLicense() throws Exception { - RestHighLevelClient client = highLevelClient(); - String license = "{\"license\": {\"uid\":\"893361dc-9749-4997-93cb-802e3d7fa4a8\",\"type\":\"gold\"," + - "\"issue_date_in_millis\":1411948800000,\"expiry_date_in_millis\":1914278399999,\"max_nodes\":1,\"issued_to\":\"issued_to\"," + - "\"issuer\":\"issuer\",\"signature\":\"AAAAAgAAAA3U8+YmnvwC+CWsV/mRAAABmC9ZN0hjZDBGYnVyRXpCOW5Bb3FjZDAxOWpSbTVoMVZwUzRxVk1PSm" + - "kxakxZdW5IMlhlTHNoN1N2MXMvRFk4d3JTZEx3R3RRZ0pzU3lobWJKZnQvSEFva0ppTHBkWkprZWZSQi9iNmRQNkw1SlpLN0lDalZCS095MXRGN1lIZlpYcVVTTn" + - "FrcTE2dzhJZmZrdFQrN3JQeGwxb0U0MXZ0dDJHSERiZTVLOHNzSDByWnpoZEphZHBEZjUrTVBxRENNSXNsWWJjZllaODdzVmEzUjNiWktNWGM5TUhQV2plaUo4Q1" + - "JOUml4MXNuL0pSOEhQaVB2azhmUk9QVzhFeTFoM1Q0RnJXSG53MWk2K055c28zSmRnVkF1b2JSQkFLV2VXUmVHNDZ2R3o2VE1qbVNQS2lxOHN5bUErZlNIWkZSVm" + - "ZIWEtaSU9wTTJENDVvT1NCYklacUYyK2FwRW9xa0t6dldMbmMzSGtQc3FWOTgzZ3ZUcXMvQkt2RUZwMFJnZzlvL2d2bDRWUzh6UG5pdENGWFRreXNKNkE9PQAAAQ" + - "Be8GfzDm6T537Iuuvjetb3xK5dvg0K5NQapv+rczWcQFxgCuzbF8plkgetP1aAGZP4uRESDQPMlOCsx4d0UqqAm9f7GbBQ3l93P+PogInPFeEH9NvOmaAQovmxVM" + - "9SE6DsDqlX4cXSO+bgWpXPTd2LmpoQc1fXd6BZ8GeuyYpVHVKp9hVU0tAYjw6HzYOE7+zuO1oJYOxElqy66AnIfkvHrvni+flym3tE7tDTgsDRaz7W3iBhaqiSnt" + - "EqabEkvHdPHQdSR99XGaEvnHO1paK01/35iZF6OXHsF7CCj+558GRXiVxzueOe7TsGSSt8g7YjZwV9bRCyU7oB4B/nidgI\"}}"; - { - //tag::put-license-execute - PutLicenseRequest request = new PutLicenseRequest(); - request.setLicenseDefinition(license); // <1> - request.setAcknowledge(false); // <2> - - PutLicenseResponse response = client.license().putLicense(request, RequestOptions.DEFAULT); - //end::put-license-execute - - //tag::put-license-response - LicensesStatus status = response.status(); // <1> - assertEquals(status, LicensesStatus.VALID); // <2> - boolean acknowledged = response.isAcknowledged(); // <3> - String acknowledgeHeader = response.acknowledgeHeader(); // <4> - Map acknowledgeMessages = response.acknowledgeMessages(); // <5> - //end::put-license-response - - assertFalse(acknowledged); // Should fail because we are trying to downgrade from platinum trial to gold - assertThat(acknowledgeHeader, startsWith("This license update requires acknowledgement.")); - assertThat(acknowledgeMessages.keySet(), not(hasSize(0))); - } - { - PutLicenseRequest request = new PutLicenseRequest(); - // tag::put-license-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(PutLicenseResponse putLicenseResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::put-license-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::put-license-execute-async - client.license().putLicenseAsync( - request, RequestOptions.DEFAULT, listener); // <1> - // end::put-license-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - // we cannot actually delete the license, otherwise the remaining tests won't work - if (Booleans.isTrue("true")) { - return; - } - { - //tag::delete-license-execute - DeleteLicenseRequest request = new DeleteLicenseRequest(); - - AcknowledgedResponse response = client.license().deleteLicense(request, RequestOptions.DEFAULT); - //end::delete-license-execute - - //tag::delete-license-response - boolean acknowledged = response.isAcknowledged(); // <1> - //end::delete-license-response - - assertTrue(acknowledged); - } - { - DeleteLicenseRequest request = new DeleteLicenseRequest(); - // tag::delete-license-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(AcknowledgedResponse deleteLicenseResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::delete-license-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::delete-license-execute-async - client.license().deleteLicenseAsync( - request, RequestOptions.DEFAULT, listener); // <1> - // end::delete-license-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testGetLicense() throws Exception { - RestHighLevelClient client = highLevelClient(); - { - //tag::get-license-execute - GetLicenseRequest request = new GetLicenseRequest(); - - GetLicenseResponse response = client.license().getLicense(request, RequestOptions.DEFAULT); - //end::get-license-execute - - //tag::get-license-response - String currentLicense = response.getLicenseDefinition(); // <1> - //end::get-license-response - - assertThat(currentLicense, containsString("trial")); - assertThat(currentLicense, containsString("ntegTest")); - } - { - GetLicenseRequest request = new GetLicenseRequest(); - // tag::get-license-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(GetLicenseResponse indexResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::get-license-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::get-license-execute-async - client.license().getLicenseAsync( - request, RequestOptions.DEFAULT, listener); // <1> - // end::get-license-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - { - GetLicenseRequest request = new GetLicenseRequest(); - RequestOptions.Builder builder = RequestOptions.DEFAULT.toBuilder(); - // Make sure that it still works in other formats - builder.addHeader("Accept", randomFrom("application/smile", "application/cbor")); - RequestOptions options = builder.build(); - GetLicenseResponse response = client.license().getLicense(request, options); - String currentLicense = response.getLicenseDefinition(); - assertThat(currentLicense, startsWith("{")); - assertThat(currentLicense, containsString("trial")); - assertThat(currentLicense, containsString("ntegTest")); - assertThat(currentLicense, endsWith("}")); - } - } - - public void testStartTrial() throws Exception { - RestHighLevelClient client = highLevelClient(); - - { - // tag::start-trial-execute - StartTrialRequest request = new StartTrialRequest(true); // <1> - - StartTrialResponse response = client.license().startTrial(request, RequestOptions.DEFAULT); - // end::start-trial-execute - - // tag::start-trial-response - boolean acknowledged = response.isAcknowledged(); // <1> - boolean trialWasStarted = response.isTrialWasStarted(); // <2> - String licenseType = response.getLicenseType(); // <3> - String errorMessage = response.getErrorMessage(); // <4> - String acknowledgeHeader = response.getAcknowledgeHeader(); // <5> - Map acknowledgeMessages = response.getAcknowledgeMessages(); // <6> - // end::start-trial-response - - assertTrue(acknowledged); - assertFalse(trialWasStarted); - assertThat(licenseType, nullValue()); - assertThat(errorMessage, is("Operation failed: Trial was already activated.")); - assertThat(acknowledgeHeader, nullValue()); - assertThat(acknowledgeMessages, nullValue()); - } - - { - StartTrialRequest request = new StartTrialRequest(); - - // tag::start-trial-execute-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(StartTrialResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::start-trial-execute-listener - - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::start-trial-execute-async - client.license().startTrialAsync(request, RequestOptions.DEFAULT, listener); - // end::start-trial-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testPostStartBasic() throws Exception { - RestHighLevelClient client = highLevelClient(); - { - //tag::start-basic-execute - StartBasicRequest request = new StartBasicRequest(); - - StartBasicResponse response = client.license().startBasic(request, RequestOptions.DEFAULT); - //end::start-basic-execute - - //tag::start-basic-response - boolean acknowledged = response.isAcknowledged(); // <1> - boolean basicStarted = response.isBasicStarted(); // <2> - String errorMessage = response.getErrorMessage(); // <3> - String acknowledgeMessage = response.getAcknowledgeMessage(); // <4> - Map acknowledgeMessages = response.getAcknowledgeMessages(); // <5> - //end::start-basic-response - } - { - StartBasicRequest request = new StartBasicRequest(); - // tag::start-basic-listener - ActionListener listener = new ActionListener() { - @Override - public void onResponse(StartBasicResponse indexResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::start-basic-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::start-basic-execute-async - client.license().startBasicAsync( - request, RequestOptions.DEFAULT, listener); // <1> - // end::start-basic-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - } - - public void testGetTrialStatus() throws IOException { - RestHighLevelClient client = highLevelClient(); - { - //tag::get-trial-status-execute - GetTrialStatusResponse response = client.license().getTrialStatus(RequestOptions.DEFAULT); - //end::get-trial-status-execute - - //tag::get-trial-status-response - boolean eligibleToStartTrial = response.isEligibleToStartTrial(); // <1> - //end::get-trial-status-response - } - } - - public void testGetBasicStatus() throws IOException { - RestHighLevelClient client = highLevelClient(); - { - //tag::get-basic-status-execute - GetBasicStatusResponse response = client.license().getBasicStatus(RequestOptions.DEFAULT); - //end::get-basic-status-execute - - //tag::get-basic-status-response - boolean eligibleToStartbasic = response.isEligibleToStartBasic(); // <1> - //end::get-basic-status-response - } - } -} diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/license/GetBasicStatusResponseTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/license/GetBasicStatusResponseTests.java deleted file mode 100644 index 2bf209fe1c8..00000000000 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/license/GetBasicStatusResponseTests.java +++ /dev/null @@ -1,47 +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.client.license; - -import org.elasticsearch.client.AbstractResponseTestCase; -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.common.xcontent.XContentType; - -import java.io.IOException; - -public class GetBasicStatusResponseTests - extends AbstractResponseTestCase { - - @Override - protected org.elasticsearch.license.GetBasicStatusResponse createServerTestInstance(XContentType xContentType) { - return new org.elasticsearch.license.GetBasicStatusResponse(randomBoolean()); - } - - @Override - protected GetBasicStatusResponse doParseToClientInstance(XContentParser parser) throws IOException { - return GetBasicStatusResponse.fromXContent(parser); - } - - @Override - protected void assertInstances(org.elasticsearch.license.GetBasicStatusResponse serverTestInstance, - GetBasicStatusResponse clientInstance) { - org.elasticsearch.license.GetBasicStatusResponse serverInstance = - new org.elasticsearch.license.GetBasicStatusResponse(clientInstance.isEligibleToStartBasic()); - assertEquals(serverTestInstance, serverInstance); - } -} diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/license/GetTrialStatusResponseTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/license/GetTrialStatusResponseTests.java deleted file mode 100644 index 60b5230e9f4..00000000000 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/license/GetTrialStatusResponseTests.java +++ /dev/null @@ -1,47 +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.client.license; - -import org.elasticsearch.client.AbstractResponseTestCase; -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.common.xcontent.XContentType; - -import java.io.IOException; - -public class GetTrialStatusResponseTests extends - AbstractResponseTestCase { - - @Override - protected org.elasticsearch.license.GetTrialStatusResponse createServerTestInstance(XContentType xContentType) { - return new org.elasticsearch.license.GetTrialStatusResponse(randomBoolean()); - } - - @Override - protected GetTrialStatusResponse doParseToClientInstance(XContentParser parser) throws IOException { - return GetTrialStatusResponse.fromXContent(parser); - } - - @Override - protected void assertInstances(org.elasticsearch.license.GetTrialStatusResponse serverTestInstance, - GetTrialStatusResponse clientInstance) { - org.elasticsearch.license.GetTrialStatusResponse serverInstance = - new org.elasticsearch.license.GetTrialStatusResponse(clientInstance.isEligibleToStartTrial()); - assertEquals(serverInstance, serverTestInstance); - } -} diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/license/LicenseStatusTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/license/LicenseStatusTests.java deleted file mode 100644 index 06e90da8a87..00000000000 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/license/LicenseStatusTests.java +++ /dev/null @@ -1,38 +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.client.license; - -import org.elasticsearch.test.ESTestCase; - -import static org.hamcrest.CoreMatchers.equalTo; - -public class LicenseStatusTests extends ESTestCase { - - public void testCompatibility() { - final LicenseStatus[] values = LicenseStatus.values(); - final LicenseStatus[] hlrcValues = LicenseStatus.values(); - - assertThat(values.length, equalTo(hlrcValues.length)); - - for (LicenseStatus value : values) { - final LicenseStatus licenseStatus = LicenseStatus.fromString(value.label()); - assertThat(licenseStatus.label(), equalTo(value.label())); - } - } -} diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/license/PutLicenseResponseTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/license/PutLicenseResponseTests.java deleted file mode 100644 index b00ef2c968c..00000000000 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/license/PutLicenseResponseTests.java +++ /dev/null @@ -1,89 +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.client.license; - -import org.elasticsearch.client.AbstractResponseTestCase; -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.common.xcontent.XContentType; - -import java.io.IOException; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import static org.hamcrest.Matchers.equalTo; - -public class PutLicenseResponseTests extends AbstractResponseTestCase< - org.elasticsearch.protocol.xpack.license.PutLicenseResponse, PutLicenseResponse> { - - @Override - protected org.elasticsearch.protocol.xpack.license.PutLicenseResponse createServerTestInstance(XContentType xContentType) { - boolean acknowledged = randomBoolean(); - org.elasticsearch.protocol.xpack.license.LicensesStatus status = - randomFrom(org.elasticsearch.protocol.xpack.license.LicensesStatus.VALID, - org.elasticsearch.protocol.xpack.license.LicensesStatus.INVALID, - org.elasticsearch.protocol.xpack.license.LicensesStatus.EXPIRED); - String messageHeader; - Map ackMessages; - if (randomBoolean()) { - messageHeader = randomAlphaOfLength(10); - ackMessages = randomAckMessages(); - } else { - messageHeader = null; - ackMessages = Collections.emptyMap(); - } - - return new org.elasticsearch.protocol.xpack.license.PutLicenseResponse(acknowledged, status, messageHeader, ackMessages); - } - - private static Map randomAckMessages() { - int nFeatures = randomIntBetween(1, 5); - - Map 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 doParseToClientInstance(XContentParser parser) throws IOException { - return PutLicenseResponse.fromXContent(parser); - } - - @Override - protected void assertInstances(org.elasticsearch.protocol.xpack.license.PutLicenseResponse serverTestInstance, - PutLicenseResponse clientInstance) { - assertThat(serverTestInstance.status().name(), equalTo(clientInstance.status().name())); - assertThat(serverTestInstance.acknowledgeHeader(), equalTo(clientInstance.acknowledgeHeader())); - assertThat(serverTestInstance.acknowledgeMessages().keySet(), equalTo(clientInstance.acknowledgeMessages().keySet())); - for(Map.Entry entry: serverTestInstance.acknowledgeMessages().entrySet()) { - assertTrue(Arrays.equals(entry.getValue(), clientInstance.acknowledgeMessages().get(entry.getKey()))); - } - } -} diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/license/StartBasicResponseTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/license/StartBasicResponseTests.java deleted file mode 100644 index af253957aeb..00000000000 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/license/StartBasicResponseTests.java +++ /dev/null @@ -1,85 +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.client.license; - -import org.elasticsearch.client.AbstractResponseTestCase; -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.common.xcontent.XContentType; -import org.elasticsearch.license.PostStartBasicResponse; - -import java.io.IOException; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import static org.hamcrest.Matchers.equalTo; - -public class StartBasicResponseTests extends AbstractResponseTestCase< - PostStartBasicResponse, StartBasicResponse> { - - @Override - protected PostStartBasicResponse createServerTestInstance(XContentType xContentType) { - PostStartBasicResponse.Status status = randomFrom(PostStartBasicResponse.Status.values()); - String acknowledgeMessage = null; - Map ackMessages = Collections.emptyMap(); - if (status != PostStartBasicResponse.Status.GENERATED_BASIC) { - acknowledgeMessage = randomAlphaOfLength(10); - ackMessages = randomAckMessages(); - } - final PostStartBasicResponse postStartBasicResponse = new PostStartBasicResponse(status, ackMessages, acknowledgeMessage); - return postStartBasicResponse; - } - - private static Map randomAckMessages() { - int nFeatures = randomIntBetween(1, 5); - - Map 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 StartBasicResponse doParseToClientInstance(XContentParser parser) throws IOException { - return StartBasicResponse.fromXContent(parser); - } - - @Override - protected void assertInstances(PostStartBasicResponse serverTestInstance, StartBasicResponse clientInstance) { - assertThat(serverTestInstance.getStatus().name(), equalTo(clientInstance.getStatus().name())); - assertThat(serverTestInstance.getStatus().isBasicStarted(), equalTo(clientInstance.isBasicStarted())); - assertThat(serverTestInstance.isAcknowledged(), equalTo(clientInstance.isAcknowledged())); - assertThat(serverTestInstance.getStatus().getErrorMessage(), equalTo(clientInstance.getErrorMessage())); - assertThat(serverTestInstance.getAcknowledgeMessage(), equalTo(clientInstance.getAcknowledgeMessage())); - assertThat(serverTestInstance.getAcknowledgeMessages().keySet(), equalTo(clientInstance.getAcknowledgeMessages().keySet())); - for(Map.Entry entry: serverTestInstance.getAcknowledgeMessages().entrySet()) { - assertTrue(Arrays.equals(entry.getValue(), clientInstance.getAcknowledgeMessages().get(entry.getKey()))); - } - } -} diff --git a/distribution/archives/build.gradle b/distribution/archives/build.gradle index d6bbf75ff73..573183784b7 100644 --- a/distribution/archives/build.gradle +++ b/distribution/archives/build.gradle @@ -61,7 +61,7 @@ CopySpec archiveFiles(CopySpec modulesFiles, String distributionType, String pla include 'README.asciidoc' } from(rootProject.file('licenses')) { - include oss ? 'APACHE-LICENSE-2.0.txt' : 'ELASTIC-LICENSE.txt' + include 'APACHE-LICENSE-2.0.txt' rename { 'LICENSE.txt' } } diff --git a/distribution/build.gradle b/distribution/build.gradle index caaf117cc27..2bcff235eee 100644 --- a/distribution/build.gradle +++ b/distribution/build.gradle @@ -529,12 +529,7 @@ subprojects { final String packagingPathLogs = "path.logs: ${pathLogs}" final String packagingLoggc = "${pathLogs}/gc.log" - String licenseText - if (oss) { - licenseText = rootProject.file('licenses/APACHE-LICENSE-2.0.txt').getText('UTF-8') - } else { - licenseText = rootProject.file('licenses/ELASTIC-LICENSE.txt').getText('UTF-8') - } + String licenseText = rootProject.file('licenses/APACHE-LICENSE-2.0.txt').getText('UTF-8') // license text needs to be indented with a single space licenseText = ' ' + licenseText.replace('\n', '\n ') diff --git a/distribution/docker/build.gradle b/distribution/docker/build.gradle index 64d8cab833b..86ad0958cab 100644 --- a/distribution/docker/build.gradle +++ b/distribution/docker/build.gradle @@ -65,7 +65,7 @@ RUN curl --retry 8 -S -L \\ 'base_image' : base.getImage(), 'build_date' : BuildParams.buildDate, 'git_revision' : BuildParams.gitRevision, - 'license' : oss ? 'Apache-2.0' : 'Elastic-License', + 'license' : 'Apache-2.0', 'package_manager' : base == DockerBase.UBI ? 'microdnf' : 'yum', 'source_elasticsearch': sourceElasticsearch, 'docker_base' : base.name().toLowerCase(), diff --git a/distribution/packages/build.gradle b/distribution/packages/build.gradle index a759e47cb14..f0385f19127 100644 --- a/distribution/packages/build.gradle +++ b/distribution/packages/build.gradle @@ -189,7 +189,7 @@ Closure commonPackageConfig(String type, boolean oss, boolean jdk, String archit assert type == 'rpm' into('/usr/share/elasticsearch') { from(rootProject.file('licenses')) { - include oss ? 'APACHE-LICENSE-2.0.txt' : 'ELASTIC-LICENSE.txt' + include 'APACHE-LICENSE-2.0.txt' rename { 'LICENSE.txt' } } fileMode 0644 @@ -327,11 +327,7 @@ Closure commonDebConfig(boolean oss, boolean jdk, String architecture) { // jdeb does not provide a way to set the License control attribute, and ospackage // silently ignores setting it. Instead, we set the license as "custom field" - if (oss) { - customFields['License'] = 'ASL-2.0' - } else { - customFields['License'] = 'Elastic-License' - } + customFields['License'] = 'ASL-2.0' archiveVersion = project.version.replace('-', '~') packageGroup 'web' @@ -379,11 +375,7 @@ Closure commonRpmConfig(boolean oss, boolean jdk, String architecture) { return { configure(commonPackageConfig('rpm', oss, jdk, architecture)) - if (oss) { - license 'ASL 2.0' - } else { - license 'Elastic License' - } + license 'ASL 2.0' packageGroup 'Application/Internet' requires '/bin/bash' @@ -502,15 +494,9 @@ subprojects { Path copyrightPath String expectedLicense String licenseFilename - if (project.name.contains('oss-')) { - copyrightPath = packageExtractionDir.toPath().resolve("usr/share/doc/elasticsearch-oss/copyright") - expectedLicense = "ASL-2.0" - licenseFilename = "APACHE-LICENSE-2.0.txt" - } else { - copyrightPath = packageExtractionDir.toPath().resolve("usr/share/doc/elasticsearch/copyright") - expectedLicense = "Elastic-License" - licenseFilename = "ELASTIC-LICENSE.txt" - } + copyrightPath = packageExtractionDir.toPath().resolve("usr/share/doc/elasticsearch-oss/copyright") + expectedLicense = "ASL-2.0" + licenseFilename = "APACHE-LICENSE-2.0.txt" final List header = Arrays.asList("Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/", "Copyright: Elasticsearch B.V. ", "License: " + expectedLicense) @@ -524,12 +510,7 @@ subprojects { tasks.named("checkLicense").configure { onlyIf rpmExists doLast { - String licenseFilename - if (project.name.contains('oss-')) { - licenseFilename = "APACHE-LICENSE-2.0.txt" - } else { - licenseFilename = "ELASTIC-LICENSE.txt" - } + String licenseFilename = "APACHE-LICENSE-2.0.txt" final List licenseLines = Files.readAllLines(rootDir.toPath().resolve("licenses/" + licenseFilename)) final Path licensePath = packageExtractionDir.toPath().resolve("usr/share/elasticsearch/LICENSE.txt") assertLinesInFile(licensePath, licenseLines) @@ -561,12 +542,7 @@ subprojects { exec.commandLine 'dpkg-deb', '--info', "${-> buildDist.get().outputs.files.filter(debFilter).singleFile}" exec.standardOutput = output doLast { - String expectedLicense - if (project.name.contains('oss-')) { - expectedLicense = "ASL-2.0" - } else { - expectedLicense = "Elastic-License" - } + String expectedLicense = "ASL-2.0" final Pattern pattern = Pattern.compile("\\s*License: (.+)") final String info = output.toString('UTF-8') final String[] actualLines = info.split("\n") @@ -598,12 +574,7 @@ subprojects { exec.standardOutput = output doLast { String license = output.toString('UTF-8') - String expectedLicense - if (project.name.contains('oss-')) { - expectedLicense = "ASL 2.0" - } else { - expectedLicense = "Elastic License" - } + String expectedLicense = "ASL-2.0" if (license != expectedLicense) { throw new GradleException("expected license [${expectedLicense}] for [${-> buildDist.get().outputs.files.singleFile}] but was [${license}]") } diff --git a/gradle/ide.gradle b/gradle/ide.gradle index 21f6ee7806c..144c1af9c85 100644 --- a/gradle/ide.gradle +++ b/gradle/ide.gradle @@ -97,13 +97,6 @@ if (System.getProperty('idea.active') == 'true') { specific language governing permissions and limitations under the License.'''.stripIndent() } - Elastic { - keyword = 'Licensed under the Elastic License' - notice = '''\ - Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - or more contributor license agreements. Licensed under the Elastic License; - you may not use this file except in compliance with the Elastic License.'''.stripIndent() - } } } } diff --git a/licenses/ELASTIC-LICENSE.txt b/licenses/ELASTIC-LICENSE.txt deleted file mode 100644 index 7376ffc3ff1..00000000000 --- a/licenses/ELASTIC-LICENSE.txt +++ /dev/null @@ -1,223 +0,0 @@ -ELASTIC LICENSE AGREEMENT - -PLEASE READ CAREFULLY THIS ELASTIC LICENSE AGREEMENT (THIS "AGREEMENT"), WHICH -CONSTITUTES A LEGALLY BINDING AGREEMENT AND GOVERNS ALL OF YOUR USE OF ALL OF -THE ELASTIC SOFTWARE WITH WHICH THIS AGREEMENT IS INCLUDED ("ELASTIC SOFTWARE") -THAT IS PROVIDED IN OBJECT CODE FORMAT, AND, IN ACCORDANCE WITH SECTION 2 BELOW, -CERTAIN OF THE ELASTIC SOFTWARE THAT IS PROVIDED IN SOURCE CODE FORMAT. BY -INSTALLING OR USING ANY OF THE ELASTIC SOFTWARE GOVERNED BY THIS AGREEMENT, YOU -ARE ASSENTING TO THE TERMS AND CONDITIONS OF THIS AGREEMENT. IF YOU DO NOT AGREE -WITH SUCH TERMS AND CONDITIONS, YOU MAY NOT INSTALL OR USE THE ELASTIC SOFTWARE -GOVERNED BY THIS AGREEMENT. IF YOU ARE INSTALLING OR USING THE SOFTWARE ON -BEHALF OF A LEGAL ENTITY, YOU REPRESENT AND WARRANT THAT YOU HAVE THE ACTUAL -AUTHORITY TO AGREE TO THE TERMS AND CONDITIONS OF THIS AGREEMENT ON BEHALF OF -SUCH ENTITY. - -Posted Date: April 20, 2018 - -This Agreement is entered into by and between Elasticsearch BV ("Elastic") and -You, or the legal entity on behalf of whom You are acting (as applicable, -"You"). - -1. OBJECT CODE END USER LICENSES, RESTRICTIONS AND THIRD PARTY OPEN SOURCE -SOFTWARE - - 1.1 Object Code End User License. Subject to the terms and conditions of - Section 1.2 of this Agreement, Elastic hereby grants to You, AT NO CHARGE and - for so long as you are not in breach of any provision of this Agreement, a - License to the Basic Features and Functions of the Elastic Software. - - 1.2 Reservation of Rights; Restrictions. As between Elastic and You, Elastic - and its licensors own all right, title and interest in and to the Elastic - Software, and except as expressly set forth in Sections 1.1, and 2.1 of this - Agreement, no other license to the Elastic Software is granted to You under - this Agreement, by implication, estoppel or otherwise. You agree not to: (i) - reverse engineer or decompile, decrypt, disassemble or otherwise reduce any - Elastic Software provided to You in Object Code, or any portion thereof, to - Source Code, except and only to the extent any such restriction is prohibited - by applicable law, (ii) except as expressly permitted in this Agreement, - prepare derivative works from, modify, copy or use the Elastic Software Object - Code or the Commercial Software Source Code in any manner; (iii) except as - expressly permitted in Section 1.1 above, transfer, sell, rent, lease, - distribute, sublicense, loan or otherwise transfer, Elastic Software Object - Code, in whole or in part, to any third party; (iv) use Elastic Software - Object Code for providing time-sharing services, any software-as-a-service, - service bureau services or as part of an application services provider or - other service offering (collectively, "SaaS Offering") where obtaining access - to the Elastic Software or the features and functions of the Elastic Software - is a primary reason or substantial motivation for users of the SaaS Offering - to access and/or use the SaaS Offering ("Prohibited SaaS Offering"); (v) - circumvent the limitations on use of Elastic Software provided to You in - Object Code format that are imposed or preserved by any License Key, or (vi) - alter or remove any Marks and Notices in the Elastic Software. If You have any - question as to whether a specific SaaS Offering constitutes a Prohibited SaaS - Offering, or are interested in obtaining Elastic's permission to engage in - commercial or non-commercial distribution of the Elastic Software, please - contact elastic_license@elastic.co. - - 1.3 Third Party Open Source Software. The Commercial Software may contain or - be provided with third party open source libraries, components, utilities and - other open source software (collectively, "Open Source Software"), which Open - Source Software may have applicable license terms as identified on a website - designated by Elastic. Notwithstanding anything to the contrary herein, use of - the Open Source Software shall be subject to the license terms and conditions - applicable to such Open Source Software, to the extent required by the - applicable licensor (which terms shall not restrict the license rights granted - to You hereunder, but may contain additional rights). To the extent any - condition of this Agreement conflicts with any license to the Open Source - Software, the Open Source Software license will govern with respect to such - Open Source Software only. Elastic may also separately provide you with - certain open source software that is licensed by Elastic. Your use of such - Elastic open source software will not be governed by this Agreement, but by - the applicable open source license terms. - -2. COMMERCIAL SOFTWARE SOURCE CODE - - 2.1 Limited License. Subject to the terms and conditions of Section 2.2 of - this Agreement, Elastic hereby grants to You, AT NO CHARGE and for so long as - you are not in breach of any provision of this Agreement, a limited, - non-exclusive, non-transferable, fully paid up royalty free right and license - to the Commercial Software in Source Code format, without the right to grant - or authorize sublicenses, to prepare Derivative Works of the Commercial - Software, provided You (i) do not hack the licensing mechanism, or otherwise - circumvent the intended limitations on the use of Elastic Software to enable - features other than Basic Features and Functions or those features You are - entitled to as part of a Subscription, and (ii) use the resulting object code - only for reasonable testing purposes. - - 2.2 Restrictions. Nothing in Section 2.1 grants You the right to (i) use the - Commercial Software Source Code other than in accordance with Section 2.1 - above, (ii) use a Derivative Work of the Commercial Software outside of a - Non-production Environment, in any production capacity, on a temporary or - permanent basis, or (iii) transfer, sell, rent, lease, distribute, sublicense, - loan or otherwise make available the Commercial Software Source Code, in whole - or in part, to any third party. Notwithstanding the foregoing, You may - maintain a copy of the repository in which the Source Code of the Commercial - Software resides and that copy may be publicly accessible, provided that you - include this Agreement with Your copy of the repository. - -3. TERMINATION - - 3.1 Termination. This Agreement will automatically terminate, whether or not - You receive notice of such Termination from Elastic, if You breach any of its - provisions. - - 3.2 Post Termination. Upon any termination of this Agreement, for any reason, - You shall promptly cease the use of the Elastic Software in Object Code format - and cease use of the Commercial Software in Source Code format. For the - avoidance of doubt, termination of this Agreement will not affect Your right - to use Elastic Software, in either Object Code or Source Code formats, made - available under the Apache License Version 2.0. - - 3.3 Survival. Sections 1.2, 2.2. 3.3, 4 and 5 shall survive any termination or - expiration of this Agreement. - -4. DISCLAIMER OF WARRANTIES AND LIMITATION OF LIABILITY - - 4.1 Disclaimer of Warranties. TO THE MAXIMUM EXTENT PERMITTED UNDER APPLICABLE - LAW, THE ELASTIC SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, - AND ELASTIC AND ITS LICENSORS MAKE NO WARRANTIES WHETHER EXPRESSED, IMPLIED OR - STATUTORY REGARDING OR RELATING TO THE ELASTIC SOFTWARE. TO THE MAXIMUM EXTENT - PERMITTED UNDER APPLICABLE LAW, ELASTIC AND ITS LICENSORS SPECIFICALLY - DISCLAIM ALL IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR - PURPOSE AND NON-INFRINGEMENT WITH RESPECT TO THE ELASTIC SOFTWARE, AND WITH - RESPECT TO THE USE OF THE FOREGOING. FURTHER, ELASTIC DOES NOT WARRANT RESULTS - OF USE OR THAT THE ELASTIC SOFTWARE WILL BE ERROR FREE OR THAT THE USE OF THE - ELASTIC SOFTWARE WILL BE UNINTERRUPTED. - - 4.2 Limitation of Liability. IN NO EVENT SHALL ELASTIC OR ITS LICENSORS BE - LIABLE TO YOU OR ANY THIRD PARTY FOR ANY DIRECT OR INDIRECT DAMAGES, - INCLUDING, WITHOUT LIMITATION, FOR ANY LOSS OF PROFITS, LOSS OF USE, BUSINESS - INTERRUPTION, LOSS OF DATA, COST OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY - SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, IN CONNECTION WITH - OR ARISING OUT OF THE USE OR INABILITY TO USE THE ELASTIC SOFTWARE, OR THE - PERFORMANCE OF OR FAILURE TO PERFORM THIS AGREEMENT, WHETHER ALLEGED AS A - BREACH OF CONTRACT OR TORTIOUS CONDUCT, INCLUDING NEGLIGENCE, EVEN IF ELASTIC - HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - -5. MISCELLANEOUS - - This Agreement completely and exclusively states the entire agreement of the - parties regarding the subject matter herein, and it supersedes, and its terms - govern, all prior proposals, agreements, or other communications between the - parties, oral or written, regarding such subject matter. This Agreement may be - modified by Elastic from time to time, and any such modifications will be - effective upon the "Posted Date" set forth at the top of the modified - Agreement. If any provision hereof is held unenforceable, this Agreement will - continue without said provision and be interpreted to reflect the original - intent of the parties. This Agreement and any non-contractual obligation - arising out of or in connection with it, is governed exclusively by Dutch law. - This Agreement shall not be governed by the 1980 UN Convention on Contracts - for the International Sale of Goods. All disputes arising out of or in - connection with this Agreement, including its existence and validity, shall be - resolved by the courts with jurisdiction in Amsterdam, The Netherlands, except - where mandatory law provides for the courts at another location in The - Netherlands to have jurisdiction. The parties hereby irrevocably waive any and - all claims and defenses either might otherwise have in any such action or - proceeding in any of such courts based upon any alleged lack of personal - jurisdiction, improper venue, forum non conveniens or any similar claim or - defense. A breach or threatened breach, by You of Section 2 may cause - irreparable harm for which damages at law may not provide adequate relief, and - therefore Elastic shall be entitled to seek injunctive relief without being - required to post a bond. You may not assign this Agreement (including by - operation of law in connection with a merger or acquisition), in whole or in - part to any third party without the prior written consent of Elastic, which - may be withheld or granted by Elastic in its sole and absolute discretion. - Any assignment in violation of the preceding sentence is void. Notices to - Elastic may also be sent to legal@elastic.co. - -6. DEFINITIONS - - The following terms have the meanings ascribed: - - 6.1 "Affiliate" means, with respect to a party, any entity that controls, is - controlled by, or which is under common control with, such party, where - "control" means ownership of at least fifty percent (50%) of the outstanding - voting shares of the entity, or the contractual right to establish policy for, - and manage the operations of, the entity. - - 6.2 "Basic Features and Functions" means those features and functions of the - Elastic Software that are eligible for use under a Basic license, as set forth - at https://www.elastic.co/subscriptions, as may be modified by Elastic from - time to time. - - 6.3 "Commercial Software" means the Elastic Software Source Code in any file - containing a header stating the contents are subject to the Elastic License or - which is contained in the repository folder labeled "x-pack", unless a LICENSE - file present in the directory subtree declares a different license. - - 6.4 "Derivative Work of the Commercial Software" means, for purposes of this - Agreement, any modification(s) or enhancement(s) to the Commercial Software, - which represent, as a whole, an original work of authorship. - - 6.5 "License" means a limited, non-exclusive, non-transferable, fully paid up, - royalty free, right and license, without the right to grant or authorize - sublicenses, solely for Your internal business operations to (i) install and - use the applicable Features and Functions of the Elastic Software in Object - Code, and (ii) permit Contractors and Your Affiliates to use the Elastic - software as set forth in (i) above, provided that such use by Contractors must - be solely for Your benefit and/or the benefit of Your Affiliates, and You - shall be responsible for all acts and omissions of such Contractors and - Affiliates in connection with their use of the Elastic software that are - contrary to the terms and conditions of this Agreement. - - 6.6 "License Key" means a sequence of bytes, including but not limited to a - JSON blob, that is used to enable certain features and functions of the - Elastic Software. - - 6.7 "Marks and Notices" means all Elastic trademarks, trade names, logos and - notices present on the Documentation as originally provided by Elastic. - - 6.8 "Non-production Environment" means an environment for development, testing - or quality assurance, where software is not used for production purposes. - - 6.9 "Object Code" means any form resulting from mechanical transformation or - translation of Source Code form, including but not limited to compiled object - code, generated documentation, and conversions to other media types. - - 6.10 "Source Code" means the preferred form of computer software for making - modifications, including but not limited to software source code, - documentation source, and configuration files. - - 6.11 "Subscription" means the right to receive Support Services and a License - to the Commercial Software.