Search in sources :

Example 16 with BuildRecord

use of org.jboss.pnc.model.BuildRecord in project pnc by project-ncl.

the class DatastoreAdapter method storeResult.

/**
 * Store build result along with error information appended to the build log
 *
 * @param buildTask task
 * @param buildResult result of running the task
 * @param e The error that occurred during the build process
 * @throws DatastoreException on failure to store data
 */
public BuildRecord storeResult(BuildTask buildTask, Optional<BuildResult> buildResult, Throwable e) throws DatastoreException {
    BuildRecord.Builder buildRecordBuilder = initBuildRecordBuilder(buildTask);
    buildRecordBuilder.status(SYSTEM_ERROR);
    StringBuilder errorLog = new StringBuilder();
    buildResult.ifPresent(result -> {
        result.getRepourResult().ifPresent(repourResult -> {
            buildRecordBuilder.executionRootName(repourResult.getExecutionRootName());
            buildRecordBuilder.executionRootVersion(repourResult.getExecutionRootVersion());
            buildRecordBuilder.repourLog(repourResult.getLog());
        });
        result.getBuildDriverResult().ifPresent(buildDriverResult -> {
            errorLog.append(buildDriverResult.getBuildLog());
            errorLog.append("\n---- End Build Log ----\n");
        });
        result.getRepositoryManagerResult().ifPresent(rmr -> {
            errorLog.append(rmr.getLog());
            errorLog.append("\n---- End Repository Manager Log ----\n");
            errorLog.append("\n---- Start Built Artifacts List ----\n");
            rmr.getBuiltArtifacts().forEach(b -> errorLog.append(b).append('\n'));
            errorLog.append("\n---- End Built Artifacts List ----\n");
        });
        result.getEnvironmentDriverResult().ifPresent(r -> {
            if (r.getLog() != null && !r.getLog().equals(""))
                errorLog.append(r.getLog());
            errorLog.append("\n---- End Environment Driver Log ----\n");
        });
        // store scm information of failed build if present
        result.getBuildExecutionConfiguration().ifPresent(r -> {
            buildRecordBuilder.scmRepoURL(r.getScmRepoURL());
            buildRecordBuilder.scmRevision(r.getScmRevision());
            buildRecordBuilder.scmTag(r.getScmTag());
        });
    });
    errorLog.append("Build status: ").append(getBuildStatus(buildResult)).append("\n");
    errorLog.append("Caught exception: ").append(e.toString()).append("\n");
    StringWriter stackTraceWriter = new StringWriter();
    e.printStackTrace(new PrintWriter(stackTraceWriter));
    errorLog.append(stackTraceWriter.getBuffer());
    buildRecordBuilder.buildLog(errorLog.toString());
    userLog.error("Build status: {}.", getBuildStatus(buildResult));
    log.debug("Storing ERROR result of " + buildTask.getBuildConfigurationAudited().getName() + " to datastore.", e);
    return datastore.storeCompletedBuild(buildRecordBuilder, Collections.emptyList(), Collections.emptyList());
}
Also used : StringWriter(java.io.StringWriter) BuildRecord(org.jboss.pnc.model.BuildRecord) PrintWriter(java.io.PrintWriter)

Example 17 with BuildRecord

use of org.jboss.pnc.model.BuildRecord in project pnc by project-ncl.

the class TemporaryBuildsCleaner method deleteTemporaryBuildConfigSetRecord.

/**
 * Deletes a BuildConfigSetRecord and BuildRecords produced in the build
 *
 * @param buildConfigSetRecordId BuildConfigSetRecord to be deleted
 * @param authToken
 */
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public Result deleteTemporaryBuildConfigSetRecord(Integer buildConfigSetRecordId, String authToken) throws ValidationException {
    BuildConfigSetRecord buildConfigSetRecord = buildConfigSetRecordRepository.queryById(buildConfigSetRecordId);
    if (buildConfigSetRecord == null) {
        throw new ValidationException("Cannot delete temporary BuildConfigSetRecord with id " + buildConfigSetRecordId + " as no BuildConfigSetRecord with this id exists");
    }
    if (!buildConfigSetRecord.isTemporaryBuild()) {
        throw new ValidationException("Only deletion of the temporary builds is allowed");
    }
    log.info("Starting deletion of a temporary build record set " + buildConfigSetRecord);
    for (BuildRecord br : buildConfigSetRecord.getBuildRecords()) {
        br.setBuildConfigSetRecord(null);
        buildRecordRepository.save(br);
    }
    buildConfigSetRecordRepository.delete(buildConfigSetRecord.getId());
    log.info("Deletion of a temporary build record set {} finished successfully.", buildConfigSetRecord);
    return new Result(buildConfigSetRecordId.toString(), ResultStatus.SUCCESS);
}
Also used : ValidationException(org.jboss.pnc.spi.exception.ValidationException) BuildRecord(org.jboss.pnc.model.BuildRecord) BuildConfigSetRecord(org.jboss.pnc.model.BuildConfigSetRecord) Result(org.jboss.pnc.spi.coordinator.Result) TransactionAttribute(javax.ejb.TransactionAttribute)

Example 18 with BuildRecord

use of org.jboss.pnc.model.BuildRecord in project pnc by project-ncl.

the class ProductMilestoneReleaseManager method storeBuildRecordPush.

