Search in sources :

Example 1 with CeActivityDto

use of org.sonar.db.ce.CeActivityDto 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)

Example 2 with CeActivityDto

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

the class InternalCeQueueImpl method remove.

@Override
public void remove(CeTask task, CeActivityDto.Status status, @Nullable CeTaskResult taskResult, @Nullable Throwable error) {
    checkArgument(error == null || status == CeActivityDto.Status.FAILED, "Error can be provided only when status is FAILED");
    try (DbSession dbSession = dbClient.openSession(false)) {
        Optional<CeQueueDto> queueDto = dbClient.ceQueueDao().selectByUuid(dbSession, task.getUuid());
        checkState(queueDto.isPresent(), "Task does not exist anymore: %s", task);
        CeActivityDto activityDto = new CeActivityDto(queueDto.get());
        activityDto.setStatus(status);
        updateQueueStatus(status, activityDto);
        updateTaskResult(activityDto, taskResult);
        updateError(activityDto, error);
        remove(dbSession, queueDto.get(), activityDto);
    }
}
Also used : DbSession(org.sonar.db.DbSession) CeActivityDto(org.sonar.db.ce.CeActivityDto) CeQueueDto(org.sonar.db.ce.CeQueueDto)

Example 3 with CeActivityDto

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

the class ComponentAction method handle.

@Override
public void handle(Request wsRequest, Response wsResponse) throws Exception {
    try (DbSession dbSession = dbClient.openSession(false)) {
        ComponentDto component = componentFinder.getByUuidOrKey(dbSession, wsRequest.param(PARAM_COMPONENT_ID), wsRequest.param(PARAM_COMPONENT_KEY), COMPONENT_ID_AND_KEY);
        userSession.checkComponentPermission(UserRole.USER, component);
        List<CeQueueDto> queueDtos = dbClient.ceQueueDao().selectByComponentUuid(dbSession, component.uuid());
        CeTaskQuery activityQuery = new CeTaskQuery().setComponentUuid(component.uuid()).setOnlyCurrents(true);
        List<CeActivityDto> activityDtos = dbClient.ceActivityDao().selectByQuery(dbSession, activityQuery, 0, 1);
        ProjectResponse.Builder wsResponseBuilder = ProjectResponse.newBuilder();
        wsResponseBuilder.addAllQueue(formatter.formatQueue(dbSession, queueDtos));
        if (activityDtos.size() == 1) {
            wsResponseBuilder.setCurrent(formatter.formatActivity(dbSession, activityDtos.get(0)));
        }
        writeProtobuf(wsResponseBuilder.build(), wsRequest, wsResponse);
    }
}
Also used : DbSession(org.sonar.db.DbSession) ProjectResponse(org.sonarqube.ws.WsCe.ProjectResponse) CeActivityDto(org.sonar.db.ce.CeActivityDto) ComponentDto(org.sonar.db.component.ComponentDto) CeQueueDto(org.sonar.db.ce.CeQueueDto) CeTaskQuery(org.sonar.db.ce.CeTaskQuery)

Example 4 with CeActivityDto

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

the class TaskAction method handle.

@Override
public void handle(Request wsRequest, Response wsResponse) throws Exception {
    String taskUuid = wsRequest.mandatoryParam(PARAM_TASK_UUID);
    try (DbSession dbSession = dbClient.openSession(false)) {
        WsCe.TaskResponse.Builder wsTaskResponse = WsCe.TaskResponse.newBuilder();
        Optional<CeQueueDto> queueDto = dbClient.ceQueueDao().selectByUuid(dbSession, taskUuid);
        if (queueDto.isPresent()) {
            Optional<ComponentDto> component = loadComponent(dbSession, queueDto.get().getComponentUuid());
            checkPermission(component);
            wsTaskResponse.setTask(wsTaskFormatter.formatQueue(dbSession, queueDto.get(), component));
        } else {
            CeActivityDto ceActivityDto = WsUtils.checkFoundWithOptional(dbClient.ceActivityDao().selectByUuid(dbSession, taskUuid), "No activity found for task '%s'", taskUuid);
            Optional<ComponentDto> component = loadComponent(dbSession, ceActivityDto.getComponentUuid());
            checkPermission(component);
            Set<AdditionalField> additionalFields = AdditionalField.getFromRequest(wsRequest);
            maskErrorStacktrace(ceActivityDto, additionalFields);
            wsTaskResponse.setTask(wsTaskFormatter.formatActivity(dbSession, ceActivityDto, component, extractScannerContext(dbSession, ceActivityDto, additionalFields)));
        }
        writeProtobuf(wsTaskResponse.build(), wsRequest, wsResponse);
    }
}
Also used : DbSession(org.sonar.db.DbSession) CeActivityDto(org.sonar.db.ce.CeActivityDto) ComponentDto(org.sonar.db.component.ComponentDto) CeQueueDto(org.sonar.db.ce.CeQueueDto)

Example 5 with CeActivityDto

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

the class TaskActionTest method return_stacktrace_of_failed_activity_with_stacktrace_when_additionalField_is_set.

@Test
public void return_stacktrace_of_failed_activity_with_stacktrace_when_additionalField_is_set() {
    logInAsRoot();
    CeActivityDto activityDto = createActivityDto(SOME_TASK_UUID).setErrorMessage("error msg").setErrorStacktrace("error stack");
    persist(activityDto);
    TestResponse wsResponse = ws.newRequest().setMediaType(PROTOBUF).setParam("id", SOME_TASK_UUID).setParam("additionalFields", "stacktrace").execute();
    WsCe.TaskResponse taskResponse = Protobuf.read(wsResponse.getInputStream(), WsCe.TaskResponse.PARSER);
    WsCe.Task task = taskResponse.getTask();
    assertThat(task.getId()).isEqualTo(SOME_TASK_UUID);
    assertThat(task.getErrorMessage()).isEqualTo(activityDto.getErrorMessage());
    assertThat(task.hasErrorStacktrace()).isTrue();
    assertThat(task.getErrorStacktrace()).isEqualTo(activityDto.getErrorStacktrace());
}
Also used : CeActivityDto(org.sonar.db.ce.CeActivityDto) TestResponse(org.sonar.server.ws.TestResponse) WsCe(org.sonarqube.ws.WsCe) Test(org.junit.Test)

Aggregations

CeActivityDto (org.sonar.db.ce.CeActivityDto)33 Test (org.junit.Test)21 CeQueueDto (org.sonar.db.ce.CeQueueDto)11 WsCe (org.sonarqube.ws.WsCe)9 CeTask (org.sonar.ce.queue.CeTask)6 TestResponse (org.sonar.server.ws.TestResponse)4 DbSession (org.sonar.db.DbSession)3 ComponentDto (org.sonar.db.component.ComponentDto)2 Date (java.util.Date)1 StringUtils.defaultString (org.apache.commons.lang.StringUtils.defaultString)1 Status (org.sonar.db.ce.CeQueueDto.Status)1 CeTaskQuery (org.sonar.db.ce.CeTaskQuery)1 ProjectResponse (org.sonarqube.ws.WsCe.ProjectResponse)1