use of org.jboss.pnc.executor.exceptions.BuildProcessException in project pnc by project-ncl.
the class DefaultBuildExecutor method stopRunningEnvironment.
/**
* Tries to stop running environment if the exception contains information about running environment
*
* @param ex Exception in build process (To stop the environment it has to be instance of BuildProcessException)
*/
private void stopRunningEnvironment(Throwable ex) {
DestroyableEnvironment destroyableEnvironment = null;
if (ex instanceof BuildProcessException) {
BuildProcessException bpEx = (BuildProcessException) ex;
destroyableEnvironment = bpEx.getDestroyableEnvironment();
} else if (ex.getCause() instanceof BuildProcessException) {
BuildProcessException bpEx = (BuildProcessException) ex.getCause();
destroyableEnvironment = bpEx.getDestroyableEnvironment();
} else {
// It shouldn't never happen - Throwable should be caught in all steps of build chain
// and BuildProcessException should be thrown instead of that
log.warn("Possible leak of a running environment! Build process ended with exception, " + "but the exception didn't contain information about running environment.", ex);
}
try {
if (destroyableEnvironment != null) {
destroyableEnvironment.destroyEnvironment();
}
} catch (Throwable envE) {
log.warn("Running environment" + destroyableEnvironment + " couldn't be destroyed!", envE);
}
}
use of org.jboss.pnc.executor.exceptions.BuildProcessException in project pnc by project-ncl.
the class DefaultBuildExecutor method runTheBuild.
private CompletableFuture<CompletedBuild> runTheBuild(DefaultBuildExecutionSession buildExecutionSession) {
CompletableFuture<CompletedBuild> waitToCompleteFuture = new CompletableFuture<>();
if (buildExecutionSession.isCanceled()) {
waitToCompleteFuture.complete(null);
return waitToCompleteFuture;
}
ProcessStageUtils.logProcessStageBegin(BuildExecutionStatus.BUILD_SETTING_UP.toString(), "Running the build ...");
buildExecutionSession.setStatus(BuildExecutionStatus.BUILD_SETTING_UP);
RunningEnvironment runningEnvironment = buildExecutionSession.getRunningEnvironment();
try {
Consumer<CompletedBuild> onComplete = value -> {
ProcessStageUtils.logProcessStageEnd(BuildExecutionStatus.BUILD_SETTING_UP.toString(), "Build completed.");
waitToCompleteFuture.complete(value);
};
Consumer<Throwable> onError = (e) -> {
ProcessStageUtils.logProcessStageEnd(BuildExecutionStatus.BUILD_SETTING_UP.toString(), "Build failed.");
waitToCompleteFuture.completeExceptionally(new BuildProcessException(e, runningEnvironment));
};
String buildAgentUrl = runningEnvironment.getBuildAgentUrl();
String liveLogWebSocketUrl = "ws" + StringUtils.addEndingSlash(buildAgentUrl).replaceAll("http(s?):", ":") + "socket/text/ro";
log.debug("Setting live log websocket url: {}", liveLogWebSocketUrl);
buildExecutionSession.setLiveLogsUri(Optional.of(new URI(liveLogWebSocketUrl)));
BuildDriver buildDriver = buildDriverFactory.getBuildDriver();
RunningBuild runningBuild = buildDriver.startProjectBuild(buildExecutionSession, runningEnvironment, onComplete, onError);
buildExecutionSession.setCancelHook(runningBuild::cancel);
buildExecutionSession.setStatus(BuildExecutionStatus.BUILD_WAITING);
} catch (Throwable e) {
throw new BuildProcessException(e, runningEnvironment);
}
return waitToCompleteFuture;
}
use of org.jboss.pnc.executor.exceptions.BuildProcessException in project pnc by project-ncl.
the class DefaultBuildExecutor method retrieveBuildDriverResults.
private Void retrieveBuildDriverResults(BuildExecutionSession buildExecutionSession, CompletedBuild completedBuild) {
if (completedBuild == null) {
userLog.warn("Unable to retrieve build driver results. Most likely due to cancelled operation.");
return null;
}
try {
buildExecutionSession.setStatus(BuildExecutionStatus.COLLECTING_RESULTS_FROM_BUILD_DRIVER);
BuildDriverResult buildResult = completedBuild.getBuildResult();
BuildStatus buildStatus = buildResult.getBuildStatus();
buildExecutionSession.setBuildDriverResult(buildResult);
if (buildStatus.completedSuccessfully()) {
userLog.info("Build successfully completed.");
buildExecutionSession.setStatus(BuildExecutionStatus.BUILD_COMPLETED_SUCCESS);
} else if (buildStatus.equals(BuildStatus.CANCELLED)) {
userLog.info("Build has been canceled.");
buildExecutionSession.setStatus(BuildExecutionStatus.CANCELLED);
} else {
userLog.warn("Build completed with errors.");
buildExecutionSession.setStatus(BuildExecutionStatus.BUILD_COMPLETED_WITH_ERROR);
}
return null;
} catch (Throwable e) {
throw new BuildProcessException(e, completedBuild.getRunningEnvironment());
}
}
use of org.jboss.pnc.executor.exceptions.BuildProcessException in project pnc by project-ncl.
the class DefaultBuildExecutor method configureRepository.
private RepositorySession configureRepository(DefaultBuildExecutionSession buildExecutionSession) {
if (buildExecutionSession.isCanceled()) {
return null;
}
ProcessStageUtils.logProcessStageBegin(BuildExecutionStatus.REPO_SETTING_UP.toString(), "Setting up repository...");
buildExecutionSession.setStatus(BuildExecutionStatus.REPO_SETTING_UP);
BuildType buildType = buildExecutionSession.getBuildExecutionConfiguration().getBuildType();
if (buildType == null) {
throw new BuildProcessException("Missing required value buildExecutionConfiguration.buildType");
}
RepositoryType repositoryType = BuildTypeToRepositoryType.getRepositoryType(buildType);
try {
RepositoryManager repositoryManager = repositoryManagerFactory.getRepositoryManager(repositoryType);
BuildExecution buildExecution = buildExecutionSession.getBuildExecutionConfiguration();
String serviceAccountToken = (serviceClient == null ? null : serviceClient.getAuthToken());
RepositorySession buildRepository = repositoryManager.createBuildRepositoryWithRetries(buildExecution, buildExecutionSession.getAccessToken(), serviceAccountToken, repositoryType, buildExecutionSession.getBuildExecutionConfiguration().getGenericParameters(), buildExecutionSession.getBuildExecutionConfiguration().isBrewPullActive());
return buildRepository;
} catch (Throwable e) {
throw new BuildProcessException(e);
} finally {
ProcessStageUtils.logProcessStageEnd(BuildExecutionStatus.REPO_SETTING_UP.toString(), "Repository setup complete.");
}
}
use of org.jboss.pnc.executor.exceptions.BuildProcessException in project pnc by project-ncl.
the class DefaultBuildExecutor method completeExecution.
private Void completeExecution(DefaultBuildExecutionSession buildExecutionSession, Throwable e) {
String buildExecutionId = buildExecutionSession.getId();
try {
// Ends when the result is stored by the Orchestrator
ProcessStageUtils.logProcessStageBegin("FINALIZING_BUILD", "Finalizing build ...");
if (e != null) {
log.debug("Finalizing FAILED execution. Exception: ", e);
} else {
log.debug("Finalizing SUCCESS execution.");
}
buildExecutionSession.setStatus(BuildExecutionStatus.FINALIZING_EXECUTION);
if (buildExecutionSession.getStartTime() == null) {
buildExecutionSession.setException(new ExecutorException("Missing start time."));
}
if (e != null) {
stopRunningEnvironment(e);
} else {
try {
destroyEnvironment(buildExecutionSession);
} catch (BuildProcessException destroyException) {
e = destroyException;
}
}
if (e != null) {
buildExecutionSession.setException(new ExecutorException(e));
}
if (buildExecutionSession.getEndTime() != null) {
buildExecutionSession.setException(new ExecutorException("End time already set."));
} else {
buildExecutionSession.setEndTime(new Date());
}
// check if any of previous statuses indicated "failed" state
if (buildExecutionSession.isCanceled()) {
buildExecutionSession.setStatus(BuildExecutionStatus.CANCELLED);
userLog.info("Build execution completed (canceled).");
} else if (buildExecutionSession.hasFailed()) {
buildExecutionSession.setStatus(BuildExecutionStatus.DONE_WITH_ERRORS);
userLog.warn("Build execution completed with errors.");
} else {
buildExecutionSession.setStatus(BuildExecutionStatus.DONE);
userLog.info("Build execution completed successfully.");
}
log.debug("Removing buildExecutionTask [" + buildExecutionId + "] from list of running tasks.");
runningExecutions.remove(buildExecutionId);
userLog.info("Build execution completed.");
} catch (Throwable t) {
userLog.error("Unable to complete execution!", t);
String executorException = "Unable to recover, see system log for the details.";
if (t.getMessage() != null) {
executorException += " " + t.getMessage();
}
buildExecutionSession.setException(new ExecutorException(executorException));
buildExecutionSession.setEndTime(new Date());
buildExecutionSession.setStatus(BuildExecutionStatus.SYSTEM_ERROR);
runningExecutions.remove(buildExecutionId);
} finally {
RunningEnvironment runningEnvironment = buildExecutionSession.getRunningEnvironment();
if (runningEnvironment == null) {
log.warn("Could not close Maven repository session [" + buildExecutionId + "]. Running environment was not set!");
} else {
RepositorySession repositorySession = runningEnvironment.getRepositorySession();
if (repositorySession == null) {
log.warn("Could not close Maven repository session [" + buildExecutionId + "]. Repository session was not set!");
} else {
log.debug("Closing Maven repository session [" + buildExecutionId + "].");
repositorySession.close();
}
}
}
return null;
}
Aggregations