Search in sources :

Example 1 with Ce

use of org.sonarqube.ws.Ce in project sonarqube by SonarSource.

the class QualityGateCheck method await.

public void await() {
    if (!enabled) {
        LOG.debug("Quality Gate check disabled - skipping");
        return;
    }
    if (analysisMode.isMediumTest()) {
        throw new IllegalStateException("Quality Gate check not available in medium test mode");
    }
    LOG.info("Waiting for the analysis report to be processed (max {}s)", properties.qualityGateWaitTimeout());
    String taskId = ceTaskReportDataHolder.getCeTaskId();
    Ce.Task task = waitForCeTaskToFinish(taskId);
    if (!TaskStatus.SUCCESS.equals(task.getStatus())) {
        throw MessageException.of(String.format("CE Task finished abnormally with status: %s, you can check details here: %s", task.getStatus().name(), ceTaskReportDataHolder.getCeTaskUrl()));
    }
    Status qualityGateStatus = getQualityGateStatus(task.getAnalysisId());
    if (Status.OK.equals(qualityGateStatus)) {
        LOG.info("QUALITY GATE STATUS: PASSED - View details on " + ceTaskReportDataHolder.getDashboardUrl());
    } else {
        throw MessageException.of("QUALITY GATE STATUS: FAILED - View details on " + ceTaskReportDataHolder.getDashboardUrl());
    }
}
Also used : TaskStatus(org.sonarqube.ws.Ce.TaskStatus) Status(org.sonarqube.ws.Qualitygates.ProjectStatusResponse.Status) Ce(org.sonarqube.ws.Ce)

Example 2 with Ce

use of org.sonarqube.ws.Ce in project sonarqube by SonarSource.

the class QualityGateCheck method waitForCeTaskToFinish.

private Ce.Task waitForCeTaskToFinish(String taskId) {
    GetRequest getTaskResultReq = new GetRequest("api/ce/task").setMediaType(MediaTypes.PROTOBUF).setParam("id", taskId);
    long currentTime = 0;
    while (qualityGateTimeoutInMs > currentTime) {
        try {
            WsResponse getTaskResultResponse = wsClient.call(getTaskResultReq).failIfNotSuccessful();
            Ce.Task task = parseCeTaskResponse(getTaskResultResponse);
            if (TASK_TERMINAL_STATUSES.contains(task.getStatus())) {
                return task;
            }
            Thread.sleep(POLLING_INTERVAL_IN_MS);
            currentTime += POLLING_INTERVAL_IN_MS;
        } catch (HttpException e) {
            throw MessageException.of(String.format("Failed to get CE Task status - %s", DefaultScannerWsClient.createErrorMessage(e)));
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new IllegalStateException("Quality Gate check has been interrupted", e);
        }
    }
    throw MessageException.of("Quality Gate check timeout exceeded - View details on " + ceTaskReportDataHolder.getDashboardUrl());
}
Also used : Ce(org.sonarqube.ws.Ce) GetRequest(org.sonarqube.ws.client.GetRequest) WsResponse(org.sonarqube.ws.client.WsResponse) HttpException(org.sonarqube.ws.client.HttpException)

Aggregations

Ce (org.sonarqube.ws.Ce)2 TaskStatus (org.sonarqube.ws.Ce.TaskStatus)1 Status (org.sonarqube.ws.Qualitygates.ProjectStatusResponse.Status)1 GetRequest (org.sonarqube.ws.client.GetRequest)1 HttpException (org.sonarqube.ws.client.HttpException)1 WsResponse (org.sonarqube.ws.client.WsResponse)1