Search in sources :

Example 11 with BuildResult

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

the class DefaultBuildCoordinator method cancelInternal.

private void cancelInternal(BuildTask buildTask) {
    BuildResult result = new BuildResult(CompletionStatus.CANCELLED, Optional.empty(), "", Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty());
    completeBuild(buildTask, result);
    // TODO 2.0 completeNoBuild(buildTask, CompletionStatus.CANCELLED); NCL-4242
    log.info("Task {} canceled internally.", buildTask.getId());
}
Also used : BuildResult(org.jboss.pnc.spi.BuildResult)

Example 12 with BuildResult

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

the class BuildResultSerializationTest method serializeAndDeserializeBuildResult.

@Test
public void serializeAndDeserializeBuildResult() throws IOException, BuildDriverException {
    BuildResult buildResult = BuildResultMock.mock(BuildStatus.SUCCESS);
    BuildResultRest buildResultRest = buildResultMapper.toDTO(buildResult);
    String buildResultJson = buildResultRest.toFullLogString();
    log.debug("BuildResultJson : {}", buildResultJson);
    BuildResultRest buildResultRestFromJson = JsonOutputConverterMapper.readValue(buildResultJson, BuildResultRest.class);
    BuildResult buildResultFromJson = buildResultMapper.toEntity(buildResultRestFromJson);
    String message = "Deserialized object does not match the original.";
    Assert.assertEquals(message, buildResult.hasFailed(), buildResultFromJson.hasFailed());
    Assert.assertEquals(message, buildResult.getCompletionStatus(), buildResultFromJson.getCompletionStatus());
    Assert.assertEquals(message, buildResult.getProcessException().get().getMessage(), buildResultFromJson.getProcessException().get().getMessage());
    Assert.assertEquals(message, buildResult.getBuildExecutionConfiguration().get().getId(), buildResultFromJson.getBuildExecutionConfiguration().get().getId());
    Assert.assertEquals(message, buildResult.getRepositoryManagerResult().get().getBuildContentId(), buildResultFromJson.getRepositoryManagerResult().get().getBuildContentId());
    Assert.assertEquals(message, buildResult.getRepositoryManagerResult().get().getBuiltArtifacts().get(0).getId(), buildResultFromJson.getRepositoryManagerResult().get().getBuiltArtifacts().get(0).getId());
    Assert.assertEquals(message, buildResult.getBuildDriverResult().get().getBuildLog(), buildResultFromJson.getBuildDriverResult().get().getBuildLog());
    Assert.assertEquals(message, buildResult.getBuildDriverResult().get().getBuildStatus(), buildResultFromJson.getBuildDriverResult().get().getBuildStatus());
    Assert.assertEquals(message, buildResult.getRepourResult().get().getCompletionStatus(), buildResultFromJson.getRepourResult().get().getCompletionStatus());
    Assert.assertEquals(message, buildResult.getRepourResult().get().getExecutionRootName(), buildResultFromJson.getRepourResult().get().getExecutionRootName());
    Assert.assertEquals(message, buildResult.getEnvironmentDriverResult().get().getCompletionStatus(), buildResultFromJson.getEnvironmentDriverResult().get().getCompletionStatus());
    Assert.assertEquals(message, buildResult.getEnvironmentDriverResult().get().getSshCredentials().get().getCommand(), buildResultFromJson.getEnvironmentDriverResult().get().getSshCredentials().get().getCommand());
}
Also used : BuildResultRest(org.jboss.pnc.bpm.model.BuildResultRest) BuildResult(org.jboss.pnc.spi.BuildResult) Test(org.junit.Test)

Example 13 with BuildResult

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

the class LocalBuildScheduler method startBuilding.

