Skip to content

Commit

Permalink
SONAR-23111 api/system/logs now correctly return logs for data center…
Browse files Browse the repository at this point in the history
… edition
  • Loading branch information
lukasz-jarocki-sonarsource authored and sonartech committed Jan 30, 2025
1 parent 8db63c7 commit c933415
Show file tree
Hide file tree
Showing 13 changed files with 873 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
import org.sonar.server.issue.workflow.FunctionExecutor;
import org.sonar.server.issue.workflow.IssueWorkflow;
import org.sonar.server.l18n.ServerI18n;
import org.sonar.server.log.DistributedServerLogging;
import org.sonar.server.log.ServerLogging;
import org.sonar.server.measure.index.ProjectMeasuresIndexer;
import org.sonar.server.metric.IssueCountMetrics;
Expand Down Expand Up @@ -417,7 +418,6 @@ private static void populateLevel4(Container container, Props props) {
new ReportAnalysisFailureNotificationModule(),

// System
ServerLogging.class,
CEQueueStatusImpl.class,

// SonarSource editions
Expand Down Expand Up @@ -462,10 +462,12 @@ private static void populateLevel4(Container container, Props props) {

// system info
DbSection.class,
DistributedServerLogging.class,
ProcessInfoProvider.class);
} else {
container.add(
new CeCleaningModule(),
ServerLogging.class,
StandaloneCeDistributedInformation.class);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,12 @@ public void propagateExceptions() {
throw new IllegalStateException("Distributed cluster action timed out in cluster nodes " + timedOutMemberNames);
}
}

/**
* Returns any answer. No guarantees are made on the order. Use this method if you only expect exactly one answer.
* @return the first answer, if any
*/
public Optional<T> getSingleAnswer() {
return answers.values().stream().findFirst();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
package org.sonar.process.cluster.hz;

import com.hazelcast.cluster.Member;
import com.hazelcast.cluster.MemberSelector;
import java.util.List;
import org.sonar.process.ProcessId;
Expand All @@ -39,4 +40,8 @@ public static MemberSelector selectorForProcessIds(ProcessId... processIds) {
return processIdList.contains(memberProcessId);
};
}

public static MemberSelector selectorForMember(Member member) {
return m -> m.getUuid().equals(member.getUuid());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ public final class HazelcastObjects {
*/
public static final String SQ_HEALTH_STATE = "sq_health_state";

/**
* Used in the header of HTTP call between the nodes to authenticate requests
*/
public static final String AUTH_SECRET = "AUTH_SECRET";

/**
* The key of replicated map holding the secrets. Used instead of CP Subsystem.
*/
public static final String SECRETS = "SECRETS";

private HazelcastObjects() {
// Holder for clustered objects
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,14 @@

public class DistributedAnswerTest {


private final Member member = newMember(UUID.randomUUID());
private final Member member = newMember(uuidFromInt(9));
private final DistributedAnswer<String> underTest = new DistributedAnswer<>();

@Test
public void getMembers_return_all_members() {
underTest.setAnswer(member, "foo");
underTest.setTimedOut(newMember(UUID.randomUUID()));
underTest.setFailed(newMember(UUID.randomUUID()), new IOException("BOOM"));
underTest.setTimedOut(newMember(uuidFromInt(0)));
underTest.setFailed(newMember(uuidFromInt(1)), new IOException("BOOM"));

assertThat(underTest.getMembers()).hasSize(3);
}
Expand Down Expand Up @@ -100,16 +99,16 @@ public void propagateExceptions_does_nothing_if_no_members() {

@Test
public void propagateExceptions_does_nothing_if_no_errors() {
underTest.setAnswer(newMember(UUID.randomUUID()), "bar");
underTest.setAnswer(newMember(uuidFromInt(3)), "bar");

// no errors
underTest.propagateExceptions();
}

@Test
public void propagateExceptions_throws_ISE_if_at_least_one_timeout() {
UUID uuid = UUID.randomUUID();
UUID otherUuid = UUID.randomUUID();
UUID uuid = uuidFromInt(4);
UUID otherUuid = uuidFromInt(5);

underTest.setAnswer(newMember(uuid), "baz");
underTest.setTimedOut(newMember(otherUuid));
Expand All @@ -121,8 +120,8 @@ public void propagateExceptions_throws_ISE_if_at_least_one_timeout() {

@Test
public void propagateExceptions_throws_ISE_if_at_least_one_failure() {
UUID foo = UUID.randomUUID();
UUID bar = UUID.randomUUID();
UUID foo = uuidFromInt(0);
UUID bar = uuidFromInt(1);

underTest.setAnswer(newMember(bar), "baz");
underTest.setFailed(newMember(foo), new IOException("BOOM"));
Expand All @@ -132,6 +131,22 @@ public void propagateExceptions_throws_ISE_if_at_least_one_failure() {
.hasMessage("Distributed cluster action in cluster nodes " + foo + " (other nodes may have timed out)");
}

@Test
public void getSingleAnswer_returns_first_answer() {
underTest.setAnswer(newMember(uuidFromInt(0)), "foo");

assertThat(underTest.getSingleAnswer()).isNotEmpty();
}

private UUID uuidFromInt(int digit) {
return UUID.fromString("00000000-0000-0000-0000-00000000000" + digit);
}

@Test
public void getSingleAnswer_whenNoAnswer_returnEmptyOptional() {
assertThat(underTest.getSingleAnswer()).isEmpty();
}

private static Member newMember(UUID uuid) {
Member member = mock(Member.class);
when(member.getUuid()).thenReturn(uuid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import com.hazelcast.cluster.Member;
import com.hazelcast.cluster.MemberSelector;
import java.util.UUID;
import org.junit.Test;

import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -62,4 +63,37 @@ public void selecting_web_and_app_nodes() {
when(member.getAttribute(PROCESS_KEY.getKey())).thenReturn(APP.getKey());
assertThat(underTest.select(member)).isTrue();
}

@Test
public void selectorForMember_whenUuidMatches_returnTrue() {
Member member = mock();
Member member2 = mock();
UUID uuid1 = uuidFromInt(0);
when(member.getUuid()).thenReturn(uuid1);
when(member2.getUuid()).thenReturn(uuid1);

MemberSelector underTest = HazelcastMemberSelectors.selectorForMember(member);
boolean found = underTest.select(member2);

assertThat(found).isTrue();
}

private UUID uuidFromInt(int digit) {
return UUID.fromString("00000000-0000-0000-0000-00000000000" + digit);
}

@Test
public void selectorForMember_whenUuidDoesntMatch_returnTrue() {
Member member = mock();
Member member2 = mock();
UUID uuid1 = uuidFromInt(0);
UUID uuid2 = uuidFromInt(1);
when(member.getUuid()).thenReturn(uuid1);
when(member2.getUuid()).thenReturn(uuid2);

MemberSelector underTest = HazelcastMemberSelectors.selectorForMember(member);
boolean found = underTest.select(member2);

assertThat(found).isFalse();
}
}
Loading

0 comments on commit c933415

Please sign in to comment.