Search in sources :

Example 1 with BuildResult

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

the class DefaultBuildCoordinatorTest method mockBuildResult.

private BuildResult mockBuildResult(boolean withSshCredentials) {
    BuildResult result = mock(BuildResult.class);
    BuildDriverResult driverResult = mock(BuildDriverResult.class);
    when(driverResult.getBuildStatus()).thenReturn(BuildStatus.FAILED);
    when(result.getBuildDriverResult()).thenReturn(Optional.of(driverResult));
    RepositoryManagerResult repoManagerResult = mock(RepositoryManagerResult.class);
    when(repoManagerResult.getCompletionStatus()).thenReturn(CompletionStatus.SUCCESS);
    when(result.getRepositoryManagerResult()).thenReturn(Optional.of(repoManagerResult));
    when(result.getBuildExecutionConfiguration()).thenReturn(Optional.of(mock(BuildExecutionConfiguration.class)));
    return result;
}
Also used : BuildResult(org.jboss.pnc.spi.BuildResult) BuildDriverResult(org.jboss.pnc.spi.builddriver.BuildDriverResult) RepositoryManagerResult(org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult)

Example 2 with BuildResult

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

the class DefaultBuildExecutionSession method getBuildResult.

private BuildResult getBuildResult() {
    EnvironmentDriverResult environmentDriverResult = null;
    DebugData debugData = getRunningEnvironment() != null ? getRunningEnvironment().getDebugData() : null;
    if (debugData != null && debugData.isDebugEnabled()) {
        environmentDriverResult = new EnvironmentDriverResult(CompletionStatus.SUCCESS, "", Optional.of(debugData.getSshCredentials()));
    }
    CompletionStatus completionStatus = CompletionStatus.SUCCESS;
    if (executorException == null) {
        if (failedReasonStatus != null) {
            switch(failedReasonStatus) {
                case BUILD_ENV_SETUP_COMPLETE_WITH_ERROR:
                case SYSTEM_ERROR:
                    completionStatus = CompletionStatus.SYSTEM_ERROR;
                    break;
                case COLLECTING_RESULTS_FROM_REPOSITORY_MANAGER_COMPLETED_WITH_ERROR:
                case BUILD_COMPLETED_WITH_ERROR:
                    completionStatus = CompletionStatus.FAILED;
                    break;
                case CANCELLED:
                    completionStatus = CompletionStatus.CANCELLED;
                    break;
                case DONE_WITH_ERRORS:
                    executorException = new ExecutorException("DONE_WITH_ERRORS cannot be set as failed reason.");
                    break;
            }
        }
    }
    ProcessException processException = null;
    if (executorException != null) {
        processException = new ProcessException(executorException);
        completionStatus = CompletionStatus.SYSTEM_ERROR;
    }
    log.debug("Returning result of task {}.", getId());
    return new BuildResult(completionStatus, Optional.ofNullable(processException), "", Optional.ofNullable(buildExecutionConfiguration), Optional.ofNullable(buildDriverResult), Optional.ofNullable(repositoryManagerResult), Optional.ofNullable(environmentDriverResult), Optional.empty());
}
Also used : ProcessException(org.jboss.pnc.spi.coordinator.ProcessException) BuildResult(org.jboss.pnc.spi.BuildResult) ExecutorException(org.jboss.pnc.spi.executor.exceptions.ExecutorException) DebugData(org.jboss.pnc.spi.builddriver.DebugData) EnvironmentDriverResult(org.jboss.pnc.spi.environment.EnvironmentDriverResult) CompletionStatus(org.jboss.pnc.spi.coordinator.CompletionStatus)

Example 3 with BuildResult

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

the class BuildEnvironmentTest method shouldReportErrorInCaseOfPodCreationFailure.

@Test
public void shouldReportErrorInCaseOfPodCreationFailure() throws ExecutorException, InterruptedException, TimeoutException {
    BuildConfiguration buildConfiguration = configurationBuilder.build(123, "Pod creation failure");
    Set<BuildExecutionStatusChangedEvent> statusChangedEvents = new HashSet<>();
    ObjectWrapper<BuildResult> buildExecutionResultWrapper = new ObjectWrapper<>();
    runBuild(buildConfiguration, statusChangedEvents, buildExecutionResultWrapper, true);
    checkBuildStatuses(statusChangedEvents, Arrays.asList(BUILD_ENV_SETTING_UP, BUILD_ENV_WAITING, BUILD_ENV_SETUP_COMPLETE_WITH_ERROR, // supported yet
    DONE_WITH_ERRORS));
    assertNoState(statusChangedEvents, BUILD_ENV_SETUP_COMPLETE_SUCCESS);
    assertNoState(statusChangedEvents, BUILD_SETTING_UP);
}
Also used : BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) BuildResult(org.jboss.pnc.spi.BuildResult) ObjectWrapper(org.jboss.pnc.common.util.ObjectWrapper) BuildExecutionStatusChangedEvent(org.jboss.pnc.spi.events.BuildExecutionStatusChangedEvent) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with BuildResult

use of org.jboss.pnc.spi.BuildResult 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 5 with BuildResult

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

Aggregations

BuildResult (org.jboss.pnc.spi.BuildResult)22 BuildExecutionStatusChangedEvent (org.jboss.pnc.spi.events.BuildExecutionStatusChangedEvent)11 ExecutorException (org.jboss.pnc.spi.executor.exceptions.ExecutorException)10 Test (org.junit.Test)10 BuildConfiguration (org.jboss.pnc.model.BuildConfiguration)9 ObjectWrapper (org.jboss.pnc.common.util.ObjectWrapper)8 HashSet (java.util.HashSet)7 BuildExecutionConfiguration (org.jboss.pnc.spi.executor.BuildExecutionConfiguration)7 BuildExecutionStatus (org.jboss.pnc.enums.BuildExecutionStatus)6 BuildDriverResult (org.jboss.pnc.spi.builddriver.BuildDriverResult)6 Consumer (java.util.function.Consumer)5 Inject (javax.inject.Inject)5 RepositoryManagerResult (org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 Set (java.util.Set)4 Configuration (org.jboss.pnc.common.Configuration)4 BuildDriverFactory (org.jboss.pnc.executor.servicefactories.BuildDriverFactory)4 EnvironmentDriverFactory (org.jboss.pnc.executor.servicefactories.EnvironmentDriverFactory)4 RepositoryManagerFactory (org.jboss.pnc.executor.servicefactories.RepositoryManagerFactory)4