Search in sources :

Example 1 with ElasticSearchConnector

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

the class ElasticSearchIndexTest method indexStoreAvailable.

@Override
protected boolean indexStoreAvailable() {
    String indexUrl = String.format("%s?_status", LC.zimbra_index_elasticsearch_url_base.value());
    HttpMethod method = new GetMethod(indexUrl);
    try {
        ElasticSearchConnector connector = new ElasticSearchConnector();
        connector.executeMethod(method);
    } catch (HttpException e) {
        ZimbraLog.index.error("Problem accessing the ElasticSearch Index store", e);
        return false;
    } catch (IOException e) {
        ZimbraLog.index.error("Problem accessing the ElasticSearch Index store", e);
        return false;
    }
    return true;
}
Also used : ElasticSearchConnector(com.zimbra.cs.index.elasticsearch.ElasticSearchConnector) GetMethod(org.apache.commons.httpclient.methods.GetMethod) HttpException(org.apache.commons.httpclient.HttpException) IOException(java.io.IOException) HttpMethod(org.apache.commons.httpclient.HttpMethod)

Example 2 with ElasticSearchConnector

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

the class ElasticSearchIndexTest method cleanupForIndexStore.

@Override
protected void cleanupForIndexStore() {
    String key = testAcct.getId();
    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) IOException(java.io.IOException) HttpMethod(org.apache.commons.httpclient.HttpMethod)

Example 3 with ElasticSearchConnector

use of com.zimbra.cs.index.elasticsearch.ElasticSearchConnector 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

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