From 45d340cd14fc49494f832943e6d7ea109af87ec3 Mon Sep 17 00:00:00 2001 From: Sébastien Lesaint Date: Fri, 25 Aug 2017 15:13:55 +0200 Subject: SONAR-9741 fix TODO in ComputeEngineContainerImpl --- .../ce/container/ComputeEngineContainerImpl.java | 62 ++++++++++------------ 1 file changed, 29 insertions(+), 33 deletions(-) (limited to 'server/sonar-ce') 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 eaf94df4bdc..759a323fa29 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 @@ -55,6 +55,7 @@ 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; @@ -167,36 +168,23 @@ public class ComputeEngineContainerImpl implements ComputeEngineContainer { @Override public ComputeEngineContainer start(Props props) { this.level1 = new ComponentContainer(); - this.level1 - .add(props.rawProperties()) - .add(level1Components()) - .add(toArray(CorePropertyDefinitions.all())) - .add(requireNonNull(computeEngineStatus)); + populateLevel1(this.level1, props, requireNonNull(computeEngineStatus)); configureFromModules(this.level1); this.level1.startComponents(); ComponentContainer level2 = this.level1.createChild(); - level2.add(level2Components()); + populateLevel2(level2); configureFromModules(level2); level2.startComponents(); ComponentContainer level3 = level2.createChild(); - level3.add(level3Components()); + populateLevel3(level3); configureFromModules(level3); level3.startComponents(); this.level4 = level3.createChild(); - this.level4.add(level4Components()); + populateLevel4(this.level4, props); - // TODO refactoring levelXComponents() - if (props.valueAsBoolean("sonar.cluster.enabled")) { - this.level4.add( - HazelcastLocalClient.class, - CeDistributedInformationImpl.class); - } else { - this.level4.add( - StandaloneCeDistributedInformation.class); - } configureFromModules(this.level4); ServerExtensionInstaller extensionInstaller = this.level4.getComponentByType(ServerExtensionInstaller.class); extensionInstaller.installExtensions(this.level4); @@ -235,9 +223,10 @@ public class ComputeEngineContainerImpl implements ComputeEngineContainer { return level4; } - private static Object[] level1Components() { + private static void populateLevel1(ComponentContainer container, Props props, ComputeEngineStatus computeEngineStatus) { Version apiVersion = ApiVersion.load(System2.INSTANCE); - return new Object[] { + container.add( + props.rawProperties(), ThreadLocalSettings.class, new ConfigurationProvider(), new SonarQubeVersion(apiVersion), @@ -274,12 +263,13 @@ public class ComputeEngineContainerImpl implements ComputeEngineContainer { // issues IssueIndex.class, - new OkHttpClientProvider() - }; + new OkHttpClientProvider(), + computeEngineStatus); + container.add(toArray(CorePropertyDefinitions.all())); } - private static Object[] level2Components() { - return new Object[] { + private static void populateLevel2(ComponentContainer container) { + container.add( MigrationConfigurationModule.class, DatabaseVersion.class, DatabaseServerCompatibility.class, @@ -303,22 +293,21 @@ public class ComputeEngineContainerImpl implements ComputeEngineContainer { // depends on plugins DefaultI18n.class, // used by RuleI18nManager RuleI18nManager.class, // used by DebtRulesXMLImporter - Durations.class, // used in Web Services and DebtCalculator - }; + Durations.class // used in Web Services and DebtCalculator + ); } - private static Object[] level3Components() { - return new Object[] { + private static void populateLevel3(ComponentContainer container) { + container.add( new StartupMetadataProvider(), ServerIdManager.class, UriReader.class, ServerImpl.class, - DefaultOrganizationProviderImpl.class - }; + DefaultOrganizationProviderImpl.class); } - private static Object[] level4Components() { - return new Object[] { + private static void populateLevel4(ComponentContainer container, Props props) { + container.add( ResourceTypes.class, DefaultResourceTypes.get(), Periods.class, @@ -424,8 +413,15 @@ public class ComputeEngineContainerImpl implements ComputeEngineContainer { ProjectConfigurationFactory.class, // cleaning - CeCleaningModule.class - }; + CeCleaningModule.class); + + if (props.valueAsBoolean(ClusterProperties.CLUSTER_ENABLED)) { + container.add( + HazelcastLocalClient.class, + CeDistributedInformationImpl.class); + } else { + container.add(StandaloneCeDistributedInformation.class); + } } private static Object[] startupComponents() { -- cgit v1.2.3