use of org.jboss.pnc.model.BuildRecordPushResult in project pnc by project-ncl.
the class BuildResultPushManager method complete.
public Long complete(Base32LongID buildRecordId, BuildRecordPushResult buildRecordPushResult) {
// accept only listed elements otherwise a new request might be wrongly completed from response of an older one
// get context for validation
InProgress.Context pushContext = inProgress.get(buildRecordId);
if (pushContext == null) {
throw new MissingInternalReferenceException("Did not find referenced element.");
}
Long expectedPushResultId = BuildPushResultMapper.idMapper.toEntity(pushContext.getPushResultId());
// if the result id is set it must match the id generated when the remote operation has been triggered
if (buildRecordPushResult.getId() != null && !buildRecordPushResult.getId().equals(expectedPushResultId)) {
throw new InvalidReferenceException("Unexpected result id: " + buildRecordPushResult.getId());
}
// get and remove the context atomically
pushContext = inProgress.remove(buildRecordId);
if (pushContext == null) {
throw new MissingInternalReferenceException("Referenced element has gone.");
}
buildRecordPushResult.setId(expectedPushResultId);
buildRecordPushResult.setTagPrefix(pushContext.getTagPrefix());
BuildRecordPushResult saved = buildRecordPushResultRepository.save(buildRecordPushResult);
buildPushResultEvent.fire(mapper.toDTO(saved));
return saved.getId();
}
use of org.jboss.pnc.model.BuildRecordPushResult 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.BuildRecordPushResult in project pnc by project-ncl.
the class DefaultRemoteBuildsCleaner method requestDeleteViaCauseway.
private Result requestDeleteViaCauseway(BuildRecord buildRecord) {
List<BuildRecordPushResult> toRemove = buildRecordPushResultRepository.getAllSuccessfulForBuildRecord(buildRecord.getId());
String externalBuildId = BuildMapper.idMapper.toDto(buildRecord.getId());
for (BuildRecordPushResult pushResult : toRemove) {
boolean success = causewayUntag(pushResult.getTagPrefix(), pushResult.getBrewBuildId());
if (!success) {
logger.error("Failed to un-tag pushed build record. BuildRecord.id: {}; brewBuildId: {}; tagPrefix: {};", buildRecord.getId(), pushResult.getBrewBuildId(), pushResult.getTagPrefix());
return new Result(externalBuildId, ResultStatus.FAILED, "Failed to un-tag pushed build record.");
}
}
return new Result(externalBuildId, ResultStatus.SUCCESS);
}
use of org.jboss.pnc.model.BuildRecordPushResult in project pnc by project-ncl.
the class BrewPusherImpl method getBrewPushResult.
@Override
public BuildPushResult getBrewPushResult(String buildId) {
Base32LongID id = BuildMapper.idMapper.toEntity(buildId);
BuildPushResult result = null;
Optional<InProgress.Context> pushContext = buildResultPushManager.getContext(id);
if (pushContext.isPresent()) {
result = BuildPushResult.builder().buildId(buildId).status(BuildPushStatus.ACCEPTED).logContext(pushContext.get().getPushResultId()).build();
} else {
BuildRecordPushResult latestForBuildRecord = buildRecordPushResultRepository.getLatestForBuildRecord(id);
if (latestForBuildRecord != null) {
return buildPushResultMapper.toDTO(latestForBuildRecord);
}
}
return result;
}
Aggregations