aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-process
diff options
context:
space:
mode:
authorAurelien Poscia <aurelien.poscia@sonarsource.com>2022-03-15 08:40:06 +0100
committersonartech <sonartech@sonarsource.com>2022-03-18 20:02:58 +0000
commit87d3bfccdbac9d330e9ad5a78da0ebbcac4d8284 (patch)
treef1b15343d98283eda2be5ac6ef5c707eb98d1f37 /server/sonar-process
parent3cd52ef6dab2fe5b7369141819fdf8f30b484f90 (diff)
downloadsonarqube-87d3bfccdbac9d330e9ad5a78da0ebbcac4d8284.tar.gz
sonarqube-87d3bfccdbac9d330e9ad5a78da0ebbcac4d8284.zip
SONAR-10179 improve consistency of start/stop log messages and identifiers of processes
Author: Aurelien Poscia <aurelien.poscia@sonarsource.com>
Diffstat (limited to 'server/sonar-process')
-rw-r--r--server/sonar-process/src/main/java/org/sonar/process/ProcessEntryPoint.java8
-rw-r--r--server/sonar-process/src/main/java/org/sonar/process/ProcessId.java23
-rw-r--r--server/sonar-process/src/test/java/org/sonar/process/ProcessEntryPointTest.java2
-rw-r--r--server/sonar-process/src/test/java/org/sonar/process/ProcessIdTest.java4
4 files changed, 19 insertions, 18 deletions
diff --git a/server/sonar-process/src/main/java/org/sonar/process/ProcessEntryPoint.java b/server/sonar-process/src/main/java/org/sonar/process/ProcessEntryPoint.java
index 51afdcf82e1..700f840f7bf 100644
--- a/server/sonar-process/src/main/java/org/sonar/process/ProcessEntryPoint.java
+++ b/server/sonar-process/src/main/java/org/sonar/process/ProcessEntryPoint.java
@@ -38,7 +38,7 @@ public class ProcessEntryPoint {
private static final long HARD_STOP_TIMEOUT_MS = 1_000L;
private final Props props;
- private final String processKey;
+ private final ProcessId processId;
private final Lifecycle lifecycle = new Lifecycle();
private final ProcessCommands commands;
private final SystemExit exit;
@@ -51,7 +51,7 @@ public class ProcessEntryPoint {
public ProcessEntryPoint(Props props, SystemExit exit, ProcessCommands commands, Runtime runtime) {
this.props = props;
- this.processKey = props.nonNullValue(PROPERTY_PROCESS_KEY);
+ this.processId = ProcessId.fromKey(props.nonNullValue(PROPERTY_PROCESS_KEY));
this.exit = exit;
this.commands = commands;
this.stopWatcher = createStopWatcher(commands, this);
@@ -80,13 +80,13 @@ public class ProcessEntryPoint {
try {
launch(logger);
} catch (Exception e) {
- logger.warn("Fail to start {}", processKey, e);
+ logger.warn("Fail to start {}", processId.getHumanReadableName(), e);
hardStop();
}
}
private void launch(Logger logger) throws InterruptedException {
- logger.info("Starting {}", processKey);
+ logger.info("Starting {}", processId.getHumanReadableName());
runtime.addShutdownHook(new Thread(() -> {
exit.setInShutdownHook();
stop();
diff --git a/server/sonar-process/src/main/java/org/sonar/process/ProcessId.java b/server/sonar-process/src/main/java/org/sonar/process/ProcessId.java
index 7ec0f477ace..380ca6aea9d 100644
--- a/server/sonar-process/src/main/java/org/sonar/process/ProcessId.java
+++ b/server/sonar-process/src/main/java/org/sonar/process/ProcessId.java
@@ -23,18 +23,21 @@ import static java.lang.String.format;
public enum ProcessId {
- APP("app", 0, "sonar"),
- ELASTICSEARCH("es", 1, "es"),
- WEB_SERVER("web", 2, "web"),
- COMPUTE_ENGINE("ce", 3, "ce");
+ APP("app", 0, "sonar", "SonarQube"),
+ ELASTICSEARCH("es", 1, "es", "ElasticSearch"),
+ WEB_SERVER("web", 2, "web", "Web Server"),
+ COMPUTE_ENGINE("ce", 3, "ce", "Compute Engine");
private final String key;
private final int ipcIndex;
private final String logFilenamePrefix;
- ProcessId(String key, int ipcIndex, String logFilenamePrefix) {
+ private final String humanReadableName;
+
+ ProcessId(String key, int ipcIndex, String logFilenamePrefix, String humanReadableName) {
this.key = key;
this.ipcIndex = ipcIndex;
this.logFilenamePrefix = logFilenamePrefix;
+ this.humanReadableName = humanReadableName;
}
public String getKey() {
@@ -55,14 +58,8 @@ public enum ProcessId {
return logFilenamePrefix;
}
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder("[");
- sb.append("key='").append(key).append('\'');
- sb.append(", ipcIndex=").append(ipcIndex);
- sb.append(", logFilenamePrefix=").append(logFilenamePrefix);
- sb.append(']');
- return sb.toString();
+ public String getHumanReadableName() {
+ return humanReadableName;
}
public static ProcessId fromKey(String key) {
diff --git a/server/sonar-process/src/test/java/org/sonar/process/ProcessEntryPointTest.java b/server/sonar-process/src/test/java/org/sonar/process/ProcessEntryPointTest.java
index ce89c599c80..69b501707c0 100644
--- a/server/sonar-process/src/test/java/org/sonar/process/ProcessEntryPointTest.java
+++ b/server/sonar-process/src/test/java/org/sonar/process/ProcessEntryPointTest.java
@@ -179,7 +179,7 @@ public class ProcessEntryPointTest {
Props props = new Props(new Properties());
props.set(PROPERTY_SHARED_PATH, temp.newFolder().getAbsolutePath());
props.set(PROPERTY_PROCESS_INDEX, "1");
- props.set(PROPERTY_PROCESS_KEY, "test");
+ props.set(PROPERTY_PROCESS_KEY, ProcessId.COMPUTE_ENGINE.getKey());
props.set(PROPERTY_GRACEFUL_STOP_TIMEOUT_MS, "30000");
return props;
}
diff --git a/server/sonar-process/src/test/java/org/sonar/process/ProcessIdTest.java b/server/sonar-process/src/test/java/org/sonar/process/ProcessIdTest.java
index 828c022a6a7..ca171b8bceb 100644
--- a/server/sonar-process/src/test/java/org/sonar/process/ProcessIdTest.java
+++ b/server/sonar-process/src/test/java/org/sonar/process/ProcessIdTest.java
@@ -39,12 +39,15 @@ public class ProcessIdTest {
public void all_values_are_unique() {
Set<Integer> ipcIndices = new HashSet<>();
Set<String> keys = new HashSet<>();
+ Set<String> humanReadableNames = new HashSet<>();
for (ProcessId processId : ProcessId.values()) {
ipcIndices.add(processId.getIpcIndex());
keys.add(processId.getKey());
+ humanReadableNames.add(processId.getHumanReadableName());
}
assertThat(ipcIndices).hasSize(ProcessId.values().length);
assertThat(keys).hasSize(ProcessId.values().length);
+ assertThat(humanReadableNames).hasSize(ProcessId.values().length);
}
@Test
@@ -68,4 +71,5 @@ public class ProcessIdTest {
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Process [foo] does not exist");
}
+
}