Search in sources :

Example 1 with BuildRecordPushResult

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();
}
Also used : MissingInternalReferenceException(org.jboss.pnc.bpm.MissingInternalReferenceException) BuildRecordPushResult(org.jboss.pnc.model.BuildRecordPushResult) InvalidReferenceException(org.jboss.pnc.bpm.InvalidReferenceException)

Example 2 with BuildRecordPushResult

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);
}
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 3 with BuildRecordPushResult

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);
}
Also used : BuildRecordPushResult(org.jboss.pnc.model.BuildRecordPushResult) BuildRecordPushResult(org.jboss.pnc.model.BuildRecordPushResult) Result(org.jboss.pnc.spi.coordinator.Result)

Example 4 with BuildRecordPushResult

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;
}
Also used : Base32LongID(org.jboss.pnc.model.Base32LongID) BuildPushResult(org.jboss.pnc.dto.BuildPushResult) BuildRecordPushResult(org.jboss.pnc.model.BuildRecordPushResult)

Aggregations

BuildRecordPushResult (org.jboss.pnc.model.BuildRecordPushResult)4 Base32LongID (org.jboss.pnc.model.Base32LongID)2 InvalidReferenceException (org.jboss.pnc.bpm.InvalidReferenceException)1 MissingInternalReferenceException (org.jboss.pnc.bpm.MissingInternalReferenceException)1 BuildPushResult (org.jboss.pnc.dto.BuildPushResult)1 BuildPushStatus (org.jboss.pnc.enums.BuildPushStatus)1 BuildRecord (org.jboss.pnc.model.BuildRecord)1 Result (org.jboss.pnc.spi.coordinator.Result)1 ProcessManagerException (org.jboss.pnc.spi.exception.ProcessManagerException)1