Search in sources :

Example 1 with ConfigurationParseException

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, "");
}
Also used : BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) Arrays(java.util.Arrays) Arquillian(org.jboss.arquillian.junit.Arquillian) RunWith(org.junit.runner.RunWith) LoggerFactory(org.slf4j.LoggerFactory) TimeoutException(java.util.concurrent.TimeoutException) AlignmentPreference(org.jboss.pnc.api.enums.AlignmentPreference) RepositoryManagerFactory(org.jboss.pnc.executor.servicefactories.RepositoryManagerFactory) BUILD_ENV_SETUP_COMPLETE_SUCCESS(org.jboss.pnc.enums.BuildExecutionStatus.BUILD_ENV_SETUP_COMPLETE_SUCCESS) Inject(javax.inject.Inject) HashSet(java.util.HashSet) BUILD_SETTING_UP(org.jboss.pnc.enums.BuildExecutionStatus.BUILD_SETTING_UP) ConfigurationParseException(org.jboss.pnc.common.json.ConfigurationParseException) Assertions(org.assertj.core.api.Assertions) BuildExecutionStatusChangedEvent(org.jboss.pnc.spi.events.BuildExecutionStatusChangedEvent) BuildExecutionConfiguration(org.jboss.pnc.spi.executor.BuildExecutionConfiguration) ExecutorException(org.jboss.pnc.spi.executor.exceptions.ExecutorException) Logger(org.slf4j.Logger) DONE_WITH_ERRORS(org.jboss.pnc.enums.BuildExecutionStatus.DONE_WITH_ERRORS) BuildDriverFactory(org.jboss.pnc.executor.servicefactories.BuildDriverFactory) BUILD_ENV_SETUP_COMPLETE_WITH_ERROR(org.jboss.pnc.enums.BuildExecutionStatus.BUILD_ENV_SETUP_COMPLETE_WITH_ERROR) BuildResult(org.jboss.pnc.spi.BuildResult) Set(java.util.Set) BUILD_ENV_WAITING(org.jboss.pnc.enums.BuildExecutionStatus.BUILD_ENV_WAITING) Test(org.junit.Test) Configuration(org.jboss.pnc.common.Configuration) TestProjectConfigurationBuilder(org.jboss.pnc.mock.model.builders.TestProjectConfigurationBuilder) Consumer(java.util.function.Consumer) ObjectWrapper(org.jboss.pnc.common.util.ObjectWrapper) List(java.util.List) ChronoUnit(java.time.temporal.ChronoUnit) Deployment(org.jboss.arquillian.container.test.api.Deployment) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) BUILD_ENV_SETTING_UP(org.jboss.pnc.enums.BuildExecutionStatus.BUILD_ENV_SETTING_UP) Assert(org.junit.Assert) EnvironmentDriverFactory(org.jboss.pnc.executor.servicefactories.EnvironmentDriverFactory) BuildExecutionStatus(org.jboss.pnc.enums.BuildExecutionStatus) Wait(org.jboss.pnc.test.util.Wait) BuildResult(org.jboss.pnc.spi.BuildResult) BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) BuildExecutionConfiguration(org.jboss.pnc.spi.executor.BuildExecutionConfiguration) Configuration(org.jboss.pnc.common.Configuration) ConfigurationParseException(org.jboss.pnc.common.json.ConfigurationParseException) BuildExecutionConfiguration(org.jboss.pnc.spi.executor.BuildExecutionConfiguration) BuildExecutionStatusChangedEvent(org.jboss.pnc.spi.events.BuildExecutionStatusChangedEvent)

Example 2 with ConfigurationParseException

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());
}
Also used : BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) BuildDriverException(org.jboss.pnc.spi.builddriver.exception.BuildDriverException) Arquillian(org.jboss.arquillian.junit.Arquillian) RunWith(org.junit.runner.RunWith) LoggerFactory(org.slf4j.LoggerFactory) TimeoutException(java.util.concurrent.TimeoutException) RepositoryManagerFactory(org.jboss.pnc.executor.servicefactories.RepositoryManagerFactory) Inject(javax.inject.Inject) HashSet(java.util.HashSet) ConfigurationParseException(org.jboss.pnc.common.json.ConfigurationParseException) BuildExecutionStatusChangedEvent(org.jboss.pnc.spi.events.BuildExecutionStatusChangedEvent) ExecutorException(org.jboss.pnc.spi.executor.exceptions.ExecutorException) Logger(org.slf4j.Logger) BuildDriverFactory(org.jboss.pnc.executor.servicefactories.BuildDriverFactory) BuildResult(org.jboss.pnc.spi.BuildResult) Set(java.util.Set) Test(org.junit.Test) Configuration(org.jboss.pnc.common.Configuration) BuildStatus(org.jboss.pnc.enums.BuildStatus) TestProjectConfigurationBuilder(org.jboss.pnc.mock.model.builders.TestProjectConfigurationBuilder) BuildDriverResult(org.jboss.pnc.spi.builddriver.BuildDriverResult) Consumer(java.util.function.Consumer) ObjectWrapper(org.jboss.pnc.common.util.ObjectWrapper) List(java.util.List) Deployment(org.jboss.arquillian.container.test.api.Deployment) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) Assert(org.junit.Assert) EnvironmentDriverFactory(org.jboss.pnc.executor.servicefactories.EnvironmentDriverFactory) BuildExecutionStatus(org.jboss.pnc.enums.BuildExecutionStatus) BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) Configuration(org.jboss.pnc.common.Configuration) BuildDriverResult(org.jboss.pnc.spi.builddriver.BuildDriverResult) BuildExecutionStatus(org.jboss.pnc.enums.BuildExecutionStatus) BuildExecutionStatusChangedEvent(org.jboss.pnc.spi.events.BuildExecutionStatusChangedEvent) BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) BuildResult(org.jboss.pnc.spi.BuildResult) ObjectWrapper(org.jboss.pnc.common.util.ObjectWrapper) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with ConfigurationParseException

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());
    }
}
Also used : ConfigurationParseException(org.jboss.pnc.common.json.ConfigurationParseException) BuildExecutionStatus(org.jboss.pnc.enums.BuildExecutionStatus) Test(org.junit.Test)

