Search in sources :

Example 1 with BuildCoordinationException

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

the class DefaultBuildCoordinator method completeNoBuild.

public void completeNoBuild(BuildTask buildTask, CompletionStatus completionStatus) {
    String buildTaskId = buildTask.getId();
    BuildCoordinationStatus coordinationStatus = BuildCoordinationStatus.SYSTEM_ERROR;
    try {
        if (CompletionStatus.NO_REBUILD_REQUIRED.equals(completionStatus)) {
            updateBuildTaskStatus(buildTask, BuildCoordinationStatus.REJECTED_ALREADY_BUILT);
        // TODO cancel should be here enable in 2.0 as CANCELed is not failed build
        // } else if (CompletionStatus.CANCELLED.equals(completionStatus)) {
        // updateBuildTaskStatus(buildTask, BuildCoordinationStatus.CANCELLED);
        } else {
            throw new BuildCoordinationException(String.format("Invalid status %s.", completionStatus));
        }
        log.debug("Storing no build required result. Id: {}", buildTaskId);
        BuildRecord buildRecord = datastoreAdapter.storeRecordForNoRebuild(buildTask);
        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;
        }
    } catch (Throwable e) {
        log.error("[buildTaskId: " + buildTaskId + "] Cannot store results to datastore.", e);
        coordinationStatus = BuildCoordinationStatus.SYSTEM_ERROR;
    } finally {
        updateBuildTaskStatus(buildTask, coordinationStatus);
    }
}
Also used : BuildCoordinationStatus(org.jboss.pnc.enums.BuildCoordinationStatus) BuildCoordinationException(org.jboss.pnc.coordinator.BuildCoordinationException) BuildRecord(org.jboss.pnc.model.BuildRecord)

Example 2 with BuildCoordinationException

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

the class DatastoreAdapter method storeResult.

