diff options
author | Eric Hartmann <hartmann.eric@gmail.Com> | 2017-03-24 10:23:29 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-24 10:23:29 +0100 |
commit | 1efd342f1c0af6f84bd8f6107ffe42e9d5d4b2b9 (patch) | |
tree | 27ee9cbdf3a269d51636c5754980bb993560feab /server/sonar-process-monitor | |
parent | c066c9818690903ca656e33060d4d77f36cbdc5b (diff) | |
download | sonarqube-1efd342f1c0af6f84bd8f6107ffe42e9d5d4b2b9.tar.gz sonarqube-1efd342f1c0af6f84bd8f6107ffe42e9d5d4b2b9.zip |
SONAR-9002 Add a log when a node is waiting for initialization
Diffstat (limited to 'server/sonar-process-monitor')
7 files changed, 52 insertions, 0 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 212fa7b33f7..cace6dfd2cf 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 @@ -51,6 +51,8 @@ public interface AppState extends AutoCloseable { void registerSonarQubeVersion(String sonarqubeVersion); + 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 3e748b70f37..5c972745771 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 @@ -25,6 +25,7 @@ import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; import javax.annotation.Nonnull; +import org.sonar.process.NetworkUtils; import org.sonar.process.ProcessId; public class AppStateImpl implements AppState { @@ -66,6 +67,11 @@ public class AppStateImpl implements AppState { } @Override + public String getLeaderHostName() { + return NetworkUtils.getHostName(); + } + + @Override public void close() { // nothing to do } 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 8359d66e08d..3a836f47a94 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 @@ -117,6 +117,8 @@ public class SchedulerImpl implements Scheduler, ProcessEventListener, ProcessLi tryToStartProcess(process, () -> javaCommandFactory.createWebCommand(false)); } else if (appState.tryToLockWebLeader()) { tryToStartProcess(process, () -> javaCommandFactory.createWebCommand(true)); + } else { + LOG.info("Waiting for initialization from " + appState.getLeaderHostName()); } } 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 cae4d880572..4b08de70890 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 @@ -90,6 +90,11 @@ public class AppStateClusterImpl implements AppState { hazelcastCluster.registerSonarQubeVersion(sonarqubeVersion); } + @Override + public String getLeaderHostName() { + return hazelcastCluster.getLeaderHostName(); + } + HazelcastCluster getHazelcastCluster() { return hazelcastCluster; } 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 39b4b18b98f..3d11c639095 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 @@ -30,10 +30,12 @@ import com.hazelcast.core.HazelcastInstance; import com.hazelcast.core.IAtomicReference; import com.hazelcast.core.ILock; import com.hazelcast.core.MapEvent; +import com.hazelcast.core.Member; import com.hazelcast.core.ReplicatedMap; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Optional; import org.sonar.application.AppStateListener; import org.sonar.process.ProcessId; @@ -196,6 +198,17 @@ public class HazelcastCluster implements AutoCloseable { return new HazelcastCluster(hzConfig); } + 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 "No leader"; + } + private class OperationalProcessListener implements EntryListener<ClusterProcess, Boolean> { @Override public void entryAdded(EntryEvent<ClusterProcess, Boolean> event) { 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 40d4196cdd8..41efc5b03ba 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 @@ -25,6 +25,7 @@ import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; import javax.annotation.Nonnull; +import org.sonar.process.NetworkUtils; import org.sonar.process.ProcessId; public class TestAppState implements AppState { @@ -76,6 +77,11 @@ public class TestAppState implements AppState { } @Override + public String getLeaderHostName() { + return NetworkUtils.getHostName(); + } + + @Override public void close() { // nothing to do } 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 a265ff1ea1d..fa73e73111e 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 @@ -32,6 +32,7 @@ import org.junit.rules.TestRule; import org.junit.rules.Timeout; import org.sonar.application.AppStateListener; import org.sonar.application.config.TestAppSettings; +import org.sonar.process.NetworkUtils; import org.sonar.process.ProcessId; import org.sonar.process.ProcessProperties; @@ -74,6 +75,23 @@ public class HazelcastClusterTest { } @Test + 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"); + } + } + + @Test + public void when_no_leader_getLeaderHostName_must_return_the_hostname() { + ClusterProperties clusterProperties = new ClusterProperties(newClusterSettings()); + try (HazelcastCluster hzCluster = HazelcastCluster.create(clusterProperties)) { + assertThat(hzCluster.tryToLockWebLeader()).isTrue(); + assertThat(hzCluster.getLeaderHostName()).isEqualTo(NetworkUtils.getHostName()); + } + } + + @Test public void members_must_be_empty_when_there_is_no_other_node() { ClusterProperties clusterProperties = new ClusterProperties(newClusterSettings()); try (HazelcastCluster hzCluster = HazelcastCluster.create(clusterProperties)) { |