Search in sources :

Example 1 with BuildExecutionConfiguration

use of org.jboss.pnc.spi.executor.BuildExecutionConfiguration in project pnc by project-ncl.

the class DefaultBuildExecutor method startBuilding.

@Override
public BuildExecutionSession startBuilding(BuildExecutionConfiguration buildExecutionConfiguration, Consumer<BuildExecutionStatusChangedEvent> onBuildExecutionStatusChangedEvent, String accessToken) throws ExecutorException {
    DefaultBuildExecutionSession buildExecutionSession = new DefaultBuildExecutionSession(buildExecutionConfiguration, onBuildExecutionStatusChangedEvent);
    String executionConfigurationId = buildExecutionConfiguration.getId();
    DefaultBuildExecutionSession existing = runningExecutions.putIfAbsent(executionConfigurationId, buildExecutionSession);
    if (existing != null) {
        throw new AlreadyRunningException("Build execution with id: " + executionConfigurationId + " is already running.");
    }
    buildExecutionSession.setStartTime(new Date());
    userLog.info("Starting build execution...");
    buildExecutionSession.setStatus(BuildExecutionStatus.NEW);
    buildExecutionSession.setAccessToken(accessToken);
    DebugData debugData = new DebugData(buildExecutionConfiguration.isPodKeptOnFailure());
    CompletableFuture.supplyAsync(() -> configureRepository(buildExecutionSession), executor).thenComposeAsync(repositoryConfiguration -> setUpEnvironment(buildExecutionSession, repositoryConfiguration, debugData), executor).thenComposeAsync(nul -> runTheBuild(buildExecutionSession), executor).thenApplyAsync(completedBuild -> {
        buildExecutionSession.setCancelHook(null);
        return optionallyEnableSsh(buildExecutionSession, completedBuild);
    }, executor).thenApplyAsync(completedBuild -> retrieveBuildDriverResults(buildExecutionSession, completedBuild), executor).thenApplyAsync(nul -> retrieveRepositoryManagerResults(buildExecutionSession), executor).handleAsync((nul, e) -> {
        // make sure there are no references left
        buildExecutionSession.setCancelHook(null);
        return completeExecution(buildExecutionSession, e);
    }, executor);
    // TODO re-connect running instances in case of crash
    return buildExecutionSession;
}
Also used : AlreadyRunningException(org.jboss.pnc.spi.executor.exceptions.AlreadyRunningException) 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) DebugData(org.jboss.pnc.spi.builddriver.DebugData) Date(java.util.Date)

Example 2 with BuildExecutionConfiguration

use of org.jboss.pnc.spi.executor.BuildExecutionConfiguration 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 3 with BuildExecutionConfiguration

use of org.jboss.pnc.spi.executor.BuildExecutionConfiguration in project pnc by project-ncl.

the class BuildExecutionBase method runBuild.

protected void runBuild(BuildConfiguration buildConfiguration, Set<BuildExecutionStatusChangedEvent> statusChangedEvents, ObjectWrapper<BuildResult> buildExecutionResultWrapper, Consumer<BuildExecutionStatusChangedEvent> onStatusUpdate, BuildExecutor executor) throws ExecutorException {
    Consumer<BuildExecutionStatusChangedEvent> onBuildExecutionStatusChangedEvent = (statusChangedEvent) -> {
        log.debug("Received execution status update {}.", statusChangedEvent);
        statusChangedEvents.add(statusChangedEvent);
        onStatusUpdate.accept(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(), false, 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) LoggerFactory(org.slf4j.LoggerFactory) AlignmentPreference(org.jboss.pnc.api.enums.AlignmentPreference) RepositoryManagerFactory(org.jboss.pnc.executor.servicefactories.RepositoryManagerFactory) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) 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) BuildDriverFactory(org.jboss.pnc.executor.servicefactories.BuildDriverFactory) BuildResult(org.jboss.pnc.spi.BuildResult) Set(java.util.Set) Configuration(org.jboss.pnc.common.Configuration) BuildExecutor(org.jboss.pnc.spi.executor.BuildExecutor) Collectors(java.util.stream.Collectors) 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) 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) BuildExecutionConfiguration(org.jboss.pnc.spi.executor.BuildExecutionConfiguration) BuildExecutionStatusChangedEvent(org.jboss.pnc.spi.events.BuildExecutionStatusChangedEvent)

