private final BatchIndex batchIndex;
private final GlobalReferentialsAction globalReferentialsAction;
private final ProjectReferentialsAction projectReferentialsAction;
- private final UploadReportAction uploadReportAction;
- public BatchWs(BatchIndex batchIndex, GlobalReferentialsAction globalReferentialsAction, ProjectReferentialsAction projectReferentialsAction,
- UploadReportAction uploadReportAction) {
+ public BatchWs(BatchIndex batchIndex, GlobalReferentialsAction globalReferentialsAction, ProjectReferentialsAction projectReferentialsAction) {
this.batchIndex = batchIndex;
this.globalReferentialsAction = globalReferentialsAction;
this.projectReferentialsAction = projectReferentialsAction;
- this.uploadReportAction = uploadReportAction;
}
@Override
defineFileAction(controller);
globalReferentialsAction.define(controller);
projectReferentialsAction.define(controller);
- uploadReportAction.define(controller);
controller.done();
}
+++ /dev/null
-/*
- * 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.batch;
-
-import org.apache.commons.io.IOUtils;
-import org.sonar.api.server.ws.Request;
-import org.sonar.api.server.ws.RequestHandler;
-import org.sonar.api.server.ws.Response;
-import org.sonar.api.server.ws.WebService;
-import org.sonar.server.computation.AnalysisReportQueue;
-import org.sonar.server.computation.AnalysisReportTaskLauncher;
-
-import java.io.InputStream;
-
-public class UploadReportAction implements RequestHandler {
-
- public static final String UPLOAD_REPORT_ACTION = "upload_report";
-
- static final String PARAM_PROJECT_KEY = "project";
- static final String PARAM_SNAPSHOT = "snapshot";
- static final String PARAM_REPORT_DATA = "report";
-
- private final AnalysisReportQueue analysisReportQueue;
- private final AnalysisReportTaskLauncher analysisTaskLauncher;
-
- public UploadReportAction(AnalysisReportQueue analysisReportQueue, AnalysisReportTaskLauncher analysisTaskLauncher) {
- this.analysisReportQueue = analysisReportQueue;
- this.analysisTaskLauncher = analysisTaskLauncher;
- }
-
- void define(WebService.NewController controller) {
- WebService.NewAction action = controller.createAction(UPLOAD_REPORT_ACTION)
- .setDescription("Update analysis report")
- .setSince("5.0")
- .setPost(true)
- .setInternal(true)
- .setHandler(this);
-
- action
- .createParam(PARAM_PROJECT_KEY)
- .setRequired(true)
- .setDescription("Project key")
- .setExampleValue("org.codehaus.sonar:sonar");
-
- action
- .createParam(PARAM_SNAPSHOT)
- .setRequired(true)
- .setDescription("Snapshot id")
- .setExampleValue("123");
-
- action
- .createParam(PARAM_REPORT_DATA)
- .setRequired(false)
- .setDescription("Report file");
- }
-
- @Override
- public void handle(Request request, Response response) throws Exception {
- String projectKey = request.mandatoryParam(PARAM_PROJECT_KEY);
- String snapshotId = request.mandatoryParam(PARAM_SNAPSHOT);
- InputStream reportData = request.paramAsInputStream(PARAM_REPORT_DATA);
-
- try {
- analysisReportQueue.add(projectKey, Long.valueOf(snapshotId), reportData);
- analysisTaskLauncher.startAnalysisTaskNow();
- } finally {
- IOUtils.closeQuietly(reportData);
- }
- }
-}
--- /dev/null
+/*
+ * 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.ws;
+
+import org.sonar.api.server.ws.Request;
+import org.sonar.api.server.ws.RequestHandler;
+import org.sonar.api.server.ws.Response;
+import org.sonar.api.server.ws.WebService;
+import org.sonar.server.computation.AnalysisReportQueue;
+import org.sonar.server.computation.AnalysisReportTaskLauncher;
+
+import java.io.InputStream;
+
+public class SubmitReportWsAction implements ComputationWsAction, RequestHandler {
+
+ public static final String ACTION = "submit_report";
+ public static final String PARAM_PROJECT_KEY = "projectKey";
+ public static final String PARAM_SNAPSHOT = "snapshot";
+ public static final String PARAM_REPORT_DATA = "report";
+
+ private final AnalysisReportQueue queue;
+ private final AnalysisReportTaskLauncher taskLauncher;
+
+ public SubmitReportWsAction(AnalysisReportQueue queue, AnalysisReportTaskLauncher taskLauncher) {
+ this.queue = queue;
+ this.taskLauncher = taskLauncher;
+ }
+
+ @Override
+ public void define(WebService.NewController controller) {
+ WebService.NewAction action = controller.createAction(ACTION)
+ .setDescription("Submit an analysis report to the queue. Report is integrated asynchronously.")
+ .setPost(true)
+ .setInternal(true)
+ .setHandler(this);
+
+ action
+ .createParam(PARAM_PROJECT_KEY)
+ .setRequired(true)
+ .setDescription("Project key")
+ .setExampleValue("org.codehaus.sonar:sonar");
+
+ action
+ .createParam(PARAM_SNAPSHOT)
+ .setRequired(true)
+ .setDescription("Snapshot ID")
+ .setExampleValue("123");
+
+ action
+ .createParam(PARAM_REPORT_DATA)
+ .setRequired(false)
+ .setDescription("Report file. Format is not an API, it changes among SonarQube versions.");
+ }
+
+ @Override
+ public void handle(Request request, Response response) throws Exception {
+ String projectKey = request.mandatoryParam(PARAM_PROJECT_KEY);
+ long snapshotId = request.mandatoryParamAsLong(PARAM_SNAPSHOT);
+ try (InputStream reportData = request.paramAsInputStream(PARAM_REPORT_DATA)) {
+ queue.add(projectKey, snapshotId, reportData);
+ taskLauncher.startAnalysisTaskNow();
+ }
+ }
+}
import org.sonar.server.computation.ws.HistoryWsAction;
import org.sonar.server.computation.ws.ComputationWebService;
import org.sonar.server.computation.ws.IsQueueEmptyWsAction;
+import org.sonar.server.computation.ws.SubmitReportWsAction;
import org.sonar.server.config.ws.PropertiesWs;
import org.sonar.server.dashboard.db.DashboardDao;
import org.sonar.server.dashboard.db.WidgetDao;
pico.addSingleton(GlobalReferentialsAction.class);
pico.addSingleton(ProjectReferentialsAction.class);
pico.addSingleton(ProjectReferentialsLoader.class);
- pico.addSingleton(UploadReportAction.class);
+ pico.addSingleton(SubmitReportWsAction.class);
pico.addSingleton(BatchWs.class);
// update center
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.sonar.core.properties.PropertiesDao;
-import org.sonar.server.computation.AnalysisReportQueue;
-import org.sonar.server.computation.AnalysisReportTaskLauncher;
import org.sonar.server.db.DbClient;
import org.sonar.server.ws.WsTester;
public void before() throws IOException {
tester = new WsTester(new BatchWs(batchIndex,
new GlobalReferentialsAction(mock(DbClient.class), mock(PropertiesDao.class)),
- new ProjectReferentialsAction(mock(ProjectReferentialsLoader.class)),
- new UploadReportAction(mock(AnalysisReportQueue.class), mock(AnalysisReportTaskLauncher.class))));
+ new ProjectReferentialsAction(mock(ProjectReferentialsLoader.class))));
}
@Test
when(dbClient.openSession(false)).thenReturn(session);
when(dbClient.metricDao()).thenReturn(metricDao);
- tester = new WsTester(new BatchWs(mock(BatchIndex.class), new GlobalReferentialsAction(dbClient, propertiesDao), mock(ProjectReferentialsAction.class), mock(UploadReportAction.class)));
+ tester = new WsTester(new BatchWs(mock(BatchIndex.class), new GlobalReferentialsAction(dbClient, propertiesDao), mock(ProjectReferentialsAction.class)));
}
@Test
@Before
public void setUp() throws Exception {
tester = new WsTester(new BatchWs(mock(BatchIndex.class), mock(GlobalReferentialsAction.class),
- new ProjectReferentialsAction(projectReferentialsLoader), mock(UploadReportAction.class)));
+ new ProjectReferentialsAction(projectReferentialsLoader)));
}
@Test
+++ /dev/null
-/*
- * 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.batch;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.sonar.api.server.ws.WebService;
-import org.sonar.core.persistence.DbSession;
-import org.sonar.core.persistence.MyBatis;
-import org.sonar.server.db.DbClient;
-import org.sonar.server.tester.ServerTester;
-import org.sonar.server.ws.WsTester;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class UploadReportActionMediumTest {
-
- @ClassRule
- public static ServerTester tester = new ServerTester();
-
- DbClient db;
- DbSession session;
-
- WsTester wsTester;
- WebService.Controller controller;
-
- @Before
- public void setUp() throws Exception {
- tester.clearDbAndIndexes();
-
- db = tester.get(DbClient.class);
- session = db.openSession(false);
-
- wsTester = tester.get(WsTester.class);
- controller = wsTester.controller(BatchWs.API_ENDPOINT);
- }
-
- @After
- public void after() {
- MyBatis.closeQuietly(session);
- }
-
- @Test
- public void define() throws Exception {
- WebService.Action action = controller.action(UploadReportAction.UPLOAD_REPORT_ACTION);
-
- assertThat(action).isNotNull();
- assertThat(action.params()).hasSize(3);
- }
-}
+++ /dev/null
-/*
- * 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.batch;
-
-import org.apache.commons.io.IOUtils;
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.api.server.ws.Request;
-import org.sonar.api.server.ws.Response;
-import org.sonar.server.computation.AnalysisReportQueue;
-import org.sonar.server.computation.AnalysisReportTaskLauncher;
-
-import java.io.InputStream;
-
-import static org.mockito.Mockito.*;
-
-public class UploadReportActionTest {
-
- private static final String DEFAULT_PROJECT_KEY = "123456789-987654321";
- private UploadReportAction sut;
-
- private AnalysisReportTaskLauncher analysisTaskLauncher;
- private AnalysisReportQueue queue;
-
- @Before
- public void before() {
- analysisTaskLauncher = mock(AnalysisReportTaskLauncher.class);
- queue = mock(AnalysisReportQueue.class);
-
- sut = new UploadReportAction(queue, analysisTaskLauncher);
- }
-
- @Test
- public void add_element_to_queue_and_launch_analysis_task() throws Exception {
- Response response = mock(Response.class);
- Request request = mock(Request.class);
-
- when(request.mandatoryParam(UploadReportAction.PARAM_PROJECT_KEY)).thenReturn(DEFAULT_PROJECT_KEY);
- when(request.mandatoryParam(UploadReportAction.PARAM_SNAPSHOT)).thenReturn("123");
- InputStream reportData = IOUtils.toInputStream("report-data");
- when(request.paramAsInputStream(UploadReportAction.PARAM_REPORT_DATA)).thenReturn(reportData);
-
- sut.handle(request, response);
-
- verify(queue).add(DEFAULT_PROJECT_KEY, 123L, reportData);
- verify(analysisTaskLauncher).startAnalysisTaskNow();
- }
-
-}
--- /dev/null
+/*
+ * 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.ws;
+
+import org.apache.commons.io.IOUtils;
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.api.server.ws.Request;
+import org.sonar.api.server.ws.Response;
+import org.sonar.api.server.ws.WebService;
+import org.sonar.server.computation.AnalysisReportQueue;
+import org.sonar.server.computation.AnalysisReportTaskLauncher;
+
+import java.io.InputStream;
+
+import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.Mockito.*;
+
+public class SubmitReportWsActionTest {
+
+ private static final String DEFAULT_PROJECT_KEY = "123456789-987654321";
+ private SubmitReportWsAction sut;
+
+ private AnalysisReportTaskLauncher analysisTaskLauncher;
+ private AnalysisReportQueue queue;
+
+ @Before
+ public void before() {
+ analysisTaskLauncher = mock(AnalysisReportTaskLauncher.class);
+ queue = mock(AnalysisReportQueue.class);
+
+ sut = new SubmitReportWsAction(queue, analysisTaskLauncher);
+ }
+
+ @Test
+ public void define_metadata() throws Exception {
+ WebService.Context context = new WebService.Context();
+ WebService.NewController controller = context.createController("api/computation");
+ sut.define(controller);
+ controller.done();
+
+ WebService.Action action = context.controller("api/computation").action("submit_report");
+ assertThat(action).isNotNull();
+ assertThat(action.params()).hasSize(3);
+ }
+
+ @Test
+ public void add_element_to_queue_and_launch_analysis_task() throws Exception {
+ Response response = mock(Response.class);
+ Request request = mock(Request.class);
+
+ when(request.mandatoryParam(SubmitReportWsAction.PARAM_PROJECT_KEY)).thenReturn(DEFAULT_PROJECT_KEY);
+ when(request.mandatoryParamAsLong(SubmitReportWsAction.PARAM_SNAPSHOT)).thenReturn(123L);
+ InputStream reportData = IOUtils.toInputStream("report-data");
+ when(request.paramAsInputStream(SubmitReportWsAction.PARAM_REPORT_DATA)).thenReturn(reportData);
+
+ sut.handle(request, response);
+
+ verify(queue).add(DEFAULT_PROJECT_KEY, 123L, reportData);
+ verify(analysisTaskLauncher).startAnalysisTaskNow();
+ }
+
+}
URL url;
try {
int snapshotId = resourceCache.get(project.getEffectiveKey()).snapshotId();
- url = new URL(serverClient.getURL() + "/batch/upload_report?project=" + project.getEffectiveKey() + "&snapshot=" + snapshotId);
+ url = new URL(serverClient.getURL() + "/api/analysis_reports/submit_report?projectKey=" + project.getEffectiveKey() + "&snapshot=" + snapshotId);
} catch (MalformedURLException e) {
throw new IllegalArgumentException("Invalid URL", e);
}