Search in sources :

Example 1 with InconsistentDataException

use of org.jboss.pnc.spi.datastore.InconsistentDataException in project pnc by project-ncl.

the class BrewPusherImpl method pushGroup.

@Override
public Set<BuildPushResult> pushGroup(int buildGroupId, String tagPrefix) {
    BuildPushParameters buildPushParameters = BuildPushParameters.builder().tagPrefix(tagPrefix).reimport(false).build();
    List<BuildRecord> buildRecords = buildRecordRepository.queryWithPredicates(BuildRecordPredicates.withBuildConfigSetRecordId(buildGroupId));
    Set<BuildPushResult> results = new HashSet<>();
    for (BuildRecord buildRecord : buildRecords) {
        Long buildPushResultId = Sequence.nextId();
        MDCUtils.addProcessContext(buildPushResultId.toString());
        MDCUtils.addCustomContext(BUILD_ID_KEY, buildRecord.getId().getId());
        try {
            results.add(doPushBuild(buildRecord.getId(), buildPushParameters, buildPushResultId));
        } catch (OperationNotAllowedException | AlreadyRunningException e) {
            results.add(BuildPushResult.builder().status(BuildPushStatus.REJECTED).id(buildPushResultId.toString()).buildId(BuildMapper.idMapper.toDto(buildRecord.getId())).message(e.getMessage()).build());
        } catch (InconsistentDataException | ProcessException e) {
            results.add(BuildPushResult.builder().status(BuildPushStatus.SYSTEM_ERROR).id(buildPushResultId.toString()).buildId(BuildMapper.idMapper.toDto(buildRecord.getId())).message(e.getMessage()).build());
        } finally {
            MDCUtils.removeProcessContext();
            MDCUtils.removeCustomContext(BUILD_ID_KEY);
        }
    }
    return results;
}
Also used : BuildPushParameters(org.jboss.pnc.dto.requests.BuildPushParameters) BuildPushResult(org.jboss.pnc.dto.BuildPushResult) OperationNotAllowedException(org.jboss.pnc.facade.validation.OperationNotAllowedException) BuildRecord(org.jboss.pnc.model.BuildRecord) AlreadyRunningException(org.jboss.pnc.facade.validation.AlreadyRunningException) ProcessException(org.jboss.pnc.spi.coordinator.ProcessException) InconsistentDataException(org.jboss.pnc.spi.datastore.InconsistentDataException) HashSet(java.util.HashSet)

Example 2 with InconsistentDataException

use of org.jboss.pnc.spi.datastore.InconsistentDataException in project pnc by project-ncl.

the class BrewPusherImpl method getLatestSuccessfullyExecutedBuildRecord.

/**
 * @param buildRecordId
 * @return Latest build record with status success or null if the build record does not exist.
 * @throws InconsistentDataException when there is no SUCCESS status before NO_REBUILD_REQUIRED
 * @throws InvalidEntityException when the status is not SUCCESS or NO_REBUILD_REQUIRED
 */
private BuildRecord getLatestSuccessfullyExecutedBuildRecord(Base32LongID buildRecordId) {
    BuildRecord buildRecord = buildRecordRepository.findByIdFetchProperties(buildRecordId);
    if (buildRecord == null) {
        throw new EmptyEntityException("Build record not found.");
    }
    switch(buildRecord.getStatus()) {
        case SUCCESS:
            return buildRecord;
        case NO_REBUILD_REQUIRED:
            // if status is NO_REBUILD_REQUIRED, find the associated BuildRecord which was linked as the no rebuild
            // cause
            BuildRecord noRebuildCause = buildRecord.getNoRebuildCause();
            if (noRebuildCause != null) {
                return noRebuildCause;
            } else {
                String message = "There is no SUCCESS build before NO_REBUILD_REQUIRED.";
                log.error(message);
                throw new InconsistentDataException(message);
            }
        default:
            // Build status is not SUCCESS or NO_REBUILD_REQUIRED.
            throw new OperationNotAllowedException("Not allowed to push failed build.");
    }
}
Also used : EmptyEntityException(org.jboss.pnc.facade.validation.EmptyEntityException) InconsistentDataException(org.jboss.pnc.spi.datastore.InconsistentDataException) OperationNotAllowedException(org.jboss.pnc.facade.validation.OperationNotAllowedException) BuildRecord(org.jboss.pnc.model.BuildRecord)

Aggregations

OperationNotAllowedException (org.jboss.pnc.facade.validation.OperationNotAllowedException)2 BuildRecord (org.jboss.pnc.model.BuildRecord)2 InconsistentDataException (org.jboss.pnc.spi.datastore.InconsistentDataException)2 HashSet (java.util.HashSet)1 BuildPushResult (org.jboss.pnc.dto.BuildPushResult)1 BuildPushParameters (org.jboss.pnc.dto.requests.BuildPushParameters)1 AlreadyRunningException (org.jboss.pnc.facade.validation.AlreadyRunningException)1 EmptyEntityException (org.jboss.pnc.facade.validation.EmptyEntityException)1 ProcessException (org.jboss.pnc.spi.coordinator.ProcessException)1