import org.sonar.server.ws.KeyExamples;
import org.sonarqube.ws.Ce.ActivityStatusWsResponse;
-import static org.sonar.server.ce.ws.CeWsParameters.DEPRECATED_PARAM_COMPONENT_KEY;
+import static org.sonar.server.ce.ws.CeWsParameters.PARAM_COMPONENT;
import static org.sonar.server.ce.ws.CeWsParameters.PARAM_COMPONENT_ID;
import static org.sonar.server.component.ComponentFinder.ParamNames.COMPONENT_ID_AND_KEY;
import static org.sonar.server.ws.WsUtils.writeProtobuf;
.setHandler(this);
action.createParam(PARAM_COMPONENT_ID)
+ .setDeprecatedSince("8.8")
.setDescription("Id of the component (project) to filter on")
.setExampleValue(Uuids.UUID_EXAMPLE_03);
- action.createParam(DEPRECATED_PARAM_COMPONENT_KEY)
- .setDeprecatedSince("6.6")
+ action.createParam(PARAM_COMPONENT)
.setDescription("Key of the component (project) to filter on")
.setExampleValue(KeyExamples.KEY_PROJECT_EXAMPLE_001);
action.setChangelog(new Change("6.6", "New field 'inProgress' in response"));
action.setChangelog(new Change("7.8", "New field 'pendingTime' in response, only included when there are pending tasks"));
+ action.setChangelog(new Change("8.8", "Parameter 'componentId' is now deprecated."));
+ action.setChangelog(new Change("8.8", "Parameter 'componentKey' is now removed. Please use parameter 'component' instead."));
}
@Override
try (DbSession dbSession = dbClient.openSession(false)) {
Optional<ComponentDto> component = searchComponent(dbSession, request);
String componentUuid = component.map(ComponentDto::uuid).orElse(null);
- checkPermissions(component);
+ checkPermissions(component.orElse(null));
int pendingCount = dbClient.ceQueueDao().countByStatusAndMainComponentUuid(dbSession, CeQueueDto.Status.PENDING, componentUuid);
int inProgressCount = dbClient.ceQueueDao().countByStatusAndMainComponentUuid(dbSession, CeQueueDto.Status.IN_PROGRESS, componentUuid);
int failingCount = dbClient.ceActivityDao().countLastByStatusAndMainComponentUuid(dbSession, CeActivityDto.Status.FAILED, componentUuid);
return Optional.ofNullable(component);
}
- private void checkPermissions(Optional<ComponentDto> component) {
- if (component.isPresent()) {
- userSession.checkComponentPermission(UserRole.ADMIN, component.get());
+ private void checkPermissions(@Nullable ComponentDto component) {
+ if (component != null) {
+ userSession.checkComponentPermission(UserRole.ADMIN, component);
} else {
userSession.checkIsSystemAdministrator();
}
}
private static Request toWsRequest(org.sonar.api.server.ws.Request request) {
- return new Request(request.param(PARAM_COMPONENT_ID), request.param(DEPRECATED_PARAM_COMPONENT_KEY));
+ return new Request(request.param(PARAM_COMPONENT_ID), request.param(PARAM_COMPONENT));
}
private static class Request {
- private String componentId;
- private String componentKey;
+ private final String componentId;
+ private final String componentKey;
Request(@Nullable String componentId, @Nullable String componentKey) {
this.componentId = componentId;
import org.sonar.db.ce.CeActivityDto;
import org.sonar.db.ce.CeQueueDto;
import org.sonar.db.component.ComponentDto;
-import org.sonar.db.component.ComponentTesting;
import org.sonar.server.component.TestComponentFinder;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
import static org.mockito.Mockito.when;
import static org.sonar.db.ce.CeQueueTesting.newCeQueueDto;
import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
-import static org.sonar.server.ce.ws.CeWsParameters.DEPRECATED_PARAM_COMPONENT_KEY;
-import static org.sonar.server.ce.ws.CeWsParameters.PARAM_COMPONENT_ID;
+import static org.sonar.server.ce.ws.CeWsParameters.PARAM_COMPONENT;
import static org.sonar.test.JsonAssert.assertJson;
public class ActivityStatusActionTest {
@Rule
public DbTester db = DbTester.create(System2.INSTANCE);
- private System2 system2 = mock(System2.class);
-
- private DbClient dbClient = db.getDbClient();
- private DbSession dbSession = db.getSession();
- private WsActionTester ws = new WsActionTester(new ActivityStatusAction(userSession, dbClient, TestComponentFinder.from(db), system2));
+ private final System2 system2 = mock(System2.class);
+ private final DbClient dbClient = db.getDbClient();
+ private final DbSession dbSession = db.getSession();
+ private final WsActionTester ws = new WsActionTester(new ActivityStatusAction(userSession, dbClient, TestComponentFinder.from(db), system2));
@Test
public void test_definition() {
assertThat(def.key()).isEqualTo("activity_status");
assertThat(def.isInternal()).isFalse();
assertThat(def.isPost()).isFalse();
- assertThat(def.params()).extracting(WebService.Param::key).containsOnly("componentId", "componentKey");
+ assertThat(def.params()).extracting(WebService.Param::key).containsOnly("componentId", "component");
}
@Test
@Test
public void status_for_a_project_as_project_admin() {
- String projectUuid = "project-uuid";
- String anotherProjectUuid = "another-project-uuid";
- ComponentDto project = newPrivateProjectDto(projectUuid);
- ComponentDto anotherProject = newPrivateProjectDto(anotherProjectUuid);
+ String projectKey = "project-key";
+ String anotherProjectKey = "another-project-key";
+ ComponentDto project = newPrivateProjectDto().setDbKey(projectKey);
+ ComponentDto anotherProject = newPrivateProjectDto().setDbKey(anotherProjectKey);
db.components().insertComponent(project);
- db.components().insertComponent(newPrivateProjectDto(anotherProjectUuid));
+ db.components().insertComponent(newPrivateProjectDto().setDbKey(anotherProjectKey));
userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
// pending tasks returned
insertInQueue(CeQueueDto.Status.PENDING, project);
insertActivity(CeActivityDto.Status.FAILED, project);
insertActivity(CeActivityDto.Status.FAILED, anotherProject);
- Ce.ActivityStatusWsResponse result = call(projectUuid);
+ Ce.ActivityStatusWsResponse result = callByComponentKey(projectKey);
assertThat(result.getPending()).isEqualTo(2);
assertThat(result.getFailing()).isEqualTo(1);
@Test
public void add_pending_time() {
- String projectUuid = "project-uuid";
- ComponentDto project = newPrivateProjectDto(projectUuid);
+ String projectKey = "project-key";
+ ComponentDto project = newPrivateProjectDto().setDbKey(projectKey);
db.components().insertComponent(project);
userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
when(system2.now()).thenReturn(2000L);
insertInQueue(CeQueueDto.Status.PENDING, project, 1000L);
- Ce.ActivityStatusWsResponse result = call(projectUuid);
+ Ce.ActivityStatusWsResponse result = callByComponentKey(projectKey);
assertThat(result).extracting(Ce.ActivityStatusWsResponse::getPending, Ce.ActivityStatusWsResponse::getFailing,
Ce.ActivityStatusWsResponse::getInProgress, Ce.ActivityStatusWsResponse::getPendingTime)
assertThat(result.getFailing()).isZero();
}
- @Test
- public void fail_if_component_uuid_and_key_are_provided() {
- ComponentDto project = ComponentTesting.newPrivateProjectDto();
- db.components().insertComponent(project);
-
- String uuid = project.uuid();
- String dbKey = project.getDbKey();
- assertThatThrownBy(() -> callByComponentUuidOrComponentKey(uuid, dbKey))
- .isInstanceOf(IllegalArgumentException.class);
- }
-
- @Test
- public void fail_if_component_uuid_is_unknown() {
- assertThatThrownBy(() -> call("unknown-uuid"))
- .isInstanceOf(NotFoundException.class);
- }
-
@Test
public void fail_if_component_key_is_unknown() {
assertThatThrownBy(() -> callByComponentKey("unknown-key"))
}
private Ce.ActivityStatusWsResponse call() {
- return callByComponentUuidOrComponentKey(null, null);
- }
-
- private Ce.ActivityStatusWsResponse call(String componentUuid) {
- return callByComponentUuidOrComponentKey(componentUuid, null);
- }
-
- private Ce.ActivityStatusWsResponse callByComponentKey(String componentKey) {
- return callByComponentUuidOrComponentKey(null, componentKey);
+ return callByComponentKey(null);
}
- private Ce.ActivityStatusWsResponse callByComponentUuidOrComponentKey(@Nullable String componentUuid, @Nullable String componentKey) {
+ private Ce.ActivityStatusWsResponse callByComponentKey(@Nullable String componentKey) {
TestRequest request = ws.newRequest();
- if (componentUuid != null) {
- request.setParam(PARAM_COMPONENT_ID, componentUuid);
- }
if (componentKey != null) {
- request.setParam(DEPRECATED_PARAM_COMPONENT_KEY, componentKey);
+ request.setParam(PARAM_COMPONENT, componentKey);
}
return request.executeProtobuf(Ce.ActivityStatusWsResponse.class);
}