use of org.jboss.pnc.enums.BuildStatus in project pnc by project-ncl.
the class ProjectBuilder method buildProject.
BuildTask buildProject(BuildConfiguration buildConfiguration, BuildCoordinator buildCoordinator, Consumer<BuildStatusChangedEvent> onStatusUpdate, BuildOptions buildOptions) throws BuildConflictException, InterruptedException, CoreException {
log.debug("Building project {}", buildConfiguration.getName());
List<BuildStatusChangedEvent> receivedStatuses = new CopyOnWriteArrayList<>();
Consumer<BuildStatusChangedEvent> onStatusUpdateInternal = (statusUpdate) -> {
receivedStatuses.add(statusUpdate);
onStatusUpdate.accept(statusUpdate);
};
// Defines a number of callbacks, which are executed after buildStatus update
final Semaphore semaphore = registerReleaseListenersAndAcquireSemaphore(onStatusUpdateInternal, N_STATUS_UPDATES_PER_TASK);
BuildSetTask taskSet = buildCoordinator.build(buildConfiguration, MockUser.newTestUser(1), buildOptions);
Set<BuildTask> buildTasks = taskSet.getBuildTasks();
assertThat(buildTasks).hasSize(1);
BuildTask buildTask = buildTasks.iterator().next();
log.info("Started build task {}", buildTask);
assertBuildStartedSuccessfully(buildTask);
waitForStatusUpdates(N_STATUS_UPDATES_PER_TASK, semaphore, "");
return buildTask;
}
use of org.jboss.pnc.enums.BuildStatus in project pnc by project-ncl.
the class DefaultBuildExecutor method retrieveBuildDriverResults.
private Void retrieveBuildDriverResults(BuildExecutionSession buildExecutionSession, CompletedBuild completedBuild) {
if (completedBuild == null) {
userLog.warn("Unable to retrieve build driver results. Most likely due to cancelled operation.");
return null;
}
try {
buildExecutionSession.setStatus(BuildExecutionStatus.COLLECTING_RESULTS_FROM_BUILD_DRIVER);
BuildDriverResult buildResult = completedBuild.getBuildResult();
BuildStatus buildStatus = buildResult.getBuildStatus();
buildExecutionSession.setBuildDriverResult(buildResult);
if (buildStatus.completedSuccessfully()) {
userLog.info("Build successfully completed.");
buildExecutionSession.setStatus(BuildExecutionStatus.BUILD_COMPLETED_SUCCESS);
} else if (buildStatus.equals(BuildStatus.CANCELLED)) {
userLog.info("Build has been canceled.");
buildExecutionSession.setStatus(BuildExecutionStatus.CANCELLED);
} else {
userLog.warn("Build completed with errors.");
buildExecutionSession.setStatus(BuildExecutionStatus.BUILD_COMPLETED_WITH_ERROR);
}
return null;
} catch (Throwable e) {
throw new BuildProcessException(e, completedBuild.getRunningEnvironment());
}
}
use of org.jboss.pnc.enums.BuildStatus in project pnc by project-ncl.
the class DatastoreAdapterTest method shouldStoreRepositoryManagerError.
@Test
public void shouldStoreRepositoryManagerError() throws DatastoreException {
// given
DatastoreMock datastore = new DatastoreMock();
DatastoreAdapter datastoreAdapter = new DatastoreAdapter(datastore);
BuildStatus buildStatus = BuildStatus.SUCCESS;
CompletionStatus completionStatus = CompletionStatus.FAILED;
// when
storeResult(datastoreAdapter, buildStatus, completionStatus);
// then
List<BuildRecord> buildRecords = datastore.getBuildRecords();
Assert.assertEquals(1, buildRecords.size());
BuildRecord buildRecord = buildRecords.get(0);
Assert.assertEquals(BuildStatus.FAILED, buildRecord.getStatus());
Assert.assertTrue(buildRecord.getBuildLog().contains(BUILD_LOG));
Assert.assertTrue(buildRecord.getBuildLog().contains(REPOSITORY_MANAGER_LOG));
}
use of org.jboss.pnc.enums.BuildStatus in project pnc by project-ncl.
the class BuildExecutorMock method startBuilding.
// @Deprecated //CDI workaround
// public BuildExecutorMock() {
// }
//
// @Inject
// public BuildExecutorMock(RepositoryManagerFactory repositoryManagerFactory, BuildDriverFactory
// buildDriverFactory, EnvironmentDriverFactory environmentDriverFactory, Configuration configuration) {
//
// }
@Override
public BuildExecutionSession startBuilding(BuildExecutionConfiguration buildExecutionConfiguration, Consumer<BuildExecutionStatusChangedEvent> onBuildExecutionStatusChangedEvent, String accessToken) throws ExecutorException {
log.info("Starting mock build execution for buildExecutionConfiguration.id {}", buildExecutionConfiguration.getId());
BuildExecutionSession buildExecutionSession = new BuildExecutionSessionMock(buildExecutionConfiguration, onBuildExecutionStatusChangedEvent);
buildExecutionSession.setStatus(BuildExecutionStatus.NEW);
runningExecutions.put(buildExecutionConfiguration.getId(), buildExecutionSession);
Consumer<BuildExecutionStatus> onCompleteInternal = (buildStatus) -> {
log.debug("Removing buildExecutionConfiguration.id [" + buildExecutionConfiguration.getId() + "] form list of running tasks.");
runningExecutions.remove(buildExecutionConfiguration.getId());
buildExecutionSession.setStatus(buildStatus);
};
CompletableFuture<Integer> future = CompletableFuture.supplyAsync(() -> mockBuild(buildExecutionSession), executor).handleAsync((buildPassed, e) -> complete(buildPassed, e, onCompleteInternal), executor);
runningFutures.put(buildExecutionConfiguration.getId(), future);
return buildExecutionSession;
}
use of org.jboss.pnc.enums.BuildStatus in project pnc by project-ncl.
the class TermdBuildDriver method collectResults.
private CompletedBuild collectResults(RunningEnvironment runningEnvironment, RemoteInvocationCompletion remoteInvocationCompletion, FileTransfer transfer) {
logger.info("Collecting results ...");
try {
StringBuffer stringBuffer = new StringBuffer();
String logsDirectory = runningEnvironment.getWorkingDirectory().toString();
transfer.downloadFileToStringBuilder(stringBuffer, logsDirectory + "/console.log");
String prependMessage = "";
BuildStatus buildStatus = getBuildStatus(remoteInvocationCompletion.getStatus());
if (!transfer.isFullyDownloaded()) {
prependMessage = "----- build log was cut -----\n";
if (buildStatus.completedSuccessfully()) {
prependMessage = "----- build has completed successfully but it is marked as failed due to log overflow. Max log size is " + MAX_LOG_SIZE + " -----\n";
buildStatus = BuildStatus.FAILED;
}
}
return new DefaultCompletedBuild(runningEnvironment, buildStatus, remoteInvocationCompletion.getOutputChecksum(), prependMessage + stringBuffer.toString());
} catch (Throwable e) {
throw new RuntimeException("Cannot collect results.", e);
}
}
Aggregations