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