package com.github.obourgain.elasticsearch.batch.util;

import java.util.Collections;
import java.util.Map;
import org.elasticsearch.action.ActionFuture;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse;
import org.elasticsearch.action.admin.indices.refresh.RefreshResponse;
import org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest;
import org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse;
import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsResponse;
import org.elasticsearch.action.support.AdapterActionFuture;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.Requests;

public class ElasticsearchBatchOperationsAsync {

    private final Client client;

    public ElasticsearchBatchOperationsAsync(Client client) {
        this.client = client;
    }

    public ActionFuture<RefreshResponse> refresh(String... indices) {
        return client.admin().indices().refresh(Requests.refreshRequest(indices));
    }

    public ActionFuture<UpdateSettingsResponse> disableRefresh(String... indices) {
        return updateSettings(Collections.singletonMap("refresh_interval", "-1"), indices);
    }

    public ActionFuture<String> getRefreshInterval(final String index) {
        AdapterActionFuture<String, GetSettingsResponse> future = new AdapterActionFuture<String, GetSettingsResponse>() {
            @Override
            protected String convert(GetSettingsResponse listenerResponse) {
                return listenerResponse.getSetting(index, "index.refresh_interval");
            }
        };
        client.admin().indices().getSettings(new GetSettingsRequest().indices(index), future);
        return future;
    }

    public ActionFuture<UpdateSettingsResponse> setRefreshInterval(String refreshInterval, String... indices) {
        return updateSettings(Collections.singletonMap("refresh_interval", refreshInterval), indices);
    }

    public ActionFuture<UpdateSettingsResponse> disableReplicas(String... indices) {
        return updateSettings(Collections.singletonMap("number_of_replicas", "0"), indices);
    }

    public ActionFuture<UpdateSettingsResponse> setReplicas(int replicas, String... indices) {
        return updateSettings(Collections.singletonMap("number_of_replicas", String.valueOf(replicas)), indices);
    }

    public ActionFuture<Integer> getReplicas(final String index) {
        AdapterActionFuture<Integer, GetSettingsResponse> future = new AdapterActionFuture<Integer, GetSettingsResponse>() {
            @Override
            protected Integer convert(GetSettingsResponse listenerResponse) {
                return Integer.valueOf(listenerResponse.getSetting(index, "index.refresh_interval"));
            }
        };
        client.admin().indices().getSettings(new GetSettingsRequest().indices(index), future);
        return future;
    }

    public ActionFuture<UpdateSettingsResponse> updateSettings(Map<String, String> settings, String... indices) {
        return client.admin().indices()
                .updateSettings(Requests.updateSettingsRequest(indices)
                        .settings(settings));
    }

    public ActionFuture<IndicesAliasesResponse> switchAlias(String alias, String fromIndex, String toIndex) {
        return client.admin().indices().aliases(Requests.indexAliasesRequest()
                .removeAlias(fromIndex, alias)
                .addAlias(alias, toIndex));
    }
}

@@ -49,16 +49,90 @@
 .util;%0A%0A
+import static org.slf4j.LoggerFactory.getLogger;%0Aimport java.util.Arrays;%0A
 import j
@@ -153,16 +153,16 @@
 ctions;%0A
-
 import j
@@ -752,16 +752,41 @@
 equests;
+%0Aimport org.slf4j.Logger;
 %0A%0Apublic
@@ -829,16 +829,110 @@
 sync %7B%0A%0A
+    private static final Logger logger = getLogger(ElasticsearchBatchOperationsAsync.class);%0A%0A
     priv
@@ -1118,32 +1118,94 @@
 g... indices) %7B%0A
+        logger.info(%22Refreshing %7B%7D%22, Arrays.asList(indices));%0A
         return c
@@ -1354,32 +1354,104 @@
 g... indices) %7B%0A
+        logger.info(%22Disabling refresh on %7B%7D%22, Arrays.asList(indices));%0A
         return u
@@ -2167,32 +2167,121 @@
 g... indices) %7B%0A
+        logger.info(%22Set refresh to %7B%7D on %7B%7D%22, refreshInterval, Arrays.asList(indices));%0A
         return u
@@ -2451,32 +2451,105 @@
 g... indices) %7B%0A
+        logger.info(%22Disabling replicas on %7B%7D%22, Arrays.asList(indices));%0A
         return u
@@ -2719,32 +2719,115 @@
 g... indices) %7B%0A
+        logger.info(%22Set replicas to %7B%7D on %7B%7D%22, replicas, Arrays.asList(indices));%0A
         return u
@@ -3581,32 +3581,120 @@
 g... indices) %7B%0A
+        logger.info(%22Update settings with %7B%7D on %7B%7D%22, settings, Arrays.asList(indices));%0A
         return c
@@ -3834,32 +3834,32 @@
 tings));%0A    %7D%0A%0A
-
     public Actio
@@ -3944,32 +3944,113 @@
 ring toIndex) %7B%0A
+        logger.info(%22Switch alias %7B%7D from %7B%7D to %7B%7D%22, alias, fromIndex, toIndex);%0A
         return c

add logs