Search in sources :

Example 6 with ConfigurationParseException

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));
}
Also used : BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) Arrays(java.util.Arrays) 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) TestProjectConfigurationBuilder(org.jboss.pnc.mock.model.builders.TestProjectConfigurationBuilder) Consumer(java.util.function.Consumer) ObjectWrapper(org.jboss.pnc.common.util.ObjectWrapper) Deployment(org.jboss.arquillian.container.test.api.Deployment) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) EnvironmentDriverFactory(org.jboss.pnc.executor.servicefactories.EnvironmentDriverFactory) BuildExecutionStatus(org.jboss.pnc.enums.BuildExecutionStatus) BuildResult(org.jboss.pnc.spi.BuildResult) ExecutorException(org.jboss.pnc.spi.executor.exceptions.ExecutorException) BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) Configuration(org.jboss.pnc.common.Configuration) ObjectWrapper(org.jboss.pnc.common.util.ObjectWrapper) BuildExecutionStatusChangedEvent(org.jboss.pnc.spi.events.BuildExecutionStatusChangedEvent) HashSet(java.util.HashSet)

Example 7 with ConfigurationParseException

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

Example 8 with ConfigurationParseException

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");
    }
}
Also used : ConfigurationParseException(org.jboss.pnc.common.json.ConfigurationParseException) PncConfigProvider(org.jboss.pnc.common.json.moduleprovider.PncConfigProvider) DemoDataConfig(org.jboss.pnc.common.json.moduleconfig.DemoDataConfig) PostConstruct(javax.annotation.PostConstruct)

Example 9 with ConfigurationParseException

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());
    }
}
Also used : TargetRepository(org.jboss.pnc.model.TargetRepository) MalformedURLException(java.net.MalformedURLException) ConfigurationParseException(org.jboss.pnc.common.json.ConfigurationParseException) GlobalModuleGroup(org.jboss.pnc.common.json.GlobalModuleGroup) RepositoryType(org.jboss.pnc.enums.RepositoryType)

Example 10 with ConfigurationParseException

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);
}
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)

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