summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorStephane Gamard <stephane.gamard@searchbox.com>2014-08-14 10:41:37 +0200
committerStephane Gamard <stephane.gamard@searchbox.com>2014-08-14 10:41:37 +0200
commit9a1366b2550521904cbda94386d174fc3c53db2f (patch)
treee120ceb94f1d75ded853fbc9b1e07b3ed89b08d4 /server
parent46bd831271222c3a9ae5c51a77e1ad693f1cc3e9 (diff)
downloadsonarqube-9a1366b2550521904cbda94386d174fc3c53db2f.tar.gz
sonarqube-9a1366b2550521904cbda94386d174fc3c53db2f.zip
fix quality flaws
Diffstat (limited to 'server')
-rw-r--r--server/sonar-search/src/main/java/org/sonar/search/SearchServer.java59
-rw-r--r--server/sonar-search/src/main/java/org/sonar/search/script/ListUpdate.java2
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/search/SearchClient.java28
3 files changed, 48 insertions, 41 deletions
diff --git a/server/sonar-search/src/main/java/org/sonar/search/SearchServer.java b/server/sonar-search/src/main/java/org/sonar/search/SearchServer.java
index 79f514643e8..7c59e0e5d37 100644
--- a/server/sonar-search/src/main/java/org/sonar/search/SearchServer.java
+++ b/server/sonar-search/src/main/java/org/sonar/search/SearchServer.java
@@ -46,6 +46,11 @@ public class SearchServer extends MonitoredProcess {
public static final String ES_CLUSTER_PROPERTY = "sonar.cluster.name";
public static final String ES_CLUSTER_INET = "sonar.cluster.master";
+ private static final String SONAR_PATH_HOME = "sonar.path.home";
+ private static final String SONAR_PATH_DATA = "sonar.path.data";
+ private static final String SONAR_PATH_TEMP = "sonar.path.temp";
+ private static final String SONAR_PATH_LOG = "sonar.path.log";
+
private static final Integer MINIMUM_INDEX_REPLICATION = 1;
private final Set<String> nodes = new HashSet<String>();
@@ -59,13 +64,13 @@ public class SearchServer extends MonitoredProcess {
this.isBlocking = blocking;
new MinimumViableSystem().check();
- String ESNodesInets = props.of(ES_CLUSTER_INET);
- if (StringUtils.isNotEmpty(ESNodesInets)) {
- Collections.addAll(nodes, ESNodesInets.split(","));
+ String esNodesInets = props.of(ES_CLUSTER_INET);
+ if (StringUtils.isNotEmpty(esNodesInets)) {
+ Collections.addAll(nodes, esNodesInets.split(","));
}
}
- public SearchServer(Props props) throws Exception {
+ public SearchServer(Props props) {
this(props, true, true);
}
@@ -80,9 +85,7 @@ public class SearchServer extends MonitoredProcess {
@Override
protected void doStart() {
- String dataDir = props.of("sonar.path.data");
- String logDir = props.of("sonar.path.logs");
- String tempDir = props.of("sonar.path.temp");
+
Integer port = props.intOf(ES_PORT_PROPERTY);
String clusterName = props.of(ES_CLUSTER_PROPERTY);
@@ -111,9 +114,9 @@ public class SearchServer extends MonitoredProcess {
.put("http.enabled", false)
// Setting up ES paths
- .put("path.data", new File(dataDir, "es").getAbsolutePath())
- .put("path.work", new File(tempDir).getAbsolutePath())
- .put("path.logs", new File(logDir).getAbsolutePath());
+ .put("path.data", esDataDir().getAbsolutePath())
+ .put("path.work", esWorkDir().getAbsolutePath())
+ .put("path.logs", esLogDir().getAbsolutePath());
if (!nodes.isEmpty()) {
LoggerFactory.getLogger(SearchServer.class).info("Joining ES cluster with masters: {}", nodes);
@@ -121,7 +124,7 @@ public class SearchServer extends MonitoredProcess {
// Enforce a N/2+1 number of masters in cluster
esSettings.put("discovery.zen.minimum_master_nodes",
- new Double(nodes.size() / 2.0).intValue() + 1);
+ (int) Math.floor(nodes.size() / 2.0) + 1);
}
// Set cluster coordinates
@@ -134,6 +137,7 @@ public class SearchServer extends MonitoredProcess {
try {
esSettings.put("node.name", InetAddress.getLocalHost().getHostName());
} catch (Exception e) {
+ LoggerFactory.getLogger(SearchServer.class).warn("Could not determine hostname", e);
esSettings.put("node.name", "sq-" + System.currentTimeMillis());
}
}
@@ -219,6 +223,37 @@ public class SearchServer extends MonitoredProcess {
}
+ private File esHomeDir() {
+ if (!props.contains(SONAR_PATH_HOME)) {
+ throw new IllegalStateException("property 'sonar.path.home' is required");
+ }
+ return new File(props.of(SONAR_PATH_HOME));
+ }
+
+ private File esDataDir() {
+ if (props.contains(SONAR_PATH_DATA)) {
+ return new File(props.of(SONAR_PATH_DATA), "es");
+ } else {
+ return new File(esHomeDir(), "data/es");
+ }
+ }
+
+ private File esLogDir() {
+ if (props.contains(SONAR_PATH_LOG)) {
+ return new File(props.of(SONAR_PATH_LOG));
+ } else {
+ return new File(esHomeDir(), "log");
+ }
+ }
+
+ private File esWorkDir() {
+ if (props.contains(SONAR_PATH_TEMP)) {
+ return new File(props.of(SONAR_PATH_TEMP));
+ } else {
+ return new File(esHomeDir(), "temp");
+ }
+ }
+
@Override
protected void doTerminate() {
if (node != null && !node.isClosed()) {
@@ -227,7 +262,7 @@ public class SearchServer extends MonitoredProcess {
}
}
- public static void main(String... args) throws Exception {
+ public static void main(String... args) {
Props props = ConfigurationUtils.loadPropsFromCommandLineArgs(args);
new ProcessLogging().configure(props, "/org/sonar/search/logback.xml");
new SearchServer(props).start();
diff --git a/server/sonar-search/src/main/java/org/sonar/search/script/ListUpdate.java b/server/sonar-search/src/main/java/org/sonar/search/script/ListUpdate.java
index 65f3fc2ffc7..c17c56b97c9 100644
--- a/server/sonar-search/src/main/java/org/sonar/search/script/ListUpdate.java
+++ b/server/sonar-search/src/main/java/org/sonar/search/script/ListUpdate.java
@@ -83,7 +83,7 @@ public class ListUpdate extends AbstractExecutableScript {
@Override
public void setNextVar(String name, Object value) {
- if (name.equals("ctx")) {
+ if ("ctx".equals(name)) {
ctx = (Map<String, Object>) value;
}
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/search/SearchClient.java b/server/sonar-server/src/main/java/org/sonar/server/search/SearchClient.java
index 7eae3813011..1810cee8cfd 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/search/SearchClient.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/search/SearchClient.java
@@ -40,17 +40,12 @@ import org.sonar.api.config.Settings;
import org.sonar.core.profiling.Profiling;
import org.sonar.core.profiling.StopWatch;
-import java.io.File;
-
/**
* ElasticSearch Node used to connect to index.
*/
public class SearchClient extends TransportClient {
private static final String DEFAULT_HEALTH_TIMEOUT = "30s";
- private static final String SONAR_PATH_HOME = "sonar.path.home";
- private static final String SONAR_PATH_DATA = "sonar.path.data";
- private static final String SONAR_PATH_LOG = "sonar.path.log";
private final Settings settings;
private final String healthTimeout;
@@ -117,29 +112,6 @@ public class SearchClient extends TransportClient {
ESLoggerFactory.setDefaultFactory(new Slf4jESLoggerFactory());
}
- private File esHomeDir() {
- if (!settings.hasKey(SONAR_PATH_HOME)) {
- throw new IllegalStateException("property 'sonar.path.home' is required");
- }
- return new File(settings.getString(SONAR_PATH_HOME));
- }
-
- private File esDataDir() {
- if (settings.hasKey(SONAR_PATH_DATA)) {
- return new File(settings.getString(SONAR_PATH_DATA), "es");
- } else {
- return new File(settings.getString(SONAR_PATH_HOME), "data/es");
- }
- }
-
- private File esLogDir() {
- if (settings.hasKey(SONAR_PATH_LOG)) {
- return new File(settings.getString(SONAR_PATH_LOG));
- } else {
- return new File(settings.getString(SONAR_PATH_HOME), "log");
- }
- }
-
public <K extends ActionResponse> K execute(ActionRequestBuilder request) {
StopWatch fullProfile = profiling.start("search", Profiling.Level.FULL);
ListenableActionFuture acc = request.execute();