aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2014-10-30 20:58:43 +0100
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2014-10-30 21:28:59 +0100
commitd8d5c8fd2d5d25822baa93d77adf02a34122a7c1 (patch)
tree0041ed055a9ac6bf956040e88c58ab599de4da48 /server
parent34a501e8a0c1764c111c12ab759d594b0c5fd729 (diff)
downloadsonarqube-d8d5c8fd2d5d25822baa93d77adf02a34122a7c1.tar.gz
sonarqube-d8d5c8fd2d5d25822baa93d77adf02a34122a7c1.zip
SONAR-5806 Invalidate database preview cache after snapshot switch on the server side
Diffstat (limited to 'server')
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/ComputationStepRegistry.java5
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/InvalidatePreviewCacheStep.java52
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java23
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/ComputationStepRegistryTest.java6
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/InvalidatePreviewCacheStepTest.java51
-rw-r--r--server/sonar-web/src/main/webapp/WEB-INF/app/controllers/batch_bootstrap_controller.rb16
6 files changed, 124 insertions, 29 deletions
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 e4a2d573bc4..0e392ca2aad 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
@@ -33,8 +33,9 @@ public class ComputationStepRegistry implements ServerComponent {
SynchronizeProjectPermissionsStep synchronizeProjectPermissionsStep,
IndexProjectIssuesStep indexProjectIssuesStep,
SwitchSnapshotStep switchSnapshotStep,
- DataCleanerStep dataCleanerStep) {
- steps = ImmutableList.of(synchronizeProjectPermissionsStep, switchSnapshotStep, dataCleanerStep, indexProjectIssuesStep);
+ DataCleanerStep dataCleanerStep,
+ InvalidatePreviewCacheStep invalidatePreviewCacheStep) {
+ steps = ImmutableList.of(synchronizeProjectPermissionsStep, switchSnapshotStep, invalidatePreviewCacheStep, dataCleanerStep, indexProjectIssuesStep);
}
public List<ComputationStep> steps() {
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
new file mode 100644
index 00000000000..dcdf9c822d1
--- /dev/null
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/InvalidatePreviewCacheStep.java
@@ -0,0 +1,52 @@
+/*
+ * 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.preview.PreviewCache;
+import org.sonar.core.properties.PropertiesDao;
+import org.sonar.core.properties.PropertyDto;
+
+
+public class InvalidatePreviewCacheStep implements ComputationStep {
+ private final PropertiesDao propertiesDao;
+
+ public InvalidatePreviewCacheStep(PropertiesDao propertiesDao) {
+ this.propertiesDao = propertiesDao;
+ }
+
+ @Override
+ public void execute(DbSession session, AnalysisReportDto analysisReportDto, ComponentDto project) {
+ propertiesDao.setProperty(updatedProjectPreviewCacheProperty(project));
+ }
+
+ private PropertyDto updatedProjectPreviewCacheProperty(ComponentDto project) {
+ return new PropertyDto().setKey(PreviewCache.SONAR_PREVIEW_CACHE_LAST_UPDATE_KEY).setResourceId(project.getId())
+ .setValue(String.valueOf(System.currentTimeMillis()));
+ }
+
+ @Override
+ public String description() {
+ return "Invalidate preview cache";
+ }
+}
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 52de0619f01..cefc8430479 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
@@ -118,7 +118,10 @@ import org.sonar.server.issue.db.IssueDao;
import org.sonar.server.issue.filter.IssueFilterService;
import org.sonar.server.issue.filter.IssueFilterWriter;
import org.sonar.server.issue.filter.IssueFilterWs;
-import org.sonar.server.issue.index.*;
+import org.sonar.server.issue.index.IssueAuthorizationIndex;
+import org.sonar.server.issue.index.IssueAuthorizationNormalizer;
+import org.sonar.server.issue.index.IssueIndex;
+import org.sonar.server.issue.index.IssueNormalizer;
import org.sonar.server.issue.ws.IssueActionsWriter;
import org.sonar.server.issue.ws.IssueShowAction;
import org.sonar.server.issue.ws.IssuesWs;
@@ -268,7 +271,7 @@ class ServerComponents {
ActivityNormalizer.class,
ActivityIndex.class,
ActivityDao.class
- ));
+ ));
components.addAll(CorePropertyDefinitions.all());
components.addAll(DatabaseMigrations.CLASSES);
components.addAll(DaoUtils.getDaoClasses());
@@ -301,7 +304,7 @@ class ServerComponents {
// ws
RestartHandler.class,
SystemWs.class
- );
+ );
}
/**
@@ -318,7 +321,7 @@ class ServerComponents {
HttpDownloader.class,
UriReader.class,
ServerIdGenerator.class
- );
+ );
}
void startLevel4Components(ComponentContainer pico) {
@@ -590,11 +593,13 @@ class ServerComponents {
// Compute engine
pico.addSingleton(ComputationService.class);
pico.addSingleton(ComputationStepRegistry.class);
- pico.addSingleton(SynchronizeProjectPermissionsStep.class);
- pico.addSingleton(IndexProjectIssuesStep.class);
- pico.addSingleton(SwitchSnapshotStep.class);
- pico.addSingleton(DataCleanerStep.class);
- pico.add(AnalysisReportQueue.class);
+ pico.addSingletons(Lists.newArrayList(
+ SynchronizeProjectPermissionsStep.class,
+ IndexProjectIssuesStep.class,
+ SwitchSnapshotStep.class,
+ InvalidatePreviewCacheStep.class,
+ DataCleanerStep.class));
+ pico.addSingleton(AnalysisReportQueue.class);
pico.addSingleton(AnalysisReportTaskLauncher.class);
pico.addSingleton(AnalysisReportWebService.class);
pico.addSingleton(ActiveAnalysisReportsAction.class);
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
index 8bf1607c54f..b47cdcf6521 100644
--- 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
@@ -33,6 +33,7 @@ public class ComputationStepRegistryTest {
private IndexProjectIssuesStep indexProjectIssuesStep;
private SwitchSnapshotStep switchSnapshotStep;
private DataCleanerStep dataCleanerStep;
+ private InvalidatePreviewCacheStep invalidatePreviewCacheStep;
@Before
public void before() {
@@ -40,12 +41,13 @@ public class ComputationStepRegistryTest {
indexProjectIssuesStep = mock(IndexProjectIssuesStep.class);
switchSnapshotStep = mock(SwitchSnapshotStep.class);
dataCleanerStep = mock(DataCleanerStep.class);
+ invalidatePreviewCacheStep = mock(InvalidatePreviewCacheStep.class);
- sut = new ComputationStepRegistry(synchronizeProjectPermissionsStep, indexProjectIssuesStep, switchSnapshotStep, dataCleanerStep);
+ 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, dataCleanerStep, indexProjectIssuesStep);
+ assertThat(sut.steps()).containsExactly(synchronizeProjectPermissionsStep, switchSnapshotStep, invalidatePreviewCacheStep, dataCleanerStep, indexProjectIssuesStep);
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/InvalidatePreviewCacheStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/InvalidatePreviewCacheStepTest.java
new file mode 100644
index 00000000000..996d56daf77
--- /dev/null
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/InvalidatePreviewCacheStepTest.java
@@ -0,0 +1,51 @@
+/*
+ * 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.properties.PropertiesDao;
+import org.sonar.core.properties.PropertyDto;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+public class InvalidatePreviewCacheStepTest {
+ private InvalidatePreviewCacheStep sut;
+ private PropertiesDao propertiesDao;
+
+ @Before
+ public void before() {
+ this.propertiesDao = mock(PropertiesDao.class);
+ this.sut = new InvalidatePreviewCacheStep(propertiesDao);
+ }
+
+ @Test
+ public void update_property_calling_propertiesDao() {
+ sut.execute(mock(DbSession.class), mock(AnalysisReportDto.class), mock(ComponentDto.class));
+
+ verify(propertiesDao).setProperty(any(PropertyDto.class));
+ }
+} \ No newline at end of file
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/batch_bootstrap_controller.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/batch_bootstrap_controller.rb
index 547d0bf7dcf..111f423168c 100644
--- a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/batch_bootstrap_controller.rb
+++ b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/batch_bootstrap_controller.rb
@@ -35,22 +35,6 @@ class BatchBootstrapController < Api::ApiController
send_data String.from_java_bytes(db_content)
end
- # PUT /batch_bootstrap/evict?project=<key or id>
- def evict
- has_scan_role = has_role?('scan')
- return render_unauthorized("You're not authorized to execute any SonarQube analysis. Please contact your SonarQube administrator.") if !has_scan_role
-
- project = load_project()
- return render_unauthorized("You're not authorized to access to project '" + project.name + "', please contact your SonarQube administrator") if project && !has_scan_role && !has_role?(:user, project)
-
- if project
- Property.set(Java::OrgSonarCorePreview::PreviewCache::SONAR_PREVIEW_CACHE_LAST_UPDATE_KEY, java.lang.System.currentTimeMillis, project.root_project.id)
- render_success('dryRun DB evicted')
- else
- render_bad_request('missing projectId')
- end
- end
-
private