Search in sources :

Example 1 with CeTaskProcessor

use of org.sonar.ce.taskprocessor.CeTaskProcessor in project sonarqube by SonarSource.

the class CeWorkerCallableImpl method executeTask.

private void executeTask(CeTask task) {
    ceLogging.initForTask(task);
    Profiler ceProfiler = startActivityProfiler(task);
    CeActivityDto.Status status = CeActivityDto.Status.FAILED;
    CeTaskResult taskResult = null;
    Throwable error = null;
    try {
        // TODO delegate the message to the related task processor, according to task type
        Optional<CeTaskProcessor> taskProcessor = taskProcessorRepository.getForCeTask(task);
        if (taskProcessor.isPresent()) {
            taskResult = taskProcessor.get().process(task);
            status = CeActivityDto.Status.SUCCESS;
        } else {
            LOG.error("No CeTaskProcessor is defined for task of type {}. Plugin configuration may have changed", task.getType());
            status = CeActivityDto.Status.FAILED;
        }
    } catch (Throwable e) {
        LOG.error(format("Failed to execute task %s", task.getUuid()), e);
        error = e;
    } finally {
        finalizeTask(task, ceProfiler, status, taskResult, error);
    }
}
Also used : CeTaskResult(org.sonar.ce.queue.CeTaskResult) CeTaskProcessor(org.sonar.ce.taskprocessor.CeTaskProcessor) CeActivityDto(org.sonar.db.ce.CeActivityDto) Profiler(org.sonar.core.util.logs.Profiler)

Example 2 with CeTaskProcessor

use of org.sonar.ce.taskprocessor.CeTaskProcessor in project sonarqube by SonarSource.

the class CeTaskProcessorRepositoryImplTest method getForTask_returns_TaskProcessor_based_on_CeTask_type_only.

@Test
public void getForTask_returns_TaskProcessor_based_on_CeTask_type_only() {
    CeTaskProcessor taskProcessor = createCeTaskProcessor(SOME_CE_TASK_TYPE);
    CeTaskProcessorRepositoryImpl underTest = new CeTaskProcessorRepositoryImpl(new CeTaskProcessor[] { taskProcessor });
    assertThat(underTest.getForCeTask(createCeTask(SOME_CE_TASK_TYPE, SOME_COMPONENT_KEY)).get()).isSameAs(taskProcessor);
    assertThat(underTest.getForCeTask(createCeTask(SOME_CE_TASK_TYPE, SOME_COMPONENT_KEY + "2")).get()).isSameAs(taskProcessor);
}
Also used : CeTaskProcessor(org.sonar.ce.taskprocessor.CeTaskProcessor) Test(org.junit.Test)

Example 3 with CeTaskProcessor

use of org.sonar.ce.taskprocessor.CeTaskProcessor in project sonarqube by SonarSource.

the class CeTaskProcessorRepositoryImplTest method getForTask_returns_TaskProcessor_even_if_it_is_not_specific.

@Test
public void getForTask_returns_TaskProcessor_even_if_it_is_not_specific() {
    CeTaskProcessor taskProcessor = createCeTaskProcessor(SOME_CE_TASK_TYPE + "_1", SOME_CE_TASK_TYPE, SOME_CE_TASK_TYPE + "_3");
    CeTaskProcessorRepositoryImpl underTest = new CeTaskProcessorRepositoryImpl(new CeTaskProcessor[] { taskProcessor });
    assertThat(underTest.getForCeTask(createCeTask(SOME_CE_TASK_TYPE, SOME_COMPONENT_KEY)).get()).isSameAs(taskProcessor);
}
Also used : CeTaskProcessor(org.sonar.ce.taskprocessor.CeTaskProcessor) Test(org.junit.Test)

Example 4 with CeTaskProcessor

use of org.sonar.ce.taskprocessor.CeTaskProcessor in project sonarqube by SonarSource.

the class CeTaskProcessorRepositoryRule method getForCeTask.

@Override
public Optional<CeTaskProcessor> getForCeTask(CeTask ceTask) {
    CeTaskProcessor taskProcessor = index.get(ceTask.getType());
    checkState(taskProcessor != null, "CeTaskProcessor was not set in rule for task %s", ceTask);
    return taskProcessor instanceof NoCeTaskProcessor ? Optional.<CeTaskProcessor>absent() : Optional.of(taskProcessor);
}
Also used : CeTaskProcessor(org.sonar.ce.taskprocessor.CeTaskProcessor)

Aggregations

CeTaskProcessor (org.sonar.ce.taskprocessor.CeTaskProcessor)4 Test (org.junit.Test)2 CeTaskResult (org.sonar.ce.queue.CeTaskResult)1 Profiler (org.sonar.core.util.logs.Profiler)1 CeActivityDto (org.sonar.db.ce.CeActivityDto)1