@@ -449,11 +449,6 @@ | |||
<artifactId>sonar-process</artifactId> | |||
<version>${project.version}</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>${project.groupId}</groupId> | |||
<artifactId>sonar-cluster</artifactId> | |||
<version>${project.version}</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>${project.groupId}</groupId> | |||
<artifactId>sonar-server</artifactId> |
@@ -13,7 +13,6 @@ | |||
<name>SonarQube :: Server :: Parent</name> | |||
<modules> | |||
<module>sonar-cluster</module> | |||
<module>sonar-process</module> | |||
<module>sonar-main</module> | |||
<module>sonar-db-core</module> |
@@ -16,11 +16,6 @@ | |||
<artifactId>sonar-server</artifactId> | |||
<scope>provided</scope> | |||
</dependency> | |||
<dependency> | |||
<groupId>${project.groupId}</groupId> | |||
<artifactId>sonar-cluster</artifactId> | |||
<scope>provided</scope> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.nanohttpd</groupId> | |||
<artifactId>nanohttpd</artifactId> |
@@ -25,11 +25,11 @@ import java.util.Set; | |||
import java.util.concurrent.locks.Lock; | |||
import org.picocontainer.Startable; | |||
import org.sonar.ce.taskprocessor.CeWorkerFactory; | |||
import org.sonar.cluster.ClusterObjectKeys; | |||
import org.sonar.cluster.localclient.HazelcastClient; | |||
import org.sonar.process.cluster.ClusterObjectKeys; | |||
import org.sonar.process.cluster.HazelcastClient; | |||
import static org.sonar.cluster.ClusterObjectKeys.WORKER_UUIDS; | |||
import static org.sonar.core.util.stream.MoreCollectors.toSet; | |||
import static org.sonar.process.cluster.ClusterObjectKeys.WORKER_UUIDS; | |||
/** | |||
* Provide the set of worker's UUID in a clustered SonarQube instance |
@@ -56,8 +56,6 @@ import org.sonar.ce.settings.ProjectConfigurationFactory; | |||
import org.sonar.ce.taskprocessor.CeProcessingScheduler; | |||
import org.sonar.ce.taskprocessor.CeTaskProcessorModule; | |||
import org.sonar.ce.user.CeUserSession; | |||
import org.sonar.cluster.ClusterProperties; | |||
import org.sonar.cluster.localclient.HazelcastLocalClient; | |||
import org.sonar.core.component.DefaultResourceTypes; | |||
import org.sonar.core.config.ConfigurationProvider; | |||
import org.sonar.core.config.CorePropertyDefinitions; | |||
@@ -76,6 +74,7 @@ import org.sonar.db.DbClient; | |||
import org.sonar.db.DefaultDatabase; | |||
import org.sonar.db.purge.PurgeProfiler; | |||
import org.sonar.process.Props; | |||
import org.sonar.process.cluster.ClusterProperties; | |||
import org.sonar.process.logging.LogbackHelper; | |||
import org.sonar.server.component.ComponentFinder; | |||
import org.sonar.server.component.index.ComponentIndexer; | |||
@@ -83,6 +82,7 @@ import org.sonar.server.computation.task.projectanalysis.ProjectAnalysisTaskModu | |||
import org.sonar.server.debt.DebtModelPluginRepository; | |||
import org.sonar.server.debt.DebtRulesXMLImporter; | |||
import org.sonar.server.event.NewAlerts; | |||
import org.sonar.server.hz.HazelcastLocalClient; | |||
import org.sonar.server.issue.IssueFieldsSetter; | |||
import org.sonar.server.issue.index.IssueIndex; | |||
import org.sonar.server.issue.index.IssueIndexer; |
@@ -27,13 +27,13 @@ import java.util.Map; | |||
import java.util.Set; | |||
import org.junit.Test; | |||
import org.sonar.ce.taskprocessor.CeWorkerFactory; | |||
import org.sonar.cluster.localclient.HazelcastLocalClient; | |||
import org.sonar.server.hz.HazelcastLocalClient; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.data.MapEntry.entry; | |||
import static org.mockito.Mockito.mock; | |||
import static org.mockito.Mockito.when; | |||
import static org.sonar.cluster.ClusterObjectKeys.WORKER_UUIDS; | |||
import static org.sonar.process.cluster.ClusterObjectKeys.WORKER_UUIDS; | |||
public class CeDistributedInformationImplTest { | |||
private String clientUUID1 = "1"; |
@@ -33,32 +33,31 @@ import org.junit.Test; | |||
import org.junit.rules.TemporaryFolder; | |||
import org.picocontainer.ComponentAdapter; | |||
import org.picocontainer.MutablePicoContainer; | |||
import org.sonar.NetworkUtils; | |||
import org.sonar.api.CoreProperties; | |||
import org.sonar.api.database.DatabaseProperties; | |||
import org.sonar.api.utils.DateUtils; | |||
import org.sonar.api.utils.System2; | |||
import org.sonar.ce.CeDistributedInformationImpl; | |||
import org.sonar.ce.StandaloneCeDistributedInformation; | |||
import org.sonar.cluster.internal.HazelcastTestHelper; | |||
import org.sonar.cluster.localclient.HazelcastLocalClient; | |||
import org.sonar.db.DbTester; | |||
import org.sonar.db.property.PropertyDto; | |||
import org.sonar.process.NetworkUtils; | |||
import org.sonar.process.ProcessId; | |||
import org.sonar.process.ProcessProperties; | |||
import org.sonar.process.Props; | |||
import org.sonar.server.hz.HazelcastLocalClient; | |||
import static java.lang.String.valueOf; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.mockito.Mockito.mock; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_ENABLED; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_LOCALENDPOINT; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_TYPE; | |||
import static org.sonar.process.ProcessEntryPoint.PROPERTY_PROCESS_INDEX; | |||
import static org.sonar.process.ProcessEntryPoint.PROPERTY_SHARED_PATH; | |||
import static org.sonar.process.ProcessProperties.PATH_DATA; | |||
import static org.sonar.process.ProcessProperties.PATH_HOME; | |||
import static org.sonar.process.ProcessProperties.PATH_TEMP; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_ENABLED; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_LOCALENDPOINT; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_NODE_TYPE; | |||
public class ComputeEngineContainerImplTest { | |||
private static final int CONTAINER_ITSELF = 1; |
@@ -18,7 +18,7 @@ | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package org.sonar.cluster.internal; | |||
package org.sonar.ce.container; | |||
import com.hazelcast.config.Config; | |||
import com.hazelcast.config.JoinConfig; | |||
@@ -28,8 +28,11 @@ import com.hazelcast.core.ClientListener; | |||
import com.hazelcast.core.Hazelcast; | |||
import com.hazelcast.core.HazelcastInstance; | |||
import java.net.InetAddress; | |||
import org.sonar.cluster.ClusterObjectKeys; | |||
import org.sonar.process.cluster.ClusterObjectKeys; | |||
/** | |||
* TODO move outside main sources | |||
*/ | |||
public class HazelcastTestHelper { | |||
private HazelcastTestHelper() { | |||
// prevents instantiation |
@@ -1,63 +0,0 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |||
<modelVersion>4.0.0</modelVersion> | |||
<parent> | |||
<groupId>org.sonarsource.sonarqube</groupId> | |||
<artifactId>server</artifactId> | |||
<version>6.6-SNAPSHOT</version> | |||
<relativePath>..</relativePath> | |||
</parent> | |||
<artifactId>sonar-cluster</artifactId> | |||
<name>SonarQube :: Cluster</name> | |||
<dependencies> | |||
<dependency> | |||
<groupId>${project.groupId}</groupId> | |||
<artifactId>sonar-plugin-api</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>com.hazelcast</groupId> | |||
<artifactId>hazelcast-client</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.picocontainer</groupId> | |||
<artifactId>picocontainer</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>com.google.guava</groupId> | |||
<artifactId>guava</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>commons-lang</groupId> | |||
<artifactId>commons-lang</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>com.google.code.findbugs</groupId> | |||
<artifactId>jsr305</artifactId> | |||
<scope>provided</scope> | |||
</dependency> | |||
<!-- unit tests --> | |||
<dependency> | |||
<groupId>junit</groupId> | |||
<artifactId>junit</artifactId> | |||
<scope>test</scope> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.assertj</groupId> | |||
<artifactId>assertj-core</artifactId> | |||
<scope>test</scope> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.mockito</groupId> | |||
<artifactId>mockito-core</artifactId> | |||
<scope>test</scope> | |||
</dependency> | |||
<dependency> | |||
<groupId>ch.qos.logback</groupId> | |||
<artifactId>logback-classic</artifactId> | |||
<scope>test</scope> | |||
</dependency> | |||
</dependencies> | |||
</project> |
@@ -1,23 +0,0 @@ | |||
/* | |||
* 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. | |||
*/ | |||
@ParametersAreNonnullByDefault | |||
package org.sonar.cluster.localclient; | |||
import javax.annotation.ParametersAreNonnullByDefault; |
@@ -1,23 +0,0 @@ | |||
/* | |||
* 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. | |||
*/ | |||
@ParametersAreNonnullByDefault | |||
package org.sonar; | |||
import javax.annotation.ParametersAreNonnullByDefault; |
@@ -1,92 +0,0 @@ | |||
/* | |||
* 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; | |||
import java.net.InetAddress; | |||
import java.util.HashSet; | |||
import java.util.Set; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import static java.net.InetAddress.getLoopbackAddress; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.mockito.Matchers.any; | |||
import static org.mockito.Mockito.mock; | |||
import static org.mockito.Mockito.when; | |||
public class NetworkUtilsImplTest { | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
private NetworkUtilsImpl underTest = new NetworkUtilsImpl(); | |||
@Test | |||
public void getNextAvailablePort_never_returns_the_same_port_in_current_jvm() { | |||
Set<Integer> ports = new HashSet<>(); | |||
for (int i = 0; i < 100; i++) { | |||
int port = underTest.getNextAvailablePort(getLoopbackAddress()); | |||
assertThat(port).isGreaterThan(1_023); | |||
ports.add(port); | |||
} | |||
assertThat(ports).hasSize(100); | |||
} | |||
@Test | |||
public void getNextAvailablePort_retries_to_get_available_port_when_port_has_already_been_allocated() { | |||
NetworkUtilsImpl.PortAllocator portAllocator = mock(NetworkUtilsImpl.PortAllocator.class); | |||
when(portAllocator.getAvailable(any(InetAddress.class))).thenReturn(9_000, 9_000, 9_000, 9_100); | |||
InetAddress address = getLoopbackAddress(); | |||
assertThat(underTest.getNextAvailablePort(address, portAllocator)).isEqualTo(9_000); | |||
assertThat(underTest.getNextAvailablePort(address, portAllocator)).isEqualTo(9_100); | |||
} | |||
@Test | |||
public void getNextAvailablePort_does_not_return_special_ports() { | |||
NetworkUtilsImpl.PortAllocator portAllocator = mock(NetworkUtilsImpl.PortAllocator.class); | |||
when(portAllocator.getAvailable(any(InetAddress.class))).thenReturn(900, 903, 1_059); | |||
// the two first ports are banned because < 1023, so 1_059 is returned | |||
assertThat(underTest.getNextAvailablePort(getLoopbackAddress(), portAllocator)).isEqualTo(1_059); | |||
} | |||
@Test | |||
public void getNextAvailablePort_throws_ISE_if_too_many_attempts() { | |||
NetworkUtilsImpl.PortAllocator portAllocator = mock(NetworkUtilsImpl.PortAllocator.class); | |||
when(portAllocator.getAvailable(any(InetAddress.class))).thenReturn(900); | |||
expectedException.expect(IllegalStateException.class); | |||
expectedException.expectMessage("Fail to find an available port on "); | |||
underTest.getNextAvailablePort(getLoopbackAddress(), portAllocator); | |||
} | |||
@Test | |||
public void getHostname_must_return_a_value() { | |||
assertThat(underTest.getHostname()).containsPattern(".+"); | |||
} | |||
@Test | |||
public void getIPAddresses_must_return_a_value() { | |||
assertThat(underTest.getIPAddresses()).matches("(\\d+\\.\\d+\\.\\d+\\.\\d+,?)+"); | |||
} | |||
} |
@@ -1,47 +0,0 @@ | |||
/* | |||
* 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.cluster; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
public class NodeTypeTest { | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
@Test | |||
public void test_parse() { | |||
assertThat(NodeType.parse("application")).isEqualTo(NodeType.APPLICATION); | |||
assertThat(NodeType.parse("search")).isEqualTo(NodeType.SEARCH); | |||
} | |||
@Test | |||
public void parse_an_unknown_value_must_throw_IAE() { | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("Invalid value for "); | |||
NodeType.parse("XYZ"); | |||
} | |||
} |
@@ -1,98 +0,0 @@ | |||
/* | |||
* 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.cluster.health; | |||
import java.util.Random; | |||
import java.util.concurrent.TimeUnit; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.mockito.ArgumentCaptor; | |||
import org.sonar.api.utils.log.LogTester; | |||
import org.sonar.api.utils.log.LoggerLevel; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.fail; | |||
import static org.mockito.Matchers.eq; | |||
import static org.mockito.Mockito.mock; | |||
import static org.mockito.Mockito.verify; | |||
import static org.mockito.Mockito.verifyZeroInteractions; | |||
import static org.mockito.Mockito.when; | |||
public class HealthStateRefresherTest { | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
@Rule | |||
public LogTester logTester = new LogTester(); | |||
private Random random = new Random(); | |||
private NodeDetailsTestSupport testSupport = new NodeDetailsTestSupport(random); | |||
private HealthStateRefresherExecutorService executorService = mock(HealthStateRefresherExecutorService.class); | |||
private NodeHealthProvider nodeHealthProvider = mock(NodeHealthProvider.class); | |||
private SharedHealthState sharedHealthState = mock(SharedHealthState.class); | |||
private HealthStateRefresher underTest = new HealthStateRefresher(executorService, nodeHealthProvider, sharedHealthState); | |||
@Test | |||
public void start_adds_runnable_with_10_second_delay_and_initial_delay_putting_NodeHealth_from_provider_into_SharedHealthState() { | |||
ArgumentCaptor<Runnable> runnableCaptor = ArgumentCaptor.forClass(Runnable.class); | |||
NodeHealth[] nodeHealths = { | |||
testSupport.randomNodeHealth(), | |||
testSupport.randomNodeHealth(), | |||
testSupport.randomNodeHealth() | |||
}; | |||
Error expected = new Error("Simulating exception raised by NodeHealthProvider"); | |||
when(nodeHealthProvider.get()) | |||
.thenReturn(nodeHealths[0]) | |||
.thenReturn(nodeHealths[1]) | |||
.thenReturn(nodeHealths[2]) | |||
.thenThrow(expected); | |||
underTest.start(); | |||
verify(executorService).scheduleWithFixedDelay(runnableCaptor.capture(), eq(1L), eq(10L), eq(TimeUnit.SECONDS)); | |||
Runnable runnable = runnableCaptor.getValue(); | |||
runnable.run(); | |||
runnable.run(); | |||
runnable.run(); | |||
verify(sharedHealthState).writeMine(nodeHealths[0]); | |||
verify(sharedHealthState).writeMine(nodeHealths[1]); | |||
verify(sharedHealthState).writeMine(nodeHealths[2]); | |||
try { | |||
runnable.run(); | |||
assertThat(logTester.logs()).hasSize(1); | |||
assertThat(logTester.logs(LoggerLevel.ERROR).iterator().next()) | |||
.isEqualTo("An error occurred while attempting to refresh HealthState of the current node in the shared state:"); | |||
} catch (IllegalStateException e) { | |||
fail("Runnable should catch any Throwable"); | |||
} | |||
} | |||
@Test | |||
public void stop_has_no_effect() { | |||
underTest.stop(); | |||
verify(sharedHealthState).clearMine(); | |||
verifyZeroInteractions(executorService, nodeHealthProvider); | |||
} | |||
} |
@@ -1,247 +0,0 @@ | |||
/* | |||
* 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.cluster.health; | |||
import java.io.ByteArrayInputStream; | |||
import java.io.IOException; | |||
import java.io.ObjectInputStream; | |||
import java.util.Random; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.sonar.cluster.health.NodeDetails.newNodeDetailsBuilder; | |||
public class NodeDetailsTest { | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
private Random random = new Random(); | |||
private NodeDetailsTestSupport testSupport = new NodeDetailsTestSupport(random); | |||
private NodeDetails.Type randomType = testSupport.randomType(); | |||
private NodeDetails.Builder builderUnderTest = newNodeDetailsBuilder(); | |||
@Test | |||
public void setType_throws_NPE_if_arg_is_null() { | |||
expectedException.expect(NullPointerException.class); | |||
expectedException.expectMessage("type can't be null"); | |||
builderUnderTest.setType(null); | |||
} | |||
@Test | |||
public void setName_throws_NPE_if_arg_is_null() { | |||
expectedException.expect(NullPointerException.class); | |||
expectedException.expectMessage("name can't be null"); | |||
builderUnderTest.setName(null); | |||
} | |||
@Test | |||
public void setName_throws_IAE_if_arg_is_empty() { | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("name can't be empty"); | |||
builderUnderTest.setName(""); | |||
} | |||
@Test | |||
public void setName_throws_IAE_if_arg_is_empty_after_trim() { | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("name can't be empty"); | |||
builderUnderTest.setName(" "); | |||
} | |||
@Test | |||
public void setHost_throws_NPE_if_arg_is_null() { | |||
expectedException.expect(NullPointerException.class); | |||
expectedException.expectMessage("host can't be null"); | |||
builderUnderTest.setHost(null); | |||
} | |||
@Test | |||
public void setHost_throws_IAE_if_arg_is_empty() { | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("host can't be empty"); | |||
builderUnderTest.setHost(""); | |||
} | |||
@Test | |||
public void setHost_throws_IAE_if_arg_is_empty_after_trim() { | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("host can't be empty"); | |||
builderUnderTest.setHost(" "); | |||
} | |||
@Test | |||
public void setPort_throws_IAE_if_arg_is_less_than_1() { | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("port must be > 0"); | |||
builderUnderTest.setPort(-random.nextInt(5)); | |||
} | |||
@Test | |||
public void setStarted_throws_IAE_if_arg_is_less_than_1() { | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("startedAt must be > 0"); | |||
builderUnderTest.setStartedAt(-random.nextInt(5)); | |||
} | |||
@Test | |||
public void build_throws_NPE_if_type_is_null() { | |||
expectedException.expect(NullPointerException.class); | |||
expectedException.expectMessage("type can't be null"); | |||
builderUnderTest.build(); | |||
} | |||
@Test | |||
public void build_throws_NPE_if_name_is_null() { | |||
builderUnderTest | |||
.setType(randomType); | |||
expectedException.expect(NullPointerException.class); | |||
expectedException.expectMessage("name can't be null"); | |||
builderUnderTest.build(); | |||
} | |||
@Test | |||
public void build_throws_NPE_if_host_is_null() { | |||
builderUnderTest | |||
.setType(randomType) | |||
.setName(randomAlphanumeric(2)); | |||
expectedException.expect(NullPointerException.class); | |||
expectedException.expectMessage("host can't be null"); | |||
builderUnderTest.build(); | |||
} | |||
@Test | |||
public void build_throws_IAE_if_setPort_not_called() { | |||
builderUnderTest | |||
.setType(randomType) | |||
.setName(randomAlphanumeric(2)) | |||
.setHost(randomAlphanumeric(3)); | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("port must be > 0"); | |||
builderUnderTest.build(); | |||
} | |||
@Test | |||
public void build_throws_IAE_if_setStarted_not_called() { | |||
builderUnderTest | |||
.setType(randomType) | |||
.setName(randomAlphanumeric(2)) | |||
.setHost(randomAlphanumeric(3)) | |||
.setPort(1 + random.nextInt(33)); | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("startedAt must be > 0"); | |||
builderUnderTest.build(); | |||
} | |||
@Test | |||
public void equals_is_based_on_content() { | |||
NodeDetails.Builder builder = testSupport.randomNodeDetailsBuilder(); | |||
NodeDetails underTest = builder.build(); | |||
assertThat(underTest).isEqualTo(underTest); | |||
assertThat(builder.build()) | |||
.isEqualTo(underTest) | |||
.isNotSameAs(underTest); | |||
assertThat(underTest).isNotEqualTo(null); | |||
assertThat(underTest).isNotEqualTo(new Object()); | |||
} | |||
@Test | |||
public void hashcode_is_based_on_content() { | |||
NodeDetails.Builder builder = testSupport.randomNodeDetailsBuilder(); | |||
NodeDetails underTest = builder.build(); | |||
assertThat(builder.build().hashCode()) | |||
.isEqualTo(underTest.hashCode()); | |||
} | |||
@Test | |||
public void NodeDetails_is_Externalizable() throws IOException, ClassNotFoundException { | |||
NodeDetails source = testSupport.randomNodeDetails(); | |||
byte[] byteArray = testSupport.serialize(source); | |||
NodeDetails underTest = (NodeDetails) new ObjectInputStream(new ByteArrayInputStream(byteArray)).readObject(); | |||
assertThat(underTest).isEqualTo(source); | |||
} | |||
@Test | |||
public void verify_toString() { | |||
String name = randomAlphanumeric(3); | |||
String host = randomAlphanumeric(10); | |||
int port = 1 + random.nextInt(10); | |||
long startedAt = 1 + random.nextInt(666); | |||
NodeDetails underTest = builderUnderTest | |||
.setType(randomType) | |||
.setName(name) | |||
.setHost(host) | |||
.setPort(port) | |||
.setStartedAt(startedAt) | |||
.build(); | |||
assertThat(underTest.toString()) | |||
.isEqualTo("NodeDetails{type=" + randomType + ", name='" + name + "', host='" + host + "', port=" + port + ", startedAt=" + startedAt + "}"); | |||
} | |||
@Test | |||
public void verify_getters() { | |||
String name = randomAlphanumeric(3); | |||
String host = randomAlphanumeric(10); | |||
int port = 1 + random.nextInt(10); | |||
long startedAt = 1 + random.nextInt(666); | |||
NodeDetails underTest = builderUnderTest | |||
.setType(randomType) | |||
.setName(name) | |||
.setHost(host) | |||
.setPort(port) | |||
.setStartedAt(startedAt) | |||
.build(); | |||
assertThat(underTest.getType()).isEqualTo(randomType); | |||
assertThat(underTest.getName()).isEqualTo(name); | |||
assertThat(underTest.getHost()).isEqualTo(host); | |||
assertThat(underTest.getPort()).isEqualTo(port); | |||
assertThat(underTest.getStartedAt()).isEqualTo(startedAt); | |||
} | |||
} |
@@ -1,88 +0,0 @@ | |||
/* | |||
* 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.cluster.health; | |||
import java.io.ByteArrayOutputStream; | |||
import java.io.IOException; | |||
import java.io.ObjectOutputStream; | |||
import java.util.Random; | |||
import java.util.stream.IntStream; | |||
import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; | |||
import static org.sonar.cluster.health.NodeDetails.newNodeDetailsBuilder; | |||
import static org.sonar.cluster.health.NodeHealth.newNodeHealthBuilder; | |||
public class NodeDetailsTestSupport { | |||
private final Random random; | |||
public NodeDetailsTestSupport() { | |||
this(new Random()); | |||
} | |||
NodeDetailsTestSupport(Random random) { | |||
this.random = random; | |||
} | |||
NodeHealth.Status randomStatus() { | |||
return NodeHealth.Status.values()[random.nextInt(NodeHealth.Status.values().length)]; | |||
} | |||
NodeHealth randomNodeHealth() { | |||
return randomBuilder().build(); | |||
} | |||
NodeHealth.Builder randomBuilder() { | |||
return randomBuilder(0); | |||
} | |||
NodeHealth.Builder randomBuilder(int minCauseCount) { | |||
NodeHealth.Builder builder = newNodeHealthBuilder() | |||
.setStatus(randomStatus()) | |||
.setDetails(randomNodeDetails()); | |||
IntStream.range(0, minCauseCount + random.nextInt(2)).mapToObj(i -> randomAlphanumeric(4)).forEach(builder::addCause); | |||
return builder; | |||
} | |||
NodeDetails randomNodeDetails() { | |||
return randomNodeDetailsBuilder() | |||
.build(); | |||
} | |||
NodeDetails.Builder randomNodeDetailsBuilder() { | |||
return newNodeDetailsBuilder() | |||
.setType(randomType()) | |||
.setName(randomAlphanumeric(3)) | |||
.setHost(randomAlphanumeric(10)) | |||
.setPort(1 + random.nextInt(10)) | |||
.setStartedAt(1 + random.nextInt(666)); | |||
} | |||
NodeDetails.Type randomType() { | |||
return NodeDetails.Type.values()[random.nextInt(NodeDetails.Type.values().length)]; | |||
} | |||
static byte[] serialize(Object source) throws IOException { | |||
ByteArrayOutputStream out = new ByteArrayOutputStream(); | |||
try (ObjectOutputStream objectOutputStream = new ObjectOutputStream(out)) { | |||
objectOutputStream.writeObject(source); | |||
} | |||
return out.toByteArray(); | |||
} | |||
} |
@@ -1,195 +0,0 @@ | |||
/* | |||
* 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.cluster.health; | |||
import java.io.ByteArrayInputStream; | |||
import java.io.IOException; | |||
import java.io.ObjectInputStream; | |||
import java.util.Arrays; | |||
import java.util.Random; | |||
import java.util.stream.IntStream; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.sonar.cluster.health.NodeHealth.newNodeHealthBuilder; | |||
public class NodeHealthTest { | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
private Random random = new Random(); | |||
private NodeDetailsTestSupport testSupport = new NodeDetailsTestSupport(random); | |||
private NodeHealth.Status randomStatus = testSupport.randomStatus(); | |||
private NodeHealth.Builder builderUnderTest = newNodeHealthBuilder(); | |||
@Test | |||
public void setStatus_throws_NPE_if_arg_is_null() { | |||
expectedException.expect(NullPointerException.class); | |||
expectedException.expectMessage("status can't be null"); | |||
builderUnderTest.setStatus(null); | |||
} | |||
@Test | |||
public void setDetails_throws_NPE_if_arg_is_null() { | |||
expectedException.expect(NullPointerException.class); | |||
expectedException.expectMessage("details can't be null"); | |||
builderUnderTest.setDetails(null); | |||
} | |||
@Test | |||
public void build_throws_NPE_if_status_is_null() { | |||
expectedException.expect(NullPointerException.class); | |||
expectedException.expectMessage("status can't be null"); | |||
builderUnderTest.build(); | |||
} | |||
@Test | |||
public void build_throws_NPE_if_details_is_null() { | |||
builderUnderTest.setStatus(randomStatus); | |||
expectedException.expect(NullPointerException.class); | |||
expectedException.expectMessage("details can't be null"); | |||
builderUnderTest.build(); | |||
} | |||
@Test | |||
public void clearClauses_clears_clauses_of_builder() { | |||
NodeHealth.Builder underTest = testSupport.randomBuilder(); | |||
NodeHealth original = underTest | |||
.addCause(randomAlphanumeric(3)) | |||
.build(); | |||
underTest.clearCauses(); | |||
NodeHealth second = underTest.build(); | |||
assertThat(second.getStatus()).isEqualTo(original.getStatus()); | |||
assertThat(second.getDetails()).isEqualTo(original.getDetails()); | |||
assertThat(second.getCauses()).isEmpty(); | |||
} | |||
@Test | |||
public void builder_can_be_reused() { | |||
NodeHealth.Builder builder = testSupport.randomBuilder(1); | |||
NodeHealth original = builder.build(); | |||
NodeHealth second = builder.build(); | |||
NodeHealth.Status newRandomStatus = NodeHealth.Status.values()[random.nextInt(NodeHealth.Status.values().length)]; | |||
NodeDetails newNodeDetails = testSupport.randomNodeDetails(); | |||
builder | |||
.clearCauses() | |||
.setStatus(newRandomStatus) | |||
.setDetails(newNodeDetails); | |||
String[] newCauses = IntStream.range(0, 1 + random.nextInt(2)).mapToObj(i -> randomAlphanumeric(4)).toArray(String[]::new); | |||
Arrays.stream(newCauses).forEach(builder::addCause); | |||
NodeHealth newNodeHealth = builder.build(); | |||
assertThat(second).isEqualTo(original); | |||
assertThat(newNodeHealth.getStatus()).isEqualTo(newRandomStatus); | |||
assertThat(newNodeHealth.getDetails()).isEqualTo(newNodeDetails); | |||
assertThat(newNodeHealth.getCauses()).containsOnly(newCauses); | |||
} | |||
@Test | |||
public void equals_is_based_on_content() { | |||
NodeHealth.Builder builder = testSupport.randomBuilder(); | |||
NodeHealth underTest = builder.build(); | |||
assertThat(underTest).isEqualTo(underTest); | |||
assertThat(builder.build()) | |||
.isEqualTo(underTest) | |||
.isNotSameAs(underTest); | |||
assertThat(underTest).isNotEqualTo(null); | |||
assertThat(underTest).isNotEqualTo(new Object()); | |||
} | |||
@Test | |||
public void hashcode_is_based_on_content() { | |||
NodeHealth.Builder builder = testSupport.randomBuilder(); | |||
NodeHealth underTest = builder.build(); | |||
assertThat(builder.build().hashCode()) | |||
.isEqualTo(underTest.hashCode()); | |||
} | |||
@Test | |||
public void class_is_serializable_with_causes() throws IOException, ClassNotFoundException { | |||
NodeHealth source = testSupport.randomBuilder(1).build(); | |||
byte[] bytes = testSupport.serialize(source); | |||
NodeHealth underTest = (NodeHealth) new ObjectInputStream(new ByteArrayInputStream(bytes)).readObject(); | |||
assertThat(underTest).isEqualTo(source); | |||
} | |||
@Test | |||
public void class_is_serializable_without_causes() throws IOException, ClassNotFoundException { | |||
NodeHealth.Builder builder = newNodeHealthBuilder() | |||
.setStatus(randomStatus) | |||
.setDetails(testSupport.randomNodeDetails()); | |||
NodeHealth source = builder.build(); | |||
byte[] bytes = testSupport.serialize(source); | |||
NodeHealth underTest = (NodeHealth) new ObjectInputStream(new ByteArrayInputStream(bytes)).readObject(); | |||
assertThat(underTest).isEqualTo(source); | |||
} | |||
@Test | |||
public void verify_toString() { | |||
NodeDetails nodeDetails = testSupport.randomNodeDetails(); | |||
String cause = randomAlphanumeric(4); | |||
NodeHealth.Builder builder = builderUnderTest | |||
.setStatus(randomStatus) | |||
.setDetails(nodeDetails) | |||
.addCause(cause); | |||
NodeHealth underTest = builder.build(); | |||
assertThat(underTest.toString()) | |||
.isEqualTo("NodeHealth{status=" + randomStatus + ", causes=[" + cause + "], details=" + nodeDetails + "}"); | |||
} | |||
@Test | |||
public void verify_getters() { | |||
NodeDetails nodeDetails = testSupport.randomNodeDetails(); | |||
NodeHealth.Builder builder = builderUnderTest | |||
.setStatus(randomStatus) | |||
.setDetails(nodeDetails); | |||
String[] causes = IntStream.range(0, random.nextInt(10)).mapToObj(i -> randomAlphanumeric(4)).toArray(String[]::new); | |||
Arrays.stream(causes).forEach(builder::addCause); | |||
NodeHealth underTest = builder.build(); | |||
assertThat(underTest.getStatus()).isEqualTo(randomStatus); | |||
assertThat(underTest.getDetails()).isEqualTo(nodeDetails); | |||
assertThat(underTest.getCauses()).containsOnly(causes); | |||
} | |||
} |
@@ -1,252 +0,0 @@ | |||
/* | |||
* 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.cluster.health; | |||
import com.google.common.collect.ImmutableSet; | |||
import java.util.HashMap; | |||
import java.util.Map; | |||
import java.util.Random; | |||
import java.util.stream.IntStream; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.mockito.Mockito; | |||
import org.sonar.api.utils.log.LogTester; | |||
import org.sonar.api.utils.log.LoggerLevel; | |||
import org.sonar.cluster.localclient.HazelcastClient; | |||
import static java.util.Collections.singleton; | |||
import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.mockito.Mockito.doReturn; | |||
import static org.mockito.Mockito.mock; | |||
import static org.mockito.Mockito.verify; | |||
import static org.mockito.Mockito.verifyNoMoreInteractions; | |||
import static org.mockito.Mockito.when; | |||
import static org.sonar.cluster.health.NodeDetails.newNodeDetailsBuilder; | |||
import static org.sonar.cluster.health.NodeHealth.newNodeHealthBuilder; | |||
public class SharedHealthStateImplTest { | |||
private static final String MAP_SQ_HEALTH_STATE = "sq_health_state"; | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
@Rule | |||
public LogTester logTester = new LogTester(); | |||
private final Random random = new Random(); | |||
private long clusterTime = 99 + Math.abs(random.nextInt(9621)); | |||
private HazelcastClient hazelcastClient = Mockito.mock(HazelcastClient.class); | |||
private SharedHealthStateImpl underTest = new SharedHealthStateImpl(hazelcastClient); | |||
@Test | |||
public void write_fails_with_NPE_if_arg_is_null() { | |||
expectedException.expect(NullPointerException.class); | |||
expectedException.expectMessage("nodeHealth can't be null"); | |||
underTest.writeMine(null); | |||
} | |||
@Test | |||
public void write_put_arg_into_map_sq_health_state_under_current_client_uuid() { | |||
NodeHealth nodeHealth = randomNodeHealth(); | |||
Map<String, TimestampedNodeHealth> map = new HashMap<>(); | |||
doReturn(map).when(hazelcastClient).getReplicatedMap(MAP_SQ_HEALTH_STATE); | |||
long clusterTime = random.nextLong(); | |||
String uuid = randomAlphanumeric(5); | |||
when(hazelcastClient.getUUID()).thenReturn(uuid); | |||
when(hazelcastClient.getClusterTime()).thenReturn(clusterTime); | |||
underTest.writeMine(nodeHealth); | |||
assertThat(map.size()).isEqualTo(1); | |||
assertThat(map.get(uuid)).isEqualTo(new TimestampedNodeHealth(nodeHealth, clusterTime)); | |||
assertThat(logTester.logs()).isEmpty(); | |||
} | |||
@Test | |||
public void write_logs_map_sq_health_state_content_and_NodeHealth_to_be_added_if_TRACE() { | |||
logTester.setLevel(LoggerLevel.TRACE); | |||
NodeHealth newNodeHealth = randomNodeHealth(); | |||
Map<String, TimestampedNodeHealth> map = new HashMap<>(); | |||
map.put(randomAlphanumeric(4), new TimestampedNodeHealth(randomNodeHealth(), random.nextLong())); | |||
doReturn(new HashMap<>(map)).when(hazelcastClient).getReplicatedMap(MAP_SQ_HEALTH_STATE); | |||
String uuid = randomAlphanumeric(5); | |||
when(hazelcastClient.getUUID()).thenReturn(uuid); | |||
underTest.writeMine(newNodeHealth); | |||
assertThat(logTester.logs()).hasSize(1); | |||
assertThat(logTester.logs(LoggerLevel.TRACE).iterator().next()).isEqualTo("Reading " + map + " and adding " + newNodeHealth); | |||
} | |||
@Test | |||
public void readAll_returns_all_NodeHealth_in_map_sq_health_state_for_existing_client_uuids_aged_less_than_30_seconds() { | |||
NodeHealth[] nodeHealths = IntStream.range(0, 1 + random.nextInt(6)).mapToObj(i -> randomNodeHealth()).toArray(NodeHealth[]::new); | |||
Map<String, TimestampedNodeHealth> allNodeHealths = new HashMap<>(); | |||
Map<String, NodeHealth> expected = new HashMap<>(); | |||
String randomUuidBase = randomAlphanumeric(5); | |||
for (int i = 0; i < nodeHealths.length; i++) { | |||
String memberUuid = randomUuidBase + i; | |||
TimestampedNodeHealth timestampedNodeHealth = new TimestampedNodeHealth(nodeHealths[i], clusterTime - random.nextInt(30 * 1000)); | |||
allNodeHealths.put(memberUuid, timestampedNodeHealth); | |||
if (random.nextBoolean()) { | |||
expected.put(memberUuid, nodeHealths[i]); | |||
} | |||
} | |||
doReturn(allNodeHealths).when(hazelcastClient).getReplicatedMap(MAP_SQ_HEALTH_STATE); | |||
when(hazelcastClient.getMemberUuids()).thenReturn(expected.keySet()); | |||
when(hazelcastClient.getClusterTime()).thenReturn(clusterTime); | |||
assertThat(underTest.readAll()) | |||
.containsOnly(expected.values().stream().toArray(NodeHealth[]::new)); | |||
assertThat(logTester.logs()).isEmpty(); | |||
} | |||
@Test | |||
public void readAll_ignores_NodeHealth_of_30_seconds_before_cluster_time() { | |||
NodeHealth nodeHealth = randomNodeHealth(); | |||
Map<String, TimestampedNodeHealth> map = new HashMap<>(); | |||
String memberUuid = randomAlphanumeric(5); | |||
TimestampedNodeHealth timestampedNodeHealth = new TimestampedNodeHealth(nodeHealth, clusterTime - 30 * 1000); | |||
map.put(memberUuid, timestampedNodeHealth); | |||
doReturn(map).when(hazelcastClient).getReplicatedMap(MAP_SQ_HEALTH_STATE); | |||
when(hazelcastClient.getMemberUuids()).thenReturn(map.keySet()); | |||
when(hazelcastClient.getClusterTime()).thenReturn(clusterTime); | |||
assertThat(underTest.readAll()).isEmpty(); | |||
} | |||
@Test | |||
public void readAll_ignores_NodeHealth_of_more_than_30_seconds_before_cluster_time() { | |||
NodeHealth nodeHealth = randomNodeHealth(); | |||
Map<String, TimestampedNodeHealth> map = new HashMap<>(); | |||
String memberUuid = randomAlphanumeric(5); | |||
TimestampedNodeHealth timestampedNodeHealth = new TimestampedNodeHealth(nodeHealth, clusterTime - 30 * 1000 - random.nextInt(99)); | |||
map.put(memberUuid, timestampedNodeHealth); | |||
doReturn(map).when(hazelcastClient).getReplicatedMap(MAP_SQ_HEALTH_STATE); | |||
when(hazelcastClient.getMemberUuids()).thenReturn(map.keySet()); | |||
when(hazelcastClient.getClusterTime()).thenReturn(clusterTime); | |||
assertThat(underTest.readAll()).isEmpty(); | |||
} | |||
@Test | |||
public void readAll_logs_map_sq_health_state_content_and_the_content_effectively_returned_if_TRACE() { | |||
logTester.setLevel(LoggerLevel.TRACE); | |||
Map<String, TimestampedNodeHealth> map = new HashMap<>(); | |||
String uuid = randomAlphanumeric(44); | |||
NodeHealth nodeHealth = randomNodeHealth(); | |||
map.put(uuid, new TimestampedNodeHealth(nodeHealth, clusterTime - 1)); | |||
when(hazelcastClient.getClusterTime()).thenReturn(clusterTime); | |||
when(hazelcastClient.getMemberUuids()).thenReturn(singleton(uuid)); | |||
doReturn(map).when(hazelcastClient).getReplicatedMap(MAP_SQ_HEALTH_STATE); | |||
underTest.readAll(); | |||
assertThat(logTester.logs()).hasSize(1); | |||
assertThat(logTester.logs(LoggerLevel.TRACE)).containsOnly("Reading " + new HashMap<>(map) + " and keeping " + singleton(nodeHealth)); | |||
} | |||
@Test | |||
public void readAll_logs_message_for_each_non_existing_member_ignored_if_TRACE() { | |||
logTester.setLevel(LoggerLevel.TRACE); | |||
Map<String, TimestampedNodeHealth> map = new HashMap<>(); | |||
String memberUuid1 = randomAlphanumeric(44); | |||
String memberUuid2 = randomAlphanumeric(44); | |||
map.put(memberUuid1, new TimestampedNodeHealth(randomNodeHealth(), clusterTime - 1)); | |||
map.put(memberUuid2, new TimestampedNodeHealth(randomNodeHealth(), clusterTime - 1)); | |||
when(hazelcastClient.getClusterTime()).thenReturn(clusterTime); | |||
doReturn(map).when(hazelcastClient).getReplicatedMap(MAP_SQ_HEALTH_STATE); | |||
underTest.readAll(); | |||
assertThat(logTester.logs()).hasSize(3); | |||
assertThat(logTester.logs(LoggerLevel.TRACE)) | |||
.containsOnly( | |||
"Reading " + new HashMap<>(map) + " and keeping []", | |||
"Ignoring NodeHealth of member " + memberUuid1 + " because it is not part of the cluster at the moment", | |||
"Ignoring NodeHealth of member " + memberUuid2 + " because it is not part of the cluster at the moment"); | |||
} | |||
@Test | |||
public void readAll_logs_message_for_each_timed_out_NodeHealth_ignored_if_TRACE() { | |||
logTester.setLevel(LoggerLevel.TRACE); | |||
Map<String, TimestampedNodeHealth> map = new HashMap<>(); | |||
String memberUuid1 = randomAlphanumeric(44); | |||
String memberUuid2 = randomAlphanumeric(44); | |||
map.put(memberUuid1, new TimestampedNodeHealth(randomNodeHealth(), clusterTime - 30 * 1000)); | |||
map.put(memberUuid2, new TimestampedNodeHealth(randomNodeHealth(), clusterTime - 30 * 1000)); | |||
doReturn(map).when(hazelcastClient).getReplicatedMap(MAP_SQ_HEALTH_STATE); | |||
when(hazelcastClient.getMemberUuids()).thenReturn(ImmutableSet.of(memberUuid1, memberUuid2)); | |||
when(hazelcastClient.getClusterTime()).thenReturn(clusterTime); | |||
underTest.readAll(); | |||
assertThat(logTester.logs()).hasSize(3); | |||
assertThat(logTester.logs(LoggerLevel.TRACE)) | |||
.containsOnly( | |||
"Reading " + new HashMap<>(map) + " and keeping []", | |||
"Ignoring NodeHealth of member " + memberUuid1 + " because it is too old", | |||
"Ignoring NodeHealth of member " + memberUuid2 + " because it is too old"); | |||
} | |||
@Test | |||
public void clearMine_clears_entry_into_map_sq_health_state_under_current_client_uuid() { | |||
Map<String, TimestampedNodeHealth> map = mock(Map.class); | |||
doReturn(map).when(hazelcastClient).getReplicatedMap(MAP_SQ_HEALTH_STATE); | |||
String uuid = randomAlphanumeric(5); | |||
when(hazelcastClient.getUUID()).thenReturn(uuid); | |||
underTest.clearMine(); | |||
verify(map).remove(uuid); | |||
verifyNoMoreInteractions(map); | |||
assertThat(logTester.logs()).isEmpty(); | |||
} | |||
@Test | |||
public void clearMine_logs_map_sq_health_state_and_current_client_uuid_if_TRACE() { | |||
logTester.setLevel(LoggerLevel.TRACE); | |||
Map<String, TimestampedNodeHealth> map = new HashMap<>(); | |||
map.put(randomAlphanumeric(4), new TimestampedNodeHealth(randomNodeHealth(), random.nextLong())); | |||
doReturn(map).when(hazelcastClient).getReplicatedMap(MAP_SQ_HEALTH_STATE); | |||
String uuid = randomAlphanumeric(5); | |||
when(hazelcastClient.getUUID()).thenReturn(uuid); | |||
underTest.clearMine(); | |||
assertThat(logTester.logs()).hasSize(1); | |||
assertThat(logTester.logs(LoggerLevel.TRACE).iterator().next()).isEqualTo("Reading " + map + " and clearing for " + uuid); | |||
} | |||
private NodeHealth randomNodeHealth() { | |||
return newNodeHealthBuilder() | |||
.setStatus(NodeHealth.Status.values()[random.nextInt(NodeHealth.Status.values().length)]) | |||
.setDetails(newNodeDetailsBuilder() | |||
.setType(random.nextBoolean() ? NodeDetails.Type.SEARCH : NodeDetails.Type.APPLICATION) | |||
.setName(randomAlphanumeric(30)) | |||
.setHost(randomAlphanumeric(10)) | |||
.setPort(1 + random.nextInt(666)) | |||
.setStartedAt(1 + random.nextInt(852)) | |||
.build()) | |||
.build(); | |||
} | |||
} |
@@ -1,304 +0,0 @@ | |||
/* | |||
* 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.cluster.localclient; | |||
import ch.qos.logback.classic.LoggerContext; | |||
import ch.qos.logback.classic.spi.ILoggingEvent; | |||
import ch.qos.logback.core.AppenderBase; | |||
import com.google.common.collect.ImmutableSet; | |||
import com.hazelcast.client.impl.HazelcastClientInstanceImpl; | |||
import com.hazelcast.client.impl.HazelcastClientProxy; | |||
import com.hazelcast.core.Client; | |||
import com.hazelcast.core.ClientListener; | |||
import com.hazelcast.core.HazelcastInstance; | |||
import java.net.InetAddress; | |||
import java.util.ArrayList; | |||
import java.util.Arrays; | |||
import java.util.HashMap; | |||
import java.util.HashSet; | |||
import java.util.List; | |||
import java.util.Map; | |||
import java.util.Set; | |||
import java.util.concurrent.CountDownLatch; | |||
import java.util.concurrent.TimeUnit; | |||
import org.apache.commons.lang.RandomStringUtils; | |||
import org.assertj.core.api.Assertions; | |||
import org.junit.AfterClass; | |||
import org.junit.BeforeClass; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.DisableOnDebug; | |||
import org.junit.rules.ExpectedException; | |||
import org.junit.rules.TestRule; | |||
import org.junit.rules.Timeout; | |||
import org.slf4j.LoggerFactory; | |||
import org.sonar.NetworkUtils; | |||
import org.sonar.api.config.PropertyDefinitions; | |||
import org.sonar.api.config.internal.MapSettings; | |||
import org.sonar.cluster.internal.HazelcastTestHelper; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.within; | |||
import static org.assertj.core.data.MapEntry.entry; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_ENABLED; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_LOCALENDPOINT; | |||
public class HazelcastLocalClientTest { | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
@Rule | |||
public TestRule safeguardTimeout = new DisableOnDebug(Timeout.seconds(60)); | |||
private static HazelcastInstance hzCluster; | |||
private static HazelcastLocalClient hzClient; | |||
@BeforeClass | |||
public static void setupHazelcastClusterAndHazelcastClient() { | |||
int port = NetworkUtils.INSTANCE.getNextAvailablePort(InetAddress.getLoopbackAddress()); | |||
hzCluster = HazelcastTestHelper.createHazelcastCluster(NetworkUtils.INSTANCE.getHostname(), port); | |||
MapSettings settings = createClusterSettings("localhost:" + port); | |||
hzClient = new HazelcastLocalClient(settings.asConfig()); | |||
} | |||
@AfterClass | |||
public static void stopHazelcastClusterAndHazelcastClient() { | |||
try { | |||
hzClient.stop(); | |||
} catch (Exception e) { | |||
// Ignore it | |||
} | |||
try { | |||
hzCluster.shutdown(); | |||
} catch (Exception e) { | |||
// Ignore it | |||
} | |||
} | |||
@Test | |||
public void start_throws_ISE_if_LOCALENDPOINT_is_incorrect() { | |||
MapSettings settings = createClusterSettings("\u4563\u1432\u1564"); | |||
HazelcastLocalClient hzClient = new HazelcastLocalClient(settings.asConfig()); | |||
expectedException.expect(IllegalStateException.class); | |||
expectedException.expectMessage("Unable to connect to any address in the config! The following addresses were tried:"); | |||
hzClient.start(); | |||
} | |||
@Test | |||
public void constructor_throws_ISE_if_LOCALENDPOINT_is_empty() { | |||
MapSettings settings = createClusterSettings(""); | |||
expectedException.expect(IllegalStateException.class); | |||
expectedException.expectMessage("LocalEndPoint have not been set"); | |||
new HazelcastLocalClient(settings.asConfig()); | |||
} | |||
@Test | |||
public void constructor_throws_ISE_if_CLUSTER_ENABLED_is_false() { | |||
MapSettings settings = createClusterSettings("localhost:9003"); | |||
settings.setProperty(CLUSTER_ENABLED, false); | |||
expectedException.expect(IllegalStateException.class); | |||
expectedException.expectMessage("Cluster is not enabled"); | |||
new HazelcastLocalClient(settings.asConfig()); | |||
} | |||
@Test | |||
public void constructor_throws_ISE_if_missing_CLUSTER_ENABLED() { | |||
MapSettings settings = createClusterSettings("localhost:9003"); | |||
settings.removeProperty(CLUSTER_ENABLED); | |||
expectedException.expect(IllegalStateException.class); | |||
expectedException.expectMessage("Cluster is not enabled"); | |||
new HazelcastLocalClient(settings.asConfig()); | |||
} | |||
@Test | |||
public void constructor_throws_ISE_if_missing_CLUSTER_LOCALENDPOINT() { | |||
MapSettings settings = createClusterSettings("localhost:9003"); | |||
settings.removeProperty(CLUSTER_LOCALENDPOINT); | |||
expectedException.expect(IllegalStateException.class); | |||
expectedException.expectMessage("LocalEndPoint have not been set"); | |||
new HazelcastLocalClient(settings.asConfig()); | |||
} | |||
@Test | |||
public void client_must_connect_to_hazelcast() throws InterruptedException { | |||
int port = NetworkUtils.INSTANCE.getNextAvailablePort(InetAddress.getLoopbackAddress()); | |||
// Launch a fake Hazelcast instance | |||
HazelcastInstance hzInstance = HazelcastTestHelper.createHazelcastCluster(NetworkUtils.INSTANCE.getHostname(), port); | |||
MapSettings settings = createClusterSettings("localhost:" + port); | |||
HazelcastLocalClient hazelcastClientWrapperImpl = new HazelcastLocalClient(settings.asConfig()); | |||
ClientListenerImpl clientListener = new ClientListenerImpl(); | |||
hzInstance.getClientService().addClientListener(clientListener); | |||
try { | |||
hazelcastClientWrapperImpl.start(); | |||
clientListener.counter.await(5, TimeUnit.SECONDS); | |||
assertThat(hazelcastClientWrapperImpl.getMemberUuids()).hasSize(2); | |||
assertThat(hazelcastClientWrapperImpl.getUUID()).isNotEmpty(); | |||
} finally { | |||
hazelcastClientWrapperImpl.stop(); | |||
} | |||
} | |||
@Test | |||
public void client_must_be_able_to_set_ReplicatedMap_objects() throws InterruptedException { | |||
hzClient.start(); | |||
try { | |||
Set<String> setTest = new HashSet<>(); | |||
setTest.addAll( | |||
Arrays.asList(RandomStringUtils.randomAlphanumeric(10), RandomStringUtils.randomAlphanumeric(10))); | |||
Map<String, Set<String>> replicatedMap = hzClient.getReplicatedMap("TEST1"); | |||
replicatedMap.put("KEY1", ImmutableSet.copyOf(setTest)); | |||
Assertions.assertThat(hzCluster.getReplicatedMap("TEST1")) | |||
.containsOnlyKeys("KEY1"); | |||
Assertions.assertThat(hzCluster.getReplicatedMap("TEST1").get("KEY1")) | |||
.isEqualTo(setTest); | |||
} finally { | |||
hzClient.stop(); | |||
} | |||
} | |||
@Test | |||
public void client_must_be_able_to_retrieve_Set_objects() { | |||
hzClient.start(); | |||
try { | |||
// Set | |||
Set<String> setTest = new HashSet<>(); | |||
setTest.addAll(Arrays.asList("8", "9")); | |||
hzCluster.getSet("TEST1").addAll(setTest); | |||
assertThat(hzClient.getSet("TEST1")).containsAll(setTest); | |||
} finally { | |||
hzClient.stop(); | |||
} | |||
} | |||
@Test | |||
public void client_must_be_able_to_retrieve_List_objects() { | |||
hzClient.start(); | |||
try { | |||
// List | |||
List<String> listTest = Arrays.asList("1", "2"); | |||
hzCluster.getList("TEST2").addAll(listTest); | |||
assertThat(hzClient.getList("TEST2")).containsAll(listTest); | |||
} finally { | |||
hzClient.stop(); | |||
} | |||
} | |||
@Test | |||
public void client_must_be_able_to_retrieve_Map_objects() { | |||
hzClient.start(); | |||
try { | |||
Map mapTest = new HashMap<>(); | |||
mapTest.put("a", Arrays.asList("123", "456")); | |||
hzCluster.getMap("TEST3").putAll(mapTest); | |||
assertThat(hzClient.getMap("TEST3")).containsExactly( | |||
entry("a", Arrays.asList("123", "456"))); | |||
} finally { | |||
hzClient.stop(); | |||
} | |||
} | |||
@Test | |||
public void configuration_tweaks_of_hazelcast_must_be_present() { | |||
hzClient.start(); | |||
try { | |||
HazelcastClientInstanceImpl realClient = ((HazelcastClientProxy) hzClient.hzInstance).client; | |||
Assertions.assertThat(realClient.getClientConfig().getProperty("hazelcast.tcp.join.port.try.count")).isEqualTo("10"); | |||
Assertions.assertThat(realClient.getClientConfig().getProperty("hazelcast.phone.home.enabled")).isEqualTo("false"); | |||
Assertions.assertThat(realClient.getClientConfig().getProperty("hazelcast.logging.type")).isEqualTo("slf4j"); | |||
} finally { | |||
hzClient.stop(); | |||
} | |||
} | |||
@Test | |||
public void hazelcast_client_must_log_through_sl4fj() { | |||
MemoryAppender<ILoggingEvent> memoryAppender = new MemoryAppender<>(); | |||
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); | |||
lc.reset(); | |||
memoryAppender.setContext(lc); | |||
memoryAppender.start(); | |||
lc.getLogger("com.hazelcast").addAppender(memoryAppender); | |||
hzClient.start(); | |||
hzClient.stop(); | |||
memoryAppender.stop(); | |||
Assertions.assertThat(memoryAppender.events).isNotEmpty(); | |||
memoryAppender.events.stream().forEach( | |||
e -> Assertions.assertThat(e.getLoggerName()).startsWith("com.hazelcast")); | |||
} | |||
@Test | |||
public void getClusterTime_returns_time_of_cluster() { | |||
try { | |||
hzClient.start(); | |||
HazelcastClientInstanceImpl realClient = ((HazelcastClientProxy) hzClient.hzInstance).client; | |||
assertThat(hzClient.getClusterTime()) | |||
.isCloseTo(realClient.getCluster().getClusterTime(), within(1000L)); | |||
} finally { | |||
hzClient.stop(); | |||
} | |||
} | |||
private class ClientListenerImpl implements ClientListener { | |||
CountDownLatch counter = new CountDownLatch(1); | |||
@Override | |||
public void clientConnected(Client client) { | |||
counter.countDown(); | |||
} | |||
@Override | |||
public void clientDisconnected(Client client) { | |||
} | |||
} | |||
private static MapSettings createClusterSettings(String localEndPoint) { | |||
return new MapSettings(new PropertyDefinitions()) | |||
.setProperty(CLUSTER_LOCALENDPOINT, localEndPoint) | |||
.setProperty(CLUSTER_ENABLED, "true"); | |||
} | |||
private class MemoryAppender<E> extends AppenderBase<E> { | |||
private final List<E> events = new ArrayList(); | |||
@Override | |||
protected void append(E eventObject) { | |||
events.add(eventObject); | |||
} | |||
} | |||
} |
@@ -52,6 +52,14 @@ | |||
<groupId>com.hazelcast</groupId> | |||
<artifactId>hazelcast</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>com.hazelcast</groupId> | |||
<artifactId>hazelcast-client</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.yaml</groupId> | |||
<artifactId>snakeyaml</artifactId> | |||
</dependency> | |||
<!-- | |||
Required by our usage of Guava for clustering : CeWorkerFactoryImpl.getClusteredWorkerUUIDs() | |||
--> | |||
@@ -85,11 +93,6 @@ | |||
<artifactId>mockito-core</artifactId> | |||
<scope>test</scope> | |||
</dependency> | |||
<dependency> | |||
<groupId>com.hazelcast</groupId> | |||
<artifactId>hazelcast-client</artifactId> | |||
<scope>test</scope> | |||
</dependency> | |||
<dependency> | |||
<groupId>${project.groupId}</groupId> | |||
<artifactId>sonar-testing-harness</artifactId> |
@@ -34,7 +34,7 @@ import org.sonar.process.logging.RootLoggerConfig; | |||
import static org.slf4j.Logger.ROOT_LOGGER_NAME; | |||
import static org.sonar.application.process.StreamGobbler.LOGGER_GOBBLER; | |||
import static org.sonar.cluster.ClusterProperties.HAZELCAST_LOG_LEVEL; | |||
import static org.sonar.process.cluster.ClusterProperties.HAZELCAST_LOG_LEVEL; | |||
import static org.sonar.process.logging.RootLoggerConfig.newRootLoggerConfigBuilder; | |||
/** |
@@ -28,7 +28,7 @@ import org.sonar.process.MessageException; | |||
import org.sonar.process.Props; | |||
import static java.lang.String.format; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_ENABLED; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_ENABLED; | |||
import static org.sonar.process.ProcessProperties.PATH_DATA; | |||
import static org.sonar.process.ProcessProperties.PATH_LOGS; | |||
import static org.sonar.process.ProcessProperties.PATH_TEMP; |
@@ -26,7 +26,7 @@ import java.util.Map; | |||
import java.util.Optional; | |||
import java.util.concurrent.atomic.AtomicBoolean; | |||
import javax.annotation.Nonnull; | |||
import org.sonar.NetworkUtils; | |||
import org.sonar.process.NetworkUtils; | |||
import org.sonar.process.ProcessId; | |||
public class AppStateImpl implements AppState { |
@@ -28,24 +28,23 @@ import java.util.concurrent.atomic.AtomicInteger; | |||
import java.util.function.Supplier; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
import org.sonar.NetworkUtils; | |||
import org.sonar.api.utils.System2; | |||
import org.sonar.application.cluster.ClusterAppState; | |||
import org.sonar.application.cluster.SearchNodeHealthProvider; | |||
import org.sonar.application.command.CommandFactory; | |||
import org.sonar.application.command.EsCommand; | |||
import org.sonar.application.command.JavaCommand; | |||
import org.sonar.application.config.AppSettings; | |||
import org.sonar.application.config.ClusterSettings; | |||
import org.sonar.application.health.HealthStateSharing; | |||
import org.sonar.application.health.HealthStateSharingImpl; | |||
import org.sonar.application.health.SearchNodeHealthProvider; | |||
import org.sonar.application.process.Lifecycle; | |||
import org.sonar.application.process.ProcessEventListener; | |||
import org.sonar.application.process.ProcessLauncher; | |||
import org.sonar.application.process.ProcessLifecycleListener; | |||
import org.sonar.application.process.ProcessMonitor; | |||
import org.sonar.application.process.SQProcess; | |||
import org.sonar.process.NetworkUtils; | |||
import org.sonar.process.ProcessId; | |||
import org.sonar.application.command.CommandFactory; | |||
import org.sonar.application.command.EsCommand; | |||
import org.sonar.application.command.JavaCommand; | |||
import org.sonar.process.cluster.health.HealthStateSharing; | |||
import org.sonar.process.cluster.health.HealthStateSharingImpl; | |||
public class SchedulerImpl implements Scheduler, ProcessEventListener, ProcessLifecycleListener, AppStateListener { | |||
@@ -152,7 +151,7 @@ public class SchedulerImpl implements Scheduler, ProcessEventListener, ProcessLi | |||
ClusterAppState clusterAppState = (ClusterAppState) appState; | |||
this.healthStateSharing = new HealthStateSharingImpl( | |||
clusterAppState.getHazelcastClient(), | |||
new SearchNodeHealthProvider(settings.getProps(), System2.INSTANCE, clusterAppState, NetworkUtils.INSTANCE)); | |||
new SearchNodeHealthProvider(settings.getProps(), clusterAppState, NetworkUtils.INSTANCE)); | |||
this.healthStateSharing.start(); | |||
} | |||
} |
@@ -20,7 +20,7 @@ | |||
package org.sonar.application.cluster; | |||
import org.sonar.application.AppState; | |||
import org.sonar.cluster.localclient.HazelcastClient; | |||
import org.sonar.process.cluster.HazelcastClient; | |||
public interface ClusterAppState extends AppState { | |||
HazelcastClient getHazelcastClient(); |
@@ -29,12 +29,12 @@ import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
import org.sonar.application.AppStateListener; | |||
import org.sonar.application.config.AppSettings; | |||
import org.sonar.cluster.localclient.HazelcastClient; | |||
import org.sonar.process.ProcessId; | |||
import org.sonar.process.cluster.HazelcastClient; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_ENABLED; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_LOCALENDPOINT; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_MEMBERUUID; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_ENABLED; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_LOCALENDPOINT; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_MEMBERUUID; | |||
public class ClusterAppStateImpl implements ClusterAppState { | |||
private static Logger LOGGER = LoggerFactory.getLogger(ClusterAppStateImpl.class); |
@@ -31,13 +31,13 @@ import org.apache.commons.lang.StringUtils; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
import org.sonar.application.config.AppSettings; | |||
import org.sonar.cluster.NodeType; | |||
import org.sonar.process.cluster.NodeType; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_HOSTS; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_HOST; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_NAME; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_PORT; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_TYPE; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_HOSTS; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_NODE_HOST; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_NODE_NAME; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_NODE_PORT; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_NODE_TYPE; | |||
/** | |||
* Properties of the cluster configuration |
@@ -48,26 +48,26 @@ import java.util.Set; | |||
import java.util.concurrent.locks.Lock; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
import org.sonar.NetworkUtils; | |||
import org.sonar.application.AppStateListener; | |||
import org.sonar.cluster.ClusterObjectKeys; | |||
import org.sonar.cluster.localclient.HazelcastClient; | |||
import org.sonar.process.MessageException; | |||
import org.sonar.cluster.NodeType; | |||
import org.sonar.process.NetworkUtils; | |||
import org.sonar.process.ProcessId; | |||
import org.sonar.process.cluster.NodeType; | |||
import org.sonar.process.cluster.ClusterObjectKeys; | |||
import org.sonar.process.cluster.HazelcastClient; | |||
import static java.lang.String.format; | |||
import static java.util.stream.Collectors.toList; | |||
import static org.sonar.application.cluster.ClusterProperties.HAZELCAST_CLUSTER_NAME; | |||
import static org.sonar.cluster.ClusterObjectKeys.CLUSTER_NAME; | |||
import static org.sonar.cluster.ClusterObjectKeys.HOSTNAME; | |||
import static org.sonar.cluster.ClusterObjectKeys.IP_ADDRESSES; | |||
import static org.sonar.cluster.ClusterObjectKeys.LEADER; | |||
import static org.sonar.cluster.ClusterObjectKeys.LOCAL_MEMBER_UUIDS; | |||
import static org.sonar.cluster.ClusterObjectKeys.NODE_NAME; | |||
import static org.sonar.cluster.ClusterObjectKeys.NODE_TYPE; | |||
import static org.sonar.cluster.ClusterObjectKeys.OPERATIONAL_PROCESSES; | |||
import static org.sonar.cluster.ClusterObjectKeys.SONARQUBE_VERSION; | |||
import static org.sonar.process.cluster.ClusterObjectKeys.CLUSTER_NAME; | |||
import static org.sonar.process.cluster.ClusterObjectKeys.HOSTNAME; | |||
import static org.sonar.process.cluster.ClusterObjectKeys.IP_ADDRESSES; | |||
import static org.sonar.process.cluster.ClusterObjectKeys.LEADER; | |||
import static org.sonar.process.cluster.ClusterObjectKeys.LOCAL_MEMBER_UUIDS; | |||
import static org.sonar.process.cluster.ClusterObjectKeys.NODE_NAME; | |||
import static org.sonar.process.cluster.ClusterObjectKeys.NODE_TYPE; | |||
import static org.sonar.process.cluster.ClusterObjectKeys.OPERATIONAL_PROCESSES; | |||
import static org.sonar.process.cluster.ClusterObjectKeys.SONARQUBE_VERSION; | |||
public class HazelcastCluster implements AutoCloseable { | |||
private static final Logger LOGGER = LoggerFactory.getLogger(HazelcastCluster.class); |
@@ -17,33 +17,36 @@ | |||
* 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.application.health; | |||
package org.sonar.application.cluster; | |||
import org.sonar.NetworkUtils; | |||
import org.sonar.api.utils.System2; | |||
import org.sonar.application.cluster.ClusterAppState; | |||
import org.sonar.cluster.health.NodeDetails; | |||
import org.sonar.cluster.health.NodeHealth; | |||
import org.sonar.cluster.health.NodeHealthProvider; | |||
import org.sonar.process.NetworkUtils; | |||
import org.sonar.process.ProcessId; | |||
import org.sonar.process.Props; | |||
import org.sonar.process.cluster.health.NodeDetails; | |||
import org.sonar.process.cluster.health.NodeHealth; | |||
import org.sonar.process.cluster.health.NodeHealthProvider; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_HOST; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_NAME; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_PORT; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_NODE_HOST; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_NODE_NAME; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_NODE_PORT; | |||
public class SearchNodeHealthProvider implements NodeHealthProvider { | |||
private final ClusterAppState clusterAppState; | |||
private final NodeDetails nodeDetails; | |||
public SearchNodeHealthProvider(Props props, System2 system2, ClusterAppState clusterAppState, NetworkUtils networkUtils) { | |||
public SearchNodeHealthProvider(Props props, ClusterAppState clusterAppState, NetworkUtils networkUtils) { | |||
this(props, clusterAppState, networkUtils, new Clock()); | |||
} | |||
SearchNodeHealthProvider(Props props, ClusterAppState clusterAppState, NetworkUtils networkUtils, Clock clock) { | |||
this.clusterAppState = clusterAppState; | |||
this.nodeDetails = NodeDetails.newNodeDetailsBuilder() | |||
.setType(NodeDetails.Type.SEARCH) | |||
.setName(props.nonNullValue(CLUSTER_NODE_NAME)) | |||
.setHost(getHost(props, networkUtils)) | |||
.setPort(Integer.valueOf(props.nonNullValue(CLUSTER_NODE_PORT))) | |||
.setStartedAt(system2.now()) | |||
.setStartedAt(clock.now()) | |||
.build(); | |||
} | |||
@@ -68,4 +71,10 @@ public class SearchNodeHealthProvider implements NodeHealthProvider { | |||
.setDetails(nodeDetails) | |||
.build(); | |||
} | |||
static class Clock { | |||
long now() { | |||
return System.currentTimeMillis(); | |||
} | |||
} | |||
} |
@@ -31,7 +31,7 @@ import java.util.List; | |||
import java.util.function.Consumer; | |||
import org.apache.commons.lang.StringUtils; | |||
import org.sonar.process.MessageException; | |||
import org.sonar.cluster.NodeType; | |||
import org.sonar.process.cluster.NodeType; | |||
import org.sonar.process.ProcessId; | |||
import org.sonar.process.Props; | |||
@@ -42,12 +42,12 @@ import static java.util.Arrays.stream; | |||
import static java.util.Collections.singletonList; | |||
import static java.util.stream.Collectors.joining; | |||
import static org.apache.commons.lang.StringUtils.isBlank; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_ENABLED; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_HOSTS; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_HOST; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_TYPE; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_SEARCH_HOSTS; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_WEB_LEADER; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_ENABLED; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_HOSTS; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_NODE_HOST; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_NODE_TYPE; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_SEARCH_HOSTS; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_WEB_LEADER; | |||
import static org.sonar.process.ProcessProperties.JDBC_URL; | |||
import static org.sonar.process.ProcessProperties.SEARCH_HOST; | |||
@@ -31,10 +31,10 @@ import org.sonar.process.Props; | |||
import org.sonar.process.System2; | |||
import static java.lang.String.valueOf; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_ENABLED; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_NAME; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_NAME; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_SEARCH_HOSTS; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_ENABLED; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_NAME; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_NODE_NAME; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_SEARCH_HOSTS; | |||
public class EsSettings { | |||
@@ -1,23 +0,0 @@ | |||
/* | |||
* 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. | |||
*/ | |||
@ParametersAreNonnullByDefault | |||
package org.sonar.application.health; | |||
import javax.annotation.ParametersAreNonnullByDefault; |
@@ -48,8 +48,8 @@ import org.sonar.process.logging.LogbackHelper; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.slf4j.Logger.ROOT_LOGGER_NAME; | |||
import static org.sonar.application.process.StreamGobbler.LOGGER_GOBBLER; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_ENABLED; | |||
import static org.sonar.cluster.ClusterProperties.HAZELCAST_LOG_LEVEL; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_ENABLED; | |||
import static org.sonar.process.cluster.ClusterProperties.HAZELCAST_LOG_LEVEL; | |||
public class AppLoggingTest { | |||
@@ -35,7 +35,7 @@ import static org.mockito.Mockito.mock; | |||
import static org.mockito.Mockito.verify; | |||
import static org.mockito.Mockito.verifyZeroInteractions; | |||
import static org.mockito.Mockito.when; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_ENABLED; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_ENABLED; | |||
public class AppReloaderImplTest { | |||
@@ -24,9 +24,9 @@ import org.sonar.application.cluster.ClusterAppStateImpl; | |||
import org.sonar.application.config.TestAppSettings; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_ENABLED; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_NAME; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_TYPE; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_ENABLED; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_NAME; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_NODE_TYPE; | |||
public class AppStateFactoryTest { | |||
@@ -38,15 +38,15 @@ import org.junit.rules.TemporaryFolder; | |||
import org.junit.rules.TestRule; | |||
import org.junit.rules.Timeout; | |||
import org.mockito.Mockito; | |||
import org.sonar.application.config.TestAppSettings; | |||
import org.sonar.application.process.ProcessLauncher; | |||
import org.sonar.application.process.ProcessMonitor; | |||
import org.sonar.cluster.localclient.HazelcastClient; | |||
import org.sonar.process.ProcessId; | |||
import org.sonar.application.command.AbstractCommand; | |||
import org.sonar.application.command.CommandFactory; | |||
import org.sonar.application.command.EsCommand; | |||
import org.sonar.application.command.JavaCommand; | |||
import org.sonar.application.config.TestAppSettings; | |||
import org.sonar.application.process.ProcessLauncher; | |||
import org.sonar.application.process.ProcessMonitor; | |||
import org.sonar.process.ProcessId; | |||
import org.sonar.process.cluster.HazelcastClient; | |||
import static java.util.Collections.synchronizedList; | |||
import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; | |||
@@ -55,14 +55,14 @@ import static org.mockito.Mockito.doThrow; | |||
import static org.mockito.Mockito.mock; | |||
import static org.mockito.Mockito.timeout; | |||
import static org.mockito.Mockito.verify; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_ENABLED; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_HOST; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_NAME; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_PORT; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_TYPE; | |||
import static org.sonar.process.ProcessId.COMPUTE_ENGINE; | |||
import static org.sonar.process.ProcessId.ELASTICSEARCH; | |||
import static org.sonar.process.ProcessId.WEB_SERVER; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_ENABLED; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_NODE_HOST; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_NODE_NAME; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_NODE_PORT; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_NODE_TYPE; | |||
public class SchedulerImplTest { | |||
@@ -26,7 +26,7 @@ import java.util.Map; | |||
import java.util.Optional; | |||
import java.util.concurrent.atomic.AtomicBoolean; | |||
import javax.annotation.Nonnull; | |||
import org.sonar.NetworkUtils; | |||
import org.sonar.process.NetworkUtils; | |||
import org.sonar.process.ProcessId; | |||
public class TestAppState implements AppState { |
@@ -20,7 +20,7 @@ | |||
package org.sonar.application; | |||
import org.sonar.application.cluster.ClusterAppState; | |||
import org.sonar.cluster.localclient.HazelcastClient; | |||
import org.sonar.process.cluster.HazelcastClient; | |||
public class TestClusterAppState extends TestAppState implements ClusterAppState { | |||
private final HazelcastClient hazelcastClient; |
@@ -42,9 +42,9 @@ import static org.mockito.Mockito.timeout; | |||
import static org.mockito.Mockito.verify; | |||
import static org.sonar.application.cluster.HazelcastClusterTestHelper.createHazelcastClient; | |||
import static org.sonar.application.cluster.HazelcastClusterTestHelper.newApplicationSettings; | |||
import static org.sonar.cluster.ClusterObjectKeys.CLUSTER_NAME; | |||
import static org.sonar.cluster.ClusterObjectKeys.SONARQUBE_VERSION; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_ENABLED; | |||
import static org.sonar.process.cluster.ClusterObjectKeys.CLUSTER_NAME; | |||
import static org.sonar.process.cluster.ClusterObjectKeys.SONARQUBE_VERSION; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_ENABLED; | |||
public class ClusterAppStateImplTest { | |||
@@ -30,12 +30,12 @@ import org.sonar.application.config.AppSettings; | |||
import org.sonar.application.config.TestAppSettings; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_ENABLED; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_HOSTS; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_NAME; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_HOST; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_PORT; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_TYPE; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_ENABLED; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_HOSTS; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_NAME; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_NODE_HOST; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_NODE_PORT; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_NODE_TYPE; | |||
public class ClusterPropertiesTest { | |||
@Rule |
@@ -41,10 +41,10 @@ import org.junit.rules.ExpectedException; | |||
import org.junit.rules.TestRule; | |||
import org.junit.rules.Timeout; | |||
import org.slf4j.LoggerFactory; | |||
import org.sonar.NetworkUtils; | |||
import org.sonar.process.NetworkUtils; | |||
import org.sonar.application.AppStateListener; | |||
import org.sonar.application.config.TestAppSettings; | |||
import org.sonar.cluster.ClusterObjectKeys; | |||
import org.sonar.process.cluster.ClusterObjectKeys; | |||
import org.sonar.process.ProcessId; | |||
import static java.lang.String.format; | |||
@@ -59,13 +59,13 @@ import static org.sonar.application.cluster.HazelcastClusterTestHelper.closeAllH | |||
import static org.sonar.application.cluster.HazelcastClusterTestHelper.createHazelcastClient; | |||
import static org.sonar.application.cluster.HazelcastClusterTestHelper.newApplicationSettings; | |||
import static org.sonar.application.cluster.HazelcastClusterTestHelper.newSearchSettings; | |||
import static org.sonar.cluster.ClusterObjectKeys.LEADER; | |||
import static org.sonar.cluster.ClusterObjectKeys.OPERATIONAL_PROCESSES; | |||
import static org.sonar.cluster.ClusterObjectKeys.SONARQUBE_VERSION; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_HOSTS; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_NAME; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_HOST; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_PORT; | |||
import static org.sonar.process.cluster.ClusterObjectKeys.LEADER; | |||
import static org.sonar.process.cluster.ClusterObjectKeys.OPERATIONAL_PROCESSES; | |||
import static org.sonar.process.cluster.ClusterObjectKeys.SONARQUBE_VERSION; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_HOSTS; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_NAME; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_NODE_HOST; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_NODE_PORT; | |||
public class HazelcastClusterTest { | |||
@Rule |
@@ -28,9 +28,9 @@ import java.util.ArrayList; | |||
import java.util.List; | |||
import org.sonar.application.config.TestAppSettings; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_ENABLED; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_NAME; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_TYPE; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_ENABLED; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_NAME; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_NODE_TYPE; | |||
public class HazelcastClusterTestHelper { | |||
@@ -17,7 +17,7 @@ | |||
* 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.application.health; | |||
package org.sonar.application.cluster; | |||
import java.util.Properties; | |||
import java.util.Random; | |||
@@ -25,29 +25,27 @@ import javax.annotation.Nullable; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.NetworkUtils; | |||
import org.sonar.api.utils.System2; | |||
import org.sonar.application.cluster.ClusterAppState; | |||
import org.sonar.cluster.ClusterProperties; | |||
import org.sonar.cluster.health.NodeHealth; | |||
import org.sonar.process.NetworkUtils; | |||
import org.sonar.process.ProcessId; | |||
import org.sonar.process.Props; | |||
import org.sonar.process.cluster.ClusterProperties; | |||
import org.sonar.process.cluster.health.NodeHealth; | |||
import static java.lang.String.valueOf; | |||
import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; | |||
import static org.mockito.Mockito.mock; | |||
import static org.mockito.Mockito.when; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_HOST; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_NAME; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_PORT; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_NODE_HOST; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_NODE_NAME; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_NODE_PORT; | |||
public class SearchNodeHealthProviderTest { | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
private final Random random = new Random(); | |||
private System2 system2 = mock(System2.class); | |||
private SearchNodeHealthProvider.Clock clock = mock(SearchNodeHealthProvider.Clock.class); | |||
private NetworkUtils networkUtils = mock(NetworkUtils.class); | |||
private ClusterAppState clusterAppState = mock(ClusterAppState.class); | |||
@@ -58,7 +56,7 @@ public class SearchNodeHealthProviderTest { | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("Missing property: sonar.cluster.node.name"); | |||
new SearchNodeHealthProvider(props, system2, clusterAppState, networkUtils); | |||
new SearchNodeHealthProvider(props, clusterAppState, networkUtils); | |||
} | |||
@Test | |||
@@ -69,7 +67,7 @@ public class SearchNodeHealthProviderTest { | |||
expectedException.expect(NullPointerException.class); | |||
new SearchNodeHealthProvider(props, system2, clusterAppState, networkUtils); | |||
new SearchNodeHealthProvider(props, clusterAppState, networkUtils, clock); | |||
} | |||
@Test | |||
@@ -82,7 +80,7 @@ public class SearchNodeHealthProviderTest { | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("Missing property: sonar.cluster.node.port"); | |||
new SearchNodeHealthProvider(props, system2, clusterAppState, networkUtils); | |||
new SearchNodeHealthProvider(props, clusterAppState, networkUtils, clock); | |||
} | |||
@Test | |||
@@ -97,7 +95,7 @@ public class SearchNodeHealthProviderTest { | |||
expectedException.expect(NumberFormatException.class); | |||
expectedException.expectMessage("For input string: \"" + port + "\""); | |||
new SearchNodeHealthProvider(props, system2, clusterAppState, networkUtils); | |||
new SearchNodeHealthProvider(props, clusterAppState, networkUtils, clock); | |||
} | |||
@Test | |||
@@ -108,8 +106,8 @@ public class SearchNodeHealthProviderTest { | |||
properties.setProperty(CLUSTER_NODE_NAME, name); | |||
properties.setProperty(CLUSTER_NODE_PORT, valueOf(port)); | |||
when(networkUtils.getHostname()).thenReturn(randomAlphanumeric(34)); | |||
when(system2.now()).thenReturn(1L + random.nextInt(87)); | |||
SearchNodeHealthProvider underTest = new SearchNodeHealthProvider(new Props(properties), system2, clusterAppState, networkUtils); | |||
when(clock.now()).thenReturn(1L + random.nextInt(87)); | |||
SearchNodeHealthProvider underTest = new SearchNodeHealthProvider(new Props(properties), clusterAppState, networkUtils, clock); | |||
NodeHealth nodeHealth = underTest.get(); | |||
@@ -133,8 +131,8 @@ public class SearchNodeHealthProviderTest { | |||
properties.setProperty(CLUSTER_NODE_NAME, randomAlphanumeric(3)); | |||
properties.setProperty(CLUSTER_NODE_PORT, valueOf(1 + random.nextInt(4))); | |||
properties.setProperty(CLUSTER_NODE_HOST, host); | |||
when(system2.now()).thenReturn(1L + random.nextInt(87)); | |||
SearchNodeHealthProvider underTest = new SearchNodeHealthProvider(new Props(properties), system2, clusterAppState, networkUtils); | |||
when(clock.now()).thenReturn(1L + random.nextInt(87)); | |||
SearchNodeHealthProvider underTest = new SearchNodeHealthProvider(new Props(properties), clusterAppState, networkUtils, clock); | |||
NodeHealth nodeHealth = underTest.get(); | |||
@@ -166,9 +164,9 @@ public class SearchNodeHealthProviderTest { | |||
if (hostPropertyValue != null) { | |||
properties.setProperty(CLUSTER_NODE_HOST, hostPropertyValue); | |||
} | |||
when(system2.now()).thenReturn(1L + random.nextInt(87)); | |||
when(clock.now()).thenReturn(1L + random.nextInt(87)); | |||
when(networkUtils.getHostname()).thenReturn(host); | |||
SearchNodeHealthProvider underTest = new SearchNodeHealthProvider(new Props(properties), system2, clusterAppState, networkUtils); | |||
SearchNodeHealthProvider underTest = new SearchNodeHealthProvider(new Props(properties), clusterAppState, networkUtils, clock); | |||
NodeHealth nodeHealth = underTest.get(); | |||
@@ -186,14 +184,14 @@ public class SearchNodeHealthProviderTest { | |||
public void get_returns_started_from_System2_now_at_constructor_time() { | |||
Properties properties = new Properties(); | |||
long now = setRequiredPropertiesAndMocks(properties); | |||
SearchNodeHealthProvider underTest = new SearchNodeHealthProvider(new Props(properties), system2, clusterAppState, networkUtils); | |||
SearchNodeHealthProvider underTest = new SearchNodeHealthProvider(new Props(properties), clusterAppState, networkUtils, clock); | |||
NodeHealth nodeHealth = underTest.get(); | |||
assertThat(nodeHealth.getDetails().getStartedAt()).isEqualTo(now); | |||
// change now | |||
when(system2.now()).thenReturn(now); | |||
when(clock.now()).thenReturn(now); | |||
NodeHealth newNodeHealth = underTest.get(); | |||
@@ -205,7 +203,7 @@ public class SearchNodeHealthProviderTest { | |||
Properties properties = new Properties(); | |||
setRequiredPropertiesAndMocks(properties); | |||
when(clusterAppState.isOperational(ProcessId.ELASTICSEARCH, true)).thenReturn(true); | |||
SearchNodeHealthProvider underTest = new SearchNodeHealthProvider(new Props(properties), system2, clusterAppState, networkUtils); | |||
SearchNodeHealthProvider underTest = new SearchNodeHealthProvider(new Props(properties), clusterAppState, networkUtils, clock); | |||
NodeHealth nodeHealth = underTest.get(); | |||
@@ -217,7 +215,7 @@ public class SearchNodeHealthProviderTest { | |||
Properties properties = new Properties(); | |||
setRequiredPropertiesAndMocks(properties); | |||
when(clusterAppState.isOperational(ProcessId.ELASTICSEARCH, true)).thenReturn(false); | |||
SearchNodeHealthProvider underTest = new SearchNodeHealthProvider(new Props(properties), system2, clusterAppState, networkUtils); | |||
SearchNodeHealthProvider underTest = new SearchNodeHealthProvider(new Props(properties), clusterAppState, networkUtils, clock); | |||
NodeHealth nodeHealth = underTest.get(); | |||
@@ -229,7 +227,7 @@ public class SearchNodeHealthProviderTest { | |||
properties.setProperty(CLUSTER_NODE_NAME, randomAlphanumeric(3)); | |||
properties.setProperty(CLUSTER_NODE_PORT, valueOf(1 + random.nextInt(4))); | |||
long now = 1L + random.nextInt(87); | |||
when(system2.now()).thenReturn(now); | |||
when(clock.now()).thenReturn(now); | |||
when(networkUtils.getHostname()).thenReturn(randomAlphanumeric(34)); | |||
return now; | |||
} |
@@ -34,11 +34,11 @@ import org.junit.rules.ExpectedException; | |||
import org.junit.runner.RunWith; | |||
import org.sonar.process.MessageException; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_ENABLED; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_HOSTS; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_HOST; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_TYPE; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_SEARCH_HOSTS; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_ENABLED; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_HOSTS; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_NODE_HOST; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_NODE_TYPE; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_SEARCH_HOSTS; | |||
import static org.sonar.process.ProcessProperties.JDBC_URL; | |||
import static org.sonar.process.ProcessProperties.SEARCH_HOST; | |||
@@ -32,10 +32,10 @@ import org.sonar.process.MessageException; | |||
import static java.lang.String.format; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_ENABLED; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_HOSTS; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_TYPE; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_SEARCH_HOSTS; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_ENABLED; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_HOSTS; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_NODE_TYPE; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_SEARCH_HOSTS; | |||
import static org.sonar.process.ProcessId.COMPUTE_ENGINE; | |||
import static org.sonar.process.ProcessId.ELASTICSEARCH; | |||
import static org.sonar.process.ProcessId.WEB_SERVER; |
@@ -31,7 +31,7 @@ import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.junit.rules.TemporaryFolder; | |||
import org.sonar.application.logging.ListAppender; | |||
import org.sonar.cluster.ClusterProperties; | |||
import org.sonar.process.cluster.ClusterProperties; | |||
import org.sonar.process.ProcessProperties; | |||
import org.sonar.process.Props; | |||
import org.sonar.process.System2; | |||
@@ -40,8 +40,8 @@ import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.mockito.Mockito.mock; | |||
import static org.mockito.Mockito.when; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_NAME; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_SEARCH_HOSTS; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_NAME; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_SEARCH_HOSTS; | |||
public class EsSettingsTest { | |||
@@ -16,10 +16,6 @@ | |||
</properties> | |||
<dependencies> | |||
<dependency> | |||
<groupId>${project.groupId}</groupId> | |||
<artifactId>sonar-cluster</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.slf4j</groupId> | |||
<artifactId>slf4j-api</artifactId> | |||
@@ -45,8 +41,8 @@ | |||
<artifactId>commons-lang</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.yaml</groupId> | |||
<artifactId>snakeyaml</artifactId> | |||
<groupId>com.google.guava</groupId> | |||
<artifactId>guava</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>com.google.code.findbugs</groupId> | |||
@@ -86,20 +82,10 @@ | |||
<artifactId>mockito-core</artifactId> | |||
<scope>test</scope> | |||
</dependency> | |||
<dependency> | |||
<groupId>com.google.guava</groupId> | |||
<artifactId>guava</artifactId> | |||
<scope>test</scope> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.eclipse.jetty</groupId> | |||
<artifactId>jetty-server</artifactId> | |||
<scope>test</scope> | |||
</dependency> | |||
<dependency> | |||
<groupId>com.squareup.okhttp3</groupId> | |||
<artifactId>okhttp</artifactId> | |||
<scope>test</scope> | |||
</dependency> | |||
</dependencies> | |||
</project> |
@@ -17,7 +17,7 @@ | |||
* 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; | |||
package org.sonar.process; | |||
import java.net.InetAddress; | |||
@@ -17,7 +17,7 @@ | |||
* 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; | |||
package org.sonar.process; | |||
import com.google.common.annotations.VisibleForTesting; | |||
import java.io.IOException; |
@@ -23,9 +23,8 @@ import java.net.InetAddress; | |||
import java.net.UnknownHostException; | |||
import java.util.Map; | |||
import java.util.Properties; | |||
import org.sonar.NetworkUtils; | |||
import static org.sonar.cluster.ClusterProperties.putClusterDefaults; | |||
import static org.sonar.process.cluster.ClusterProperties.putClusterDefaults; | |||
/** | |||
* Constants shared by search, web server and app processes. |
@@ -18,7 +18,7 @@ | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package org.sonar.cluster; | |||
package org.sonar.process.cluster; | |||
/** | |||
* This class holds all object keys accessible via Hazelcast | |||
@@ -51,7 +51,7 @@ public final class ClusterObjectKeys { | |||
public static final String NODE_NAME = "NODE_NAME"; | |||
/** | |||
* The role of the sonar-application inside the SonarQube cluster | |||
* {@link org.sonar.cluster.NodeType} | |||
* {@link NodeType} | |||
*/ | |||
public static final String NODE_TYPE = "NODE_TYPE"; | |||
/** |
@@ -17,7 +17,7 @@ | |||
* 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.cluster; | |||
package org.sonar.process.cluster; | |||
import java.util.Properties; | |||
import java.util.UUID; |
@@ -18,7 +18,7 @@ | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package org.sonar.cluster.localclient; | |||
package org.sonar.process.cluster; | |||
import java.util.List; | |||
import java.util.Map; |
@@ -17,10 +17,10 @@ | |||
* 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.cluster; | |||
package org.sonar.process.cluster; | |||
import static java.util.Arrays.stream; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_TYPE; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_NODE_TYPE; | |||
public enum NodeType { | |||
APPLICATION("application"), SEARCH("search"); |
@@ -17,7 +17,7 @@ | |||
* 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.application.health; | |||
package org.sonar.process.cluster.health; | |||
import java.util.Collection; | |||
import java.util.List; | |||
@@ -28,7 +28,6 @@ import java.util.concurrent.ScheduledExecutorService; | |||
import java.util.concurrent.ScheduledFuture; | |||
import java.util.concurrent.TimeUnit; | |||
import java.util.concurrent.TimeoutException; | |||
import org.sonar.cluster.health.HealthStateRefresherExecutorService; | |||
class DelegateHealthStateRefresherExecutorService implements HealthStateRefresherExecutorService { | |||
private final ScheduledExecutorService delegate; |
@@ -17,15 +17,14 @@ | |||
* 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.cluster.health; | |||
package org.sonar.process.cluster.health; | |||
import java.util.concurrent.TimeUnit; | |||
import org.picocontainer.Startable; | |||
import org.sonar.api.utils.log.Logger; | |||
import org.sonar.api.utils.log.Loggers; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
public class HealthStateRefresher implements Startable { | |||
private static final Logger LOG = Loggers.get(HealthStateRefresher.class); | |||
public class HealthStateRefresher { | |||
private static final Logger LOG = LoggerFactory.getLogger(HealthStateRefresher.class); | |||
private static final int INITIAL_DELAY = 1; | |||
private static final int DELAY = 10; | |||
@@ -40,7 +39,6 @@ public class HealthStateRefresher implements Startable { | |||
this.sharedHealthState = sharedHealthState; | |||
} | |||
@Override | |||
public void start() { | |||
executorService.scheduleWithFixedDelay(this::refresh, INITIAL_DELAY, DELAY, TimeUnit.SECONDS); | |||
} | |||
@@ -54,7 +52,6 @@ public class HealthStateRefresher implements Startable { | |||
} | |||
} | |||
@Override | |||
public void stop() { | |||
sharedHealthState.clearMine(); | |||
} |
@@ -17,7 +17,7 @@ | |||
* 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.cluster.health; | |||
package org.sonar.process.cluster.health; | |||
import java.util.concurrent.ScheduledExecutorService; | |||
@@ -17,7 +17,7 @@ | |||
* 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.application.health; | |||
package org.sonar.process.cluster.health; | |||
public interface HealthStateSharing { | |||
void start(); |
@@ -17,24 +17,20 @@ | |||
* 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.application.health; | |||
package org.sonar.process.cluster.health; | |||
import com.google.common.util.concurrent.ThreadFactoryBuilder; | |||
import java.util.concurrent.Executors; | |||
import java.util.concurrent.ScheduledExecutorService; | |||
import java.util.concurrent.TimeUnit; | |||
import org.sonar.api.utils.log.Logger; | |||
import org.sonar.api.utils.log.Loggers; | |||
import org.sonar.cluster.health.HealthStateRefresher; | |||
import org.sonar.cluster.health.HealthStateRefresherExecutorService; | |||
import org.sonar.cluster.health.NodeHealthProvider; | |||
import org.sonar.cluster.health.SharedHealthStateImpl; | |||
import org.sonar.cluster.localclient.HazelcastClient; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
import org.sonar.process.cluster.HazelcastClient; | |||
import static java.lang.String.format; | |||
public class HealthStateSharingImpl implements HealthStateSharing { | |||
private static final Logger LOG = Loggers.get(HealthStateSharingImpl.class); | |||
private static final Logger LOG = LoggerFactory.getLogger(HealthStateSharingImpl.class); | |||
private final HazelcastClient hazelcastClient; | |||
private final NodeHealthProvider nodeHealthProvider; | |||
@@ -74,7 +70,7 @@ public class HealthStateSharingImpl implements HealthStateSharing { | |||
executorService.shutdownNow(); | |||
// Wait a while for tasks to respond to being canceled | |||
if (!executorService.awaitTermination(5, TimeUnit.SECONDS)) { | |||
LOG.warn(format("Pool %s did not terminate", HealthStateSharingImpl.class.getSimpleName())); | |||
LOG.warn("Pool {} did not terminate", HealthStateSharingImpl.class.getSimpleName()); | |||
} | |||
} | |||
} catch (InterruptedException ie) { |
@@ -17,16 +17,15 @@ | |||
* 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.cluster.health; | |||
package org.sonar.process.cluster.health; | |||
import com.google.common.base.Preconditions; | |||
import java.io.Externalizable; | |||
import java.io.IOException; | |||
import java.io.ObjectInput; | |||
import java.io.ObjectOutput; | |||
import java.util.Objects; | |||
import static com.google.common.base.Preconditions.checkArgument; | |||
import static com.google.common.base.Preconditions.checkNotNull; | |||
import static java.util.Objects.requireNonNull; | |||
/** | |||
@@ -179,18 +178,18 @@ public class NodeDetails implements Externalizable { | |||
} | |||
private static String checkString(String name, String label) { | |||
checkNotNull(name, "%s can't be null", label); | |||
Preconditions.checkNotNull(name, "%s can't be null", label); | |||
String value = name.trim(); | |||
checkArgument(!value.isEmpty(), "%s can't be empty", label); | |||
Preconditions.checkArgument(!value.isEmpty(), "%s can't be empty", label); | |||
return value; | |||
} | |||
private static void checkPort(int port) { | |||
checkArgument(port > 0, "port must be > 0"); | |||
Preconditions.checkArgument(port > 0, "port must be > 0"); | |||
} | |||
private static void checkStartedAt(long startedAt) { | |||
checkArgument(startedAt > 0, "startedAt must be > 0"); | |||
Preconditions.checkArgument(startedAt > 0, "startedAt must be > 0"); | |||
} | |||
} | |||
@@ -17,8 +17,9 @@ | |||
* 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.cluster.health; | |||
package org.sonar.process.cluster.health; | |||
import com.google.common.base.Preconditions; | |||
import com.google.common.collect.ImmutableSet; | |||
import java.io.Externalizable; | |||
import java.io.IOException; | |||
@@ -28,7 +29,6 @@ import java.util.HashSet; | |||
import java.util.Objects; | |||
import java.util.Set; | |||
import static com.google.common.base.Preconditions.checkArgument; | |||
import static java.util.Objects.requireNonNull; | |||
/** | |||
@@ -146,7 +146,7 @@ public class NodeHealth implements Externalizable { | |||
public Builder addCause(String cause) { | |||
requireNonNull(cause, "cause can't be null"); | |||
String trimmed = cause.trim(); | |||
checkArgument(!trimmed.isEmpty(), "cause can't be empty"); | |||
Preconditions.checkArgument(!trimmed.isEmpty(), "cause can't be empty"); | |||
causes.add(cause); | |||
return this; | |||
} |
@@ -17,7 +17,7 @@ | |||
* 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.cluster.health; | |||
package org.sonar.process.cluster.health; | |||
public interface NodeHealthProvider { | |||
/** |
@@ -17,7 +17,7 @@ | |||
* 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.cluster.health; | |||
package org.sonar.process.cluster.health; | |||
import java.util.Set; | |||
@@ -17,7 +17,7 @@ | |||
* 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.cluster.health; | |||
package org.sonar.process.cluster.health; | |||
import com.google.common.collect.ImmutableSet; | |||
import java.util.HashMap; | |||
@@ -25,15 +25,15 @@ import java.util.Map; | |||
import java.util.Set; | |||
import java.util.function.Predicate; | |||
import java.util.stream.Collectors; | |||
import org.sonar.api.utils.log.Logger; | |||
import org.sonar.api.utils.log.Loggers; | |||
import org.sonar.cluster.ClusterObjectKeys; | |||
import org.sonar.cluster.localclient.HazelcastClient; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
import org.sonar.process.cluster.ClusterObjectKeys; | |||
import org.sonar.process.cluster.HazelcastClient; | |||
import static java.util.Objects.requireNonNull; | |||
public class SharedHealthStateImpl implements SharedHealthState { | |||
private static final Logger LOG = Loggers.get(SharedHealthStateImpl.class); | |||
private static final Logger LOG = LoggerFactory.getLogger(SharedHealthStateImpl.class); | |||
private static final int TIMEOUT_30_SECONDS = 30 * 1000; | |||
private final HazelcastClient hazelcastClient; |
@@ -17,7 +17,7 @@ | |||
* 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.cluster.health; | |||
package org.sonar.process.cluster.health; | |||
import java.io.Externalizable; | |||
import java.io.IOException; |
@@ -18,6 +18,6 @@ | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
@ParametersAreNonnullByDefault | |||
package org.sonar.cluster.internal; | |||
package org.sonar.process.cluster.health; | |||
import javax.annotation.ParametersAreNonnullByDefault; |
@@ -18,6 +18,6 @@ | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
@ParametersAreNonnullByDefault | |||
package org.sonar.cluster.health; | |||
package org.sonar.process.cluster; | |||
import javax.annotation.ParametersAreNonnullByDefault; |
@@ -17,7 +17,7 @@ | |||
* 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.application.health; | |||
package org.sonar.process.cluster.health; | |||
import java.util.Collection; | |||
import java.util.Random; |
@@ -89,11 +89,6 @@ | |||
<artifactId>sonar-process</artifactId> | |||
<version>${project.version}</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>${project.groupId}</groupId> | |||
<artifactId>sonar-cluster</artifactId> | |||
<version>${project.version}</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>${project.groupId}</groupId> | |||
<artifactId>sonar-plugin-api</artifactId> |
@@ -42,15 +42,15 @@ import org.sonar.api.config.Configuration; | |||
import org.sonar.api.server.ServerSide; | |||
import org.sonar.api.utils.log.Logger; | |||
import org.sonar.api.utils.log.Loggers; | |||
import org.sonar.cluster.NodeType; | |||
import org.sonar.process.cluster.NodeType; | |||
import org.sonar.process.ProcessProperties; | |||
import static java.util.Collections.unmodifiableList; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_ENABLED; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_NAME; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_TYPE; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_SEARCH_HOSTS; | |||
import static org.sonar.cluster.NodeType.SEARCH; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_ENABLED; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_NAME; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_NODE_TYPE; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_SEARCH_HOSTS; | |||
import static org.sonar.process.cluster.NodeType.SEARCH; | |||
@ComputeEngineSide | |||
@ServerSide |
@@ -39,7 +39,7 @@ import static com.google.common.base.Preconditions.checkArgument; | |||
import static java.lang.String.format; | |||
import static java.lang.String.valueOf; | |||
import static java.util.Objects.requireNonNull; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_ENABLED; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_ENABLED; | |||
import static org.sonar.server.es.DefaultIndexSettings.ANALYZER; | |||
import static org.sonar.server.es.DefaultIndexSettings.FIELDDATA_ENABLED; | |||
import static org.sonar.server.es.DefaultIndexSettings.FIELD_FIELDDATA; |
@@ -21,13 +21,13 @@ package org.sonar.server.health; | |||
import java.util.Arrays; | |||
import java.util.Set; | |||
import org.sonar.cluster.health.NodeDetails; | |||
import org.sonar.cluster.health.NodeHealth; | |||
import org.sonar.process.cluster.health.NodeDetails; | |||
import org.sonar.process.cluster.health.NodeHealth; | |||
import static org.sonar.cluster.health.NodeHealth.Status.GREEN; | |||
import static org.sonar.cluster.health.NodeHealth.Status.RED; | |||
import static org.sonar.cluster.health.NodeHealth.Status.YELLOW; | |||
import static org.sonar.core.util.stream.MoreCollectors.toSet; | |||
import static org.sonar.process.cluster.health.NodeHealth.Status.GREEN; | |||
import static org.sonar.process.cluster.health.NodeHealth.Status.RED; | |||
import static org.sonar.process.cluster.health.NodeHealth.Status.YELLOW; | |||
import static org.sonar.server.health.Health.newHealthCheckBuilder; | |||
public class AppNodeClusterCheck implements ClusterHealthCheck { |
@@ -21,7 +21,7 @@ package org.sonar.server.health; | |||
import java.util.Objects; | |||
import java.util.Set; | |||
import org.sonar.cluster.health.NodeHealth; | |||
import org.sonar.process.cluster.health.NodeHealth; | |||
import static com.google.common.collect.ImmutableSet.copyOf; | |||
import static java.util.Objects.requireNonNull; |
@@ -20,7 +20,7 @@ | |||
package org.sonar.server.health; | |||
import java.util.Set; | |||
import org.sonar.cluster.health.NodeHealth; | |||
import org.sonar.process.cluster.health.NodeHealth; | |||
public interface ClusterHealthCheck { | |||
Health check(Set<NodeHealth> nodeHealths); |
@@ -21,7 +21,7 @@ package org.sonar.server.health; | |||
import java.util.Set; | |||
import java.util.stream.Stream; | |||
import org.sonar.cluster.health.NodeHealth; | |||
import org.sonar.process.cluster.health.NodeHealth; | |||
interface ClusterHealthSubCheck extends ClusterHealthCheck { | |||
@@ -20,7 +20,7 @@ | |||
package org.sonar.server.health; | |||
import java.util.Set; | |||
import org.sonar.cluster.health.NodeHealth; | |||
import org.sonar.process.cluster.health.NodeHealth; | |||
import org.sonar.server.es.EsClient; | |||
public class EsStatusClusterCheck extends EsStatusCheck implements ClusterHealthCheck { |
@@ -23,8 +23,8 @@ import java.util.List; | |||
import java.util.Set; | |||
import javax.annotation.CheckForNull; | |||
import javax.annotation.Nullable; | |||
import org.sonar.cluster.health.NodeHealth; | |||
import org.sonar.cluster.health.SharedHealthState; | |||
import org.sonar.process.cluster.health.NodeHealth; | |||
import org.sonar.process.cluster.health.SharedHealthState; | |||
import org.sonar.server.platform.WebServer; | |||
import static com.google.common.base.Preconditions.checkState; |
@@ -22,7 +22,7 @@ package org.sonar.server.health; | |||
import com.google.common.util.concurrent.ThreadFactoryBuilder; | |||
import java.util.concurrent.Executors; | |||
import java.util.concurrent.ScheduledExecutorService; | |||
import org.sonar.cluster.health.HealthStateRefresherExecutorService; | |||
import org.sonar.process.cluster.health.HealthStateRefresherExecutorService; | |||
import org.sonar.server.util.AbstractStoppableScheduledExecutorServiceImpl; | |||
public class HealthStateRefresherExecutorServiceImpl |
@@ -19,9 +19,9 @@ | |||
*/ | |||
package org.sonar.server.health; | |||
import org.sonar.cluster.health.HealthStateRefresher; | |||
import org.sonar.cluster.health.SharedHealthStateImpl; | |||
import org.sonar.core.platform.Module; | |||
import org.sonar.process.cluster.health.HealthStateRefresher; | |||
import org.sonar.process.cluster.health.SharedHealthStateImpl; | |||
public class NodeHealthModule extends Module { | |||
@Override |
@@ -20,19 +20,19 @@ | |||
package org.sonar.server.health; | |||
import java.util.function.Supplier; | |||
import org.sonar.NetworkUtils; | |||
import org.sonar.api.config.Configuration; | |||
import org.sonar.api.platform.Server; | |||
import org.sonar.cluster.health.NodeDetails; | |||
import org.sonar.cluster.health.NodeHealth; | |||
import org.sonar.cluster.health.NodeHealthProvider; | |||
import org.sonar.process.NetworkUtils; | |||
import org.sonar.process.cluster.health.NodeDetails; | |||
import org.sonar.process.cluster.health.NodeHealth; | |||
import org.sonar.process.cluster.health.NodeHealthProvider; | |||
import static java.lang.String.format; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_HOST; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_NAME; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_PORT; | |||
import static org.sonar.cluster.health.NodeDetails.newNodeDetailsBuilder; | |||
import static org.sonar.cluster.health.NodeHealth.newNodeHealthBuilder; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_NODE_HOST; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_NODE_NAME; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_NODE_PORT; | |||
import static org.sonar.process.cluster.health.NodeDetails.newNodeDetailsBuilder; | |||
import static org.sonar.process.cluster.health.NodeHealth.newNodeHealthBuilder; | |||
public class NodeHealthProviderImpl implements NodeHealthProvider { | |||
private final HealthChecker healthChecker; |
@@ -21,13 +21,13 @@ package org.sonar.server.health; | |||
import java.util.Arrays; | |||
import java.util.Set; | |||
import org.sonar.cluster.health.NodeDetails; | |||
import org.sonar.cluster.health.NodeHealth; | |||
import org.sonar.process.cluster.health.NodeDetails; | |||
import org.sonar.process.cluster.health.NodeHealth; | |||
import static org.sonar.cluster.health.NodeHealth.Status.GREEN; | |||
import static org.sonar.cluster.health.NodeHealth.Status.RED; | |||
import static org.sonar.cluster.health.NodeHealth.Status.YELLOW; | |||
import static org.sonar.core.util.stream.MoreCollectors.toSet; | |||
import static org.sonar.process.cluster.health.NodeHealth.Status.GREEN; | |||
import static org.sonar.process.cluster.health.NodeHealth.Status.RED; | |||
import static org.sonar.process.cluster.health.NodeHealth.Status.YELLOW; | |||
import static org.sonar.server.health.Health.newHealthCheckBuilder; | |||
public class SearchNodeClusterCheck implements ClusterHealthCheck { |
@@ -18,9 +18,10 @@ | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package org.sonar.cluster.localclient; | |||
package org.sonar.server.hz; | |||
import com.google.common.annotations.VisibleForTesting; | |||
import com.google.common.base.Preconditions; | |||
import com.google.common.collect.ImmutableSet; | |||
import com.hazelcast.client.config.ClientConfig; | |||
import com.hazelcast.core.HazelcastInstance; | |||
@@ -31,12 +32,12 @@ import java.util.Set; | |||
import java.util.concurrent.locks.Lock; | |||
import org.picocontainer.Startable; | |||
import org.sonar.api.config.Configuration; | |||
import org.sonar.cluster.ClusterObjectKeys; | |||
import org.sonar.process.cluster.ClusterObjectKeys; | |||
import org.sonar.process.cluster.HazelcastClient; | |||
import static com.google.common.base.Preconditions.checkState; | |||
import static org.apache.commons.lang.StringUtils.isNotEmpty; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_ENABLED; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_LOCALENDPOINT; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_ENABLED; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_LOCALENDPOINT; | |||
/** | |||
* This class will connect as a Hazelcast client to the local instance of Hazelcluster | |||
@@ -53,8 +54,8 @@ public class HazelcastLocalClient implements Startable, HazelcastClient { | |||
boolean clusterEnabled = config.getBoolean(CLUSTER_ENABLED).orElse(false); | |||
String clusterLocalEndPoint = config.get(CLUSTER_LOCALENDPOINT).orElse(null); | |||
checkState(clusterEnabled, "Cluster is not enabled"); | |||
checkState(isNotEmpty(clusterLocalEndPoint), "LocalEndPoint have not been set"); | |||
Preconditions.checkState(clusterEnabled, "Cluster is not enabled"); | |||
Preconditions.checkState(isNotEmpty(clusterLocalEndPoint), "LocalEndPoint have not been set"); | |||
hzConfig = new ClientConfig(); | |||
hzConfig.getGroupConfig().setName(HAZELCAST_CLUSTER_NAME); |
@@ -18,6 +18,6 @@ | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
@ParametersAreNonnullByDefault | |||
package org.sonar.cluster; | |||
package org.sonar.server.hz; | |||
import javax.annotation.ParametersAreNonnullByDefault; |
@@ -19,10 +19,12 @@ | |||
*/ | |||
package org.sonar.server.platform; | |||
import org.sonar.process.cluster.ClusterProperties; | |||
public interface WebServer { | |||
/** | |||
* WebServer is standalone when property {@link org.sonar.cluster.ClusterProperties#CLUSTER_ENABLED} is {@code false} or | |||
* WebServer is standalone when property {@link ClusterProperties#CLUSTER_ENABLED} is {@code false} or | |||
* undefined. | |||
*/ | |||
boolean isStandalone(); |
@@ -22,8 +22,8 @@ package org.sonar.server.platform; | |||
import org.sonar.api.config.Configuration; | |||
import org.sonar.api.utils.log.Loggers; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_ENABLED; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_WEB_LEADER; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_ENABLED; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_WEB_LEADER; | |||
public class WebServerImpl implements WebServer { | |||
@@ -22,7 +22,7 @@ package org.sonar.server.platform.platformlevel; | |||
import java.time.Clock; | |||
import java.util.Properties; | |||
import javax.annotation.Nullable; | |||
import org.sonar.NetworkUtils; | |||
import org.sonar.process.NetworkUtils; | |||
import org.sonar.api.SonarQubeSide; | |||
import org.sonar.api.SonarQubeVersion; | |||
import org.sonar.api.internal.ApiVersion; |
@@ -31,7 +31,6 @@ import org.sonar.api.rules.XMLRuleParser; | |||
import org.sonar.api.server.rule.RulesDefinitionXmlLoader; | |||
import org.sonar.ce.CeModule; | |||
import org.sonar.ce.settings.ProjectConfigurationFactory; | |||
import org.sonar.cluster.localclient.HazelcastLocalClient; | |||
import org.sonar.core.component.DefaultResourceTypes; | |||
import org.sonar.core.timemachine.Periods; | |||
import org.sonar.server.authentication.AuthenticationModule; | |||
@@ -63,6 +62,7 @@ import org.sonar.server.es.metadata.MetadataIndexDefinition; | |||
import org.sonar.server.event.NewAlerts; | |||
import org.sonar.server.favorite.FavoriteModule; | |||
import org.sonar.server.health.NodeHealthModule; | |||
import org.sonar.server.hz.HazelcastLocalClient; | |||
import org.sonar.server.issue.AddTagsAction; | |||
import org.sonar.server.issue.AssignAction; | |||
import org.sonar.server.issue.CommentAction; |
@@ -22,8 +22,8 @@ package org.sonar.server.platform.ws; | |||
import com.google.common.io.Resources; | |||
import java.util.Comparator; | |||
import org.sonar.api.server.ws.WebService; | |||
import org.sonar.cluster.health.NodeDetails; | |||
import org.sonar.cluster.health.NodeHealth; | |||
import org.sonar.process.cluster.health.NodeDetails; | |||
import org.sonar.process.cluster.health.NodeHealth; | |||
import org.sonar.server.health.ClusterHealth; | |||
import org.sonar.server.health.Health; | |||
import org.sonar.server.health.HealthChecker; |
@@ -28,7 +28,7 @@ import org.apache.commons.io.FileUtils; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.TemporaryFolder; | |||
import org.sonar.NetworkUtils; | |||
import org.sonar.process.NetworkUtils; | |||
import org.sonar.process.Props; | |||
import static org.assertj.core.api.Assertions.assertThat; |
@@ -34,10 +34,10 @@ import org.sonar.process.ProcessProperties; | |||
import static java.lang.String.format; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_ENABLED; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_NAME; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_TYPE; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_SEARCH_HOSTS; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_ENABLED; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_NAME; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_NODE_TYPE; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_SEARCH_HOSTS; | |||
public class EsClientProviderTest { | |||
@@ -32,7 +32,7 @@ import org.sonar.process.ProcessProperties; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.data.MapEntry.entry; | |||
import static org.junit.Assert.fail; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_ENABLED; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_ENABLED; | |||
import static org.sonar.server.es.NewIndex.SettingsConfiguration.newBuilder; | |||
public class NewIndexTest { |
@@ -25,15 +25,15 @@ import java.util.Set; | |||
import java.util.stream.IntStream; | |||
import java.util.stream.Stream; | |||
import org.junit.Test; | |||
import org.sonar.cluster.health.NodeDetails; | |||
import org.sonar.cluster.health.NodeHealth; | |||
import org.sonar.process.cluster.health.NodeDetails; | |||
import org.sonar.process.cluster.health.NodeHealth; | |||
import static java.util.stream.Collectors.toSet; | |||
import static java.util.stream.Stream.of; | |||
import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; | |||
import static org.sonar.cluster.health.NodeHealth.Status.GREEN; | |||
import static org.sonar.cluster.health.NodeHealth.Status.RED; | |||
import static org.sonar.cluster.health.NodeHealth.Status.YELLOW; | |||
import static org.sonar.process.cluster.health.NodeHealth.Status.GREEN; | |||
import static org.sonar.process.cluster.health.NodeHealth.Status.RED; | |||
import static org.sonar.process.cluster.health.NodeHealth.Status.YELLOW; | |||
import static org.sonar.server.health.HealthAssert.assertThat; | |||
public class AppNodeClusterCheckTest { |
@@ -27,8 +27,8 @@ import java.util.stream.IntStream; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.cluster.health.NodeDetails; | |||
import org.sonar.cluster.health.NodeHealth; | |||
import org.sonar.process.cluster.health.NodeDetails; | |||
import org.sonar.process.cluster.health.NodeHealth; | |||
import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; | |||
import static org.assertj.core.api.Assertions.assertThat; |
@@ -26,8 +26,8 @@ import java.util.stream.IntStream; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.mockito.Mockito; | |||
import org.sonar.cluster.health.NodeDetails; | |||
import org.sonar.cluster.health.NodeHealth; | |||
import org.sonar.process.cluster.health.NodeDetails; | |||
import org.sonar.process.cluster.health.NodeHealth; | |||
import org.sonar.server.es.EsClient; | |||
import org.sonar.server.es.EsTester; | |||
@@ -28,7 +28,7 @@ import java.util.Set; | |||
import java.util.stream.Collectors; | |||
import javax.annotation.Nullable; | |||
import org.assertj.core.api.AbstractAssert; | |||
import org.sonar.cluster.health.NodeHealth; | |||
import org.sonar.process.cluster.health.NodeHealth; | |||
final class HealthAssert extends AbstractAssert<HealthAssert, Health> { | |||
private Set<NodeHealth> nodeHealths; |
@@ -31,9 +31,9 @@ import java.util.stream.Stream; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.cluster.health.NodeDetails; | |||
import org.sonar.cluster.health.NodeHealth; | |||
import org.sonar.cluster.health.SharedHealthState; | |||
import org.sonar.process.cluster.health.NodeDetails; | |||
import org.sonar.process.cluster.health.NodeHealth; | |||
import org.sonar.process.cluster.health.SharedHealthState; | |||
import org.sonar.server.platform.WebServer; | |||
import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; | |||
@@ -42,8 +42,8 @@ import static org.mockito.Matchers.same; | |||
import static org.mockito.Mockito.mock; | |||
import static org.mockito.Mockito.verify; | |||
import static org.mockito.Mockito.when; | |||
import static org.sonar.cluster.health.NodeDetails.newNodeDetailsBuilder; | |||
import static org.sonar.cluster.health.NodeHealth.newNodeHealthBuilder; | |||
import static org.sonar.process.cluster.health.NodeDetails.newNodeDetailsBuilder; | |||
import static org.sonar.process.cluster.health.NodeHealth.newNodeHealthBuilder; | |||
import static org.sonar.server.health.Health.newHealthCheckBuilder; | |||
import static org.sonar.server.health.Health.Status.GREEN; | |||
import static org.sonar.server.health.Health.Status.RED; |
@@ -26,13 +26,13 @@ import java.util.Random; | |||
import java.util.stream.Collectors; | |||
import org.junit.Test; | |||
import org.picocontainer.ComponentAdapter; | |||
import org.sonar.NetworkUtils; | |||
import org.sonar.api.config.internal.MapSettings; | |||
import org.sonar.api.platform.Server; | |||
import org.sonar.api.utils.System2; | |||
import org.sonar.cluster.health.SharedHealthStateImpl; | |||
import org.sonar.cluster.localclient.HazelcastClient; | |||
import org.sonar.core.platform.ComponentContainer; | |||
import org.sonar.process.NetworkUtils; | |||
import org.sonar.process.cluster.HazelcastClient; | |||
import org.sonar.process.cluster.health.SharedHealthStateImpl; | |||
import static java.lang.String.valueOf; | |||
import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; |
@@ -26,20 +26,20 @@ import java.util.stream.IntStream; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.NetworkUtils; | |||
import org.sonar.api.config.internal.MapSettings; | |||
import org.sonar.api.platform.Server; | |||
import org.sonar.cluster.health.NodeDetails; | |||
import org.sonar.cluster.health.NodeHealth; | |||
import org.sonar.process.NetworkUtils; | |||
import org.sonar.process.cluster.health.NodeDetails; | |||
import org.sonar.process.cluster.health.NodeHealth; | |||
import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic; | |||
import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.mockito.Mockito.mock; | |||
import static org.mockito.Mockito.when; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_HOST; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_NAME; | |||
import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_PORT; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_NODE_HOST; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_NODE_NAME; | |||
import static org.sonar.process.cluster.ClusterProperties.CLUSTER_NODE_PORT; | |||
public class NodeHealthProviderImplTest { | |||
@Rule |
@@ -25,15 +25,15 @@ import java.util.Set; | |||
import java.util.stream.IntStream; | |||
import java.util.stream.Stream; | |||
import org.junit.Test; | |||
import org.sonar.cluster.health.NodeDetails; | |||
import org.sonar.cluster.health.NodeHealth; | |||
import org.sonar.process.cluster.health.NodeDetails; | |||
import org.sonar.process.cluster.health.NodeHealth; | |||
import static java.util.stream.Collectors.toSet; | |||
import static java.util.stream.Stream.of; | |||
import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; | |||
import static org.sonar.cluster.health.NodeHealth.Status.GREEN; | |||
import static org.sonar.cluster.health.NodeHealth.Status.RED; | |||
import static org.sonar.cluster.health.NodeHealth.Status.YELLOW; | |||
import static org.sonar.process.cluster.health.NodeHealth.Status.GREEN; | |||
import static org.sonar.process.cluster.health.NodeHealth.Status.RED; | |||
import static org.sonar.process.cluster.health.NodeHealth.Status.YELLOW; | |||
import static org.sonar.server.health.HealthAssert.assertThat; | |||
public class SearchNodeClusterCheckTest { |