use of org.jboss.pnc.common.json.ConfigurationParseException 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.common.json.ConfigurationParseException in project pnc by project-ncl.
the class EarlyCancellationTest method cancelAfterEnvSetUp.
@Test(timeout = 3000)
public void cancelAfterEnvSetUp() throws InterruptedException, TimeoutException, ExecutorException, BuildDriverException {
BuildExecutionStatus cancelAfter = BuildExecutionStatus.BUILD_ENV_SETUP_COMPLETE_SUCCESS;
BuildExecutionStatus[] expectedStatuses = { BuildExecutionStatus.NEW, BuildExecutionStatus.REPO_SETTING_UP, BuildExecutionStatus.BUILD_ENV_SETTING_UP, BuildExecutionStatus.BUILD_ENV_WAITING, BuildExecutionStatus.BUILD_ENV_SETUP_COMPLETE_SUCCESS, BuildExecutionStatus.BUILD_ENV_DESTROYING, BuildExecutionStatus.BUILD_ENV_DESTROYED, BuildExecutionStatus.FINALIZING_EXECUTION, BuildExecutionStatus.CANCELLED };
BuildExecutionStatus[] unexpectedStatuses = { BuildExecutionStatus.BUILD_SETTING_UP, BuildExecutionStatus.BUILD_WAITING, BuildExecutionStatus.COLLECTING_RESULTS_FROM_BUILD_DRIVER, BuildExecutionStatus.COLLECTING_RESULTS_FROM_REPOSITORY_MANAGER, 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 DemoDataInitializer method initialize.
@PostConstruct
public void initialize() {
DemoDataConfig demoDataConfig = null;
try {
demoDataConfig = configuration.getModuleConfig(new PncConfigProvider<>(DemoDataConfig.class));
} catch (ConfigurationParseException e) {
logger.warn("Cannot read demo data config.", e);
}
if (demoDataConfig == null || !demoDataConfig.getImportDemoData()) {
logger.info("Demo data import is not enabled.");
return;
}
long numberOfProjectInDB = projectRepository.count();
if (numberOfProjectInDB != 0) {
logger.info("There are >0 ({}) projects in DB. Skipping initialization." + numberOfProjectInDB);
} else {
logger.info("Initializing DEMO data");
dbDataInitializer.initiliazeProjectProductData();
dbDataInitializer.initiliazeBuildRecordDemoData();
dbDataInitializer.verifyData();
logger.info("Finished initializing DEMO data");
}
}
use of org.jboss.pnc.common.json.ConfigurationParseException in project pnc by project-ncl.
the class AbstractArtifactMapper method fillDeployAndPublicUrl.
private void fillDeployAndPublicUrl(org.jboss.pnc.model.Artifact artifactDB, Consumer<String> deployUrlSetter, Consumer<String> publicUrlSetter) {
GlobalModuleGroup globalConfig = null;
try {
globalConfig = config.getGlobalConfig();
} catch (ConfigurationParseException e) {
logger.error("Cannot read configuration", e);
}
if (globalConfig == null) {
return;
}
TargetRepository targetRepository = artifactDB.getTargetRepository();
if (targetRepository == null) {
logger.error("Artifact DB object does not have target repository set: {}", artifactDB);
return;
}
RepositoryType repositoryType = targetRepository.getRepositoryType();
if (repositoryType.equals(RepositoryType.MAVEN) || repositoryType.equals(RepositoryType.NPM)) {
if (artifactDB.getDeployPath() == null || artifactDB.getDeployPath().equals("")) {
deployUrlSetter.accept("");
publicUrlSetter.accept("");
} else {
try {
deployUrlSetter.accept(UrlUtils.buildUrl(globalConfig.getIndyUrl(), targetRepository.getRepositoryPath(), artifactDB.getDeployPath()));
publicUrlSetter.accept(UrlUtils.buildUrl(globalConfig.getExternalIndyUrl(), targetRepository.getRepositoryPath(), artifactDB.getDeployPath()));
} catch (MalformedURLException e) {
logger.error("Cannot construct internal artifactDB URL.", e);
deployUrlSetter.accept(null);
publicUrlSetter.accept(null);
}
}
} else {
deployUrlSetter.accept(artifactDB.getOriginUrl());
publicUrlSetter.accept(artifactDB.getOriginUrl());
}
}
use of org.jboss.pnc.common.json.ConfigurationParseException in project pnc by project-ncl.
the class TermdBuildDriverTest method shouldStartAndCancelWhileExecutingCommand.
@Test(timeout = 5_000)
public void shouldStartAndCancelWhileExecutingCommand() throws ConfigurationParseException, BuildDriverException, InterruptedException {
// given
String dirName = "test-workdir";
String logStart = "Running the command...";
String logEnd = "Command completed.";
CountDownLatch latchCompleted = new CountDownLatch(1);
ClientMockFactory mockFactory = new ClientMockFactory();
TermdBuildDriver driver = new TermdBuildDriver(systemConfig, buildDriverModuleConfig, mockFactory);
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
Consumer<CompletedBuild> onComplete = (completedBuild) -> {
buildResult.set(completedBuild);
latchCompleted.countDown();
};
Consumer<Throwable> onError = (throwable) -> {
logger.error("Error received: ", throwable);
fail(throwable.getMessage());
};
RunningBuild runningBuild = driver.startProjectBuild(buildExecution, localEnvironmentPointer, onComplete, onError);
runningBuild.cancel();
// simulate update for "CTRL+C" on a command, which results in the command failing
mockFactory.getOnStatusUpdate().accept(TaskStatusUpdateEvent.newBuilder().newStatus(Status.FAILED).build());
latchCompleted.await();
// then
assertThat(buildResult.get().getBuildResult()).isNotNull();
assertThat(buildResult.get().getBuildResult().getBuildStatus()).isEqualTo(CANCELLED);
}
Aggregations