use of org.jboss.pnc.common.json.ConfigurationParseException 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.common.json.ConfigurationParseException in project pnc by project-ncl.
the class BuildExecutionCancellationTest method testBuild.
@Test(timeout = 3000)
public void testBuild() 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 (BuildExecutionStatus.BUILD_WAITING.equals(e.getNewStatus())) {
try {
log.info("Cancelling build ...");
Thread.sleep(100);
executor.cancel(e.getBuildTaskId());
} catch (ExecutorException | InterruptedException e0) {
e0.printStackTrace();
}
}
};
runBuild(buildConfiguration, statusChangedEvents, buildExecutionResultWrapper, cancel, executor);
List<BuildExecutionStatus> expectedStatuses = getBuildExecutionStatusesBase();
expectedStatuses.add(BuildExecutionStatus.CANCELLED);
// check build statuses
checkBuildStatuses(statusChangedEvents, expectedStatuses);
// check results
BuildResult buildResult = buildExecutionResultWrapper.get();
BuildDriverResult buildDriverResult = buildResult.getBuildDriverResult().get();
Assert.assertEquals(BuildStatus.CANCELLED, buildDriverResult.getBuildStatus());
}
use of org.jboss.pnc.common.json.ConfigurationParseException in project pnc by project-ncl.
the class EarlyCancellationTest method cancelImmediately.
@Test(timeout = 3000)
public void cancelImmediately() throws InterruptedException, TimeoutException, ExecutorException, BuildDriverException {
BuildExecutionStatus cancelAfter = BuildExecutionStatus.NEW;
BuildExecutionStatus[] expectedStatuses = { BuildExecutionStatus.NEW, BuildExecutionStatus.FINALIZING_EXECUTION, BuildExecutionStatus.CANCELLED };
BuildExecutionStatus[] unexpectedStatuses = { BuildExecutionStatus.BUILD_ENV_SETTING_UP, BuildExecutionStatus.BUILD_ENV_WAITING, BuildExecutionStatus.BUILD_ENV_SETUP_COMPLETE_SUCCESS, BuildExecutionStatus.REPO_SETTING_UP, BuildExecutionStatus.BUILD_SETTING_UP, BuildExecutionStatus.BUILD_WAITING, BuildExecutionStatus.COLLECTING_RESULTS_FROM_BUILD_DRIVER, BuildExecutionStatus.COLLECTING_RESULTS_FROM_REPOSITORY_MANAGER, BuildExecutionStatus.BUILD_ENV_DESTROYING, BuildExecutionStatus.BUILD_ENV_DESTROYED, BuildExecutionStatus.DONE, BuildExecutionStatus.DONE_WITH_ERRORS };
try {
testBuild(cancelAfter, expectedStatuses, unexpectedStatuses);
} catch (ConfigurationParseException e) {
log.error(e.toString());
}
}
use of org.jboss.pnc.common.json.ConfigurationParseException in project pnc by project-ncl.
the class TermdBuildDriverTest method shouldStartAndCancelTheExecutionImmediately.
@Test(timeout = 5_000)
public void shouldStartAndCancelTheExecutionImmediately() throws ConfigurationParseException, BuildDriverException, InterruptedException, IOException {
// given
String dirName = "test-workdir";
String logStart = "Running the command...";
String logEnd = "Command completed.";
TermdBuildDriver driver = new TermdBuildDriver(systemConfig, buildDriverModuleConfig, clientFactory);
BuildExecutionSession buildExecution = mock(BuildExecutionSession.class);
BuildExecutionConfiguration buildExecutionConfiguration = mock(BuildExecutionConfiguration.class);
doReturn("echo \"" + logStart + "\"; mvn validate; echo \"" + logEnd + "\";").when(buildExecutionConfiguration).getBuildScript();
doReturn(dirName).when(buildExecutionConfiguration).getName();
doReturn(buildExecutionConfiguration).when(buildExecution).getBuildExecutionConfiguration();
AtomicReference<CompletedBuild> buildResult = new AtomicReference<>();
// when
CountDownLatch latch = new CountDownLatch(1);
Consumer<CompletedBuild> onComplete = (completedBuild) -> {
buildResult.set(completedBuild);
latch.countDown();
};
Consumer<Throwable> onError = (throwable) -> {
logger.error("Error received: ", throwable);
fail(throwable.getMessage());
};
RunningBuild runningBuild = driver.startProjectBuild(buildExecution, localEnvironmentPointer, onComplete, onError);
runningBuild.cancel();
latch.await();
// then
assertThat(buildResult.get().getBuildResult().getBuildLog()).doesNotContain(logEnd);
assertThat(buildResult.get().getBuildResult().getBuildStatus()).isEqualTo(CANCELLED);
}
use of org.jboss.pnc.common.json.ConfigurationParseException in project pnc by project-ncl.
the class UIConfigurationServletJs method init.
@Override
public void init() throws ServletException {
try {
UiConfigRest configRest = UiConfigRestBuilder.build(configuration);
String json = JsonOutputConverterMapper.apply(configRest);
this.uiConfig = generateJS(json);
} catch (ConfigurationParseException e) {
throw new ServletException("Lazy-loading of UI configuration failed because the servlet was not able to fetch the configuration.", e);
}
}
Aggregations