]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9228 drop deprecated Elasticsearch count query
authorDaniel Schwarz <daniel.schwarz@sonarsource.com>
Mon, 15 May 2017 08:38:07 +0000 (10:38 +0200)
committerDaniel Schwarz <bartfastiel@users.noreply.github.com>
Fri, 26 May 2017 08:58:48 +0000 (10:58 +0200)
server/sonar-server/src/main/java/org/sonar/server/es/EsClient.java
server/sonar-server/src/main/java/org/sonar/server/es/request/ProxyCountRequestBuilder.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/es/EsClientTest.java
server/sonar-server/src/test/java/org/sonar/server/es/request/ProxyCountRequestBuilderTest.java [deleted file]

index 2bf75677dd92cbf070ee3695d18e6fa71531d95a..742625ce1f1580f1cbbcde4bd1fb8de2ab225887 100644 (file)
  */
 package org.sonar.server.es;
 
-import static java.util.Objects.requireNonNull;
-
 import java.io.Closeable;
-
 import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequestBuilder;
 import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequestBuilder;
 import org.elasticsearch.action.admin.cluster.state.ClusterStateRequestBuilder;
@@ -36,7 +33,6 @@ import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequestBuild
 import org.elasticsearch.action.admin.indices.refresh.RefreshRequestBuilder;
 import org.elasticsearch.action.admin.indices.stats.IndicesStatsRequestBuilder;
 import org.elasticsearch.action.bulk.BulkRequestBuilder;
-import org.elasticsearch.action.count.CountRequestBuilder;
 import org.elasticsearch.action.delete.DeleteRequestBuilder;
 import org.elasticsearch.action.get.GetRequestBuilder;
 import org.elasticsearch.action.get.MultiGetRequestBuilder;
@@ -56,7 +52,6 @@ import org.sonar.server.es.request.ProxyClearCacheRequestBuilder;
 import org.sonar.server.es.request.ProxyClusterHealthRequestBuilder;
 import org.sonar.server.es.request.ProxyClusterStateRequestBuilder;
 import org.sonar.server.es.request.ProxyClusterStatsRequestBuilder;
-import org.sonar.server.es.request.ProxyCountRequestBuilder;
 import org.sonar.server.es.request.ProxyCreateIndexRequestBuilder;
 import org.sonar.server.es.request.ProxyDeleteRequestBuilder;
 import org.sonar.server.es.request.ProxyFlushRequestBuilder;
@@ -71,6 +66,8 @@ import org.sonar.server.es.request.ProxyRefreshRequestBuilder;
 import org.sonar.server.es.request.ProxySearchRequestBuilder;
 import org.sonar.server.es.request.ProxySearchScrollRequestBuilder;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * Facade to connect to Elasticsearch node. Handles correctly errors (logging + exceptions
  * with context) and profiling of requests.
@@ -155,14 +152,6 @@ public class EsClient implements Closeable {
     return new ProxyMultiGetRequestBuilder(nativeClient());
   }
 
-  /**
-   * @deprecated use {@link #prepareSearch(String...)} with size 0, or {@link #count(IndexType)}
-   */
-  @Deprecated
-  public CountRequestBuilder prepareCount(String... indices) {
-    return new ProxyCountRequestBuilder(nativeClient()).setIndices(indices);
-  }
-
   public BulkRequestBuilder prepareBulk() {
     return new ProxyBulkRequestBuilder(nativeClient());
   }
diff --git a/server/sonar-server/src/main/java/org/sonar/server/es/request/ProxyCountRequestBuilder.java b/server/sonar-server/src/main/java/org/sonar/server/es/request/ProxyCountRequestBuilder.java
deleted file mode 100644 (file)
index a5a327e..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.server.es.request;
-
-import org.apache.commons.lang.StringUtils;
-import org.elasticsearch.action.ListenableActionFuture;
-import org.elasticsearch.action.count.CountAction;
-import org.elasticsearch.action.count.CountRequestBuilder;
-import org.elasticsearch.action.count.CountResponse;
-import org.elasticsearch.client.Client;
-import org.elasticsearch.common.unit.TimeValue;
-import org.sonar.api.utils.log.Profiler;
-import org.sonar.server.es.EsClient;
-
-public class ProxyCountRequestBuilder extends CountRequestBuilder {
-
-  public ProxyCountRequestBuilder(Client client) {
-    super(client, CountAction.INSTANCE);
-  }
-
-  @Override
-  public CountResponse get() {
-    Profiler profiler = Profiler.createIfTrace(EsClient.LOGGER).start();
-    try {
-      return super.execute().actionGet();
-    } catch (Exception e) {
-      throw new IllegalStateException(String.format("Fail to execute %s", toString()), e);
-    } finally {
-      if (profiler.isTraceEnabled()) {
-        profiler.stopTrace(toString());
-      }
-    }
-  }
-
-  @Override
-  public CountResponse get(TimeValue timeout) {
-    throw new IllegalStateException("Not yet implemented");
-  }
-
-  @Override
-  public CountResponse get(String timeout) {
-    throw new IllegalStateException("Not yet implemented");
-  }
-
-  @Override
-  public ListenableActionFuture<CountResponse> execute() {
-    throw new UnsupportedOperationException("execute() should not be called as it's used for asynchronous");
-  }
-
-  @Override
-  public String toString() {
-    StringBuilder message = new StringBuilder();
-    message.append("ES count request");
-    if (request.indices().length > 0) {
-      message.append(String.format(" on indices '%s'", StringUtils.join(request.indices(), ",")));
-    }
-    if (request.types().length > 0) {
-      message.append(String.format(" on types '%s'", StringUtils.join(request.types(), ",")));
-    }
-    return message.toString();
-  }
-}
index f8c5172ee7dc9d5bc275d0ed1d719a2e65375c03..d36aef930edf0f0483506ac1656a186da5948ebe 100644 (file)
@@ -25,7 +25,6 @@ import org.sonar.server.es.request.ProxyBulkRequestBuilder;
 import org.sonar.server.es.request.ProxyClusterHealthRequestBuilder;
 import org.sonar.server.es.request.ProxyClusterStateRequestBuilder;
 import org.sonar.server.es.request.ProxyClusterStatsRequestBuilder;
