diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackClient.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackClient.java index 77f511ba4d0..da879e87c54 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackClient.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackClient.java @@ -13,6 +13,7 @@ import org.elasticsearch.protocol.xpack.XPackInfoRequest; import org.elasticsearch.protocol.xpack.XPackInfoResponse; import org.elasticsearch.xpack.core.action.XPackInfoAction; import org.elasticsearch.xpack.core.action.XPackInfoRequestBuilder; +import org.elasticsearch.xpack.core.indexlifecycle.client.ILMClient; import org.elasticsearch.xpack.core.ml.client.MachineLearningClient; import org.elasticsearch.xpack.core.monitoring.client.MonitoringClient; import org.elasticsearch.xpack.core.security.client.SecurityClient; @@ -33,6 +34,7 @@ public class XPackClient { private final SecurityClient securityClient; private final WatcherClient watcherClient; private final MachineLearningClient machineLearning; + private final ILMClient ilmClient; public XPackClient(Client client) { this.client = client; @@ -41,6 +43,7 @@ public class XPackClient { this.securityClient = new SecurityClient(client); this.watcherClient = new WatcherClient(client); this.machineLearning = new MachineLearningClient(client); + this.ilmClient = new ILMClient(client); } public Client es() { @@ -67,6 +70,10 @@ public class XPackClient { return machineLearning; } + public ILMClient ilmClient() { + return ilmClient; + } + public XPackClient withHeaders(Map headers) { return new XPackClient(client.filterWithHeader(headers)); } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/client/ILMClient.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/client/ILMClient.java new file mode 100644 index 00000000000..ef842f20242 --- /dev/null +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/client/ILMClient.java @@ -0,0 +1,181 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +package org.elasticsearch.xpack.core.indexlifecycle.client; + +import org.elasticsearch.action.ActionFuture; +import org.elasticsearch.action.ActionListener; +import org.elasticsearch.action.support.master.AcknowledgedResponse; +import org.elasticsearch.client.ElasticsearchClient; +import org.elasticsearch.xpack.core.indexlifecycle.ExplainLifecycleRequest; +import org.elasticsearch.xpack.core.indexlifecycle.ExplainLifecycleResponse; +import org.elasticsearch.xpack.core.indexlifecycle.SetIndexLifecyclePolicyRequest; +import org.elasticsearch.xpack.core.indexlifecycle.SetIndexLifecyclePolicyResponse; +import org.elasticsearch.xpack.core.indexlifecycle.StartILMRequest; +import org.elasticsearch.xpack.core.indexlifecycle.StopILMRequest; +import org.elasticsearch.xpack.core.indexlifecycle.action.DeleteLifecycleAction; +import org.elasticsearch.xpack.core.indexlifecycle.action.ExplainLifecycleAction; +import org.elasticsearch.xpack.core.indexlifecycle.action.GetLifecycleAction; +import org.elasticsearch.xpack.core.indexlifecycle.action.GetStatusAction; +import org.elasticsearch.xpack.core.indexlifecycle.action.PutLifecycleAction; +import org.elasticsearch.xpack.core.indexlifecycle.action.RemovePolicyForIndexAction; +import org.elasticsearch.xpack.core.indexlifecycle.action.RetryAction; +import org.elasticsearch.xpack.core.indexlifecycle.action.SetIndexLifecyclePolicyAction; +import org.elasticsearch.xpack.core.indexlifecycle.action.StartILMAction; +import org.elasticsearch.xpack.core.indexlifecycle.action.StopILMAction; + +/** + * A wrapper to elasticsearch clients that exposes all ILM related APIs + */ +public class ILMClient { + + private ElasticsearchClient client; + + public ILMClient(ElasticsearchClient client) { + this.client = client; + } + + /** + * Create or modify a lifecycle policy definition + */ + public void putLifecyclePolicy(PutLifecycleAction.Request request, ActionListener listener) { + client.execute(PutLifecycleAction.INSTANCE, request, listener); + } + + /** + * Create or modify a lifecycle policy definition + */ + public ActionFuture putLifecyclePolicy(PutLifecycleAction.Request request) { + return client.execute(PutLifecycleAction.INSTANCE, request); + } + + /** + * Get a lifecycle policy definition + */ + public void getLifecyclePolicy(GetLifecycleAction.Request request, ActionListener listener) { + client.execute(GetLifecycleAction.INSTANCE, request, listener); + } + + /** + * Get a lifecycle policy definition + */ + public ActionFuture getLifecyclePolicy(GetLifecycleAction.Request request) { + return client.execute(GetLifecycleAction.INSTANCE, request); + } + + /** + * Delete a lifecycle policy definition + */ + public void deleteLifecyclePolicy(DeleteLifecycleAction.Request request, ActionListener listener) { + client.execute(DeleteLifecycleAction.INSTANCE, request, listener); + } + + /** + * Delete a lifecycle policy definition + */ + public ActionFuture deleteLifecyclePolicy(DeleteLifecycleAction.Request request) { + return client.execute(DeleteLifecycleAction.INSTANCE, request); + } + + /** + * Explain the current lifecycle state for an index + */ + public void explainLifecycle(ExplainLifecycleRequest request, ActionListener listener) { + client.execute(ExplainLifecycleAction.INSTANCE, request, listener); + } + + /** + * Explain the current lifecycle state for an index + */ + public ActionFuture explainLifecycle(ExplainLifecycleRequest request) { + return client.execute(ExplainLifecycleAction.INSTANCE, request); + } + + /** + * Returns the current status of the ILM plugin + */ + public void getStatus(GetStatusAction.Request request, ActionListener listener) { + client.execute(GetStatusAction.INSTANCE, request, listener); + } + + /** + * Returns the current status of the ILM plugin + */ + public ActionFuture getStatus(GetStatusAction.Request request) { + return client.execute(GetStatusAction.INSTANCE, request); + } + + /** + * Sets the lifecycle policy to use for an index + */ + public void setIndexLifecyclePolicy(SetIndexLifecyclePolicyRequest request, ActionListener listener) { + client.execute(SetIndexLifecyclePolicyAction.INSTANCE, request, listener); + } + + /** + * Sets the lifecycle policy to use for an index + */ + public ActionFuture setIndexLifecyclePolicy(SetIndexLifecyclePolicyRequest request) { + return client.execute(SetIndexLifecyclePolicyAction.INSTANCE, request); + } + + /** + * Removes index lifecycle management from an index + */ + public void removePolicyForIndex(RemovePolicyForIndexAction.Request request, + ActionListener listener) { + client.execute(RemovePolicyForIndexAction.INSTANCE, request, listener); + } + + /** + * Removes index lifecycle management from an index + */ + public ActionFuture removePolicyForIndex(RemovePolicyForIndexAction.Request request) { + return client.execute(RemovePolicyForIndexAction.INSTANCE, request); + } + + /** + * Retries the policy for an index which is currently in ERROR + */ + public void retryPolicy(RetryAction.Request request, ActionListener listener) { + client.execute(RetryAction.INSTANCE, request, listener); + } + + /** + * Removes index lifecycle management from an index + */ + public ActionFuture retryPolicy(RetryAction.Request request) { + return client.execute(RetryAction.INSTANCE, request); + } + + /** + * Starts the ILM plugin + */ + public void startILM(StartILMRequest request, ActionListener listener) { + client.execute(StartILMAction.INSTANCE, request, listener); + } + + /** + * Starts the ILM plugin + */ + public ActionFuture startILM(StartILMRequest request) { + return client.execute(StartILMAction.INSTANCE, request); + } + + /** + * Stops the ILM plugin + */ + public void stopILM(StopILMRequest request, ActionListener listener) { + client.execute(StopILMAction.INSTANCE, request, listener); + } + + /** + * Stops the ILM plugin + */ + public ActionFuture stopILM(StopILMRequest request) { + return client.execute(StopILMAction.INSTANCE, request); + } +}