use of org.jboss.pnc.enums.BuildCoordinationStatus 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.enums.BuildCoordinationStatus 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.");
}
}
use of org.jboss.pnc.enums.BuildCoordinationStatus in project pnc by project-ncl.
the class DefaultBuildCoordinator method updateBuildTaskStatus.
private void updateBuildTaskStatus(BuildTask task, BuildCoordinationStatus status, String statusDescription) {
BuildCoordinationStatus oldStatus = task.getStatus();
// REJECTED_ALREADY_BUILT -> DONE
if (status.isCompleted() && !oldStatus.isCompleted()) {
markFinished(task, status, statusDescription);
} else {
task.setStatus(status);
task.setStatusDescription(statusDescription);
}
Build build = buildMapper.fromBuildTask(task);
BuildStatusChangedEvent buildStatusChanged = new DefaultBuildStatusChangedEvent(build, BuildStatus.fromBuildCoordinationStatus(oldStatus), BuildStatus.fromBuildCoordinationStatus(status));
log.debug("Updated build task {} status to {}; old coord status: {}, new coord status: {}", task.getId(), buildStatusChanged, oldStatus, status);
userLog.info("Build status updated to {}; previous: {}", status, oldStatus);
BuildStatus oldBuildStatus = BuildStatus.fromBuildCoordinationStatus(oldStatus);
BuildStatus newBuildStatus = BuildStatus.fromBuildCoordinationStatus(status);
if ((oldBuildStatus != newBuildStatus) && !(oldBuildStatus.isFinal() && newBuildStatus.isFinal())) {
// only fire notification when BuildStatus changes
// and avoid firing the notification when old and new statuses are final (NCL-5885)
buildStatusChangedEventNotifier.fire(buildStatusChanged);
log.debug("Fired buildStatusChangedEventNotifier after task {} status update to {}.", task.getId(), status);
}
}
Aggregations