Search in sources :

Example 66 with CeQueueDto

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

the class CeQueueCleanerTest method insertInQueue.

private CeQueueDto insertInQueue(String taskUuid, CeQueueDto.Status status) throws IOException {
    CeQueueDto dto = new CeQueueDto();
    dto.setTaskType(CeTaskTypes.REPORT);
    dto.setComponentUuid("PROJECT_1");
    dto.setUuid(taskUuid);
    dto.setStatus(status);
    dbTester.getDbClient().ceQueueDao().insert(dbTester.getSession(), dto);
    dbTester.getSession().commit();
    return dto;
}
Also used : CeQueueDto(org.sonar.db.ce.CeQueueDto)

Example 67 with CeQueueDto

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

the class CeQueueImpl method submit.

@Override
public CeTask submit(CeTaskSubmit submission) {
    checkState(!submitPaused.get(), "Compute Engine does not currently accept new tasks");
    try (DbSession dbSession = dbClient.openSession(false)) {
        CeQueueDto dto = new CeTaskSubmitToInsertedCeQueueDto(dbSession, dbClient).apply(submission);
        CeTask task = loadTask(dbSession, dto);
        dbSession.commit();
        return task;
    }
}
Also used : DbSession(org.sonar.db.DbSession) CeQueueDto(org.sonar.db.ce.CeQueueDto)

Example 68 with CeQueueDto

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

the class CeQueueImpl method cancel.

@Override
public boolean cancel(String taskUuid) {
    try (DbSession dbSession = dbClient.openSession(false)) {
        Optional<CeQueueDto> queueDto = dbClient.ceQueueDao().selectByUuid(dbSession, taskUuid);
        if (queueDto.isPresent()) {
            checkState(CeQueueDto.Status.PENDING.equals(queueDto.get().getStatus()), "Task is in progress and can't be canceled [uuid=%s]", taskUuid);
            cancelImpl(dbSession, queueDto.get());
            return true;
        }
        return false;
    }
}
Also used : DbSession(org.sonar.db.DbSession) CeQueueDto(org.sonar.db.ce.CeQueueDto)

Example 69 with CeQueueDto

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

the class ActivityAction method searchTaskByUuid.

private Optional<WsCe.Task> searchTaskByUuid(DbSession dbSession, ActivityWsRequest request) {
    String textQuery = request.getQuery();
    if (textQuery == null) {
        return Optional.absent();
    }
    Optional<CeQueueDto> queue = dbClient.ceQueueDao().selectByUuid(dbSession, textQuery);
    if (queue.isPresent()) {
        return Optional.of(formatter.formatQueue(dbSession, queue.get()));
    }
    Optional<CeActivityDto> activity = dbClient.ceActivityDao().selectByUuid(dbSession, textQuery);
    if (activity.isPresent()) {
        return Optional.of(formatter.formatActivity(dbSession, activity.get()));
    }
    return Optional.absent();
}
Also used : CeActivityDto(org.sonar.db.ce.CeActivityDto) CeQueueDto(org.sonar.db.ce.CeQueueDto) StringUtils.defaultString(org.apache.commons.lang.StringUtils.defaultString)

Example 70 with CeQueueDto

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

the class CeQueueImpl method massSubmit.

@Override
public List<CeTask> massSubmit(Collection<CeTaskSubmit> submissions, SubmitOption... options) {
    if (submissions.isEmpty()) {
        return Collections.emptyList();
    }
    try (DbSession dbSession = dbClient.openSession(false)) {
        List<CeQueueDto> taskDtos = submissions.stream().filter(filterBySubmitOptions(options, submissions, dbSession)).map(submission -> addToQueueInDb(dbSession, submission)).collect(Collectors.toList());
        List<CeTask> tasks = loadTasks(dbSession, taskDtos);
        dbSession.commit();
        return tasks;
    }
}
Also used : Arrays(java.util.Arrays) UserDto(org.sonar.db.user.UserDto) Optional.of(java.util.Optional.of) DeleteIf(org.sonar.db.ce.DeleteIf) Multimap(com.google.common.collect.Multimap) DbSession(org.sonar.db.DbSession) ArrayList(java.util.ArrayList) Loggers(org.sonar.api.utils.log.Loggers) CeActivityDto(org.sonar.db.ce.CeActivityDto) Collections.singleton(java.util.Collections.singleton) CeTask(org.sonar.ce.task.CeTask) Map(java.util.Map) InternalProperties(org.sonar.server.property.InternalProperties) PENDING(org.sonar.db.ce.CeQueueDto.Status.PENDING) MoreCollectors(org.sonar.core.util.stream.MoreCollectors) CeTaskCharacteristicDto(org.sonar.db.ce.CeTaskCharacteristicDto) EnumSet(java.util.EnumSet) Nullable(javax.annotation.Nullable) Collections.emptyMap(java.util.Collections.emptyMap) IN_PROGRESS(org.sonar.db.ce.CeQueueDto.Status.IN_PROGRESS) System2(org.sonar.api.utils.System2) Predicate(java.util.function.Predicate) Optional.ofNullable(java.util.Optional.ofNullable) Collection(java.util.Collection) UuidFactory(org.sonar.core.util.UuidFactory) Set(java.util.Set) MoreCollectors.toEnumSet(org.sonar.core.util.stream.MoreCollectors.toEnumSet) Collectors(java.util.stream.Collectors) Preconditions.checkState(com.google.common.base.Preconditions.checkState) Objects(java.util.Objects) DbClient(org.sonar.db.DbClient) List(java.util.List) ComponentDto(org.sonar.db.component.ComponentDto) Stream(java.util.stream.Stream) ServerSide(org.sonar.api.server.ServerSide) CeQueueDto(org.sonar.db.ce.CeQueueDto) MoreCollectors.uniqueIndex(org.sonar.core.util.stream.MoreCollectors.uniqueIndex) Optional(java.util.Optional) UNIQUE_QUEUE_PER_MAIN_COMPONENT(org.sonar.ce.queue.CeQueue.SubmitOption.UNIQUE_QUEUE_PER_MAIN_COMPONENT) Collections(java.util.Collections) CheckForNull(javax.annotation.CheckForNull) DbSession(org.sonar.db.DbSession) CeQueueDto(org.sonar.db.ce.CeQueueDto) CeTask(org.sonar.ce.task.CeTask)

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