use of org.jboss.pnc.model.BuildRecord in project pnc by project-ncl.
the class DefaultBuildCoordinator method completeBuild.
public void completeBuild(BuildTask buildTask, BuildResult buildResult) {
String buildTaskId = buildTask.getId();
BuildCoordinationStatus coordinationStatus = BuildCoordinationStatus.SYSTEM_ERROR;
try {
if (buildResult.hasFailed()) {
CompletionStatus operationCompletionStatus = buildResult.getCompletionStatus();
switch(operationCompletionStatus) {
case SYSTEM_ERROR:
ProcessException exception;
if (buildResult.getProcessException().isPresent()) {
exception = buildResult.getProcessException().get();
log.debug("[buildTaskId: {}] Storing build result with exception {}.", buildTaskId, exception.getMessage());
} else if (buildResult.getRepourResult().isPresent()) {
RepourResult repourResult = buildResult.getRepourResult().get();
if (repourResult.getCompletionStatus().isFailed()) {
exception = new ProcessException("Repour completed with system error.");
log.debug("[buildTaskId: {}] Storing build result with system error from repour: {}.", buildTaskId, repourResult.getLog());
} else {
exception = new ProcessException("Build completed with system error but no exception.");
log.error("[buildTaskId: {}] Storing build result with system_error and missing exception.", buildTaskId);
}
} else {
exception = new ProcessException("Build completed with system error but no exception and no Repour result.");
log.error("[buildTaskId: {}] Storing build result with system_error no exception and no Repour result.", buildTaskId);
}
datastoreAdapter.storeResult(buildTask, Optional.of(buildResult), exception);
coordinationStatus = BuildCoordinationStatus.SYSTEM_ERROR;
break;
case CANCELLED:
case TIMED_OUT:
log.debug("[buildTaskId: {}] Storing failed build result. FailedReasonStatus: {}", buildTaskId, operationCompletionStatus);
datastoreAdapter.storeResult(buildTask, buildResult);
coordinationStatus = BuildCoordinationStatus.CANCELLED;
break;
case FAILED:
log.debug("[buildTaskId: {}] Storing failed build result. FailedReasonStatus: {}", buildTaskId, operationCompletionStatus);
datastoreAdapter.storeResult(buildTask, buildResult);
coordinationStatus = BuildCoordinationStatus.DONE_WITH_ERRORS;
break;
case SUCCESS:
throw new BuildCoordinationException("Failed task with SUCCESS completion status ?!.");
}
} else {
log.debug("[buildTaskId: {}] Storing success build result.", buildTaskId);
BuildRecord buildRecord = datastoreAdapter.storeResult(buildTask, buildResult);
if (buildRecord.getStatus().completedSuccessfully()) {
coordinationStatus = BuildCoordinationStatus.DONE;
} else {
log.warn("[buildTaskId: {}] Something went wrong while storing the success result. The status has changed to {}.", buildTaskId, buildRecord.getStatus());
coordinationStatus = BuildCoordinationStatus.SYSTEM_ERROR;
}
}
updateBuildTaskStatus(buildTask, coordinationStatus);
} catch (Throwable e) {
log.error("[buildTaskId: " + buildTaskId + "] Cannot store results to datastore.", e);
updateBuildTaskStatus(buildTask, BuildCoordinationStatus.SYSTEM_ERROR);
} finally {
// Starts when the build execution completes
ProcessStageUtils.logProcessStageEnd("FINALIZING_BUILD", "Finalizing completed.");
}
}
use of org.jboss.pnc.model.BuildRecord in project pnc by project-ncl.
the class DefaultBuildCoordinatorTest method shouldStoreSshCredentialsOnSshEnabled.
@Test
public void shouldStoreSshCredentialsOnSshEnabled() throws DatastoreException {
BuildTask buildTask = mockBuildTask();
BuildResult buildResult = mockBuildResult(true);
SshCredentials sshCredentials = new SshCredentials();
sshCredentials.setCommand(RandomStringUtils.randomAlphabetic(30));
sshCredentials.setPassword(RandomStringUtils.randomAlphabetic(30));
when(buildResult.getEnvironmentDriverResult()).thenReturn(Optional.of(new EnvironmentDriverResult(CompletionStatus.FAILED, "", Optional.of(sshCredentials))));
when(buildResult.getRepourResult()).thenReturn(Optional.of(RepourResultMock.mock()));
ArgumentGrabbingAnswer<BuildRecord.Builder> answer = new ArgumentGrabbingAnswer<>(BuildRecord.Builder.class);
when(datastore.storeCompletedBuild(any(BuildRecord.Builder.class), any(), any())).thenAnswer(answer);
coordinator.completeBuild(buildTask, buildResult);
assertThat(answer.arguments).hasSize(1);
BuildRecord.Builder builder = answer.arguments.iterator().next();
BuildRecord record = builder.build();
assertThat(record.getSshCommand()).isEqualTo(sshCredentials.getCommand());
assertThat(record.getSshPassword()).isEqualTo(sshCredentials.getPassword());
}
use of org.jboss.pnc.model.BuildRecord in project pnc by project-ncl.
the class BuildResultPushManagerTest method buildRecord.
private BuildRecord buildRecord(boolean withExecutionRootName) {
BuildRecord record = new BuildRecord();
record.setId(new Base32LongID(Sequence.nextId()));
record.setStatus(BuildStatus.SUCCESS);
record.setBuildConfigurationAudited(bca);
record.setDependencies(Collections.emptySet());
record.setStartTime(new Date());
record.setEndTime(new Date());
record.setScmRepoURL("https://example.com/foo.git");
record.setScmRevision("abcdef012345");
if (withExecutionRootName) {
record.setExecutionRootName("execution:root");
}
buildRecordRepository.save(record);
return record;
}
use of org.jboss.pnc.model.BuildRecord in project pnc by project-ncl.
the class BuildResultPushManagerTest method shouldAccept.
@Test
public void shouldAccept() {
// given
BuildRecord record = buildRecord(true);
record.setExecutionRootName("Foo:bar");
record.setExecutionRootVersion("baz");
// when
Result result = release(record);
// then
assertThat(result).extracting(Result::getStatus).isEqualTo(BuildPushStatus.ACCEPTED);
}
use of org.jboss.pnc.model.BuildRecord in project pnc by project-ncl.
the class BuildResultPushManagerTest method shouldRejectWhenSameBuildIdIsInProgress.
@Test
public void shouldRejectWhenSameBuildIdIsInProgress() {
// given
BuildRecord record = buildRecord(true);
// when
release(record);
Result result = release(record);
// then
assertThat(result).extracting(Result::getStatus).isEqualTo(BuildPushStatus.REJECTED);
}
Aggregations