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());
}
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());
}
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);
}
}
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());
}
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));
}
Aggregations