Search in sources :

Example 1 with StoreResultException

use of com.qasymphony.ci.plugin.exception.StoreResultException in project jenkin-qtest-plugin by QASymphony.

the class StoreResultServiceImpl method fetchAll.

@Override
public ReadSubmitLogResult fetchAll(ReadSubmitLogRequest request) throws StoreResultException {
    FilePath resultPath = JobUtils.isPipelineJob(request.getJob()) == false ? getResultFolder(request.getProject()) : getResultFolder(request.getJob());
    Map<Integer, SubmittedResult> buildResults = new HashMap<>();
    int numOrder = request.getCurrentBuildNumber() / BREAK_FILE_BY;
    // get saved configuration
    Configuration configuration = null;
    if (JobUtils.isFreeStyleProjectJob(request.getProject()) == true) {
        configuration = ConfigService.getPluginConfiguration(request.getProject());
    }
    String qTestUrl = configuration == null ? "" : configuration.getUrl();
    Long projectId = configuration == null ? 0L : configuration.getProjectId();
    try {
        if (numOrder <= 0) {
            FilePath resultFile = getResultFile(resultPath, numOrder);
            buildResults.putAll(readResult(resultFile, qTestUrl, projectId));
        } else {
            for (int i = 0; i < numOrder; i++) {
                FilePath resultFile = getResultFile(resultPath, i);
                buildResults.putAll(readResult(resultFile, qTestUrl, projectId));
            }
        }
    } catch (Exception e) {
        throw new StoreResultException(e);
    }
    return new ReadSubmitLogResult().setResults(buildResults).setTotal(buildResults.size());
}
Also used : FilePath(hudson.FilePath) SubmittedResult(com.qasymphony.ci.plugin.model.SubmittedResult) Configuration(com.qasymphony.ci.plugin.model.Configuration) StoreResultException(com.qasymphony.ci.plugin.exception.StoreResultException) IOException(java.io.IOException) StoreResultException(com.qasymphony.ci.plugin.exception.StoreResultException)

Example 2 with StoreResultException

use of com.qasymphony.ci.plugin.exception.StoreResultException in project jenkin-qtest-plugin by QASymphony.

the class StoreResultServiceImpl method fetch.

@Override
public ReadSubmitLogResult fetch(ReadSubmitLogRequest request) throws StoreResultException {
    FilePath resultPath = getResultFolder(request.getProject());
    int numOrder = request.getCurrentBuildNumber() / BREAK_FILE_BY;
    List<FileReader> readerList = getReaderList(resultPath, numOrder);
    // get saved configuration
    Configuration configuration = ConfigService.getPluginConfiguration(request.getProject());
    String qTestUrl = configuration == null ? "" : configuration.getUrl();
    Long projectId = configuration == null ? 0L : configuration.getProjectId();
    int total = 0;
    Map<Integer, SubmittedResult> resultMap = new HashMap<>();
    for (FileReader reader : readerList) {
        total += reader.size();
        try {
            resultMap.putAll(buildSubmittedResult(reader.readAll(), qTestUrl, projectId));
        } catch (IOException e) {
            throw new StoreResultException(e.getMessage(), e);
        } finally {
            try {
                reader.close();
            } catch (IOException e) {
                throw new StoreResultException(e.getMessage(), e);
            }
        }
    }
    return new ReadSubmitLogResult().setTotal(total).setResults(resultMap);
}
Also used : FilePath(hudson.FilePath) SubmittedResult(com.qasymphony.ci.plugin.model.SubmittedResult) Configuration(com.qasymphony.ci.plugin.model.Configuration) StoreResultException(com.qasymphony.ci.plugin.exception.StoreResultException) IOException(java.io.IOException) FileReader(com.qasymphony.ci.plugin.store.file.FileReader)

Example 3 with StoreResultException

use of com.qasymphony.ci.plugin.exception.StoreResultException in project jenkin-qtest-plugin by QASymphony.

the class StoreResultServiceImpl method readResult.

private static Map<Integer, SubmittedResult> readResult(FilePath resultFile, String url, Long projectId) throws StoreResultException {
    SortedMap<Integer, String> lines = null;
    try {
        lines = resultFile.act(new FilePath.FileCallable<SortedMap<Integer, String>>() {

            @Override
            public SortedMap<Integer, String> invoke(File file, VirtualChannel virtualChannel) throws IOException, InterruptedException {
                FileReader fileReader = new FileReader(file);
                SortedMap<Integer, String> lines;
                try {
                    lines = fileReader.readAll();
                } finally {
                    if (null != fileReader)
                        fileReader.close();
                }
                return lines;
            }

            @Override
            public void checkRoles(RoleChecker roleChecker) throws SecurityException {
            }
        });
    } catch (Exception e) {
        throw new StoreResultException(String.format("Cannot read from result file:%s, %s", resultFile.getName(), e.getMessage()));
    }
    return buildSubmittedResult(lines, url, projectId);
}
Also used : VirtualChannel(hudson.remoting.VirtualChannel) RoleChecker(org.jenkinsci.remoting.RoleChecker) StoreResultException(com.qasymphony.ci.plugin.exception.StoreResultException) FileReader(com.qasymphony.ci.plugin.store.file.FileReader) File(java.io.File) IOException(java.io.IOException) StoreResultException(com.qasymphony.ci.plugin.exception.StoreResultException)

