diff options
author | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2014-10-31 10:54:32 +0100 |
---|---|---|
committer | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2014-10-31 13:53:23 +0100 |
commit | a067ae93be8a7303a94b901b0b3e8cd212c19788 (patch) | |
tree | d1b096521679d413f4bac57c4c8c9912f7f19a6b /server | |
parent | ac5b044e84b65a1b0fae568070049c3ba1e675fd (diff) | |
download | sonarqube-a067ae93be8a7303a94b901b0b3e8cd212c19788.tar.gz sonarqube-a067ae93be8a7303a94b901b0b3e8cd212c19788.zip |
SONAR-5795 Move project indexation post job on server side
Diffstat (limited to 'server')
13 files changed, 205 insertions, 72 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/ComputationService.java b/server/sonar-server/src/main/java/org/sonar/server/computation/ComputationService.java index b49f2dce617..afb6b8542b6 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/ComputationService.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/ComputationService.java @@ -65,7 +65,7 @@ public class ComputationService implements ServerComponent { try { report.succeed(); for (ComputationStep step : stepRegistry.steps()) { - TimeProfiler stepProfiler = new TimeProfiler(LOG).start(step.description()); + TimeProfiler stepProfiler = new TimeProfiler(LOG).start(step.getDescription()); step.execute(session, report, project); session.commit(); stepProfiler.stop(); diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/ComputationStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/ComputationStep.java index a451f09da94..ed52abee335 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/ComputationStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/ComputationStep.java @@ -29,5 +29,5 @@ public interface ComputationStep extends ServerComponent { void execute(DbSession session, AnalysisReportDto analysisReportDto, ComponentDto project); - String description(); + String getDescription(); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/ComputationStepRegistry.java b/server/sonar-server/src/main/java/org/sonar/server/computation/ComputationStepRegistry.java index 0e392ca2aad..f5140b19d25 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/ComputationStepRegistry.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/ComputationStepRegistry.java @@ -21,24 +21,30 @@ package org.sonar.server.computation; import com.google.common.collect.ImmutableList; +import com.google.common.collect.Lists; import org.sonar.api.ServerComponent; +import org.sonar.api.platform.ComponentContainer; import java.util.List; public class ComputationStepRegistry implements ServerComponent { - private final List<ComputationStep> steps; + private final ComponentContainer pico; + + public ComputationStepRegistry(ComponentContainer pico) { + this.pico = pico; - public ComputationStepRegistry( - SynchronizeProjectPermissionsStep synchronizeProjectPermissionsStep, - IndexProjectIssuesStep indexProjectIssuesStep, - SwitchSnapshotStep switchSnapshotStep, - DataCleanerStep dataCleanerStep, - InvalidatePreviewCacheStep invalidatePreviewCacheStep) { - steps = ImmutableList.of(synchronizeProjectPermissionsStep, switchSnapshotStep, invalidatePreviewCacheStep, dataCleanerStep, indexProjectIssuesStep); } public List<ComputationStep> steps() { - return steps; + List<ComputationStep> steps = Lists.newArrayList(); + steps.add(pico.getComponentByType(SynchronizeProjectPermissionsStep.class)); + steps.add(pico.getComponentByType(SwitchSnapshotStep.class)); + steps.add(pico.getComponentByType(InvalidatePreviewCacheStep.class)); + steps.add(pico.getComponentByType(DataCleanerStep.class)); + steps.add(pico.getComponentByType(ProjectDatabaseIndexationStep.class)); + steps.add(pico.getComponentByType(IndexProjectIssuesStep.class)); + + return ImmutableList.copyOf(steps); } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/DataCleanerStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/DataCleanerStep.java index fcd0de2e2b4..8532f486ad1 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/DataCleanerStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/DataCleanerStep.java @@ -53,7 +53,7 @@ public class DataCleanerStep implements ComputationStep { } @Override - public String description() { + public String getDescription() { return "Purge database"; } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/IndexProjectIssuesStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/IndexProjectIssuesStep.java index d84cff541ac..34936e7febe 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/IndexProjectIssuesStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/IndexProjectIssuesStep.java @@ -47,7 +47,7 @@ public class IndexProjectIssuesStep implements ComputationStep { } @Override - public String description() { + public String getDescription() { return "Update issues index"; } diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/InvalidatePreviewCacheStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/InvalidatePreviewCacheStep.java index dcdf9c822d1..e71ee278627 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/InvalidatePreviewCacheStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/InvalidatePreviewCacheStep.java @@ -46,7 +46,7 @@ public class InvalidatePreviewCacheStep implements ComputationStep { } @Override - public String description() { + public String getDescription() { return "Invalidate preview cache"; } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/ProjectDatabaseIndexationStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/ProjectDatabaseIndexationStep.java new file mode 100644 index 00000000000..7f2c5d33503 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/ProjectDatabaseIndexationStep.java @@ -0,0 +1,44 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube 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. + * + * SonarQube 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.server.computation; + +import org.sonar.core.component.ComponentDto; +import org.sonar.core.computation.db.AnalysisReportDto; +import org.sonar.core.persistence.DbSession; +import org.sonar.core.resource.ResourceIndexerDao; + +public class ProjectDatabaseIndexationStep implements ComputationStep { + private final ResourceIndexerDao resourceIndexerDao; + + public ProjectDatabaseIndexationStep(ResourceIndexerDao resourceIndexerDao) { + this.resourceIndexerDao = resourceIndexerDao; + } + + @Override + public void execute(DbSession session, AnalysisReportDto analysisReportDto, ComponentDto project) { + resourceIndexerDao.indexProject(project.getId().intValue()); + } + + @Override + public String getDescription() { + return "Index project in database"; + } +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/SwitchSnapshotStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/SwitchSnapshotStep.java index 1fe6f0a29b9..c1109ed6310 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/SwitchSnapshotStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/SwitchSnapshotStep.java @@ -43,7 +43,7 @@ public class SwitchSnapshotStep implements ComputationStep { } @Override - public String description() { + public String getDescription() { return "Switch last snapshot flag"; } diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/SynchronizeProjectPermissionsStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/SynchronizeProjectPermissionsStep.java index 7d388dd8e08..01815b0a857 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/SynchronizeProjectPermissionsStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/SynchronizeProjectPermissionsStep.java @@ -47,7 +47,7 @@ public class SynchronizeProjectPermissionsStep implements ComputationStep { } @Override - public String description() { + public String getDescription() { return "Synchronize project permissions"; } diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java b/server/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java index cefc8430479..03132c8a74b 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java @@ -271,7 +271,7 @@ class ServerComponents { ActivityNormalizer.class, ActivityIndex.class, ActivityDao.class - )); + )); components.addAll(CorePropertyDefinitions.all()); components.addAll(DatabaseMigrations.CLASSES); components.addAll(DaoUtils.getDaoClasses()); @@ -304,7 +304,7 @@ class ServerComponents { // ws RestartHandler.class, SystemWs.class - ); + ); } /** @@ -321,7 +321,7 @@ class ServerComponents { HttpDownloader.class, UriReader.class, ServerIdGenerator.class - ); + ); } void startLevel4Components(ComponentContainer pico) { @@ -598,6 +598,7 @@ class ServerComponents { IndexProjectIssuesStep.class, SwitchSnapshotStep.class, InvalidatePreviewCacheStep.class, + ProjectDatabaseIndexationStep.class, DataCleanerStep.class)); pico.addSingleton(AnalysisReportQueue.class); pico.addSingleton(AnalysisReportTaskLauncher.class); diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/ComputationStepRegistryMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/ComputationStepRegistryMediumTest.java new file mode 100644 index 00000000000..cdf59656cc9 --- /dev/null +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/ComputationStepRegistryMediumTest.java @@ -0,0 +1,82 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube 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. + * + * SonarQube 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.server.computation; + +import com.google.common.collect.Lists; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Test; +import org.sonar.api.platform.ComponentContainer; +import org.sonar.server.tester.ServerTester; + +import java.util.List; + +import static org.fest.assertions.Assertions.assertThat; +import static org.mockito.Mockito.mock; + +public class ComputationStepRegistryMediumTest { + + @ClassRule + public static ServerTester tester = new ServerTester(); + + private ComputationStepRegistry sut; + + @Before + public void before() { + ComponentContainer pico = new ComponentContainer(); + + pico.addSingleton(mock(SynchronizeProjectPermissionsStep.class)); + pico.addSingleton(mock(IndexProjectIssuesStep.class)); + pico.addSingleton(mock(SwitchSnapshotStep.class)); + pico.addSingleton(mock(DataCleanerStep.class)); + pico.addSingleton(mock(InvalidatePreviewCacheStep.class)); + pico.addSingleton(mock(ProjectDatabaseIndexationStep.class)); + + sut = new ComputationStepRegistry(pico); + } + + @Test + public void steps_returned_in_the_right_order() throws Exception { + List<Class<? extends ComputationStep>> wishStepsClasses = Lists.newArrayList( + SynchronizeProjectPermissionsStep.class, + SwitchSnapshotStep.class, + InvalidatePreviewCacheStep.class, + DataCleanerStep.class, + ProjectDatabaseIndexationStep.class, + IndexProjectIssuesStep.class + ); + List<ComputationStep> steps = sut.steps(); + + assertThat(steps).hasSize(wishStepsClasses.size()); + for (int i = 0; i < steps.size(); i++) { + assertThat(steps.get(i)).isInstanceOf(wishStepsClasses.get(i)); + } + } + + @Test + public void steps_have_a_non_empty_description() { + ComputationStepRegistry sut = tester.get(ComputationStepRegistry.class); + + List<ComputationStep> steps = sut.steps(); + + assertThat(steps).onProperty("description").excludes(null, ""); + } +} diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/ComputationStepRegistryTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/ComputationStepRegistryTest.java deleted file mode 100644 index b47cdcf6521..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/ComputationStepRegistryTest.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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.server.computation; - -import org.junit.Before; -import org.junit.Test; - -import static org.fest.assertions.Assertions.assertThat; -import static org.mockito.Mockito.mock; - -public class ComputationStepRegistryTest { - - private ComputationStepRegistry sut; - private SynchronizeProjectPermissionsStep synchronizeProjectPermissionsStep; - private IndexProjectIssuesStep indexProjectIssuesStep; - private SwitchSnapshotStep switchSnapshotStep; - private DataCleanerStep dataCleanerStep; - private InvalidatePreviewCacheStep invalidatePreviewCacheStep; - - @Before - public void before() { - synchronizeProjectPermissionsStep = mock(SynchronizeProjectPermissionsStep.class); - indexProjectIssuesStep = mock(IndexProjectIssuesStep.class); - switchSnapshotStep = mock(SwitchSnapshotStep.class); - dataCleanerStep = mock(DataCleanerStep.class); - invalidatePreviewCacheStep = mock(InvalidatePreviewCacheStep.class); - - sut = new ComputationStepRegistry(synchronizeProjectPermissionsStep, indexProjectIssuesStep, switchSnapshotStep, dataCleanerStep, invalidatePreviewCacheStep); - } - - @Test - public void steps_returned_in_the_right_order() throws Exception { - assertThat(sut.steps()).containsExactly(synchronizeProjectPermissionsStep, switchSnapshotStep, invalidatePreviewCacheStep, dataCleanerStep, indexProjectIssuesStep); - } -} diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/ProjectDatabaseIndexationStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/ProjectDatabaseIndexationStepTest.java new file mode 100644 index 00000000000..fdc9a57d55b --- /dev/null +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/ProjectDatabaseIndexationStepTest.java @@ -0,0 +1,53 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube 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. + * + * SonarQube 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.server.computation; + +import org.junit.Before; +import org.junit.Test; +import org.sonar.core.component.ComponentDto; +import org.sonar.core.computation.db.AnalysisReportDto; +import org.sonar.core.persistence.DbSession; +import org.sonar.core.resource.ResourceIndexerDao; + +import static org.mockito.Mockito.*; + +public class ProjectDatabaseIndexationStepTest { + + private ProjectDatabaseIndexationStep sut; + private ResourceIndexerDao resourceIndexerDao; + + @Before + public void before() { + this.resourceIndexerDao = mock(ResourceIndexerDao.class); + this.sut = new ProjectDatabaseIndexationStep(resourceIndexerDao); + } + + @Test + public void call_indexProject_of_dao() { + ComponentDto project = mock(ComponentDto.class); + when(project.getId()).thenReturn(123L); + + sut.execute(mock(DbSession.class), mock(AnalysisReportDto.class), project); + + verify(resourceIndexerDao).indexProject(123); + } + +} |