diff options
author | Eric Hartmann <hartmann.eric@gmail.Com> | 2017-04-04 08:55:43 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-04 08:55:43 +0200 |
commit | d2561d2d55e2f9a967db9ebfd829dec17abbadd1 (patch) | |
tree | 0d62e887f69282c254d61327fadeca4f26a5c3fb /server/sonar-process-monitor | |
parent | 1bcea8eb2e7a2f3741030f0181b76fa857779111 (diff) | |
download | sonarqube-d2561d2d55e2f9a967db9ebfd829dec17abbadd1.tar.gz sonarqube-d2561d2d55e2f9a967db9ebfd829dec17abbadd1.zip |
SONAR-9002 Add a better log information (#1868)
Diffstat (limited to 'server/sonar-process-monitor')
7 files changed, 22 insertions, 12 deletions
diff --git a/server/sonar-process-monitor/src/main/java/org/sonar/application/AppState.java b/server/sonar-process-monitor/src/main/java/org/sonar/application/AppState.java index cace6dfd2cf..43cb69e75c3 100644 --- a/server/sonar-process-monitor/src/main/java/org/sonar/application/AppState.java +++ b/server/sonar-process-monitor/src/main/java/org/sonar/application/AppState.java @@ -19,6 +19,7 @@ */ package org.sonar.application; +import java.util.Optional; import org.sonar.process.ProcessId; public interface AppState extends AutoCloseable { @@ -51,7 +52,7 @@ public interface AppState extends AutoCloseable { void registerSonarQubeVersion(String sonarqubeVersion); - String getLeaderHostName(); + Optional<String> getLeaderHostName(); @Override void close(); diff --git a/server/sonar-process-monitor/src/main/java/org/sonar/application/AppStateImpl.java b/server/sonar-process-monitor/src/main/java/org/sonar/application/AppStateImpl.java index 5c972745771..9c5e03c296c 100644 --- a/server/sonar-process-monitor/src/main/java/org/sonar/application/AppStateImpl.java +++ b/server/sonar-process-monitor/src/main/java/org/sonar/application/AppStateImpl.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.EnumMap; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.concurrent.atomic.AtomicBoolean; import javax.annotation.Nonnull; import org.sonar.process.NetworkUtils; @@ -67,8 +68,8 @@ public class AppStateImpl implements AppState { } @Override - public String getLeaderHostName() { - return NetworkUtils.getHostName(); + public Optional<String> getLeaderHostName() { + return Optional.of(NetworkUtils.getHostName()); } @Override diff --git a/server/sonar-process-monitor/src/main/java/org/sonar/application/SchedulerImpl.java b/server/sonar-process-monitor/src/main/java/org/sonar/application/SchedulerImpl.java index 3a836f47a94..91f914b7f38 100644 --- a/server/sonar-process-monitor/src/main/java/org/sonar/application/SchedulerImpl.java +++ b/server/sonar-process-monitor/src/main/java/org/sonar/application/SchedulerImpl.java @@ -20,6 +20,7 @@ package org.sonar.application; import java.util.EnumMap; +import java.util.Optional; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; @@ -118,7 +119,12 @@ public class SchedulerImpl implements Scheduler, ProcessEventListener, ProcessLi } else if (appState.tryToLockWebLeader()) { tryToStartProcess(process, () -> javaCommandFactory.createWebCommand(true)); } else { - LOG.info("Waiting for initialization from " + appState.getLeaderHostName()); + Optional<String> leader = appState.getLeaderHostName(); + if (leader.isPresent()) { + LOG.info("Waiting for initialization from " + appState.getLeaderHostName()); + } else { + LOG.error("Initialization failed. All nodes must be restarted"); + } } } diff --git a/server/sonar-process-monitor/src/main/java/org/sonar/application/cluster/AppStateClusterImpl.java b/server/sonar-process-monitor/src/main/java/org/sonar/application/cluster/AppStateClusterImpl.java index 4b08de70890..93b6faeafdf 100644 --- a/server/sonar-process-monitor/src/main/java/org/sonar/application/cluster/AppStateClusterImpl.java +++ b/server/sonar-process-monitor/src/main/java/org/sonar/application/cluster/AppStateClusterImpl.java @@ -22,6 +22,7 @@ package org.sonar.application.cluster; import java.util.EnumMap; import java.util.Map; +import java.util.Optional; import java.util.stream.Collectors; import javax.annotation.Nonnull; import org.slf4j.Logger; @@ -91,7 +92,7 @@ public class AppStateClusterImpl implements AppState { } @Override - public String getLeaderHostName() { + public Optional<String> getLeaderHostName() { return hazelcastCluster.getLeaderHostName(); } diff --git a/server/sonar-process-monitor/src/main/java/org/sonar/application/cluster/HazelcastCluster.java b/server/sonar-process-monitor/src/main/java/org/sonar/application/cluster/HazelcastCluster.java index 3d11c639095..b8a2e7e993f 100644 --- a/server/sonar-process-monitor/src/main/java/org/sonar/application/cluster/HazelcastCluster.java +++ b/server/sonar-process-monitor/src/main/java/org/sonar/application/cluster/HazelcastCluster.java @@ -198,15 +198,15 @@ public class HazelcastCluster implements AutoCloseable { return new HazelcastCluster(hzConfig); } - String getLeaderHostName() { + Optional<String> getLeaderHostName() { String leaderId = (String) hzInstance.getAtomicReference(LEADER).get(); if (leaderId != null) { Optional<Member> leader = hzInstance.getCluster().getMembers().stream().filter(m -> m.getUuid().equals(leaderId)).findFirst(); if (leader.isPresent()) { - return leader.get().getStringAttribute(HOSTNAME); + return Optional.of(leader.get().getStringAttribute(HOSTNAME)); } } - return "No leader"; + return Optional.empty(); } private class OperationalProcessListener implements EntryListener<ClusterProcess, Boolean> { diff --git a/server/sonar-process-monitor/src/test/java/org/sonar/application/TestAppState.java b/server/sonar-process-monitor/src/test/java/org/sonar/application/TestAppState.java index 41efc5b03ba..d01b12901c7 100644 --- a/server/sonar-process-monitor/src/test/java/org/sonar/application/TestAppState.java +++ b/server/sonar-process-monitor/src/test/java/org/sonar/application/TestAppState.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.EnumMap; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.concurrent.atomic.AtomicBoolean; import javax.annotation.Nonnull; import org.sonar.process.NetworkUtils; @@ -77,8 +78,8 @@ public class TestAppState implements AppState { } @Override - public String getLeaderHostName() { - return NetworkUtils.getHostName(); + public Optional<String> getLeaderHostName() { + return Optional.of(NetworkUtils.getHostName()); } @Override diff --git a/server/sonar-process-monitor/src/test/java/org/sonar/application/cluster/HazelcastClusterTest.java b/server/sonar-process-monitor/src/test/java/org/sonar/application/cluster/HazelcastClusterTest.java index fa73e73111e..c418c07bac8 100644 --- a/server/sonar-process-monitor/src/test/java/org/sonar/application/cluster/HazelcastClusterTest.java +++ b/server/sonar-process-monitor/src/test/java/org/sonar/application/cluster/HazelcastClusterTest.java @@ -78,7 +78,7 @@ public class HazelcastClusterTest { public void when_no_leader_getLeaderHostName_must_return_NO_LEADER() { ClusterProperties clusterProperties = new ClusterProperties(newClusterSettings()); try (HazelcastCluster hzCluster = HazelcastCluster.create(clusterProperties)) { - assertThat(hzCluster.getLeaderHostName()).isEqualTo("No leader"); + assertThat(hzCluster.getLeaderHostName()).isEmpty(); } } @@ -87,7 +87,7 @@ public class HazelcastClusterTest { ClusterProperties clusterProperties = new ClusterProperties(newClusterSettings()); try (HazelcastCluster hzCluster = HazelcastCluster.create(clusterProperties)) { assertThat(hzCluster.tryToLockWebLeader()).isTrue(); - assertThat(hzCluster.getLeaderHostName()).isEqualTo(NetworkUtils.getHostName()); + assertThat(hzCluster.getLeaderHostName().get()).isEqualTo(NetworkUtils.getHostName()); } } |