Example 4 with BuildExecutionConfiguration

use of org.jboss.pnc.spi.executor.BuildExecutionConfiguration in project pnc by project-ncl.

the class DatastoreAdapterTest method storeResult.

private void storeResult(DatastoreAdapter datastoreAdapter, BuildStatus buildStatus, CompletionStatus completionStatus) throws DatastoreException {
    BuildDriverResult buildDriverResult = mock(BuildDriverResult.class);
    when(buildDriverResult.getBuildStatus()).thenReturn(buildStatus);
    when(buildDriverResult.getBuildLog()).thenReturn(BUILD_LOG);
    RepositoryManagerResult repositoryManagerResult = mock(RepositoryManagerResult.class);
    when(repositoryManagerResult.getCompletionStatus()).thenReturn(completionStatus);
    when(repositoryManagerResult.getLog()).thenReturn(REPOSITORY_MANAGER_LOG);
    BuildExecutionConfiguration buildExecutionConfiguration = mock(BuildExecutionConfiguration.class);
    BuildResult buildResult = new BuildResult(CompletionStatus.SUCCESS, Optional.empty(), "", Optional.of(buildExecutionConfiguration), Optional.of(buildDriverResult), Optional.of(repositoryManagerResult), Optional.of(EnvironmentDriverResultMock.mock()), Optional.of(RepourResultMock.mock()));
    BuildTask buildTask = mockBuildTask();
    datastoreAdapter.storeResult(buildTask, buildResult);
}
Also used : BuildResult(org.jboss.pnc.spi.BuildResult) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) BuildExecutionConfiguration(org.jboss.pnc.spi.executor.BuildExecutionConfiguration) BuildDriverResult(org.jboss.pnc.spi.builddriver.BuildDriverResult) RepositoryManagerResult(org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult)

Example 5 with BuildExecutionConfiguration

use of org.jboss.pnc.spi.executor.BuildExecutionConfiguration 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)

Aggregations

BuildExecutionConfiguration (org.jboss.pnc.spi.executor.BuildExecutionConfiguration)24 Consumer (java.util.function.Consumer)11 Logger (org.slf4j.Logger)11 LoggerFactory (org.slf4j.LoggerFactory)11 Test (org.junit.Test)10 BuildExecutionSession (org.jboss.pnc.spi.executor.BuildExecutionSession)9 SystemConfig (org.jboss.pnc.common.json.moduleconfig.SystemConfig)7 BuildResult (org.jboss.pnc.spi.BuildResult)7 ExecutorException (org.jboss.pnc.spi.executor.exceptions.ExecutorException)7 RepositoryManagerResult (org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult)7 ConfigurationParseException (org.jboss.pnc.common.json.ConfigurationParseException)6 BuildDriverResult (org.jboss.pnc.spi.builddriver.BuildDriverResult)6 CompletedBuild (org.jboss.pnc.spi.builddriver.CompletedBuild)6 RunningBuild (org.jboss.pnc.spi.builddriver.RunningBuild)6 RunningEnvironment (org.jboss.pnc.spi.environment.RunningEnvironment)6 IOException (java.io.IOException)5 BuildExecutionStatusChangedEvent (org.jboss.pnc.spi.events.BuildExecutionStatusChangedEvent)5 Inject (javax.inject.Inject)4 TaskStatusUpdateEvent (org.jboss.pnc.buildagent.api.TaskStatusUpdateEvent)4 BuildExecutionStatus (org.jboss.pnc.enums.BuildExecutionStatus)4