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);
}
}
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);
}
}
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.");
}
}
Aggregations