001/*
002 * (C) Copyright 2014 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     tdelprat
018 *     bdelbosc
019 */
020
021package org.nuxeo.elasticsearch.api;
022
023import com.google.common.util.concurrent.ListenableFuture;
024import org.elasticsearch.client.Client;
025
026import java.util.List;
027import java.util.NoSuchElementException;
028
029/**
030 * Administration interface for Elasticsearch service
031 *
032 * @since 5.9.3
033 */
034public interface ElasticSearchAdmin {
035
036    /**
037     * Retrieves the {@link Client} that can be used to access Elasticsearch API
038     *
039     * @since 5.9.3
040     */
041    Client getClient();
042
043    /**
044     * Initialize Elasticsearch indexes. Setup the index settings and mapping for each index that has been registered.
045     *
046     * @param dropIfExists if {true} remove an existing index
047     * @since 5.9.3
048     */
049    void initIndexes(boolean dropIfExists);
050
051    /**
052     * Reinitialize an index. This will drop the existing index, recreate it with its settings and mapping, the index
053     * will be empty.
054     *
055     * @since 7.3
056     */
057    void dropAndInitIndex(String indexName);
058
059    /**
060     * Reinitialize the index of a repository. This will drop the existing index, recreate it with its settings and
061     * mapping, the index will be empty.
062     *
063     * @since 7.1
064     */
065    void dropAndInitRepositoryIndex(String repositoryName);
066
067    /**
068     * List repository names that have Elasticsearch support.
069     *
070     * @since 7.1
071     */
072    List<String> getRepositoryNames();
073
074    /**
075     * Get the index name associated with the repository name.
076     *
077     * @throws NoSuchElementException if there is no Elasticsearch index associated with the requested repository.
078     * @since 7.2
079     */
080    String getIndexNameForRepository(String repositoryName);
081
082    /**
083     * Get the index names with the given type.
084     *
085     * @since 7.10
086     */
087    List<String> getIndexNamesForType(String type);
088
089    /**
090     * Get the first index name with the given type.
091     *
092     * @throws NoSuchElementException if there is no Elasticsearch index with the given type.
093     * @since 7.10
094     */
095    String getIndexNameForType(String type);
096
097    /**
098     * Returns true if there are indexing activities scheduled or running.
099     *
100     * @since 5.9.5
101     */
102    boolean isIndexingInProgress();
103
104    /**
105     * A {@link java.util.concurrent.Future} that accepts callback on completion when all the indexing worker are done.
106     *
107     * @since 7.2
108     */
109    ListenableFuture<Boolean> prepareWaitForIndexing();
110
111    /**
112     * Refresh all document indexes, immediately after the operation occurs, so that the updated document appears in
113     * search results immediately. There is no fsync thus doesn't guarantee durability.
114     *
115     * @since 5.9.3
116     */
117    void refresh();
118
119    /**
120     * Refresh document index for the specific repository, immediately after the operation occurs, so that the updated
121     * document appears in search results immediately. There is no fsync thus doesn't guarantee durability.
122     *
123     * @since 5.9.4
124     */
125    void refreshRepositoryIndex(String repositoryName);
126
127    /**
128     * Elasticsearch flush on all document indexes, triggers a lucene commit, empties the transaction log. Data is
129     * flushed to disk.
130     *
131     * @since 5.9.3
132     */
133    void flush();
134
135    /**
136     * Elasticsearch flush on document index for a specific repository, triggers a lucene commit, empties the
137     * transaction log. Data is flushed to disk.
138     *
139     * @since 5.9.4
140     */
141    void flushRepositoryIndex(String repositoryName);
142
143    /**
144     * Elasticsearch run {@link ElasticSearchAdmin#optimizeRepositoryIndex} on all document indexes,
145     *
146     * @since 7.2
147     */
148    void optimize();
149
150    /**
151     * Elasticsearch optimize operation allows to reduce the number of segments to one, Note that this can potentially
152     * be a very heavy operation.
153     *
154     * @since 7.2
155     */
156    void optimizeRepositoryIndex(String repositoryName);
157
158    /**
159     * Elasticsearch optimize operation allows to reduce the number of segments to one, Note that this can potentially
160     * be a very heavy operation.
161     *
162     * @since 7.3
163     */
164    void optimizeIndex(String indexName);
165
166    /**
167     * Returns the number of indexing worker scheduled waiting to be executed.
168     *
169     * @since 7.1
170     */
171    long getPendingWorkerCount();
172
173    /**
174     * Returns the number of indexing worker that are currently running.
175     *
176     * @since 7.1
177     */
178    long getRunningWorkerCount();
179
180    /**
181     * Returns the total number of command processed by Elasticsearch for this Nuxeo instance. Useful for test
182     * assertion.
183     *
184     * @since 5.9.4
185     */
186    int getTotalCommandProcessed();
187
188    /**
189     * Returns true if the Elasticsearch is embedded with Nuxeo, sharing the same JVM.
190     *
191     * @since 7.2
192     */
193    boolean isEmbedded();
194
195    /**
196     * When true use an external version for Elasticsearch document, this enable an optimistic concurrency control
197     * ensuring that an older version of a document never overwrites a newer version.
198     *
199     * @since 8.3
200     */
201    boolean useExternalVersion();
202
203}