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;
022import java.util.NoSuchElementException;
023
024import org.elasticsearch.client.Client;
025
026import com.google.common.util.concurrent.ListenableFuture;
027
028/**
029 * Administration interface for Elasticsearch service
030 *
031 * @since 5.9.3
032 */
033public interface ElasticSearchAdmin {
034
035    /**
036     * Retrieves the {@link Client} that can be used to access Elasticsearch API
037     *
038     * @since 5.9.3
039     */
040    Client getClient();
041
042    /**
043     * Initialize Elasticsearch indexes. Setup the index settings and mapping for each index that has been registered.
044     *
045     * @param dropIfExists if {true} remove an existing index
046     * @since 5.9.3
047     */
048    void initIndexes(boolean dropIfExists);
049
050    /**
051     * Reinitialize an index. This will drop the existing index, recreate it with its settings and mapping, the index
052     * will be empty.
053     *
054     * @since 7.3
055     */
056    void dropAndInitIndex(String indexName);
057
058    /**
059     * Reinitialize the index of a repository. This will drop the existing index, recreate it with its settings and
060     * mapping, the index will be empty.
061     *
062     * @since 7.1
063     */
064    void dropAndInitRepositoryIndex(String repositoryName);
065
066    /**
067     * List repository names that have Elasticsearch support.
068     *
069     * @since 7.1
070     */
071    List<String> getRepositoryNames();
072
073    /**
074     * Get the index name associated with the repository name.
075     *
076     * @throws NoSuchElementException if there is no Elasticsearch index associated with the requested repository.
077     * @since 7.2
078     */
079    String getIndexNameForRepository(String repositoryName);
080
081    /**
082     * Get the index names with the given type.
083     *
084     * @since 7.10
085     */
086    List<String> getIndexNamesForType(String type);
087
088    /**
089     * Get the first index name with the given type.
090     *
091     * @throws NoSuchElementException if there is no Elasticsearch index with the given type.
092     * @since 7.10
093     */
094    String getIndexNameForType(String type);
095
096    /**
097     * Returns true if there are indexing activities scheduled or running.
098     *
099     * @since 5.9.5
100     */
101    boolean isIndexingInProgress();
102
103    /**
104     * A {@link java.util.concurrent.Future} that accepts callback on completion when all the indexing worker are done.
105     *
106     * @since 7.2
107     */
108    ListenableFuture<Boolean> prepareWaitForIndexing();
109
110    /**
111     * Refresh all document indexes, immediately after the operation occurs, so that the updated document appears in
112     * search results immediately. There is no fsync thus doesn't guarantee durability.
113     *
114     * @since 5.9.3
115     */
116    void refresh();
117
118    /**
119     * Refresh document index for the specific repository, immediately after the operation occurs, so that the updated
120     * document appears in search results immediately. There is no fsync thus doesn't guarantee durability.
121     *
122     * @since 5.9.4
123     */
124    void refreshRepositoryIndex(String repositoryName);
125
126    /**
127     * Elasticsearch flush on all document indexes, triggers a lucene commit, empties the transaction log. Data is
128     * flushed to disk.
129     *
130     * @since 5.9.3
131     */
132    void flush();
133
134    /**
135     * Elasticsearch flush on document index for a specific repository, triggers a lucene commit, empties the
136     * transaction log. Data is flushed to disk.
137     *
138     * @since 5.9.4
139     */
140    void flushRepositoryIndex(String repositoryName);
141
142    /**
143     * Elasticsearch run {@link ElasticSearchAdmin#optimizeRepositoryIndex} on all document indexes,
144     *
145     * @since 7.2
146     */
147    void optimize();
148
149    /**
150     * Elasticsearch optimize operation allows to reduce the number of segments to one, Note that this can potentially
151     * be a very heavy operation.
152     *
153     * @since 7.2
154     */
155    void optimizeRepositoryIndex(String repositoryName);
156
157    /**
158     * Elasticsearch optimize operation allows to reduce the number of segments to one, Note that this can potentially
159     * be a very heavy operation.
160     *
161     * @since 7.3
162     */
163    void optimizeIndex(String indexName);
164
165    /**
166     * Returns the number of indexing worker scheduled waiting to be executed.
167     *
168     * @since 7.1
169     */
170    int getPendingWorkerCount();
171
172    /**
173     * Returns the number of indexing worker that are currently running.
174     *
175     * @since 7.1
176     */
177    int getRunningWorkerCount();
178
179    /**
180     * Returns the total number of command processed by Elasticsearch for this Nuxeo instance. Useful for test
181     * assertion.
182     *
183     * @since 5.9.4
184     */
185    int getTotalCommandProcessed();
186
187    /**
188     * Returns true if the Elasticsearch is embedded with Nuxeo, sharing the same JVM.
189     *
190     * @since 7.2
191     */
192    boolean isEmbedded();
193
194}