mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-03-24 17:09:48 +00:00
[PURIFY] remove all trace of x-pack index lifecycle management (#20)
This commit removes all trace of Elastic licensed ILM. Signed-off-by: Peter Nied <petern@amazon.com>
This commit is contained in:
parent
46f37bfa81
commit
4aee8e56db
@ -492,11 +492,7 @@ public class ElasticsearchCluster implements TestClusterConfiguration, Named {
|
||||
private void addWaitForClusterHealth() {
|
||||
waitConditions.put("cluster health yellow", (node) -> {
|
||||
try {
|
||||
WaitForHttpResource wait = new WaitForHttpResource(
|
||||
"http",
|
||||
getFirstNode().getHttpSocketURI(),
|
||||
nodes.size()
|
||||
);
|
||||
WaitForHttpResource wait = new WaitForHttpResource("http", getFirstNode().getHttpSocketURI(), nodes.size());
|
||||
|
||||
List<Map<String, String>> credentials = getFirstNode().getCredentials();
|
||||
if (getFirstNode().getCredentials().isEmpty() == false) {
|
||||
|
@ -32,7 +32,6 @@ import org.elasticsearch.gradle.PropertyNormalization;
|
||||
import org.elasticsearch.gradle.ReaperService;
|
||||
import org.elasticsearch.gradle.Version;
|
||||
import org.elasticsearch.gradle.VersionProperties;
|
||||
import org.elasticsearch.gradle.http.WaitForHttpResource;
|
||||
import org.elasticsearch.gradle.info.BuildParams;
|
||||
import org.gradle.api.Action;
|
||||
import org.gradle.api.Named;
|
||||
@ -72,7 +71,6 @@ import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
@ -1,686 +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.core.AcknowledgedResponse;
|
||||
import org.elasticsearch.client.indexlifecycle.DeleteLifecyclePolicyRequest;
|
||||
import org.elasticsearch.client.indexlifecycle.ExplainLifecycleRequest;
|
||||
import org.elasticsearch.client.indexlifecycle.ExplainLifecycleResponse;
|
||||
import org.elasticsearch.client.indexlifecycle.GetLifecyclePolicyRequest;
|
||||
import org.elasticsearch.client.indexlifecycle.GetLifecyclePolicyResponse;
|
||||
import org.elasticsearch.client.indexlifecycle.LifecycleManagementStatusRequest;
|
||||
import org.elasticsearch.client.indexlifecycle.LifecycleManagementStatusResponse;
|
||||
import org.elasticsearch.client.indexlifecycle.PutLifecyclePolicyRequest;
|
||||
import org.elasticsearch.client.indexlifecycle.RemoveIndexLifecyclePolicyRequest;
|
||||
import org.elasticsearch.client.indexlifecycle.RemoveIndexLifecyclePolicyResponse;
|
||||
import org.elasticsearch.client.indexlifecycle.RetryLifecyclePolicyRequest;
|
||||
import org.elasticsearch.client.indexlifecycle.StartILMRequest;
|
||||
import org.elasticsearch.client.indexlifecycle.StopILMRequest;
|
||||
import org.elasticsearch.client.slm.DeleteSnapshotLifecyclePolicyRequest;
|
||||
import org.elasticsearch.client.slm.ExecuteSnapshotLifecyclePolicyRequest;
|
||||
import org.elasticsearch.client.slm.ExecuteSnapshotLifecyclePolicyResponse;
|
||||
import org.elasticsearch.client.slm.ExecuteSnapshotLifecycleRetentionRequest;
|
||||
import org.elasticsearch.client.slm.GetSnapshotLifecyclePolicyRequest;
|
||||
import org.elasticsearch.client.slm.GetSnapshotLifecyclePolicyResponse;
|
||||
import org.elasticsearch.client.slm.GetSnapshotLifecycleStatsRequest;
|
||||
import org.elasticsearch.client.slm.GetSnapshotLifecycleStatsResponse;
|
||||
import org.elasticsearch.client.slm.PutSnapshotLifecyclePolicyRequest;
|
||||
import org.elasticsearch.client.slm.SnapshotLifecycleManagementStatusRequest;
|
||||
import org.elasticsearch.client.slm.StartSLMRequest;
|
||||
import org.elasticsearch.client.slm.StopSLMRequest;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static java.util.Collections.emptySet;
|
||||
|
||||
public class IndexLifecycleClient {
|
||||
private final RestHighLevelClient restHighLevelClient;
|
||||
|
||||
IndexLifecycleClient(RestHighLevelClient restHighLevelClient) {
|
||||
this.restHighLevelClient = restHighLevelClient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve one or more lifecycle policy definition. See
|
||||
* <a href="https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high-ilm-ilm-get-lifecycle-policy.html">
|
||||
* the docs</a> 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 GetLifecyclePolicyResponse getLifecyclePolicy(GetLifecyclePolicyRequest request,
|
||||
RequestOptions options) throws IOException {
|
||||
return restHighLevelClient.performRequestAndParseEntity(request, IndexLifecycleRequestConverters::getLifecyclePolicy, options,
|
||||
GetLifecyclePolicyResponse::fromXContent, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously retrieve one or more lifecycle policy definition. See
|
||||
* <a href="https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high-ilm-ilm-get-lifecycle-policy.html">
|
||||
* the docs</a> 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 getLifecyclePolicyAsync(GetLifecyclePolicyRequest request, RequestOptions options,
|
||||
ActionListener<GetLifecyclePolicyResponse> listener) {
|
||||
return restHighLevelClient.performRequestAsyncAndParseEntity(request, IndexLifecycleRequestConverters::getLifecyclePolicy, options,
|
||||
GetLifecyclePolicyResponse::fromXContent, listener, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create or modify a lifecycle definition. See <a href=
|
||||
* "https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high-ilm-ilm-put-lifecycle-policy.html">
|
||||
* the docs</a> 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 AcknowledgedResponse putLifecyclePolicy(PutLifecyclePolicyRequest request,
|
||||
RequestOptions options) throws IOException {
|
||||
return restHighLevelClient.performRequestAndParseEntity(request, IndexLifecycleRequestConverters::putLifecyclePolicy, options,
|
||||
AcknowledgedResponse::fromXContent, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously create or modify a lifecycle definition. See <a href=
|
||||
* "https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high-ilm-ilm-put-lifecycle-policy.html">
|
||||
* the docs</a> 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 putLifecyclePolicyAsync(PutLifecyclePolicyRequest request, RequestOptions options,
|
||||
ActionListener<AcknowledgedResponse> listener) {
|
||||
return restHighLevelClient.performRequestAsyncAndParseEntity(request, IndexLifecycleRequestConverters::putLifecyclePolicy, options,
|
||||
AcknowledgedResponse::fromXContent, listener, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a lifecycle definition
|
||||
* See <pre>
|
||||
* https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/
|
||||
* java-rest-high-ilm-ilm-delete-lifecycle-policy.html
|
||||
* </pre>
|
||||
* 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 AcknowledgedResponse deleteLifecyclePolicy(DeleteLifecyclePolicyRequest request,
|
||||
RequestOptions options) throws IOException {
|
||||
return restHighLevelClient.performRequestAndParseEntity(request, IndexLifecycleRequestConverters::deleteLifecyclePolicy, options,
|
||||
AcknowledgedResponse::fromXContent, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously delete a lifecycle definition
|
||||
* See <pre>
|
||||
* https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/
|
||||
* java-rest-high-ilm-ilm-delete-lifecycle-policy.html
|
||||
* </pre>
|
||||
* 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 deleteLifecyclePolicyAsync(DeleteLifecyclePolicyRequest request, RequestOptions options,
|
||||
ActionListener<AcknowledgedResponse> listener) {
|
||||
return restHighLevelClient.performRequestAsyncAndParseEntity(
|
||||
request, IndexLifecycleRequestConverters::deleteLifecyclePolicy, options,
|
||||
AcknowledgedResponse::fromXContent, listener, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the index lifecycle policy for an index
|
||||
* See <pre>
|
||||
* https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/
|
||||
* java-rest-high-ilm-ilm-remove-lifecycle-policy-from-index.html
|
||||
* </pre>
|
||||
* 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 RemoveIndexLifecyclePolicyResponse removeIndexLifecyclePolicy(RemoveIndexLifecyclePolicyRequest request,
|
||||
RequestOptions options) throws IOException {
|
||||
return restHighLevelClient.performRequestAndParseEntity(request, IndexLifecycleRequestConverters::removeIndexLifecyclePolicy,
|
||||
options, RemoveIndexLifecyclePolicyResponse::fromXContent, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously remove the index lifecycle policy for an index
|
||||
* See <pre>
|
||||
* https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/
|
||||
* java-rest-high-ilm-ilm-remove-lifecycle-policy-from-index.html
|
||||
* </pre>
|
||||
* 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 removeIndexLifecyclePolicyAsync(RemoveIndexLifecyclePolicyRequest request, RequestOptions options,
|
||||
ActionListener<RemoveIndexLifecyclePolicyResponse> listener) {
|
||||
return restHighLevelClient.performRequestAsyncAndParseEntity(
|
||||
request, IndexLifecycleRequestConverters::removeIndexLifecyclePolicy, options,
|
||||
RemoveIndexLifecyclePolicyResponse::fromXContent, listener, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the Index Lifecycle Management feature.
|
||||
* See <pre>
|
||||
* https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/
|
||||
* java-rest-high-ilm-ilm-start-ilm.html
|
||||
* </pre>
|
||||
* 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 AcknowledgedResponse startILM(StartILMRequest request, RequestOptions options) throws IOException {
|
||||
return restHighLevelClient.performRequestAndParseEntity(request, IndexLifecycleRequestConverters::startILM, options,
|
||||
AcknowledgedResponse::fromXContent, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously start the Index Lifecycle Management feature.
|
||||
* See <pre>
|
||||
* https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/
|
||||
* java-rest-high-ilm-ilm-start-ilm.html
|
||||
* </pre>
|
||||
* 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 startILMAsync(StartILMRequest request, RequestOptions options, ActionListener<AcknowledgedResponse> listener) {
|
||||
return restHighLevelClient.performRequestAsyncAndParseEntity(request, IndexLifecycleRequestConverters::startILM, options,
|
||||
AcknowledgedResponse::fromXContent, listener, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop the Index Lifecycle Management feature.
|
||||
* See <pre>
|
||||
* https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/
|
||||
* java-rest-high-ilm-ilm-stop-ilm.html
|
||||
* </pre>
|
||||
* 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 AcknowledgedResponse stopILM(StopILMRequest request, RequestOptions options) throws IOException {
|
||||
return restHighLevelClient.performRequestAndParseEntity(request, IndexLifecycleRequestConverters::stopILM, options,
|
||||
AcknowledgedResponse::fromXContent, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously stop the Index Lifecycle Management feature.
|
||||
* See <pre>
|
||||
* https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/
|
||||
* java-rest-high-ilm-ilm-stop-ilm.html
|
||||
* </pre>
|
||||
* 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 stopILMAsync(StopILMRequest request, RequestOptions options, ActionListener<AcknowledgedResponse> listener) {
|
||||
return restHighLevelClient.performRequestAsyncAndParseEntity(request, IndexLifecycleRequestConverters::stopILM, options,
|
||||
AcknowledgedResponse::fromXContent, listener, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the status of index lifecycle management
|
||||
* See <pre>
|
||||
* https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/
|
||||
* java-rest-high-ilm-ilm-status.html
|
||||
* </pre>
|
||||
* for more.
|
||||
*
|
||||
* @param request the request
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
*/
|
||||
public LifecycleManagementStatusResponse lifecycleManagementStatus(LifecycleManagementStatusRequest request, RequestOptions options)
|
||||
throws IOException {
|
||||
return restHighLevelClient.performRequestAndParseEntity(request, IndexLifecycleRequestConverters::lifecycleManagementStatus,
|
||||
options, LifecycleManagementStatusResponse::fromXContent, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously get the status of index lifecycle management
|
||||
* See <pre>
|
||||
* https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/
|
||||
* java-rest-high-ilm-ilm-status.html
|
||||
* </pre>
|
||||
* 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 lifecycleManagementStatusAsync(LifecycleManagementStatusRequest request, RequestOptions options,
|
||||
ActionListener<LifecycleManagementStatusResponse> listener) {
|
||||
return restHighLevelClient.performRequestAsyncAndParseEntity(
|
||||
request, IndexLifecycleRequestConverters::lifecycleManagementStatus, options,
|
||||
LifecycleManagementStatusResponse::fromXContent, listener, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Explain the lifecycle state for an index
|
||||
* See <pre>
|
||||
* https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/
|
||||
* java-rest-high-ilm-ilm-explain-lifecycle.html
|
||||
* </pre>
|
||||
* 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 ExplainLifecycleResponse explainLifecycle(ExplainLifecycleRequest request,RequestOptions options) throws IOException {
|
||||
return restHighLevelClient.performRequestAndParseEntity(request, IndexLifecycleRequestConverters::explainLifecycle, options,
|
||||
ExplainLifecycleResponse::fromXContent, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously explain the lifecycle state for an index
|
||||
* See <pre>
|
||||
* https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/
|
||||
* java-rest-high-ilm-ilm-explain-lifecycle.html
|
||||
* </pre>
|
||||
* 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 explainLifecycleAsync(ExplainLifecycleRequest request, RequestOptions options,
|
||||
ActionListener<ExplainLifecycleResponse> listener) {
|
||||
return restHighLevelClient.performRequestAsyncAndParseEntity(request, IndexLifecycleRequestConverters::explainLifecycle, options,
|
||||
ExplainLifecycleResponse::fromXContent, listener, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Retry lifecycle step for given indices
|
||||
* See <pre>
|
||||
* https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/
|
||||
* java-rest-high-ilm-ilm-retry-lifecycle-policy.html
|
||||
* </pre>
|
||||
* 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 AcknowledgedResponse retryLifecyclePolicy(RetryLifecyclePolicyRequest request, RequestOptions options) throws IOException {
|
||||
return restHighLevelClient.performRequestAndParseEntity(request, IndexLifecycleRequestConverters::retryLifecycle, options,
|
||||
AcknowledgedResponse::fromXContent, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously retry the lifecycle step for given indices
|
||||
* See <pre>
|
||||
* https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/
|
||||
* java-rest-high-ilm-ilm-retry-lifecycle-policy.html
|
||||
* </pre>
|
||||
* 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 retryLifecyclePolicyAsync(RetryLifecyclePolicyRequest request, RequestOptions options,
|
||||
ActionListener<AcknowledgedResponse> listener) {
|
||||
return restHighLevelClient.performRequestAsyncAndParseEntity(request, IndexLifecycleRequestConverters::retryLifecycle, options,
|
||||
AcknowledgedResponse::fromXContent, listener, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve one or more snapshot lifecycle policy definitions.
|
||||
* See <pre>
|
||||
* https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/
|
||||
* java-rest-high-ilm-slm-get-snapshot-lifecycle-policy.html
|
||||
* </pre>
|
||||
* 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 GetSnapshotLifecyclePolicyResponse getSnapshotLifecyclePolicy(GetSnapshotLifecyclePolicyRequest request,
|
||||
RequestOptions options) throws IOException {
|
||||
return restHighLevelClient.performRequestAndParseEntity(request, IndexLifecycleRequestConverters::getSnapshotLifecyclePolicy,
|
||||
options, GetSnapshotLifecyclePolicyResponse::fromXContent, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously retrieve one or more snapshot lifecycle policy definition.
|
||||
* See <pre>
|
||||
* https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/
|
||||
* java-rest-high-ilm-slm-get-snapshot-lifecycle-policy.html
|
||||
* </pre>
|
||||
* 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 getSnapshotLifecyclePolicyAsync(GetSnapshotLifecyclePolicyRequest request, RequestOptions options,
|
||||
ActionListener<GetSnapshotLifecyclePolicyResponse> listener) {
|
||||
return restHighLevelClient.performRequestAsyncAndParseEntity(request, IndexLifecycleRequestConverters::getSnapshotLifecyclePolicy,
|
||||
options, GetSnapshotLifecyclePolicyResponse::fromXContent, listener, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create or modify a snapshot lifecycle definition.
|
||||
* See <pre>
|
||||
* https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/
|
||||
* java-rest-high-ilm-slm-put-snapshot-lifecycle-policy.html
|
||||
* </pre>
|
||||
* 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 AcknowledgedResponse putSnapshotLifecyclePolicy(PutSnapshotLifecyclePolicyRequest request,
|
||||
RequestOptions options) throws IOException {
|
||||
return restHighLevelClient.performRequestAndParseEntity(request, IndexLifecycleRequestConverters::putSnapshotLifecyclePolicy,
|
||||
options, AcknowledgedResponse::fromXContent, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously create or modify a snapshot lifecycle definition.
|
||||
* See <pre>
|
||||
* https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/
|
||||
* java-rest-high-ilm-slm-put-snapshot-lifecycle-policy.html
|
||||
* </pre>
|
||||
* 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 putSnapshotLifecyclePolicyAsync(PutSnapshotLifecyclePolicyRequest request, RequestOptions options,
|
||||
ActionListener<AcknowledgedResponse> listener) {
|
||||
return restHighLevelClient.performRequestAsyncAndParseEntity(request, IndexLifecycleRequestConverters::putSnapshotLifecyclePolicy,
|
||||
options, AcknowledgedResponse::fromXContent, listener, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a snapshot lifecycle definition
|
||||
* See <pre>
|
||||
* https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/
|
||||
* java-rest-high-ilm-slm-delete-snapshot-lifecycle-policy.html
|
||||
* </pre>
|
||||
* 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 AcknowledgedResponse deleteSnapshotLifecyclePolicy(DeleteSnapshotLifecyclePolicyRequest request,
|
||||
RequestOptions options) throws IOException {
|
||||
return restHighLevelClient.performRequestAndParseEntity(request, IndexLifecycleRequestConverters::deleteSnapshotLifecyclePolicy,
|
||||
options, AcknowledgedResponse::fromXContent, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously delete a snapshot lifecycle definition
|
||||
* See <pre>
|
||||
* https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/
|
||||
* java-rest-high-ilm-slm-delete-snapshot-lifecycle-policy.html
|
||||
* </pre>
|
||||
* 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 deleteSnapshotLifecyclePolicyAsync(DeleteSnapshotLifecyclePolicyRequest request,
|
||||
RequestOptions options,ActionListener<AcknowledgedResponse> listener) {
|
||||
return restHighLevelClient.performRequestAsyncAndParseEntity(
|
||||
request, IndexLifecycleRequestConverters::deleteSnapshotLifecyclePolicy,
|
||||
options, AcknowledgedResponse::fromXContent, listener, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute a snapshot lifecycle definition
|
||||
* See <pre>
|
||||
* https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/
|
||||
* java-rest-high-ilm-slm-execute-snapshot-lifecycle-policy.html
|
||||
* </pre>
|
||||
* 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 ExecuteSnapshotLifecyclePolicyResponse executeSnapshotLifecyclePolicy(ExecuteSnapshotLifecyclePolicyRequest request,
|
||||
RequestOptions options) throws IOException {
|
||||
return restHighLevelClient.performRequestAndParseEntity(request, IndexLifecycleRequestConverters::executeSnapshotLifecyclePolicy,
|
||||
options, ExecuteSnapshotLifecyclePolicyResponse::fromXContent, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously execute a snapshot lifecycle definition
|
||||
* See <pre>
|
||||
* https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/
|
||||
* java-rest-high-ilm-slm-execute-snapshot-lifecycle-policy.html
|
||||
* </pre>
|
||||
* 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 executeSnapshotLifecyclePolicyAsync(
|
||||
ExecuteSnapshotLifecyclePolicyRequest request, RequestOptions options,
|
||||
ActionListener<ExecuteSnapshotLifecyclePolicyResponse> listener) {
|
||||
return restHighLevelClient.performRequestAsyncAndParseEntity(
|
||||
request, IndexLifecycleRequestConverters::executeSnapshotLifecyclePolicy,
|
||||
options, ExecuteSnapshotLifecyclePolicyResponse::fromXContent, listener, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute snapshot lifecycle retention
|
||||
* See <pre>
|
||||
* https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/
|
||||
* java-rest-high-ilm-slm-execute-snapshot-lifecycle-retention.html
|
||||
* </pre>
|
||||
* 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 AcknowledgedResponse executeSnapshotLifecycleRetention(ExecuteSnapshotLifecycleRetentionRequest request,
|
||||
RequestOptions options) throws IOException {
|
||||
return restHighLevelClient.performRequestAndParseEntity(request, IndexLifecycleRequestConverters::executeSnapshotLifecycleRetention,
|
||||
options, AcknowledgedResponse::fromXContent, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously execute snapshot lifecycle retention
|
||||
* See <pre>
|
||||
* https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/
|
||||
* java-rest-high-ilm-slm-execute-snapshot-lifecycle-retention.html
|
||||
* </pre>
|
||||
* 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 executeSnapshotLifecycleRetentionAsync(
|
||||
ExecuteSnapshotLifecycleRetentionRequest request, RequestOptions options,
|
||||
ActionListener<AcknowledgedResponse> listener) {
|
||||
return restHighLevelClient.performRequestAsyncAndParseEntity(
|
||||
request, IndexLifecycleRequestConverters::executeSnapshotLifecycleRetention,
|
||||
options, AcknowledgedResponse::fromXContent, listener, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve snapshot lifecycle statistics.
|
||||
* See <pre>
|
||||
* https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/
|
||||
* java-rest-high-ilm-slm-get-snapshot-lifecycle-stats.html
|
||||
* </pre>
|
||||
* 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 GetSnapshotLifecycleStatsResponse getSnapshotLifecycleStats(GetSnapshotLifecycleStatsRequest request,
|
||||
RequestOptions options) throws IOException {
|
||||
return restHighLevelClient.performRequestAndParseEntity(request, IndexLifecycleRequestConverters::getSnapshotLifecycleStats,
|
||||
options, GetSnapshotLifecycleStatsResponse::fromXContent, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously retrieve snapshot lifecycle statistics.
|
||||
* See <pre>
|
||||
* https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/
|
||||
* java-rest-high-ilm-slm-get-snapshot-lifecycle-stats.html
|
||||
* </pre>
|
||||
* 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
|
||||
*/
|
||||
public Cancellable getSnapshotLifecycleStatsAsync(GetSnapshotLifecycleStatsRequest request, RequestOptions options,
|
||||
ActionListener<GetSnapshotLifecycleStatsResponse> listener) {
|
||||
return restHighLevelClient.performRequestAsyncAndParseEntity(request, IndexLifecycleRequestConverters::getSnapshotLifecycleStats,
|
||||
options, GetSnapshotLifecycleStatsResponse::fromXContent, listener, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the Snapshot Lifecycle Management feature.
|
||||
* See <pre>
|
||||
* https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/
|
||||
* java-rest-high-ilm-slm-start-slm.html
|
||||
* </pre> 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 AcknowledgedResponse startSLM(StartSLMRequest request, RequestOptions options) throws IOException {
|
||||
return restHighLevelClient.performRequestAndParseEntity(request, IndexLifecycleRequestConverters::startSLM, options,
|
||||
AcknowledgedResponse::fromXContent, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously start the Snapshot Lifecycle Management feature.
|
||||
* See <pre>
|
||||
* https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/
|
||||
* java-rest-high-ilm-slm-start-slm.html
|
||||
* </pre> for more.
|
||||
* @param request the request
|
||||
* @param listener the listener to be notified upon request completion
|
||||
* @return cancellable that may be used to cancel the request
|
||||
*/
|
||||
public Cancellable startSLMAsync(StartSLMRequest request, RequestOptions options, ActionListener<AcknowledgedResponse> listener) {
|
||||
return restHighLevelClient.performRequestAsyncAndParseEntity(request, IndexLifecycleRequestConverters::startSLM, options,
|
||||
AcknowledgedResponse::fromXContent, listener, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop the Snapshot Lifecycle Management feature.
|
||||
* See <pre>
|
||||
* https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/
|
||||
* java-rest-high-ilm-slm-stop-slm.html
|
||||
* </pre> 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 AcknowledgedResponse stopSLM(StopSLMRequest request, RequestOptions options) throws IOException {
|
||||
return restHighLevelClient.performRequestAndParseEntity(request, IndexLifecycleRequestConverters::stopSLM, options,
|
||||
AcknowledgedResponse::fromXContent, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously stop the Snapshot Lifecycle Management feature.
|
||||
* See <pre>
|
||||
* https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/
|
||||
* java-rest-high-ilm-slm-stop-slm.html
|
||||
* </pre> 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 stopSLMAsync(StopSLMRequest request, RequestOptions options, ActionListener<AcknowledgedResponse> listener) {
|
||||
return restHighLevelClient.performRequestAsyncAndParseEntity(request, IndexLifecycleRequestConverters::stopSLM, options,
|
||||
AcknowledgedResponse::fromXContent, listener, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the status of Snapshot Lifecycle Management.
|
||||
* See <pre>
|
||||
* https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/
|
||||
* java-rest-high-ilm-slm-status.html
|
||||
* </pre> 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 LifecycleManagementStatusResponse getSLMStatus(SnapshotLifecycleManagementStatusRequest request,
|
||||
RequestOptions options) throws IOException {
|
||||
return restHighLevelClient.performRequestAndParseEntity(request, IndexLifecycleRequestConverters::snapshotLifecycleManagementStatus,
|
||||
options, LifecycleManagementStatusResponse::fromXContent, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously get the status of Snapshot Lifecycle Management.
|
||||
* See <pre>
|
||||
* https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/
|
||||
* java-rest-high-ilm-slm-status.html
|
||||
* </pre> 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 getSLMStatusAsync(SnapshotLifecycleManagementStatusRequest request, RequestOptions options,
|
||||
ActionListener<LifecycleManagementStatusResponse> listener) {
|
||||
return restHighLevelClient.performRequestAsyncAndParseEntity(request,
|
||||
IndexLifecycleRequestConverters::snapshotLifecycleManagementStatus, options, LifecycleManagementStatusResponse::fromXContent,
|
||||
listener, emptySet());
|
||||
}
|
||||
}
|
@ -1,284 +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.indexlifecycle.DeleteLifecyclePolicyRequest;
|
||||
import org.elasticsearch.client.indexlifecycle.ExplainLifecycleRequest;
|
||||
import org.elasticsearch.client.indexlifecycle.GetLifecyclePolicyRequest;
|
||||
import org.elasticsearch.client.indexlifecycle.LifecycleManagementStatusRequest;
|
||||
import org.elasticsearch.client.indexlifecycle.PutLifecyclePolicyRequest;
|
||||
import org.elasticsearch.client.indexlifecycle.RemoveIndexLifecyclePolicyRequest;
|
||||
import org.elasticsearch.client.indexlifecycle.RetryLifecyclePolicyRequest;
|
||||
import org.elasticsearch.client.indexlifecycle.StartILMRequest;
|
||||
import org.elasticsearch.client.indexlifecycle.StopILMRequest;
|
||||
import org.elasticsearch.client.slm.DeleteSnapshotLifecyclePolicyRequest;
|
||||
import org.elasticsearch.client.slm.ExecuteSnapshotLifecyclePolicyRequest;
|
||||
import org.elasticsearch.client.slm.ExecuteSnapshotLifecycleRetentionRequest;
|
||||
import org.elasticsearch.client.slm.GetSnapshotLifecyclePolicyRequest;
|
||||
import org.elasticsearch.client.slm.GetSnapshotLifecycleStatsRequest;
|
||||
import org.elasticsearch.client.slm.PutSnapshotLifecyclePolicyRequest;
|
||||
import org.elasticsearch.client.slm.SnapshotLifecycleManagementStatusRequest;
|
||||
import org.elasticsearch.client.slm.StartSLMRequest;
|
||||
import org.elasticsearch.client.slm.StopSLMRequest;
|
||||
import org.elasticsearch.common.Strings;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
final class IndexLifecycleRequestConverters {
|
||||
|
||||
private IndexLifecycleRequestConverters() {}
|
||||
|
||||
static Request getLifecyclePolicy(GetLifecyclePolicyRequest getLifecyclePolicyRequest) {
|
||||
String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_ilm/policy")
|
||||
.addCommaSeparatedPathParts(getLifecyclePolicyRequest.getPolicyNames()).build();
|
||||
Request request = new Request(HttpGet.METHOD_NAME, endpoint);
|
||||
RequestConverters.Params params = new RequestConverters.Params();
|
||||
params.withMasterTimeout(getLifecyclePolicyRequest.masterNodeTimeout());
|
||||
params.withTimeout(getLifecyclePolicyRequest.timeout());
|
||||
request.addParameters(params.asMap());
|
||||
return request;
|
||||
}
|
||||
|
||||
static Request putLifecyclePolicy(PutLifecyclePolicyRequest putLifecycleRequest) throws IOException {
|
||||
String endpoint = new RequestConverters.EndpointBuilder()
|
||||
.addPathPartAsIs("_ilm/policy")
|
||||
.addPathPartAsIs(putLifecycleRequest.getName())
|
||||
.build();
|
||||
Request request = new Request(HttpPut.METHOD_NAME, endpoint);
|
||||
RequestConverters.Params params = new RequestConverters.Params();
|
||||
params.withMasterTimeout(putLifecycleRequest.masterNodeTimeout());
|
||||
params.withTimeout(putLifecycleRequest.timeout());
|
||||
request.addParameters(params.asMap());
|
||||
request.setEntity(RequestConverters.createEntity(putLifecycleRequest, RequestConverters.REQUEST_BODY_CONTENT_TYPE));
|
||||
return request;
|
||||
}
|
||||
|
||||
static Request deleteLifecyclePolicy(DeleteLifecyclePolicyRequest deleteLifecyclePolicyRequest) {
|
||||
Request request = new Request(HttpDelete.METHOD_NAME,
|
||||
new RequestConverters.EndpointBuilder()
|
||||
.addPathPartAsIs("_ilm/policy")
|
||||
.addPathPartAsIs(deleteLifecyclePolicyRequest.getLifecyclePolicy())
|
||||
.build());
|
||||
RequestConverters.Params params = new RequestConverters.Params();
|
||||
params.withMasterTimeout(deleteLifecyclePolicyRequest.masterNodeTimeout());
|
||||
params.withTimeout(deleteLifecyclePolicyRequest.timeout());
|
||||
request.addParameters(params.asMap());
|
||||
return request;
|
||||
}
|
||||
|
||||
static Request removeIndexLifecyclePolicy(RemoveIndexLifecyclePolicyRequest removePolicyRequest) {
|
||||
String[] indices = removePolicyRequest.indices() == null ?
|
||||
Strings.EMPTY_ARRAY : removePolicyRequest.indices().toArray(new String[] {});
|
||||
Request request = new Request(HttpPost.METHOD_NAME,
|
||||
new RequestConverters.EndpointBuilder()
|
||||
.addCommaSeparatedPathParts(indices)
|
||||
.addPathPartAsIs("_ilm", "remove")
|
||||
.build());
|
||||
RequestConverters.Params params = new RequestConverters.Params();
|
||||
params.withIndicesOptions(removePolicyRequest.indicesOptions());
|
||||
params.withMasterTimeout(removePolicyRequest.masterNodeTimeout());
|
||||
request.addParameters(params.asMap());
|
||||
return request;
|
||||
}
|
||||
|
||||
static Request startILM(StartILMRequest startILMRequest) {
|
||||
Request request = new Request(HttpPost.METHOD_NAME,
|
||||
new RequestConverters.EndpointBuilder()
|
||||
.addPathPartAsIs("_ilm")
|
||||
.addPathPartAsIs("start")
|
||||
.build());
|
||||
RequestConverters.Params params = new RequestConverters.Params();
|
||||
params.withMasterTimeout(startILMRequest.masterNodeTimeout());
|
||||
params.withTimeout(startILMRequest.timeout());
|
||||
request.addParameters(params.asMap());
|
||||
return request;
|
||||
}
|
||||
|
||||
static Request stopILM(StopILMRequest stopILMRequest) {
|
||||
Request request = new Request(HttpPost.METHOD_NAME,
|
||||
new RequestConverters.EndpointBuilder()
|
||||
.addPathPartAsIs("_ilm")
|
||||
.addPathPartAsIs("stop")
|
||||
.build());
|
||||
RequestConverters.Params params = new RequestConverters.Params();
|
||||
params.withMasterTimeout(stopILMRequest.masterNodeTimeout());
|
||||
params.withTimeout(stopILMRequest.timeout());
|
||||
request.addParameters(params.asMap());
|
||||
return request;
|
||||
}
|
||||
|
||||
static Request lifecycleManagementStatus(LifecycleManagementStatusRequest lifecycleManagementStatusRequest){
|
||||
Request request = new Request(HttpGet.METHOD_NAME,
|
||||
new RequestConverters.EndpointBuilder()
|
||||
.addPathPartAsIs("_ilm")
|
||||
.addPathPartAsIs("status")
|
||||
.build());
|
||||
RequestConverters.Params params = new RequestConverters.Params();
|
||||
params.withMasterTimeout(lifecycleManagementStatusRequest.masterNodeTimeout());
|
||||
params.withTimeout(lifecycleManagementStatusRequest.timeout());
|
||||
request.addParameters(params.asMap());
|
||||
return request;
|
||||
}
|
||||
|
||||
static Request explainLifecycle(ExplainLifecycleRequest explainLifecycleRequest) {
|
||||
Request request = new Request(HttpGet.METHOD_NAME,
|
||||
new RequestConverters.EndpointBuilder()
|
||||
.addCommaSeparatedPathParts(explainLifecycleRequest.getIndices())
|
||||
.addPathPartAsIs("_ilm")
|
||||
.addPathPartAsIs("explain")
|
||||
.build());
|
||||
RequestConverters.Params params = new RequestConverters.Params();
|
||||
params.withIndicesOptions(explainLifecycleRequest.indicesOptions());
|
||||
params.withMasterTimeout(explainLifecycleRequest.masterNodeTimeout());
|
||||
request.addParameters(params.asMap());
|
||||
return request;
|
||||
}
|
||||
|
||||
static Request retryLifecycle(RetryLifecyclePolicyRequest retryLifecyclePolicyRequest) {
|
||||
Request request = new Request(HttpPost.METHOD_NAME,
|
||||
new RequestConverters.EndpointBuilder()
|
||||
.addCommaSeparatedPathParts(retryLifecyclePolicyRequest.getIndices())
|
||||
.addPathPartAsIs("_ilm")
|
||||
.addPathPartAsIs("retry")
|
||||
.build());
|
||||
RequestConverters.Params params = new RequestConverters.Params();
|
||||
params.withMasterTimeout(retryLifecyclePolicyRequest.masterNodeTimeout());
|
||||
params.withTimeout(retryLifecyclePolicyRequest.timeout());
|
||||
request.addParameters(params.asMap());
|
||||
return request;
|
||||
}
|
||||
|
||||
static Request getSnapshotLifecyclePolicy(GetSnapshotLifecyclePolicyRequest getSnapshotLifecyclePolicyRequest) {
|
||||
String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_slm/policy")
|
||||
.addCommaSeparatedPathParts(getSnapshotLifecyclePolicyRequest.getPolicyIds()).build();
|
||||
Request request = new Request(HttpGet.METHOD_NAME, endpoint);
|
||||
RequestConverters.Params params = new RequestConverters.Params();
|
||||
params.withMasterTimeout(getSnapshotLifecyclePolicyRequest.masterNodeTimeout());
|
||||
params.withTimeout(getSnapshotLifecyclePolicyRequest.timeout());
|
||||
request.addParameters(params.asMap());
|
||||
return request;
|
||||
}
|
||||
|
||||
static Request putSnapshotLifecyclePolicy(PutSnapshotLifecyclePolicyRequest putSnapshotLifecyclePolicyRequest) throws IOException {
|
||||
String endpoint = new RequestConverters.EndpointBuilder()
|
||||
.addPathPartAsIs("_slm/policy")
|
||||
.addPathPartAsIs(putSnapshotLifecyclePolicyRequest.getPolicy().getId())
|
||||
.build();
|
||||
Request request = new Request(HttpPut.METHOD_NAME, endpoint);
|
||||
RequestConverters.Params params = new RequestConverters.Params();
|
||||
params.withMasterTimeout(putSnapshotLifecyclePolicyRequest.masterNodeTimeout());
|
||||
params.withTimeout(putSnapshotLifecyclePolicyRequest.timeout());
|
||||
request.addParameters(params.asMap());
|
||||
request.setEntity(RequestConverters.createEntity(putSnapshotLifecyclePolicyRequest, RequestConverters.REQUEST_BODY_CONTENT_TYPE));
|
||||
return request;
|
||||
}
|
||||
|
||||
static Request deleteSnapshotLifecyclePolicy(DeleteSnapshotLifecyclePolicyRequest deleteSnapshotLifecyclePolicyRequest) {
|
||||
Request request = new Request(HttpDelete.METHOD_NAME,
|
||||
new RequestConverters.EndpointBuilder()
|
||||
.addPathPartAsIs("_slm/policy")
|
||||
.addPathPartAsIs(deleteSnapshotLifecyclePolicyRequest.getPolicyId())
|
||||
.build());
|
||||
RequestConverters.Params params = new RequestConverters.Params();
|
||||
params.withMasterTimeout(deleteSnapshotLifecyclePolicyRequest.masterNodeTimeout());
|
||||
params.withTimeout(deleteSnapshotLifecyclePolicyRequest.timeout());
|
||||
request.addParameters(params.asMap());
|
||||
return request;
|
||||
}
|
||||
|
||||
static Request executeSnapshotLifecyclePolicy(ExecuteSnapshotLifecyclePolicyRequest executeSnapshotLifecyclePolicyRequest) {
|
||||
Request request = new Request(HttpPost.METHOD_NAME,
|
||||
new RequestConverters.EndpointBuilder()
|
||||
.addPathPartAsIs("_slm/policy")
|
||||
.addPathPartAsIs(executeSnapshotLifecyclePolicyRequest.getPolicyId())
|
||||
.addPathPartAsIs("_execute")
|
||||
.build());
|
||||
RequestConverters.Params params = new RequestConverters.Params();
|
||||
params.withMasterTimeout(executeSnapshotLifecyclePolicyRequest.masterNodeTimeout());
|
||||
params.withTimeout(executeSnapshotLifecyclePolicyRequest.timeout());
|
||||
request.addParameters(params.asMap());
|
||||
return request;
|
||||
}
|
||||
|
||||
static Request executeSnapshotLifecycleRetention(ExecuteSnapshotLifecycleRetentionRequest executeSnapshotLifecycleRetentionRequest) {
|
||||
Request request = new Request(HttpPost.METHOD_NAME,
|
||||
new RequestConverters.EndpointBuilder()
|
||||
.addPathPartAsIs("_slm/_execute_retention")
|
||||
.build());
|
||||
RequestConverters.Params params = new RequestConverters.Params();
|
||||
params.withMasterTimeout(executeSnapshotLifecycleRetentionRequest.masterNodeTimeout());
|
||||
params.withTimeout(executeSnapshotLifecycleRetentionRequest.timeout());
|
||||
request.addParameters(params.asMap());
|
||||
return request;
|
||||
}
|
||||
|
||||
static Request getSnapshotLifecycleStats(GetSnapshotLifecycleStatsRequest getSnapshotLifecycleStatsRequest) {
|
||||
String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_slm/stats").build();
|
||||
Request request = new Request(HttpGet.METHOD_NAME, endpoint);
|
||||
RequestConverters.Params params = new RequestConverters.Params();
|
||||
params.withMasterTimeout(getSnapshotLifecycleStatsRequest.masterNodeTimeout());
|
||||
params.withTimeout(getSnapshotLifecycleStatsRequest.timeout());
|
||||
request.addParameters(params.asMap());
|
||||
return request;
|
||||
}
|
||||
|
||||
static Request snapshotLifecycleManagementStatus(SnapshotLifecycleManagementStatusRequest snapshotLifecycleManagementStatusRequest){
|
||||
Request request = new Request(HttpGet.METHOD_NAME,
|
||||
new RequestConverters.EndpointBuilder()
|
||||
.addPathPartAsIs("_slm")
|
||||
.addPathPartAsIs("status")
|
||||
.build());
|
||||
RequestConverters.Params params = new RequestConverters.Params();
|
||||
params.withMasterTimeout(snapshotLifecycleManagementStatusRequest.masterNodeTimeout());
|
||||
params.withTimeout(snapshotLifecycleManagementStatusRequest.timeout());
|
||||
request.addParameters(params.asMap());
|
||||
return request;
|
||||
}
|
||||
|
||||
static Request startSLM(StartSLMRequest startSLMRequest) {
|
||||
Request request = new Request(HttpPost.METHOD_NAME,
|
||||
new RequestConverters.EndpointBuilder()
|
||||
.addPathPartAsIs("_slm")
|
||||
.addPathPartAsIs("start")
|
||||
.build());
|
||||
RequestConverters.Params params = new RequestConverters.Params();
|
||||
params.withMasterTimeout(startSLMRequest.masterNodeTimeout());
|
||||
params.withTimeout(startSLMRequest.timeout());
|
||||
request.addParameters(params.asMap());
|
||||
return request;
|
||||
}
|
||||
|
||||
static Request stopSLM(StopSLMRequest stopSLMRequest) {
|
||||
Request request = new Request(HttpPost.METHOD_NAME,
|
||||
new RequestConverters.EndpointBuilder()
|
||||
.addPathPartAsIs("_slm")
|
||||
.addPathPartAsIs("stop")
|
||||
.build());
|
||||
RequestConverters.Params params = new RequestConverters.Params();
|
||||
params.withMasterTimeout(stopSLMRequest.masterNodeTimeout());
|
||||
params.withTimeout(stopSLMRequest.timeout());
|
||||
request.addParameters(params.asMap());
|
||||
return request;
|
||||
}
|
||||
}
|
@ -261,7 +261,6 @@ public class RestHighLevelClient implements Closeable {
|
||||
private final SnapshotClient snapshotClient = new SnapshotClient(this);
|
||||
private final TasksClient tasksClient = new TasksClient(this);
|
||||
private final WatcherClient watcherClient = new WatcherClient(this);
|
||||
private final IndexLifecycleClient ilmClient = new IndexLifecycleClient(this);
|
||||
private final TransformClient transformClient = new TransformClient(this);
|
||||
|
||||
/**
|
||||
@ -363,17 +362,6 @@ public class RestHighLevelClient implements Closeable {
|
||||
*/
|
||||
public WatcherClient watcher() { return watcherClient; }
|
||||
|
||||
/**
|
||||
* A wrapper for the {@link RestHighLevelClient} that provides methods for
|
||||
* accessing the Elastic Index Lifecycle APIs.
|
||||
* <p>
|
||||
* See the <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/index-lifecycle-management-api.html"> X-Pack APIs
|
||||
* on elastic.co</a> for more information.
|
||||
*/
|
||||
public IndexLifecycleClient indexLifecycle() {
|
||||
return ilmClient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides methods for accessing the Elastic Licensed Data Frame APIs that
|
||||
* are shipped with the Elastic Stack distribution of Elasticsearch. All of
|
||||
|
@ -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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.ToXContentObject;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class AllocateAction implements LifecycleAction, ToXContentObject {
|
||||
|
||||
public static final String NAME = "allocate";
|
||||
static final ParseField NUMBER_OF_REPLICAS_FIELD = new ParseField("number_of_replicas");
|
||||
static final ParseField INCLUDE_FIELD = new ParseField("include");
|
||||
static final ParseField EXCLUDE_FIELD = new ParseField("exclude");
|
||||
static final ParseField REQUIRE_FIELD = new ParseField("require");
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static final ConstructingObjectParser<AllocateAction, Void> PARSER = new ConstructingObjectParser<>(NAME, true,
|
||||
a -> new AllocateAction((Integer) a[0], (Map<String, String>) a[1], (Map<String, String>) a[2], (Map<String, String>) a[3]));
|
||||
|
||||
static {
|
||||
PARSER.declareInt(ConstructingObjectParser.optionalConstructorArg(), NUMBER_OF_REPLICAS_FIELD);
|
||||
PARSER.declareObject(ConstructingObjectParser.optionalConstructorArg(), (p, c) -> p.mapStrings(), INCLUDE_FIELD);
|
||||
PARSER.declareObject(ConstructingObjectParser.optionalConstructorArg(), (p, c) -> p.mapStrings(), EXCLUDE_FIELD);
|
||||
PARSER.declareObject(ConstructingObjectParser.optionalConstructorArg(), (p, c) -> p.mapStrings(), REQUIRE_FIELD);
|
||||
}
|
||||
|
||||
private final Integer numberOfReplicas;
|
||||
private final Map<String, String> include;
|
||||
private final Map<String, String> exclude;
|
||||
private final Map<String, String> require;
|
||||
|
||||
public static AllocateAction parse(XContentParser parser) {
|
||||
return PARSER.apply(parser, null);
|
||||
}
|
||||
|
||||
public AllocateAction(Integer numberOfReplicas, Map<String, String> include, Map<String, String> exclude, Map<String, String> require) {
|
||||
if (include == null) {
|
||||
this.include = Collections.emptyMap();
|
||||
} else {
|
||||
this.include = include;
|
||||
}
|
||||
if (exclude == null) {
|
||||
this.exclude = Collections.emptyMap();
|
||||
} else {
|
||||
this.exclude = exclude;
|
||||
}
|
||||
if (require == null) {
|
||||
this.require = Collections.emptyMap();
|
||||
} else {
|
||||
this.require = require;
|
||||
}
|
||||
if (this.include.isEmpty() && this.exclude.isEmpty() && this.require.isEmpty() && numberOfReplicas == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"At least one of " + INCLUDE_FIELD.getPreferredName() + ", " + EXCLUDE_FIELD.getPreferredName() + " or "
|
||||
+ REQUIRE_FIELD.getPreferredName() + "must contain attributes for action " + NAME);
|
||||
}
|
||||
if (numberOfReplicas != null && numberOfReplicas < 0) {
|
||||
throw new IllegalArgumentException("[" + NUMBER_OF_REPLICAS_FIELD.getPreferredName() + "] must be >= 0");
|
||||
}
|
||||
this.numberOfReplicas = numberOfReplicas;
|
||||
}
|
||||
|
||||
public Integer getNumberOfReplicas() {
|
||||
return numberOfReplicas;
|
||||
}
|
||||
|
||||
public Map<String, String> getInclude() {
|
||||
return include;
|
||||
}
|
||||
|
||||
public Map<String, String> getExclude() {
|
||||
return exclude;
|
||||
}
|
||||
|
||||
public Map<String, String> getRequire() {
|
||||
return require;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException {
|
||||
builder.startObject();
|
||||
if (numberOfReplicas != null) {
|
||||
builder.field(NUMBER_OF_REPLICAS_FIELD.getPreferredName(), numberOfReplicas);
|
||||
}
|
||||
builder.field(INCLUDE_FIELD.getPreferredName(), include);
|
||||
builder.field(EXCLUDE_FIELD.getPreferredName(), exclude);
|
||||
builder.field(REQUIRE_FIELD.getPreferredName(), require);
|
||||
builder.endObject();
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(numberOfReplicas, include, exclude, require);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (obj.getClass() != getClass()) {
|
||||
return false;
|
||||
}
|
||||
AllocateAction other = (AllocateAction) obj;
|
||||
return Objects.equals(numberOfReplicas, other.numberOfReplicas) &&
|
||||
Objects.equals(include, other.include) &&
|
||||
Objects.equals(exclude, other.exclude) &&
|
||||
Objects.equals(require, other.require);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Strings.toString(this);
|
||||
}
|
||||
}
|
@ -1,74 +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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.xcontent.ObjectParser;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.ToXContentObject;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class DeleteAction implements LifecycleAction, ToXContentObject {
|
||||
public static final String NAME = "delete";
|
||||
|
||||
private static final ObjectParser<DeleteAction, Void> PARSER = new ObjectParser<>(NAME, true, DeleteAction::new);
|
||||
|
||||
public static DeleteAction parse(XContentParser parser) {
|
||||
return PARSER.apply(parser, null);
|
||||
}
|
||||
|
||||
public DeleteAction() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException {
|
||||
builder.startObject();
|
||||
builder.endObject();
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (obj.getClass() != getClass()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Strings.toString(this);
|
||||
}
|
||||
}
|
@ -1,59 +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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.client.TimedRequest;
|
||||
import org.elasticsearch.common.Strings;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class DeleteLifecyclePolicyRequest extends TimedRequest {
|
||||
|
||||
private final String lifecyclePolicy;
|
||||
|
||||
public DeleteLifecyclePolicyRequest(String lifecyclePolicy) {
|
||||
if (Strings.isNullOrEmpty(lifecyclePolicy)) {
|
||||
throw new IllegalArgumentException("lifecycle name must be present");
|
||||
}
|
||||
this.lifecyclePolicy = lifecyclePolicy;
|
||||
}
|
||||
|
||||
public String getLifecyclePolicy() {
|
||||
return lifecyclePolicy;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
DeleteLifecyclePolicyRequest that = (DeleteLifecyclePolicyRequest) o;
|
||||
return Objects.equals(getLifecyclePolicy(), that.getLifecyclePolicy());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(getLifecyclePolicy());
|
||||
}
|
||||
}
|
@ -1,86 +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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.action.support.IndicesOptions;
|
||||
import org.elasticsearch.client.TimedRequest;
|
||||
import org.elasticsearch.client.ValidationException;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* The request object used by the Explain Lifecycle API.
|
||||
*/
|
||||
public class ExplainLifecycleRequest extends TimedRequest {
|
||||
|
||||
private final String[] indices;
|
||||
private IndicesOptions indicesOptions = IndicesOptions.strictExpandOpen();
|
||||
|
||||
public ExplainLifecycleRequest(String... indices) {
|
||||
if (indices.length == 0) {
|
||||
throw new IllegalArgumentException("Must at least specify one index to explain");
|
||||
}
|
||||
this.indices = indices;
|
||||
}
|
||||
|
||||
public String[] getIndices() {
|
||||
return indices;
|
||||
}
|
||||
|
||||
public ExplainLifecycleRequest indicesOptions(IndicesOptions indicesOptions) {
|
||||
this.indicesOptions = indicesOptions;
|
||||
return this;
|
||||
}
|
||||
|
||||
public IndicesOptions indicesOptions() {
|
||||
return indicesOptions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ValidationException> validate() {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(Arrays.hashCode(indices), indicesOptions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (obj.getClass() != getClass()) {
|
||||
return false;
|
||||
}
|
||||
ExplainLifecycleRequest other = (ExplainLifecycleRequest) obj;
|
||||
return Objects.deepEquals(getIndices(), other.getIndices()) &&
|
||||
Objects.equals(indicesOptions(), other.indicesOptions());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ExplainLifecycleRequest [indices()=" + Arrays.toString(indices) + ", indicesOptions()=" + indicesOptions + "]";
|
||||
}
|
||||
|
||||
}
|
@ -1,109 +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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
|
||||
import org.elasticsearch.common.xcontent.ToXContentObject;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* The response object returned by the Explain Lifecycle API.
|
||||
*
|
||||
* Since the API can be run over multiple indices the response provides a map of
|
||||
* index to the explanation of the lifecycle status for that index.
|
||||
*/
|
||||
public class ExplainLifecycleResponse implements ToXContentObject {
|
||||
|
||||
private static final ParseField INDICES_FIELD = new ParseField("indices");
|
||||
|
||||
private Map<String, IndexLifecycleExplainResponse> indexResponses;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static final ConstructingObjectParser<ExplainLifecycleResponse, Void> PARSER = new ConstructingObjectParser<>(
|
||||
"explain_lifecycle_response", a -> new ExplainLifecycleResponse(((List<IndexLifecycleExplainResponse>) a[0]).stream()
|
||||
.collect(Collectors.toMap(IndexLifecycleExplainResponse::getIndex, Function.identity()))));
|
||||
static {
|
||||
PARSER.declareNamedObjects(ConstructingObjectParser.constructorArg(), (p, c, n) -> IndexLifecycleExplainResponse.PARSER.apply(p, c),
|
||||
INDICES_FIELD);
|
||||
}
|
||||
|
||||
public static ExplainLifecycleResponse fromXContent(XContentParser parser) {
|
||||
return PARSER.apply(parser, null);
|
||||
}
|
||||
|
||||
public ExplainLifecycleResponse(Map<String, IndexLifecycleExplainResponse> indexResponses) {
|
||||
this.indexResponses = indexResponses;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a map of the responses from each requested index. The maps key is
|
||||
* the index name and the value is the
|
||||
* {@link IndexLifecycleExplainResponse} describing the current
|
||||
* lifecycle status of that index
|
||||
*/
|
||||
public Map<String, IndexLifecycleExplainResponse> getIndexResponses() {
|
||||
return indexResponses;
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject();
|
||||
builder.startObject(INDICES_FIELD.getPreferredName());
|
||||
for (IndexLifecycleExplainResponse indexResponse : indexResponses.values()) {
|
||||
builder.field(indexResponse.getIndex(), indexResponse);
|
||||
}
|
||||
builder.endObject();
|
||||
builder.endObject();
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(indexResponses);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (obj.getClass() != getClass()) {
|
||||
return false;
|
||||
}
|
||||
ExplainLifecycleResponse other = (ExplainLifecycleResponse) obj;
|
||||
return Objects.equals(indexResponses, other.indexResponses);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Strings.toString(this, true, true);
|
||||
}
|
||||
|
||||
}
|
@ -1,97 +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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
|
||||
import org.elasticsearch.common.xcontent.ToXContentObject;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ForceMergeAction implements LifecycleAction, ToXContentObject {
|
||||
public static final String NAME = "forcemerge";
|
||||
private static final ParseField MAX_NUM_SEGMENTS_FIELD = new ParseField("max_num_segments");
|
||||
|
||||
private static final ConstructingObjectParser<ForceMergeAction, Void> PARSER = new ConstructingObjectParser<>(NAME,
|
||||
true, a -> {
|
||||
int maxNumSegments = (int) a[0];
|
||||
return new ForceMergeAction(maxNumSegments);
|
||||
});
|
||||
|
||||
static {
|
||||
PARSER.declareInt(ConstructingObjectParser.constructorArg(), MAX_NUM_SEGMENTS_FIELD);
|
||||
}
|
||||
|
||||
private final int maxNumSegments;
|
||||
|
||||
public static ForceMergeAction parse(XContentParser parser) {
|
||||
return PARSER.apply(parser, null);
|
||||
}
|
||||
|
||||
public ForceMergeAction(int maxNumSegments) {
|
||||
if (maxNumSegments <= 0) {
|
||||
throw new IllegalArgumentException("[" + MAX_NUM_SEGMENTS_FIELD.getPreferredName()
|
||||
+ "] must be a positive integer");
|
||||
}
|
||||
this.maxNumSegments = maxNumSegments;
|
||||
}
|
||||
|
||||
public int getMaxNumSegments() {
|
||||
return maxNumSegments;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject();
|
||||
builder.field(MAX_NUM_SEGMENTS_FIELD.getPreferredName(), maxNumSegments);
|
||||
builder.endObject();
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(maxNumSegments);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (obj.getClass() != getClass()) {
|
||||
return false;
|
||||
}
|
||||
ForceMergeAction other = (ForceMergeAction) obj;
|
||||
return Objects.equals(maxNumSegments, other.maxNumSegments);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Strings.toString(this);
|
||||
}
|
||||
}
|
@ -1,73 +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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.xcontent.ObjectParser;
|
||||
import org.elasticsearch.common.xcontent.ToXContentObject;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class FreezeAction implements LifecycleAction, ToXContentObject {
|
||||
public static final String NAME = "freeze";
|
||||
|
||||
private static final ObjectParser<FreezeAction, Void> PARSER = new ObjectParser<>(NAME, true, FreezeAction::new);
|
||||
|
||||
public static FreezeAction parse(XContentParser parser) {
|
||||
return PARSER.apply(parser, null);
|
||||
}
|
||||
|
||||
public FreezeAction() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject();
|
||||
builder.endObject();
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (obj.getClass() != getClass()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Strings.toString(this);
|
||||
}
|
||||
}
|
@ -1,61 +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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.client.TimedRequest;
|
||||
import org.elasticsearch.common.Strings;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class GetLifecyclePolicyRequest extends TimedRequest {
|
||||
|
||||
private final String[] policyNames;
|
||||
|
||||
public GetLifecyclePolicyRequest(String... policyNames) {
|
||||
if (policyNames == null) {
|
||||
this.policyNames = Strings.EMPTY_ARRAY;
|
||||
} else {
|
||||
for (String name : policyNames) {
|
||||
if (name == null) {
|
||||
throw new IllegalArgumentException("cannot include null policy name");
|
||||
}
|
||||
}
|
||||
this.policyNames = policyNames;
|
||||
}
|
||||
}
|
||||
|
||||
public String[] getPolicyNames() {
|
||||
return policyNames;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
GetLifecyclePolicyRequest request = (GetLifecyclePolicyRequest) o;
|
||||
return Arrays.equals(getPolicyNames(), request.getPolicyNames());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Arrays.hashCode(getPolicyNames());
|
||||
}
|
||||
}
|
@ -1,91 +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.indexlifecycle;
|
||||
|
||||
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
|
||||
import org.elasticsearch.common.collect.ImmutableOpenMap;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.ToXContentObject;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
import static org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken;
|
||||
|
||||
public class GetLifecyclePolicyResponse implements ToXContentObject {
|
||||
|
||||
private final ImmutableOpenMap<String, LifecyclePolicyMetadata> policies;
|
||||
|
||||
public GetLifecyclePolicyResponse(ImmutableOpenMap<String, LifecyclePolicyMetadata> policies) {
|
||||
this.policies = policies;
|
||||
}
|
||||
|
||||
public ImmutableOpenMap<String, LifecyclePolicyMetadata> getPolicies() {
|
||||
return policies;
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException {
|
||||
builder.startObject();
|
||||
for (ObjectObjectCursor<String, LifecyclePolicyMetadata> stringLifecyclePolicyObjectObjectCursor : policies) {
|
||||
builder.field(stringLifecyclePolicyObjectObjectCursor.key, stringLifecyclePolicyObjectObjectCursor.value);
|
||||
}
|
||||
builder.endObject();
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static GetLifecyclePolicyResponse fromXContent(XContentParser parser) throws IOException {
|
||||
ImmutableOpenMap.Builder<String, LifecyclePolicyMetadata> policies = ImmutableOpenMap.builder();
|
||||
|
||||
if (parser.currentToken() == null) {
|
||||
parser.nextToken();
|
||||
}
|
||||
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.currentToken(), parser);
|
||||
parser.nextToken();
|
||||
|
||||
while (!parser.isClosed()) {
|
||||
if (parser.currentToken() == XContentParser.Token.START_OBJECT) {
|
||||
String policyName = parser.currentName();
|
||||
LifecyclePolicyMetadata policyDefinion = LifecyclePolicyMetadata.parse(parser, policyName);
|
||||
policies.put(policyName, policyDefinion);
|
||||
} else {
|
||||
parser.nextToken();
|
||||
}
|
||||
}
|
||||
|
||||
return new GetLifecyclePolicyResponse(policies.build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
GetLifecyclePolicyResponse that = (GetLifecyclePolicyResponse) o;
|
||||
return Objects.equals(getPolicies(), that.getPolicies());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(getPolicies());
|
||||
}
|
||||
}
|
@ -1,296 +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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
|
||||
import org.elasticsearch.common.xcontent.ToXContentObject;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class IndexLifecycleExplainResponse implements ToXContentObject {
|
||||
|
||||
private static final ParseField INDEX_FIELD = new ParseField("index");
|
||||
private static final ParseField MANAGED_BY_ILM_FIELD = new ParseField("managed");
|
||||
private static final ParseField POLICY_NAME_FIELD = new ParseField("policy");
|
||||
private static final ParseField LIFECYCLE_DATE_MILLIS_FIELD = new ParseField("lifecycle_date_millis");
|
||||
private static final ParseField LIFECYCLE_DATE_FIELD = new ParseField("lifecycle_date");
|
||||
private static final ParseField PHASE_FIELD = new ParseField("phase");
|
||||
private static final ParseField ACTION_FIELD = new ParseField("action");
|
||||
private static final ParseField STEP_FIELD = new ParseField("step");
|
||||
private static final ParseField FAILED_STEP_FIELD = new ParseField("failed_step");
|
||||
private static final ParseField PHASE_TIME_MILLIS_FIELD = new ParseField("phase_time_millis");
|
||||
private static final ParseField PHASE_TIME_FIELD = new ParseField("phase_time");
|
||||
private static final ParseField ACTION_TIME_MILLIS_FIELD = new ParseField("action_time_millis");
|
||||
private static final ParseField ACTION_TIME_FIELD = new ParseField("action_time");
|
||||
private static final ParseField STEP_TIME_MILLIS_FIELD = new ParseField("step_time_millis");
|
||||
private static final ParseField STEP_TIME_FIELD = new ParseField("step_time");
|
||||
private static final ParseField STEP_INFO_FIELD = new ParseField("step_info");
|
||||
private static final ParseField PHASE_EXECUTION_INFO = new ParseField("phase_execution");
|
||||
private static final ParseField AGE_FIELD = new ParseField("age");
|
||||
|
||||
public static final ConstructingObjectParser<IndexLifecycleExplainResponse, Void> PARSER = new ConstructingObjectParser<>(
|
||||
"index_lifecycle_explain_response", true,
|
||||
a -> new IndexLifecycleExplainResponse(
|
||||
(String) a[0],
|
||||
(boolean) a[1],
|
||||
(String) a[2],
|
||||
(Long) a[3],
|
||||
(String) a[4],
|
||||
(String) a[5],
|
||||
(String) a[6],
|
||||
(String) a[7],
|
||||
(Long) a[8],
|
||||
(Long) a[9],
|
||||
(Long) a[10],
|
||||
(BytesReference) a[11],
|
||||
(PhaseExecutionInfo) a[12]));
|
||||
static {
|
||||
PARSER.declareString(ConstructingObjectParser.constructorArg(), INDEX_FIELD);
|
||||
PARSER.declareBoolean(ConstructingObjectParser.constructorArg(), MANAGED_BY_ILM_FIELD);
|
||||
PARSER.declareString(ConstructingObjectParser.optionalConstructorArg(), POLICY_NAME_FIELD);
|
||||
PARSER.declareLong(ConstructingObjectParser.optionalConstructorArg(), LIFECYCLE_DATE_MILLIS_FIELD);
|
||||
PARSER.declareString(ConstructingObjectParser.optionalConstructorArg(), PHASE_FIELD);
|
||||
PARSER.declareString(ConstructingObjectParser.optionalConstructorArg(), ACTION_FIELD);
|
||||
PARSER.declareString(ConstructingObjectParser.optionalConstructorArg(), STEP_FIELD);
|
||||
PARSER.declareString(ConstructingObjectParser.optionalConstructorArg(), FAILED_STEP_FIELD);
|
||||
PARSER.declareLong(ConstructingObjectParser.optionalConstructorArg(), PHASE_TIME_MILLIS_FIELD);
|
||||
PARSER.declareLong(ConstructingObjectParser.optionalConstructorArg(), ACTION_TIME_MILLIS_FIELD);
|
||||
PARSER.declareLong(ConstructingObjectParser.optionalConstructorArg(), STEP_TIME_MILLIS_FIELD);
|
||||
PARSER.declareObject(ConstructingObjectParser.optionalConstructorArg(), (p, c) -> {
|
||||
XContentBuilder builder = JsonXContent.contentBuilder();
|
||||
builder.copyCurrentStructure(p);
|
||||
return BytesReference.bytes(builder);
|
||||
}, STEP_INFO_FIELD);
|
||||
PARSER.declareObject(ConstructingObjectParser.optionalConstructorArg(), (p, c) -> PhaseExecutionInfo.parse(p, ""),
|
||||
PHASE_EXECUTION_INFO);
|
||||
}
|
||||
|
||||
private final String index;
|
||||
private final String policyName;
|
||||
private final String phase;
|
||||
private final String action;
|
||||
private final String step;
|
||||
private final String failedStep;
|
||||
private final Long lifecycleDate;
|
||||
private final Long phaseTime;
|
||||
private final Long actionTime;
|
||||
private final Long stepTime;
|
||||
private final boolean managedByILM;
|
||||
private final BytesReference stepInfo;
|
||||
private final PhaseExecutionInfo phaseExecutionInfo;
|
||||
|
||||
public static IndexLifecycleExplainResponse newManagedIndexResponse(String index, String policyName, Long lifecycleDate,
|
||||
String phase, String action, String step, String failedStep,
|
||||
Long phaseTime, Long actionTime, Long stepTime,
|
||||
BytesReference stepInfo, PhaseExecutionInfo phaseExecutionInfo) {
|
||||
return new IndexLifecycleExplainResponse(index, true, policyName, lifecycleDate, phase, action, step, failedStep, phaseTime,
|
||||
actionTime, stepTime, stepInfo, phaseExecutionInfo);
|
||||
}
|
||||
|
||||
public static IndexLifecycleExplainResponse newUnmanagedIndexResponse(String index) {
|
||||
return new IndexLifecycleExplainResponse(index, false, null, null, null, null, null, null, null, null, null, null, null);
|
||||
}
|
||||
|
||||
private IndexLifecycleExplainResponse(String index, boolean managedByILM, String policyName, Long lifecycleDate,
|
||||
String phase, String action, String step, String failedStep, Long phaseTime, Long actionTime,
|
||||
Long stepTime, BytesReference stepInfo, PhaseExecutionInfo phaseExecutionInfo) {
|
||||
if (managedByILM) {
|
||||
if (policyName == null) {
|
||||
throw new IllegalArgumentException("[" + POLICY_NAME_FIELD.getPreferredName() + "] cannot be null for managed index");
|
||||
}
|
||||
// check to make sure that step details are either all null or all set.
|
||||
long numNull = Stream.of(phase, action, step).filter(Objects::isNull).count();
|
||||
if (numNull > 0 && numNull < 3) {
|
||||
throw new IllegalArgumentException("managed index response must have complete step details [" +
|
||||
PHASE_FIELD.getPreferredName() + "=" + phase + ", " +
|
||||
ACTION_FIELD.getPreferredName() + "=" + action + ", " +
|
||||
STEP_FIELD.getPreferredName() + "=" + step + "]");
|
||||
}
|
||||
} else {
|
||||
if (policyName != null || lifecycleDate != null || phase != null || action != null || step != null || failedStep != null
|
||||
|| phaseTime != null || actionTime != null || stepTime != null || stepInfo != null || phaseExecutionInfo != null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Unmanaged index response must only contain fields: [" + MANAGED_BY_ILM_FIELD + ", " + INDEX_FIELD + "]");
|
||||
}
|
||||
}
|
||||
this.index = index;
|
||||
this.policyName = policyName;
|
||||
this.managedByILM = managedByILM;
|
||||
this.lifecycleDate = lifecycleDate;
|
||||
this.phase = phase;
|
||||
this.action = action;
|
||||
this.step = step;
|
||||
this.phaseTime = phaseTime;
|
||||
this.actionTime = actionTime;
|
||||
this.stepTime = stepTime;
|
||||
this.failedStep = failedStep;
|
||||
this.stepInfo = stepInfo;
|
||||
this.phaseExecutionInfo = phaseExecutionInfo;
|
||||
}
|
||||
|
||||
public String getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
public boolean managedByILM() {
|
||||
return managedByILM;
|
||||
}
|
||||
|
||||
public String getPolicyName() {
|
||||
return policyName;
|
||||
}
|
||||
|
||||
public long getLifecycleDate() {
|
||||
return lifecycleDate;
|
||||
}
|
||||
|
||||
public String getPhase() {
|
||||
return phase;
|
||||
}
|
||||
|
||||
public long getPhaseTime() {
|
||||
return phaseTime;
|
||||
}
|
||||
|
||||
public String getAction() {
|
||||
return action;
|
||||
}
|
||||
|
||||
public long getActionTime() {
|
||||
return actionTime;
|
||||
}
|
||||
|
||||
public String getStep() {
|
||||
return step;
|
||||
}
|
||||
|
||||
public long getStepTime() {
|
||||
return stepTime;
|
||||
}
|
||||
|
||||
public String getFailedStep() {
|
||||
return failedStep;
|
||||
}
|
||||
|
||||
public BytesReference getStepInfo() {
|
||||
return stepInfo;
|
||||
}
|
||||
|
||||
public PhaseExecutionInfo getPhaseExecutionInfo() {
|
||||
return phaseExecutionInfo;
|
||||
}
|
||||
|
||||
public TimeValue getAge() {
|
||||
if (lifecycleDate == null) {
|
||||
return TimeValue.MINUS_ONE;
|
||||
} else {
|
||||
return TimeValue.timeValueMillis(System.currentTimeMillis() - lifecycleDate);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject();
|
||||
builder.field(INDEX_FIELD.getPreferredName(), index);
|
||||
builder.field(MANAGED_BY_ILM_FIELD.getPreferredName(), managedByILM);
|
||||
if (managedByILM) {
|
||||
builder.field(POLICY_NAME_FIELD.getPreferredName(), policyName);
|
||||
if (lifecycleDate != null) {
|
||||
builder.timeField(LIFECYCLE_DATE_MILLIS_FIELD.getPreferredName(), LIFECYCLE_DATE_FIELD.getPreferredName(), lifecycleDate);
|
||||
builder.field(AGE_FIELD.getPreferredName(), getAge().toHumanReadableString(2));
|
||||
}
|
||||
if (phase != null) {
|
||||
builder.field(PHASE_FIELD.getPreferredName(), phase);
|
||||
}
|
||||
if (phaseTime != null) {
|
||||
builder.timeField(PHASE_TIME_MILLIS_FIELD.getPreferredName(), PHASE_TIME_FIELD.getPreferredName(), phaseTime);
|
||||
}
|
||||
if (action != null) {
|
||||
builder.field(ACTION_FIELD.getPreferredName(), action);
|
||||
}
|
||||
if (actionTime != null) {
|
||||
builder.timeField(ACTION_TIME_MILLIS_FIELD.getPreferredName(), ACTION_TIME_FIELD.getPreferredName(), actionTime);
|
||||
}
|
||||
if (step != null) {
|
||||
builder.field(STEP_FIELD.getPreferredName(), step);
|
||||
}
|
||||
if (stepTime != null) {
|
||||
builder.timeField(STEP_TIME_MILLIS_FIELD.getPreferredName(), STEP_TIME_FIELD.getPreferredName(), stepTime);
|
||||
}
|
||||
if (Strings.hasLength(failedStep)) {
|
||||
builder.field(FAILED_STEP_FIELD.getPreferredName(), failedStep);
|
||||
}
|
||||
if (stepInfo != null && stepInfo.length() > 0) {
|
||||
builder.rawField(STEP_INFO_FIELD.getPreferredName(), stepInfo.streamInput(), XContentType.JSON);
|
||||
}
|
||||
if (phaseExecutionInfo != null) {
|
||||
builder.field(PHASE_EXECUTION_INFO.getPreferredName(), phaseExecutionInfo);
|
||||
}
|
||||
}
|
||||
builder.endObject();
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(index, managedByILM, policyName, lifecycleDate, phase, action, step, failedStep, phaseTime, actionTime,
|
||||
stepTime, stepInfo, phaseExecutionInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (obj.getClass() != getClass()) {
|
||||
return false;
|
||||
}
|
||||
IndexLifecycleExplainResponse other = (IndexLifecycleExplainResponse) obj;
|
||||
return Objects.equals(index, other.index) &&
|
||||
Objects.equals(managedByILM, other.managedByILM) &&
|
||||
Objects.equals(policyName, other.policyName) &&
|
||||
Objects.equals(lifecycleDate, other.lifecycleDate) &&
|
||||
Objects.equals(phase, other.phase) &&
|
||||
Objects.equals(action, other.action) &&
|
||||
Objects.equals(step, other.step) &&
|
||||
Objects.equals(failedStep, other.failedStep) &&
|
||||
Objects.equals(phaseTime, other.phaseTime) &&
|
||||
Objects.equals(actionTime, other.actionTime) &&
|
||||
Objects.equals(stepTime, other.stepTime) &&
|
||||
Objects.equals(stepInfo, other.stepInfo) &&
|
||||
Objects.equals(phaseExecutionInfo, other.phaseExecutionInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Strings.toString(this, true, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,74 +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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
||||
import org.elasticsearch.plugins.spi.NamedXContentProvider;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class IndexLifecycleNamedXContentProvider implements NamedXContentProvider {
|
||||
|
||||
|
||||
@Override
|
||||
public List<NamedXContentRegistry.Entry> getNamedXContentParsers() {
|
||||
return Arrays.asList(
|
||||
// ILM
|
||||
new NamedXContentRegistry.Entry(LifecycleAction.class,
|
||||
new ParseField(AllocateAction.NAME),
|
||||
AllocateAction::parse),
|
||||
new NamedXContentRegistry.Entry(LifecycleAction.class,
|
||||
new ParseField(DeleteAction.NAME),
|
||||
DeleteAction::parse),
|
||||
new NamedXContentRegistry.Entry(LifecycleAction.class,
|
||||
new ParseField(ForceMergeAction.NAME),
|
||||
ForceMergeAction::parse),
|
||||
new NamedXContentRegistry.Entry(LifecycleAction.class,
|
||||
new ParseField(ReadOnlyAction.NAME),
|
||||
ReadOnlyAction::parse),
|
||||
new NamedXContentRegistry.Entry(LifecycleAction.class,
|
||||
new ParseField(RolloverAction.NAME),
|
||||
RolloverAction::parse),
|
||||
new NamedXContentRegistry.Entry(LifecycleAction.class,
|
||||
new ParseField(ShrinkAction.NAME),
|
||||
ShrinkAction::parse),
|
||||
new NamedXContentRegistry.Entry(LifecycleAction.class,
|
||||
new ParseField(WaitForSnapshotAction.NAME),
|
||||
WaitForSnapshotAction::parse),
|
||||
new NamedXContentRegistry.Entry(LifecycleAction.class,
|
||||
new ParseField(FreezeAction.NAME),
|
||||
FreezeAction::parse),
|
||||
new NamedXContentRegistry.Entry(LifecycleAction.class,
|
||||
new ParseField(SetPriorityAction.NAME),
|
||||
SetPriorityAction::parse),
|
||||
new NamedXContentRegistry.Entry(LifecycleAction.class,
|
||||
new ParseField(MigrateAction.NAME),
|
||||
MigrateAction::parse),
|
||||
new NamedXContentRegistry.Entry(LifecycleAction.class,
|
||||
new ParseField(SearchableSnapshotAction.NAME),
|
||||
SearchableSnapshotAction::parse),
|
||||
new NamedXContentRegistry.Entry(LifecycleAction.class,
|
||||
new ParseField(UnfollowAction.NAME),
|
||||
UnfollowAction::parse)
|
||||
);
|
||||
}
|
||||
}
|
@ -1,30 +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.indexlifecycle;
|
||||
|
||||
/**
|
||||
* interface for index lifecycle management actions
|
||||
*/
|
||||
public interface LifecycleAction {
|
||||
|
||||
/**
|
||||
* @return the name of this action
|
||||
*/
|
||||
String getName();
|
||||
}
|
@ -1,28 +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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.client.TimedRequest;
|
||||
|
||||
/**
|
||||
* A {@link TimedRequest} to get the current status of index lifecycle management.
|
||||
*/
|
||||
public class LifecycleManagementStatusRequest extends TimedRequest {
|
||||
}
|
@ -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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* The current status of index lifecycle management. See {@link OperationMode} for available statuses.
|
||||
*/
|
||||
public class LifecycleManagementStatusResponse {
|
||||
|
||||
private final OperationMode operationMode;
|
||||
private static final String OPERATION_MODE = "operation_mode";
|
||||
@SuppressWarnings("unchecked")
|
||||
private static final ConstructingObjectParser<LifecycleManagementStatusResponse, Void> PARSER = new ConstructingObjectParser<>(
|
||||
OPERATION_MODE, true, a -> new LifecycleManagementStatusResponse((String) a[0]));
|
||||
|
||||
static {
|
||||
PARSER.declareString(ConstructingObjectParser.constructorArg(), new ParseField(OPERATION_MODE));
|
||||
}
|
||||
|
||||
//package private for testing
|
||||
LifecycleManagementStatusResponse(String operationMode) {
|
||||
this.operationMode = OperationMode.fromString(operationMode);
|
||||
}
|
||||
|
||||
public OperationMode getOperationMode() {
|
||||
return operationMode;
|
||||
}
|
||||
|
||||
public static LifecycleManagementStatusResponse 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;
|
||||
LifecycleManagementStatusResponse that = (LifecycleManagementStatusResponse) o;
|
||||
return operationMode == that.operationMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(operationMode);
|
||||
}
|
||||
}
|
@ -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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.util.set.Sets;
|
||||
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
|
||||
import org.elasticsearch.common.xcontent.ToXContentObject;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Represents the lifecycle of an index from creation to deletion. A
|
||||
* {@link LifecyclePolicy} is made up of a set of {@link Phase}s which it will
|
||||
* move through.
|
||||
*/
|
||||
public class LifecyclePolicy implements ToXContentObject {
|
||||
static final ParseField PHASES_FIELD = new ParseField("phases");
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static final ConstructingObjectParser<LifecyclePolicy, String> PARSER = new ConstructingObjectParser<>("lifecycle_policy", true,
|
||||
(a, name) -> {
|
||||
List<Phase> phases = (List<Phase>) a[0];
|
||||
Map<String, Phase> phaseMap = phases.stream().collect(Collectors.toMap(Phase::getName, Function.identity()));
|
||||
return new LifecyclePolicy(name, phaseMap);
|
||||
});
|
||||
private static Map<String, Set<String>> ALLOWED_ACTIONS = new HashMap<>();
|
||||
|
||||
static {
|
||||
PARSER.declareNamedObjects(ConstructingObjectParser.constructorArg(), (p, c, n) -> Phase.parse(p, n), v -> {
|
||||
throw new IllegalArgumentException("ordered " + PHASES_FIELD.getPreferredName() + " are not supported");
|
||||
}, PHASES_FIELD);
|
||||
|
||||
ALLOWED_ACTIONS.put("hot", Sets.newHashSet(UnfollowAction.NAME, SetPriorityAction.NAME, RolloverAction.NAME));
|
||||
ALLOWED_ACTIONS.put("warm", Sets.newHashSet(UnfollowAction.NAME, SetPriorityAction.NAME, MigrateAction.NAME, AllocateAction.NAME,
|
||||
ForceMergeAction.NAME, ReadOnlyAction.NAME, ShrinkAction.NAME));
|
||||
ALLOWED_ACTIONS.put("cold", Sets.newHashSet(UnfollowAction.NAME, SetPriorityAction.NAME, MigrateAction.NAME, AllocateAction.NAME,
|
||||
FreezeAction.NAME, SearchableSnapshotAction.NAME));
|
||||
ALLOWED_ACTIONS.put("delete", Sets.newHashSet(DeleteAction.NAME, WaitForSnapshotAction.NAME));
|
||||
}
|
||||
|
||||
private final String name;
|
||||
private final Map<String, Phase> phases;
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* the name of this {@link LifecyclePolicy}
|
||||
* @param phases
|
||||
* a {@link Map} of {@link Phase}s which make up this
|
||||
* {@link LifecyclePolicy}.
|
||||
*/
|
||||
public LifecyclePolicy(String name, Map<String, Phase> phases) {
|
||||
phases.values().forEach(phase -> {
|
||||
if (ALLOWED_ACTIONS.containsKey(phase.getName()) == false) {
|
||||
throw new IllegalArgumentException("Lifecycle does not support phase [" + phase.getName() + "]");
|
||||
}
|
||||
phase.getActions().forEach((actionName, action) -> {
|
||||
if (ALLOWED_ACTIONS.get(phase.getName()).contains(actionName) == false) {
|
||||
throw new IllegalArgumentException("invalid action [" + actionName + "] " +
|
||||
"defined in phase [" + phase.getName() +"]");
|
||||
}
|
||||
});
|
||||
});
|
||||
this.name = name;
|
||||
this.phases = phases;
|
||||
}
|
||||
|
||||
public static LifecyclePolicy parse(XContentParser parser, String name) {
|
||||
return PARSER.apply(parser, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name of this {@link LifecyclePolicy}
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the {@link Phase}s for this {@link LifecyclePolicy} in the order
|
||||
* in which they will be executed.
|
||||
*/
|
||||
public Map<String, Phase> getPhases() {
|
||||
return phases;
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject();
|
||||
builder.startObject(PHASES_FIELD.getPreferredName());
|
||||
for (Phase phase : phases.values()) {
|
||||
builder.field(phase.getName(), phase);
|
||||
}
|
||||
builder.endObject();
|
||||
builder.endObject();
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(name, phases);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (obj.getClass() != getClass()) {
|
||||
return false;
|
||||
}
|
||||
LifecyclePolicy other = (LifecyclePolicy) obj;
|
||||
return Objects.equals(name, other.name) &&
|
||||
Objects.equals(phases, other.phases);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Strings.toString(this, true, true);
|
||||
}
|
||||
}
|
@ -1,118 +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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
|
||||
import org.elasticsearch.common.xcontent.ToXContentObject;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.Instant;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Objects;
|
||||
|
||||
public class LifecyclePolicyMetadata implements ToXContentObject {
|
||||
|
||||
static final ParseField POLICY = new ParseField("policy");
|
||||
static final ParseField VERSION = new ParseField("version");
|
||||
static final ParseField MODIFIED_DATE = new ParseField("modified_date");
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static final ConstructingObjectParser<LifecyclePolicyMetadata, String> PARSER = new ConstructingObjectParser<>(
|
||||
"policy_metadata", true,
|
||||
a -> {
|
||||
LifecyclePolicy policy = (LifecyclePolicy) a[0];
|
||||
return new LifecyclePolicyMetadata(policy, (long) a[1], ZonedDateTime.parse((String) a[2]).toInstant().toEpochMilli());
|
||||
});
|
||||
static {
|
||||
PARSER.declareObject(ConstructingObjectParser.constructorArg(), LifecyclePolicy::parse, POLICY);
|
||||
PARSER.declareLong(ConstructingObjectParser.constructorArg(), VERSION);
|
||||
PARSER.declareString(ConstructingObjectParser.constructorArg(), MODIFIED_DATE);
|
||||
}
|
||||
|
||||
public static LifecyclePolicyMetadata parse(XContentParser parser, String name) {
|
||||
return PARSER.apply(parser, name);
|
||||
}
|
||||
|
||||
private final LifecyclePolicy policy;
|
||||
private final long version;
|
||||
private final long modifiedDate;
|
||||
|
||||
public LifecyclePolicyMetadata(LifecyclePolicy policy, long version, long modifiedDate) {
|
||||
this.policy = policy;
|
||||
this.version = version;
|
||||
this.modifiedDate = modifiedDate;
|
||||
}
|
||||
|
||||
public LifecyclePolicy getPolicy() {
|
||||
return policy;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return policy.getName();
|
||||
}
|
||||
|
||||
public long getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public long getModifiedDate() {
|
||||
return modifiedDate;
|
||||
}
|
||||
|
||||
public String getModifiedDateString() {
|
||||
ZonedDateTime modifiedDateTime = ZonedDateTime.ofInstant(Instant.ofEpochMilli(modifiedDate), ZoneOffset.UTC);
|
||||
return modifiedDateTime.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject();
|
||||
builder.field(POLICY.getPreferredName(), policy);
|
||||
builder.field(VERSION.getPreferredName(), version);
|
||||
builder.field(MODIFIED_DATE.getPreferredName(),
|
||||
ZonedDateTime.ofInstant(Instant.ofEpochMilli(modifiedDate), ZoneOffset.UTC).toString());
|
||||
builder.endObject();
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(policy, version, modifiedDate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
LifecyclePolicyMetadata other = (LifecyclePolicyMetadata) obj;
|
||||
return Objects.equals(policy, other.policy) &&
|
||||
Objects.equals(version, other.version) &&
|
||||
Objects.equals(modifiedDate, other.modifiedDate);
|
||||
}
|
||||
|
||||
}
|
@ -1,90 +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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
|
||||
import org.elasticsearch.common.xcontent.ToXContentObject;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
public class MigrateAction implements LifecycleAction, ToXContentObject {
|
||||
public static final String NAME = "migrate";
|
||||
|
||||
public static final ParseField ENABLED_FIELD = new ParseField("enabled");
|
||||
|
||||
private static final ConstructingObjectParser<MigrateAction, Void> PARSER = new ConstructingObjectParser<>(NAME,
|
||||
a -> new MigrateAction(a[0] == null ? true : (boolean) a[0]));
|
||||
|
||||
static {
|
||||
PARSER.declareBoolean(ConstructingObjectParser.optionalConstructorArg(), ENABLED_FIELD);
|
||||
}
|
||||
|
||||
public static MigrateAction parse(XContentParser parser) {
|
||||
return PARSER.apply(parser, null);
|
||||
}
|
||||
|
||||
private final boolean enabled;
|
||||
|
||||
public MigrateAction() {
|
||||
this(true);
|
||||
}
|
||||
|
||||
public MigrateAction(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject();
|
||||
builder.field(ENABLED_FIELD.getPreferredName(), enabled);
|
||||
builder.endObject();
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(enabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (obj.getClass() != getClass()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Strings.toString(this);
|
||||
}
|
||||
}
|
@ -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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.action.admin.indices.shrink.ShrinkAction;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Enum representing the different modes that Index Lifecycle Service can operate in.
|
||||
*/
|
||||
public enum OperationMode {
|
||||
/**
|
||||
* This represents a state where no policies are executed
|
||||
*/
|
||||
STOPPED {
|
||||
@Override
|
||||
public boolean isValidChange(OperationMode nextMode) {
|
||||
return nextMode == RUNNING;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* this represents a state where only sensitive actions (like {@link ShrinkAction}) will be executed
|
||||
* until they finish, at which point the operation mode will move to <code>STOPPED</code>.
|
||||
*/
|
||||
STOPPING {
|
||||
@Override
|
||||
public boolean isValidChange(OperationMode nextMode) {
|
||||
return nextMode == RUNNING || nextMode == STOPPED;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Normal operation where all policies are executed as normal.
|
||||
*/
|
||||
RUNNING {
|
||||
@Override
|
||||
public boolean isValidChange(OperationMode nextMode) {
|
||||
return nextMode == STOPPING;
|
||||
}
|
||||
};
|
||||
|
||||
public abstract boolean isValidChange(OperationMode nextMode);
|
||||
|
||||
static OperationMode fromString(String string) {
|
||||
return EnumSet.allOf(OperationMode.class).stream()
|
||||
.filter(e -> string.equalsIgnoreCase(e.name())).findFirst()
|
||||
.orElseThrow(() -> new IllegalArgumentException(String.format(Locale.ROOT, "%s is not a valid operation_mode", string)));
|
||||
}
|
||||
}
|
@ -1,143 +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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
|
||||
import org.elasticsearch.common.xcontent.ObjectParser.ValueType;
|
||||
import org.elasticsearch.common.xcontent.ToXContentObject;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Represents set of {@link LifecycleAction}s which should be executed at a
|
||||
* particular point in the lifecycle of an index.
|
||||
*/
|
||||
public class Phase implements ToXContentObject {
|
||||
|
||||
static final ParseField MIN_AGE = new ParseField("min_age");
|
||||
static final ParseField ACTIONS_FIELD = new ParseField("actions");
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static final ConstructingObjectParser<Phase, String> PARSER = new ConstructingObjectParser<>("phase", true,
|
||||
(a, name) -> new Phase(name, (TimeValue) a[0], ((List<LifecycleAction>) a[1]).stream()
|
||||
.collect(Collectors.toMap(LifecycleAction::getName, Function.identity()))));
|
||||
static {
|
||||
PARSER.declareField(ConstructingObjectParser.optionalConstructorArg(),
|
||||
(p, c) -> TimeValue.parseTimeValue(p.text(), MIN_AGE.getPreferredName()), MIN_AGE, ValueType.VALUE);
|
||||
PARSER.declareNamedObjects(ConstructingObjectParser.constructorArg(),
|
||||
(p, c, n) -> p.namedObject(LifecycleAction.class, n, null), v -> {
|
||||
throw new IllegalArgumentException("ordered " + ACTIONS_FIELD.getPreferredName() + " are not supported");
|
||||
}, ACTIONS_FIELD);
|
||||
}
|
||||
|
||||
public static Phase parse(XContentParser parser, String name) {
|
||||
return PARSER.apply(parser, name);
|
||||
}
|
||||
|
||||
private final String name;
|
||||
private final Map<String, LifecycleAction> actions;
|
||||
private final TimeValue minimumAge;
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* the name of this {@link Phase}.
|
||||
* @param minimumAge
|
||||
* the age of the index when the index should move to this
|
||||
* {@link Phase}.
|
||||
* @param actions
|
||||
* a {@link Map} of the {@link LifecycleAction}s to run when
|
||||
* during this {@link Phase}. The keys in this map are the associated
|
||||
* action names.
|
||||
*/
|
||||
public Phase(String name, TimeValue minimumAge, Map<String, LifecycleAction> actions) {
|
||||
this.name = name;
|
||||
if (minimumAge == null) {
|
||||
this.minimumAge = TimeValue.ZERO;
|
||||
} else {
|
||||
this.minimumAge = minimumAge;
|
||||
}
|
||||
this.actions = actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the age of the index when the index should move to this
|
||||
* {@link Phase}.
|
||||
*/
|
||||
public TimeValue getMinimumAge() {
|
||||
return minimumAge;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name of this {@link Phase}
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a {@link Map} of the {@link LifecycleAction}s to run when during
|
||||
* this {@link Phase}.
|
||||
*/
|
||||
public Map<String, LifecycleAction> getActions() {
|
||||
return actions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject();
|
||||
builder.field(MIN_AGE.getPreferredName(), minimumAge.getStringRep());
|
||||
builder.field(ACTIONS_FIELD.getPreferredName(), actions);
|
||||
builder.endObject();
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(name, minimumAge, actions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (obj.getClass() != getClass()) {
|
||||
return false;
|
||||
}
|
||||
Phase other = (Phase) obj;
|
||||
return Objects.equals(name, other.name) &&
|
||||
Objects.equals(minimumAge, other.minimumAge) &&
|
||||
Objects.equals(actions, other.actions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Strings.toString(this, true, true);
|
||||
}
|
||||
}
|
@ -1,130 +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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
|
||||
import org.elasticsearch.common.xcontent.ToXContentObject;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* This class contains information about the current phase being executed by Index
|
||||
* Lifecycle Management on the specific index.
|
||||
*/
|
||||
public class PhaseExecutionInfo implements ToXContentObject {
|
||||
private static final ParseField POLICY_NAME_FIELD = new ParseField("policy");
|
||||
private static final ParseField PHASE_DEFINITION_FIELD = new ParseField("phase_definition");
|
||||
private static final ParseField VERSION_FIELD = new ParseField("version");
|
||||
private static final ParseField MODIFIED_DATE_IN_MILLIS_FIELD = new ParseField("modified_date_in_millis");
|
||||
|
||||
private static final ConstructingObjectParser<PhaseExecutionInfo, String> PARSER = new ConstructingObjectParser<>(
|
||||
"phase_execution_info", true,
|
||||
(a, name) -> new PhaseExecutionInfo((String) a[0], (Phase) a[1], (long) a[2], (long) a[3]));
|
||||
static {
|
||||
PARSER.declareString(ConstructingObjectParser.constructorArg(), POLICY_NAME_FIELD);
|
||||
PARSER.declareObject(ConstructingObjectParser.optionalConstructorArg(), Phase::parse, PHASE_DEFINITION_FIELD);
|
||||
PARSER.declareLong(ConstructingObjectParser.constructorArg(), VERSION_FIELD);
|
||||
PARSER.declareLong(ConstructingObjectParser.constructorArg(), MODIFIED_DATE_IN_MILLIS_FIELD);
|
||||
}
|
||||
|
||||
public static PhaseExecutionInfo parse(XContentParser parser, String name) {
|
||||
return PARSER.apply(parser, name);
|
||||
}
|
||||
|
||||
private final String policyName;
|
||||
private final Phase phase;
|
||||
private final long version;
|
||||
private final long modifiedDate;
|
||||
|
||||
/**
|
||||
* This class holds information about the current phase that is being executed
|
||||
*
|
||||
* @param policyName the name of the policy being executed, this may not be the current policy assigned to an index
|
||||
* @param phase the current phase definition executed
|
||||
* @param version the version of the <code>policyName</code> being executed
|
||||
* @param modifiedDate the time the executing version of the phase was modified
|
||||
*/
|
||||
public PhaseExecutionInfo(String policyName, Phase phase, long version, long modifiedDate) {
|
||||
this.policyName = policyName;
|
||||
this.phase = phase;
|
||||
this.version = version;
|
||||
this.modifiedDate = modifiedDate;
|
||||
}
|
||||
|
||||
public String getPolicyName() {
|
||||
return policyName;
|
||||
}
|
||||
|
||||
public Phase getPhase() {
|
||||
return phase;
|
||||
}
|
||||
|
||||
public long getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public long getModifiedDate() {
|
||||
return modifiedDate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(policyName, phase, version, modifiedDate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
PhaseExecutionInfo other = (PhaseExecutionInfo) obj;
|
||||
return Objects.equals(policyName, other.policyName) &&
|
||||
Objects.equals(phase, other.phase) &&
|
||||
Objects.equals(version, other.version) &&
|
||||
Objects.equals(modifiedDate, other.modifiedDate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Strings.toString(this, false, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject();
|
||||
builder.field(POLICY_NAME_FIELD.getPreferredName(), policyName);
|
||||
if (phase != null) {
|
||||
builder.field(PHASE_DEFINITION_FIELD.getPreferredName(), phase);
|
||||
}
|
||||
builder.field(VERSION_FIELD.getPreferredName(), version);
|
||||
builder.timeField(MODIFIED_DATE_IN_MILLIS_FIELD.getPreferredName(), "modified_date", modifiedDate);
|
||||
builder.endObject();
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
|
@ -1,72 +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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.client.TimedRequest;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.xcontent.ToXContentObject;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
public class PutLifecyclePolicyRequest extends TimedRequest implements ToXContentObject {
|
||||
|
||||
private final LifecyclePolicy policy;
|
||||
|
||||
public PutLifecyclePolicyRequest(LifecyclePolicy policy) {
|
||||
if (policy == null) {
|
||||
throw new IllegalArgumentException("policy definition cannot be null");
|
||||
}
|
||||
if (Strings.isNullOrEmpty(policy.getName())) {
|
||||
throw new IllegalArgumentException("policy name must be present");
|
||||
}
|
||||
this.policy = policy;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return policy.getName();
|
||||
}
|
||||
|
||||
public LifecyclePolicy getLifecyclePolicy() {
|
||||
return policy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject();
|
||||
builder.field("policy", policy);
|
||||
builder.endObject();
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
PutLifecyclePolicyRequest that = (PutLifecyclePolicyRequest) o;
|
||||
return Objects.equals(getLifecyclePolicy(), that.getLifecyclePolicy());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(getLifecyclePolicy());
|
||||
}
|
||||
}
|
@ -1,73 +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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.xcontent.ObjectParser;
|
||||
import org.elasticsearch.common.xcontent.ToXContentObject;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class ReadOnlyAction implements LifecycleAction, ToXContentObject {
|
||||
public static final String NAME = "readonly";
|
||||
|
||||
private static final ObjectParser<ReadOnlyAction, Void> PARSER = new ObjectParser<>(NAME, true, ReadOnlyAction::new);
|
||||
|
||||
public static ReadOnlyAction parse(XContentParser parser) {
|
||||
return PARSER.apply(parser, null);
|
||||
}
|
||||
|
||||
public ReadOnlyAction() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject();
|
||||
builder.endObject();
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ReadOnlyAction.class.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (obj.getClass() != getClass()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Strings.toString(this);
|
||||
}
|
||||
}
|
@ -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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.action.support.IndicesOptions;
|
||||
import org.elasticsearch.client.TimedRequest;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class RemoveIndexLifecyclePolicyRequest extends TimedRequest {
|
||||
|
||||
private final List<String> indices;
|
||||
private final IndicesOptions indicesOptions;
|
||||
|
||||
public RemoveIndexLifecyclePolicyRequest(List<String> indices) {
|
||||
this(indices, IndicesOptions.strictExpandOpen());
|
||||
}
|
||||
|
||||
public RemoveIndexLifecyclePolicyRequest(List<String> indices, IndicesOptions indicesOptions) {
|
||||
this.indices = Collections.unmodifiableList(Objects.requireNonNull(indices));
|
||||
this.indicesOptions = Objects.requireNonNull(indicesOptions);
|
||||
}
|
||||
|
||||
public List<String> indices() {
|
||||
return indices;
|
||||
}
|
||||
|
||||
public IndicesOptions indicesOptions() {
|
||||
return indicesOptions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(indices, indicesOptions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
RemoveIndexLifecyclePolicyRequest other = (RemoveIndexLifecyclePolicyRequest) obj;
|
||||
return Objects.deepEquals(indices, other.indices) &&
|
||||
Objects.equals(indicesOptions, other.indicesOptions);
|
||||
}
|
||||
}
|
@ -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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class RemoveIndexLifecyclePolicyResponse {
|
||||
|
||||
public static final ParseField HAS_FAILURES_FIELD = new ParseField("has_failures");
|
||||
public static final ParseField FAILED_INDEXES_FIELD = new ParseField("failed_indexes");
|
||||
@SuppressWarnings("unchecked")
|
||||
public static final ConstructingObjectParser<RemoveIndexLifecyclePolicyResponse, Void> PARSER = new ConstructingObjectParser<>(
|
||||
"change_policy_for_index_response", true, args -> new RemoveIndexLifecyclePolicyResponse((List<String>)args[0]));
|
||||
static {
|
||||
PARSER.declareStringArray(ConstructingObjectParser.constructorArg(), FAILED_INDEXES_FIELD);
|
||||
// Needs to be declared but not used in constructing the response object
|
||||
PARSER.declareBoolean(ConstructingObjectParser.constructorArg(), HAS_FAILURES_FIELD);
|
||||
}
|
||||
|
||||
private final List<String> failedIndexes;
|
||||
|
||||
public RemoveIndexLifecyclePolicyResponse(List<String> failedIndexes) {
|
||||
if (failedIndexes == null) {
|
||||
throw new IllegalArgumentException(FAILED_INDEXES_FIELD.getPreferredName() + " cannot be null");
|
||||
}
|
||||
this.failedIndexes = Collections.unmodifiableList(failedIndexes);
|
||||
}
|
||||
|
||||
public List<String> getFailedIndexes() {
|
||||
return failedIndexes;
|
||||
}
|
||||
|
||||
public boolean hasFailures() {
|
||||
return failedIndexes.isEmpty() == false;
|
||||
}
|
||||
|
||||
public static RemoveIndexLifecyclePolicyResponse fromXContent(XContentParser parser) {
|
||||
return PARSER.apply(parser, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(failedIndexes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
RemoveIndexLifecyclePolicyResponse other = (RemoveIndexLifecyclePolicyResponse) obj;
|
||||
return Objects.equals(failedIndexes, other.failedIndexes);
|
||||
}
|
||||
}
|
@ -1,58 +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.indexlifecycle;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import org.elasticsearch.client.TimedRequest;
|
||||
|
||||
public class RetryLifecyclePolicyRequest extends TimedRequest {
|
||||
|
||||
private final List<String> indices;
|
||||
|
||||
public RetryLifecyclePolicyRequest(String... indices) {
|
||||
if (indices.length == 0) {
|
||||
throw new IllegalArgumentException("Must at least specify one index to retry");
|
||||
}
|
||||
this.indices = Arrays.asList(indices);
|
||||
}
|
||||
|
||||
public List<String> getIndices() {
|
||||
return indices;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
RetryLifecyclePolicyRequest that = (RetryLifecyclePolicyRequest) o;
|
||||
return indices.size() == that.indices.size() && indices.containsAll(that.indices);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(indices);
|
||||
}
|
||||
}
|
@ -1,123 +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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.unit.ByteSizeValue;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
|
||||
import org.elasticsearch.common.xcontent.ObjectParser.ValueType;
|
||||
import org.elasticsearch.common.xcontent.ToXContentObject;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
public class RolloverAction implements LifecycleAction, ToXContentObject {
|
||||
public static final String NAME = "rollover";
|
||||
private static final ParseField MAX_SIZE_FIELD = new ParseField("max_size");
|
||||
private static final ParseField MAX_DOCS_FIELD = new ParseField("max_docs");
|
||||
private static final ParseField MAX_AGE_FIELD = new ParseField("max_age");
|
||||
|
||||
private static final ConstructingObjectParser<RolloverAction, Void> PARSER = new ConstructingObjectParser<>(NAME, true,
|
||||
a -> new RolloverAction((ByteSizeValue) a[0], (TimeValue) a[1], (Long) a[2]));
|
||||
static {
|
||||
PARSER.declareField(ConstructingObjectParser.optionalConstructorArg(),
|
||||
(p, c) -> ByteSizeValue.parseBytesSizeValue(p.text(), MAX_SIZE_FIELD.getPreferredName()), MAX_SIZE_FIELD, ValueType.VALUE);
|
||||
PARSER.declareField(ConstructingObjectParser.optionalConstructorArg(),
|
||||
(p, c) -> TimeValue.parseTimeValue(p.text(), MAX_AGE_FIELD.getPreferredName()), MAX_AGE_FIELD, ValueType.VALUE);
|
||||
PARSER.declareLong(ConstructingObjectParser.optionalConstructorArg(), MAX_DOCS_FIELD);
|
||||
}
|
||||
|
||||
private final ByteSizeValue maxSize;
|
||||
private final Long maxDocs;
|
||||
private final TimeValue maxAge;
|
||||
|
||||
public static RolloverAction parse(XContentParser parser) {
|
||||
return PARSER.apply(parser, null);
|
||||
}
|
||||
|
||||
public RolloverAction(ByteSizeValue maxSize, TimeValue maxAge, Long maxDocs) {
|
||||
if (maxSize == null && maxAge == null && maxDocs == null) {
|
||||
throw new IllegalArgumentException("At least one rollover condition must be set.");
|
||||
}
|
||||
this.maxSize = maxSize;
|
||||
this.maxAge = maxAge;
|
||||
this.maxDocs = maxDocs;
|
||||
}
|
||||
public ByteSizeValue getMaxSize() {
|
||||
return maxSize;
|
||||
}
|
||||
|
||||
public TimeValue getMaxAge() {
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
public Long getMaxDocs() {
|
||||
return maxDocs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject();
|
||||
if (maxSize != null) {
|
||||
builder.field(MAX_SIZE_FIELD.getPreferredName(), maxSize.getStringRep());
|
||||
}
|
||||
if (maxAge != null) {
|
||||
builder.field(MAX_AGE_FIELD.getPreferredName(), maxAge.getStringRep());
|
||||
}
|
||||
if (maxDocs != null) {
|
||||
builder.field(MAX_DOCS_FIELD.getPreferredName(), maxDocs);
|
||||
}
|
||||
builder.endObject();
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(maxSize, maxAge, maxDocs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (obj.getClass() != getClass()) {
|
||||
return false;
|
||||
}
|
||||
RolloverAction other = (RolloverAction) obj;
|
||||
return Objects.equals(maxSize, other.maxSize) &&
|
||||
Objects.equals(maxAge, other.maxAge) &&
|
||||
Objects.equals(maxDocs, other.maxDocs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Strings.toString(this);
|
||||
}
|
||||
}
|
@ -1,100 +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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.ToXContentObject;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* A {@link LifecycleAction} that will convert the index into a searchable snapshot.
|
||||
*/
|
||||
public class SearchableSnapshotAction implements LifecycleAction, ToXContentObject {
|
||||
public static final String NAME = "searchable_snapshot";
|
||||
|
||||
public static final ParseField SNAPSHOT_REPOSITORY = new ParseField("snapshot_repository");
|
||||
public static final ParseField FORCE_MERGE_INDEX = new ParseField("force_merge_index");
|
||||
|
||||
|
||||
private static final ConstructingObjectParser<SearchableSnapshotAction, Void> PARSER = new ConstructingObjectParser<>(NAME,
|
||||
true, a -> new SearchableSnapshotAction((String) a[0], a[1] == null || (boolean) a[1]));
|
||||
|
||||
static {
|
||||
PARSER.declareString(ConstructingObjectParser.constructorArg(), SNAPSHOT_REPOSITORY);
|
||||
PARSER.declareBoolean(ConstructingObjectParser.optionalConstructorArg(), FORCE_MERGE_INDEX);
|
||||
}
|
||||
|
||||
public static SearchableSnapshotAction parse(XContentParser parser) {
|
||||
return PARSER.apply(parser, null);
|
||||
}
|
||||
|
||||
private final String snapshotRepository;
|
||||
private final boolean forceMergeIndex;
|
||||
|
||||
public SearchableSnapshotAction(String snapshotRepository, boolean forceMergeIndex) {
|
||||
if (Strings.hasText(snapshotRepository) == false) {
|
||||
throw new IllegalArgumentException("the snapshot repository must be specified");
|
||||
}
|
||||
this.snapshotRepository = snapshotRepository;
|
||||
this.forceMergeIndex = forceMergeIndex;
|
||||
}
|
||||
|
||||
public SearchableSnapshotAction(String snapshotRepository) {
|
||||
this(snapshotRepository, true);
|
||||
}
|
||||
|
||||
boolean isForceMergeIndex() {
|
||||
return forceMergeIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException {
|
||||
builder.startObject();
|
||||
builder.field(SNAPSHOT_REPOSITORY.getPreferredName(), snapshotRepository);
|
||||
builder.field(FORCE_MERGE_INDEX.getPreferredName(), forceMergeIndex);
|
||||
builder.endObject();
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
SearchableSnapshotAction that = (SearchableSnapshotAction) o;
|
||||
return forceMergeIndex == that.forceMergeIndex &&
|
||||
snapshotRepository.equals(that.snapshotRepository);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(snapshotRepository, forceMergeIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return NAME;
|
||||
}
|
||||
}
|
@ -1,96 +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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
|
||||
import org.elasticsearch.common.xcontent.ObjectParser;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.ToXContentObject;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* A {@link LifecycleAction} which sets the index's priority. The higher the priority, the faster the recovery.
|
||||
*/
|
||||
public class SetPriorityAction implements LifecycleAction, ToXContentObject {
|
||||
public static final String NAME = "set_priority";
|
||||
private static final ParseField RECOVERY_PRIORITY_FIELD = new ParseField("priority");
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static final ConstructingObjectParser<SetPriorityAction, Void> PARSER = new ConstructingObjectParser<>(NAME, true,
|
||||
a -> new SetPriorityAction((Integer) a[0]));
|
||||
|
||||
//package private for testing
|
||||
final Integer recoveryPriority;
|
||||
|
||||
static {
|
||||
PARSER.declareField(ConstructingObjectParser.constructorArg(),
|
||||
(p) -> p.currentToken() == XContentParser.Token.VALUE_NULL ? null : p.intValue()
|
||||
, RECOVERY_PRIORITY_FIELD, ObjectParser.ValueType.INT_OR_NULL);
|
||||
}
|
||||
|
||||
public static SetPriorityAction parse(XContentParser parser) {
|
||||
return PARSER.apply(parser, null);
|
||||
}
|
||||
|
||||
public SetPriorityAction(@Nullable Integer recoveryPriority) {
|
||||
if (recoveryPriority != null && recoveryPriority < 0) {
|
||||
throw new IllegalArgumentException("[" + RECOVERY_PRIORITY_FIELD.getPreferredName() + "] must be 0 or greater");
|
||||
}
|
||||
this.recoveryPriority = recoveryPriority;
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException {
|
||||
builder.startObject();
|
||||
builder.field(RECOVERY_PRIORITY_FIELD.getPreferredName(), recoveryPriority);
|
||||
builder.endObject();
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
SetPriorityAction that = (SetPriorityAction) o;
|
||||
|
||||
return recoveryPriority != null ? recoveryPriority.equals(that.recoveryPriority) : that.recoveryPriority == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return recoveryPriority != null ? recoveryPriority.hashCode() : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Strings.toString(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return NAME;
|
||||
}
|
||||
}
|
@ -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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
|
||||
import org.elasticsearch.common.xcontent.ToXContentObject;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ShrinkAction implements LifecycleAction, ToXContentObject {
|
||||
public static final String NAME = "shrink";
|
||||
private static final ParseField NUMBER_OF_SHARDS_FIELD = new ParseField("number_of_shards");
|
||||
|
||||
private static final ConstructingObjectParser<ShrinkAction, Void> PARSER =
|
||||
new ConstructingObjectParser<>(NAME, true, a -> new ShrinkAction((Integer) a[0]));
|
||||
|
||||
static {
|
||||
PARSER.declareInt(ConstructingObjectParser.constructorArg(), NUMBER_OF_SHARDS_FIELD);
|
||||
}
|
||||
|
||||
private int numberOfShards;
|
||||
|
||||
public static ShrinkAction parse(XContentParser parser) throws IOException {
|
||||
return PARSER.parse(parser, null);
|
||||
}
|
||||
|
||||
public ShrinkAction(int numberOfShards) {
|
||||
if (numberOfShards <= 0) {
|
||||
throw new IllegalArgumentException("[" + NUMBER_OF_SHARDS_FIELD.getPreferredName() + "] must be greater than 0");
|
||||
}
|
||||
this.numberOfShards = numberOfShards;
|
||||
}
|
||||
|
||||
int getNumberOfShards() {
|
||||
return numberOfShards;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject();
|
||||
builder.field(NUMBER_OF_SHARDS_FIELD.getPreferredName(), numberOfShards);
|
||||
builder.endObject();
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
ShrinkAction that = (ShrinkAction) o;
|
||||
return Objects.equals(numberOfShards, that.numberOfShards);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(numberOfShards);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Strings.toString(this);
|
||||
}
|
||||
}
|
@ -1,44 +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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.client.TimedRequest;
|
||||
|
||||
public class StartILMRequest extends TimedRequest {
|
||||
|
||||
public StartILMRequest() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 64;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (obj.getClass() != getClass()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,44 +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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.client.TimedRequest;
|
||||
|
||||
public class StopILMRequest extends TimedRequest {
|
||||
|
||||
public StopILMRequest() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 75;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (obj.getClass() != getClass()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,74 +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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.xcontent.ObjectParser;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.ToXContentObject;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class UnfollowAction implements LifecycleAction, ToXContentObject {
|
||||
public static final String NAME = "unfollow";
|
||||
|
||||
private static final ObjectParser<UnfollowAction, Void> PARSER = new ObjectParser<>(NAME, true, UnfollowAction::new);
|
||||
|
||||
public UnfollowAction() {}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return NAME;
|
||||
}
|
||||
|
||||
public static UnfollowAction parse(XContentParser parser) {
|
||||
return PARSER.apply(parser, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException {
|
||||
builder.startObject();
|
||||
builder.endObject();
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 36970;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (obj.getClass() != getClass()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Strings.toString(this);
|
||||
}
|
||||
}
|
@ -1,86 +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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.ToXContentObject;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* A {@link LifecycleAction} which waits for snapshot to be taken (by configured SLM policy).
|
||||
*/
|
||||
public class WaitForSnapshotAction implements LifecycleAction, ToXContentObject {
|
||||
|
||||
public static final String NAME = "wait_for_snapshot";
|
||||
public static final ParseField POLICY_FIELD = new ParseField("policy");
|
||||
|
||||
private static final ConstructingObjectParser<WaitForSnapshotAction, Void> PARSER = new ConstructingObjectParser<>(NAME,
|
||||
true, a -> new WaitForSnapshotAction((String) a[0]));
|
||||
|
||||
static {
|
||||
PARSER.declareString(ConstructingObjectParser.constructorArg(), POLICY_FIELD);
|
||||
}
|
||||
|
||||
private final String policy;
|
||||
|
||||
public static WaitForSnapshotAction parse(XContentParser parser) {
|
||||
return PARSER.apply(parser, null);
|
||||
}
|
||||
|
||||
public WaitForSnapshotAction(String policy) {
|
||||
if (Strings.hasText(policy) == false) {
|
||||
throw new IllegalArgumentException("policy name must be specified");
|
||||
}
|
||||
this.policy = policy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException {
|
||||
builder.startObject();
|
||||
builder.field(POLICY_FIELD.getPreferredName(), policy);
|
||||
builder.endObject();
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
WaitForSnapshotAction that = (WaitForSnapshotAction) o;
|
||||
return policy.equals(that.policy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(policy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return NAME;
|
||||
}
|
||||
}
|
@ -87,7 +87,6 @@ public final class DataStream {
|
||||
public static final ParseField GENERATION_FIELD = new ParseField("generation");
|
||||
public static final ParseField STATUS_FIELD = new ParseField("status");
|
||||
public static final ParseField INDEX_TEMPLATE_FIELD = new ParseField("template");
|
||||
public static final ParseField ILM_POLICY_FIELD = new ParseField("ilm_policy");
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static final ConstructingObjectParser<DataStream, Void> PARSER = new ConstructingObjectParser<>("data_stream",
|
||||
@ -111,7 +110,6 @@ public final class DataStream {
|
||||
PARSER.declareLong(ConstructingObjectParser.constructorArg(), GENERATION_FIELD);
|
||||
PARSER.declareString(ConstructingObjectParser.constructorArg(), STATUS_FIELD);
|
||||
PARSER.declareString(ConstructingObjectParser.optionalConstructorArg(), INDEX_TEMPLATE_FIELD);
|
||||
PARSER.declareString(ConstructingObjectParser.optionalConstructorArg(), ILM_POLICY_FIELD);
|
||||
}
|
||||
|
||||
public static DataStream fromXContent(XContentParser parser) throws IOException {
|
||||
|
@ -1,4 +1,3 @@
|
||||
org.elasticsearch.client.indexlifecycle.IndexLifecycleNamedXContentProvider
|
||||
org.elasticsearch.client.ml.dataframe.MlDataFrameAnalysisNamedXContentProvider
|
||||
org.elasticsearch.client.ml.dataframe.evaluation.MlEvaluationNamedXContentProvider
|
||||
org.elasticsearch.client.ml.dataframe.stats.AnalysisStatsNamedXContentProvider
|
||||
|
@ -1,298 +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.ElasticsearchStatusException;
|
||||
import org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest;
|
||||
import org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse;
|
||||
import org.elasticsearch.client.core.AcknowledgedResponse;
|
||||
import org.elasticsearch.client.indexlifecycle.AllocateAction;
|
||||
import org.elasticsearch.client.indexlifecycle.DeleteAction;
|
||||
import org.elasticsearch.client.indexlifecycle.DeleteLifecyclePolicyRequest;
|
||||
import org.elasticsearch.client.indexlifecycle.ExplainLifecycleRequest;
|
||||
import org.elasticsearch.client.indexlifecycle.ExplainLifecycleResponse;
|
||||
import org.elasticsearch.client.indexlifecycle.ForceMergeAction;
|
||||
import org.elasticsearch.client.indexlifecycle.GetLifecyclePolicyRequest;
|
||||
import org.elasticsearch.client.indexlifecycle.GetLifecyclePolicyResponse;
|
||||
import org.elasticsearch.client.indexlifecycle.IndexLifecycleExplainResponse;
|
||||
import org.elasticsearch.client.indexlifecycle.LifecycleAction;
|
||||
import org.elasticsearch.client.indexlifecycle.LifecycleManagementStatusRequest;
|
||||
import org.elasticsearch.client.indexlifecycle.LifecycleManagementStatusResponse;
|
||||
import org.elasticsearch.client.indexlifecycle.LifecyclePolicy;
|
||||
import org.elasticsearch.client.indexlifecycle.LifecyclePolicyMetadata;
|
||||
import org.elasticsearch.client.indexlifecycle.OperationMode;
|
||||
import org.elasticsearch.client.indexlifecycle.Phase;
|
||||
import org.elasticsearch.client.indexlifecycle.PhaseExecutionInfo;
|
||||
import org.elasticsearch.client.indexlifecycle.PutLifecyclePolicyRequest;
|
||||
import org.elasticsearch.client.indexlifecycle.RemoveIndexLifecyclePolicyRequest;
|
||||
import org.elasticsearch.client.indexlifecycle.RemoveIndexLifecyclePolicyResponse;
|
||||
import org.elasticsearch.client.indexlifecycle.RetryLifecyclePolicyRequest;
|
||||
import org.elasticsearch.client.indexlifecycle.RolloverAction;
|
||||
import org.elasticsearch.client.indexlifecycle.SearchableSnapshotAction;
|
||||
import org.elasticsearch.client.indexlifecycle.ShrinkAction;
|
||||
import org.elasticsearch.client.indexlifecycle.StartILMRequest;
|
||||
import org.elasticsearch.client.indexlifecycle.StopILMRequest;
|
||||
import org.elasticsearch.client.indexlifecycle.UnfollowAction;
|
||||
import org.elasticsearch.client.indexlifecycle.WaitForSnapshotAction;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.hamcrest.Matchers;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.elasticsearch.client.indexlifecycle.LifecyclePolicyTests.createRandomPolicy;
|
||||
import static org.elasticsearch.test.ClientAssertions.assertAcked;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasItems;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
public class IndexLifecycleIT extends ESRestHighLevelClientTestCase {
|
||||
|
||||
public void testRemoveIndexLifecyclePolicy() throws Exception {
|
||||
String policyName = randomAlphaOfLength(10);
|
||||
LifecyclePolicy policy = createRandomPolicy(policyName);
|
||||
PutLifecyclePolicyRequest putRequest = new PutLifecyclePolicyRequest(policy);
|
||||
assertAcked(execute(putRequest, highLevelClient().indexLifecycle()::putLifecyclePolicy,
|
||||
highLevelClient().indexLifecycle()::putLifecyclePolicyAsync));
|
||||
|
||||
createIndex("foo", Settings.builder().put("index.lifecycle.name", policyName).build());
|
||||
createIndex("baz", Settings.builder().put("index.lifecycle.name", policyName).build());
|
||||
createIndex("rbh", Settings.builder().put("index.lifecycle.name", policyName).build());
|
||||
|
||||
GetSettingsRequest getSettingsRequest = new GetSettingsRequest().indices("foo", "baz", "rbh");
|
||||
GetSettingsResponse settingsResponse = highLevelClient().indices().getSettings(getSettingsRequest, RequestOptions.DEFAULT);
|
||||
assertThat(settingsResponse.getSetting("foo", "index.lifecycle.name"), equalTo(policyName));
|
||||
assertThat(settingsResponse.getSetting("baz", "index.lifecycle.name"), equalTo(policyName));
|
||||
assertThat(settingsResponse.getSetting("rbh", "index.lifecycle.name"), equalTo(policyName));
|
||||
|
||||
List<String> indices = new ArrayList<>();
|
||||
indices.add("foo");
|
||||
indices.add("rbh");
|
||||
RemoveIndexLifecyclePolicyRequest removeReq = new RemoveIndexLifecyclePolicyRequest(indices);
|
||||
RemoveIndexLifecyclePolicyResponse removeResp = execute(removeReq, highLevelClient().indexLifecycle()::removeIndexLifecyclePolicy,
|
||||
highLevelClient().indexLifecycle()::removeIndexLifecyclePolicyAsync);
|
||||
assertThat(removeResp.hasFailures(), is(false));
|
||||
assertThat(removeResp.getFailedIndexes().isEmpty(), is(true));
|
||||
|
||||
getSettingsRequest = new GetSettingsRequest().indices("foo", "baz", "rbh");
|
||||
settingsResponse = highLevelClient().indices().getSettings(getSettingsRequest, RequestOptions.DEFAULT);
|
||||
assertNull(settingsResponse.getSetting("foo", "index.lifecycle.name"));
|
||||
assertThat(settingsResponse.getSetting("baz", "index.lifecycle.name"), equalTo(policyName));
|
||||
assertNull(settingsResponse.getSetting("rbh", "index.lifecycle.name"));
|
||||
}
|
||||
|
||||
public void testStartStopILM() throws Exception {
|
||||
String policyName = randomAlphaOfLength(10);
|
||||
LifecyclePolicy policy = createRandomPolicy(policyName);
|
||||
PutLifecyclePolicyRequest putRequest = new PutLifecyclePolicyRequest(policy);
|
||||
assertAcked(execute(putRequest, highLevelClient().indexLifecycle()::putLifecyclePolicy,
|
||||
highLevelClient().indexLifecycle()::putLifecyclePolicyAsync));
|
||||
|
||||
createIndex("foo", Settings.builder().put("index.lifecycle.name", "bar").build());
|
||||
createIndex("baz", Settings.builder().put("index.lifecycle.name", "eggplant").build());
|
||||
createIndex("squash", Settings.EMPTY);
|
||||
|
||||
LifecycleManagementStatusRequest statusRequest = new LifecycleManagementStatusRequest();
|
||||
LifecycleManagementStatusResponse statusResponse = execute(
|
||||
statusRequest,
|
||||
highLevelClient().indexLifecycle()::lifecycleManagementStatus,
|
||||
highLevelClient().indexLifecycle()::lifecycleManagementStatusAsync);
|
||||
assertEquals(statusResponse.getOperationMode(), OperationMode.RUNNING);
|
||||
|
||||
StopILMRequest stopReq = new StopILMRequest();
|
||||
AcknowledgedResponse stopResponse = execute(stopReq, highLevelClient().indexLifecycle()::stopILM,
|
||||
highLevelClient().indexLifecycle()::stopILMAsync);
|
||||
assertTrue(stopResponse.isAcknowledged());
|
||||
|
||||
|
||||
statusResponse = execute(statusRequest, highLevelClient().indexLifecycle()::lifecycleManagementStatus,
|
||||
highLevelClient().indexLifecycle()::lifecycleManagementStatusAsync);
|
||||
assertThat(statusResponse.getOperationMode(),
|
||||
Matchers.anyOf(equalTo(OperationMode.STOPPING),
|
||||
equalTo(OperationMode.STOPPED)));
|
||||
|
||||
StartILMRequest startReq = new StartILMRequest();
|
||||
AcknowledgedResponse startResponse = execute(startReq, highLevelClient().indexLifecycle()::startILM,
|
||||
highLevelClient().indexLifecycle()::startILMAsync);
|
||||
assertTrue(startResponse.isAcknowledged());
|
||||
|
||||
statusResponse = execute(statusRequest, highLevelClient().indexLifecycle()::lifecycleManagementStatus,
|
||||
highLevelClient().indexLifecycle()::lifecycleManagementStatusAsync);
|
||||
assertEquals(statusResponse.getOperationMode(), OperationMode.RUNNING);
|
||||
}
|
||||
|
||||
public void testExplainLifecycle() throws Exception {
|
||||
Map<String, Phase> lifecyclePhases = new HashMap<>();
|
||||
Map<String, LifecycleAction> hotActions = new HashMap<>();
|
||||
hotActions.put(RolloverAction.NAME, new RolloverAction(null, TimeValue.timeValueHours(50 * 24), null));
|
||||
Phase hotPhase = new Phase("hot", randomFrom(TimeValue.ZERO, null), hotActions);
|
||||
lifecyclePhases.put("hot", hotPhase);
|
||||
|
||||
Map<String, LifecycleAction> warmActions = new HashMap<>();
|
||||
warmActions.put(UnfollowAction.NAME, new UnfollowAction());
|
||||
warmActions.put(AllocateAction.NAME, new AllocateAction(null, null, null, Collections.singletonMap("_name", "node-1")));
|
||||
warmActions.put(ShrinkAction.NAME, new ShrinkAction(1));
|
||||
warmActions.put(ForceMergeAction.NAME, new ForceMergeAction(1000));
|
||||
lifecyclePhases.put("warm", new Phase("warm", TimeValue.timeValueSeconds(1000), warmActions));
|
||||
|
||||
Map<String, LifecycleAction> coldActions = new HashMap<>();
|
||||
coldActions.put(UnfollowAction.NAME, new UnfollowAction());
|
||||
coldActions.put(AllocateAction.NAME, new AllocateAction(0, null, null, null));
|
||||
coldActions.put(SearchableSnapshotAction.NAME, new SearchableSnapshotAction("repo"));
|
||||
lifecyclePhases.put("cold", new Phase("cold", TimeValue.timeValueSeconds(2000), coldActions));
|
||||
|
||||
Map<String, LifecycleAction> deleteActions = new HashMap<>();
|
||||
deleteActions.put(WaitForSnapshotAction.NAME, new WaitForSnapshotAction("policy"));
|
||||
deleteActions.put(DeleteAction.NAME, new DeleteAction());
|
||||
lifecyclePhases.put("delete", new Phase("delete", TimeValue.timeValueSeconds(3000), deleteActions));
|
||||
|
||||
LifecyclePolicy policy = new LifecyclePolicy(randomAlphaOfLength(10), lifecyclePhases);
|
||||
PutLifecyclePolicyRequest putRequest = new PutLifecyclePolicyRequest(policy);
|
||||
AcknowledgedResponse putResponse = execute(putRequest, highLevelClient().indexLifecycle()::putLifecyclePolicy,
|
||||
highLevelClient().indexLifecycle()::putLifecyclePolicyAsync);
|
||||
assertTrue(putResponse.isAcknowledged());
|
||||
GetLifecyclePolicyRequest getRequest = new GetLifecyclePolicyRequest(policy.getName());
|
||||
GetLifecyclePolicyResponse getResponse = execute(getRequest, highLevelClient().indexLifecycle()::getLifecyclePolicy,
|
||||
highLevelClient().indexLifecycle()::getLifecyclePolicyAsync);
|
||||
long expectedPolicyModifiedDate = getResponse.getPolicies().get(policy.getName()).getModifiedDate();
|
||||
|
||||
|
||||
createIndex("foo-01", Settings.builder().put("index.lifecycle.name", policy.getName())
|
||||
.put("index.lifecycle.rollover_alias", "foo-alias").build(), "", "\"foo-alias\" : {}");
|
||||
|
||||
createIndex("baz-01", Settings.builder().put("index.lifecycle.name", policy.getName())
|
||||
.put("index.lifecycle.rollover_alias", "baz-alias").build(), "", "\"baz-alias\" : {}");
|
||||
|
||||
createIndex("squash", Settings.EMPTY);
|
||||
|
||||
// The injected Unfollow step will run pretty rapidly here, so we need
|
||||
// to wait for it to settle into the "stable" step of waiting to be
|
||||
// ready to roll over
|
||||
assertBusy(() -> {
|
||||
ExplainLifecycleRequest req = new ExplainLifecycleRequest("foo-01", "baz-01", "squash");
|
||||
ExplainLifecycleResponse response = execute(req, highLevelClient().indexLifecycle()::explainLifecycle,
|
||||
highLevelClient().indexLifecycle()::explainLifecycleAsync);
|
||||
Map<String, IndexLifecycleExplainResponse> indexResponses = response.getIndexResponses();
|
||||
assertEquals(3, indexResponses.size());
|
||||
IndexLifecycleExplainResponse fooResponse = indexResponses.get("foo-01");
|
||||
assertNotNull(fooResponse);
|
||||
assertTrue(fooResponse.managedByILM());
|
||||
assertEquals("foo-01", fooResponse.getIndex());
|
||||
assertEquals("hot", fooResponse.getPhase());
|
||||
assertEquals("rollover", fooResponse.getAction());
|
||||
assertEquals("check-rollover-ready", fooResponse.getStep());
|
||||
assertEquals(new PhaseExecutionInfo(policy.getName(), new Phase("", hotPhase.getMinimumAge(), hotPhase.getActions()),
|
||||
1L, expectedPolicyModifiedDate), fooResponse.getPhaseExecutionInfo());
|
||||
IndexLifecycleExplainResponse bazResponse = indexResponses.get("baz-01");
|
||||
assertNotNull(bazResponse);
|
||||
assertTrue(bazResponse.managedByILM());
|
||||
assertEquals("baz-01", bazResponse.getIndex());
|
||||
assertEquals("hot", bazResponse.getPhase());
|
||||
assertEquals("rollover", bazResponse.getAction());
|
||||
assertEquals("check-rollover-ready", bazResponse.getStep());
|
||||
IndexLifecycleExplainResponse squashResponse = indexResponses.get("squash");
|
||||
assertNotNull(squashResponse);
|
||||
assertFalse(squashResponse.managedByILM());
|
||||
assertEquals("squash", squashResponse.getIndex());
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
public void testDeleteLifecycle() throws IOException {
|
||||
String policyName = randomAlphaOfLength(10);
|
||||
LifecyclePolicy policy = createRandomPolicy(policyName);
|
||||
PutLifecyclePolicyRequest putRequest = new PutLifecyclePolicyRequest(policy);
|
||||
assertAcked(execute(putRequest, highLevelClient().indexLifecycle()::putLifecyclePolicy,
|
||||
highLevelClient().indexLifecycle()::putLifecyclePolicyAsync));
|
||||
|
||||
DeleteLifecyclePolicyRequest deleteRequest = new DeleteLifecyclePolicyRequest(policy.getName());
|
||||
assertAcked(execute(deleteRequest, highLevelClient().indexLifecycle()::deleteLifecyclePolicy,
|
||||
highLevelClient().indexLifecycle()::deleteLifecyclePolicyAsync));
|
||||
|
||||
GetLifecyclePolicyRequest getRequest = new GetLifecyclePolicyRequest(policyName);
|
||||
ElasticsearchStatusException ex = expectThrows(ElasticsearchStatusException.class,
|
||||
() -> execute(getRequest, highLevelClient().indexLifecycle()::getLifecyclePolicy,
|
||||
highLevelClient().indexLifecycle()::getLifecyclePolicyAsync));
|
||||
assertEquals(404, ex.status().getStatus());
|
||||
}
|
||||
|
||||
public void testPutLifecycle() throws IOException {
|
||||
String name = randomAlphaOfLengthBetween(5, 20);
|
||||
LifecyclePolicy policy = createRandomPolicy(name);
|
||||
PutLifecyclePolicyRequest putRequest = new PutLifecyclePolicyRequest(policy);
|
||||
|
||||
assertAcked(execute(putRequest, highLevelClient().indexLifecycle()::putLifecyclePolicy,
|
||||
highLevelClient().indexLifecycle()::putLifecyclePolicyAsync));
|
||||
|
||||
GetLifecyclePolicyRequest getRequest = new GetLifecyclePolicyRequest(name);
|
||||
GetLifecyclePolicyResponse response = execute(getRequest, highLevelClient().indexLifecycle()::getLifecyclePolicy,
|
||||
highLevelClient().indexLifecycle()::getLifecyclePolicyAsync);
|
||||
assertEquals(policy, response.getPolicies().get(name).getPolicy());
|
||||
}
|
||||
|
||||
public void testGetMultipleLifecyclePolicies() throws IOException {
|
||||
int numPolicies = randomIntBetween(1, 10);
|
||||
String[] policyNames = new String[numPolicies];
|
||||
LifecyclePolicy[] policies = new LifecyclePolicy[numPolicies];
|
||||
for (int i = 0; i < numPolicies; i++) {
|
||||
policyNames[i] = "policy-" + randomAlphaOfLengthBetween(5, 10);
|
||||
policies[i] = createRandomPolicy(policyNames[i]);
|
||||
PutLifecyclePolicyRequest putRequest = new PutLifecyclePolicyRequest(policies[i]);
|
||||
assertAcked(execute(putRequest, highLevelClient().indexLifecycle()::putLifecyclePolicy,
|
||||
highLevelClient().indexLifecycle()::putLifecyclePolicyAsync));
|
||||
}
|
||||
|
||||
GetLifecyclePolicyRequest getRequest = new GetLifecyclePolicyRequest(randomFrom(policyNames, null));
|
||||
GetLifecyclePolicyResponse response = execute(getRequest, highLevelClient().indexLifecycle()::getLifecyclePolicy,
|
||||
highLevelClient().indexLifecycle()::getLifecyclePolicyAsync);
|
||||
List<LifecyclePolicy> retrievedPolicies = Arrays.stream(response.getPolicies().values().toArray())
|
||||
.map(p -> ((LifecyclePolicyMetadata) p).getPolicy()).collect(Collectors.toList());
|
||||
assertThat(retrievedPolicies, hasItems(policies));
|
||||
}
|
||||
|
||||
public void testRetryLifecycleStep() throws IOException {
|
||||
String policyName = randomAlphaOfLength(10);
|
||||
LifecyclePolicy policy = createRandomPolicy(policyName);
|
||||
PutLifecyclePolicyRequest putRequest = new PutLifecyclePolicyRequest(policy);
|
||||
assertAcked(execute(putRequest, highLevelClient().indexLifecycle()::putLifecyclePolicy,
|
||||
highLevelClient().indexLifecycle()::putLifecyclePolicyAsync));
|
||||
createIndex("retry", Settings.builder().put("index.lifecycle.name", policy.getName()).build());
|
||||
RetryLifecyclePolicyRequest retryRequest = new RetryLifecyclePolicyRequest("retry");
|
||||
ElasticsearchStatusException ex = expectThrows(ElasticsearchStatusException.class,
|
||||
() -> execute(
|
||||
retryRequest, highLevelClient().indexLifecycle()::retryLifecyclePolicy,
|
||||
highLevelClient().indexLifecycle()::retryLifecyclePolicyAsync
|
||||
)
|
||||
);
|
||||
assertEquals(400, ex.status().getStatus());
|
||||
assertEquals(
|
||||
"Elasticsearch exception [type=illegal_argument_exception, reason=cannot retry an action for an index [retry]" +
|
||||
" that has not encountered an error when running a Lifecycle Policy]",
|
||||
ex.getRootCause().getMessage()
|
||||
);
|
||||
}
|
||||
}
|
@ -1,169 +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.action.support.IndicesOptions;
|
||||
import org.elasticsearch.client.indexlifecycle.DeleteLifecyclePolicyRequest;
|
||||
import org.elasticsearch.client.indexlifecycle.ExplainLifecycleRequest;
|
||||
import org.elasticsearch.client.indexlifecycle.GetLifecyclePolicyRequest;
|
||||
import org.elasticsearch.client.indexlifecycle.LifecycleManagementStatusRequest;
|
||||
import org.elasticsearch.client.indexlifecycle.LifecyclePolicy;
|
||||
import org.elasticsearch.client.indexlifecycle.PutLifecyclePolicyRequest;
|
||||
import org.elasticsearch.client.indexlifecycle.RemoveIndexLifecyclePolicyRequest;
|
||||
import org.elasticsearch.client.indexlifecycle.RetryLifecyclePolicyRequest;
|
||||
import org.elasticsearch.client.indexlifecycle.StartILMRequest;
|
||||
import org.elasticsearch.client.indexlifecycle.StopILMRequest;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.elasticsearch.client.RequestConvertersTests.randomIndicesNames;
|
||||
import static org.elasticsearch.client.RequestConvertersTests.setRandomIndicesOptions;
|
||||
import static org.elasticsearch.client.RequestConvertersTests.setRandomMasterTimeout;
|
||||
import static org.elasticsearch.client.RequestConvertersTests.setRandomTimeoutTimeValue;
|
||||
import static org.elasticsearch.client.indexlifecycle.LifecyclePolicyTests.createRandomPolicy;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
|
||||
public class IndexLifecycleRequestConvertersTests extends ESTestCase {
|
||||
|
||||
public void testGetLifecyclePolicy() {
|
||||
String[] policies = rarely() ? null : randomIndicesNames(0, 10);
|
||||
GetLifecyclePolicyRequest req = new GetLifecyclePolicyRequest(policies);
|
||||
Map<String, String> expectedParams = new HashMap<>();
|
||||
setRandomMasterTimeout(req::setMasterTimeout, TimedRequest.DEFAULT_MASTER_NODE_TIMEOUT, expectedParams);
|
||||
setRandomTimeoutTimeValue(req::setTimeout, TimedRequest.DEFAULT_ACK_TIMEOUT, expectedParams);
|
||||
|
||||
Request request = IndexLifecycleRequestConverters.getLifecyclePolicy(req);
|
||||
assertEquals(request.getMethod(), HttpGet.METHOD_NAME);
|
||||
String policiesStr = Strings.arrayToCommaDelimitedString(policies);
|
||||
assertEquals(request.getEndpoint(), "/_ilm/policy" + (policiesStr.isEmpty() ? "" : ("/" + policiesStr)));
|
||||
assertEquals(request.getParameters(), expectedParams);
|
||||
}
|
||||
|
||||
public void testPutLifecyclePolicy() throws Exception {
|
||||
String name = randomAlphaOfLengthBetween(2, 20);
|
||||
LifecyclePolicy policy = createRandomPolicy(name);
|
||||
PutLifecyclePolicyRequest req = new PutLifecyclePolicyRequest(policy);
|
||||
Map<String, String> expectedParams = new HashMap<>();
|
||||
setRandomMasterTimeout(req::setMasterTimeout, TimedRequest.DEFAULT_MASTER_NODE_TIMEOUT, expectedParams);
|
||||
setRandomTimeoutTimeValue(req::setTimeout, TimedRequest.DEFAULT_ACK_TIMEOUT, expectedParams);
|
||||
|
||||
Request request = IndexLifecycleRequestConverters.putLifecyclePolicy(req);
|
||||
assertEquals(HttpPut.METHOD_NAME, request.getMethod());
|
||||
assertEquals("/_ilm/policy/" + name, request.getEndpoint());
|
||||
assertEquals(expectedParams, request.getParameters());
|
||||
}
|
||||
|
||||
public void testDeleteLifecycle() {
|
||||
String lifecycleName = randomAlphaOfLengthBetween(2,20);
|
||||
DeleteLifecyclePolicyRequest req = new DeleteLifecyclePolicyRequest(lifecycleName);
|
||||
Map<String, String> expectedParams = new HashMap<>();
|
||||
setRandomMasterTimeout(req::setMasterTimeout, TimedRequest.DEFAULT_MASTER_NODE_TIMEOUT, expectedParams);
|
||||
setRandomTimeoutTimeValue(req::setTimeout, TimedRequest.DEFAULT_ACK_TIMEOUT, expectedParams);
|
||||
|
||||
Request request = IndexLifecycleRequestConverters.deleteLifecyclePolicy(req);
|
||||
assertEquals(request.getMethod(), HttpDelete.METHOD_NAME);
|
||||
assertEquals(request.getEndpoint(), "/_ilm/policy/" + lifecycleName);
|
||||
assertEquals(request.getParameters(), expectedParams);
|
||||
}
|
||||
|
||||
public void testRemoveIndexLifecyclePolicy() {
|
||||
Map<String, String> expectedParams = new HashMap<>();
|
||||
String[] indices = randomIndicesNames(0, 10);
|
||||
IndicesOptions indicesOptions = setRandomIndicesOptions(IndicesOptions.strictExpandOpen(), expectedParams);
|
||||
RemoveIndexLifecyclePolicyRequest req = new RemoveIndexLifecyclePolicyRequest(Arrays.asList(indices), indicesOptions);
|
||||
setRandomMasterTimeout(req::setMasterTimeout, TimedRequest.DEFAULT_MASTER_NODE_TIMEOUT, expectedParams);
|
||||
|
||||
Request request = IndexLifecycleRequestConverters.removeIndexLifecyclePolicy(req);
|
||||
assertThat(request.getMethod(), equalTo(HttpPost.METHOD_NAME));
|
||||
String idxString = Strings.arrayToCommaDelimitedString(indices);
|
||||
assertThat(request.getEndpoint(), equalTo("/" + (idxString.isEmpty() ? "" : (idxString + "/")) + "_ilm/remove"));
|
||||
assertThat(request.getParameters(), equalTo(expectedParams));
|
||||
}
|
||||
|
||||
public void testStartILM() throws Exception {
|
||||
StartILMRequest req = new StartILMRequest();
|
||||
Map<String, String> expectedParams = new HashMap<>();
|
||||
setRandomMasterTimeout(req::setMasterTimeout, TimedRequest.DEFAULT_MASTER_NODE_TIMEOUT, expectedParams);
|
||||
setRandomTimeoutTimeValue(req::setTimeout, TimedRequest.DEFAULT_ACK_TIMEOUT, expectedParams);
|
||||
|
||||
Request request = IndexLifecycleRequestConverters.startILM(req);
|
||||
assertThat(request.getMethod(), equalTo(HttpPost.METHOD_NAME));
|
||||
assertThat(request.getEndpoint(), equalTo("/_ilm/start"));
|
||||
assertThat(request.getParameters(), equalTo(expectedParams));
|
||||
}
|
||||
|
||||
public void testStopILM() throws Exception {
|
||||
StopILMRequest req = new StopILMRequest();
|
||||
Map<String, String> expectedParams = new HashMap<>();
|
||||
setRandomMasterTimeout(req::setMasterTimeout, TimedRequest.DEFAULT_MASTER_NODE_TIMEOUT, expectedParams);
|
||||
setRandomTimeoutTimeValue(req::setTimeout, TimedRequest.DEFAULT_ACK_TIMEOUT, expectedParams);
|
||||
|
||||
Request request = IndexLifecycleRequestConverters.stopILM(req);
|
||||
assertThat(request.getMethod(), equalTo(HttpPost.METHOD_NAME));
|
||||
assertThat(request.getEndpoint(), equalTo("/_ilm/stop"));
|
||||
assertThat(request.getParameters(), equalTo(expectedParams));
|
||||
}
|
||||
|
||||
public void testLifecycleManagementStatus() throws Exception {
|
||||
LifecycleManagementStatusRequest req = new LifecycleManagementStatusRequest();
|
||||
Map<String, String> expectedParams = new HashMap<>();
|
||||
setRandomMasterTimeout(req::setMasterTimeout, TimedRequest.DEFAULT_MASTER_NODE_TIMEOUT, expectedParams);
|
||||
setRandomTimeoutTimeValue(req::setTimeout, TimedRequest.DEFAULT_ACK_TIMEOUT, expectedParams);
|
||||
|
||||
Request request = IndexLifecycleRequestConverters.lifecycleManagementStatus(req);
|
||||
assertThat(request.getMethod(), equalTo(HttpGet.METHOD_NAME));
|
||||
assertThat(request.getEndpoint(), equalTo("/_ilm/status"));
|
||||
assertThat(request.getParameters(), equalTo(expectedParams));
|
||||
}
|
||||
|
||||
public void testExplainLifecycle() throws Exception {
|
||||
ExplainLifecycleRequest req = new ExplainLifecycleRequest(randomIndicesNames(1, 10));
|
||||
Map<String, String> expectedParams = new HashMap<>();
|
||||
setRandomMasterTimeout(req, expectedParams);
|
||||
setRandomIndicesOptions(req::indicesOptions, req::indicesOptions, expectedParams);
|
||||
|
||||
Request request = IndexLifecycleRequestConverters.explainLifecycle(req);
|
||||
assertThat(request.getMethod(), equalTo(HttpGet.METHOD_NAME));
|
||||
String idxString = Strings.arrayToCommaDelimitedString(req.getIndices());
|
||||
assertThat(request.getEndpoint(), equalTo("/" + idxString + "/" + "_ilm/explain"));
|
||||
assertThat(request.getParameters(), equalTo(expectedParams));
|
||||
}
|
||||
|
||||
public void testRetryLifecycle() throws Exception {
|
||||
String[] indices = randomIndicesNames(1, 10);
|
||||
RetryLifecyclePolicyRequest req = new RetryLifecyclePolicyRequest(indices);
|
||||
Map<String, String> expectedParams = new HashMap<>();
|
||||
setRandomMasterTimeout(req::setMasterTimeout, TimedRequest.DEFAULT_MASTER_NODE_TIMEOUT, expectedParams);
|
||||
setRandomTimeoutTimeValue(req::setTimeout, TimedRequest.DEFAULT_ACK_TIMEOUT, expectedParams);
|
||||
Request request = IndexLifecycleRequestConverters.retryLifecycle(req);
|
||||
assertThat(request.getMethod(), equalTo(HttpPost.METHOD_NAME));
|
||||
String idxString = Strings.arrayToCommaDelimitedString(indices);
|
||||
assertThat(request.getEndpoint(), equalTo("/" + (idxString.isEmpty() ? "" : (idxString + "/")) + "_ilm/retry"));
|
||||
assertThat(request.getParameters(), equalTo(expectedParams));
|
||||
}
|
||||
}
|
@ -21,10 +21,6 @@ package org.elasticsearch.client;
|
||||
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.elasticsearch.client.core.MainResponse;
|
||||
import org.elasticsearch.client.xpack.XPackInfoRequest;
|
||||
import org.elasticsearch.client.xpack.XPackInfoResponse;
|
||||
import org.elasticsearch.client.xpack.XPackInfoResponse.FeatureSetsInfo.FeatureSet;
|
||||
import org.elasticsearch.client.license.LicenseStatus;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.EnumSet;
|
||||
|
@ -45,18 +45,6 @@ import org.elasticsearch.action.search.SearchScrollRequest;
|
||||
import org.elasticsearch.action.search.ShardSearchFailure;
|
||||
import org.elasticsearch.client.core.MainRequest;
|
||||
import org.elasticsearch.client.core.MainResponse;
|
||||
import org.elasticsearch.client.indexlifecycle.AllocateAction;
|
||||
import org.elasticsearch.client.indexlifecycle.DeleteAction;
|
||||
import org.elasticsearch.client.indexlifecycle.ForceMergeAction;
|
||||
import org.elasticsearch.client.indexlifecycle.FreezeAction;
|
||||
import org.elasticsearch.client.indexlifecycle.LifecycleAction;
|
||||
import org.elasticsearch.client.indexlifecycle.ReadOnlyAction;
|
||||
import org.elasticsearch.client.indexlifecycle.RolloverAction;
|
||||
import org.elasticsearch.client.indexlifecycle.SearchableSnapshotAction;
|
||||
import org.elasticsearch.client.indexlifecycle.SetPriorityAction;
|
||||
import org.elasticsearch.client.indexlifecycle.ShrinkAction;
|
||||
import org.elasticsearch.client.indexlifecycle.UnfollowAction;
|
||||
import org.elasticsearch.client.indexlifecycle.WaitForSnapshotAction;
|
||||
import org.elasticsearch.client.ml.dataframe.DataFrameAnalysis;
|
||||
import org.elasticsearch.client.ml.dataframe.evaluation.classification.AccuracyMetric;
|
||||
import org.elasticsearch.client.ml.dataframe.evaluation.classification.AucRocMetric;
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,107 +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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.test.AbstractXContentTestCase;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class AllocateActionTests extends AbstractXContentTestCase<AllocateAction> {
|
||||
|
||||
@Override
|
||||
protected AllocateAction createTestInstance() {
|
||||
return randomInstance();
|
||||
}
|
||||
|
||||
static AllocateAction randomInstance() {
|
||||
boolean hasAtLeastOneMap = false;
|
||||
Map<String, String> includes;
|
||||
if (randomBoolean()) {
|
||||
includes = randomMap(1, 100);
|
||||
hasAtLeastOneMap = true;
|
||||
} else {
|
||||
includes = randomBoolean() ? null : Collections.emptyMap();
|
||||
}
|
||||
Map<String, String> excludes;
|
||||
if (randomBoolean()) {
|
||||
hasAtLeastOneMap = true;
|
||||
excludes = randomMap(1, 100);
|
||||
} else {
|
||||
excludes = randomBoolean() ? null : Collections.emptyMap();
|
||||
}
|
||||
Map<String, String> requires;
|
||||
if (hasAtLeastOneMap == false || randomBoolean()) {
|
||||
requires = randomMap(1, 100);
|
||||
} else {
|
||||
requires = randomBoolean() ? null : Collections.emptyMap();
|
||||
}
|
||||
Integer numberOfReplicas = randomBoolean() ? null : randomIntBetween(0, 10);
|
||||
return new AllocateAction(numberOfReplicas, includes, excludes, requires);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AllocateAction doParseInstance(XContentParser parser) {
|
||||
return AllocateAction.parse(parser);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean supportsUnknownFields() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Predicate<String> getRandomFieldsExcludeFilter() {
|
||||
// this whole structure expects to be maps of strings, so more complex objects would just mess that up.
|
||||
// setting it this way allows for new fields at the root
|
||||
return (field) -> field.isEmpty() == false;
|
||||
}
|
||||
|
||||
public void testAllMapsNullOrEmpty() {
|
||||
Map<String, String> include = randomBoolean() ? null : Collections.emptyMap();
|
||||
Map<String, String> exclude = randomBoolean() ? null : Collections.emptyMap();
|
||||
Map<String, String> require = randomBoolean() ? null : Collections.emptyMap();
|
||||
IllegalArgumentException exception = expectThrows(IllegalArgumentException.class,
|
||||
() -> new AllocateAction(null, include, exclude, require));
|
||||
assertEquals("At least one of " + AllocateAction.INCLUDE_FIELD.getPreferredName() + ", "
|
||||
+ AllocateAction.EXCLUDE_FIELD.getPreferredName() + " or " + AllocateAction.REQUIRE_FIELD.getPreferredName()
|
||||
+ "must contain attributes for action " + AllocateAction.NAME, exception.getMessage());
|
||||
}
|
||||
|
||||
public void testInvalidNumberOfReplicas() {
|
||||
Map<String, String> include = randomMap(1, 5);
|
||||
Map<String, String> exclude = randomBoolean() ? null : Collections.emptyMap();
|
||||
Map<String, String> require = randomBoolean() ? null : Collections.emptyMap();
|
||||
IllegalArgumentException exception = expectThrows(IllegalArgumentException.class,
|
||||
() -> new AllocateAction(randomIntBetween(-1000, -1), include, exclude, require));
|
||||
assertEquals("[" + AllocateAction.NUMBER_OF_REPLICAS_FIELD.getPreferredName() + "] must be >= 0", exception.getMessage());
|
||||
}
|
||||
|
||||
public static Map<String, String> randomMap(int minEntries, int maxEntries) {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
int numIncludes = randomIntBetween(minEntries, maxEntries);
|
||||
for (int i = 0; i < numIncludes; i++) {
|
||||
map.put(randomAlphaOfLengthBetween(1, 20), randomAlphaOfLengthBetween(1, 20));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}
|
@ -1,40 +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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.test.AbstractXContentTestCase;
|
||||
|
||||
public class DeleteActionTests extends AbstractXContentTestCase<DeleteAction> {
|
||||
|
||||
@Override
|
||||
protected DeleteAction createTestInstance() {
|
||||
return new DeleteAction();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DeleteAction doParseInstance(XContentParser parser) {
|
||||
return DeleteAction.parse(parser);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean supportsUnknownFields() {
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,39 +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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
||||
public class DeleteLifecyclePolicyRequestTests extends ESTestCase {
|
||||
|
||||
private DeleteLifecyclePolicyRequest createTestInstance() {
|
||||
return new DeleteLifecyclePolicyRequest(randomAlphaOfLengthBetween(2, 20));
|
||||
}
|
||||
|
||||
public void testValidate() {
|
||||
DeleteLifecyclePolicyRequest req = createTestInstance();
|
||||
assertFalse(req.validate().isPresent());
|
||||
|
||||
}
|
||||
|
||||
public void testValidationFailure() {
|
||||
expectThrows(IllegalArgumentException.class, () -> new DeleteLifecyclePolicyRequest(randomFrom("", null)));
|
||||
}
|
||||
}
|
@ -1,77 +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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.action.support.IndicesOptions;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.test.EqualsHashCodeTestUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
public class ExplainLifecycleRequestTests extends ESTestCase {
|
||||
|
||||
public void testEqualsAndHashcode() {
|
||||
EqualsHashCodeTestUtils.checkEqualsAndHashCode(createTestInstance(), this::copy, this::mutateInstance);
|
||||
}
|
||||
|
||||
public void testEmptyIndices() {
|
||||
IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, ExplainLifecycleRequest::new);
|
||||
assertThat(exception.getMessage(), equalTo("Must at least specify one index to explain"));
|
||||
}
|
||||
|
||||
private ExplainLifecycleRequest createTestInstance() {
|
||||
ExplainLifecycleRequest request = new ExplainLifecycleRequest(generateRandomStringArray(20, 20, false, false));
|
||||
if (randomBoolean()) {
|
||||
IndicesOptions indicesOptions = IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(),
|
||||
randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean());
|
||||
request.indicesOptions(indicesOptions);
|
||||
}
|
||||
return request;
|
||||
}
|
||||
|
||||
private ExplainLifecycleRequest mutateInstance(ExplainLifecycleRequest instance) {
|
||||
String[] indices = instance.getIndices();
|
||||
IndicesOptions indicesOptions = instance.indicesOptions();
|
||||
switch (between(0, 1)) {
|
||||
case 0:
|
||||
indices = randomValueOtherThanMany(i -> Arrays.equals(i, instance.getIndices()),
|
||||
() -> generateRandomStringArray(20, 10, false, false));
|
||||
break;
|
||||
case 1:
|
||||
indicesOptions = randomValueOtherThan(indicesOptions, () -> IndicesOptions.fromOptions(randomBoolean(), randomBoolean(),
|
||||
randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean()));
|
||||
break;
|
||||
default:
|
||||
throw new AssertionError("Illegal randomisation branch");
|
||||
}
|
||||
ExplainLifecycleRequest newRequest = new ExplainLifecycleRequest(indices);
|
||||
newRequest.indicesOptions(indicesOptions);
|
||||
return newRequest;
|
||||
}
|
||||
|
||||
private ExplainLifecycleRequest copy(ExplainLifecycleRequest original) {
|
||||
ExplainLifecycleRequest copy = new ExplainLifecycleRequest(original.getIndices());
|
||||
copy.indicesOptions(original.indicesOptions());
|
||||
return copy;
|
||||
}
|
||||
|
||||
}
|
@ -1,66 +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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.cluster.ClusterModule;
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.test.AbstractXContentTestCase;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ExplainLifecycleResponseTests extends AbstractXContentTestCase<ExplainLifecycleResponse> {
|
||||
|
||||
@Override
|
||||
protected ExplainLifecycleResponse createTestInstance() {
|
||||
Map<String, IndexLifecycleExplainResponse> indexResponses = new HashMap<>();
|
||||
for (int i = 0; i < randomIntBetween(0, 2); i++) {
|
||||
IndexLifecycleExplainResponse indexResponse = IndexLifecycleExplainResponseTests.randomIndexExplainResponse();
|
||||
indexResponses.put(indexResponse.getIndex(), indexResponse);
|
||||
}
|
||||
return new ExplainLifecycleResponse(indexResponses);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ExplainLifecycleResponse doParseInstance(XContentParser parser) throws IOException {
|
||||
return ExplainLifecycleResponse.fromXContent(parser);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean supportsUnknownFields() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean assertToXContentEquivalence() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NamedXContentRegistry xContentRegistry() {
|
||||
List<NamedXContentRegistry.Entry> entries = new ArrayList<>(ClusterModule.getNamedXWriteables());
|
||||
entries.add(new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(DeleteAction.NAME), DeleteAction::parse));
|
||||
return new NamedXContentRegistry(entries);
|
||||
}
|
||||
}
|
@ -1,66 +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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.xcontent.DeprecationHandler;
|
||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.test.AbstractXContentTestCase;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
public class ForceMergeActionTests extends AbstractXContentTestCase<ForceMergeAction> {
|
||||
|
||||
@Override
|
||||
protected ForceMergeAction doParseInstance(XContentParser parser) {
|
||||
return ForceMergeAction.parse(parser);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean supportsUnknownFields() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ForceMergeAction createTestInstance() {
|
||||
return randomInstance();
|
||||
}
|
||||
|
||||
static ForceMergeAction randomInstance() {
|
||||
return new ForceMergeAction(randomIntBetween(1, 100));
|
||||
}
|
||||
|
||||
public void testMissingMaxNumSegments() throws IOException {
|
||||
BytesReference emptyObject = BytesReference.bytes(JsonXContent.contentBuilder().startObject().endObject());
|
||||
XContentParser parser = XContentHelper.createParser(null, DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
|
||||
emptyObject, XContentType.JSON);
|
||||
Exception e = expectThrows(IllegalArgumentException.class, () -> ForceMergeAction.parse(parser));
|
||||
assertThat(e.getMessage(), equalTo("Required [max_num_segments]"));
|
||||
}
|
||||
|
||||
public void testInvalidNegativeSegmentNumber() {
|
||||
Exception r = expectThrows(IllegalArgumentException.class, () -> new ForceMergeAction(randomIntBetween(-10, 0)));
|
||||
assertThat(r.getMessage(), equalTo("[max_num_segments] must be a positive integer"));
|
||||
}
|
||||
}
|
@ -1,40 +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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.test.AbstractXContentTestCase;
|
||||
|
||||
public class FreezeActionTests extends AbstractXContentTestCase<FreezeAction> {
|
||||
|
||||
@Override
|
||||
protected FreezeAction createTestInstance() {
|
||||
return new FreezeAction();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FreezeAction doParseInstance(XContentParser parser) {
|
||||
return FreezeAction.parse(parser);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean supportsUnknownFields() {
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,45 +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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
||||
public class GetLifecyclePolicyRequestTests extends ESTestCase {
|
||||
|
||||
private GetLifecyclePolicyRequest createTestInstance() {
|
||||
int numPolicies = randomIntBetween(0, 10);
|
||||
String[] policyNames = new String[numPolicies];
|
||||
for (int i = 0; i < numPolicies; i++) {
|
||||
policyNames[i] = "policy-" + randomAlphaOfLengthBetween(2, 5);
|
||||
}
|
||||
return new GetLifecyclePolicyRequest(policyNames);
|
||||
}
|
||||
|
||||
public void testValidation() {
|
||||
GetLifecyclePolicyRequest request = createTestInstance();
|
||||
assertFalse(request.validate().isPresent());
|
||||
}
|
||||
|
||||
public void testNullPolicyNameShouldFail() {
|
||||
expectThrows(IllegalArgumentException.class,
|
||||
() -> new GetLifecyclePolicyRequest(randomAlphaOfLengthBetween(2,20), null, randomAlphaOfLengthBetween(2,20)));
|
||||
}
|
||||
|
||||
}
|
@ -1,97 +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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.cluster.ClusterModule;
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.collect.ImmutableOpenMap;
|
||||
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.test.AbstractXContentTestCase;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import static org.elasticsearch.client.indexlifecycle.LifecyclePolicyTests.createRandomPolicy;
|
||||
|
||||
public class GetLifecyclePolicyResponseTests extends AbstractXContentTestCase<GetLifecyclePolicyResponse> {
|
||||
|
||||
@Override
|
||||
protected GetLifecyclePolicyResponse createTestInstance() {
|
||||
int numPolicies = randomIntBetween(1, 10);
|
||||
ImmutableOpenMap.Builder<String, LifecyclePolicyMetadata> policies = ImmutableOpenMap.builder();
|
||||
for (int i = 0; i < numPolicies; i++) {
|
||||
String policyName = "policy-" + randomAlphaOfLengthBetween(2, 5);
|
||||
LifecyclePolicy policy = createRandomPolicy(policyName);
|
||||
policies.put(policyName, new LifecyclePolicyMetadata(policy, randomLong(), randomLong()));
|
||||
}
|
||||
return new GetLifecyclePolicyResponse(policies.build());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GetLifecyclePolicyResponse doParseInstance(XContentParser parser) throws IOException {
|
||||
return GetLifecyclePolicyResponse.fromXContent(parser);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean supportsUnknownFields() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Predicate<String> getRandomFieldsExcludeFilter() {
|
||||
return (field) ->
|
||||
// phases is a list of Phase parsable entries only
|
||||
field.endsWith(".phases")
|
||||
// these are all meant to be maps of strings, so complex objects will confuse the parser
|
||||
|| field.endsWith(".include")
|
||||
|| field.endsWith(".exclude")
|
||||
|| field.endsWith(".require")
|
||||
// actions are meant to be a list of LifecycleAction parsable entries only
|
||||
|| field.endsWith(".actions")
|
||||
// field.isEmpty() means do not insert an object at the root of the json. This parser expects
|
||||
// every root level named object to be parsable as a specific type
|
||||
|| field.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NamedXContentRegistry xContentRegistry() {
|
||||
List<NamedXContentRegistry.Entry> entries = new ArrayList<>(ClusterModule.getNamedXWriteables());
|
||||
entries.addAll(Arrays.asList(
|
||||
new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(AllocateAction.NAME), AllocateAction::parse),
|
||||
new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(DeleteAction.NAME), DeleteAction::parse),
|
||||
new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(ForceMergeAction.NAME), ForceMergeAction::parse),
|
||||
new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(ReadOnlyAction.NAME), ReadOnlyAction::parse),
|
||||
new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(RolloverAction.NAME), RolloverAction::parse),
|
||||
new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(ShrinkAction.NAME), ShrinkAction::parse),
|
||||
new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(FreezeAction.NAME), FreezeAction::parse),
|
||||
new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(WaitForSnapshotAction.NAME),
|
||||
WaitForSnapshotAction::parse),
|
||||
new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(SetPriorityAction.NAME), SetPriorityAction::parse),
|
||||
new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(SearchableSnapshotAction.NAME),
|
||||
SearchableSnapshotAction::parse),
|
||||
new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(UnfollowAction.NAME), UnfollowAction::parse)
|
||||
));
|
||||
return new NamedXContentRegistry(entries);
|
||||
}
|
||||
}
|
@ -1,167 +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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.cluster.ClusterModule;
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.bytes.BytesArray;
|
||||
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
||||
import org.elasticsearch.common.xcontent.ToXContentObject;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.test.AbstractXContentTestCase;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
|
||||
public class IndexLifecycleExplainResponseTests extends AbstractXContentTestCase<IndexLifecycleExplainResponse> {
|
||||
|
||||
static IndexLifecycleExplainResponse randomIndexExplainResponse() {
|
||||
if (frequently()) {
|
||||
return randomManagedIndexExplainResponse();
|
||||
} else {
|
||||
return randomUnmanagedIndexExplainResponse();
|
||||
}
|
||||
}
|
||||
|
||||
private static IndexLifecycleExplainResponse randomUnmanagedIndexExplainResponse() {
|
||||
return IndexLifecycleExplainResponse.newUnmanagedIndexResponse(randomAlphaOfLength(10));
|
||||
}
|
||||
|
||||
private static IndexLifecycleExplainResponse randomManagedIndexExplainResponse() {
|
||||
boolean stepNull = randomBoolean();
|
||||
return IndexLifecycleExplainResponse.newManagedIndexResponse(randomAlphaOfLength(10),
|
||||
randomAlphaOfLength(10),
|
||||
randomBoolean() ? null : randomLongBetween(0, System.currentTimeMillis()),
|
||||
stepNull ? null : randomAlphaOfLength(10),
|
||||
stepNull ? null : randomAlphaOfLength(10),
|
||||
stepNull ? null : randomAlphaOfLength(10),
|
||||
randomBoolean() ? null : randomAlphaOfLength(10),
|
||||
stepNull ? null : randomNonNegativeLong(),
|
||||
stepNull ? null : randomNonNegativeLong(),
|
||||
stepNull ? null : randomNonNegativeLong(),
|
||||
randomBoolean() ? null : new BytesArray(new RandomStepInfo(() -> randomAlphaOfLength(10)).toString()),
|
||||
randomBoolean() ? null : PhaseExecutionInfoTests.randomPhaseExecutionInfo(""));
|
||||
}
|
||||
|
||||
public void testInvalidStepDetails() {
|
||||
final int numNull = randomIntBetween(1, 3);
|
||||
IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, () ->
|
||||
IndexLifecycleExplainResponse.newManagedIndexResponse(randomAlphaOfLength(10),
|
||||
randomAlphaOfLength(10),
|
||||
randomBoolean() ? null : randomNonNegativeLong(),
|
||||
(numNull == 1) ? null : randomAlphaOfLength(10),
|
||||
(numNull == 2) ? null : randomAlphaOfLength(10),
|
||||
(numNull == 3) ? null : randomAlphaOfLength(10),
|
||||
randomBoolean() ? null : randomAlphaOfLength(10),
|
||||
randomBoolean() ? null : randomNonNegativeLong(),
|
||||
randomBoolean() ? null : randomNonNegativeLong(),
|
||||
randomBoolean() ? null : randomNonNegativeLong(),
|
||||
randomBoolean() ? null : new BytesArray(new RandomStepInfo(() -> randomAlphaOfLength(10)).toString()),
|
||||
randomBoolean() ? null : PhaseExecutionInfoTests.randomPhaseExecutionInfo("")));
|
||||
assertThat(exception.getMessage(), startsWith("managed index response must have complete step details"));
|
||||
assertThat(exception.getMessage(), containsString("=null"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IndexLifecycleExplainResponse createTestInstance() {
|
||||
return randomIndexExplainResponse();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IndexLifecycleExplainResponse doParseInstance(XContentParser parser) throws IOException {
|
||||
return IndexLifecycleExplainResponse.PARSER.apply(parser, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean supportsUnknownFields() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean assertToXContentEquivalence() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Predicate<String> getRandomFieldsExcludeFilter() {
|
||||
return (field) ->
|
||||
// actions are plucked from the named registry, and it fails if the action is not in the named registry
|
||||
field.endsWith("phase_definition.actions")
|
||||
// This is a bytes reference, so any new fields are tested for equality in this bytes reference.
|
||||
|| field.contains("step_info");
|
||||
}
|
||||
|
||||
private static class RandomStepInfo implements ToXContentObject {
|
||||
|
||||
private final String key;
|
||||
private final String value;
|
||||
|
||||
RandomStepInfo(Supplier<String> randomStringSupplier) {
|
||||
this.key = randomStringSupplier.get();
|
||||
this.value = randomStringSupplier.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject();
|
||||
builder.field(key, value);
|
||||
builder.endObject();
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
RandomStepInfo other = (RandomStepInfo) obj;
|
||||
return Objects.equals(key, other.key) && Objects.equals(value, other.value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Strings.toString(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NamedXContentRegistry xContentRegistry() {
|
||||
List<NamedXContentRegistry.Entry> entries = new ArrayList<>(ClusterModule.getNamedXWriteables());
|
||||
entries.add(new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(DeleteAction.NAME), DeleteAction::parse));
|
||||
return new NamedXContentRegistry(entries);
|
||||
}
|
||||
}
|
@ -1,81 +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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.common.xcontent.DeprecationHandler;
|
||||
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.hamcrest.CoreMatchers;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.EnumSet;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.elasticsearch.test.AbstractXContentTestCase.xContentTester;
|
||||
|
||||
public class LifecycleManagementStatusResponseTests extends ESTestCase {
|
||||
|
||||
public void testFromXContent() throws IOException {
|
||||
xContentTester(this::createParser,
|
||||
LifecycleManagementStatusResponseTests::createTestInstance,
|
||||
LifecycleManagementStatusResponseTests::toXContent,
|
||||
LifecycleManagementStatusResponse::fromXContent)
|
||||
.supportsUnknownFields(true)
|
||||
.assertToXContentEquivalence(false)
|
||||
.test();
|
||||
}
|
||||
|
||||
private static XContentBuilder toXContent(LifecycleManagementStatusResponse response, XContentBuilder builder) throws IOException {
|
||||
builder.startObject();
|
||||
builder.field("operation_mode", response.getOperationMode());
|
||||
builder.endObject();
|
||||
return builder;
|
||||
}
|
||||
|
||||
private static LifecycleManagementStatusResponse createTestInstance() {
|
||||
return new LifecycleManagementStatusResponse(randomFrom(OperationMode.values()).name());
|
||||
}
|
||||
|
||||
public void testAllValidStatuses() {
|
||||
EnumSet.allOf(OperationMode.class)
|
||||
.forEach(e -> assertEquals(new LifecycleManagementStatusResponse(e.name()).getOperationMode(), e));
|
||||
}
|
||||
|
||||
public void testXContent() throws IOException {
|
||||
XContentType xContentType = XContentType.JSON;
|
||||
String mode = randomFrom(EnumSet.allOf(OperationMode.class)
|
||||
.stream().map(Enum::name).collect(Collectors.toList()));
|
||||
XContentParser parser = xContentType.xContent().createParser(NamedXContentRegistry.EMPTY,
|
||||
DeprecationHandler.THROW_UNSUPPORTED_OPERATION, "{\"operation_mode\" : \"" + mode + "\"}");
|
||||
assertEquals(LifecycleManagementStatusResponse.fromXContent(parser).getOperationMode(), OperationMode.fromString(mode));
|
||||
}
|
||||
|
||||
public void testXContentInvalid() throws IOException {
|
||||
XContentType xContentType = XContentType.JSON;
|
||||
String mode = randomAlphaOfLength(10);
|
||||
XContentParser parser = xContentType.xContent().createParser(NamedXContentRegistry.EMPTY,
|
||||
DeprecationHandler.THROW_UNSUPPORTED_OPERATION, "{\"operation_mode\" : \"" + mode + "\"}");
|
||||
Exception e = expectThrows(IllegalArgumentException.class, () -> LifecycleManagementStatusResponse.fromXContent(parser));
|
||||
assertThat(e.getMessage(), CoreMatchers.containsString("failed to parse field [operation_mode]"));
|
||||
}
|
||||
}
|
@ -1,91 +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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.cluster.ClusterModule;
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.test.AbstractXContentTestCase;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import static org.elasticsearch.client.indexlifecycle.LifecyclePolicyTests.createRandomPolicy;
|
||||
|
||||
public class LifecyclePolicyMetadataTests extends AbstractXContentTestCase<LifecyclePolicyMetadata> {
|
||||
|
||||
private String policyName;
|
||||
|
||||
@Override
|
||||
protected LifecyclePolicyMetadata createTestInstance() {
|
||||
policyName = randomAlphaOfLengthBetween(5,20);
|
||||
LifecyclePolicy policy = createRandomPolicy(policyName);
|
||||
return new LifecyclePolicyMetadata(policy, randomLong(), randomLong());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected LifecyclePolicyMetadata doParseInstance(XContentParser parser) throws IOException {
|
||||
return LifecyclePolicyMetadata.parse(parser, policyName);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean supportsUnknownFields() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Predicate<String> getRandomFieldsExcludeFilter() {
|
||||
return (field) ->
|
||||
// phases is a list of Phase parsable entries only
|
||||
field.endsWith(".phases")
|
||||
// these are all meant to be maps of strings, so complex objects will confuse the parser
|
||||
|| field.endsWith(".include")
|
||||
|| field.endsWith(".exclude")
|
||||
|| field.endsWith(".require")
|
||||
// actions are meant to be a list of LifecycleAction parsable entries only
|
||||
|| field.endsWith(".actions");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NamedXContentRegistry xContentRegistry() {
|
||||
List<NamedXContentRegistry.Entry> entries = new ArrayList<>(ClusterModule.getNamedXWriteables());
|
||||
entries.addAll(Arrays.asList(
|
||||
new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(AllocateAction.NAME), AllocateAction::parse),
|
||||
new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(DeleteAction.NAME), DeleteAction::parse),
|
||||
new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(ForceMergeAction.NAME), ForceMergeAction::parse),
|
||||
new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(ReadOnlyAction.NAME), ReadOnlyAction::parse),
|
||||
new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(RolloverAction.NAME), RolloverAction::parse),
|
||||
new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(ShrinkAction.NAME), ShrinkAction::parse),
|
||||
new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(WaitForSnapshotAction.NAME),
|
||||
WaitForSnapshotAction::parse),
|
||||
new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(FreezeAction.NAME), FreezeAction::parse),
|
||||
new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(SetPriorityAction.NAME), SetPriorityAction::parse),
|
||||
new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(SearchableSnapshotAction.NAME),
|
||||
SearchableSnapshotAction::parse),
|
||||
new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(UnfollowAction.NAME), UnfollowAction::parse)
|
||||
));
|
||||
return new NamedXContentRegistry(entries);
|
||||
}
|
||||
}
|
@ -1,278 +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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.cluster.ClusterModule;
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.common.util.set.Sets;
|
||||
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.test.AbstractXContentTestCase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
public class LifecyclePolicyTests extends AbstractXContentTestCase<LifecyclePolicy> {
|
||||
private static final Set<String> VALID_HOT_ACTIONS = Sets.newHashSet(UnfollowAction.NAME, SetPriorityAction.NAME, RolloverAction.NAME);
|
||||
private static final Set<String> VALID_WARM_ACTIONS = Sets.newHashSet(UnfollowAction.NAME, SetPriorityAction.NAME, AllocateAction.NAME,
|
||||
ForceMergeAction.NAME, ReadOnlyAction.NAME, ShrinkAction.NAME);
|
||||
private static final Set<String> VALID_COLD_ACTIONS = Sets.newHashSet(UnfollowAction.NAME, SetPriorityAction.NAME, AllocateAction.NAME,
|
||||
FreezeAction.NAME, SearchableSnapshotAction.NAME);
|
||||
private static final Set<String> VALID_DELETE_ACTIONS = Sets.newHashSet(DeleteAction.NAME, WaitForSnapshotAction.NAME);
|
||||
|
||||
private String lifecycleName;
|
||||
|
||||
@Override
|
||||
protected LifecyclePolicy doParseInstance(XContentParser parser) {
|
||||
return LifecyclePolicy.parse(parser, lifecycleName);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean supportsUnknownFields() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Predicate<String> getRandomFieldsExcludeFilter() {
|
||||
// these items all have some specific parsing that does not allow them to have additional objects within them.
|
||||
return (field) -> field.contains("allocate.") || field.equals("phases") || field.endsWith("actions");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NamedXContentRegistry xContentRegistry() {
|
||||
List<NamedXContentRegistry.Entry> entries = new ArrayList<>(ClusterModule.getNamedXWriteables());
|
||||
entries.addAll(Arrays.asList(
|
||||
new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(AllocateAction.NAME), AllocateAction::parse),
|
||||
new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(DeleteAction.NAME), DeleteAction::parse),
|
||||
new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(ForceMergeAction.NAME), ForceMergeAction::parse),
|
||||
new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(ReadOnlyAction.NAME), ReadOnlyAction::parse),
|
||||
new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(RolloverAction.NAME), RolloverAction::parse),
|
||||
new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(ShrinkAction.NAME), ShrinkAction::parse),
|
||||
new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(WaitForSnapshotAction.NAME),
|
||||
WaitForSnapshotAction::parse),
|
||||
new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(FreezeAction.NAME), FreezeAction::parse),
|
||||
new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(SetPriorityAction.NAME), SetPriorityAction::parse),
|
||||
new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(SearchableSnapshotAction.NAME),
|
||||
SearchableSnapshotAction::parse),
|
||||
new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(UnfollowAction.NAME), UnfollowAction::parse)
|
||||
));
|
||||
return new NamedXContentRegistry(entries);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected LifecyclePolicy createTestInstance() {
|
||||
lifecycleName = randomAlphaOfLength(5);
|
||||
return createRandomPolicy(lifecycleName);
|
||||
}
|
||||
|
||||
public void testValidatePhases() {
|
||||
boolean invalid = randomBoolean();
|
||||
String phaseName = randomFrom("hot", "warm", "cold", "delete");
|
||||
if (invalid) {
|
||||
phaseName += randomAlphaOfLength(5);
|
||||
}
|
||||
Map<String, Phase> phases = Collections.singletonMap(phaseName,
|
||||
new Phase(phaseName, TimeValue.ZERO, Collections.emptyMap()));
|
||||
if (invalid) {
|
||||
Exception e = expectThrows(IllegalArgumentException.class, () -> new LifecyclePolicy(lifecycleName, phases));
|
||||
assertThat(e.getMessage(), equalTo("Lifecycle does not support phase [" + phaseName + "]"));
|
||||
} else {
|
||||
new LifecyclePolicy(lifecycleName, phases);
|
||||
}
|
||||
}
|
||||
|
||||
public void testValidateHotPhase() {
|
||||
LifecycleAction invalidAction = null;
|
||||
Map<String, LifecycleAction> actions = randomSubsetOf(VALID_HOT_ACTIONS)
|
||||
.stream().map(this::getTestAction).collect(Collectors.toMap(LifecycleAction::getName, Function.identity()));
|
||||
if (randomBoolean()) {
|
||||
invalidAction = getTestAction(randomFrom("allocate", "forcemerge", "delete", "shrink"));
|
||||
actions.put(invalidAction.getName(), invalidAction);
|
||||
}
|
||||
Map<String, Phase> hotPhase = Collections.singletonMap("hot",
|
||||
new Phase("hot", TimeValue.ZERO, actions));
|
||||
|
||||
if (invalidAction != null) {
|
||||
Exception e = expectThrows(IllegalArgumentException.class,
|
||||
() -> new LifecyclePolicy(lifecycleName, hotPhase));
|
||||
assertThat(e.getMessage(),
|
||||
equalTo("invalid action [" + invalidAction.getName() + "] defined in phase [hot]"));
|
||||
} else {
|
||||
new LifecyclePolicy(lifecycleName, hotPhase);
|
||||
}
|
||||
}
|
||||
|
||||
public void testValidateWarmPhase() {
|
||||
LifecycleAction invalidAction = null;
|
||||
Map<String, LifecycleAction> actions = randomSubsetOf(VALID_WARM_ACTIONS)
|
||||
.stream().map(this::getTestAction).collect(Collectors.toMap(LifecycleAction::getName, Function.identity()));
|
||||
if (randomBoolean()) {
|
||||
invalidAction = getTestAction(randomFrom("rollover", "delete"));
|
||||
actions.put(invalidAction.getName(), invalidAction);
|
||||
}
|
||||
Map<String, Phase> warmPhase = Collections.singletonMap("warm",
|
||||
new Phase("warm", TimeValue.ZERO, actions));
|
||||
|
||||
if (invalidAction != null) {
|
||||
Exception e = expectThrows(IllegalArgumentException.class,
|
||||
() -> new LifecyclePolicy(lifecycleName, warmPhase));
|
||||
assertThat(e.getMessage(),
|
||||
equalTo("invalid action [" + invalidAction.getName() + "] defined in phase [warm]"));
|
||||
} else {
|
||||
new LifecyclePolicy(lifecycleName, warmPhase);
|
||||
}
|
||||
}
|
||||
|
||||
public void testValidateColdPhase() {
|
||||
LifecycleAction invalidAction = null;
|
||||
Map<String, LifecycleAction> actions = randomSubsetOf(VALID_COLD_ACTIONS)
|
||||
.stream().map(this::getTestAction).collect(Collectors.toMap(LifecycleAction::getName, Function.identity()));
|
||||
if (randomBoolean()) {
|
||||
invalidAction = getTestAction(randomFrom("rollover", "delete", "forcemerge", "shrink"));
|
||||
actions.put(invalidAction.getName(), invalidAction);
|
||||
}
|
||||
Map<String, Phase> coldPhase = Collections.singletonMap("cold",
|
||||
new Phase("cold", TimeValue.ZERO, actions));
|
||||
|
||||
if (invalidAction != null) {
|
||||
Exception e = expectThrows(IllegalArgumentException.class,
|
||||
() -> new LifecyclePolicy(lifecycleName, coldPhase));
|
||||
assertThat(e.getMessage(),
|
||||
equalTo("invalid action [" + invalidAction.getName() + "] defined in phase [cold]"));
|
||||
} else {
|
||||
new LifecyclePolicy(lifecycleName, coldPhase);
|
||||
}
|
||||
}
|
||||
|
||||
public void testValidateDeletePhase() {
|
||||
LifecycleAction invalidAction = null;
|
||||
Map<String, LifecycleAction> actions = VALID_DELETE_ACTIONS
|
||||
.stream().map(this::getTestAction).collect(Collectors.toMap(LifecycleAction::getName, Function.identity()));
|
||||
if (randomBoolean()) {
|
||||
invalidAction = getTestAction(randomFrom("allocate", "rollover", "forcemerge", "shrink"));
|
||||
actions.put(invalidAction.getName(), invalidAction);
|
||||
}
|
||||
Map<String, Phase> deletePhase = Collections.singletonMap("delete",
|
||||
new Phase("delete", TimeValue.ZERO, actions));
|
||||
|
||||
if (invalidAction != null) {
|
||||
Exception e = expectThrows(IllegalArgumentException.class,
|
||||
() -> new LifecyclePolicy(lifecycleName, deletePhase));
|
||||
assertThat(e.getMessage(),
|
||||
equalTo("invalid action [" + invalidAction.getName() + "] defined in phase [delete]"));
|
||||
} else {
|
||||
new LifecyclePolicy(lifecycleName, deletePhase);
|
||||
}
|
||||
}
|
||||
|
||||
public static LifecyclePolicy createRandomPolicy(String lifecycleName) {
|
||||
List<String> phaseNames = randomSubsetOf(Arrays.asList("hot", "warm", "cold", "delete"));
|
||||
Map<String, Phase> phases = new HashMap<>(phaseNames.size());
|
||||
Function<String, Set<String>> validActions = (phase) -> {
|
||||
switch (phase) {
|
||||
case "hot":
|
||||
return VALID_HOT_ACTIONS;
|
||||
case "warm":
|
||||
return VALID_WARM_ACTIONS;
|
||||
case "cold":
|
||||
return VALID_COLD_ACTIONS;
|
||||
case "delete":
|
||||
return VALID_DELETE_ACTIONS;
|
||||
default:
|
||||
throw new IllegalArgumentException("invalid phase [" + phase + "]");
|
||||
}};
|
||||
Function<String, LifecycleAction> randomAction = (action) -> {
|
||||
switch (action) {
|
||||
case AllocateAction.NAME:
|
||||
return AllocateActionTests.randomInstance();
|
||||
case DeleteAction.NAME:
|
||||
return new DeleteAction();
|
||||
case ForceMergeAction.NAME:
|
||||
return ForceMergeActionTests.randomInstance();
|
||||
case ReadOnlyAction.NAME:
|
||||
return new ReadOnlyAction();
|
||||
case RolloverAction.NAME:
|
||||
return RolloverActionTests.randomInstance();
|
||||
case ShrinkAction.NAME:
|
||||
return ShrinkActionTests.randomInstance();
|
||||
case FreezeAction.NAME:
|
||||
return new FreezeAction();
|
||||
case WaitForSnapshotAction.NAME:
|
||||
return WaitForSnapshotActionTests.randomInstance();
|
||||
case SetPriorityAction.NAME:
|
||||
return SetPriorityActionTests.randomInstance();
|
||||
case UnfollowAction.NAME:
|
||||
return new UnfollowAction();
|
||||
case SearchableSnapshotAction.NAME:
|
||||
return SearchableSnapshotActionTests.randomInstance();
|
||||
default:
|
||||
throw new IllegalArgumentException("invalid action [" + action + "]");
|
||||
}};
|
||||
for (String phase : phaseNames) {
|
||||
TimeValue after = TimeValue.parseTimeValue(randomTimeValue(0, 1000000000, "s", "m", "h", "d"), "test_after");
|
||||
Map<String, LifecycleAction> actions = new HashMap<>();
|
||||
List<String> actionNames = randomSubsetOf(validActions.apply(phase));
|
||||
for (String action : actionNames) {
|
||||
actions.put(action, randomAction.apply(action));
|
||||
}
|
||||
phases.put(phase, new Phase(phase, after, actions));
|
||||
}
|
||||
return new LifecyclePolicy(lifecycleName, phases);
|
||||
}
|
||||
|
||||
private LifecycleAction getTestAction(String actionName) {
|
||||
switch (actionName) {
|
||||
case AllocateAction.NAME:
|
||||
return AllocateActionTests.randomInstance();
|
||||
case DeleteAction.NAME:
|
||||
return new DeleteAction();
|
||||
case ForceMergeAction.NAME:
|
||||
return ForceMergeActionTests.randomInstance();
|
||||
case ReadOnlyAction.NAME:
|
||||
return new ReadOnlyAction();
|
||||
case RolloverAction.NAME:
|
||||
return RolloverActionTests.randomInstance();
|
||||
case ShrinkAction.NAME:
|
||||
return ShrinkActionTests.randomInstance();
|
||||
case FreezeAction.NAME:
|
||||
return new FreezeAction();
|
||||
case WaitForSnapshotAction.NAME:
|
||||
return WaitForSnapshotActionTests.randomInstance();
|
||||
case SetPriorityAction.NAME:
|
||||
return SetPriorityActionTests.randomInstance();
|
||||
case SearchableSnapshotAction.NAME:
|
||||
return SearchableSnapshotActionTests.randomInstance();
|
||||
case UnfollowAction.NAME:
|
||||
return new UnfollowAction();
|
||||
default:
|
||||
throw new IllegalArgumentException("unsupported phase action [" + actionName + "]");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,46 +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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.test.AbstractXContentTestCase;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class MigrateActionTests extends AbstractXContentTestCase<MigrateAction> {
|
||||
|
||||
@Override
|
||||
protected MigrateAction doParseInstance(XContentParser parser) throws IOException {
|
||||
return MigrateAction.parse(parser);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MigrateAction createTestInstance() {
|
||||
return randomInstance();
|
||||
}
|
||||
|
||||
static MigrateAction randomInstance() {
|
||||
return new MigrateAction(randomBoolean());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean supportsUnknownFields() {
|
||||
return false;
|
||||
}
|
||||
}
|
@ -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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.hamcrest.CoreMatchers;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
public class OperationModeTests extends ESTestCase {
|
||||
|
||||
public void testIsValidChange() {
|
||||
assertFalse(OperationMode.RUNNING.isValidChange(OperationMode.RUNNING));
|
||||
assertTrue(OperationMode.RUNNING.isValidChange(OperationMode.STOPPING));
|
||||
assertFalse(OperationMode.RUNNING.isValidChange(OperationMode.STOPPED));
|
||||
|
||||
assertTrue(OperationMode.STOPPING.isValidChange(OperationMode.RUNNING));
|
||||
assertFalse(OperationMode.STOPPING.isValidChange(OperationMode.STOPPING));
|
||||
assertTrue(OperationMode.STOPPING.isValidChange(OperationMode.STOPPED));
|
||||
|
||||
assertTrue(OperationMode.STOPPED.isValidChange(OperationMode.RUNNING));
|
||||
assertFalse(OperationMode.STOPPED.isValidChange(OperationMode.STOPPING));
|
||||
assertFalse(OperationMode.STOPPED.isValidChange(OperationMode.STOPPED));
|
||||
}
|
||||
|
||||
public void testFromName() {
|
||||
EnumSet.allOf(OperationMode.class).forEach(e -> assertEquals(OperationMode.fromString(e.name()), e));
|
||||
}
|
||||
|
||||
public void testFromNameInvalid() {
|
||||
String invalidName = randomAlphaOfLength(10);
|
||||
Exception e = expectThrows(IllegalArgumentException.class, () -> OperationMode.fromString(invalidName));
|
||||
assertThat(e.getMessage(), CoreMatchers.containsString(invalidName + " is not a valid operation_mode"));
|
||||
}
|
||||
}
|
@ -1,74 +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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.cluster.ClusterModule;
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.test.AbstractXContentTestCase;
|
||||
import org.junit.Before;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class PhaseExecutionInfoTests extends AbstractXContentTestCase<PhaseExecutionInfo> {
|
||||
|
||||
static PhaseExecutionInfo randomPhaseExecutionInfo(String phaseName) {
|
||||
return new PhaseExecutionInfo(randomAlphaOfLength(5), PhaseTests.randomPhase(phaseName),
|
||||
randomNonNegativeLong(), randomNonNegativeLong());
|
||||
}
|
||||
|
||||
String phaseName;
|
||||
|
||||
@Before
|
||||
public void setupPhaseName() {
|
||||
phaseName = randomAlphaOfLength(7);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PhaseExecutionInfo createTestInstance() {
|
||||
return randomPhaseExecutionInfo(phaseName);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PhaseExecutionInfo doParseInstance(XContentParser parser) throws IOException {
|
||||
return PhaseExecutionInfo.parse(parser, phaseName);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Predicate<String> getRandomFieldsExcludeFilter() {
|
||||
// actions are plucked from the named registry, and it fails if the action is not in the named registry
|
||||
return (field) -> field.equals("phase_definition.actions");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean supportsUnknownFields() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NamedXContentRegistry xContentRegistry() {
|
||||
List<NamedXContentRegistry.Entry> entries = new ArrayList<>(ClusterModule.getNamedXWriteables());
|
||||
entries.add(new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(DeleteAction.NAME), DeleteAction::parse));
|
||||
return new NamedXContentRegistry(entries);
|
||||
}
|
||||
}
|
@ -1,87 +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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.cluster.ClusterModule;
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.test.AbstractXContentTestCase;
|
||||
import org.junit.Before;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class PhaseTests extends AbstractXContentTestCase<Phase> {
|
||||
private String phaseName;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
phaseName = randomAlphaOfLength(20);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Phase createTestInstance() {
|
||||
return randomPhase(phaseName);
|
||||
}
|
||||
|
||||
static Phase randomPhase(String phaseName) {
|
||||
TimeValue after = null;
|
||||
if (randomBoolean()) {
|
||||
after = TimeValue.parseTimeValue(randomTimeValue(0, 1000000000, "s", "m", "h", "d"), "test_after");
|
||||
}
|
||||
Map<String, LifecycleAction> actions = Collections.emptyMap();
|
||||
if (randomBoolean()) {
|
||||
actions = Collections.singletonMap(DeleteAction.NAME, new DeleteAction());
|
||||
}
|
||||
return new Phase(phaseName, after, actions);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Phase doParseInstance(XContentParser parser) {
|
||||
return Phase.parse(parser, phaseName);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Predicate<String> getRandomFieldsExcludeFilter() {
|
||||
// actions are plucked from the named registry, and it fails if the action is not in the named registry
|
||||
return (field) -> field.equals("actions");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NamedXContentRegistry xContentRegistry() {
|
||||
List<NamedXContentRegistry.Entry> entries = new ArrayList<>(ClusterModule.getNamedXWriteables());
|
||||
entries.add(new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(DeleteAction.NAME), DeleteAction::parse));
|
||||
return new NamedXContentRegistry(entries);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean supportsUnknownFields() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void testDefaultAfter() {
|
||||
Phase phase = new Phase(randomAlphaOfLength(20), null, Collections.emptyMap());
|
||||
assertEquals(TimeValue.ZERO, phase.getMinimumAge());
|
||||
}
|
||||
}
|
@ -1,45 +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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
||||
import static org.elasticsearch.client.indexlifecycle.LifecyclePolicyTests.createRandomPolicy;
|
||||
|
||||
public class PutLifecyclePolicyRequestTests extends ESTestCase {
|
||||
|
||||
private PutLifecyclePolicyRequest createTestInstance() {
|
||||
return new PutLifecyclePolicyRequest(createRandomPolicy(randomAlphaOfLengthBetween(5, 20)));
|
||||
}
|
||||
|
||||
public void testValidation() {
|
||||
PutLifecyclePolicyRequest req = createTestInstance();
|
||||
assertFalse(req.validate().isPresent());
|
||||
}
|
||||
|
||||
public void testNullPolicy() {
|
||||
expectThrows(IllegalArgumentException.class, () -> new PutLifecyclePolicyRequest(null));
|
||||
}
|
||||
|
||||
public void testNullPolicyName() {
|
||||
expectThrows(IllegalArgumentException.class, () -> new PutLifecyclePolicyRequest(createRandomPolicy(randomFrom("", null))));
|
||||
}
|
||||
|
||||
}
|
@ -1,40 +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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.test.AbstractXContentTestCase;
|
||||
|
||||
public class ReadOnlyActionTests extends AbstractXContentTestCase<ReadOnlyAction> {
|
||||
|
||||
@Override
|
||||
protected ReadOnlyAction doParseInstance(XContentParser parser) {
|
||||
return ReadOnlyAction.parse(parser);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean supportsUnknownFields() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReadOnlyAction createTestInstance() {
|
||||
return new ReadOnlyAction();
|
||||
}
|
||||
}
|
@ -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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.action.support.IndicesOptions;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.test.EqualsHashCodeTestUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
public class RemoveIndexLifecyclePolicyRequestTests extends ESTestCase {
|
||||
|
||||
public void testNullIndices() {
|
||||
expectThrows(NullPointerException.class, () -> new RemoveIndexLifecyclePolicyRequest(null));
|
||||
}
|
||||
|
||||
public void testNullIndicesOptions() {
|
||||
expectThrows(NullPointerException.class, () -> new RemoveIndexLifecyclePolicyRequest(Collections.emptyList(), null));
|
||||
}
|
||||
|
||||
public void testValidate() {
|
||||
RemoveIndexLifecyclePolicyRequest request = new RemoveIndexLifecyclePolicyRequest(Collections.emptyList());
|
||||
assertFalse(request.validate().isPresent());
|
||||
}
|
||||
|
||||
protected RemoveIndexLifecyclePolicyRequest createInstance() {
|
||||
if (randomBoolean()) {
|
||||
return new RemoveIndexLifecyclePolicyRequest(Arrays.asList(generateRandomStringArray(20, 20, false)),
|
||||
IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), randomBoolean(),
|
||||
randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean()));
|
||||
} else {
|
||||
return new RemoveIndexLifecyclePolicyRequest(Arrays.asList(generateRandomStringArray(20, 20, false)));
|
||||
}
|
||||
}
|
||||
|
||||
private RemoveIndexLifecyclePolicyRequest copyInstance(RemoveIndexLifecyclePolicyRequest req) {
|
||||
return new RemoveIndexLifecyclePolicyRequest(new ArrayList<>(req.indices()), IndicesOptions.fromOptions(
|
||||
req.indicesOptions().ignoreUnavailable(), req.indicesOptions().allowNoIndices(),
|
||||
req.indicesOptions().expandWildcardsOpen(), req.indicesOptions().expandWildcardsClosed(),
|
||||
req.indicesOptions().allowAliasesToMultipleIndices(), req.indicesOptions().forbidClosedIndices(),
|
||||
req.indicesOptions().ignoreAliases(), req.indicesOptions().ignoreThrottled()));
|
||||
}
|
||||
|
||||
private RemoveIndexLifecyclePolicyRequest mutateInstance(RemoveIndexLifecyclePolicyRequest req) {
|
||||
if (randomBoolean()) {
|
||||
return new RemoveIndexLifecyclePolicyRequest(req.indices(),
|
||||
randomValueOtherThan(req.indicesOptions(), () -> IndicesOptions.fromOptions(randomBoolean(), randomBoolean(),
|
||||
randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean())));
|
||||
} else {
|
||||
return new RemoveIndexLifecyclePolicyRequest(
|
||||
randomValueOtherThan(req.indices(), () -> Arrays.asList(generateRandomStringArray(20, 20, false))),
|
||||
req.indicesOptions());
|
||||
}
|
||||
}
|
||||
|
||||
public void testEqualsAndHashCode() {
|
||||
for (int count = 0; count < 100; ++count) {
|
||||
EqualsHashCodeTestUtils.checkEqualsAndHashCode(createInstance(), this::copyInstance, this::mutateInstance);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,93 +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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.test.EqualsHashCodeTestUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.elasticsearch.test.AbstractXContentTestCase.xContentTester;
|
||||
|
||||
public class RemoveIndexLifecyclePolicyResponseTests extends ESTestCase {
|
||||
|
||||
private void toXContent(RemoveIndexLifecyclePolicyResponse response, XContentBuilder builder) throws IOException {
|
||||
builder.startObject();
|
||||
builder.field(RemoveIndexLifecyclePolicyResponse.HAS_FAILURES_FIELD.getPreferredName(), response.hasFailures());
|
||||
builder.field(RemoveIndexLifecyclePolicyResponse.FAILED_INDEXES_FIELD.getPreferredName(), response.getFailedIndexes());
|
||||
builder.endObject();
|
||||
}
|
||||
|
||||
private RemoveIndexLifecyclePolicyResponse createInstance() {
|
||||
List<String> failedIndexes = Arrays.asList(generateRandomStringArray(20, 20, false));
|
||||
return new RemoveIndexLifecyclePolicyResponse(failedIndexes);
|
||||
}
|
||||
|
||||
private RemoveIndexLifecyclePolicyResponse copyInstance(RemoveIndexLifecyclePolicyResponse req) {
|
||||
return new RemoveIndexLifecyclePolicyResponse(new ArrayList<>(req.getFailedIndexes()));
|
||||
}
|
||||
|
||||
private RemoveIndexLifecyclePolicyResponse mutateInstance(RemoveIndexLifecyclePolicyResponse req) {
|
||||
return new RemoveIndexLifecyclePolicyResponse(randomValueOtherThan(req.getFailedIndexes(),
|
||||
() -> Arrays.asList(generateRandomStringArray(20, 20, false))));
|
||||
}
|
||||
|
||||
public void testFromXContent() throws IOException {
|
||||
xContentTester(
|
||||
this::createParser,
|
||||
this::createInstance,
|
||||
this::toXContent,
|
||||
RemoveIndexLifecyclePolicyResponse::fromXContent)
|
||||
.supportsUnknownFields(true)
|
||||
.test();
|
||||
}
|
||||
|
||||
public void testNullFailedIndices() {
|
||||
IllegalArgumentException exception =
|
||||
expectThrows(IllegalArgumentException.class, () -> new RemoveIndexLifecyclePolicyResponse(null));
|
||||
assertEquals("failed_indexes cannot be null", exception.getMessage());
|
||||
}
|
||||
|
||||
public void testHasFailures() {
|
||||
RemoveIndexLifecyclePolicyResponse response = new RemoveIndexLifecyclePolicyResponse(new ArrayList<>());
|
||||
assertFalse(response.hasFailures());
|
||||
assertEquals(Collections.emptyList(), response.getFailedIndexes());
|
||||
|
||||
int size = randomIntBetween(1, 10);
|
||||
List<String> failedIndexes = new ArrayList<>(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
failedIndexes.add(randomAlphaOfLength(20));
|
||||
}
|
||||
response = new RemoveIndexLifecyclePolicyResponse(failedIndexes);
|
||||
assertTrue(response.hasFailures());
|
||||
assertEquals(failedIndexes, response.getFailedIndexes());
|
||||
}
|
||||
|
||||
public void testEqualsAndHashCode() {
|
||||
for (int count = 0; count < 100; ++count) {
|
||||
EqualsHashCodeTestUtils.checkEqualsAndHashCode(createInstance(), this::copyInstance, this::mutateInstance);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,59 +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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.common.unit.ByteSizeUnit;
|
||||
import org.elasticsearch.common.unit.ByteSizeValue;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.test.AbstractXContentTestCase;
|
||||
|
||||
public class RolloverActionTests extends AbstractXContentTestCase<RolloverAction> {
|
||||
|
||||
@Override
|
||||
protected RolloverAction doParseInstance(XContentParser parser) {
|
||||
return RolloverAction.parse(parser);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean supportsUnknownFields() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RolloverAction createTestInstance() {
|
||||
return randomInstance();
|
||||
}
|
||||
|
||||
static RolloverAction randomInstance() {
|
||||
ByteSizeUnit maxSizeUnit = randomFrom(ByteSizeUnit.values());
|
||||
ByteSizeValue maxSize = randomBoolean() ? null : new ByteSizeValue(randomNonNegativeLong() / maxSizeUnit.toBytes(1), maxSizeUnit);
|
||||
Long maxDocs = randomBoolean() ? null : randomNonNegativeLong();
|
||||
TimeValue maxAge = (maxDocs == null && maxSize == null || randomBoolean())
|
||||
? TimeValue.parseTimeValue(randomPositiveTimeValue(), "rollover_action_test")
|
||||
: null;
|
||||
return new RolloverAction(maxSize, maxAge, maxDocs);
|
||||
}
|
||||
|
||||
public void testNoConditions() {
|
||||
IllegalArgumentException exception = expectThrows(IllegalArgumentException.class,
|
||||
() -> new RolloverAction(null, null, null));
|
||||
assertEquals("At least one rollover condition must be set.", exception.getMessage());
|
||||
}
|
||||
}
|
@ -1,59 +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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.test.AbstractXContentTestCase;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
public class SearchableSnapshotActionTests extends AbstractXContentTestCase<SearchableSnapshotAction> {
|
||||
|
||||
@Override
|
||||
protected SearchableSnapshotAction doParseInstance(XContentParser parser) throws IOException {
|
||||
return SearchableSnapshotAction.parse(parser);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SearchableSnapshotAction createTestInstance() {
|
||||
return randomInstance();
|
||||
}
|
||||
|
||||
static SearchableSnapshotAction randomInstance() {
|
||||
return new SearchableSnapshotAction(randomAlphaOfLengthBetween(5, 10), randomBoolean());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean supportsUnknownFields() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void testEmptyOrNullRepository() {
|
||||
{
|
||||
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> new SearchableSnapshotAction(""));
|
||||
assertThat(e.getMessage(), equalTo("the snapshot repository must be specified"));
|
||||
}
|
||||
{
|
||||
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> new SearchableSnapshotAction(null));
|
||||
assertThat(e.getMessage(), equalTo("the snapshot repository must be specified"));
|
||||
}
|
||||
}
|
||||
}
|
@ -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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.test.AbstractXContentTestCase;
|
||||
import org.elasticsearch.test.EqualsHashCodeTestUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
public class SetPriorityActionTests extends AbstractXContentTestCase<SetPriorityAction> {
|
||||
|
||||
@Override
|
||||
protected SetPriorityAction doParseInstance(XContentParser parser) throws IOException {
|
||||
return SetPriorityAction.parse(parser);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SetPriorityAction createTestInstance() {
|
||||
return randomInstance();
|
||||
}
|
||||
|
||||
static SetPriorityAction randomInstance() {
|
||||
return new SetPriorityAction(randomIntBetween(1, 100));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean supportsUnknownFields() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void testNonPositivePriority() {
|
||||
Exception e = expectThrows(Exception.class, () -> new SetPriorityAction(randomIntBetween(-100, -1)));
|
||||
assertThat(e.getMessage(), equalTo("[priority] must be 0 or greater"));
|
||||
}
|
||||
|
||||
public void testNullPriorityAllowed(){
|
||||
SetPriorityAction nullPriority = new SetPriorityAction(null);
|
||||
assertNull(nullPriority.recoveryPriority);
|
||||
}
|
||||
|
||||
public void testEqualsAndHashCode() {
|
||||
EqualsHashCodeTestUtils.checkEqualsAndHashCode(createTestInstance(), this::copy);
|
||||
}
|
||||
|
||||
SetPriorityAction copy(SetPriorityAction setPriorityAction) {
|
||||
return new SetPriorityAction(setPriorityAction.recoveryPriority);
|
||||
}
|
||||
|
||||
SetPriorityAction notCopy(SetPriorityAction setPriorityAction) {
|
||||
return new SetPriorityAction(setPriorityAction.recoveryPriority + 1);
|
||||
}
|
||||
}
|
@ -1,53 +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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.test.AbstractXContentTestCase;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
public class ShrinkActionTests extends AbstractXContentTestCase<ShrinkAction> {
|
||||
|
||||
@Override
|
||||
protected ShrinkAction doParseInstance(XContentParser parser) throws IOException {
|
||||
return ShrinkAction.parse(parser);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ShrinkAction createTestInstance() {
|
||||
return randomInstance();
|
||||
}
|
||||
|
||||
static ShrinkAction randomInstance() {
|
||||
return new ShrinkAction(randomIntBetween(1, 100));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean supportsUnknownFields() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void testNonPositiveShardNumber() {
|
||||
Exception e = expectThrows(Exception.class, () -> new ShrinkAction(randomIntBetween(-100, 0)));
|
||||
assertThat(e.getMessage(), equalTo("[number_of_shards] must be greater than 0"));
|
||||
}
|
||||
}
|
@ -1,40 +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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.test.EqualsHashCodeTestUtils;
|
||||
|
||||
public class StartILMRequestTests extends ESTestCase {
|
||||
|
||||
protected StartILMRequest createTestInstance() {
|
||||
return new StartILMRequest();
|
||||
}
|
||||
|
||||
public void testValidate() {
|
||||
StartILMRequest request = createTestInstance();
|
||||
assertFalse(request.validate().isPresent());
|
||||
}
|
||||
|
||||
public void testEqualsAndHashcode() {
|
||||
EqualsHashCodeTestUtils.checkEqualsAndHashCode(createTestInstance(), (original) -> createTestInstance());
|
||||
}
|
||||
|
||||
}
|
@ -1,40 +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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.test.EqualsHashCodeTestUtils;
|
||||
|
||||
public class StopILMRequestTests extends ESTestCase {
|
||||
|
||||
protected StopILMRequest createTestInstance() {
|
||||
return new StopILMRequest();
|
||||
}
|
||||
|
||||
public void testValidate() {
|
||||
StopILMRequest request = createTestInstance();
|
||||
assertFalse(request.validate().isPresent());
|
||||
}
|
||||
|
||||
public void testEqualsAndHashcode() {
|
||||
EqualsHashCodeTestUtils.checkEqualsAndHashCode(createTestInstance(), (original) -> createTestInstance());
|
||||
}
|
||||
|
||||
}
|
@ -1,43 +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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.test.AbstractXContentTestCase;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class UnfollowActionTests extends AbstractXContentTestCase<UnfollowAction> {
|
||||
|
||||
@Override
|
||||
protected UnfollowAction createTestInstance() {
|
||||
return new UnfollowAction();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected UnfollowAction doParseInstance(XContentParser parser) throws IOException {
|
||||
return UnfollowAction.parse(parser);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean supportsUnknownFields() {
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,58 +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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.test.AbstractXContentTestCase;
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
public class WaitForSnapshotActionTests extends AbstractXContentTestCase<WaitForSnapshotAction> {
|
||||
|
||||
@Override
|
||||
protected WaitForSnapshotAction doParseInstance(XContentParser parser) {
|
||||
return WaitForSnapshotAction.parse(parser);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean supportsUnknownFields() {
|
||||
return true;
|
||||
}
|
||||
|
||||
static WaitForSnapshotAction randomInstance() {
|
||||
return new WaitForSnapshotAction(randomAlphaOfLength(5));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected WaitForSnapshotAction createTestInstance() {
|
||||
return randomInstance();
|
||||
}
|
||||
|
||||
public void testActionWithEmptyOrNullPolicy() {
|
||||
{
|
||||
IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, () -> new WaitForSnapshotAction(""));
|
||||
assertThat(exception.getMessage(), is("policy name must be specified"));
|
||||
}
|
||||
|
||||
{
|
||||
IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, () -> new WaitForSnapshotAction(null));
|
||||
assertThat(exception.getMessage(), is("policy name must be specified"));
|
||||
}
|
||||
}
|
||||
}
|
@ -126,7 +126,6 @@ def projectPathsToExclude = [
|
||||
':x-pack:plugin:deprecation',
|
||||
':x-pack:plugin:frozen-indices',
|
||||
':x-pack:plugin:identity-provider',
|
||||
':x-pack:plugin:ilm',
|
||||
':x-pack:plugin:mapper-constant-keyword',
|
||||
':x-pack:plugin:mapper-flattened',
|
||||
':x-pack:plugin:monitoring',
|
||||
|
@ -39,7 +39,6 @@ import static java.nio.file.StandardOpenOption.CREATE;
|
||||
import static org.elasticsearch.packaging.util.FileMatcher.Fileness.File;
|
||||
import static org.elasticsearch.packaging.util.FileMatcher.file;
|
||||
import static org.elasticsearch.packaging.util.FileMatcher.p600;
|
||||
import static org.elasticsearch.packaging.util.FileUtils.escapePath;
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
|
||||
|
@ -45,7 +45,6 @@ import static org.elasticsearch.packaging.util.FileMatcher.p660;
|
||||
import static org.elasticsearch.packaging.util.FileMatcher.p755;
|
||||
import static org.elasticsearch.packaging.util.FileMatcher.p770;
|
||||
import static org.elasticsearch.packaging.util.FileMatcher.p775;
|
||||
import static org.elasticsearch.packaging.util.FileUtils.getCurrentVersion;
|
||||
import static org.elasticsearch.packaging.util.ServerUtils.makeRequest;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
|
@ -43,7 +43,6 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.InetAddress;
|
||||
import java.net.Socket;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.security.KeyStore;
|
||||
@ -51,7 +50,6 @@ import java.security.cert.CertificateFactory;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
@ -60,7 +58,6 @@ public class ServerUtils {
|
||||
|
||||
private static final Logger logger = LogManager.getLogger(ServerUtils.class);
|
||||
|
||||
|
||||
// generous timeout as nested virtualization can be quite slow ...
|
||||
private static final long waitTime = TimeUnit.MINUTES.toMillis(3);
|
||||
private static final long timeoutLength = TimeUnit.SECONDS.toMillis(30);
|
||||
|
@ -1,228 +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.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
|
||||
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
|
||||
import org.elasticsearch.action.support.master.AcknowledgedResponse;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.health.ClusterHealthStatus;
|
||||
import org.elasticsearch.cluster.routing.RoutingNode;
|
||||
import org.elasticsearch.cluster.routing.RoutingNodes;
|
||||
import org.elasticsearch.common.Priority;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.test.ESIntegTestCase;
|
||||
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
|
||||
import org.elasticsearch.test.ESIntegTestCase.Scope;
|
||||
import org.elasticsearch.test.InternalTestCluster;
|
||||
import org.elasticsearch.transport.TransportService;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
import static org.elasticsearch.client.Requests.clusterHealthRequest;
|
||||
import static org.elasticsearch.client.Requests.createIndexRequest;
|
||||
import static org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_REPLICAS;
|
||||
import static org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_SHARDS;
|
||||
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
|
||||
import static org.elasticsearch.cluster.routing.ShardRoutingState.RELOCATING;
|
||||
import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
||||
import static org.hamcrest.Matchers.anyOf;
|
||||
import static org.hamcrest.Matchers.containsInAnyOrder;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
||||
|
||||
@ClusterScope(scope = Scope.TEST, numDataNodes = 0)
|
||||
public class IndexLifecycleActionIT extends ESIntegTestCase {
|
||||
public void testIndexLifecycleActionsWith11Shards1Backup() throws Exception {
|
||||
Settings settings = Settings.builder()
|
||||
.put(indexSettings())
|
||||
.put(SETTING_NUMBER_OF_SHARDS, 11)
|
||||
.put(SETTING_NUMBER_OF_REPLICAS, 1)
|
||||
.build();
|
||||
|
||||
// start one server
|
||||
logger.info("Starting sever1");
|
||||
final String server_1 = internalCluster().startNode();
|
||||
final String node1 = getLocalNodeId(server_1);
|
||||
|
||||
logger.info("Creating index [test]");
|
||||
CreateIndexResponse createIndexResponse = client().admin().indices().create(
|
||||
createIndexRequest("test").settings(settings)).actionGet();
|
||||
assertAcked(createIndexResponse);
|
||||
|
||||
ClusterState clusterState = client().admin().cluster().prepareState().get().getState();
|
||||
RoutingNode routingNodeEntry1 = clusterState.getRoutingNodes().node(node1);
|
||||
assertThat(routingNodeEntry1.numberOfShardsWithState(STARTED), equalTo(11));
|
||||
|
||||
logger.info("Starting server2");
|
||||
// start another server
|
||||
String server_2 = internalCluster().startNode();
|
||||
|
||||
// first wait for 2 nodes in the cluster
|
||||
logger.info("Waiting for replicas to be assigned");
|
||||
ClusterHealthResponse clusterHealth = client().admin().cluster().prepareHealth()
|
||||
.setWaitForGreenStatus().setWaitForNodes("2").setWaitForNoRelocatingShards(true).setWaitForEvents(Priority.LANGUID).get();
|
||||
logger.info("Done Cluster Health, status {}", clusterHealth.getStatus());
|
||||
assertThat(clusterHealth.isTimedOut(), equalTo(false));
|
||||
assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.GREEN));
|
||||
final String node2 = getLocalNodeId(server_2);
|
||||
|
||||
// explicitly call reroute, so shards will get relocated to the new node (we delay it in ES in case other nodes join)
|
||||
client().admin().cluster().prepareReroute().execute().actionGet();
|
||||
|
||||
clusterHealth = client().admin().cluster().health(
|
||||
clusterHealthRequest().waitForGreenStatus().waitForNodes("2").waitForNoRelocatingShards(true)).actionGet();
|
||||
assertThat(clusterHealth.isTimedOut(), equalTo(false));
|
||||
assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.GREEN));
|
||||
assertThat(clusterHealth.getNumberOfDataNodes(), equalTo(2));
|
||||
assertThat(clusterHealth.getInitializingShards(), equalTo(0));
|
||||
assertThat(clusterHealth.getUnassignedShards(), equalTo(0));
|
||||
assertThat(clusterHealth.getRelocatingShards(), equalTo(0));
|
||||
assertThat(clusterHealth.getActiveShards(), equalTo(22));
|
||||
assertThat(clusterHealth.getActivePrimaryShards(), equalTo(11));
|
||||
|
||||
|
||||
clusterState = client().admin().cluster().prepareState().get().getState();
|
||||
assertNodesPresent(clusterState.getRoutingNodes(), node1, node2);
|
||||
routingNodeEntry1 = clusterState.getRoutingNodes().node(node1);
|
||||
assertThat(routingNodeEntry1.numberOfShardsWithState(RELOCATING), equalTo(0));
|
||||
assertThat(routingNodeEntry1.numberOfShardsWithState(STARTED), equalTo(11));
|
||||
RoutingNode routingNodeEntry2 = clusterState.getRoutingNodes().node(node2);
|
||||
assertThat(routingNodeEntry2.numberOfShardsWithState(INITIALIZING), equalTo(0));
|
||||
assertThat(routingNodeEntry2.numberOfShardsWithState(STARTED), equalTo(11));
|
||||
|
||||
logger.info("Starting server3");
|
||||
// start another server
|
||||
String server_3 = internalCluster().startNode();
|
||||
|
||||
// first wait for 3 nodes in the cluster
|
||||
logger.info("Waiting for replicas to be assigned");
|
||||
clusterHealth = client().admin().cluster().prepareHealth()
|
||||
.setWaitForGreenStatus().setWaitForNodes("3").setWaitForNoRelocatingShards(true).setWaitForEvents(Priority.LANGUID).get();
|
||||
assertThat(clusterHealth.isTimedOut(), equalTo(false));
|
||||
assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.GREEN));
|
||||
|
||||
|
||||
final String node3 = getLocalNodeId(server_3);
|
||||
|
||||
|
||||
// explicitly call reroute, so shards will get relocated to the new node (we delay it in ES in case other nodes join)
|
||||
client().admin().cluster().prepareReroute().execute().actionGet();
|
||||
|
||||
clusterHealth = client().admin().cluster().prepareHealth()
|
||||
.setWaitForGreenStatus().setWaitForNodes("3").setWaitForNoRelocatingShards(true).setWaitForEvents(Priority.LANGUID).get();
|
||||
assertThat(clusterHealth.isTimedOut(), equalTo(false));
|
||||
assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.GREEN));
|
||||
assertThat(clusterHealth.getNumberOfDataNodes(), equalTo(3));
|
||||
assertThat(clusterHealth.getInitializingShards(), equalTo(0));
|
||||
assertThat(clusterHealth.getUnassignedShards(), equalTo(0));
|
||||
assertThat(clusterHealth.getRelocatingShards(), equalTo(0));
|
||||
assertThat(clusterHealth.getActiveShards(), equalTo(22));
|
||||
assertThat(clusterHealth.getActivePrimaryShards(), equalTo(11));
|
||||
|
||||
|
||||
clusterState = client().admin().cluster().prepareState().get().getState();
|
||||
assertNodesPresent(clusterState.getRoutingNodes(), node1, node2, node3);
|
||||
|
||||
routingNodeEntry1 = clusterState.getRoutingNodes().node(node1);
|
||||
routingNodeEntry2 = clusterState.getRoutingNodes().node(node2);
|
||||
RoutingNode routingNodeEntry3 = clusterState.getRoutingNodes().node(node3);
|
||||
|
||||
assertThat(routingNodeEntry1.numberOfShardsWithState(STARTED) +
|
||||
routingNodeEntry2.numberOfShardsWithState(STARTED) +
|
||||
routingNodeEntry3.numberOfShardsWithState(STARTED), equalTo(22));
|
||||
|
||||
assertThat(routingNodeEntry1.numberOfShardsWithState(RELOCATING), equalTo(0));
|
||||
assertThat(routingNodeEntry1.numberOfShardsWithState(STARTED), anyOf(equalTo(7), equalTo(8)));
|
||||
|
||||
assertThat(routingNodeEntry2.numberOfShardsWithState(RELOCATING), equalTo(0));
|
||||
assertThat(routingNodeEntry2.numberOfShardsWithState(STARTED), anyOf(equalTo(7), equalTo(8)));
|
||||
|
||||
assertThat(routingNodeEntry3.numberOfShardsWithState(INITIALIZING), equalTo(0));
|
||||
assertThat(routingNodeEntry3.numberOfShardsWithState(STARTED), equalTo(7));
|
||||
|
||||
logger.info("Closing server1");
|
||||
// kill the first server
|
||||
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(server_1));
|
||||
// verify health
|
||||
logger.info("Running Cluster Health");
|
||||
clusterHealth = client().admin().cluster().prepareHealth()
|
||||
.setWaitForGreenStatus().setWaitForNodes("2").setWaitForNoRelocatingShards(true).setWaitForEvents(Priority.LANGUID).get();
|
||||
logger.info("Done Cluster Health, status {}", clusterHealth.getStatus());
|
||||
assertThat(clusterHealth.isTimedOut(), equalTo(false));
|
||||
assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.GREEN));
|
||||
|
||||
client().admin().cluster().prepareReroute().get();
|
||||
|
||||
clusterHealth = client().admin().cluster().prepareHealth()
|
||||
.setWaitForGreenStatus().setWaitForNodes("2").setWaitForNoRelocatingShards(true).setWaitForEvents(Priority.LANGUID).get();
|
||||
assertThat(clusterHealth.isTimedOut(), equalTo(false));
|
||||
assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.GREEN));
|
||||
assertThat(clusterHealth.getRelocatingShards(), equalTo(0));
|
||||
assertThat(clusterHealth.getActiveShards(), equalTo(22));
|
||||
assertThat(clusterHealth.getActivePrimaryShards(), equalTo(11));
|
||||
|
||||
clusterState = client().admin().cluster().prepareState().get().getState();
|
||||
assertNodesPresent(clusterState.getRoutingNodes(), node3, node2);
|
||||
routingNodeEntry2 = clusterState.getRoutingNodes().node(node2);
|
||||
routingNodeEntry3 = clusterState.getRoutingNodes().node(node3);
|
||||
|
||||
assertThat(routingNodeEntry2.numberOfShardsWithState(STARTED) + routingNodeEntry3.numberOfShardsWithState(STARTED), equalTo(22));
|
||||
|
||||
assertThat(routingNodeEntry2.numberOfShardsWithState(RELOCATING), equalTo(0));
|
||||
assertThat(routingNodeEntry2.numberOfShardsWithState(STARTED), equalTo(11));
|
||||
|
||||
assertThat(routingNodeEntry3.numberOfShardsWithState(RELOCATING), equalTo(0));
|
||||
assertThat(routingNodeEntry3.numberOfShardsWithState(STARTED), equalTo(11));
|
||||
|
||||
|
||||
logger.info("Deleting index [test]");
|
||||
// last, lets delete the index
|
||||
AcknowledgedResponse deleteIndexResponse = client().admin().indices().prepareDelete("test").execute().actionGet();
|
||||
assertThat(deleteIndexResponse.isAcknowledged(), equalTo(true));
|
||||
|
||||
clusterState = client().admin().cluster().prepareState().get().getState();
|
||||
assertNodesPresent(clusterState.getRoutingNodes(), node3, node2);
|
||||
routingNodeEntry2 = clusterState.getRoutingNodes().node(node2);
|
||||
assertThat(routingNodeEntry2.isEmpty(), equalTo(true));
|
||||
|
||||
routingNodeEntry3 = clusterState.getRoutingNodes().node(node3);
|
||||
assertThat(routingNodeEntry3.isEmpty(), equalTo(true));
|
||||
}
|
||||
|
||||
private String getLocalNodeId(String name) {
|
||||
TransportService transportService = internalCluster().getInstance(TransportService.class, name);
|
||||
String nodeId = transportService.getLocalNode().getId();
|
||||
assertThat(nodeId, not(nullValue()));
|
||||
return nodeId;
|
||||
}
|
||||
|
||||
private void assertNodesPresent(RoutingNodes routingNodes, String... nodes) {
|
||||
final Set<String> keySet = StreamSupport.stream(routingNodes.spliterator(), false)
|
||||
.map(RoutingNode::nodeId)
|
||||
.collect(Collectors.toSet());
|
||||
assertThat(keySet, containsInAnyOrder(nodes));
|
||||
}
|
||||
}
|
@ -48,7 +48,6 @@ import org.elasticsearch.common.io.PathUtils;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.common.util.concurrent.ThreadContext;
|
||||
import org.elasticsearch.common.util.set.Sets;
|
||||
import org.elasticsearch.common.xcontent.DeprecationHandler;
|
||||
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
@ -427,7 +426,7 @@ public abstract class ESRestTestCase extends ESTestCase {
|
||||
/**
|
||||
* Returns whether to preserve the state of the cluster upon completion of this test. Defaults to false. If true, overrides the value of
|
||||
* {@link #preserveIndicesUponCompletion()}, {@link #preserveTemplatesUponCompletion()}, {@link #preserveReposUponCompletion()},
|
||||
* {@link #preserveSnapshotsUponCompletion()}, and {@link #preserveILMPoliciesUponCompletion()}.
|
||||
* and {@link #preserveSnapshotsUponCompletion()}.
|
||||
*
|
||||
* @return true if the state of the cluster should be preserved
|
||||
*/
|
||||
@ -492,15 +491,6 @@ public abstract class ESRestTestCase extends ESTestCase {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether to preserve ILM Policies of this test. Defaults to not
|
||||
* preserving them. Only runs at all if xpack is installed on the cluster
|
||||
* being tested.
|
||||
*/
|
||||
protected boolean preserveILMPoliciesUponCompletion() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether to preserve SLM Policies of this test. Defaults to not
|
||||
* preserving them. Only runs at all if xpack is installed on the cluster
|
||||
@ -510,14 +500,6 @@ public abstract class ESRestTestCase extends ESTestCase {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* A set of ILM policies that should be preserved between runs.
|
||||
*/
|
||||
protected Set<String> preserveILMPolicyIds() {
|
||||
return Sets.newHashSet("ilm-history-ilm-policy", "slm-history-ilm-policy",
|
||||
"watch-history-ilm-policy", "ml-size-based-ilm-policy", "logs", "metrics");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether to wait to make absolutely certain that all snapshots
|
||||
* have been deleted.
|
||||
@ -634,10 +616,6 @@ public abstract class ESRestTestCase extends ESTestCase {
|
||||
wipeClusterSettings();
|
||||
}
|
||||
|
||||
if (hasXPack && false == preserveILMPoliciesUponCompletion()) {
|
||||
deleteAllILMPolicies(preserveILMPolicyIds());
|
||||
}
|
||||
|
||||
assertThat("Found in progress snapshots [" + inProgressSnapshots.get() + "].", inProgressSnapshots.get(), anEmptyMap());
|
||||
}
|
||||
|
||||
@ -776,35 +754,6 @@ public abstract class ESRestTestCase extends ESTestCase {
|
||||
client().performRequest(refreshRequest);
|
||||
}
|
||||
|
||||
private static void deleteAllILMPolicies(Set<String> exclusions) throws IOException {
|
||||
Map<String, Object> policies;
|
||||
|
||||
try {
|
||||
Response response = adminClient().performRequest(new Request("GET", "/_ilm/policy"));
|
||||
policies = entityAsMap(response);
|
||||
} catch (ResponseException e) {
|
||||
if (RestStatus.METHOD_NOT_ALLOWED.getStatus() == e.getResponse().getStatusLine().getStatusCode()) {
|
||||
// If bad request returned, ILM is not enabled.
|
||||
return;
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
|
||||
if (policies == null || policies.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
policies.keySet().stream()
|
||||
.filter(p -> exclusions.contains(p) == false)
|
||||
.forEach(policyName -> {
|
||||
try {
|
||||
adminClient().performRequest(new Request("DELETE", "/_ilm/policy/" + policyName));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("failed to delete policy: " + policyName, e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void deleteAllSLMPolicies() throws IOException {
|
||||
Map<String, Object> policies;
|
||||
|
||||
@ -1233,7 +1182,6 @@ public abstract class ESRestTestCase extends ESTestCase {
|
||||
case "security_audit_log":
|
||||
case ".slm-history":
|
||||
case "saml-service-provider":
|
||||
case "ilm-history":
|
||||
case "logs":
|
||||
case "logs-settings":
|
||||
case "logs-mappings":
|
||||
|
@ -102,11 +102,6 @@ public abstract class AbstractFullClusterRestartTestCase extends ESRestTestCase
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean preserveILMPoliciesUponCompletion() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean preserveSLMPoliciesUponCompletion() {
|
||||
return true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user