aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorDaniel Schwarz <daniel.schwarz@sonarsource.com>2017-05-15 10:38:07 +0200
committerDaniel Schwarz <bartfastiel@users.noreply.github.com>2017-05-26 10:58:48 +0200
commit2fbb2d7a6c766e7a33fbae4811eb3de160cd1f07 (patch)
treef308ced5826bb6d95a0d0b93d56f2a77897d2ff4 /server
parentad3acf44729e99dd40c74d99cd0529196cb2aeec (diff)
downloadsonarqube-2fbb2d7a6c766e7a33fbae4811eb3de160cd1f07.tar.gz
sonarqube-2fbb2d7a6c766e7a33fbae4811eb3de160cd1f07.zip
SONAR-9228 drop deprecated Elasticsearch count query
Diffstat (limited to 'server')
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/es/EsClient.java15
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/es/request/ProxyCountRequestBuilder.java79
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/es/EsClientTest.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/es/request/ProxyCountRequestBuilderTest.java103
4 files changed, 2 insertions, 197 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/es/EsClient.java b/server/sonar-server/src/main/java/org/sonar/server/es/EsClient.java
index 2bf75677dd9..742625ce1f1 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/es/EsClient.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/es/EsClient.java
@@ -19,10 +19,7 @@
*/
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
index a5a327e5b55..00000000000
--- a/server/sonar-server/src/main/java/org/sonar/server/es/request/ProxyCountRequestBuilder.java
+++ /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();
- }
-}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/es/EsClientTest.java b/server/sonar-server/src/test/java/org/sonar/server/es/EsClientTest.java
index f8c5172ee7d..d36aef930ed 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/es/EsClientTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/es/EsClientTest.java
@@ -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
index 5a06d2d10dd..00000000000
--- a/server/sonar-server/src/test/java/org/sonar/server/es/request/ProxyCountRequestBuilderTest.java
+++ /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");
- }
- }
-
-}