use of org.jboss.pnc.spi.events.BuildExecutionStatusChangedEvent 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.events.BuildExecutionStatusChangedEvent in project pnc by project-ncl.
the class BuildEnvironmentTest method shouldReportErrorInCaseOfPodCreationFailure.
@Test
public void shouldReportErrorInCaseOfPodCreationFailure() throws ExecutorException, InterruptedException, TimeoutException {
BuildConfiguration buildConfiguration = configurationBuilder.build(123, "Pod creation failure");
Set<BuildExecutionStatusChangedEvent> statusChangedEvents = new HashSet<>();
ObjectWrapper<BuildResult> buildExecutionResultWrapper = new ObjectWrapper<>();
runBuild(buildConfiguration, statusChangedEvents, buildExecutionResultWrapper, true);
checkBuildStatuses(statusChangedEvents, Arrays.asList(BUILD_ENV_SETTING_UP, BUILD_ENV_WAITING, BUILD_ENV_SETUP_COMPLETE_WITH_ERROR, // supported yet
DONE_WITH_ERRORS));
assertNoState(statusChangedEvents, BUILD_ENV_SETUP_COMPLETE_SUCCESS);
assertNoState(statusChangedEvents, BUILD_SETTING_UP);
}
use of org.jboss.pnc.spi.events.BuildExecutionStatusChangedEvent 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.events.BuildExecutionStatusChangedEvent 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.events.BuildExecutionStatusChangedEvent in project pnc by project-ncl.
the class BuildExecutionBase method buildStatusesShouldNotContain.
protected void buildStatusesShouldNotContain(Set<BuildExecutionStatusChangedEvent> statusChangedEvents, List<BuildExecutionStatus> unexpectedStatuses) {
List<BuildExecutionStatus> statusReceived = statusChangedEvents.stream().map(BuildExecutionStatusChangedEvent::getNewStatus).collect(Collectors.toList());
for (BuildExecutionStatusChangedEvent statusChangedEvent : statusChangedEvents) {
BuildExecutionStatus status = statusChangedEvent.getNewStatus();
if (unexpectedStatuses.contains(status)) {
log.info("Received statuses: {}", statusReceived);
Assert.fail("Unexpected status [" + status + "] has been received.");
}
}
}
Aggregations