use of org.jboss.pnc.spi.executor.exceptions.ExecutorException in project pnc by project-ncl.
the class DefaultBuildExecutionSession 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 SYSTEM_ERROR:
completionStatus = CompletionStatus.SYSTEM_ERROR;
break;
case COLLECTING_RESULTS_FROM_REPOSITORY_MANAGER_COMPLETED_WITH_ERROR:
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());
}
use of org.jboss.pnc.spi.executor.exceptions.ExecutorException in project pnc by project-ncl.
the class DefaultBuildExecutor method startBuilding.
@Override
public BuildExecutionSession startBuilding(BuildExecutionConfiguration buildExecutionConfiguration, Consumer<BuildExecutionStatusChangedEvent> onBuildExecutionStatusChangedEvent, String accessToken) throws ExecutorException {
DefaultBuildExecutionSession buildExecutionSession = new DefaultBuildExecutionSession(buildExecutionConfiguration, onBuildExecutionStatusChangedEvent);
String executionConfigurationId = buildExecutionConfiguration.getId();
DefaultBuildExecutionSession existing = runningExecutions.putIfAbsent(executionConfigurationId, buildExecutionSession);
if (existing != null) {
throw new AlreadyRunningException("Build execution with id: " + executionConfigurationId + " is already running.");
}
buildExecutionSession.setStartTime(new Date());
userLog.info("Starting build execution...");
buildExecutionSession.setStatus(BuildExecutionStatus.NEW);
buildExecutionSession.setAccessToken(accessToken);
DebugData debugData = new DebugData(buildExecutionConfiguration.isPodKeptOnFailure());
CompletableFuture.supplyAsync(() -> configureRepository(buildExecutionSession), executor).thenComposeAsync(repositoryConfiguration -> setUpEnvironment(buildExecutionSession, repositoryConfiguration, debugData), executor).thenComposeAsync(nul -> runTheBuild(buildExecutionSession), executor).thenApplyAsync(completedBuild -> {
buildExecutionSession.setCancelHook(null);
return optionallyEnableSsh(buildExecutionSession, completedBuild);
}, executor).thenApplyAsync(completedBuild -> retrieveBuildDriverResults(buildExecutionSession, completedBuild), executor).thenApplyAsync(nul -> retrieveRepositoryManagerResults(buildExecutionSession), executor).handleAsync((nul, e) -> {
// make sure there are no references left
buildExecutionSession.setCancelHook(null);
return completeExecution(buildExecutionSession, e);
}, executor);
// TODO re-connect running instances in case of crash
return buildExecutionSession;
}
use of org.jboss.pnc.spi.executor.exceptions.ExecutorException 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;
}
use of org.jboss.pnc.spi.executor.exceptions.ExecutorException in project pnc by project-ncl.
the class BuildEnvironmentTest method runBuild.
private void runBuild(BuildConfiguration buildConfiguration, Set<BuildExecutionStatusChangedEvent> statusChangedEvents, ObjectWrapper<BuildResult> buildExecutionResultWrapper, boolean keepAliveOnFailure) throws ExecutorException {
DefaultBuildExecutor executor = null;
try {
executor = new DefaultBuildExecutor(repositoryManagerFactory, buildDriverFactory, environmentDriverFactory, new Configuration(), null);
} catch (ConfigurationParseException e) {
log.error(e.toString());
}
Consumer<BuildExecutionStatusChangedEvent> onBuildExecutionStatusChangedEvent = (statusChangedEvent) -> {
log.debug("Received execution status update {}.", statusChangedEvent);
statusChangedEvents.add(statusChangedEvent);
if (statusChangedEvent.getNewStatus().isCompleted()) {
BuildResult buildResult = statusChangedEvent.getBuildResult().get();
buildExecutionResultWrapper.set(buildResult);
}
};
BuildExecutionConfiguration buildExecutionConfiguration = new DefaultBuildExecutionConfiguration("1", "build-content-id", "1", buildConfiguration.getBuildScript(), buildConfiguration.getId().toString(), buildConfiguration.getName(), buildConfiguration.getRepositoryConfiguration().getInternalUrl(), buildConfiguration.getScmRevision(), null, buildConfiguration.getRepositoryConfiguration().getExternalUrl(), buildConfiguration.getRepositoryConfiguration().isPreBuildSyncEnabled(), buildConfiguration.getBuildType(), buildConfiguration.getBuildEnvironment().getSystemImageId(), buildConfiguration.getBuildEnvironment().getSystemImageRepositoryUrl(), buildConfiguration.getBuildEnvironment().getSystemImageType(), keepAliveOnFailure, null, buildConfiguration.getGenericParameters(), false, null, buildConfiguration.isBrewPullActive(), buildConfiguration.getDefaultAlignmentParams(), AlignmentPreference.PREFER_TEMPORARY);
executor.startBuilding(buildExecutionConfiguration, onBuildExecutionStatusChangedEvent, "");
}
use of org.jboss.pnc.spi.executor.exceptions.ExecutorException in project pnc by project-ncl.
the class BuildExecutionBase method runBuild.
protected void runBuild(BuildConfiguration buildConfiguration, Set<BuildExecutionStatusChangedEvent> statusChangedEvents, ObjectWrapper<BuildResult> buildExecutionResultWrapper, Consumer<BuildExecutionStatusChangedEvent> onStatusUpdate, BuildExecutor executor) throws ExecutorException {
Consumer<BuildExecutionStatusChangedEvent> onBuildExecutionStatusChangedEvent = (statusChangedEvent) -> {
log.debug("Received execution status update {}.", statusChangedEvent);
statusChangedEvents.add(statusChangedEvent);
onStatusUpdate.accept(statusChangedEvent);
if (statusChangedEvent.getNewStatus().isCompleted()) {
BuildResult buildResult = statusChangedEvent.getBuildResult().get();
buildExecutionResultWrapper.set(buildResult);
}
};
BuildExecutionConfiguration buildExecutionConfiguration = new DefaultBuildExecutionConfiguration("1", "build-content-id", "1", buildConfiguration.getBuildScript(), buildConfiguration.getId().toString(), buildConfiguration.getName(), buildConfiguration.getRepositoryConfiguration().getInternalUrl(), buildConfiguration.getScmRevision(), null, buildConfiguration.getRepositoryConfiguration().getExternalUrl(), buildConfiguration.getRepositoryConfiguration().isPreBuildSyncEnabled(), buildConfiguration.getBuildType(), buildConfiguration.getBuildEnvironment().getSystemImageId(), buildConfiguration.getBuildEnvironment().getSystemImageRepositoryUrl(), buildConfiguration.getBuildEnvironment().getSystemImageType(), false, null, buildConfiguration.getGenericParameters(), false, null, buildConfiguration.isBrewPullActive(), buildConfiguration.getDefaultAlignmentParams(), AlignmentPreference.PREFER_TEMPORARY);
executor.startBuilding(buildExecutionConfiguration, onBuildExecutionStatusChangedEvent, "");
}
Aggregations