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());
}
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);
}
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);
}
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);
}
}
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);
}
}
Aggregations