Search in sources :

Example 1 with BuildDriver

use of org.jboss.pnc.spi.builddriver.BuildDriver in project pnc by project-ncl.

the class DefaultBuildExecutor method runTheBuild.

private CompletableFuture<CompletedBuild> runTheBuild(DefaultBuildExecutionSession buildExecutionSession) {
    CompletableFuture<CompletedBuild> waitToCompleteFuture = new CompletableFuture<>();
    if (buildExecutionSession.isCanceled()) {
        waitToCompleteFuture.complete(null);
        return waitToCompleteFuture;
    }
    ProcessStageUtils.logProcessStageBegin(BuildExecutionStatus.BUILD_SETTING_UP.toString(), "Running the build ...");
    buildExecutionSession.setStatus(BuildExecutionStatus.BUILD_SETTING_UP);
    RunningEnvironment runningEnvironment = buildExecutionSession.getRunningEnvironment();
    try {
        Consumer<CompletedBuild> onComplete = value -> {
            ProcessStageUtils.logProcessStageEnd(BuildExecutionStatus.BUILD_SETTING_UP.toString(), "Build completed.");
            waitToCompleteFuture.complete(value);
        };
        Consumer<Throwable> onError = (e) -> {
            ProcessStageUtils.logProcessStageEnd(BuildExecutionStatus.BUILD_SETTING_UP.toString(), "Build failed.");
            waitToCompleteFuture.completeExceptionally(new BuildProcessException(e, runningEnvironment));
        };
        String buildAgentUrl = runningEnvironment.getBuildAgentUrl();
        String liveLogWebSocketUrl = "ws" + StringUtils.addEndingSlash(buildAgentUrl).replaceAll("http(s?):", ":") + "socket/text/ro";
        log.debug("Setting live log websocket url: {}", liveLogWebSocketUrl);
        buildExecutionSession.setLiveLogsUri(Optional.of(new URI(liveLogWebSocketUrl)));
        BuildDriver buildDriver = buildDriverFactory.getBuildDriver();
        RunningBuild runningBuild = buildDriver.startProjectBuild(buildExecutionSession, runningEnvironment, onComplete, onError);
        buildExecutionSession.setCancelHook(runningBuild::cancel);
        buildExecutionSession.setStatus(BuildExecutionStatus.BUILD_WAITING);
    } catch (Throwable e) {
        throw new BuildProcessException(e, runningEnvironment);
    }
    return waitToCompleteFuture;
}
Also used : CompletedBuild(org.jboss.pnc.spi.builddriver.CompletedBuild) RunningBuild(org.jboss.pnc.spi.builddriver.RunningBuild) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) RepositoryManagerFactory(org.jboss.pnc.executor.servicefactories.RepositoryManagerFactory) StringUtils(org.jboss.pnc.common.util.StringUtils) PreDestroy(javax.annotation.PreDestroy) RepositoryManager(org.jboss.pnc.spi.repositorymanager.RepositoryManager) KeycloakServiceClient(org.jboss.pnc.auth.KeycloakServiceClient) DestroyableEnvironment(org.jboss.pnc.spi.environment.DestroyableEnvironment) BuildExecutionConfiguration(org.jboss.pnc.spi.executor.BuildExecutionConfiguration) URI(java.net.URI) EnvironmentDriver(org.jboss.pnc.spi.environment.EnvironmentDriver) BuildDriverFactory(org.jboss.pnc.executor.servicefactories.BuildDriverFactory) RepositoryManagerException(org.jboss.pnc.spi.repositorymanager.RepositoryManagerException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) CompletedBuild(org.jboss.pnc.spi.builddriver.CompletedBuild) BuildStatus(org.jboss.pnc.enums.BuildStatus) BuildDriverResult(org.jboss.pnc.spi.builddriver.BuildDriverResult) PncConfigProvider(org.jboss.pnc.common.json.moduleprovider.PncConfigProvider) RunningEnvironment(org.jboss.pnc.spi.environment.RunningEnvironment) RepositorySession(org.jboss.pnc.spi.repositorymanager.model.RepositorySession) BuildExecution(org.jboss.pnc.spi.repositorymanager.BuildExecution) MDCExecutors(org.jboss.pnc.common.concurrent.MDCExecutors) DebugData(org.jboss.pnc.spi.builddriver.DebugData) Optional(java.util.Optional) ApplicationScoped(javax.enterprise.context.ApplicationScoped) SystemConfig(org.jboss.pnc.common.json.moduleconfig.SystemConfig) NamedThreadFactory(org.jboss.pnc.common.concurrent.NamedThreadFactory) BuildDriver(org.jboss.pnc.spi.builddriver.BuildDriver) BuildProcessException(org.jboss.pnc.executor.exceptions.BuildProcessException) CompletableFuture(java.util.concurrent.CompletableFuture) ConcurrentMap(java.util.concurrent.ConcurrentMap) Inject(javax.inject.Inject) ConfigurationParseException(org.jboss.pnc.common.json.ConfigurationParseException) RepositoryType(org.jboss.pnc.enums.RepositoryType) BuildExecutionStatusChangedEvent(org.jboss.pnc.spi.events.BuildExecutionStatusChangedEvent) ExecutorException(org.jboss.pnc.spi.executor.exceptions.ExecutorException) BuildType(org.jboss.pnc.enums.BuildType) ExecutorService(java.util.concurrent.ExecutorService) Logger(org.slf4j.Logger) Configuration(org.jboss.pnc.common.Configuration) ProcessStageUtils(org.jboss.pnc.common.util.ProcessStageUtils) BuildExecutor(org.jboss.pnc.spi.executor.BuildExecutor) Consumer(java.util.function.Consumer) StartedEnvironment(org.jboss.pnc.spi.environment.StartedEnvironment) AlreadyRunningException(org.jboss.pnc.spi.executor.exceptions.AlreadyRunningException) RepositoryManagerResult(org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult) BuildExecutionStatus(org.jboss.pnc.enums.BuildExecutionStatus) EnvironmentDriverFactory(org.jboss.pnc.executor.servicefactories.EnvironmentDriverFactory) BuildExecutionSession(org.jboss.pnc.spi.executor.BuildExecutionSession) RunningBuild(org.jboss.pnc.spi.builddriver.RunningBuild) URI(java.net.URI) RunningEnvironment(org.jboss.pnc.spi.environment.RunningEnvironment) BuildProcessException(org.jboss.pnc.executor.exceptions.BuildProcessException) BuildDriver(org.jboss.pnc.spi.builddriver.BuildDriver) CompletableFuture(java.util.concurrent.CompletableFuture)

