Search in sources :

Example 1 with ProcessException

use of org.jboss.pnc.spi.coordinator.ProcessException in project pnc by project-ncl.

the class DefaultBuildExecutionSession method getBuildResult.

private BuildResult getBuildResult() {
    EnvironmentDriverResult environmentDriverResult = null;
    DebugData debugData = getRunningEnvironment() != null ? getRunningEnvironment().getDebugData() : null;
    if (debugData != null && debugData.isDebugEnabled()) {
        environmentDriverResult = new EnvironmentDriverResult(CompletionStatus.SUCCESS, "", Optional.of(debugData.getSshCredentials()));
    }
    CompletionStatus completionStatus = CompletionStatus.SUCCESS;
    if (executorException == null) {
        if (failedReasonStatus != null) {
            switch(failedReasonStatus) {
                case BUILD_ENV_SETUP_COMPLETE_WITH_ERROR:
                case SYSTEM_ERROR:
                    completionStatus = CompletionStatus.SYSTEM_ERROR;
                    break;
                case COLLECTING_RESULTS_FROM_REPOSITORY_MANAGER_COMPLETED_WITH_ERROR:
                case BUILD_COMPLETED_WITH_ERROR:
                    completionStatus = CompletionStatus.FAILED;
                    break;
                case CANCELLED:
                    completionStatus = CompletionStatus.CANCELLED;
                    break;
                case DONE_WITH_ERRORS:
                    executorException = new ExecutorException("DONE_WITH_ERRORS cannot be set as failed reason.");
                    break;
            }
        }
    }
    ProcessException processException = null;
    if (executorException != null) {
        processException = new ProcessException(executorException);
        completionStatus = CompletionStatus.SYSTEM_ERROR;
    }
    log.debug("Returning result of task {}.", getId());
    return new BuildResult(completionStatus, Optional.ofNullable(processException), "", Optional.ofNullable(buildExecutionConfiguration), Optional.ofNullable(buildDriverResult), Optional.ofNullable(repositoryManagerResult), Optional.ofNullable(environmentDriverResult), Optional.empty());
}
Also used : ProcessException(org.jboss.pnc.spi.coordinator.ProcessException) BuildResult(org.jboss.pnc.spi.BuildResult) ExecutorException(org.jboss.pnc.spi.executor.exceptions.ExecutorException) DebugData(org.jboss.pnc.spi.builddriver.DebugData) EnvironmentDriverResult(org.jboss.pnc.spi.environment.EnvironmentDriverResult) CompletionStatus(org.jboss.pnc.spi.coordinator.CompletionStatus)

Example 2 with ProcessException

use of org.jboss.pnc.spi.coordinator.ProcessException in project pnc by project-ncl.

the class BuildResultMapper method toDTO.

public BuildResultRest toDTO(BuildResult buildResult) {
    CompletionStatus completionStatus = buildResult.getCompletionStatus();
    ProcessException processException = buildResult.getProcessException().orElse(null);
    String processLog = buildResult.getProcessLog();
    BuildExecutionConfigurationRest buildExecutionConfiguration;
    if (buildResult.getBuildExecutionConfiguration().isPresent()) {
        BuildExecutionConfiguration bec = buildResult.getBuildExecutionConfiguration().get();
        buildExecutionConfiguration = new BuildExecutionConfigurationRest(bec);
    } else {
        buildExecutionConfiguration = null;
    }
    BuildDriverResultRest buildDriverResult;
    if (buildResult.getBuildDriverResult().isPresent()) {
        BuildDriverResult result = buildResult.getBuildDriverResult().get();
        buildDriverResult = new BuildDriverResultRest(result);
    } else {
        buildDriverResult = null;
    }
    RepositoryManagerResultRest repositoryManagerResult;
    if (buildResult.getRepositoryManagerResult().isPresent()) {
        RepositoryManagerResult result = buildResult.getRepositoryManagerResult().get();
        repositoryManagerResult = repositoryManagerResultMapper.toDTO(result);
    } else {
        repositoryManagerResult = null;
    }
    EnvironmentDriverResult environmentDriverResult;
    if (buildResult.getEnvironmentDriverResult().isPresent()) {
        environmentDriverResult = buildResult.getEnvironmentDriverResult().get();
    } else {
        environmentDriverResult = null;
    }
    RepourResult repourResult = buildResult.getRepourResult().orElse(null);
    return new BuildResultRest(completionStatus, processException, processLog, buildExecutionConfiguration, buildDriverResult, repositoryManagerResult, environmentDriverResult, repourResult);
}
Also used : BuildResultRest(org.jboss.pnc.bpm.model.BuildResultRest) ProcessException(org.jboss.pnc.spi.coordinator.ProcessException) BuildExecutionConfiguration(org.jboss.pnc.spi.executor.BuildExecutionConfiguration) BuildDriverResult(org.jboss.pnc.spi.builddriver.BuildDriverResult) RepositoryManagerResultRest(org.jboss.pnc.bpm.model.RepositoryManagerResultRest) EnvironmentDriverResult(org.jboss.pnc.spi.environment.EnvironmentDriverResult) CompletionStatus(org.jboss.pnc.spi.coordinator.CompletionStatus) RepositoryManagerResult(org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult) BuildExecutionConfigurationRest(org.jboss.pnc.bpm.model.BuildExecutionConfigurationRest) RepourResult(org.jboss.pnc.spi.repour.RepourResult) BuildDriverResultRest(org.jboss.pnc.bpm.model.BuildDriverResultRest)