Example 4 with ConfigurationParseException

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);
}
Also used : BuildExecutionSession(org.jboss.pnc.spi.executor.BuildExecutionSession) CompletedBuild(org.jboss.pnc.spi.builddriver.CompletedBuild) CANCELLED(org.jboss.pnc.enums.BuildStatus.CANCELLED) BuildDriverException(org.jboss.pnc.spi.builddriver.exception.BuildDriverException) RunningBuild(org.jboss.pnc.spi.builddriver.RunningBuild) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LoggerFactory(org.slf4j.LoggerFactory) AtomicReference(java.util.concurrent.atomic.AtomicReference) ConfigurationParseException(org.jboss.pnc.common.json.ConfigurationParseException) Assert.fail(org.junit.Assert.fail) BuildExecutionConfiguration(org.jboss.pnc.spi.executor.BuildExecutionConfiguration) Path(java.nio.file.Path) Mockito.doReturn(org.mockito.Mockito.doReturn) Logger(org.slf4j.Logger) TaskStatusUpdateEvent(org.jboss.pnc.buildagent.api.TaskStatusUpdateEvent) Files(java.nio.file.Files) MethodHandles(java.lang.invoke.MethodHandles) CompletedBuild(org.jboss.pnc.spi.builddriver.CompletedBuild) Test(org.junit.Test) IOException(java.io.IOException) Consumer(java.util.function.Consumer) CountDownLatch(java.util.concurrent.CountDownLatch) RunningEnvironment(org.jboss.pnc.spi.environment.RunningEnvironment) Status(org.jboss.pnc.buildagent.api.Status) SystemConfig(org.jboss.pnc.common.json.moduleconfig.SystemConfig) BuildExecutionSession(org.jboss.pnc.spi.executor.BuildExecutionSession) Mockito.mock(org.mockito.Mockito.mock) BuildExecutionConfiguration(org.jboss.pnc.spi.executor.BuildExecutionConfiguration) RunningBuild(org.jboss.pnc.spi.builddriver.RunningBuild) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 5 with ConfigurationParseException

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);
    }
}
Also used : ServletException(javax.servlet.ServletException) ConfigurationParseException(org.jboss.pnc.common.json.ConfigurationParseException)

Aggregations

ConfigurationParseException (org.jboss.pnc.common.json.ConfigurationParseException)11 Test (org.junit.Test)7 Consumer (java.util.function.Consumer)5 BuildExecutionStatus (org.jboss.pnc.enums.BuildExecutionStatus)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 BuildDriverException (org.jboss.pnc.spi.builddriver.exception.BuildDriverException)4 HashSet (java.util.HashSet)3 Set (java.util.Set)3 TimeoutException (java.util.concurrent.TimeoutException)3 Inject (javax.inject.Inject)3 Deployment (org.jboss.arquillian.container.test.api.Deployment)3 Arquillian (org.jboss.arquillian.junit.Arquillian)3 Configuration (org.jboss.pnc.common.Configuration)3 ObjectWrapper (org.jboss.pnc.common.util.ObjectWrapper)3 BuildDriverFactory (org.jboss.pnc.executor.servicefactories.BuildDriverFactory)3 EnvironmentDriverFactory (org.jboss.pnc.executor.servicefactories.EnvironmentDriverFactory)3 RepositoryManagerFactory (org.jboss.pnc.executor.servicefactories.RepositoryManagerFactory)3 TestProjectConfigurationBuilder (org.jboss.pnc.mock.model.builders.TestProjectConfigurationBuilder)3 BuildConfiguration (org.jboss.pnc.model.BuildConfiguration)3