Example 2 with BuildDriver

use of org.jboss.pnc.spi.builddriver.BuildDriver in project pnc by project-ncl.

the class BuildDriverFactoryTest method shouldSkipDriversWhichAreNotMentionedInConfiguration.

@Test(expected = ExecutorException.class)
public void shouldSkipDriversWhichAreNotMentionedInConfiguration() throws Exception {
    // given
    ProperDriver testedBuildDriver = new ProperDriver();
    TestInstance<BuildDriver> allDrivers = new TestInstance<>(testedBuildDriver);
    Configuration configuration = new Configuration();
    BuildDriverFactory factory = new BuildDriverFactory(allDrivers, configuration);
    factory.initConfiguration();
    // when
    factory.getBuildDriver();
}
Also used : BuildDriver(org.jboss.pnc.spi.builddriver.BuildDriver) TestInstance(org.jboss.pnc.test.cdi.TestInstance) Configuration(org.jboss.pnc.common.Configuration) BuildDriverFactory(org.jboss.pnc.executor.servicefactories.BuildDriverFactory) Test(org.junit.Test)

Example 3 with BuildDriver

use of org.jboss.pnc.spi.builddriver.BuildDriver in project pnc by project-ncl.

the class BuildDriverFactoryTest method shouldPickProperDriver.

@Test
public void shouldPickProperDriver() throws Exception {
    // given
    ProperDriver testedBuildDriver = new ProperDriver();
    TestInstance<BuildDriver> allDrivers = new TestInstance<>(testedBuildDriver);
    Configuration configuration = mock(Configuration.class);
    BuildDriverFactory factory = new BuildDriverFactory(allDrivers, configuration);
    // when
    BuildDriver buildDriver = factory.getBuildDriver();
    // then
    assertThat(buildDriver).isEqualTo(testedBuildDriver);
}
Also used : BuildDriver(org.jboss.pnc.spi.builddriver.BuildDriver) TestInstance(org.jboss.pnc.test.cdi.TestInstance) Configuration(org.jboss.pnc.common.Configuration) BuildDriverFactory(org.jboss.pnc.executor.servicefactories.BuildDriverFactory) Test(org.junit.Test)

Aggregations

Configuration (org.jboss.pnc.common.Configuration)3 BuildDriverFactory (org.jboss.pnc.executor.servicefactories.BuildDriverFactory)3 BuildDriver (org.jboss.pnc.spi.builddriver.BuildDriver)3 URI (java.net.URI)1 Date (java.util.Date)1 Optional (java.util.Optional)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 ExecutorService (java.util.concurrent.ExecutorService)1 Consumer (java.util.function.Consumer)1 PreDestroy (javax.annotation.PreDestroy)1 ApplicationScoped (javax.enterprise.context.ApplicationScoped)1 Inject (javax.inject.Inject)1 KeycloakServiceClient (org.jboss.pnc.auth.KeycloakServiceClient)1 MDCExecutors (org.jboss.pnc.common.concurrent.MDCExecutors)1 NamedThreadFactory (org.jboss.pnc.common.concurrent.NamedThreadFactory)1 ConfigurationParseException (org.jboss.pnc.common.json.ConfigurationParseException)1 SystemConfig (org.jboss.pnc.common.json.moduleconfig.SystemConfig)1 PncConfigProvider (org.jboss.pnc.common.json.moduleprovider.PncConfigProvider)1