aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-ce-common/src
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2023-06-07 12:30:33 +0200
committersonartech <sonartech@sonarsource.com>2023-06-20 13:10:18 +0000
commit667618747b9e64f552eda5fc24df8398ca7afbef (patch)
tree642f7d84c3888e4081daff283acbbfe07116aff7 /server/sonar-ce-common/src
parent93734208da4519e1872e80c59f7edd1612dac5da (diff)
downloadsonarqube-667618747b9e64f552eda5fc24df8398ca7afbef.tar.gz
sonarqube-667618747b9e64f552eda5fc24df8398ca7afbef.zip
SONAR-19556 Refactor use of DB columns referencing projects or branches for Entities
Diffstat (limited to 'server/sonar-ce-common/src')
-rw-r--r--server/sonar-ce-common/src/it/java/org/sonar/ce/queue/CeQueueImplIT.java101
-rw-r--r--server/sonar-ce-common/src/main/java/org/sonar/ce/queue/CeQueue.java4
-rw-r--r--server/sonar-ce-common/src/main/java/org/sonar/ce/queue/CeQueueImpl.java75
-rw-r--r--server/sonar-ce-common/src/main/java/org/sonar/ce/queue/CeTaskSubmit.java31
4 files changed, 100 insertions, 111 deletions
diff --git a/server/sonar-ce-common/src/it/java/org/sonar/ce/queue/CeQueueImplIT.java b/server/sonar-ce-common/src/it/java/org/sonar/ce/queue/CeQueueImplIT.java
index 12195d1aac8..32f62b39957 100644
--- a/server/sonar-ce-common/src/it/java/org/sonar/ce/queue/CeQueueImplIT.java
+++ b/server/sonar-ce-common/src/it/java/org/sonar/ce/queue/CeQueueImplIT.java
@@ -39,8 +39,11 @@ import org.sonar.db.DbTester;
import org.sonar.db.ce.CeActivityDto;
import org.sonar.db.ce.CeQueueDto;
import org.sonar.db.ce.CeTaskTypes;
+import org.sonar.db.component.BranchDto;
import org.sonar.db.component.ComponentDto;
-import org.sonar.db.component.ComponentTesting;
+import org.sonar.db.component.ProjectData;
+import org.sonar.db.entity.EntityDto;
+import org.sonar.db.project.ProjectDto;
import org.sonar.db.user.UserDto;
import org.sonar.db.user.UserTesting;
import org.sonar.server.platform.NodeInformation;
@@ -55,7 +58,7 @@ import static org.assertj.core.api.Assertions.catchThrowable;
import static org.assertj.core.api.Assertions.tuple;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import static org.sonar.ce.queue.CeQueue.SubmitOption.UNIQUE_QUEUE_PER_MAIN_COMPONENT;
+import static org.sonar.ce.queue.CeQueue.SubmitOption.UNIQUE_QUEUE_PER_ENTITY;
import static org.sonar.ce.queue.CeQueue.SubmitOption.UNIQUE_QUEUE_PER_TASK_TYPE;
public class CeQueueImplIT {
@@ -86,18 +89,18 @@ public class CeQueueImplIT {
CeTask task = underTest.submit(taskSubmit);
- verifyCeTask(taskSubmit, task, null, userDto);
+ verifyCeTask(taskSubmit, task, null, null, userDto);
verifyCeQueueDtoForTaskSubmit(taskSubmit);
}
@Test
public void submit_populates_component_name_and_key_of_CeTask_if_component_exists() {
- ComponentDto componentDto = insertComponent(ComponentTesting.newPrivateProjectDto("PROJECT_1"));
- CeTaskSubmit taskSubmit = createTaskSubmit(CeTaskTypes.REPORT, Component.fromDto(componentDto.uuid(), componentDto.uuid()), null);
+ ProjectData projectData = db.components().insertPrivateProject("PROJECT_1");
+ CeTaskSubmit taskSubmit = createTaskSubmit(CeTaskTypes.REPORT, Component.fromDto(projectData.getMainBranchDto()), null);
CeTask task = underTest.submit(taskSubmit);
- verifyCeTask(taskSubmit, task, componentDto, null);
+ verifyCeTask(taskSubmit, task, projectData.getProjectDto(), projectData.getMainBranchDto(), null);
}
@Test
@@ -106,7 +109,7 @@ public class CeQueueImplIT {
CeTask task = underTest.submit(taskSubmit);
- verifyCeTask(taskSubmit, task, null, null);
+ verifyCeTask(taskSubmit, task, null, null, null);
}
@Test
@@ -116,7 +119,7 @@ public class CeQueueImplIT {
CeTask task = underTest.submit(taskSubmit);
- verifyCeTask(taskSubmit, task, null, userDto);
+ verifyCeTask(taskSubmit, task, null, null, userDto);
}
@Test
@@ -124,7 +127,7 @@ public class CeQueueImplIT {
CeTaskSubmit taskSubmit = createTaskSubmit("no_component");
CeQueueDto dto = insertPendingInQueue(null);
- Optional<CeTask> task = underTest.submit(taskSubmit, UNIQUE_QUEUE_PER_MAIN_COMPONENT);
+ Optional<CeTask> task = underTest.submit(taskSubmit, UNIQUE_QUEUE_PER_ENTITY);
assertThat(task).isNotEmpty();
assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession()))
@@ -139,7 +142,7 @@ public class CeQueueImplIT {
CeTaskSubmit taskSubmit = createTaskSubmit("with_component", newComponent(mainComponentUuid), null);
CeQueueDto dto = insertPendingInQueue(newComponent(otherMainComponentUuid));
- Optional<CeTask> task = underTest.submit(taskSubmit, UNIQUE_QUEUE_PER_MAIN_COMPONENT);
+ Optional<CeTask> task = underTest.submit(taskSubmit, UNIQUE_QUEUE_PER_ENTITY);
assertThat(task).isNotEmpty();
assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession()))
@@ -153,7 +156,7 @@ public class CeQueueImplIT {
CeTaskSubmit taskSubmit = createTaskSubmit("with_component", newComponent(mainComponentUuid), null);
CeQueueDto dto = insertPendingInQueue(newComponent(mainComponentUuid));
- Optional<CeTask> task = underTest.submit(taskSubmit, UNIQUE_QUEUE_PER_MAIN_COMPONENT);
+ Optional<CeTask> task = underTest.submit(taskSubmit, UNIQUE_QUEUE_PER_ENTITY);
assertThat(task).isEmpty();
assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession()))
@@ -170,7 +173,7 @@ public class CeQueueImplIT {
.map(CeQueueDto::getUuid)
.toArray(String[]::new);
- Optional<CeTask> task = underTest.submit(taskSubmit, UNIQUE_QUEUE_PER_MAIN_COMPONENT);
+ Optional<CeTask> task = underTest.submit(taskSubmit, UNIQUE_QUEUE_PER_ENTITY);
assertThat(task).isEmpty();
assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession()))
@@ -235,38 +238,38 @@ public class CeQueueImplIT {
List<CeTask> tasks = underTest.massSubmit(asList(taskSubmit1, taskSubmit2));
assertThat(tasks).hasSize(2);
- verifyCeTask(taskSubmit1, tasks.get(0), null, userDto1);
- verifyCeTask(taskSubmit2, tasks.get(1), null, null);
+ verifyCeTask(taskSubmit1, tasks.get(0), null, null, userDto1);
+ verifyCeTask(taskSubmit2, tasks.get(1), null, null, null);
verifyCeQueueDtoForTaskSubmit(taskSubmit1);
verifyCeQueueDtoForTaskSubmit(taskSubmit2);
}
@Test
public void massSubmit_populates_component_name_and_key_of_CeTask_if_project_exists() {
- ComponentDto componentDto1 = insertComponent(ComponentTesting.newPrivateProjectDto("PROJECT_1"));
- CeTaskSubmit taskSubmit1 = createTaskSubmit(CeTaskTypes.REPORT, Component.fromDto(componentDto1.uuid(), componentDto1.uuid()), null);
+ ProjectData projectData = db.components().insertPrivateProject("PROJECT_1");
+ CeTaskSubmit taskSubmit1 = createTaskSubmit(CeTaskTypes.REPORT, Component.fromDto(projectData.getMainBranchDto()), null);
CeTaskSubmit taskSubmit2 = createTaskSubmit("something", newComponent(randomAlphabetic(12)), null);
List<CeTask> tasks = underTest.massSubmit(asList(taskSubmit1, taskSubmit2));
assertThat(tasks).hasSize(2);
- verifyCeTask(taskSubmit1, tasks.get(0), componentDto1, null);
- verifyCeTask(taskSubmit2, tasks.get(1), null, null);
+ verifyCeTask(taskSubmit1, tasks.get(0), projectData.getProjectDto(), projectData.getMainBranchDto(), null);
+ verifyCeTask(taskSubmit2, tasks.get(1), null, null, null);
}
@Test
public void massSubmit_populates_component_name_and_key_of_CeTask_if_project_and_branch_exists() {
- ComponentDto project = db.components().insertPublicProject(p -> p.setUuid("PROJECT_1").setBranchUuid("PROJECT_1")).getMainBranchComponent();
- ComponentDto branch1 = db.components().insertProjectBranch(project);
- ComponentDto branch2 = db.components().insertProjectBranch(project);
- CeTaskSubmit taskSubmit1 = createTaskSubmit(CeTaskTypes.REPORT, Component.fromDto(branch1.uuid(), project.uuid()), null);
- CeTaskSubmit taskSubmit2 = createTaskSubmit("something", Component.fromDto(branch2.uuid(), project.uuid()), null);
+ ProjectDto project = db.components().insertPublicProject(p -> p.setUuid("PROJECT_1").setBranchUuid("PROJECT_1")).getProjectDto();
+ BranchDto branch1 = db.components().insertProjectBranch(project);
+ BranchDto branch2 = db.components().insertProjectBranch(project);
+ CeTaskSubmit taskSubmit1 = createTaskSubmit(CeTaskTypes.REPORT, Component.fromDto(branch1.getUuid(), project.getUuid()), null);
+ CeTaskSubmit taskSubmit2 = createTaskSubmit("something", Component.fromDto(branch2.getUuid(), project.getUuid()), null);
List<CeTask> tasks = underTest.massSubmit(asList(taskSubmit1, taskSubmit2));
assertThat(tasks).hasSize(2);
- verifyCeTask(taskSubmit1, tasks.get(0), branch1, project, null);
- verifyCeTask(taskSubmit2, tasks.get(1), branch2, project, null);
+ verifyCeTask(taskSubmit1, tasks.get(0), project, branch1, null);
+ verifyCeTask(taskSubmit2, tasks.get(1), project, branch2, null);
}
@Test
@@ -274,7 +277,7 @@ public class CeQueueImplIT {
CeTaskSubmit taskSubmit = createTaskSubmit("no_component");
CeQueueDto dto = insertPendingInQueue(null);
- List<CeTask> tasks = underTest.massSubmit(of(taskSubmit), UNIQUE_QUEUE_PER_MAIN_COMPONENT);
+ List<CeTask> tasks = underTest.massSubmit(of(taskSubmit), UNIQUE_QUEUE_PER_ENTITY);
assertThat(tasks).hasSize(1);
assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession()))
@@ -289,7 +292,7 @@ public class CeQueueImplIT {
CeTaskSubmit taskSubmit = createTaskSubmit("with_component", newComponent(mainComponentUuid), null);
CeQueueDto dto = insertPendingInQueue(newComponent(otherMainComponentUuid));
- List<CeTask> tasks = underTest.massSubmit(of(taskSubmit), UNIQUE_QUEUE_PER_MAIN_COMPONENT);
+ List<CeTask> tasks = underTest.massSubmit(of(taskSubmit), UNIQUE_QUEUE_PER_ENTITY);
assertThat(tasks).hasSize(1);
assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession()))
@@ -303,7 +306,7 @@ public class CeQueueImplIT {
CeTaskSubmit taskSubmit = createTaskSubmit("with_component", newComponent(mainComponentUuid), null);
CeQueueDto dto = insertPendingInQueue(newComponent(mainComponentUuid));
- List<CeTask> tasks = underTest.massSubmit(of(taskSubmit), UNIQUE_QUEUE_PER_MAIN_COMPONENT);
+ List<CeTask> tasks = underTest.massSubmit(of(taskSubmit), UNIQUE_QUEUE_PER_ENTITY);
assertThat(tasks).isEmpty();
assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession()))
@@ -320,7 +323,7 @@ public class CeQueueImplIT {
.map(CeQueueDto::getUuid)
.toArray(String[]::new);
- List<CeTask> tasks = underTest.massSubmit(of(taskSubmit), UNIQUE_QUEUE_PER_MAIN_COMPONENT);
+ List<CeTask> tasks = underTest.massSubmit(of(taskSubmit), UNIQUE_QUEUE_PER_ENTITY);
assertThat(tasks).isEmpty();
assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession()))
@@ -382,13 +385,13 @@ public class CeQueueImplIT {
CeTaskSubmit taskSubmit5 = createTaskSubmit("with_pending_2", newComponent(mainComponentUuid5), null);
CeQueueDto dto5 = insertPendingInQueue(newComponent(mainComponentUuid5));
- List<CeTask> tasks = underTest.massSubmit(of(taskSubmit1, taskSubmit2, taskSubmit3, taskSubmit4, taskSubmit5), UNIQUE_QUEUE_PER_MAIN_COMPONENT);
+ List<CeTask> tasks = underTest.massSubmit(of(taskSubmit1, taskSubmit2, taskSubmit3, taskSubmit4, taskSubmit5), UNIQUE_QUEUE_PER_ENTITY);
assertThat(tasks)
.hasSize(2)
- .extracting(task -> task.getComponent().get().getUuid(), task -> task.getMainComponent().get().getUuid())
- .containsOnly(tuple(componentForMainComponentUuid2.getUuid(), componentForMainComponentUuid2.getMainComponentUuid()),
- tuple(componentForMainComponentUuid4.getUuid(), componentForMainComponentUuid4.getMainComponentUuid()));
+ .extracting(task -> task.getComponent().get().getUuid(), task -> task.getEntity().get().getUuid())
+ .containsOnly(tuple(componentForMainComponentUuid2.getUuid(), componentForMainComponentUuid2.getEntityUuid()),
+ tuple(componentForMainComponentUuid4.getUuid(), componentForMainComponentUuid4.getEntityUuid()));
assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession()))
.extracting(CeQueueDto::getUuid)
.hasSize(1 + uuids3.length + 1 + tasks.size())
@@ -565,31 +568,27 @@ public class CeQueueImplIT {
.hasMessage("Task is not in-progress and can't be marked as failed [uuid=" + task.getUuid() + "]");
}
- private void verifyCeTask(CeTaskSubmit taskSubmit, CeTask task, @Nullable ComponentDto componentDto, UserDto userDto) {
- verifyCeTask(taskSubmit, task, componentDto, componentDto, userDto);
- }
-
- private void verifyCeTask(CeTaskSubmit taskSubmit, CeTask task, @Nullable ComponentDto componentDto, @Nullable ComponentDto mainComponentDto, @Nullable UserDto userDto) {
+ private void verifyCeTask(CeTaskSubmit taskSubmit, CeTask task, @Nullable EntityDto entityDto, @Nullable BranchDto branch, @Nullable UserDto userDto) {
assertThat(task.getUuid()).isEqualTo(taskSubmit.getUuid());
- if (componentDto != null) {
+ if (branch != null) {
CeTask.Component component = task.getComponent().get();
- assertThat(component.getUuid()).isEqualTo(componentDto.uuid());
- assertThat(component.getKey()).contains(componentDto.getKey());
- assertThat(component.getName()).contains(componentDto.name());
+ assertThat(component.getUuid()).isEqualTo(branch.getUuid());
+ assertThat(component.getKey()).contains(entityDto.getKey());
+ assertThat(component.getName()).contains(entityDto.getName());
} else if (taskSubmit.getComponent().isPresent()) {
assertThat(task.getComponent()).contains(new CeTask.Component(taskSubmit.getComponent().get().getUuid(), null, null));
} else {
assertThat(task.getComponent()).isEmpty();
}
- if (mainComponentDto != null) {
- CeTask.Component component = task.getMainComponent().get();
- assertThat(component.getUuid()).isEqualTo(mainComponentDto.uuid());
- assertThat(component.getKey()).contains(mainComponentDto.getKey());
- assertThat(component.getName()).contains(mainComponentDto.name());
+ if (entityDto != null) {
+ CeTask.Component component = task.getEntity().get();
+ assertThat(component.getUuid()).isEqualTo(entityDto.getUuid());
+ assertThat(component.getKey()).contains(entityDto.getKey());
+ assertThat(component.getName()).contains(entityDto.getName());
} else if (taskSubmit.getComponent().isPresent()) {
- assertThat(task.getMainComponent()).contains(new CeTask.Component(taskSubmit.getComponent().get().getMainComponentUuid(), null, null));
+ assertThat(task.getEntity()).contains(new CeTask.Component(taskSubmit.getComponent().get().getEntityUuid(), null, null));
} else {
- assertThat(task.getMainComponent()).isEmpty();
+ assertThat(task.getEntity()).isEmpty();
}
assertThat(task.getType()).isEqualTo(taskSubmit.getType());
if (taskSubmit.getSubmitterUuid() != null) {
@@ -610,7 +609,7 @@ public class CeQueueImplIT {
Optional<Component> component = taskSubmit.getComponent();
if (component.isPresent()) {
assertThat(queueDto.get().getComponentUuid()).isEqualTo(component.get().getUuid());
- assertThat(queueDto.get().getMainComponentUuid()).isEqualTo(component.get().getMainComponentUuid());
+ assertThat(queueDto.get().getEntityUuid()).isEqualTo(component.get().getEntityUuid());
} else {
assertThat(queueDto.get().getComponentUuid()).isNull();
assertThat(queueDto.get().getComponentUuid()).isNull();
@@ -653,7 +652,7 @@ public class CeQueueImplIT {
.setStatus(CeQueueDto.Status.PENDING);
if (component != null) {
dto.setComponentUuid(component.getUuid())
- .setMainComponentUuid(component.getMainComponentUuid());
+ .setEntityUuid(component.getEntityUuid());
}
db.getDbClient().ceQueueDao().insert(db.getSession(), dto);
db.commit();
diff --git a/server/sonar-ce-common/src/main/java/org/sonar/ce/queue/CeQueue.java b/server/sonar-ce-common/src/main/java/org/sonar/ce/queue/CeQueue.java
index adee3c00e93..f0333f07bea 100644
--- a/server/sonar-ce-common/src/main/java/org/sonar/ce/queue/CeQueue.java
+++ b/server/sonar-ce-common/src/main/java/org/sonar/ce/queue/CeQueue.java
@@ -59,7 +59,7 @@ public interface CeQueue {
* <p>
* This method is equivalent to calling {@code massSubmit(Collections.singletonList(submission))}.
*
- * @return empty if {@code options} contains {@link SubmitOption#UNIQUE_QUEUE_PER_MAIN_COMPONENT UNIQUE_QUEUE_PER_MAIN_COMPONENT}
+ * @return empty if {@code options} contains {@link SubmitOption#UNIQUE_QUEUE_PER_ENTITY UNIQUE_QUEUE_PER_MAIN_COMPONENT}
* and there's already a queued task, otherwise the created task.
*/
Optional<CeTask> submit(CeTaskSubmit submission, SubmitOption... options);
@@ -124,7 +124,7 @@ public interface CeQueue {
int clear();
enum SubmitOption {
- UNIQUE_QUEUE_PER_MAIN_COMPONENT,
+ UNIQUE_QUEUE_PER_ENTITY,
UNIQUE_QUEUE_PER_TASK_TYPE
}
diff --git a/server/sonar-ce-common/src/main/java/org/sonar/ce/queue/CeQueueImpl.java b/server/sonar-ce-common/src/main/java/org/sonar/ce/queue/CeQueueImpl.java
index 88b77baec5c..0a78e1a5804 100644
--- a/server/sonar-ce-common/src/main/java/org/sonar/ce/queue/CeQueueImpl.java
+++ b/server/sonar-ce-common/src/main/java/org/sonar/ce/queue/CeQueueImpl.java
@@ -32,7 +32,6 @@ import java.util.Optional;
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Collectors;
-import java.util.stream.Stream;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.sonar.api.server.ServerSide;
@@ -49,15 +48,15 @@ import org.sonar.db.ce.CeTaskCharacteristicDto;
import org.sonar.db.ce.CeTaskQuery;
import org.sonar.db.ce.DeleteIf;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.entity.EntityDto;
import org.sonar.db.user.UserDto;
import org.sonar.server.platform.NodeInformation;
import org.sonar.server.property.InternalProperties;
import static com.google.common.base.Preconditions.checkState;
-import static java.util.Collections.emptyMap;
import static java.util.Collections.singleton;
import static java.util.Optional.ofNullable;
-import static org.sonar.ce.queue.CeQueue.SubmitOption.UNIQUE_QUEUE_PER_MAIN_COMPONENT;
+import static org.sonar.ce.queue.CeQueue.SubmitOption.UNIQUE_QUEUE_PER_ENTITY;
import static org.sonar.core.util.stream.MoreCollectors.toEnumSet;
import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
import static org.sonar.db.ce.CeQueueDto.Status.IN_PROGRESS;
@@ -105,14 +104,14 @@ public class CeQueueImpl implements CeQueue {
CeTaskQuery query = new CeTaskQuery();
for (SubmitOption option : submitOptions) {
switch (option) {
- case UNIQUE_QUEUE_PER_MAIN_COMPONENT -> submission.getComponent()
- .flatMap(component -> Optional.ofNullable(component.getMainComponentUuid()))
- .ifPresent(mainComponentUuid -> query.setMainComponentUuid(mainComponentUuid).setStatuses(List.of(PENDING.name())));
+ case UNIQUE_QUEUE_PER_ENTITY -> submission.getComponent()
+ .flatMap(component -> Optional.ofNullable(component.getEntityUuid()))
+ .ifPresent(entityUuid -> query.setEntityUuid(entityUuid).setStatuses(List.of(PENDING.name())));
case UNIQUE_QUEUE_PER_TASK_TYPE -> query.setType(submission.getType());
}
}
- boolean queryNonEmpty = query.getMainComponentUuids() != null || query.getStatuses() != null || query.getType() != null;
+ boolean queryNonEmpty = query.getEntityUuids() != null || query.getStatuses() != null || query.getType() != null;
if (queryNonEmpty && dbClient.ceQueueDao().countByQuery(dbSession, query) > 0) {
return Optional.empty();
}
@@ -121,26 +120,22 @@ public class CeQueueImpl implements CeQueue {
}
private CeTask convertQueueDtoToTask(DbSession dbSession, CeQueueDto queueDto, CeTaskSubmit submission) {
- Map<String, ComponentDto> componentsByUuid = loadComponentDtos(dbSession, queueDto);
- if (componentsByUuid.isEmpty()) {
- return convertToTask(dbSession, queueDto, submission.getCharacteristics(), null, null);
- }
- return convertToTask(dbSession, queueDto, submission.getCharacteristics(),
- ofNullable(queueDto.getComponentUuid()).map(componentsByUuid::get).orElse(null),
- ofNullable(queueDto.getMainComponentUuid()).map(componentsByUuid::get).orElse(null));
+ return convertToTask(dbSession, queueDto, submission.getCharacteristics());
}
- Map<String, ComponentDto> loadComponentDtos(DbSession dbSession, CeQueueDto taskDto) {
- Set<String> componentUuids = Stream.of(taskDto.getComponentUuid(), taskDto.getMainComponentUuid())
- .filter(Objects::nonNull)
- .collect(MoreCollectors.toSet(2));
- if (componentUuids.isEmpty()) {
- return emptyMap();
+ protected CeTask convertToTask(DbSession dbSession, CeQueueDto queueDto, Map<String, String> characteristicDto) {
+ ComponentDto component = null;
+ EntityDto entity = null;
+
+ if (queueDto.getComponentUuid() != null) {
+ component = dbClient.componentDao().selectByUuid(dbSession, queueDto.getComponentUuid()).orElse(null);
}
+ if (queueDto.getEntityUuid() != null) {
+ entity = dbClient.entityDao().selectByUuid(dbSession, queueDto.getEntityUuid()).orElse(null);
+ }
+
+ return convertToTask(dbSession, queueDto, characteristicDto, component, entity);
- return dbClient.componentDao().selectByUuids(dbSession, componentUuids)
- .stream()
- .collect(uniqueIndex(ComponentDto::uuid, 2));
}
@Override
@@ -163,12 +158,12 @@ public class CeQueueImpl implements CeQueue {
private Predicate<CeTaskSubmit> filterBySubmitOptions(SubmitOption[] options, Collection<CeTaskSubmit> submissions, DbSession dbSession) {
EnumSet<SubmitOption> submitOptions = toSet(options);
- if (submitOptions.contains(UNIQUE_QUEUE_PER_MAIN_COMPONENT)) {
+ if (submitOptions.contains(UNIQUE_QUEUE_PER_ENTITY)) {
Set<String> mainComponentUuids = submissions.stream()
.map(CeTaskSubmit::getComponent)
.filter(Optional::isPresent)
.map(Optional::get)
- .map(CeTaskSubmit.Component::getMainComponentUuid)
+ .map(CeTaskSubmit.Component::getEntityUuid)
.collect(MoreCollectors.toSet(submissions.size()));
if (mainComponentUuids.isEmpty()) {
return t -> true;
@@ -183,13 +178,13 @@ public class CeQueueImpl implements CeQueue {
private final Map<String, Integer> queuedItemsByMainComponentUuid;
private NoPendingTaskFilter(DbSession dbSession, Set<String> projectUuids) {
- queuedItemsByMainComponentUuid = dbClient.ceQueueDao().countByStatusAndMainComponentUuids(dbSession, PENDING, projectUuids);
+ queuedItemsByMainComponentUuid = dbClient.ceQueueDao().countByStatusAndEntityUuids(dbSession, PENDING, projectUuids);
}
@Override
public boolean test(CeTaskSubmit ceTaskSubmit) {
return ceTaskSubmit.getComponent()
- .map(component -> queuedItemsByMainComponentUuid.getOrDefault(component.getMainComponentUuid(), 0) == 0)
+ .map(component -> queuedItemsByMainComponentUuid.getOrDefault(component.getEntityUuid(), 0) == 0)
.orElse(true);
}
}
@@ -217,7 +212,7 @@ public class CeQueueImpl implements CeQueue {
dto.setTaskType(submission.getType());
submission.getComponent().ifPresent(component -> dto
.setComponentUuid(component.getUuid())
- .setMainComponentUuid(component.getMainComponentUuid()));
+ .setEntityUuid(component.getEntityUuid()));
dto.setStatus(PENDING);
dto.setSubmitterUuid(submission.getSubmitterUuid());
dbClient.ceQueueDao().insert(dbSession, dto);
@@ -228,12 +223,16 @@ public class CeQueueImpl implements CeQueue {
private List<CeTask> loadTasks(DbSession dbSession, List<CeQueueDto> dtos) {
// load components, if defined
Set<String> componentUuids = dtos.stream()
- .flatMap(dto -> Stream.of(dto.getComponentUuid(), dto.getMainComponentUuid()))
+ .map(CeQueueDto::getComponentUuid)
.filter(Objects::nonNull)
.collect(Collectors.toSet());
+ // these components correspond to a branch or a portfolio (analysis target)
Map<String, ComponentDto> componentsByUuid = dbClient.componentDao()
.selectByUuids(dbSession, componentUuids).stream()
.collect(uniqueIndex(ComponentDto::uuid));
+ Set<String> entityUuids = dtos.stream().map(CeQueueDto::getEntityUuid).filter(Objects::nonNull).collect(Collectors.toSet());
+ Map<String, EntityDto> entitiesByUuid = dbClient.entityDao().selectByUuids(dbSession, entityUuids).stream()
+ .collect(Collectors.toMap(EntityDto::getUuid, e -> e));
// load characteristics
// TODO could be avoided, characteristics are already present in submissions
@@ -247,12 +246,12 @@ public class CeQueueImpl implements CeQueue {
ComponentDto component = ofNullable(dto.getComponentUuid())
.map(componentsByUuid::get)
.orElse(null);
- ComponentDto mainComponent = ofNullable(dto.getMainComponentUuid())
- .map(componentsByUuid::get)
+ EntityDto entity = ofNullable(dto.getEntityUuid())
+ .map(entitiesByUuid::get)
.orElse(null);
Map<String, String> characteristics = characteristicsByTaskUuid.get(dto.getUuid()).stream()
.collect(uniqueIndex(CeTaskCharacteristicDto::getKey, CeTaskCharacteristicDto::getValue));
- result.add(convertToTask(dbSession, dto, characteristics, component, mainComponent));
+ result.add(convertToTask(dbSession, dto, characteristics, component, entity));
}
return result;
}
@@ -366,7 +365,7 @@ public class CeQueueImpl implements CeQueue {
return cancelAll(true);
}
- CeTask convertToTask(DbSession dbSession, CeQueueDto taskDto, Map<String, String> characteristics, @Nullable ComponentDto component, @Nullable ComponentDto mainComponent) {
+ CeTask convertToTask(DbSession dbSession, CeQueueDto taskDto, Map<String, String> characteristics, @Nullable ComponentDto component, @Nullable EntityDto entity) {
CeTask.Builder builder = new CeTask.Builder()
.setUuid(taskDto.getUuid())
.setType(taskDto.getTaskType())
@@ -380,11 +379,11 @@ public class CeQueueImpl implements CeQueue {
builder.setComponent(new CeTask.Component(componentUuid, null, null));
}
- String mainComponentUuid = taskDto.getMainComponentUuid();
- if (mainComponent != null) {
- builder.setMainComponent(new CeTask.Component(mainComponent.uuid(), mainComponent.getKey(), mainComponent.name()));
- } else if (mainComponentUuid != null) {
- builder.setMainComponent(new CeTask.Component(mainComponentUuid, null, null));
+ String entityUuid = taskDto.getEntityUuid();
+ if (entity != null) {
+ builder.setEntity(new CeTask.Component(entity.getUuid(), entity.getKey(), entity.getName()));
+ } else if (entityUuid != null) {
+ builder.setEntity(new CeTask.Component(entityUuid, null, null));
}
return builder.build();
diff --git a/server/sonar-ce-common/src/main/java/org/sonar/ce/queue/CeTaskSubmit.java b/server/sonar-ce-common/src/main/java/org/sonar/ce/queue/CeTaskSubmit.java
index a6e45798323..a9749b01fe6 100644
--- a/server/sonar-ce-common/src/main/java/org/sonar/ce/queue/CeTaskSubmit.java
+++ b/server/sonar-ce-common/src/main/java/org/sonar/ce/queue/CeTaskSubmit.java
@@ -27,7 +27,6 @@ import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
import org.sonar.db.component.BranchDto;
import org.sonar.db.portfolio.PortfolioDto;
-import org.sonar.db.project.ProjectDto;
import static com.google.common.base.Strings.emptyToNull;
import static com.google.common.base.Strings.nullToEmpty;
@@ -116,20 +115,16 @@ public final class CeTaskSubmit {
}
public static class Component {
- private String uuid;
- private String mainComponentUuid;
+ private final String uuid;
+ private final String entityUuid;
- public Component(String uuid, String mainComponentUuid) {
+ public Component(String uuid, String entityUuid) {
this.uuid = requireNonNull(nullToEmpty(uuid), "uuid can't be null");
- this.mainComponentUuid = requireNonNull(nullToEmpty(mainComponentUuid), "mainComponentUuid can't be null");
- }
-
- public static Component fromDto(String componentUuid, String mainComponentUuid) {
- return new Component(componentUuid, mainComponentUuid);
+ this.entityUuid = requireNonNull(nullToEmpty(entityUuid), "mainComponentUuid can't be null");
}
- public static Component fromDto(ProjectDto dto) {
- return new Component(dto.getUuid(), dto.getUuid());
+ public static Component fromDto(String componentUuid, String entityUuid) {
+ return new Component(componentUuid, entityUuid);
}
public static Component fromDto(PortfolioDto dto) {
@@ -140,23 +135,19 @@ public final class CeTaskSubmit {
return new Component(dto.getUuid(), dto.getProjectUuid());
}
- public static Component fromProjectUuid(String projectUuid) {
- return new Component(projectUuid, projectUuid);
- }
-
public String getUuid() {
return uuid;
}
- public String getMainComponentUuid() {
- return mainComponentUuid;
+ public String getEntityUuid() {
+ return entityUuid;
}
@Override
public String toString() {
return "Component{" +
"uuid='" + uuid + '\'' +
- ", mainComponentUuid='" + mainComponentUuid + '\'' +
+ ", entityUuid='" + entityUuid + '\'' +
'}';
}
@@ -169,12 +160,12 @@ public final class CeTaskSubmit {
return false;
}
Component component = (Component) o;
- return uuid.equals(component.uuid) && mainComponentUuid.equals(component.mainComponentUuid);
+ return uuid.equals(component.uuid) && entityUuid.equals(component.entityUuid);
}
@Override
public int hashCode() {
- return Objects.hash(uuid, mainComponentUuid);
+ return Objects.hash(uuid, entityUuid);
}
}
}