public void define(WebService.NewController controller) {
WebService.NewAction action = controller.createAction("activity")
.setInternal(true)
+ .setDescription(format("Search for past task executions. Requires the system administration permission, " +
+ "or project administration permission if %s is set.", PARAM_COMPONENT_UUID))
.setResponseExample(getClass().getResource("activity-example.json"))
- .setHandler(this);
+ .setHandler(this)
+ .setSince("5.2");
action.createParam(PARAM_COMPONENT_UUID)
.setDescription("Optional id of the component (project) to filter on")
.setExampleValue(Uuids.UUID_EXAMPLE_03);
action.createParam(PARAM_COMPONENT_QUERY)
- .setDescription(format("Optional search by component name or key. Must not be set together with %s", PARAM_COMPONENT_UUID))
+ .setDescription(format("Optional search by component name or key. Must not be set together with %s.", PARAM_COMPONENT_UUID))
.setExampleValue("Apache");
action.createParam(PARAM_STATUS)
.setDescription("Optional filter on task status")
@Override
public void define(WebService.NewController controller) {
controller.createAction("cancel_all")
- .setDescription("Cancels all pending task. Requires system administration permission.")
+ .setDescription("Cancels all pending tasks. Requires system administration permission. In-progress tasks are not canceled.")
.setInternal(true)
.setPost(true)
+ .setSince("5.2")
.setHandler(this);
}
@Override
public void define(WebService.NewController controller) {
WebService.NewAction action = controller.createAction("cancel")
- .setDescription("Cancels a pending task. Requires system administration permission.")
+ .setDescription("Cancels a pending task. Requires system administration permission. In-progress tasks can not be canceled.")
.setInternal(true)
.setPost(true)
+ .setSince("5.2")
.setHandler(this);
action
@Override
public void define(WebService.NewController controller) {
WebService.NewAction action = controller.createAction("component")
- .setDescription("Get the pending and last executed tasks of a given component (usually a project)")
+ .setDescription("Get the pending tasks, in-progress tasks and the last executed task of a given component " +
+ "(usually a project). Requires the administration permission on the component.")
.setInternal(true)
+ .setSince("5.2")
.setResponseExample(getClass().getResource("component-example.json"))
.setHandler(this);
public void define(Context context) {
NewController controller = context
.createController(API_ENDPOINT)
- .setDescription("Analysis reports processed");
+ .setDescription("For internal testing - do not use");
action.define(controller);
controller.done();
}
@Override
public void define(WebService.NewController controller) {
WebService.NewAction action = controller.createAction(ACTION)
- .setDescription("Logs of a task. Returns HTTP code 404 if task does not " +
+ .setDescription("Logs of a task. Format of response is plain text. HTTP code 404 is returned if the task does not " +
"exist or if logs are not available. Requires system administration permission.")
.setInternal(true)
+ .setSince("5.2")
.setHandler(this);
action
@Override
public void define(WebService.NewController controller) {
WebService.NewAction action = controller.createAction("queue")
- .setDescription("Gets the tasks of the Compute Engine queue")
+ .setDescription("Gets the pending and in-progress tasks. Requires system administration permission.")
.setInternal(true)
+ .setSince("5.2")
.setResponseExample(getClass().getResource("queue-example.json"))
.setHandler(this);
if (userSession.hasGlobalPermission(GlobalPermissions.SYSTEM_ADMIN) || userSession.hasComponentUuidPermission(UserRole.ADMIN, componentUuid)) {
dtos = dbClient.ceQueueDao().selectByComponentUuid(dbSession, componentUuid);
} else {
- throw new ForbiddenException("Requires administration permission");
+ throw new ForbiddenException("Requires system administration permission");
}
}
@Override
public void define(WebService.NewController controller) {
WebService.NewAction action = controller.createAction("submit")
- .setDescription("Submit an analysis report to the queue of Compute Engine. Report is processed asynchronously.")
+ .setDescription("Submits a scanner report to the queue. Report is processed asynchronously. Requires analysis permission. " +
+ "If the project does not exist, then the provisioning permission is also required.")
.setPost(true)
.setInternal(true)
+ .setSince("5.2")
.setHandler(this)
.setResponseExample(getClass().getResource("submit-example.json"));
WebService.NewAction action = controller.createAction(ACTION)
.setDescription("Task information")
.setInternal(true)
+ .setResponseExample(getClass().getResource("task-example.json"))
+ .setSince("5.2")
.setHandler(this);
action
--- /dev/null
+{
+ "task": {
+ "id": "AVAn5RKqYwETbXvgas-I",
+ "type": "REPORT",
+ "componentId": "AVAn5RJmYwETbXvgas-H",
+ "componentKey": "project_1",
+ "componentName": "Project One",
+ "status": "SUCCESS",
+ "submittedAt": "2015-10-02T11:32:15+0200",
+ "startedAt": "2015-10-02T11:32:16+0200",
+ "executedAt": "2015-10-02T11:32:22+0200",
+ "executionTimeMs": 5286,
+ "logs": true
+ }
+}
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.TestResponse;
import org.sonar.server.ws.WsActionTester;
+import org.sonar.test.JsonAssert;
import org.sonarqube.ws.WsCe;
import static java.util.Arrays.asList;
.execute();
}
+ @Test
+ public void support_json_response() {
+ userSession.setGlobalPermissions(UserRole.ADMIN);
+ TestResponse wsResponse = tester.newRequest()
+ .setMediaType(MimeTypes.JSON)
+ .execute();
+
+ JsonAssert.assertJson(wsResponse.getInput()).isSimilarTo("{\"tasks\":[]}");
+ }
+
private CeActivityDto insert(String taskUuid, String componentUuid, CeActivityDto.Status status) {
CeQueueDto queueDto = new CeQueueDto();
queueDto.setTaskType(CeTaskTypes.REPORT);
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.TestResponse;
import org.sonar.server.ws.WsActionTester;
+import org.sonar.test.JsonAssert;
import org.sonarqube.ws.WsCe;
import static org.assertj.core.api.Assertions.assertThat;
queueDto.setStatus(CeQueueDto.Status.PENDING);
queueDto.setSubmitterLogin("john");
dbTester.getDbClient().ceQueueDao().insert(dbTester.getSession(), queueDto);
- dbTester.getSession().commit();
+ dbTester.commit();
TestResponse wsResponse = tester.newRequest()
.setMediaType(MimeTypes.PROTOBUF)
.setParam("id", "TASK_1")
.execute();
- // verify the protobuf response
WsCe.TaskResponse taskResponse = Protobuf.read(wsResponse.getInputStream(), WsCe.TaskResponse.PARSER);
assertThat(taskResponse.getTask().getId()).isEqualTo("TASK_1");
assertThat(taskResponse.getTask().getStatus()).isEqualTo(WsCe.TaskStatus.PENDING);
activityDto.setStatus(CeActivityDto.Status.FAILED);
activityDto.setExecutionTimeMs(500L);
dbTester.getDbClient().ceActivityDao().insert(dbTester.getSession(), activityDto);
- dbTester.getSession().commit();
+ dbTester.commit();
TestResponse wsResponse = tester.newRequest()
.setMediaType(MimeTypes.PROTOBUF)
.setParam("id", "TASK_1")
.execute();
- // verify the protobuf response
WsCe.TaskResponse taskResponse = Protobuf.read(wsResponse.getInputStream(), WsCe.TaskResponse.PARSER);
assertThat(taskResponse.getTask().getId()).isEqualTo("TASK_1");
assertThat(taskResponse.getTask().getStatus()).isEqualTo(WsCe.TaskStatus.FAILED);
.setParam("id", "DOES_NOT_EXIST")
.execute();
}
+
+ @Test
+ public void support_json_response() {
+ CeQueueDto queueDto = new CeQueueDto();
+ queueDto.setTaskType("fake");
+ queueDto.setUuid("TASK_1");
+ queueDto.setStatus(CeQueueDto.Status.PENDING);
+ dbTester.getDbClient().ceQueueDao().insert(dbTester.getSession(), queueDto);
+ dbTester.commit();
+
+ userSession.setGlobalPermissions(UserRole.ADMIN);
+ TestResponse wsResponse = tester.newRequest()
+ .setMediaType(MimeTypes.JSON)
+ .setParam("id", "TASK_1")
+ .execute();
+
+ JsonAssert.assertJson(wsResponse.getInput()).isSimilarTo("{\"task\":{}}");
+ }
}