@Override
public void startBuilding(BuildTask buildTask) throws CoreException {
    Consumer<BuildExecutionStatusChangedEvent> onBuildExecutionStatusChangedEvent = (statusChangedEvent) -> {
        try {
            log.debug("Received execution status update {}.", statusChangedEvent);
            if (statusChangedEvent.getNewStatus().isCompleted()) {
                BuildResult buildResult = statusChangedEvent.getBuildResult().get();
                log.debug("Notifying build execution completed {}.", statusChangedEvent);
                buildCoordinator.completeBuild(buildTask, buildResult);
            }
        } catch (Throwable t) {
            log.error("Failed to notify build completion.", t);
        }
    };
    String contentId = ContentIdentityManager.getBuildContentId(buildTask.getId());
    BuildConfigurationAudited configuration = buildTask.getBuildConfigurationAudited();
    BuildExecutionConfiguration buildExecutionConfiguration = BuildExecutionConfiguration.build(buildTask.getId(), contentId, buildTask.getUser().getId().toString(), configuration.getBuildScript(), configuration.getId().toString(), configuration.getName(), configuration.getRepositoryConfiguration().getInternalUrl(), configuration.getScmRevision(), null, configuration.getRepositoryConfiguration().getExternalUrl(), configuration.getRepositoryConfiguration().isPreBuildSyncEnabled(), configuration.getBuildEnvironment().getSystemImageId(), configuration.getBuildEnvironment().getSystemImageRepositoryUrl(), configuration.getBuildEnvironment().getSystemImageType(), configuration.getBuildType(), buildTask.getBuildOptions().isKeepPodOnFailure(), configuration.getGenericParameters(), buildTask.getBuildOptions().isTemporaryBuild(), TimeUtils.generateTimestamp(buildTask.getBuildOptions().isTimestampAlignment(), buildTask.getBuildSetTask().getStartTime()), configuration.isBrewPullActive(), configuration.getDefaultAlignmentParams(), buildTask.getBuildOptions().getAlignmentPreference());
    try {
        buildExecutor.startBuilding(buildExecutionConfiguration, onBuildExecutionStatusChangedEvent, buildTask.getUser().getLoginToken());
    } catch (ExecutorException e) {
        throw new CoreException("Could not start build execution.", e);
    }
}
Also used : TimeUtils(org.jboss.pnc.common.util.TimeUtils) Logger(org.slf4j.Logger) BuildScheduler(org.jboss.pnc.coordinator.builder.BuildScheduler) ContentIdentityManager(org.jboss.pnc.model.utils.ContentIdentityManager) BuildCoordinator(org.jboss.pnc.spi.coordinator.BuildCoordinator) BuildResult(org.jboss.pnc.spi.BuildResult) LoggerFactory(org.slf4j.LoggerFactory) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) BuildExecutor(org.jboss.pnc.spi.executor.BuildExecutor) BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) Inject(javax.inject.Inject) Consumer(java.util.function.Consumer) CoreException(org.jboss.pnc.spi.exception.CoreException) 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) BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) BuildResult(org.jboss.pnc.spi.BuildResult) ExecutorException(org.jboss.pnc.spi.executor.exceptions.ExecutorException) BuildExecutionConfiguration(org.jboss.pnc.spi.executor.BuildExecutionConfiguration) CoreException(org.jboss.pnc.spi.exception.CoreException) BuildExecutionStatusChangedEvent(org.jboss.pnc.spi.events.BuildExecutionStatusChangedEvent)

Example 14 with BuildResult

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

the class DatastoreAdapterTest method shouldStoreRepourResult.

@Test
public void shouldStoreRepourResult() throws DatastoreException {
    // given
    DatastoreMock datastore = new DatastoreMock();
    DatastoreAdapter datastoreAdapter = new DatastoreAdapter(datastore);
    RepourResult repourResult = RepourResultMock.mock();
    // when
    BuildConfiguration buildConfiguration = BuildConfiguration.Builder.newBuilder().name("Configuration.").build();
    BuildConfigurationAudited buildConfigurationAudited = BuildConfigurationAudited.Builder.newBuilder().buildConfiguration(buildConfiguration).build();
    BuildTask buildTask = mockBuildTask();
    BuildExecutionConfiguration buildExecutionConfiguration = mock(BuildExecutionConfiguration.class);
    BuildResult buildResult = new BuildResult(CompletionStatus.SUCCESS, Optional.empty(), "", Optional.of(buildExecutionConfiguration), Optional.of(BuildDriverResultMock.mockResult(BuildStatus.SUCCESS)), Optional.of(RepositoryManagerResultMock.mockResult()), Optional.of(EnvironmentDriverResultMock.mock()), Optional.of(repourResult));
    datastoreAdapter.storeResult(buildTask, buildResult);
    // then
    List<BuildRecord> buildRecords = datastore.getBuildRecords();
    Assert.assertEquals(1, buildRecords.size());
    BuildRecord buildRecord = buildRecords.get(0);
    Assert.assertEquals(buildRecord.getStatus(), BuildStatus.SUCCESS);
    Assert.assertEquals(repourResult.getExecutionRootName(), buildRecord.getExecutionRootName());
    Assert.assertEquals(repourResult.getExecutionRootVersion(), buildRecord.getExecutionRootVersion());
    Assert.assertEquals(repourResult.getLog(), buildRecord.getRepourLog());
}
Also used : BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) BuildResult(org.jboss.pnc.spi.BuildResult) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) BuildExecutionConfiguration(org.jboss.pnc.spi.executor.BuildExecutionConfiguration) DatastoreMock(org.jboss.pnc.mock.datastore.DatastoreMock) DatastoreAdapter(org.jboss.pnc.coordinator.builder.datastore.DatastoreAdapter) RepourResult(org.jboss.pnc.spi.repour.RepourResult) BuildRecord(org.jboss.pnc.model.BuildRecord) Test(org.junit.Test)

Example 15 with BuildResult

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

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