Example 3 with ProcessException

use of org.jboss.pnc.spi.coordinator.ProcessException 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 4 with ProcessException

use of org.jboss.pnc.spi.coordinator.ProcessException 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 5 with ProcessException

use of org.jboss.pnc.spi.coordinator.ProcessException in project pnc by project-ncl.

the class BuildResultMock method mock.

public static BuildResult mock(BuildStatus status) {
    BuildExecutionConfiguration buildExecutionConfig = BuildExecutionConfigurationMock.mockConfig();
    BuildDriverResult buildDriverResult = BuildDriverResultMock.mockResult(status);
    RepositoryManagerResult repositoryManagerResult = RepositoryManagerResultMock.mockResult();
    ExecutorException exception = buildException();
    CompletionStatus completionStatus;
    if (status.completedSuccessfully()) {
        completionStatus = CompletionStatus.SUCCESS;
    } else {
        completionStatus = CompletionStatus.FAILED;
    }
    return new BuildResult(completionStatus, Optional.of(new ProcessException("Test Exception.")), "", Optional.ofNullable(buildExecutionConfig), Optional.ofNullable(buildDriverResult), Optional.ofNullable(repositoryManagerResult), Optional.of(EnvironmentDriverResultMock.mock()), Optional.of(RepourResultMock.mock()));
}
Also used : BuildResult(org.jboss.pnc.spi.BuildResult) ProcessException(org.jboss.pnc.spi.coordinator.ProcessException) ExecutorException(org.jboss.pnc.spi.executor.exceptions.ExecutorException) BuildExecutionConfiguration(org.jboss.pnc.spi.executor.BuildExecutionConfiguration) BuildDriverResult(org.jboss.pnc.spi.builddriver.BuildDriverResult) RepositoryManagerResult(org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult) CompletionStatus(org.jboss.pnc.spi.coordinator.CompletionStatus)

Aggregations

ProcessException (org.jboss.pnc.spi.coordinator.ProcessException)7 CompletionStatus (org.jboss.pnc.spi.coordinator.CompletionStatus)5 BuildRecord (org.jboss.pnc.model.BuildRecord)3 BuildResult (org.jboss.pnc.spi.BuildResult)3 EnvironmentDriverResult (org.jboss.pnc.spi.environment.EnvironmentDriverResult)3 ExecutorException (org.jboss.pnc.spi.executor.exceptions.ExecutorException)3 BuildPushResult (org.jboss.pnc.dto.BuildPushResult)2 AlreadyRunningException (org.jboss.pnc.facade.validation.AlreadyRunningException)2 OperationNotAllowedException (org.jboss.pnc.facade.validation.OperationNotAllowedException)2 BuildDriverResult (org.jboss.pnc.spi.builddriver.BuildDriverResult)2 DebugData (org.jboss.pnc.spi.builddriver.DebugData)2 BuildExecutionConfiguration (org.jboss.pnc.spi.executor.BuildExecutionConfiguration)2 RepositoryManagerResult (org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult)2 RepourResult (org.jboss.pnc.spi.repour.RepourResult)2 HashSet (java.util.HashSet)1 BuildPushOperation (org.jboss.pnc.bpm.causeway.BuildPushOperation)1 Result (org.jboss.pnc.bpm.causeway.Result)1 BuildDriverResultRest (org.jboss.pnc.bpm.model.BuildDriverResultRest)1 BuildExecutionConfigurationRest (org.jboss.pnc.bpm.model.BuildExecutionConfigurationRest)1 BuildResultRest (org.jboss.pnc.bpm.model.BuildResultRest)1