Search in sources :

Example 1 with ElasticSearchIndex

use of com.zimbra.cs.index.elasticsearch.ElasticSearchIndex in project zm-mailbox by Zimbra.

the class MailboxTestUtil method cleanupIndexStore.

public static void cleanupIndexStore(Mailbox mbox) {
    IndexStore index = mbox.index.getIndexStore();
    if (index instanceof ElasticSearchIndex) {
        String key = mbox.getAccountId();
        String indexUrl = String.format("%s%s/", LC.zimbra_index_elasticsearch_url_base.value(), key);
        HttpMethod method = new DeleteMethod(indexUrl);
        try {
            ElasticSearchConnector connector = new ElasticSearchConnector();
            int statusCode = connector.executeMethod(method);
            if (statusCode == HttpStatus.SC_OK) {
                boolean ok = connector.getBooleanAtJsonPath(new String[] { "ok" }, false);
                boolean acknowledged = connector.getBooleanAtJsonPath(new String[] { "acknowledged" }, false);
                if (!ok || !acknowledged) {
                    ZimbraLog.index.debug("Delete index status ok=%b acknowledged=%b", ok, acknowledged);
                }
            } else {
                String error = connector.getStringAtJsonPath(new String[] { "error" });
                if (error != null && error.startsWith("IndexMissingException")) {
                    ZimbraLog.index.debug("Unable to delete index for key=%s.  Index is missing", key);
                } else {
                    ZimbraLog.index.error("Problem deleting index for key=%s error=%s", key, error);
                }
            }
        } catch (HttpException e) {
            ZimbraLog.index.error("Problem Deleting index with key=" + key, e);
        } catch (IOException e) {
            ZimbraLog.index.error("Problem Deleting index with key=" + key, e);
        }
    }
}
Also used : DeleteMethod(org.apache.commons.httpclient.methods.DeleteMethod) ElasticSearchConnector(com.zimbra.cs.index.elasticsearch.ElasticSearchConnector) HttpException(org.apache.commons.httpclient.HttpException) ElasticSearchIndex(com.zimbra.cs.index.elasticsearch.ElasticSearchIndex) IOException(java.io.IOException) IndexStore(com.zimbra.cs.index.IndexStore) HttpMethod(org.apache.commons.httpclient.HttpMethod)

Aggregations

IndexStore (com.zimbra.cs.index.IndexStore)1 ElasticSearchConnector (com.zimbra.cs.index.elasticsearch.ElasticSearchConnector)1 ElasticSearchIndex (com.zimbra.cs.index.elasticsearch.ElasticSearchIndex)1 IOException (java.io.IOException)1 HttpException (org.apache.commons.httpclient.HttpException)1 HttpMethod (org.apache.commons.httpclient.HttpMethod)1 DeleteMethod (org.apache.commons.httpclient.methods.DeleteMethod)1