use of org.sonar.db.ce.CeQueueDto in project sonarqube by SonarSource.
the class CeQueueImpl method cancelAll.
int cancelAll(boolean includeInProgress) {
int count = 0;
try (DbSession dbSession = dbClient.openSession(false)) {
for (CeQueueDto queueDto : dbClient.ceQueueDao().selectAllInAscOrder(dbSession)) {
if (includeInProgress || !queueDto.getStatus().equals(IN_PROGRESS)) {
cancelImpl(dbSession, queueDto);
count++;
}
}
return count;
}
}
use of org.sonar.db.ce.CeQueueDto in project sonarqube by SonarSource.
the class CeQueueImpl method submit.
private Optional<CeTask> submit(CeTaskSubmit submission, EnumSet<SubmitOption> submitOptions) {
try (DbSession dbSession = dbClient.openSession(false)) {
if (submitOptions.contains(UNIQUE_QUEUE_PER_MAIN_COMPONENT) && submission.getComponent().map(component -> dbClient.ceQueueDao().countByStatusAndMainComponentUuid(dbSession, PENDING, component.getMainComponentUuid()) > 0).orElse(false)) {
return Optional.empty();
}
CeQueueDto taskDto = addToQueueInDb(dbSession, submission);
dbSession.commit();
Map<String, ComponentDto> componentsByUuid = loadComponentDtos(dbSession, taskDto);
if (componentsByUuid.isEmpty()) {
return of(convertToTask(dbSession, taskDto, submission.getCharacteristics(), null, null));
}
return of(convertToTask(dbSession, taskDto, submission.getCharacteristics(), ofNullable(taskDto.getComponentUuid()).map(componentsByUuid::get).orElse(null), ofNullable(taskDto.getMainComponentUuid()).map(componentsByUuid::get).orElse(null)));
}
}
use of org.sonar.db.ce.CeQueueDto in project sonarqube by SonarSource.
the class CeQueueImpl method remove.
protected void remove(DbSession dbSession, CeQueueDto queueDto, CeActivityDto activityDto) {
String taskUuid = queueDto.getUuid();
CeQueueDto.Status expectedQueueDtoStatus = queueDto.getStatus();
dbClient.ceActivityDao().insert(dbSession, activityDto);
dbClient.ceTaskInputDao().deleteByUuids(dbSession, singleton(taskUuid));
int deletedTasks = dbClient.ceQueueDao().deleteByUuid(dbSession, taskUuid, new DeleteIf(expectedQueueDtoStatus));
if (deletedTasks == 1) {
dbSession.commit();
} else {
Loggers.get(CeQueueImpl.class).debug("Remove rolled back because task in queue with uuid {} and status {} could not be deleted", taskUuid, expectedQueueDtoStatus);
dbSession.rollback();
}
}
use of org.sonar.db.ce.CeQueueDto in project sonarqube by SonarSource.
the class CeQueueImplTest method insertPendingInQueue.
private CeQueueDto insertPendingInQueue(@Nullable Component component) {
CeQueueDto dto = new CeQueueDto().setUuid(UuidFactoryFast.getInstance().create()).setTaskType("some type").setStatus(CeQueueDto.Status.PENDING);
if (component != null) {
dto.setComponentUuid(component.getUuid()).setMainComponentUuid(component.getMainComponentUuid());
}
db.getDbClient().ceQueueDao().insert(db.getSession(), dto);
db.commit();
return dto;
}
use of org.sonar.db.ce.CeQueueDto in project sonarqube by SonarSource.
the class CeQueueImplTest method submit_without_UNIQUE_QUEUE_PER_MAIN_COMPONENT_creates_task_when_there_is_one_pending_task_for_same_main_component.
@Test
public void submit_without_UNIQUE_QUEUE_PER_MAIN_COMPONENT_creates_task_when_there_is_one_pending_task_for_same_main_component() {
String mainComponentUuid = randomAlphabetic(5);
CeTaskSubmit taskSubmit = createTaskSubmit("with_component", newComponent(mainComponentUuid), null);
CeQueueDto dto = insertPendingInQueue(newComponent(mainComponentUuid));
CeTask task = underTest.submit(taskSubmit);
assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession())).extracting(CeQueueDto::getUuid).containsOnly(dto.getUuid(), task.getUuid());
}
Aggregations