public BuildRecord storeResult(BuildTask buildTask, BuildResult buildResult) throws DatastoreException {
    try {
        BuildStatus buildRecordStatus = NEW;
        BuildRecord.Builder buildRecordBuilder = initBuildRecordBuilder(buildTask);
        buildRecordBuilder.buildContentId(buildTask.getContentId());
        if (buildResult.getRepourResult().isPresent()) {
            RepourResult repourResult = buildResult.getRepourResult().get();
            buildRecordBuilder.repourLog(repourResult.getLog());
            buildRecordBuilder.executionRootName(repourResult.getExecutionRootName());
            buildRecordBuilder.executionRootVersion(repourResult.getExecutionRootVersion());
            CompletionStatus repourCompletionStatus = repourResult.getCompletionStatus();
            if (repourCompletionStatus != null) {
                switch(repourCompletionStatus) {
                    case SUCCESS:
                    case NO_REBUILD_REQUIRED:
                        break;
                    case FAILED:
                        buildRecordBuilder.appendLog("\nBuild failed during the alignment phase, please check the 'Alignment Log' tab for more information.\n");
                        buildRecordStatus = FAILED;
                        break;
                    case CANCELLED:
                        buildRecordBuilder.appendLog("\nBuild cancelled during alignment phase.\n");
                        buildRecordStatus = CANCELLED;
                        break;
                    case TIMED_OUT:
                        buildRecordBuilder.appendLog("\nBuild timed-out during alignment phase.\n");
                        buildRecordStatus = SYSTEM_ERROR;
                        break;
                    case SYSTEM_ERROR:
                        buildRecordBuilder.appendLog("\nBuild failed with SYSTEM_ERROR during the alignment phase, " + "please check the 'Alignment Log' tab for more information.\n");
                        buildRecordStatus = SYSTEM_ERROR;
                        break;
                    default:
                        buildRecordBuilder.appendLog("\nInvalid status during the alignment phase, failing with SYSTEM_ERROR.\n");
                        buildRecordStatus = SYSTEM_ERROR;
                        break;
                }
            }
        } else {
            userLog.warn("Missing Repour Result!");
            log.warn("[BuildTask:" + buildTask.getId() + "] Missing RepourResult.");
        }
        if (buildResult.getBuildDriverResult().isPresent()) {
            BuildDriverResult buildDriverResult = buildResult.getBuildDriverResult().get();
            buildRecordBuilder.appendLog(buildDriverResult.getBuildLog());
            buildDriverResult.getOutputChecksum().ifPresent(buildRecordBuilder::buildOutputChecksum);
            // TODO buildRecord should use CompletionStatus
            buildRecordStatus = buildDriverResult.getBuildStatus();
        } else if (!buildResult.hasFailed()) {
            return storeResult(buildTask, Optional.of(buildResult), new BuildCoordinationException("Trying to store success build with incomplete result. Missing BuildDriverResult."));
        }
        if (buildResult.getEnvironmentDriverResult().isPresent()) {
            EnvironmentDriverResult environmentDriverResult = buildResult.getEnvironmentDriverResult().get();
            buildRecordBuilder.appendLog(environmentDriverResult.getLog());
            environmentDriverResult.getSshCredentials().ifPresent(c -> {
                buildRecordBuilder.sshCommand(c.getCommand());
                buildRecordBuilder.sshPassword(c.getPassword());
            });
            if (environmentDriverResult.getCompletionStatus() != null) {
                switch(environmentDriverResult.getCompletionStatus()) {
                    case SUCCESS:
                    case NO_REBUILD_REQUIRED:
                        break;
                    case FAILED:
                        buildRecordStatus = FAILED;
                        break;
                    case CANCELLED:
                        buildRecordStatus = CANCELLED;
                        break;
                    case TIMED_OUT:
                    case SYSTEM_ERROR:
                        buildRecordStatus = SYSTEM_ERROR;
                        break;
                    default:
                        buildRecordBuilder.appendLog("\nInvalid status during the environment setup phase, failing with SYSTEM_ERROR.\n");
                        buildRecordStatus = SYSTEM_ERROR;
                        break;
                }
            }
        }
        List<Artifact> builtArtifacts = Collections.emptyList();
        List<Artifact> dependencies = Collections.emptyList();
        if (buildResult.getRepositoryManagerResult().isPresent()) {
            RepositoryManagerResult repositoryManagerResult = buildResult.getRepositoryManagerResult().get();
            buildRecordBuilder.appendLog(repositoryManagerResult.getLog());
            if (repositoryManagerResult.getCompletionStatus() != null) {
                switch(// TODO, do not mix statuses
                repositoryManagerResult.getCompletionStatus()) {
                    case SUCCESS:
                    case NO_REBUILD_REQUIRED:
                        break;
                    case FAILED:
                        buildRecordStatus = FAILED;
                        break;
                    case CANCELLED:
                        buildRecordStatus = CANCELLED;
                        break;
                    case TIMED_OUT:
                    case SYSTEM_ERROR:
                        buildRecordStatus = SYSTEM_ERROR;
                        break;
                    default:
                        buildRecordBuilder.appendLog("\nInvalid status during the promotion phase, failing with SYSTEM_ERROR.\n");
                        buildRecordStatus = SYSTEM_ERROR;
                        break;
                }
            }
            builtArtifacts = repositoryManagerResult.getBuiltArtifacts();
            Map<Artifact, String> builtConflicts = datastore.checkForBuiltArtifacts(builtArtifacts);
            if (builtConflicts.size() > 0) {
                return storeResult(buildTask, Optional.of(buildResult), new BuildCoordinationException("Trying to store success build with invalid repository manager result. Conflicting artifact data found: " + builtConflicts.toString()));
            }
            dependencies = repositoryManagerResult.getDependencies();
        } else if (!buildResult.hasFailed()) {
            return storeResult(buildTask, Optional.of(buildResult), new BuildCoordinationException("Trying to store success build with incomplete result. Missing RepositoryManagerResult."));
        }
        if (NEW.equals(buildRecordStatus)) {
            switch(buildResult.getCompletionStatus()) {
                case SUCCESS:
                case NO_REBUILD_REQUIRED:
                case FAILED:
                case SYSTEM_ERROR:
                    break;
                case CANCELLED:
                    buildRecordStatus = CANCELLED;
                    break;
                case TIMED_OUT:
                    buildRecordStatus = SYSTEM_ERROR;
                    buildRecordBuilder.appendLog("-- Operation TIMED-OUT --");
                    userLog.warn("Operation TIMED-OUT.");
                    break;
                default:
                    buildRecordBuilder.appendLog("\nInvalid status detected in the final completion status, failing with SYSTEM_ERROR.\n");
                    break;
            }
        }
        log.debug("Setting status " + buildRecordStatus.toString() + " to buildRecord.");
        buildRecordBuilder.status(buildRecordStatus);
        if (buildResult.getBuildExecutionConfiguration().isPresent()) {
            BuildExecutionConfiguration buildExecutionConfig = buildResult.getBuildExecutionConfiguration().get();
            buildRecordBuilder.scmRepoURL(buildExecutionConfig.getScmRepoURL());
            buildRecordBuilder.scmRevision(buildExecutionConfig.getScmRevision());
            buildRecordBuilder.scmTag(buildExecutionConfig.getScmTag());
        } else if (!buildResult.hasFailed()) {
            return storeResult(buildTask, Optional.of(buildResult), new BuildCoordinationException("Trying to store success build with incomplete result. Missing BuildExecutionConfiguration."));
        }
        log.debug("Storing results of buildTask [{}] to datastore.", buildTask.getId());
        userLog.info("Successfully completed.");
        return datastore.storeCompletedBuild(buildRecordBuilder, builtArtifacts, dependencies);
    } catch (Exception e) {
        return storeResult(buildTask, Optional.of(buildResult), e);
    }
}
Also used : BuildExecutionConfiguration(org.jboss.pnc.spi.executor.BuildExecutionConfiguration) BuildDriverResult(org.jboss.pnc.spi.builddriver.BuildDriverResult) RepositoryManagerResult(org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult) BuildRecord(org.jboss.pnc.model.BuildRecord) BuildCoordinationException(org.jboss.pnc.coordinator.BuildCoordinationException) Artifact(org.jboss.pnc.model.Artifact) BuildCoordinationException(org.jboss.pnc.coordinator.BuildCoordinationException) DatastoreException(org.jboss.pnc.spi.datastore.DatastoreException) EnvironmentDriverResult(org.jboss.pnc.spi.environment.EnvironmentDriverResult) CompletionStatus(org.jboss.pnc.spi.coordinator.CompletionStatus) BuildStatus(org.jboss.pnc.enums.BuildStatus) RepourResult(org.jboss.pnc.spi.repour.RepourResult)

Example 3 with BuildCoordinationException

use of org.jboss.pnc.coordinator.BuildCoordinationException 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

BuildCoordinationException (org.jboss.pnc.coordinator.BuildCoordinationException)3 BuildRecord (org.jboss.pnc.model.BuildRecord)3 BuildCoordinationStatus (org.jboss.pnc.enums.BuildCoordinationStatus)2 CompletionStatus (org.jboss.pnc.spi.coordinator.CompletionStatus)2 RepourResult (org.jboss.pnc.spi.repour.RepourResult)2 BuildStatus (org.jboss.pnc.enums.BuildStatus)1 Artifact (org.jboss.pnc.model.Artifact)1 BuildDriverResult (org.jboss.pnc.spi.builddriver.BuildDriverResult)1 ProcessException (org.jboss.pnc.spi.coordinator.ProcessException)1 DatastoreException (org.jboss.pnc.spi.datastore.DatastoreException)1 EnvironmentDriverResult (org.jboss.pnc.spi.environment.EnvironmentDriverResult)1 BuildExecutionConfiguration (org.jboss.pnc.spi.executor.BuildExecutionConfiguration)1 RepositoryManagerResult (org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult)1