Search in sources :

Example 1 with AlreadyRunningException

use of org.jboss.pnc.facade.validation.AlreadyRunningException in project pnc by project-ncl.

the class GroupConfigurationEndpointImpl method triggerBuild.

private GroupBuild triggerBuild(String groupConfigId, Optional<GroupBuildRequest> buildConfigRevisions, GroupBuildParameters buildParams) {
    try {
        BuildOptions buildOptions = toBuildOptions(buildParams);
        int groupBuildId = buildTriggerer.triggerGroupBuild(Integer.parseInt(groupConfigId), buildConfigRevisions, buildOptions);
        return groupBuildProvider.getSpecific(Integer.toString(groupBuildId));
    } catch (BuildConflictException ex) {
        throw new AlreadyRunningException(ex, ex.getBuildTaskId());
    } catch (CoreException ex) {
        throw new RuntimeException(ex);
    }
}
Also used : AlreadyRunningException(org.jboss.pnc.facade.validation.AlreadyRunningException) CoreException(org.jboss.pnc.spi.exception.CoreException) BuildOptions(org.jboss.pnc.spi.BuildOptions) BuildConflictException(org.jboss.pnc.spi.exception.BuildConflictException) GroupConfigurationEndpoint(org.jboss.pnc.rest.api.endpoints.GroupConfigurationEndpoint)

Example 2 with AlreadyRunningException

use of org.jboss.pnc.facade.validation.AlreadyRunningException in project pnc by project-ncl.

the class BrewPusherImpl method doPushBuild.

private BuildPushResult doPushBuild(Base32LongID buildId, BuildPushParameters buildPushParameters, Long buildPushResultId) throws ProcessException {
    // TODO START timing event
    userLog.info("Push started.");
    // collect and validate input data
    BuildRecord buildRecord = getLatestSuccessfullyExecutedBuildRecord(buildId);
    if (buildRecord.getExecutionRootName() == null && !buildRecord.getBuildConfigurationAudited().getGenericParameters().containsKey(BREW_BUILD_NAME.name())) {
        throw new InvalidEntityException("Build " + buildId + " cannot be pushed to brew, because it is missing " + Attributes.BUILD_BREW_NAME + " attribute with brew name.");
    }
    List<Artifact> artifacts = artifactRepository.queryWithPredicates(ArtifactPredicates.withBuildRecordId(buildRecord.getId()));
    if (hasBadArtifactQuality(artifacts)) {
        String message = "Build contains artifacts of insufficient quality: BLACKLISTED/DELETED.";
        log.debug(message);
        BuildPushResult pushResult = BuildPushResult.builder().buildId(BuildMapper.idMapper.toDto(buildId)).status(BuildPushStatus.REJECTED).id(buildPushResultId.toString()).logContext(buildPushResultId.toString()).message(message).build();
        throw new OperationNotAllowedException(message, pushResult);
    }
    log.debug("Pushing Build.id {}.", buildRecord.getId());
    BuildPushOperation buildPushOperation = new BuildPushOperation(buildRecord, buildPushResultId, buildPushParameters.getTagPrefix(), buildPushParameters.isReimport(), getCompleteCallbackUrlTemplate());
    Result pushResult = buildResultPushManager.push(buildPushOperation, userService.currentUserToken());
    log.info("Push Result {}.", pushResult);
    BuildPushResult result = BuildPushResult.builder().id(pushResult.getId()).buildId(pushResult.getBuildId()).status(pushResult.getStatus()).logContext(pushResult.getId()).message(pushResult.getMessage()).build();
    // verify operation status
    switch(pushResult.getStatus()) {
        case ACCEPTED:
            userLog.info("Push ACCEPTED.");
            return result;
        case REJECTED:
            userLog.warn("Push REJECTED.");
            throw new AlreadyRunningException(pushResult.getMessage(), result);
        case SYSTEM_ERROR:
            userLog.error("Brew push failed: " + pushResult.getMessage());
            throw new ProcessException(pushResult.getMessage());
        default:
            userLog.error("Invalid push result status.");
            throw new ProcessException("Invalid push result status.");
    }
}
Also used : AlreadyRunningException(org.jboss.pnc.facade.validation.AlreadyRunningException) ProcessException(org.jboss.pnc.spi.coordinator.ProcessException) BuildPushOperation(org.jboss.pnc.bpm.causeway.BuildPushOperation) BuildPushResult(org.jboss.pnc.dto.BuildPushResult) OperationNotAllowedException(org.jboss.pnc.facade.validation.OperationNotAllowedException) BuildRecord(org.jboss.pnc.model.BuildRecord) InvalidEntityException(org.jboss.pnc.facade.validation.InvalidEntityException) Artifact(org.jboss.pnc.model.Artifact) Result(org.jboss.pnc.bpm.causeway.Result) BuildPushResult(org.jboss.pnc.dto.BuildPushResult) BuildRecordPushResult(org.jboss.pnc.model.BuildRecordPushResult)

Example 3 with AlreadyRunningException

use of org.jboss.pnc.facade.validation.AlreadyRunningException 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)

Aggregations

AlreadyRunningException (org.jboss.pnc.facade.validation.AlreadyRunningException)3 BuildPushResult (org.jboss.pnc.dto.BuildPushResult)2 OperationNotAllowedException (org.jboss.pnc.facade.validation.OperationNotAllowedException)2 BuildRecord (org.jboss.pnc.model.BuildRecord)2 ProcessException (org.jboss.pnc.spi.coordinator.ProcessException)2 HashSet (java.util.HashSet)1 BuildPushOperation (org.jboss.pnc.bpm.causeway.BuildPushOperation)1 Result (org.jboss.pnc.bpm.causeway.Result)1 BuildPushParameters (org.jboss.pnc.dto.requests.BuildPushParameters)1 InvalidEntityException (org.jboss.pnc.facade.validation.InvalidEntityException)1 Artifact (org.jboss.pnc.model.Artifact)1 BuildRecordPushResult (org.jboss.pnc.model.BuildRecordPushResult)1 GroupConfigurationEndpoint (org.jboss.pnc.rest.api.endpoints.GroupConfigurationEndpoint)1 BuildOptions (org.jboss.pnc.spi.BuildOptions)1 InconsistentDataException (org.jboss.pnc.spi.datastore.InconsistentDataException)1 BuildConflictException (org.jboss.pnc.spi.exception.BuildConflictException)1 CoreException (org.jboss.pnc.spi.exception.CoreException)1