Search in sources :

Example 6 with BuildExecutionStatus

use of org.jboss.pnc.enums.BuildExecutionStatus in project pnc by project-ncl.

the class BuildExecutorMock method startBuilding.

// @Deprecated //CDI workaround
// public BuildExecutorMock() {
// }
// 
// @Inject
// public BuildExecutorMock(RepositoryManagerFactory repositoryManagerFactory, BuildDriverFactory
// buildDriverFactory, EnvironmentDriverFactory environmentDriverFactory, Configuration configuration) {
// 
// }
@Override
public BuildExecutionSession startBuilding(BuildExecutionConfiguration buildExecutionConfiguration, Consumer<BuildExecutionStatusChangedEvent> onBuildExecutionStatusChangedEvent, String accessToken) throws ExecutorException {
    log.info("Starting mock build execution for buildExecutionConfiguration.id {}", buildExecutionConfiguration.getId());
    BuildExecutionSession buildExecutionSession = new BuildExecutionSessionMock(buildExecutionConfiguration, onBuildExecutionStatusChangedEvent);
    buildExecutionSession.setStatus(BuildExecutionStatus.NEW);
    runningExecutions.put(buildExecutionConfiguration.getId(), buildExecutionSession);
    Consumer<BuildExecutionStatus> onCompleteInternal = (buildStatus) -> {
        log.debug("Removing buildExecutionConfiguration.id [" + buildExecutionConfiguration.getId() + "] form list of running tasks.");
        runningExecutions.remove(buildExecutionConfiguration.getId());
        buildExecutionSession.setStatus(buildStatus);
    };
    CompletableFuture<Integer> future = CompletableFuture.supplyAsync(() -> mockBuild(buildExecutionSession), executor).handleAsync((buildPassed, e) -> complete(buildPassed, e, onCompleteInternal), executor);
    runningFutures.put(buildExecutionConfiguration.getId(), future);
    return buildExecutionSession;
}
Also used : BuildExecutionSession(org.jboss.pnc.spi.executor.BuildExecutionSession) Logger(org.slf4j.Logger) RepositoryManagerResultMock(org.jboss.pnc.mock.repositorymanager.RepositoryManagerResultMock) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) BuildExecutor(org.jboss.pnc.spi.executor.BuildExecutor) BuildStatus(org.jboss.pnc.enums.BuildStatus) BuildDriverResultMock(org.jboss.pnc.mock.builddriver.BuildDriverResultMock) TestProjectConfigurationBuilder(org.jboss.pnc.mock.model.builders.TestProjectConfigurationBuilder) BuildDriverResult(org.jboss.pnc.spi.builddriver.BuildDriverResult) Consumer(java.util.function.Consumer) MDCExecutors(org.jboss.pnc.common.concurrent.MDCExecutors) RepositoryManagerResult(org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult) Map(java.util.Map) BuildExecutionStatusChangedEvent(org.jboss.pnc.spi.events.BuildExecutionStatusChangedEvent) ApplicationScoped(javax.enterprise.context.ApplicationScoped) BuildExecutionConfiguration(org.jboss.pnc.spi.executor.BuildExecutionConfiguration) ExecutorException(org.jboss.pnc.spi.executor.exceptions.ExecutorException) NamedThreadFactory(org.jboss.pnc.common.concurrent.NamedThreadFactory) BuildExecutionStatus(org.jboss.pnc.enums.BuildExecutionStatus) BuildExecutionSession(org.jboss.pnc.spi.executor.BuildExecutionSession) ExecutorService(java.util.concurrent.ExecutorService) BuildExecutionStatus(org.jboss.pnc.enums.BuildExecutionStatus)

Example 7 with BuildExecutionStatus

use of org.jboss.pnc.enums.BuildExecutionStatus 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 8 with BuildExecutionStatus

use of org.jboss.pnc.enums.BuildExecutionStatus 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)

Aggregations

BuildExecutionStatus (org.jboss.pnc.enums.BuildExecutionStatus)8 BuildExecutionStatusChangedEvent (org.jboss.pnc.spi.events.BuildExecutionStatusChangedEvent)6 Test (org.junit.Test)6 HashSet (java.util.HashSet)4 ConfigurationParseException (org.jboss.pnc.common.json.ConfigurationParseException)4 ObjectWrapper (org.jboss.pnc.common.util.ObjectWrapper)4 BuildConfiguration (org.jboss.pnc.model.BuildConfiguration)4 BuildResult (org.jboss.pnc.spi.BuildResult)4 Consumer (java.util.function.Consumer)3 TestProjectConfigurationBuilder (org.jboss.pnc.mock.model.builders.TestProjectConfigurationBuilder)3 BuildDriverResult (org.jboss.pnc.spi.builddriver.BuildDriverResult)3 ExecutorException (org.jboss.pnc.spi.executor.exceptions.ExecutorException)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 Set (java.util.Set)2 TimeoutException (java.util.concurrent.TimeoutException)2 Inject (javax.inject.Inject)2 Deployment (org.jboss.arquillian.container.test.api.Deployment)2 Arquillian (org.jboss.arquillian.junit.Arquillian)2 Configuration (org.jboss.pnc.common.Configuration)2