2 * SonarQube, open source software quality management tool.
3 * Copyright (C) 2008-2014 SonarSource
4 * mailto:contact AT sonarsource DOT com
6 * SonarQube is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * SonarQube is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 package org.sonar.server.search.request;
23 import org.apache.commons.lang.StringUtils;
24 import org.elasticsearch.action.ListenableActionFuture;
25 import org.elasticsearch.action.admin.cluster.stats.ClusterStatsRequestBuilder;
26 import org.elasticsearch.action.admin.cluster.stats.ClusterStatsResponse;
27 import org.elasticsearch.client.Client;
28 import org.elasticsearch.common.unit.TimeValue;
29 import org.sonar.core.profiling.Profiling;
30 import org.sonar.core.profiling.StopWatch;
31 import org.sonar.server.search.SearchClient;
33 public class ProxyClusterStatsRequestBuilder extends ClusterStatsRequestBuilder {
35 private final Profiling profiling;
37 public ProxyClusterStatsRequestBuilder(Client client, Profiling profiling) {
38 super(client.admin().cluster());
39 this.profiling = profiling;
43 public ClusterStatsResponse get() {
44 StopWatch fullProfile = profiling.start("cluster stats", Profiling.Level.FULL);
46 return super.execute().actionGet();
47 } catch (Exception e) {
48 throw new IllegalStateException(String.format("Fail to execute %s", toString()), e);
50 if (profiling.isProfilingEnabled(Profiling.Level.BASIC)) {
51 fullProfile.stop("%s", toString());
57 public ClusterStatsResponse get(TimeValue timeout) {
58 throw new IllegalStateException("Not yet implemented");
62 public ClusterStatsResponse get(String timeout) {
63 throw new IllegalStateException("Not yet implemented");
67 public ListenableActionFuture<ClusterStatsResponse> execute() {
68 throw new UnsupportedOperationException("execute() should not be called as it's used for asynchronous");
72 public String toString() {
73 StringBuilder message = new StringBuilder();
74 message.append("ES cluster stats request");
75 if (request.nodesIds().length > 0) {
76 message.append(String.format(" on nodes '%s'", StringUtils.join(request.nodesIds(), ",")));
78 return message.toString();