Search in sources :

Example 6 with CeQueueDto

use of org.sonar.db.ce.CeQueueDto 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 7 with CeQueueDto

use of org.sonar.db.ce.CeQueueDto 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 8 with CeQueueDto

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

the class TaskFormatterTest method formatQueue_without_component.

@Test
public void formatQueue_without_component() {
    CeQueueDto dto = new CeQueueDto();
    dto.setUuid("UUID");
    dto.setTaskType("TYPE");
    dto.setStatus(CeQueueDto.Status.PENDING);
    dto.setCreatedAt(1_450_000_000_000L);
    WsCe.Task wsTask = underTest.formatQueue(db.getSession(), dto);
    assertThat(wsTask.getType()).isEqualTo("TYPE");
    assertThat(wsTask.getId()).isEqualTo("UUID");
    assertThat(wsTask.getStatus()).isEqualTo(WsCe.TaskStatus.PENDING);
    assertThat(wsTask.getLogs()).isFalse();
    assertThat(wsTask.getSubmittedAt()).isEqualTo(DateUtils.formatDateTime(new Date(1_450_000_000_000L)));
    assertThat(wsTask.hasScannerContext()).isFalse();
    assertThat(wsTask.hasExecutionTimeMs()).isFalse();
    assertThat(wsTask.hasSubmitterLogin()).isFalse();
    assertThat(wsTask.hasComponentId()).isFalse();
    assertThat(wsTask.hasComponentKey()).isFalse();
    assertThat(wsTask.hasComponentName()).isFalse();
    assertThat(wsTask.hasExecutedAt()).isFalse();
    assertThat(wsTask.hasStartedAt()).isFalse();
    assertThat(wsTask.hasExecutionTimeMs()).isFalse();
}
Also used : WsCe(org.sonarqube.ws.WsCe) CeQueueDto(org.sonar.db.ce.CeQueueDto) Date(java.util.Date) Test(org.junit.Test)

Example 9 with CeQueueDto

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

the class TaskFormatterTest method formatQueue_with_component_and_other_fields.

@Test
public void formatQueue_with_component_and_other_fields() throws IOException {
    String uuid = "COMPONENT_UUID";
    OrganizationDto organizationDto = db.organizations().insert();
    db.components().insertProject(organizationDto, (t) -> t.setUuid(uuid).setKey("COMPONENT_KEY").setName("Component Name"));
    CeQueueDto dto = new CeQueueDto();
    dto.setUuid("UUID");
    dto.setTaskType("TYPE");
    dto.setStatus(CeQueueDto.Status.IN_PROGRESS);
    dto.setCreatedAt(1_450_000_000_000L);
    dto.setStartedAt(1_451_000_000_000L);
    dto.setComponentUuid(uuid);
    dto.setSubmitterLogin("rob");
    WsCe.Task wsTask = underTest.formatQueue(db.getSession(), dto);
    assertThat(wsTask.getType()).isEqualTo("TYPE");
    assertThat(wsTask.getId()).isEqualTo("UUID");
    assertThat(wsTask.getComponentId()).isEqualTo(uuid);
    assertThat(wsTask.getComponentKey()).isEqualTo("COMPONENT_KEY");
    assertThat(wsTask.getComponentName()).isEqualTo("Component Name");
    assertThat(wsTask.getComponentQualifier()).isEqualTo("TRK");
    assertThat(wsTask.getStatus()).isEqualTo(WsCe.TaskStatus.IN_PROGRESS);
    assertThat(wsTask.getLogs()).isFalse();
    assertThat(wsTask.getSubmitterLogin()).isEqualTo("rob");
    assertThat(wsTask.hasExecutionTimeMs()).isTrue();
    assertThat(wsTask.hasExecutedAt()).isFalse();
    assertThat(wsTask.hasScannerContext()).isFalse();
}
Also used : WsCe(org.sonarqube.ws.WsCe) CeQueueDto(org.sonar.db.ce.CeQueueDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 10 with CeQueueDto

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

the class ComponentActionTest method insertQueue.

private CeQueueDto insertQueue(String taskUuid, String componentUuid, CeQueueDto.Status status) {
    CeQueueDto queueDto = new CeQueueDto();
    queueDto.setTaskType(CeTaskTypes.REPORT);
    queueDto.setComponentUuid(componentUuid);
    queueDto.setUuid(taskUuid);
    queueDto.setStatus(status);
    dbTester.getDbClient().ceQueueDao().insert(dbTester.getSession(), queueDto);
    dbTester.getSession().commit();
    return queueDto;
}
Also used : CeQueueDto(org.sonar.db.ce.CeQueueDto)

Aggregations

CeQueueDto (org.sonar.db.ce.CeQueueDto)32 Test (org.junit.Test)11 CeActivityDto (org.sonar.db.ce.CeActivityDto)11 DbSession (org.sonar.db.DbSession)8 WsCe (org.sonarqube.ws.WsCe)5 ComponentDto (org.sonar.db.component.ComponentDto)2 Date (java.util.Date)1 StringUtils.defaultString (org.apache.commons.lang.StringUtils.defaultString)1 CeTask (org.sonar.ce.queue.CeTask)1 Status (org.sonar.db.ce.CeQueueDto.Status)1 CeTaskQuery (org.sonar.db.ce.CeTaskQuery)1 OrganizationDto (org.sonar.db.organization.OrganizationDto)1 TestResponse (org.sonar.server.ws.TestResponse)1 ProjectResponse (org.sonarqube.ws.WsCe.ProjectResponse)1