diff options
author | Daniel Schwarz <daniel.schwarz@sonarsource.com> | 2017-09-18 13:28:57 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2017-09-26 23:49:38 +0200 |
commit | 257d4d9b268cdd2e517d75c42f2eee83a80cfdd1 (patch) | |
tree | 8d8bd0379d6b1b13ff9d6c6538a357bd1a7874a6 /server/sonar-process/src | |
parent | 50a29c569f8448a939877de1918ab3ff937366b8 (diff) | |
download | sonarqube-257d4d9b268cdd2e517d75c42f2eee83a80cfdd1.tar.gz sonarqube-257d4d9b268cdd2e517d75c42f2eee83a80cfdd1.zip |
SONAR-9802 allow to change the log level of a cluster
Diffstat (limited to 'server/sonar-process/src')
3 files changed, 124 insertions, 0 deletions
diff --git a/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/DistributedAnswer.java b/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/DistributedAnswer.java index be6105cc511..f5a0bc920c8 100644 --- a/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/DistributedAnswer.java +++ b/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/DistributedAnswer.java @@ -28,6 +28,7 @@ import java.util.List; import java.util.Map; import java.util.Optional; import java.util.Set; +import java.util.stream.Collectors; /** * Answer of {@link DistributedCall}, aggregating the answers from @@ -70,4 +71,21 @@ public class DistributedAnswer<T> { public void setFailed(Member member, Exception e) { failedMembers.put(member, e); } + + public void propagateExceptions() { + if (!failedMembers.isEmpty()) { + String failedMemberNames = failedMembers.keySet().stream() + .map(m -> m.getStringAttribute(HazelcastMember.Attribute.NODE_NAME)) + .collect(Collectors.joining(", ")); + throw new IllegalStateException("Distributed cluster action in cluster nodes " + failedMemberNames + " (other nodes may have timed out)", + failedMembers.values().iterator().next()); + } + + if (!timedOutMembers.isEmpty()) { + String timedOutMemberNames = timedOutMembers.stream() + .map(m -> m.getStringAttribute(HazelcastMember.Attribute.NODE_NAME)) + .collect(Collectors.joining(", ")); + throw new IllegalStateException("Distributed cluster action timed out in cluster nodes " + timedOutMemberNames); + } + } } diff --git a/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMemberSelectors.java b/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMemberSelectors.java new file mode 100644 index 00000000000..3b7abe59f89 --- /dev/null +++ b/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMemberSelectors.java @@ -0,0 +1,41 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.process.cluster.hz; + +import com.hazelcast.core.MemberSelector; +import java.util.List; +import org.sonar.process.ProcessId; + +import static java.util.Arrays.asList; +import static org.sonar.process.ProcessId.fromKey; + +public class HazelcastMemberSelectors { + + private HazelcastMemberSelectors() { + } + + public static MemberSelector selectorForProcessIds(ProcessId... processIds) { + List<ProcessId> processIdList = asList(processIds); + return member -> { + ProcessId memberProcessId = fromKey(member.getStringAttribute(HazelcastMember.Attribute.PROCESS_KEY)); + return processIdList.contains(memberProcessId); + }; + } +} diff --git a/server/sonar-process/src/test/java/org/sonar/process/cluster/hz/HazelcastMemberSelectorsTest.java b/server/sonar-process/src/test/java/org/sonar/process/cluster/hz/HazelcastMemberSelectorsTest.java new file mode 100644 index 00000000000..309e3463a32 --- /dev/null +++ b/server/sonar-process/src/test/java/org/sonar/process/cluster/hz/HazelcastMemberSelectorsTest.java @@ -0,0 +1,65 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.process.cluster.hz; + +import com.hazelcast.core.Member; +import com.hazelcast.core.MemberSelector; +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import static org.sonar.process.ProcessId.APP; +import static org.sonar.process.ProcessId.COMPUTE_ENGINE; +import static org.sonar.process.ProcessId.WEB_SERVER; +import static org.sonar.process.cluster.hz.HazelcastMember.Attribute.PROCESS_KEY; + +public class HazelcastMemberSelectorsTest { + + @Test + public void selecting_ce_nodes() throws Exception { + Member member = mock(Member.class); + MemberSelector underTest = HazelcastMemberSelectors.selectorForProcessIds(COMPUTE_ENGINE); + + when(member.getStringAttribute(PROCESS_KEY)).thenReturn(COMPUTE_ENGINE.getKey()); + assertThat(underTest.select(member)).isTrue(); + + when(member.getStringAttribute(PROCESS_KEY)).thenReturn(WEB_SERVER.getKey()); + assertThat(underTest.select(member)).isFalse(); + + when(member.getStringAttribute(PROCESS_KEY)).thenReturn(APP.getKey()); + assertThat(underTest.select(member)).isFalse(); + } + + @Test + public void selecting_web_and_app_nodes() throws Exception { + Member member = mock(Member.class); + MemberSelector underTest = HazelcastMemberSelectors.selectorForProcessIds(WEB_SERVER, APP); + + when(member.getStringAttribute(PROCESS_KEY)).thenReturn(COMPUTE_ENGINE.getKey()); + assertThat(underTest.select(member)).isFalse(); + + when(member.getStringAttribute(PROCESS_KEY)).thenReturn(WEB_SERVER.getKey()); + assertThat(underTest.select(member)).isTrue(); + + when(member.getStringAttribute(PROCESS_KEY)).thenReturn(APP.getKey()); + assertThat(underTest.select(member)).isTrue(); + } +}
\ No newline at end of file |