-import org.sonar.server.es.request.ProxyCountRequestBuilder;
 import org.sonar.server.es.request.ProxyCreateIndexRequestBuilder;
 import org.sonar.server.es.request.ProxyDeleteRequestBuilder;
 import org.sonar.server.es.request.ProxyFlushRequestBuilder;
@@ -53,7 +52,6 @@ public class EsClientTest {
     assertThat(underTest.nativeClient()).isNotNull();
     assertThat(underTest.prepareBulk()).isInstanceOf(ProxyBulkRequestBuilder.class);
     assertThat(underTest.prepareClusterStats()).isInstanceOf(ProxyClusterStatsRequestBuilder.class);
-    assertThat(underTest.prepareCount()).isInstanceOf(ProxyCountRequestBuilder.class);
     assertThat(underTest.prepareCreate("fakes")).isInstanceOf(ProxyCreateIndexRequestBuilder.class);
     assertThat(underTest.prepareDelete("fakes", "fake", "my_id")).isInstanceOf(ProxyDeleteRequestBuilder.class);
     assertThat(underTest.prepareIndicesExist()).isInstanceOf(ProxyIndicesExistsRequestBuilder.class);
diff --git a/server/sonar-server/src/test/java/org/sonar/server/es/request/ProxyCountRequestBuilderTest.java b/server/sonar-server/src/test/java/org/sonar/server/es/request/ProxyCountRequestBuilderTest.java
deleted file mode 100644 (file)
index 5a06d2d..0000000
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.server.es.request;
-
-import org.elasticsearch.common.unit.TimeValue;
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonar.api.utils.log.LogTester;
-import org.sonar.api.utils.log.LoggerLevel;
-import org.sonar.server.es.EsTester;
-import org.sonar.server.es.FakeIndexDefinition;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.fail;
-
-public class ProxyCountRequestBuilderTest {
-
-  @Rule
-  public EsTester esTester = new EsTester(new FakeIndexDefinition());
-
-  @Rule
-  public LogTester logTester = new LogTester();
-
-  @Test
-  public void count() {
-    esTester.client().prepareCount(FakeIndexDefinition.INDEX).get();
-  }
-
-  @Test
-  public void to_string() {
-    assertThat(esTester.client().prepareCount(FakeIndexDefinition.INDEX).setTypes(FakeIndexDefinition.INDEX_TYPE_FAKE.getType()).toString())
-      .isEqualTo("ES count request on indices 'fakes' on types 'fake'");
-    assertThat(esTester.client().prepareCount(FakeIndexDefinition.INDEX).toString()).isEqualTo("ES count request on indices 'fakes'");
-    assertThat(esTester.client().prepareCount().toString()).isEqualTo("ES count request");
-  }
-
-  @Test
-  public void trace_logs() {
-    logTester.setLevel(LoggerLevel.TRACE);
-
-    esTester.client().prepareCount(FakeIndexDefinition.INDEX).get();
-    assertThat(logTester.logs(LoggerLevel.TRACE)).hasSize(1);
-  }
-
-  @Test
-  public void fail_to_count_bad_query() {
-    try {
-      esTester.client().prepareCount("unknown_index1, unknown_index2").setTypes("unknown_type").get();
-      fail();
-    } catch (Exception e) {
-      assertThat(e).isInstanceOf(IllegalStateException.class);
-      assertThat(e.getMessage()).contains("Fail to execute ES count request on indices 'unknown_index1, unknown_index2' on types 'unknown_type'");
-    }
-  }
-
-  @Test
-  public void get_with_string_timeout_is_not_yet_implemented() {
-    try {
-      esTester.client().prepareCount(FakeIndexDefinition.INDEX).get("1");
-      fail();
-    } catch (Exception e) {
-      assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented");
-    }
-  }
-
-  @Test
-  public void get_with_time_value_timeout_is_not_yet_implemented() {
-    try {
-      esTester.client().prepareCount(FakeIndexDefinition.INDEX).get(TimeValue.timeValueMinutes(1));
-      fail();
-    } catch (Exception e) {
-      assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented");
-    }
-  }
-
-  @Test
-  public void execute_should_throw_an_unsupported_operation_exception() {
-    try {
-      esTester.client().prepareCount(FakeIndexDefinition.INDEX).execute();
-      fail();
-    } catch (Exception e) {
-      assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");
-    }
-  }
-
-}