001/*
002 * (C) Copyright 2014 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl-2.1.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     tdelprat
016 *     bdelbosc
017 */
018
019package org.nuxeo.elasticsearch.api;
020
021import java.util.List;
022
023import com.google.common.util.concurrent.ListenableFuture;
024import org.elasticsearch.client.Client;
025
026/**
027 * Administration interface for Elasticsearch service
028 *
029 * @since 5.9.3
030 */
031public interface ElasticSearchAdmin {
032
033    /**
034     * Retrieves the {@link Client} that can be used to access Elasticsearch API
035     *
036     * @since 5.9.3
037     */
038    Client getClient();
039
040    /**
041     * Initialize Elasticsearch indexes. Setup the index settings and mapping for each index that has been registered.
042     *
043     * @param dropIfExists if {true} remove an existing index
044     * @since 5.9.3
045     */
046    void initIndexes(boolean dropIfExists);
047
048    /**
049     * Reinitialize an index. This will drop the existing index, recreate it with its settings and
050     * mapping, the index will be empty.
051     *
052     * @since 7.3
053     */
054    void dropAndInitIndex(String indexName);
055
056    /**
057     * Reinitialize the index of a repository. This will drop the existing index, recreate it with its settings and
058     * mapping, the index will be empty.
059     *
060     * @since 7.1
061     */
062    void dropAndInitRepositoryIndex(String repositoryName);
063
064    /**
065     * List repository names that have Elasticsearch support.
066     *
067     * @since 7.1
068     */
069    List<String> getRepositoryNames();
070
071    /**
072     * Get the index name associated with the repository name.
073
074     * throws NoSuchElementException if there is no Elasticsearch index associated with the requested repository.
075     *
076     * @since 7.2
077     */
078    String getIndexNameForRepository(String repositoryName);
079
080    /**
081     * Returns true if there are indexing activities scheduled or running.
082     *
083     * @since 5.9.5
084     */
085    boolean isIndexingInProgress();
086
087    /**
088     * A {@link java.util.concurrent.Future} that accepts callback on completion when all the indexing
089     * worker are done.
090     *
091     * @since 7.2
092     */
093    ListenableFuture<Boolean> prepareWaitForIndexing();
094
095    /**
096     * Refresh all document indexes, immediately after the operation occurs, so that the updated document appears in
097     * search results immediately. There is no fsync thus doesn't guarantee durability.
098     *
099     * @since 5.9.3
100     */
101    void refresh();
102
103    /**
104     * Refresh document index for the specific repository, immediately after the operation occurs, so that the updated
105     * document appears in search results immediately. There is no fsync thus doesn't guarantee durability.
106     *
107     * @since 5.9.4
108     */
109    void refreshRepositoryIndex(String repositoryName);
110
111    /**
112     * Elasticsearch flush on all document indexes, triggers a lucene commit, empties the transaction log. Data is
113     * flushed to disk.
114     *
115     * @since 5.9.3
116     */
117    void flush();
118
119    /**
120     * Elasticsearch flush on document index for a specific repository, triggers a lucene commit, empties the
121     * transaction log. Data is flushed to disk.
122     *
123     * @since 5.9.4
124     */
125    void flushRepositoryIndex(String repositoryName);
126
127    /**
128     * Elasticsearch run {@link ElasticSearchAdmin#optimizeRepositoryIndex} on all document indexes,
129     * @since 7.2
130     */
131    void optimize();
132
133    /**
134     * Elasticsearch optimize operation allows to reduce the number of segments to one, Note that this can potentially
135     * be a very heavy operation.
136     *
137     * @since 7.2
138     */
139    void optimizeRepositoryIndex(String repositoryName);
140
141    /**
142     * Elasticsearch optimize operation allows to reduce the number of segments to one, Note that this can potentially
143     * be a very heavy operation.
144     *
145     * @since 7.3
146     */
147    void optimizeIndex(String indexName);
148
149    /**
150     * Returns the number of indexing worker scheduled waiting to be executed.
151     *
152     * @since 7.1
153     */
154    int getPendingWorkerCount();
155
156    /**
157     * Returns the number of indexing worker that are currently running.
158     *
159     * @since 7.1
160     */
161    int getRunningWorkerCount();
162
163    /**
164     * Returns the total number of command processed by Elasticsearch for this Nuxeo instance.
165     * Useful for test assertion.
166     *
167     * @since 5.9.4
168     */
169    int getTotalCommandProcessed();
170
171    /**
172     * Returns true if the Elasticsearch is embedded with Nuxeo, sharing the same JVM.
173     *
174     * @since 7.2
175     */
176    boolean isEmbedded();
177
178
179}