Search in sources :

Example 51 with CeQueueDto

use of org.sonar.db.ce.CeQueueDto in project sonarqube by SonarSource.

the class InternalCeQueueImplTest method peek_resets_to_pending_any_task_in_progress_for_specified_worker_uuid_and_only_this_uuid.

@Test
public void peek_resets_to_pending_any_task_in_progress_for_specified_worker_uuid_and_only_this_uuid() {
    // add a pending one that will be picked so that u1 isn't peek and status reset is visible in DB
    insertPending("u0");
    CeQueueDto u1 = insertInProgress("u1", WORKER_UUID_1);
    CeQueueDto u2 = insertInProgress("u2", WORKER_UUID_2);
    CeQueueDto u3 = insertInProgress("u3", WORKER_UUID_1);
    CeQueueDto u4 = insertInProgress("u4", WORKER_UUID_2);
    assertThat(underTest.peek(WORKER_UUID_1, true).get().getUuid()).isEqualTo("u0");
    verifyResetTask(u1);
    verifyUnmodifiedTask(u2);
    verifyResetTask(u3);
    verifyUnmodifiedTask(u4);
}
Also used : CeQueueDto(org.sonar.db.ce.CeQueueDto) Test(org.junit.Test)

Example 52 with CeQueueDto

use of org.sonar.db.ce.CeQueueDto in project sonarqube by SonarSource.

the class UpdateVisibilityActionTest method insertCeQueueDto.

private void insertCeQueueDto(ComponentDto project, CeQueueDto.Status status) {
    dbClient.ceQueueDao().insert(dbTester.getSession(), new CeQueueDto().setUuid("pending" + counter++).setComponent(project).setTaskType("foo").setStatus(status));
    dbTester.commit();
}
Also used : CeQueueDto(org.sonar.db.ce.CeQueueDto)

Example 53 with CeQueueDto

use of org.sonar.db.ce.CeQueueDto in project sonarqube by SonarSource.

the class CeQueueImpl method loadTasks.

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())).filter(Objects::nonNull).collect(Collectors.toSet());
    Map<String, ComponentDto> componentsByUuid = dbClient.componentDao().selectByUuids(dbSession, componentUuids).stream().collect(uniqueIndex(ComponentDto::uuid));
    // load characteristics
    // TODO could be avoided, characteristics are already present in submissions
    Set<String> taskUuids = dtos.stream().map(CeQueueDto::getUuid).collect(MoreCollectors.toSet(dtos.size()));
    Multimap<String, CeTaskCharacteristicDto> characteristicsByTaskUuid = dbClient.ceTaskCharacteristicsDao().selectByTaskUuids(dbSession, taskUuids).stream().collect(MoreCollectors.index(CeTaskCharacteristicDto::getTaskUuid));
    List<CeTask> result = new ArrayList<>();
    for (CeQueueDto dto : dtos) {
        ComponentDto component = ofNullable(dto.getComponentUuid()).map(componentsByUuid::get).orElse(null);
        ComponentDto mainComponent = ofNullable(dto.getMainComponentUuid()).map(componentsByUuid::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));
    }
    return result;
}
Also used : CeTaskCharacteristicDto(org.sonar.db.ce.CeTaskCharacteristicDto) ComponentDto(org.sonar.db.component.ComponentDto) ArrayList(java.util.ArrayList) CeQueueDto(org.sonar.db.ce.CeQueueDto) CeTask(org.sonar.ce.task.CeTask)

Example 54 with CeQueueDto

use of org.sonar.db.ce.CeQueueDto in project sonarqube by SonarSource.

the class CeQueueImpl method addToQueueInDb.

private CeQueueDto addToQueueInDb(DbSession dbSession, CeTaskSubmit submission) {
    for (Map.Entry<String, String> characteristic : submission.getCharacteristics().entrySet()) {
        CeTaskCharacteristicDto characteristicDto = new CeTaskCharacteristicDto();
        characteristicDto.setUuid(uuidFactory.create());
        characteristicDto.setTaskUuid(submission.getUuid());
        characteristicDto.setKey(characteristic.getKey());
        characteristicDto.setValue(characteristic.getValue());
        dbClient.ceTaskCharacteristicsDao().insert(dbSession, characteristicDto);
    }
    CeQueueDto dto = new CeQueueDto();
    dto.setUuid(submission.getUuid());
    dto.setTaskType(submission.getType());
    submission.getComponent().ifPresent(component -> dto.setComponentUuid(component.getUuid()).setMainComponentUuid(component.getMainComponentUuid()));
    dto.setStatus(PENDING);
    dto.setSubmitterUuid(submission.getSubmitterUuid());
    dbClient.ceQueueDao().insert(dbSession, dto);
    return dto;
}
Also used : CeTaskCharacteristicDto(org.sonar.db.ce.CeTaskCharacteristicDto) CeQueueDto(org.sonar.db.ce.CeQueueDto) Map(java.util.Map) Collections.emptyMap(java.util.Collections.emptyMap)

Example 55 with CeQueueDto

use of org.sonar.db.ce.CeQueueDto in project sonarqube by SonarSource.

the class PurgeDaoTest method insertCeActivity.

private CeActivityDto insertCeActivity(ComponentDto component) {
    Status unusedStatus = Status.values()[RandomUtils.nextInt(Status.values().length)];
    CeQueueDto queueDto = createCeQueue(component, unusedStatus);
    CeActivityDto dto = new CeActivityDto(queueDto);
    dto.setStatus(CeActivityDto.Status.SUCCESS);
    dto.setStartedAt(1_500_000_000_000L);
    dto.setExecutedAt(1_500_000_000_500L);
    dto.setExecutionTimeMs(500L);
    dbClient.ceActivityDao().insert(dbSession, dto);
    return dto;
}
Also used : Status(org.sonar.db.ce.CeQueueDto.Status) CeActivityDto(org.sonar.db.ce.CeActivityDto) CeQueueDto(org.sonar.db.ce.CeQueueDto)

Aggregations

CeQueueDto (org.sonar.db.ce.CeQueueDto)120 Test (org.junit.Test)58 CeActivityDto (org.sonar.db.ce.CeActivityDto)36 ComponentDto (org.sonar.db.component.ComponentDto)20 DbSession (org.sonar.db.DbSession)18 CeTask (org.sonar.ce.task.CeTask)17 UserDto (org.sonar.db.user.UserDto)17 Ce (org.sonarqube.ws.Ce)11 CeTaskCharacteristicDto (org.sonar.db.ce.CeTaskCharacteristicDto)6 List (java.util.List)5 Optional (java.util.Optional)5 Random (java.util.Random)5 Collectors (java.util.stream.Collectors)5 System2 (org.sonar.api.utils.System2)5 Arrays (java.util.Arrays)4 Arrays.asList (java.util.Arrays.asList)4 Collection (java.util.Collection)4 Collections (java.util.Collections)4 Date (java.util.Date)4 IntStream (java.util.stream.IntStream)4