use of org.jboss.pnc.spi.executor.BuildExecutionConfiguration 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.BuildExecutionConfiguration 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.BuildExecutionConfiguration 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, "");
}
use of org.jboss.pnc.spi.executor.BuildExecutionConfiguration in project pnc by project-ncl.
the class DatastoreAdapterTest method storeResult.
private void storeResult(DatastoreAdapter datastoreAdapter, BuildStatus buildStatus, CompletionStatus completionStatus) throws DatastoreException {
BuildDriverResult buildDriverResult = mock(BuildDriverResult.class);
when(buildDriverResult.getBuildStatus()).thenReturn(buildStatus);
when(buildDriverResult.getBuildLog()).thenReturn(BUILD_LOG);
RepositoryManagerResult repositoryManagerResult = mock(RepositoryManagerResult.class);
when(repositoryManagerResult.getCompletionStatus()).thenReturn(completionStatus);
when(repositoryManagerResult.getLog()).thenReturn(REPOSITORY_MANAGER_LOG);
BuildExecutionConfiguration buildExecutionConfiguration = mock(BuildExecutionConfiguration.class);
BuildResult buildResult = new BuildResult(CompletionStatus.SUCCESS, Optional.empty(), "", Optional.of(buildExecutionConfiguration), Optional.of(buildDriverResult), Optional.of(repositoryManagerResult), Optional.of(EnvironmentDriverResultMock.mock()), Optional.of(RepourResultMock.mock()));
BuildTask buildTask = mockBuildTask();
datastoreAdapter.storeResult(buildTask, buildResult);
}
use of org.jboss.pnc.spi.executor.BuildExecutionConfiguration in project pnc by project-ncl.
the class BuildExecutorMock method startBuilding.
// @Deprecated //CDI workaround
// public BuildExecutorMock() {
// }
//
// @Inject
// public BuildExecutorMock(RepositoryManagerFactory repositoryManagerFactory, BuildDriverFactory
// buildDriverFactory, EnvironmentDriverFactory environmentDriverFactory, Configuration configuration) {
//
// }
@Override
public BuildExecutionSession startBuilding(BuildExecutionConfiguration buildExecutionConfiguration, Consumer<BuildExecutionStatusChangedEvent> onBuildExecutionStatusChangedEvent, String accessToken) throws ExecutorException {
log.info("Starting mock build execution for buildExecutionConfiguration.id {}", buildExecutionConfiguration.getId());
BuildExecutionSession buildExecutionSession = new BuildExecutionSessionMock(buildExecutionConfiguration, onBuildExecutionStatusChangedEvent);
buildExecutionSession.setStatus(BuildExecutionStatus.NEW);
runningExecutions.put(buildExecutionConfiguration.getId(), buildExecutionSession);
Consumer<BuildExecutionStatus> onCompleteInternal = (buildStatus) -> {
log.debug("Removing buildExecutionConfiguration.id [" + buildExecutionConfiguration.getId() + "] form list of running tasks.");
runningExecutions.remove(buildExecutionConfiguration.getId());
buildExecutionSession.setStatus(buildStatus);
};
CompletableFuture<Integer> future = CompletableFuture.supplyAsync(() -> mockBuild(buildExecutionSession), executor).handleAsync((buildPassed, e) -> complete(buildPassed, e, onCompleteInternal), executor);
runningFutures.put(buildExecutionConfiguration.getId(), future);
return buildExecutionSession;
}
Aggregations