use of org.jboss.pnc.spi.repour.RepourResult in project pnc by project-ncl.
the class BuildResultMapper method toDTO.
public BuildResultRest toDTO(BuildResult buildResult) {
CompletionStatus completionStatus = buildResult.getCompletionStatus();
ProcessException processException = buildResult.getProcessException().orElse(null);
String processLog = buildResult.getProcessLog();
BuildExecutionConfigurationRest buildExecutionConfiguration;
if (buildResult.getBuildExecutionConfiguration().isPresent()) {
BuildExecutionConfiguration bec = buildResult.getBuildExecutionConfiguration().get();
buildExecutionConfiguration = new BuildExecutionConfigurationRest(bec);
} else {
buildExecutionConfiguration = null;
}
BuildDriverResultRest buildDriverResult;
if (buildResult.getBuildDriverResult().isPresent()) {
BuildDriverResult result = buildResult.getBuildDriverResult().get();
buildDriverResult = new BuildDriverResultRest(result);
} else {
buildDriverResult = null;
}
RepositoryManagerResultRest repositoryManagerResult;
if (buildResult.getRepositoryManagerResult().isPresent()) {
RepositoryManagerResult result = buildResult.getRepositoryManagerResult().get();
repositoryManagerResult = repositoryManagerResultMapper.toDTO(result);
} else {
repositoryManagerResult = null;
}
EnvironmentDriverResult environmentDriverResult;
if (buildResult.getEnvironmentDriverResult().isPresent()) {
environmentDriverResult = buildResult.getEnvironmentDriverResult().get();
} else {
environmentDriverResult = null;
}
RepourResult repourResult = buildResult.getRepourResult().orElse(null);
return new BuildResultRest(completionStatus, processException, processLog, buildExecutionConfiguration, buildDriverResult, repositoryManagerResult, environmentDriverResult, repourResult);
}
use of org.jboss.pnc.spi.repour.RepourResult 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.repour.RepourResult in project pnc by project-ncl.
the class DatastoreAdapter method storeResult.
public BuildRecord storeResult(BuildTask buildTask, BuildResult buildResult) throws DatastoreException {
try {
BuildStatus buildRecordStatus = NEW;
BuildRecord.Builder buildRecordBuilder = initBuildRecordBuilder(buildTask);
buildRecordBuilder.buildContentId(buildTask.getContentId());
if (buildResult.getRepourResult().isPresent()) {
RepourResult repourResult = buildResult.getRepourResult().get();
buildRecordBuilder.repourLog(repourResult.getLog());
buildRecordBuilder.executionRootName(repourResult.getExecutionRootName());
buildRecordBuilder.executionRootVersion(repourResult.getExecutionRootVersion());
CompletionStatus repourCompletionStatus = repourResult.getCompletionStatus();
if (repourCompletionStatus != null) {
switch(repourCompletionStatus) {
case SUCCESS:
case NO_REBUILD_REQUIRED:
break;
case FAILED:
buildRecordBuilder.appendLog("\nBuild failed during the alignment phase, please check the 'Alignment Log' tab for more information.\n");
buildRecordStatus = FAILED;
break;
case CANCELLED:
buildRecordBuilder.appendLog("\nBuild cancelled during alignment phase.\n");
buildRecordStatus = CANCELLED;
break;
case TIMED_OUT:
buildRecordBuilder.appendLog("\nBuild timed-out during alignment phase.\n");
buildRecordStatus = SYSTEM_ERROR;
break;
case SYSTEM_ERROR:
buildRecordBuilder.appendLog("\nBuild failed with SYSTEM_ERROR during the alignment phase, " + "please check the 'Alignment Log' tab for more information.\n");
buildRecordStatus = SYSTEM_ERROR;
break;
default:
buildRecordBuilder.appendLog("\nInvalid status during the alignment phase, failing with SYSTEM_ERROR.\n");
buildRecordStatus = SYSTEM_ERROR;
break;
}
}
} else {
userLog.warn("Missing Repour Result!");
log.warn("[BuildTask:" + buildTask.getId() + "] Missing RepourResult.");
}
if (buildResult.getBuildDriverResult().isPresent()) {
BuildDriverResult buildDriverResult = buildResult.getBuildDriverResult().get();
buildRecordBuilder.appendLog(buildDriverResult.getBuildLog());
buildDriverResult.getOutputChecksum().ifPresent(buildRecordBuilder::buildOutputChecksum);
// TODO buildRecord should use CompletionStatus
buildRecordStatus = buildDriverResult.getBuildStatus();
} else if (!buildResult.hasFailed()) {
return storeResult(buildTask, Optional.of(buildResult), new BuildCoordinationException("Trying to store success build with incomplete result. Missing BuildDriverResult."));
}
if (buildResult.getEnvironmentDriverResult().isPresent()) {
EnvironmentDriverResult environmentDriverResult = buildResult.getEnvironmentDriverResult().get();
buildRecordBuilder.appendLog(environmentDriverResult.getLog());
environmentDriverResult.getSshCredentials().ifPresent(c -> {
buildRecordBuilder.sshCommand(c.getCommand());
buildRecordBuilder.sshPassword(c.getPassword());
});
if (environmentDriverResult.getCompletionStatus() != null) {
switch(environmentDriverResult.getCompletionStatus()) {
case SUCCESS:
case NO_REBUILD_REQUIRED:
break;
case FAILED:
buildRecordStatus = FAILED;
break;
case CANCELLED:
buildRecordStatus = CANCELLED;
break;
case TIMED_OUT:
case SYSTEM_ERROR:
buildRecordStatus = SYSTEM_ERROR;
break;
default:
buildRecordBuilder.appendLog("\nInvalid status during the environment setup phase, failing with SYSTEM_ERROR.\n");
buildRecordStatus = SYSTEM_ERROR;
break;
}
}
}
List<Artifact> builtArtifacts = Collections.emptyList();
List<Artifact> dependencies = Collections.emptyList();
if (buildResult.getRepositoryManagerResult().isPresent()) {
RepositoryManagerResult repositoryManagerResult = buildResult.getRepositoryManagerResult().get();
buildRecordBuilder.appendLog(repositoryManagerResult.getLog());
if (repositoryManagerResult.getCompletionStatus() != null) {
switch(// TODO, do not mix statuses
repositoryManagerResult.getCompletionStatus()) {
case SUCCESS:
case NO_REBUILD_REQUIRED:
break;
case FAILED:
buildRecordStatus = FAILED;
break;
case CANCELLED:
buildRecordStatus = CANCELLED;
break;
case TIMED_OUT:
case SYSTEM_ERROR:
buildRecordStatus = SYSTEM_ERROR;
break;
default:
buildRecordBuilder.appendLog("\nInvalid status during the promotion phase, failing with SYSTEM_ERROR.\n");
buildRecordStatus = SYSTEM_ERROR;
break;
}
}
builtArtifacts = repositoryManagerResult.getBuiltArtifacts();
Map<Artifact, String> builtConflicts = datastore.checkForBuiltArtifacts(builtArtifacts);
if (builtConflicts.size() > 0) {
return storeResult(buildTask, Optional.of(buildResult), new BuildCoordinationException("Trying to store success build with invalid repository manager result. Conflicting artifact data found: " + builtConflicts.toString()));
}
dependencies = repositoryManagerResult.getDependencies();
} else if (!buildResult.hasFailed()) {
return storeResult(buildTask, Optional.of(buildResult), new BuildCoordinationException("Trying to store success build with incomplete result. Missing RepositoryManagerResult."));
}
if (NEW.equals(buildRecordStatus)) {
switch(buildResult.getCompletionStatus()) {
case SUCCESS:
case NO_REBUILD_REQUIRED:
case FAILED:
case SYSTEM_ERROR:
break;
case CANCELLED:
buildRecordStatus = CANCELLED;
break;
case TIMED_OUT:
buildRecordStatus = SYSTEM_ERROR;
buildRecordBuilder.appendLog("-- Operation TIMED-OUT --");
userLog.warn("Operation TIMED-OUT.");
break;
default:
buildRecordBuilder.appendLog("\nInvalid status detected in the final completion status, failing with SYSTEM_ERROR.\n");
break;
}
}
log.debug("Setting status " + buildRecordStatus.toString() + " to buildRecord.");
buildRecordBuilder.status(buildRecordStatus);
if (buildResult.getBuildExecutionConfiguration().isPresent()) {
BuildExecutionConfiguration buildExecutionConfig = buildResult.getBuildExecutionConfiguration().get();
buildRecordBuilder.scmRepoURL(buildExecutionConfig.getScmRepoURL());
buildRecordBuilder.scmRevision(buildExecutionConfig.getScmRevision());
buildRecordBuilder.scmTag(buildExecutionConfig.getScmTag());
} else if (!buildResult.hasFailed()) {
return storeResult(buildTask, Optional.of(buildResult), new BuildCoordinationException("Trying to store success build with incomplete result. Missing BuildExecutionConfiguration."));
}
log.debug("Storing results of buildTask [{}] to datastore.", buildTask.getId());
userLog.info("Successfully completed.");
return datastore.storeCompletedBuild(buildRecordBuilder, builtArtifacts, dependencies);
} catch (Exception e) {
return storeResult(buildTask, Optional.of(buildResult), e);
}
}
use of org.jboss.pnc.spi.repour.RepourResult 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.spi.repour.RepourResult in project pnc by project-ncl.
the class BuildResultRestTest method shouldGetLimitedToStringWithSomeValues.
@Test
public void shouldGetLimitedToStringWithSomeValues() {
BuildResultRest buildResultRest = new BuildResultRest();
buildResultRest.setCompletionStatus(CompletionStatus.SUCCESS);
buildResultRest.setProcessException(null);
buildResultRest.setProcessLog(LOG);
buildResultRest.setBuildExecutionConfiguration(null);
buildResultRest.setBuildDriverResult(null);
buildResultRest.setRepositoryManagerResult(null);
EnvironmentDriverResult environmentDriverResult = new EnvironmentDriverResult(CompletionStatus.SUCCESS, "SUCCESS", Optional.empty());
buildResultRest.setEnvironmentDriverResult(environmentDriverResult);
buildResultRest.setRepourResult(new RepourResult(CompletionStatus.SUCCESS, "Repour Success", "org.jboss", "1.1.0.Final-redhat-1"));
buildResultRest.toString();
}
Aggregations