Example 4 with StoreResultException

use of com.qasymphony.ci.plugin.exception.StoreResultException in project jenkin-qtest-plugin by QASymphony.

the class StoreResultServiceImpl method store.

@Override
public Boolean store(Job job, final SubmittedResult result) throws StoreResultException {
    FilePath resultFolder = getResultFolder(job);
    try {
        resultFolder.mkdirs();
    } catch (Exception e) {
        throw new StoreResultException(String.format("Cannot make result folder:%s, %s", resultFolder.getName(), e.getMessage()));
    }
    FilePath resultFile = getResultFile(resultFolder, result.getBuildNumber() / BREAK_FILE_BY);
    try {
        resultFile.act(new FilePath.FileCallable<String>() {

            @Override
            public String invoke(File file, VirtualChannel virtualChannel) throws IOException, InterruptedException {
                BufferedWriter writer = null;
                try {
                    writer = new BufferedWriter(new FileWriter(file.getPath(), true));
                    writer.write(JsonUtils.toJson(result));
                    writer.newLine();
                    return null;
                } finally {
                    if (null != writer)
                        writer.close();
                }
            }

            @Override
            public void checkRoles(RoleChecker roleChecker) throws SecurityException {
            }
        });
    } catch (Exception e) {
        throw new StoreResultException("Cannot store result to file:" + e.getMessage());
    }
    return true;
}
Also used : FilePath(hudson.FilePath) VirtualChannel(hudson.remoting.VirtualChannel) FileWriter(java.io.FileWriter) StoreResultException(com.qasymphony.ci.plugin.exception.StoreResultException) IOException(java.io.IOException) IOException(java.io.IOException) StoreResultException(com.qasymphony.ci.plugin.exception.StoreResultException) BufferedWriter(java.io.BufferedWriter) RoleChecker(org.jenkinsci.remoting.RoleChecker) File(java.io.File)

Example 5 with StoreResultException

use of com.qasymphony.ci.plugin.exception.StoreResultException in project jenkin-qtest-plugin by QASymphony.

the class JunitQtestSubmitterImpl method storeSubmittedResult.

@Override
public SubmittedResult storeSubmittedResult(JunitSubmitterRequest junitSubmitterRequest, Run build, String buildResult, JunitSubmitterResult result) throws StoreResultException {
    String qTestUrl = junitSubmitterRequest.getqTestURL();
    Long projectId = junitSubmitterRequest.getProjectID();
    SubmittedResult submitResult = new SubmittedResult().setUrl(qTestUrl).setProjectId(projectId).setBuildNumber(build.getNumber()).setStatusBuild(buildResult).setTestSuiteId(result.getTestSuiteId()).setTestSuiteName(result.getTestSuiteName()).setSubmitStatus(result.getSubmittedStatus()).setNumberTestLog(result.getNumberOfTestLog()).setNumberTestResult(result.getNumberOfTestResult());
    try {
        storeResultService.store(build.getParent(), submitResult);
        return submitResult;
    } catch (Exception e) {
        LOG.log(Level.WARNING, e.getMessage(), e);
        throw new StoreResultException("Cannot store result." + e.getMessage(), e);
    }
}
Also used : SubmittedResult(com.qasymphony.ci.plugin.model.SubmittedResult) StoreResultException(com.qasymphony.ci.plugin.exception.StoreResultException) ClientRequestException(com.qasymphony.ci.plugin.utils.ClientRequestException) StoreResultException(com.qasymphony.ci.plugin.exception.StoreResultException) SubmittedException(com.qasymphony.ci.plugin.exception.SubmittedException)

Aggregations

StoreResultException (com.qasymphony.ci.plugin.exception.StoreResultException)5 IOException (java.io.IOException)4 SubmittedResult (com.qasymphony.ci.plugin.model.SubmittedResult)3 FilePath (hudson.FilePath)3 Configuration (com.qasymphony.ci.plugin.model.Configuration)2 FileReader (com.qasymphony.ci.plugin.store.file.FileReader)2 VirtualChannel (hudson.remoting.VirtualChannel)2 File (java.io.File)2 RoleChecker (org.jenkinsci.remoting.RoleChecker)2 SubmittedException (com.qasymphony.ci.plugin.exception.SubmittedException)1 ClientRequestException (com.qasymphony.ci.plugin.utils.ClientRequestException)1 BufferedWriter (java.io.BufferedWriter)1 FileWriter (java.io.FileWriter)1