From 69a73bc1eb2e4178ac4daef8417e3b2d123ad9ee Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Lesaint?= Date: Fri, 11 Mar 2016 13:38:03 +0100 Subject: [PATCH] SONAR-6732 add components from PlatformLevel1 to CE container --- .../container/ComputeEngineContainerImpl.java | 83 ++++++++++++++++++- .../ComputeEngineContainerImplTest.java | 35 +++++++- 2 files changed, 114 insertions(+), 4 deletions(-) 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 445c5f95c96..26426184039 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 @@ -20,10 +20,71 @@ package org.sonar.ce.container; import com.google.common.annotations.VisibleForTesting; +import java.util.List; +import org.sonar.api.utils.System2; +import org.sonar.core.config.CorePropertyDefinitions; import org.sonar.core.platform.ComponentContainer; +import org.sonar.core.platform.Module; +import org.sonar.core.platform.SonarQubeVersionProvider; +import org.sonar.core.util.UuidFactoryImpl; +import org.sonar.db.DaoModule; +import org.sonar.db.DatabaseChecker; +import org.sonar.db.DbClient; +import org.sonar.db.DefaultDatabase; +import org.sonar.db.purge.PurgeProfiler; +import org.sonar.db.version.DatabaseVersion; +import org.sonar.db.version.MigrationStepModule; import org.sonar.process.Props; +import org.sonar.server.computation.property.CePropertyDefinitions; +import org.sonar.server.issue.index.IssueIndex; +import org.sonar.server.platform.DatabaseServerCompatibility; +import org.sonar.server.platform.DefaultServerFileSystem; +import org.sonar.server.platform.ServerImpl; +import org.sonar.server.platform.ServerSettings; +import org.sonar.server.platform.TempFolderProvider; +import org.sonar.server.qualityprofile.index.ActiveRuleIndex; +import org.sonar.server.rule.index.RuleIndex; +import org.sonar.server.search.EsSearchModule; public class ComputeEngineContainerImpl implements ComputeEngineContainer { + private static final Object[] LEVEL_1_COMPONENTS = new Object[] { + new SonarQubeVersionProvider(), + ServerSettings.class, + ServerImpl.class, + UuidFactoryImpl.INSTANCE, + // no EmbeddedDatabaseFactory.class, creating H2 DB if responsibility of WebServer + DefaultDatabase.class, + DatabaseChecker.class, + // must instantiate deprecated class in 5.2 and only this one (and not its replacement) + // to avoid having two SqlSessionFactory instances + org.sonar.core.persistence.MyBatis.class, + DatabaseServerCompatibility.class, + DatabaseVersion.class, + PurgeProfiler.class, + DefaultServerFileSystem.class, + // no TempFolderCleaner.class, responsibility of Web Server + new TempFolderProvider(), + System2.INSTANCE, + + // DB + DbClient.class, + DaoModule.class, + MigrationStepModule.class, + + // Elasticsearch + EsSearchModule.class, + + // rules/qprofiles + RuleIndex.class, + ActiveRuleIndex.class, + + // issues + IssueIndex.class, + + // Classes kept for backward compatibility of plugins/libs (like sonar-license) that are directly calling classes from the core + org.sonar.core.properties.PropertiesDao.class + }; + private final ComponentContainer componentContainer; public ComputeEngineContainerImpl() { @@ -32,12 +93,28 @@ public class ComputeEngineContainerImpl implements ComputeEngineContainer { @Override public ComputeEngineContainer configure(Props props) { - this.componentContainer.add( - props.rawProperties() - ); + this.componentContainer + .add(props.rawProperties()) + .add(LEVEL_1_COMPONENTS) + .add(toArray(CorePropertyDefinitions.all())) + .add(toArray(CePropertyDefinitions.all())); + + configureFromModules(); + return this; } + private static Object[] toArray(List list) { + return list.toArray(new Object[list.size()]); + } + + private void configureFromModules() { + List modules = this.componentContainer.getComponentsByType(Module.class); + for (Module module : modules) { + module.configure(this.componentContainer); + } + } + @Override public ComputeEngineContainer start() { this.componentContainer.startComponents(); 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 bf42fa8a390..abd6705062b 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 @@ -19,11 +19,17 @@ */ package org.sonar.ce.container; +import java.io.File; +import java.io.IOException; import java.util.Properties; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TemporaryFolder; import org.picocontainer.MutablePicoContainer; import org.sonar.api.config.PropertyDefinitions; +import org.sonar.api.database.DatabaseProperties; import org.sonar.core.platform.ComponentContainer; +import org.sonar.process.ProcessProperties; import org.sonar.process.Props; import static org.assertj.core.api.Assertions.assertThat; @@ -31,6 +37,9 @@ import static org.assertj.core.api.Assertions.assertThat; public class ComputeEngineContainerImplTest { private static final int COMPONENTS_IN_CONTAINER_AT_CONSTRUCTION = 2; + @Rule + public TemporaryFolder tempFolder = new TemporaryFolder(); + private ComputeEngineContainerImpl underTest = new ComputeEngineContainerImpl(); @Test @@ -56,7 +65,31 @@ public class ComputeEngineContainerImplTest { underTest.configure(new Props(properties)); assertThat(underTest.getComponentContainer().getPicoContainer().getComponentAdapters()) - .hasSize(COMPONENTS_IN_CONTAINER_AT_CONSTRUCTION + 1); + .hasSize(COMPONENTS_IN_CONTAINER_AT_CONSTRUCTION + + 22 // level 1 + + 47 // content of DaoModule + + 1 // content of EsSearchModule + + 58 // content of CorePropertyDefinitions + + 1 // content of CePropertyDefinitions + + 59 // content of MigrationStepModule + ); + } + + @Test + public void real_start() throws IOException { + Properties properties = new Properties(); + File homeDir = tempFolder.newFolder(); + File dataDir = new File(homeDir, "data"); + File tmpDir = new File(homeDir, "tmp"); + properties.setProperty(ProcessProperties.PATH_HOME, homeDir.getAbsolutePath()); + properties.setProperty(ProcessProperties.PATH_DATA, dataDir.getAbsolutePath()); + properties.setProperty(ProcessProperties.PATH_TEMP, tmpDir.getAbsolutePath()); + properties.setProperty(DatabaseProperties.PROP_URL, "jdbc:h2:mem:sonar"); + + underTest + .configure(new Props(properties)) + .start(); + } @Test -- 2.39.5