Search in sources :

Example 91 with BuildRecord

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

the class BrewPusherImpl method pushBuild.

@Override
public BuildPushResult pushBuild(String buildId, BuildPushParameters buildPushParameters) throws ProcessException {
    Base32LongID id = BuildMapper.idMapper.toEntity(buildId);
    BuildRecord build = buildRecordRepository.queryById(BuildMapper.idMapper.toEntity(buildId));
    if (build.getStatus().equals(BuildStatus.NO_REBUILD_REQUIRED)) {
        throw new OperationNotAllowedException("Build has NO_REBUILD_REQUIRED status, push last successful build or use force-rebuild.");
    }
    Long buildPushResultId = Sequence.nextId();
    MDCUtils.addProcessContext(buildPushResultId.toString());
    MDCUtils.addCustomContext(BUILD_ID_KEY, id.getId());
    try {
        return doPushBuild(id, buildPushParameters, buildPushResultId);
    } finally {
        MDCUtils.removeProcessContext();
        MDCUtils.removeCustomContext(BUILD_ID_KEY);
    }
}
Also used : Base32LongID(org.jboss.pnc.model.Base32LongID) OperationNotAllowedException(org.jboss.pnc.facade.validation.OperationNotAllowedException) BuildRecord(org.jboss.pnc.model.BuildRecord)

Example 92 with BuildRecord

use of org.jboss.pnc.model.BuildRecord 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

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