aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-ce/src
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2017-06-29 18:13:15 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2017-07-04 23:47:46 +0200
commit5694a472f1f507f80c7aad3edee93df95a23a4c2 (patch)
treed8ba063d3bc7d3f65f65dc737287cf5b980d2879 /server/sonar-ce/src
parent4ad21e8bc6085cb13d16e5b7e68b475296833bd2 (diff)
downloadsonarqube-5694a472f1f507f80c7aad3edee93df95a23a4c2.tar.gz
sonarqube-5694a472f1f507f80c7aad3edee93df95a23a4c2.zip
SONAR-9478 Replace Settings by Configuration
Diffstat (limited to 'server/sonar-ce/src')
-rw-r--r--server/sonar-ce/src/main/java/org/sonar/ce/cluster/HazelcastClientWrapperImpl.java12
-rw-r--r--server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java12
-rw-r--r--server/sonar-ce/src/test/java/org/sonar/ce/cluster/HazelcastClientWrapperImplTest.java56
-rw-r--r--server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java2
4 files changed, 38 insertions, 44 deletions
diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/cluster/HazelcastClientWrapperImpl.java b/server/sonar-ce/src/main/java/org/sonar/ce/cluster/HazelcastClientWrapperImpl.java
index 13c383ba329..b913387c84a 100644
--- a/server/sonar-ce/src/main/java/org/sonar/ce/cluster/HazelcastClientWrapperImpl.java
+++ b/server/sonar-ce/src/main/java/org/sonar/ce/cluster/HazelcastClientWrapperImpl.java
@@ -29,7 +29,7 @@ import java.util.Map;
import java.util.Set;
import java.util.concurrent.locks.Lock;
import org.picocontainer.Startable;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
import org.sonar.process.ProcessProperties;
import static com.google.common.base.Preconditions.checkState;
@@ -46,10 +46,10 @@ public class HazelcastClientWrapperImpl implements Startable, HazelcastClientWra
@VisibleForTesting
protected HazelcastInstance hzInstance;
- public HazelcastClientWrapperImpl(Settings settings) {
- boolean clusterEnabled = settings.getBoolean(ProcessProperties.CLUSTER_ENABLED);
- String clusterName = settings.getString(ProcessProperties.CLUSTER_NAME);
- String clusterLocalEndPoint = settings.getString(ProcessProperties.CLUSTER_LOCALENDPOINT);
+ public HazelcastClientWrapperImpl(Configuration config) {
+ boolean clusterEnabled = config.getBoolean(ProcessProperties.CLUSTER_ENABLED).orElse(false);
+ String clusterName = config.get(ProcessProperties.CLUSTER_NAME).orElse(null);
+ String clusterLocalEndPoint = config.get(ProcessProperties.CLUSTER_LOCALENDPOINT).orElse(null);
checkState(clusterEnabled, "Cluster is not enabled");
checkState(isNotEmpty(clusterLocalEndPoint), "LocalEndPoint have not been set");
@@ -85,7 +85,7 @@ public class HazelcastClientWrapperImpl implements Startable, HazelcastClientWra
}
@Override
- public <K,V> Map<K,V> getReplicatedMap(String name) {
+ public <K, V> Map<K, V> getReplicatedMap(String name) {
return hzInstance.getReplicatedMap(name);
}
diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java b/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java
index 992df9f4a30..5f50464eb51 100644
--- a/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java
+++ b/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java
@@ -52,10 +52,11 @@ import org.sonar.ce.log.CeProcessLogging;
import org.sonar.ce.platform.ComputeEngineExtensionInstaller;
import org.sonar.ce.queue.CeQueueCleaner;
import org.sonar.ce.queue.PurgeCeActivities;
-import org.sonar.ce.settings.ProjectSettingsFactory;
+import org.sonar.ce.settings.ProjectConfigurationFactory;
import org.sonar.ce.taskprocessor.CeTaskProcessorModule;
import org.sonar.ce.user.CeUserSession;
import org.sonar.core.component.DefaultResourceTypes;
+import org.sonar.core.config.ConfigurationProvider;
import org.sonar.core.config.CorePropertyDefinitions;
import org.sonar.core.i18n.DefaultI18n;
import org.sonar.core.i18n.RuleI18nManager;
@@ -181,12 +182,10 @@ public class ComputeEngineContainerImpl implements ComputeEngineContainer {
if (props.valueAsBoolean("sonar.cluster.enabled")) {
this.level4.add(
HazelcastClientWrapperImpl.class,
- CeDistributedInformationImpl.class
- );
+ CeDistributedInformationImpl.class);
} else {
this.level4.add(
- StandaloneCeDistributedInformation.class
- );
+ StandaloneCeDistributedInformation.class);
}
configureFromModules(this.level4);
ServerExtensionInstaller extensionInstaller = this.level4.getComponentByType(ServerExtensionInstaller.class);
@@ -225,6 +224,7 @@ public class ComputeEngineContainerImpl implements ComputeEngineContainer {
Version apiVersion = ApiVersion.load(System2.INSTANCE);
return new Object[] {
ThreadLocalSettings.class,
+ new ConfigurationProvider(),
new SonarQubeVersion(apiVersion),
SonarRuntimeImpl.forSonarQube(ApiVersion.load(System2.INSTANCE), SonarQubeSide.COMPUTE_ENGINE),
CeProcessLogging.class,
@@ -406,7 +406,7 @@ public class ComputeEngineContainerImpl implements ComputeEngineContainer {
CeTaskProcessorModule.class,
InternalPropertiesImpl.class,
- ProjectSettingsFactory.class,
+ ProjectConfigurationFactory.class,
// cleaning
CeCleaningModule.class
diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/cluster/HazelcastClientWrapperImplTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/cluster/HazelcastClientWrapperImplTest.java
index 1267693e9e1..3c483a80f3e 100644
--- a/server/sonar-ce/src/test/java/org/sonar/ce/cluster/HazelcastClientWrapperImplTest.java
+++ b/server/sonar-ce/src/test/java/org/sonar/ce/cluster/HazelcastClientWrapperImplTest.java
@@ -36,7 +36,6 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
-import java.util.Properties;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@@ -51,7 +50,6 @@ import org.junit.rules.TestRule;
import org.junit.rules.Timeout;
import org.slf4j.LoggerFactory;
import org.sonar.api.config.PropertyDefinitions;
-import org.sonar.api.config.Settings;
import org.sonar.api.config.internal.MapSettings;
import org.sonar.process.NetworkUtils;
import org.sonar.process.ProcessProperties;
@@ -74,8 +72,8 @@ public class HazelcastClientWrapperImplTest {
int port = NetworkUtils.getNextAvailablePort(InetAddress.getLoopbackAddress());
hzCluster = HazelcastTestHelper.createHazelcastCluster("cluster_with_client", port);
- Settings settings = createClusterSettings("cluster_with_client", "localhost:" + port);
- hzClient = new HazelcastClientWrapperImpl(settings);
+ MapSettings settings = createClusterSettings("cluster_with_client", "localhost:" + port);
+ hzClient = new HazelcastClientWrapperImpl(settings.asConfig());
}
@AfterClass
@@ -94,8 +92,8 @@ public class HazelcastClientWrapperImplTest {
@Test
public void start_throws_ISE_if_LOCALENDPOINT_is_incorrect() {
- Settings settings = createClusterSettings("sonarqube", "\u4563\u1432\u1564");
- HazelcastClientWrapperImpl hzClient = new HazelcastClientWrapperImpl(settings);
+ MapSettings settings = createClusterSettings("sonarqube", "\u4563\u1432\u1564");
+ HazelcastClientWrapperImpl hzClient = new HazelcastClientWrapperImpl(settings.asConfig());
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("Unable to connect to any address in the config! The following addresses were tried:");
@@ -105,56 +103,56 @@ public class HazelcastClientWrapperImplTest {
@Test
public void constructor_throws_ISE_if_LOCALENDPOINT_is_empty() {
- Settings settings = createClusterSettings("sonarqube", "");
+ MapSettings settings = createClusterSettings("sonarqube", "");
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("LocalEndPoint have not been set");
- new HazelcastClientWrapperImpl(settings);
+ new HazelcastClientWrapperImpl(settings.asConfig());
}
@Test
public void constructor_throws_ISE_if_CLUSTER_ENABLED_is_false() {
- Settings settings = createClusterSettings("sonarqube", "localhost:9003");
+ MapSettings settings = createClusterSettings("sonarqube", "localhost:9003");
settings.setProperty(ProcessProperties.CLUSTER_ENABLED, false);
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("Cluster is not enabled");
- new HazelcastClientWrapperImpl(settings);
+ new HazelcastClientWrapperImpl(settings.asConfig());
}
@Test
public void constructor_throws_ISE_if_missing_CLUSTER_ENABLED() {
- Settings settings = createClusterSettings("sonarqube", "localhost:9003");
+ MapSettings settings = createClusterSettings("sonarqube", "localhost:9003");
settings.removeProperty(ProcessProperties.CLUSTER_ENABLED);
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("Cluster is not enabled");
- new HazelcastClientWrapperImpl(settings);
+ new HazelcastClientWrapperImpl(settings.asConfig());
}
@Test
public void constructor_throws_ISE_if_missing_CLUSTER_NAME() {
- Settings settings = createClusterSettings("sonarqube", "localhost:9003");
+ MapSettings settings = createClusterSettings("sonarqube", "localhost:9003");
settings.removeProperty(ProcessProperties.CLUSTER_NAME);
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("sonar.cluster.name is missing");
- new HazelcastClientWrapperImpl(settings);
+ new HazelcastClientWrapperImpl(settings.asConfig());
}
@Test
public void constructor_throws_ISE_if_missing_CLUSTER_LOCALENDPOINT() {
- Settings settings = createClusterSettings("sonarqube", "localhost:9003");
+ MapSettings settings = createClusterSettings("sonarqube", "localhost:9003");
settings.removeProperty(ProcessProperties.CLUSTER_LOCALENDPOINT);
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("LocalEndPoint have not been set");
- new HazelcastClientWrapperImpl(settings);
+ new HazelcastClientWrapperImpl(settings.asConfig());
}
@Test
@@ -162,9 +160,9 @@ public class HazelcastClientWrapperImplTest {
int port = NetworkUtils.getNextAvailablePort(InetAddress.getLoopbackAddress());
// Launch a fake Hazelcast instance
HazelcastInstance hzInstance = HazelcastTestHelper.createHazelcastCluster("client_must_connect_to_hazelcast", port);
- Settings settings = createClusterSettings("client_must_connect_to_hazelcast", "localhost:" + port);
+ MapSettings settings = createClusterSettings("client_must_connect_to_hazelcast", "localhost:" + port);
- HazelcastClientWrapperImpl hazelcastClientWrapperImpl = new HazelcastClientWrapperImpl(settings);
+ HazelcastClientWrapperImpl hazelcastClientWrapperImpl = new HazelcastClientWrapperImpl(settings.asConfig());
ClientListenerImpl clientListener = new ClientListenerImpl();
hzInstance.getClientService().addClientListener(clientListener);
try {
@@ -184,9 +182,8 @@ public class HazelcastClientWrapperImplTest {
Set<String> setTest = new HashSet<>();
setTest.addAll(
- Arrays.asList(RandomStringUtils.randomAlphanumeric(10), RandomStringUtils.randomAlphanumeric(10))
- );
- Map<String, Set<String>> replicatedMap = hzClient.getReplicatedMap("TEST1");
+ Arrays.asList(RandomStringUtils.randomAlphanumeric(10), RandomStringUtils.randomAlphanumeric(10)));
+ Map<String, Set<String>> replicatedMap = hzClient.getReplicatedMap("TEST1");
replicatedMap.put("KEY1", ImmutableSet.copyOf(setTest));
assertThat(hzCluster.getReplicatedMap("TEST1"))
.containsOnlyKeys("KEY1");
@@ -235,8 +232,7 @@ public class HazelcastClientWrapperImplTest {
mapTest.put("a", Arrays.asList("123", "456"));
hzCluster.getMap("TEST3").putAll(mapTest);
assertThat(hzClient.getMap("TEST3")).containsExactly(
- entry("a", Arrays.asList("123", "456"))
- );
+ entry("a", Arrays.asList("123", "456")));
} finally {
hzClient.stop();
}
@@ -272,8 +268,7 @@ public class HazelcastClientWrapperImplTest {
}
assertThat(memoryAppender.events).isNotEmpty();
memoryAppender.events.stream().forEach(
- e -> assertThat(e.getLoggerName()).startsWith("com.hazelcast")
- );
+ e -> assertThat(e.getLoggerName()).startsWith("com.hazelcast"));
}
private class ClientListenerImpl implements ClientListener {
@@ -290,12 +285,11 @@ public class HazelcastClientWrapperImplTest {
}
}
- private static Settings createClusterSettings(String name, String localEndPoint) {
- Properties properties = new Properties();
- properties.setProperty(ProcessProperties.CLUSTER_NAME, name);
- properties.setProperty(ProcessProperties.CLUSTER_LOCALENDPOINT, localEndPoint);
- properties.setProperty(ProcessProperties.CLUSTER_ENABLED, "true");
- return new MapSettings(new PropertyDefinitions()).addProperties(properties);
+ private static MapSettings createClusterSettings(String name, String localEndPoint) {
+ return new MapSettings(new PropertyDefinitions())
+ .setProperty(ProcessProperties.CLUSTER_NAME, name)
+ .setProperty(ProcessProperties.CLUSTER_LOCALENDPOINT, localEndPoint)
+ .setProperty(ProcessProperties.CLUSTER_ENABLED, "true");
}
private class MemoryAppender<E> extends AppenderBase<E> {
diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java
index 4fdec8c4058..ca5b507a24b 100644
--- a/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java
+++ b/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java
@@ -134,7 +134,7 @@ public class ComputeEngineContainerImplTest {
);
assertThat(picoContainer.getParent().getParent().getParent().getComponentAdapters()).hasSize(
COMPONENTS_IN_LEVEL_1_AT_CONSTRUCTION
- + 23 // level 1
+ + 24 // level 1
+ 46 // content of DaoModule
+ 3 // content of EsSearchModule
+ 58 // content of CorePropertyDefinitions