use of org.jboss.pnc.spi.events.BuildExecutionStatusChangedEvent in project pnc by project-ncl.
the class EarlyCancellationTest method testBuild.
private void testBuild(BuildExecutionStatus cancelAfter, BuildExecutionStatus[] expectedStatuses, BuildExecutionStatus[] unexpectedStatuses) throws ExecutorException, TimeoutException, InterruptedException, BuildDriverException, ConfigurationParseException {
BuildConfiguration buildConfiguration = configurationBuilder.build(1, "c1-java");
Set<BuildExecutionStatusChangedEvent> statusChangedEvents = new HashSet<>();
ObjectWrapper<BuildResult> buildExecutionResultWrapper = new ObjectWrapper<>();
DefaultBuildExecutor executor = new DefaultBuildExecutor(repositoryManagerFactory, buildDriverFactory, environmentDriverFactory, new Configuration(), null);
Consumer<BuildExecutionStatusChangedEvent> cancel = (e) -> {
if (cancelAfter.equals(e.getNewStatus())) {
try {
log.info("Cancelling build ...");
executor.cancel("1");
} catch (ExecutorException e0) {
e0.printStackTrace();
}
}
};
runBuild(buildConfiguration, statusChangedEvents, buildExecutionResultWrapper, cancel, executor);
// check build statuses
checkBuildStatuses(statusChangedEvents, Arrays.asList(expectedStatuses));
buildStatusesShouldNotContain(statusChangedEvents, Arrays.asList(unexpectedStatuses));
}
use of org.jboss.pnc.spi.events.BuildExecutionStatusChangedEvent in project pnc by project-ncl.
the class DefaultBuildExecutionSession method setStatus.
@Override
public void setStatus(BuildExecutionStatus status) {
if (status.hasFailed() && failedReasonStatus == null) {
if (status.equals(DONE_WITH_ERRORS) && executorException == null) {
setException(new ExecutorException("FailedReasonStatus or executorException must be set before final DONE_WITH_ERRORS."));
}
log.debug("Setting status {} as failed reason for session {}.", status, getId());
failedReasonStatus = status;
}
Optional<BuildResult> buildResult;
if (status.isCompleted()) {
buildResult = Optional.of(getBuildResult());
} else {
buildResult = Optional.empty();
}
BuildExecutionStatusChangedEvent statusChanged = new DefaultBuildExecutorStatusChangedEvent(this.status, status, getId(), null, buildResult, status.isCompleted());
log.debug("Updating build execution task {} status to {}.", getId(), statusChanged);
this.status = status;
onBuildExecutionStatusChangedEvent.accept(statusChanged);
log.debug("Fired events after build execution task {} update.", getId());
}
use of org.jboss.pnc.spi.events.BuildExecutionStatusChangedEvent in project pnc by project-ncl.
the class BuildExecutionTest method shouldNotContinueBuildOnMavenError.
@Test
public void shouldNotContinueBuildOnMavenError() throws ExecutorException, InterruptedException, TimeoutException {
BuildConfiguration buildConfiguration = configurationBuilder.buildFailingConfiguration(3, "build-failed-on-maven", null);
Set<BuildExecutionStatusChangedEvent> statusChangedEvents = new HashSet<>();
ObjectWrapper<BuildResult> buildExecutionResultWrapper = new ObjectWrapper<>();
runBuild(buildConfiguration, statusChangedEvents, buildExecutionResultWrapper);
checkBuildStatuses(statusChangedEvents, Arrays.asList(DONE_WITH_ERRORS, BUILD_ENV_DESTROYED, BUILD_ENV_DESTROYING));
assertNoState(statusChangedEvents, BuildExecutionStatus.COLLECTING_RESULTS_FROM_REPOSITORY_MANAGER);
}
use of org.jboss.pnc.spi.events.BuildExecutionStatusChangedEvent in project pnc by project-ncl.
the class BuildExecutionSessionMock method setStatus.
@Override
public void setStatus(BuildExecutionStatus status) {
if (status.hasFailed() && failedReasonStatus == null) {
if (status.equals(DONE_WITH_ERRORS)) {
setException(new ExecutorException("Missing failedReasonStatus. Failed reason must be sat before final DONE_WITH_ERRORS."));
}
log.debug("Setting status {} as failed reason for session {}.", status, getId());
failedReasonStatus = status;
}
Optional<BuildResult> buildResult;
if (status.isCompleted()) {
buildResult = Optional.of(getBuildResult());
} else {
buildResult = Optional.empty();
}
BuildExecutionStatusChangedEvent statusChanged = new BuildExecutorStatusChangedEventMock(this.status, status, getId(), null, buildResult, status.isCompleted());
log.debug("Updating build execution task {} status to {}.", getId(), statusChanged);
this.status = status;
onBuildExecutionStatusChangedEvent.accept(statusChanged);
log.debug("Fired events after build execution task {} update.", getId());
}
use of org.jboss.pnc.spi.events.BuildExecutionStatusChangedEvent in project pnc by project-ncl.
the class BuildExecutorTriggerer method executeBuild.
public BuildExecutionSession executeBuild(BuildExecutionConfiguration buildExecutionConfig, String callbackUrl, String accessToken) throws CoreException, ExecutorException {
Consumer<BuildExecutionStatusChangedEvent> onExecutionStatusChange = (statusChangedEvent) -> {
log.debug("Received BuildExecutionStatusChangedEvent: " + statusChangedEvent);
if (statusChangedEvent.isFinal() && callbackUrl != null && !callbackUrl.isEmpty()) {
statusChangedEvent.getBuildResult().ifPresent((buildResult) -> bpmNotifier.sendBuildExecutionCompleted(callbackUrl, buildResult, accessToken));
}
};
BuildExecutionSession buildExecutionSession = buildExecutor.startBuilding(buildExecutionConfig, onExecutionStatusChange, accessToken);
return buildExecutionSession;
}
Aggregations