Search in sources :

Example 6 with ProcessException

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

the class BuildExecutionSessionMock 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 COLLECTING_RESULTS_FROM_REPOSITORY_MANAGER_COMPLETED_WITH_ERROR:
                case SYSTEM_ERROR:
                    completionStatus = CompletionStatus.SYSTEM_ERROR;
                    break;
                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 7 with ProcessException

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

the class DefaultBuildCoordinator method completeBuild.

public void completeBuild(BuildTask buildTask, BuildResult buildResult) {
    String buildTaskId = buildTask.getId();
    BuildCoordinationStatus coordinationStatus = BuildCoordinationStatus.SYSTEM_ERROR;
    try {
        if (buildResult.hasFailed()) {
            CompletionStatus operationCompletionStatus = buildResult.getCompletionStatus();
            switch(operationCompletionStatus) {
                case SYSTEM_ERROR:
                    ProcessException exception;
                    if (buildResult.getProcessException().isPresent()) {
                        exception = buildResult.getProcessException().get();
                        log.debug("[buildTaskId: {}] Storing build result with exception {}.", buildTaskId, exception.getMessage());
                    } else if (buildResult.getRepourResult().isPresent()) {
                        RepourResult repourResult = buildResult.getRepourResult().get();
                        if (repourResult.getCompletionStatus().isFailed()) {
                            exception = new ProcessException("Repour completed with system error.");
                            log.debug("[buildTaskId: {}] Storing build result with system error from repour: {}.", buildTaskId, repourResult.getLog());
                        } else {
                            exception = new ProcessException("Build completed with system error but no exception.");
                            log.error("[buildTaskId: {}] Storing build result with system_error and missing exception.", buildTaskId);
                        }
                    } else {
                        exception = new ProcessException("Build completed with system error but no exception and no Repour result.");
                        log.error("[buildTaskId: {}] Storing build result with system_error no exception and no Repour result.", buildTaskId);
                    }
                    datastoreAdapter.storeResult(buildTask, Optional.of(buildResult), exception);
                    coordinationStatus = BuildCoordinationStatus.SYSTEM_ERROR;
                    break;
                case CANCELLED:
                case TIMED_OUT:
                    log.debug("[buildTaskId: {}] Storing failed build result. FailedReasonStatus: {}", buildTaskId, operationCompletionStatus);
                    datastoreAdapter.storeResult(buildTask, buildResult);
                    coordinationStatus = BuildCoordinationStatus.CANCELLED;
                    break;
                case FAILED:
                    log.debug("[buildTaskId: {}] Storing failed build result. FailedReasonStatus: {}", buildTaskId, operationCompletionStatus);
                    datastoreAdapter.storeResult(buildTask, buildResult);
                    coordinationStatus = BuildCoordinationStatus.DONE_WITH_ERRORS;
                    break;
                case SUCCESS:
                    throw new BuildCoordinationException("Failed task with SUCCESS completion status ?!.");
            }
        } else {
            log.debug("[buildTaskId: {}] Storing success build result.", buildTaskId);
            BuildRecord buildRecord = datastoreAdapter.storeResult(buildTask, buildResult);
            if (buildRecord.getStatus().completedSuccessfully()) {
                coordinationStatus = BuildCoordinationStatus.DONE;
            } else {
                log.warn("[buildTaskId: {}] Something went wrong while storing the success result. The status has changed to {}.", buildTaskId, buildRecord.getStatus());
                coordinationStatus = BuildCoordinationStatus.SYSTEM_ERROR;
            }
        }
        updateBuildTaskStatus(buildTask, coordinationStatus);
    } catch (Throwable e) {
        log.error("[buildTaskId: " + buildTaskId + "] Cannot store results to datastore.", e);
        updateBuildTaskStatus(buildTask, BuildCoordinationStatus.SYSTEM_ERROR);
    } finally {
        // Starts when the build execution completes
        ProcessStageUtils.logProcessStageEnd("FINALIZING_BUILD", "Finalizing completed.");
    }
}
Also used : BuildCoordinationStatus(org.jboss.pnc.enums.BuildCoordinationStatus) ProcessException(org.jboss.pnc.spi.coordinator.ProcessException) CompletionStatus(org.jboss.pnc.spi.coordinator.CompletionStatus) RepourResult(org.jboss.pnc.spi.repour.RepourResult) BuildCoordinationException(org.jboss.pnc.coordinator.BuildCoordinationException) BuildRecord(org.jboss.pnc.model.BuildRecord)

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