]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-19850 Use different uuids for project and branch
authorlukasz-jarocki-sonarsource <lukasz.jarocki@sonarsource.com>
Tue, 11 Jul 2023 05:26:49 +0000 (07:26 +0200)
committersonartech <sonartech@sonarsource.com>
Wed, 19 Jul 2023 20:03:06 +0000 (20:03 +0000)
15 files changed:
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/ProjectPersister.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/taskprocessor/ProjectExportTaskProcessor.java
server/sonar-ce-task-projectanalysis/src/main/protobuf/project_dump.proto
server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentMapper.java
server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDto.java
server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java
server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml
server/sonar-webserver-webapi/src/it/java/org/sonar/server/ce/projectdump/ExportSubmitterImplIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/ce/queue/BranchReportSubmitterIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/ce/queue/ReportSubmitterIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/ce/ws/ComponentActionIT.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/projectdump/ExportSubmitterImpl.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/queue/ReportSubmitter.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/ws/ComponentAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ComponentUpdater.java

index cc6f1e76bc98ba939c01ed98190e8c8d4b435f44..c733fe9007b0cc9c58ddee9732cae0dd72103359 100644 (file)
@@ -47,7 +47,7 @@ public class ProjectPersister {
 
     ProjectDto dbProjectDto = dbClient.projectDao().selectProjectByKey(dbSession, treeRootHolder.getRoot().getKey())
       .orElseThrow(() -> new IllegalStateException("Project has been deleted by end-user during analysis"));
-    ProjectDto projectDto = toProjectDto(treeRootHolder.getRoot());
+    ProjectDto projectDto = toProjectDto(treeRootHolder.getRoot(), dbProjectDto);
 
     if (hasChanged(dbProjectDto, projectDto)) {
       // insert or update in projects table
@@ -64,9 +64,10 @@ public class ProjectPersister {
       !StringUtils.equals(dbProject.getDescription(), newProject.getDescription());
   }
 
-  private ProjectDto toProjectDto(Component root) {
+  private ProjectDto toProjectDto(Component root, ProjectDto projectDtoFromDatabase) {
     ProjectDto projectDto = new ProjectDto();
-    projectDto.setUuid(root.getUuid());
+    // Component has different uuid from project
+    projectDto.setUuid(projectDtoFromDatabase.getUuid());
     projectDto.setName(root.getName());
     projectDto.setDescription(root.getDescription());
     projectDto.setUpdatedAt(system2.now());
index 3383d7258e3bd0351afae5410140ee4f7e3c6680..e18d97a589bd0a765e7c4db8ad4c752cf321c8c9 100644 (file)
@@ -52,8 +52,7 @@ public class ProjectExportTaskProcessor implements CeTaskProcessor {
 
   private void processProjectExport(CeTask task) {
     CeTask.Component exportComponent = mandatoryComponent(task, PROJECT_EXPORT);
-    failIfNotMain(exportComponent, task);
-    ProjectDescriptor projectExportDescriptor = new ProjectDescriptor(exportComponent.getUuid(),
+    ProjectDescriptor projectExportDescriptor = new ProjectDescriptor(task.getEntity().get().getUuid(),
       mandatoryKey(exportComponent), mandatoryName(exportComponent));
 
     try (TaskContainer taskContainer = new TaskContainerImpl(componentContainer,
@@ -64,11 +63,6 @@ public class ProjectExportTaskProcessor implements CeTaskProcessor {
 
   }
 
-  private static void failIfNotMain(CeTask.Component exportComponent, CeTask task) {
-    task.getEntity().filter(entity -> entity.equals(exportComponent))
-      .orElseThrow(() -> new IllegalStateException("Component of task must be the same as entity"));
-  }
-
   private static CeTask.Component mandatoryComponent(CeTask task, String type) {
     return task.getComponent().orElseThrow(() -> new IllegalStateException(String.format("Task with type %s must have a component", type)));
   }
index 854edbbeeb3d85f9245b5e783cc7483352e139ec..f495c6df4d05a4d4233576d07cefbe3cbe650d42 100644 (file)
@@ -210,6 +210,7 @@ message Plugin {
 message LineHashes {
   int64 component_ref = 1;
   string hashes = 2;
+  // this is branch uuid
   string project_uuid = 3;
 }
 
index 68c0d16bf74fb666a0d80b97695d7ea4cec271a9..25424e7534944536eeba9b42753bf6a6d3bfc956 100644 (file)
@@ -85,7 +85,7 @@ public interface ComponentMapper {
   List<KeyWithUuidDto> selectUuidsByKeyFromProjectKeyAndBranchOrPr(@Param("projectKey") String projectKey,
     @Nullable @Param("branch") String branch, @Nullable @Param("pullRequest") String pullRequest);
 
-  Set<String> selectViewKeysWithEnabledCopyOfProject(@Param("projectUuids") Collection<String> projectUuids);
+  Set<String> selectViewKeysWithEnabledCopyOfProject(@Param("branchUuids") Collection<String> branchUuids);
 
   /**
    * Return technical projects from a view or a sub-view
index 88b351b71263c501d5e2f6a913d53f3f62545282..06334fd6de6b0ad14b3d33f9d61b8dd9d338bc1a 100644 (file)
@@ -218,9 +218,9 @@ public final class IssueDto implements Serializable {
    * The project branch where the issue is located.
    * Note that the name is misleading - it should be branch.
    */
-  public IssueDto setProject(ComponentDto project) {
-    this.projectKey = project.getKey();
-    this.projectUuid = project.uuid();
+  public IssueDto setProject(ComponentDto branch) {
+    this.projectKey = branch.getKey();
+    this.projectUuid = branch.uuid();
     return this;
   }
 
@@ -585,8 +585,7 @@ public final class IssueDto implements Serializable {
   }
 
   /**
-   * Should only be used to persist in E/S
-   * <p/>
+   * This is branch uuid, not a project uuid. The naming is wrong, the javadoc is right.
    * Please use {@link #setProject(ComponentDto)} instead
    */
   public IssueDto setProjectUuid(String s) {
index daf1ddd183df63ae0703064fa8eabe5ebe21c177..0e35b7cd53fd74b5d2ed5470fc888bfaf36ab868 100644 (file)
@@ -118,7 +118,7 @@ public class PurgeDao implements Dao {
     String rootUuid = conf.rootUuid();
     List<String> issueKeys = mapper.selectOldClosedIssueKeys(rootUuid, dateToLong(toDate));
     deleteIssues(mapper, issueKeys);
-    listener.onIssuesRemoval(rootUuid, issueKeys);
+    listener.onIssuesRemoval(conf.projectUuid(), issueKeys);
   }
 
   private static void deleteIssues(PurgeMapper mapper, Collection<String> issueKeys) {
index 9e499a062df14f46b62c85d4f0f4020fcbbb633f..e55f64f3fde694dfa355913c94abd80d6062bea2 100644 (file)
       and leaf.scope = 'FIL'
       and leaf.enabled = ${_true}
       and leaf.copy_component_uuid in
-        <foreach collection="projectUuids" open="(" close=")" item="uuid" separator=",">#{uuid,jdbcType=VARCHAR}</foreach>
+        <foreach collection="branchUuids" open="(" close=")" item="uuid" separator=",">#{uuid,jdbcType=VARCHAR}</foreach>
     where
       p.enabled = ${_true}
       and p.uuid = leaf.branch_uuid
index a67966441418beea2256358eea6e0641ed2dd640..a9af4585f5b9e8b792009eaf2e7a39897cd17899 100644 (file)
@@ -70,7 +70,7 @@ public class ExportSubmitterImplIT {
     underTest.submitProjectExport(projectDto.getKey(), SOME_SUBMITTER_UUID);
 
     assertThat(dbClient.ceQueueDao().selectAllInAscOrder(db.getSession()))
-      .extracting(CeQueueDto::getComponentUuid, CeQueueDto::getTaskType, CeQueueDto::getSubmitterUuid)
+      .extracting(CeQueueDto::getEntityUuid, CeQueueDto::getTaskType, CeQueueDto::getSubmitterUuid)
       .containsExactlyInAnyOrder(tuple(projectDto.getUuid(), "PROJECT_EXPORT", SOME_SUBMITTER_UUID));
   }
 
@@ -81,7 +81,7 @@ public class ExportSubmitterImplIT {
     underTest.submitProjectExport(projectDto.getKey(), null);
 
     assertThat(dbClient.ceQueueDao().selectAllInAscOrder(db.getSession()))
-      .extracting(CeQueueDto::getComponentUuid, CeQueueDto::getTaskType, CeQueueDto::getSubmitterUuid)
+      .extracting(CeQueueDto::getEntityUuid, CeQueueDto::getTaskType, CeQueueDto::getSubmitterUuid)
       .containsExactlyInAnyOrder(tuple(projectDto.getUuid(), "PROJECT_EXPORT", null));
   }
 
index 0086013dc79d271e0620d90c67625a9e30bb02c6..7a485268bac7bdc4feb9bb973a009c4b9aae70fc 100644 (file)
@@ -200,10 +200,10 @@ public class BranchReportSubmitterIT {
 
     underTest.submit(nonExistingBranch.getKey(), nonExistingBranch.name(), randomCharacteristics, reportInput);
 
-    BranchDto exitingProjectMainBranch = db.getDbClient().branchDao().selectByUuid(db.getSession(), nonExistingBranch.uuid()).get();
-    verify(branchSupport).createBranchComponent(any(DbSession.class), same(componentKey), eq(nonExistingBranch), eq(exitingProjectMainBranch));
+    BranchDto existingProjectMainBranch = db.getDbClient().branchDao().selectByUuid(db.getSession(), nonExistingBranch.uuid()).get();
+    verify(branchSupport).createBranchComponent(any(DbSession.class), same(componentKey), eq(nonExistingBranch), eq(existingProjectMainBranch));
     verify(branchSupportDelegate).createComponentKey(nonExistingBranch.getKey(), randomCharacteristics);
-    verify(branchSupportDelegate).createBranchComponent(any(DbSession.class), same(componentKey), eq(nonExistingBranch), eq(exitingProjectMainBranch));
+    verify(branchSupportDelegate).createBranchComponent(any(DbSession.class), same(componentKey), eq(nonExistingBranch), eq(existingProjectMainBranch));
     verifyNoMoreInteractions(branchSupportDelegate);
     verifyQueueSubmit(nonExistingBranch, createdBranch, user, randomCharacteristics, taskUuid);
     verify(componentUpdater).commitAndIndex(any(DbSession.class), eq(componentCreationData));
@@ -261,7 +261,6 @@ public class BranchReportSubmitterIT {
 
   private void verifyQueueSubmit(ComponentDto project, ComponentDto branch, UserDto user, Map<String, String> characteristics, String taskUuid) {
     ArgumentCaptor<CeTaskSubmit> captor = ArgumentCaptor.forClass(CeTaskSubmit.class);
-
     verify(queue).submit(captor.capture());
     CeTaskSubmit ceTask = captor.getValue();
     assertThat(ceTask.getUuid()).isEqualTo(taskUuid);
@@ -270,7 +269,8 @@ public class BranchReportSubmitterIT {
     assertThat(ceTask.getType()).isEqualTo(CeTaskTypes.REPORT);
     assertThat(ceTask.getComponent()).isPresent();
     assertThat(ceTask.getComponent().get().getUuid()).isEqualTo(branch.uuid());
-    assertThat(ceTask.getComponent().get().getEntityUuid()).isEqualTo(project.uuid());
+    BranchDto branchDto = db.getDbClient().branchDao().selectByUuid(db.getSession(), project.uuid()).get();
+    assertThat(ceTask.getComponent().get().getEntityUuid()).isEqualTo(branchDto.getProjectUuid());
   }
 
   private static BranchSupport.ComponentKey createComponentKeyOfBranch(String projectKey) {
index edd8ac74eecce1b0ecf87b4fe4ca67a9bbd78550..748ed942153161fbc0d1e616b3c164ca7ee66566 100644 (file)
@@ -38,6 +38,7 @@ import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
 import org.sonar.db.ce.CeTaskTypes;
 import org.sonar.db.component.ComponentDto;
+import org.sonar.db.entity.EntityDto;
 import org.sonar.db.component.ProjectData;
 import org.sonar.db.permission.GlobalPermission;
 import org.sonar.db.project.ProjectDto;
@@ -138,17 +139,17 @@ public class ReportSubmitterIT {
 
   @Test
   public void submit_a_report_on_existing_project() {
-    ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
+    ProjectData project = db.components().insertPrivateProject();
     UserDto user = db.users().insertUser();
-    userSession.logIn(user).addProjectPermission(SCAN.getKey(), project);
+    userSession.logIn(user).addProjectPermission(SCAN.getKey(), project.getMainBranchComponent());
     mockSuccessfulPrepareSubmitCall();
 
-    underTest.submit(project.getKey(), project.name(), emptyMap(), IOUtils.toInputStream("{binary}", UTF_8));
+    underTest.submit(project.projectKey(), project.getProjectDto().getName(), emptyMap(), IOUtils.toInputStream("{binary}", UTF_8));
 
     verifyReportIsPersisted(TASK_UUID);
     verifyNoInteractions(permissionTemplateService);
     verify(queue).submit(argThat(submit -> submit.getType().equals(CeTaskTypes.REPORT)
-      && submit.getComponent().filter(cpt -> cpt.getUuid().equals(project.uuid()) && cpt.getEntityUuid().equals(project.uuid())).isPresent()
+      && submit.getComponent().filter(cpt -> cpt.getUuid().equals(project.getMainBranchComponent().uuid()) && cpt.getEntityUuid().equals(project.projectUuid())).isPresent()
       && submit.getSubmitterUuid().equals(user.getUuid())
       && submit.getUuid().equals(TASK_UUID)));
   }
@@ -165,9 +166,11 @@ public class ReportSubmitterIT {
     underTest.submit(PROJECT_KEY, PROJECT_NAME, emptyMap(), IOUtils.toInputStream("{binary}", UTF_8));
 
     ComponentDto createdProject = db.getDbClient().componentDao().selectByKey(db.getSession(), PROJECT_KEY).get();
+    EntityDto entityDto = db.getDbClient().entityDao().selectByKey(db.getSession(), PROJECT_KEY).get();
+
     verifyReportIsPersisted(TASK_UUID);
     verify(queue).submit(argThat(submit -> submit.getType().equals(CeTaskTypes.REPORT)
-      && submit.getComponent().filter(cpt -> cpt.getUuid().equals(createdProject.uuid()) && cpt.getEntityUuid().equals(createdProject.uuid())).isPresent()
+      && submit.getComponent().filter(cpt -> cpt.getUuid().equals(createdProject.uuid()) && cpt.getEntityUuid().equals(entityDto.getUuid())).isPresent()
       && submit.getUuid().equals(TASK_UUID)));
   }
 
index 219ad666f72e67223c8d44d3badf5df0b4566923..2018a1b80ba1fe1d0acc05fbd62925ba2da7fe41 100644 (file)
@@ -36,7 +36,10 @@ import org.sonar.db.ce.CeTaskMessageDto;
 import org.sonar.db.ce.CeTaskMessageType;
 import org.sonar.db.ce.CeTaskTypes;
 import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ProjectData;
 import org.sonar.db.component.SnapshotDto;
+import org.sonar.db.entity.EntityDto;
+import org.sonar.db.project.ProjectDto;
 import org.sonar.server.component.TestComponentFinder;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.exceptions.NotFoundException;
@@ -73,7 +76,7 @@ public class ComponentActionIT {
 
   @Test
   public void empty_queue_and_empty_activity() {
-    ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
+    ProjectDto project = db.components().insertPrivateProject().getProjectDto();
     userSession.addProjectPermission(UserRole.USER, project);
 
     Ce.ComponentResponse response = ws.newRequest()
@@ -86,18 +89,18 @@ public class ComponentActionIT {
 
   @Test
   public void project_tasks() {
-    ComponentDto project1 = db.components().insertPrivateProject().getMainBranchComponent();
-    SnapshotDto analysisProject1 = db.components().insertSnapshot(project1);
-    ComponentDto project2 = db.components().insertPrivateProject().getMainBranchComponent();
-    userSession.addProjectPermission(UserRole.USER, project1);
-    insertActivity("T1", project1, CeActivityDto.Status.SUCCESS, analysisProject1);
-    insertActivity("T2", project2, CeActivityDto.Status.FAILED, null);
-    insertActivity("T3", project1, CeActivityDto.Status.FAILED, null);
-    insertQueue("T4", project1, IN_PROGRESS);
-    insertQueue("T5", project1, PENDING);
+    ProjectData project1 = db.components().insertPrivateProject();
+    SnapshotDto analysisProject1 = db.components().insertSnapshot(project1.getMainBranchComponent());
+    ProjectData project2 = db.components().insertPrivateProject();
+    userSession.addProjectPermission(UserRole.USER, project1.getProjectDto());
+    insertActivity("T1", project1.getMainBranchComponent(), project1.getProjectDto(), CeActivityDto.Status.SUCCESS, analysisProject1);
+    insertActivity("T2", project2.getMainBranchComponent(), project2.getProjectDto(), CeActivityDto.Status.FAILED, null);
+    insertActivity("T3", project1.getMainBranchComponent(), project1.getProjectDto(), CeActivityDto.Status.FAILED, null);
+    insertQueue("T4", project1.getMainBranchComponent(), project1.getProjectDto(), IN_PROGRESS);
+    insertQueue("T5", project1.getMainBranchComponent(), project1.getProjectDto(), PENDING);
 
     Ce.ComponentResponse response = ws.newRequest()
-      .setParam(PARAM_COMPONENT, project1.getKey())
+      .setParam(PARAM_COMPONENT, project1.projectKey())
       .executeProtobuf(Ce.ComponentResponse.class);
     assertThat(response.getQueueCount()).isEqualTo(2);
     assertThat(response.getQueue(0).getId()).isEqualTo("T4");
@@ -113,13 +116,13 @@ public class ComponentActionIT {
 
   @Test
   public void search_tasks_by_component_key() {
-    ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
-    logInWithBrowsePermission(project);
-    SnapshotDto analysis = db.components().insertSnapshot(project);
-    insertActivity("T1", project, CeActivityDto.Status.SUCCESS, analysis);
+    ProjectData project = db.components().insertPrivateProject();
+    logInWithBrowsePermission(project.getProjectDto());
+    SnapshotDto analysis = db.components().insertSnapshot(project.getMainBranchComponent());
+    insertActivity("T1", project.getMainBranchComponent(), project.getProjectDto(), CeActivityDto.Status.SUCCESS, analysis);
 
     Ce.ComponentResponse response = ws.newRequest()
-      .setParam(PARAM_COMPONENT, project.getKey())
+      .setParam(PARAM_COMPONENT, project.projectKey())
       .executeProtobuf(Ce.ComponentResponse.class);
     assertThat(response.hasCurrent()).isTrue();
     Ce.Task current = response.getCurrent();
@@ -131,13 +134,13 @@ public class ComponentActionIT {
 
   @Test
   public void search_tasks_by_component() {
-    ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
-    logInWithBrowsePermission(project);
-    SnapshotDto analysis = db.components().insertSnapshot(project);
-    insertActivity("T1", project, CeActivityDto.Status.SUCCESS, analysis);
+    ProjectData project = db.components().insertPrivateProject();
+    logInWithBrowsePermission(project.getProjectDto());
+    SnapshotDto analysis = db.components().insertSnapshot(project.getMainBranchComponent());
+    insertActivity("T1", project.getMainBranchComponent(), project.getProjectDto(), CeActivityDto.Status.SUCCESS, analysis);
 
     Ce.ComponentResponse response = ws.newRequest()
-      .setParam(PARAM_COMPONENT, project.getKey())
+      .setParam(PARAM_COMPONENT, project.projectKey())
       .executeProtobuf(Ce.ComponentResponse.class);
     assertThat(response.hasCurrent()).isTrue();
     Ce.Task current = response.getCurrent();
@@ -149,16 +152,16 @@ public class ComponentActionIT {
 
   @Test
   public void canceled_tasks_must_not_be_picked_as_current_analysis() {
-    ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
-    userSession.addProjectPermission(UserRole.USER, project);
-    insertActivity("T1", project, CeActivityDto.Status.SUCCESS);
-    insertActivity("T2", project, CeActivityDto.Status.FAILED);
-    insertActivity("T3", project, CeActivityDto.Status.SUCCESS);
-    insertActivity("T4", project, CeActivityDto.Status.CANCELED);
-    insertActivity("T5", project, CeActivityDto.Status.CANCELED);
+    ProjectData project = db.components().insertPrivateProject();
+    userSession.addProjectPermission(UserRole.USER, project.getProjectDto());
+    insertActivity("T1", project.getMainBranchComponent(), project.getProjectDto(), CeActivityDto.Status.SUCCESS);
+    insertActivity("T2", project.getMainBranchComponent(), project.getProjectDto(), CeActivityDto.Status.FAILED);
+    insertActivity("T3", project.getMainBranchComponent(), project.getProjectDto(), CeActivityDto.Status.SUCCESS);
+    insertActivity("T4", project.getMainBranchComponent(), project.getProjectDto(), CeActivityDto.Status.CANCELED);
+    insertActivity("T5", project.getMainBranchComponent(), project.getProjectDto(), CeActivityDto.Status.CANCELED);
 
     Ce.ComponentResponse response = ws.newRequest()
-      .setParam(PARAM_COMPONENT, project.getKey())
+      .setParam(PARAM_COMPONENT, project.projectKey())
       .executeProtobuf(Ce.ComponentResponse.class);
     assertThat(response.getQueueCount()).isZero();
     // T3 is the latest task executed on PROJECT_1 ignoring Canceled ones
@@ -171,35 +174,35 @@ public class ComponentActionIT {
 
   @Test
   public void branch_in_activity() {
-    ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
-    userSession.addProjectPermission(UserRole.USER, project);
+    ProjectData project = db.components().insertPrivateProject();
+    userSession.addProjectPermission(UserRole.USER, project.getProjectDto());
     String branchName = randomAlphanumeric(248);
-    ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH).setKey(branchName));
+    ComponentDto branch = db.components().insertProjectBranch(project.getMainBranchComponent(), b -> b.setBranchType(BRANCH).setKey(branchName));
     SnapshotDto analysis = db.components().insertSnapshot(branch);
-    CeActivityDto activity = insertActivity("T1", project, SUCCESS, analysis);
+    CeActivityDto activity = insertActivity("T1", project.getMainBranchComponent(), project.getProjectDto(), SUCCESS, analysis);
     insertCharacteristic(activity, BRANCH_KEY, branchName);
     insertCharacteristic(activity, BRANCH_TYPE_KEY, BRANCH.name());
 
     Ce.ComponentResponse response = ws.newRequest()
-      .setParam(PARAM_COMPONENT, project.getKey())
+      .setParam(PARAM_COMPONENT, project.projectKey())
       .executeProtobuf(Ce.ComponentResponse.class);
 
     assertThat(response.getCurrent())
       .extracting(Ce.Task::getId, Ce.Task::getBranch, Ce.Task::getBranchType, Ce.Task::getStatus, Ce.Task::getComponentKey, Ce.Task::getWarningCount, Ce.Task::getWarningsList)
       .containsOnly(
-        "T1", branchName, Common.BranchType.BRANCH, Ce.TaskStatus.SUCCESS, project.getKey(), 0, emptyList());
+        "T1", branchName, Common.BranchType.BRANCH, Ce.TaskStatus.SUCCESS, project.projectKey(), 0, emptyList());
   }
 
   @Test
   public void branch_in_queue_analysis() {
-    ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
-    userSession.addProjectPermission(UserRole.USER, project);
+    ProjectData project = db.components().insertPrivateProject();
+    userSession.addProjectPermission(UserRole.USER, project.getProjectDto());
     String branchName = randomAlphanumeric(248);
-    ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH).setKey(branchName));
-    CeQueueDto queue1 = insertQueue("T1", project, IN_PROGRESS);
+    ComponentDto branch = db.components().insertProjectBranch(project.getMainBranchComponent(), b -> b.setBranchType(BRANCH).setKey(branchName));
+    CeQueueDto queue1 = insertQueue("T1", project.getMainBranchComponent(), project.getProjectDto(), IN_PROGRESS);
     insertCharacteristic(queue1, BRANCH_KEY, branchName);
     insertCharacteristic(queue1, BRANCH_TYPE_KEY, BRANCH.name());
-    CeQueueDto queue2 = insertQueue("T2", project, PENDING);
+    CeQueueDto queue2 = insertQueue("T2", project.getMainBranchComponent(), project.getProjectDto(), PENDING);
     insertCharacteristic(queue2, BRANCH_KEY, branchName);
     insertCharacteristic(queue2, BRANCH_TYPE_KEY, BRANCH.name());
 
@@ -210,44 +213,46 @@ public class ComponentActionIT {
     assertThat(response.getQueueList())
       .extracting(Ce.Task::getId, Ce.Task::getBranch, Ce.Task::getBranchType, Ce.Task::getStatus, Ce.Task::getComponentKey, Ce.Task::getWarningCount, Ce.Task::getWarningsList)
       .containsOnly(
-        tuple("T1", branchName, Common.BranchType.BRANCH, Ce.TaskStatus.IN_PROGRESS, project.getKey(), 0, emptyList()),
-        tuple("T2", branchName, Common.BranchType.BRANCH, Ce.TaskStatus.PENDING, project.getKey(), 0, emptyList()));
+        tuple("T1", branchName, Common.BranchType.BRANCH, Ce.TaskStatus.IN_PROGRESS, project.projectKey(), 0, emptyList()),
+        tuple("T2", branchName, Common.BranchType.BRANCH, Ce.TaskStatus.PENDING, project.projectKey(), 0, emptyList()));
   }
 
   @Test
   public void return_many_tasks_from_same_project() {
-    ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
-    userSession.addProjectPermission(UserRole.USER, project);
-    insertQueue("Main", project, IN_PROGRESS);
+    ProjectData project = db.components().insertPrivateProject();
+    userSession.addProjectPermission(UserRole.USER, project.getProjectDto());
+    insertQueue("Main", project.getMainBranchComponent(), project.getProjectDto(), IN_PROGRESS);
+
     String branchName1 = "Branch1";
-    ComponentDto branch1 = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH).setKey("branch1"));
-    CeQueueDto branchQueue1 = insertQueue("Branch1", project, IN_PROGRESS);
+    ComponentDto branch1 = db.components().insertProjectBranch(project.getMainBranchComponent(), b -> b.setBranchType(BRANCH).setKey("branch1"));
+    CeQueueDto branchQueue1 = insertQueue("Branch1", project.getMainBranchComponent(), project.getProjectDto(), IN_PROGRESS);
     insertCharacteristic(branchQueue1, BRANCH_KEY, branchName1);
     insertCharacteristic(branchQueue1, BRANCH_TYPE_KEY, BRANCH.name());
-    ComponentDto branch2 = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH).setKey("branch2"));
+
+    ComponentDto branch2 = db.components().insertProjectBranch(project.getMainBranchComponent(), b -> b.setBranchType(BRANCH).setKey("branch2"));
     String branchName2 = "Branch2";
-    CeQueueDto branchQueue2 = insertQueue("Branch2", project, PENDING);
+    CeQueueDto branchQueue2 = insertQueue("Branch2", project.getMainBranchComponent(), project.getProjectDto(), PENDING);
     insertCharacteristic(branchQueue2, BRANCH_KEY, branchName2);
     insertCharacteristic(branchQueue2, BRANCH_TYPE_KEY, BRANCH.name());
 
     Ce.ComponentResponse response = ws.newRequest()
-      .setParam(PARAM_COMPONENT, branch1.getKey())
+      .setParam(PARAM_COMPONENT, project.projectKey())
       .executeProtobuf(Ce.ComponentResponse.class);
 
     assertThat(response.getQueueList())
       .extracting(Ce.Task::getId, Ce.Task::getComponentKey, Ce.Task::getBranch, Ce.Task::getBranchType, Ce.Task::getWarningCount, Ce.Task::getWarningsList)
       .containsOnly(
-        tuple("Main", project.getKey(), "", Common.BranchType.UNKNOWN_BRANCH_TYPE, 0, emptyList()),
+        tuple("Main", project.projectKey(), "", Common.BranchType.UNKNOWN_BRANCH_TYPE, 0, emptyList()),
         tuple("Branch1", branch1.getKey(), branchName1, Common.BranchType.BRANCH, 0, emptyList()),
         tuple("Branch2", branch2.getKey(), branchName2, Common.BranchType.BRANCH, 0, emptyList()));
   }
 
   @Test
   public void populates_warning_count_and_warnings_of_activities() {
-    ComponentDto privateProject = db.components().insertPrivateProject().getMainBranchComponent();
-    userSession.addProjectPermission(UserRole.USER, privateProject);
-    SnapshotDto analysis = db.components().insertSnapshot(privateProject);
-    CeActivityDto activity = insertActivity("Branch", privateProject, SUCCESS, analysis);
+    ProjectData privateProject = db.components().insertPrivateProject();
+    userSession.addProjectPermission(UserRole.USER, privateProject.getProjectDto());
+    SnapshotDto analysis = db.components().insertSnapshot(privateProject.getMainBranchComponent());
+    CeActivityDto activity = insertActivity("Branch", privateProject.getMainBranchComponent(), privateProject.getProjectDto(), SUCCESS, analysis);
     int messageCount = 5;
     List<CeTaskMessageDto> ceTaskMessageDtos = IntStream.range(0, messageCount)
       .mapToObj(i -> new CeTaskMessageDto()
@@ -262,7 +267,7 @@ public class ComponentActionIT {
     db.commit();
 
     Ce.ComponentResponse response = ws.newRequest()
-      .setParam(PARAM_COMPONENT, privateProject.getKey())
+      .setParam(PARAM_COMPONENT, privateProject.projectKey())
       .executeProtobuf(Ce.ComponentResponse.class);
     assertThat(response.hasCurrent()).isTrue();
     assertThat(response.getCurrent())
@@ -294,22 +299,22 @@ public class ComponentActionIT {
 
   @Test
   public void fail_when_no_component_parameter() {
-    logInWithBrowsePermission(db.components().insertPrivateProject().getMainBranchComponent());
+    logInWithBrowsePermission(db.components().insertPrivateProject().getProjectDto());
 
     TestRequest request = ws.newRequest();
     assertThatThrownBy(request::execute)
       .isInstanceOf(IllegalArgumentException.class);
   }
 
-  private void logInWithBrowsePermission(ComponentDto project) {
+  private void logInWithBrowsePermission(ProjectDto project) {
     userSession.logIn().addProjectPermission(UserRole.USER, project);
   }
 
-  private CeQueueDto insertQueue(String taskUuid, ComponentDto component, CeQueueDto.Status status) {
+  private CeQueueDto insertQueue(String taskUuid, ComponentDto component, EntityDto entityDto, CeQueueDto.Status status) {
     CeQueueDto queueDto = new CeQueueDto();
     queueDto.setTaskType(CeTaskTypes.REPORT);
     queueDto.setComponentUuid(component.uuid());
-    queueDto.setEntityUuid(component.uuid());
+    queueDto.setEntityUuid(entityDto.getUuid());
     queueDto.setUuid(taskUuid);
     queueDto.setStatus(status);
     db.getDbClient().ceQueueDao().insert(db.getSession(), queueDto);
@@ -317,15 +322,15 @@ public class ComponentActionIT {
     return queueDto;
   }
 
-  private CeActivityDto insertActivity(String taskUuid, ComponentDto component, CeActivityDto.Status status) {
-    return insertActivity(taskUuid, component, status, db.components().insertSnapshot(component));
+  private CeActivityDto insertActivity(String taskUuid, ComponentDto component, EntityDto entityDto, CeActivityDto.Status status) {
+    return insertActivity(taskUuid, component, entityDto, status, db.components().insertSnapshot(component));
   }
 
-  private CeActivityDto insertActivity(String taskUuid, ComponentDto component, CeActivityDto.Status status, @Nullable SnapshotDto analysis) {
+  private CeActivityDto insertActivity(String taskUuid, ComponentDto component, EntityDto entityDto, CeActivityDto.Status status, @Nullable SnapshotDto analysis) {
     CeQueueDto queueDto = new CeQueueDto();
     queueDto.setTaskType(CeTaskTypes.REPORT);
     queueDto.setComponentUuid(component.uuid());
-    queueDto.setEntityUuid(component.uuid());
+    queueDto.setEntityUuid(entityDto.getUuid());
     queueDto.setUuid(taskUuid);
     CeActivityDto activityDto = new CeActivityDto(queueDto);
     activityDto.setStatus(status);
index 45223f39d8062293d7f2f24eea2021055ffa2ad0..96f4b5721db935e330c1b42d65fd21bfba262574 100644 (file)
@@ -27,6 +27,7 @@ import org.sonar.ce.task.CeTask;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.ce.CeTaskTypes;
+import org.sonar.db.component.ComponentDto;
 import org.sonar.db.project.ProjectDto;
 
 import static com.google.common.base.Preconditions.checkArgument;
@@ -49,10 +50,12 @@ public class ExportSubmitterImpl implements ExportSubmitter {
 
     try (DbSession dbSession = dbClient.openSession(false)) {
       Optional<ProjectDto> project = dbClient.projectDao().selectProjectByKey(dbSession, projectKey);
+      Optional<ComponentDto> componentDto = dbClient.componentDao().selectByKey(dbSession, projectKey);
       checkArgument(project.isPresent(), "Project with key [%s] does not exist", projectKey);
+      checkArgument(componentDto.isPresent(), "Component with key [%s] does not exist", projectKey);
 
       CeTaskSubmit submit = ceQueue.prepareSubmit()
-        .setComponent(fromDto(project.get().getUuid(), project.get().getUuid()))
+        .setComponent(fromDto(componentDto.get().uuid(), project.get().getUuid()))
         .setType(CeTaskTypes.PROJECT_EXPORT)
         .setSubmitterUuid(submitterUuid)
         .setCharacteristics(emptyMap())
index 81427f7d77daaef119f66c49dbcd3c0b6349865b..9a332ccbd7d2607213853c296c9773ef4af2703c 100644 (file)
@@ -182,7 +182,7 @@ public class ReportSubmitter {
     dbClient.ceTaskInputDao().insert(dbSession, submit.getUuid(), reportInput);
     dbSession.commit();
     submit.setType(CeTaskTypes.REPORT);
-    submit.setComponent(CeTaskSubmit.Component.fromDto(branch.uuid(), mainBranch.getUuid()));
+    submit.setComponent(CeTaskSubmit.Component.fromDto(branch.uuid(), mainBranch.getProjectUuid()));
     submit.setSubmitterUuid(userSession.getUuid());
     submit.setCharacteristics(characteristics);
     return queue.submit(submit.build());
index 7ea20e7da03ba8b300461a5afa68de747b95f58b..fb3d38625b7a4330b06af2cb03a9155897f45d17 100644 (file)
@@ -30,7 +30,7 @@ import org.sonar.db.DbSession;
 import org.sonar.db.ce.CeActivityDto;
 import org.sonar.db.ce.CeQueueDto;
 import org.sonar.db.ce.CeTaskQuery;
-import org.sonar.db.component.ComponentDto;
+import org.sonar.db.entity.EntityDto;
 import org.sonar.server.component.ComponentFinder;
 import org.sonar.server.user.UserSession;
 import org.sonar.server.ws.KeyExamples;
@@ -80,11 +80,12 @@ public class ComponentAction implements CeWsAction {
   @Override
   public void handle(Request wsRequest, Response wsResponse) throws Exception {
     try (DbSession dbSession = dbClient.openSession(false)) {
-      ComponentDto component = loadComponent(dbSession, wsRequest);
-      userSession.checkComponentPermission(UserRole.USER, component);
-      List<CeQueueDto> queueDtos = dbClient.ceQueueDao().selectByEntityUuid(dbSession, component.uuid());
+      String entityKey = wsRequest.mandatoryParam(PARAM_COMPONENT);
+      EntityDto entityDto = componentFinder.getEntityByKey(dbSession, entityKey);
+      userSession.checkEntityPermission(UserRole.USER, entityDto);
+      List<CeQueueDto> queueDtos = dbClient.ceQueueDao().selectByEntityUuid(dbSession, entityDto.getUuid());
       CeTaskQuery activityQuery = new CeTaskQuery()
-        .setEntityUuid(component.uuid())
+        .setEntityUuid(entityDto.getUuid())
         .setOnlyCurrents(true);
       List<CeActivityDto> activityDtos = dbClient.ceActivityDao().selectByQuery(dbSession, activityQuery, forPage(1).andSize(1));
 
@@ -96,9 +97,4 @@ public class ComponentAction implements CeWsAction {
       writeProtobuf(wsResponseBuilder.build(), wsRequest, wsResponse);
     }
   }
-
-  private ComponentDto loadComponent(DbSession dbSession, Request wsRequest) {
-    String componentKey = wsRequest.mandatoryParam(PARAM_COMPONENT);
-    return componentFinder.getByKey(dbSession, componentKey);
-  }
 }
index 56713dd745a813d3dfaa64a462665d14c4d86d4c..843183bd137ac79a7d3453ff9e1849bef0aa2b2f 100644 (file)
@@ -204,7 +204,7 @@ public class ComponentUpdater {
 
   private ProjectDto toProjectDto(ComponentDto component, long now) {
     return new ProjectDto()
-      .setUuid(useDifferentUuids ? uuidFactory.create() : component.uuid())
+      .setUuid(uuidFactory.create())
       .setKey(component.getKey())
       .setQualifier(component.qualifier())
       .setName(component.name())