private void storeBuildRecordPush(BuildImportResultRest buildRest, ProductMilestoneRelease productMilestoneRelease) {
    Base32LongID recordId = BuildMapper.idMapper.toEntity(buildRest.getBuildRecordId());
    BuildRecord record = buildRecordRepository.queryById(recordId);
    if (record == null) {
        log.error("No record found for record id: {}, skipped saving info: {}", recordId, buildRest);
        return;
    }
    BuildPushStatus status;
    try {
        status = convertStatus(buildRest.getStatus());
    } catch (ProcessManagerException e) {
        log.error("Cannot convert status.", e);
        throw new RuntimeException("Cannot convert status.", e);
    }
    BuildRecordPushResult buildRecordPush = BuildRecordPushResult.newBuilder().id(Sequence.nextId()).buildRecord(record).status(status).brewBuildId(buildRest.getBrewBuildId()).brewBuildUrl(buildRest.getBrewBuildUrl()).tagPrefix(// TODO tag!
    "").productMilestoneRelease(productMilestoneRelease).build();
    buildRecordPushResultRepository.save(buildRecordPush);
}
Also used : Base32LongID(org.jboss.pnc.model.Base32LongID) BuildPushStatus(org.jboss.pnc.enums.BuildPushStatus) ProcessManagerException(org.jboss.pnc.spi.exception.ProcessManagerException) BuildRecordPushResult(org.jboss.pnc.model.BuildRecordPushResult) BuildRecord(org.jboss.pnc.model.BuildRecord)

Example 19 with BuildRecord

use of org.jboss.pnc.model.BuildRecord in project pnc by project-ncl.

the class BuildRecordRepositoryImpl method getAnyLatestSuccessfulBuildRecordWithBuildConfig.

@Override
public BuildRecord getAnyLatestSuccessfulBuildRecordWithBuildConfig(Integer configurationId, boolean temporaryBuild) {
    PageInfo pageInfo = new DefaultPageInfo(0, 1);
    SortInfo sortInfo = new DefaultSortInfo(SortInfo.SortingDirection.DESC, BuildRecord_.submitTime.getName());
    List<BuildRecord> buildRecords = queryWithPredicates(pageInfo, sortInfo, withBuildConfigurationId(configurationId), withSuccess(), includeTemporary(temporaryBuild));
    if (buildRecords.size() == 0) {
        return null;
    } else {
        return buildRecords.get(0);
    }
}
Also used : PageInfo(org.jboss.pnc.spi.datastore.repositories.api.PageInfo) DefaultPageInfo(org.jboss.pnc.spi.datastore.repositories.api.impl.DefaultPageInfo) DefaultPageInfo(org.jboss.pnc.spi.datastore.repositories.api.impl.DefaultPageInfo) DefaultSortInfo(org.jboss.pnc.spi.datastore.repositories.api.impl.DefaultSortInfo) BuildRecord(org.jboss.pnc.model.BuildRecord) SortInfo(org.jboss.pnc.spi.datastore.repositories.api.SortInfo) DefaultSortInfo(org.jboss.pnc.spi.datastore.repositories.api.impl.DefaultSortInfo)

Example 20 with BuildRecord

use of org.jboss.pnc.model.BuildRecord in project pnc by project-ncl.

the class BuildRecordRepositoryImpl method getPreferredLatestSuccessfulBuildRecordWithRevision.

@Override
public BuildRecord getPreferredLatestSuccessfulBuildRecordWithRevision(IdRev idRev, boolean temporaryBuild, AlignmentPreference alignmentPreference) {
    PageInfo pageInfo = new DefaultPageInfo(0, 1);
    SortInfo sortInfo = new DefaultSortInfo(SortInfo.SortingDirection.DESC, BuildRecord_.submitTime.getName());
    List<BuildRecord> buildRecords = queryWithPredicates(pageInfo, sortInfo, withBuildConfigurationIdRev(idRev), withSuccess(), includeTemporary(idRev, temporaryBuild, alignmentPreference));
    if (buildRecords.size() == 0) {
        return null;
    } else {
        return buildRecords.get(0);
    }
}
Also used : PageInfo(org.jboss.pnc.spi.datastore.repositories.api.PageInfo) DefaultPageInfo(org.jboss.pnc.spi.datastore.repositories.api.impl.DefaultPageInfo) DefaultPageInfo(org.jboss.pnc.spi.datastore.repositories.api.impl.DefaultPageInfo) DefaultSortInfo(org.jboss.pnc.spi.datastore.repositories.api.impl.DefaultSortInfo) BuildRecord(org.jboss.pnc.model.BuildRecord) SortInfo(org.jboss.pnc.spi.datastore.repositories.api.SortInfo) DefaultSortInfo(org.jboss.pnc.spi.datastore.repositories.api.impl.DefaultSortInfo)

Aggregations

BuildRecord (org.jboss.pnc.model.BuildRecord)92 Test (org.junit.Test)50 Base32LongID (org.jboss.pnc.model.Base32LongID)19 Build (org.jboss.pnc.dto.Build)15 BuildTask (org.jboss.pnc.spi.coordinator.BuildTask)15 ContainerTest (org.jboss.pnc.test.category.ContainerTest)14 HashSet (java.util.HashSet)13 Artifact (org.jboss.pnc.model.Artifact)13 BuildConfiguration (org.jboss.pnc.model.BuildConfiguration)13 SortInfo (org.jboss.pnc.spi.datastore.repositories.api.SortInfo)13 Date (java.util.Date)12 List (java.util.List)12 BuildConfigSetRecord (org.jboss.pnc.model.BuildConfigSetRecord)12 BuildConfigurationAudited (org.jboss.pnc.model.BuildConfigurationAudited)12 DatastoreMock (org.jboss.pnc.mock.datastore.DatastoreMock)11 PageInfo (org.jboss.pnc.spi.datastore.repositories.api.PageInfo)11 Logger (org.slf4j.Logger)11 LoggerFactory (org.slf4j.LoggerFactory)11 Inject (javax.inject.Inject)10 BuildStatus (org.jboss.pnc.enums.BuildStatus)10