use of org.jboss.pnc.spi.coordinator.BuildTask in project pnc by project-ncl.
the class BuildTaskEndpointImpl method buildTaskCompleted.
@Override
public Response buildTaskCompleted(String buildId, BuildResultRest buildResult) throws InvalidEntityException {
// TODO set MDC from request headers instead of business data
// logger.debug("Received task completed notification for coordinating task id [{}].", buildId);
// BuildExecutionConfigurationRest buildExecutionConfiguration = buildResult.getBuildExecutionConfiguration();
// buildResult.getRepositoryManagerResult().getBuildContentId();
// if (buildExecutionConfiguration == null) {
// logger.error("Missing buildExecutionConfiguration in buildResult for buildTaskId [{}].", buildId);
// throw new CoreException("Missing buildExecutionConfiguration in buildResult for buildTaskId " + buildId);
// }
// MDCUtils.addContext(buildExecutionConfiguration.getBuildContentId(),
// buildExecutionConfiguration.isTempBuild(), systemConfig.getTemporaryBuildExpireDate());
logger.info("Received build task completed notification for id {}.", buildId);
ValidationBuilder.validateObject(buildResult, WhenCreatingNew.class).validateAnnotations();
// check if task is already completed
// required workaround as we don't remove the BpmTasks immediately after the completion
Optional<BuildTask> maybeBuildTask = buildCoordinator.getSubmittedBuildTask(buildId);
if (maybeBuildTask.isPresent()) {
BuildTask buildTask = maybeBuildTask.get();
boolean temporaryBuild = buildTask.getBuildOptions().isTemporaryBuild();
MDCUtils.addBuildContext(buildTask.getContentId(), temporaryBuild, ExpiresDate.getTemporaryBuildExpireDate(systemConfig.getTemporaryBuildsLifeSpan(), temporaryBuild), userService.currentUser().getId().toString());
try {
if (buildTask.getStatus().isCompleted()) {
logger.warn("BuildTask with id: {} is already completed with status: {}", buildTask.getId(), buildTask.getStatus());
return Response.status(Response.Status.GONE).entity("BuildTask with id: " + buildTask.getId() + " is already completed with status: " + buildTask.getStatus() + ".").build();
}
if (logger.isTraceEnabled()) {
logger.trace("Received build result wit full log: {}.", buildResult.toFullLogString());
}
logger.debug("Completing buildTask [{}] ...", buildId);
buildCoordinator.completeBuild(buildTask, mapper.toEntity(buildResult));
logger.debug("Completed buildTask [{}].", buildId);
return Response.ok().build();
} finally {
MDCUtils.removeBuildContext();
}
} else {
return Response.status(Response.Status.NOT_FOUND).entity("No active build with id: " + buildId).build();
}
}
use of org.jboss.pnc.spi.coordinator.BuildTask in project pnc by project-ncl.
the class BuildProviderImplTest method dependencyGraphTest.
@Test
public void dependencyGraphTest() {
// given
BuildTask bt100002 = mock(BuildTask.class);
when(bt100002.getId()).thenReturn("100002");
BuildTask bt110000 = mock(BuildTask.class);
when(bt110000.getId()).thenReturn("110000");
when(bt110000.getDependencies()).thenReturn(Collections.emptySet());
when(bt110000.getDependants()).thenReturn(Collections.singleton(bt100002));
runningBuilds.add(bt110000);
mockBuildRecord(new Base32LongID(100000L), new Long[] { 100002L }, new Long[] {});
mockBuildRecord(new Base32LongID(100001L), new Long[] { 100002L }, new Long[] {});
BuildRecord currentBuild = mockBuildRecord(new Base32LongID(100002L), new Long[] { 100003L, 100005L, 100006L }, new Long[] { 100000L, 100001L, Long.valueOf(bt110000.getId()) });
BuildRecord buildRecord100003 = mockBuildRecord(new Base32LongID(100003L), new Long[] { 100004L }, new Long[] { 100002L });
mockBuildRecord(new Base32LongID(100004L), new Long[] {}, new Long[] { 100003L });
mockBuildRecord(new Base32LongID(100005L), new Long[] {}, new Long[] { 100002L });
mockBuildRecord(new Base32LongID(100006L), new Long[] {}, new Long[] { 100002L });
// when
Graph<Build> dependencyGraph = provider.getDependencyGraph(bt100002.getId());
// then
logger.info("Graph: {}", dependencyGraph.toString());
assertEquals(8, dependencyGraph.getVertices().size());
Vertex<Build> vertex = getBuildVertexByName(dependencyGraph, BuildMapper.idMapper.toDto(currentBuild.getId()));
Build build = vertex.getData();
assertEquals(BuildMapper.idMapper.toDto(currentBuild.getId()), build.getId());
assertEquals(4, getOutgoingEdges(dependencyGraph, vertex).count());
assertEquals(3, getIncommingEdges(dependencyGraph, vertex).count());
Vertex<Build> vertex3 = getBuildVertexByName(dependencyGraph, BuildMapper.idMapper.toDto(buildRecord100003.getId()));
assertEquals(1, getOutgoingEdges(dependencyGraph, vertex3).count());
assertEquals(1, getIncommingEdges(dependencyGraph, vertex3).count());
// then from running build
Graph<Build> dependencyGraphFromRunning = provider.getDependencyGraph(bt110000.getId());
Vertex<Build> runningVertex = getBuildVertexByName(dependencyGraphFromRunning, bt110000.getId());
assertEquals(1, getOutgoingEdges(dependencyGraphFromRunning, runningVertex).count());
assertEquals(1, getIncommingEdges(dependencyGraphFromRunning, runningVertex).count());
}
use of org.jboss.pnc.spi.coordinator.BuildTask in project pnc by project-ncl.
the class BuildProviderImplTest method mockBuildTaskWithSet.
private BuildTask mockBuildTaskWithSet(BuildSetTask buildSetTask) {
BuildTask task = mockBuildTask();
when(task.getBuildSetTask()).thenReturn(buildSetTask);
when(task.getUser()).thenReturn(mock(User.class));
return task;
}
use of org.jboss.pnc.spi.coordinator.BuildTask in project pnc by project-ncl.
the class BuildProviderImplTest method testFailFilterLikeRunningBuildsByBuildConfigName.
@Test
public void testFailFilterLikeRunningBuildsByBuildConfigName() {
// Given
mockBuildRecord();
mockBuildTask();
String givenBcName = "VeryLongAndComplicatedBcName";
String givenBcNamePattern = "LongAndComplicated*";
BuildTask givenBT = mockBuildTask(givenBcName);
// When
BuildPageInfo pageInfo = new BuildPageInfo(0, 2, "", "", false, true, givenBcNamePattern);
Page<Build> builds = provider.getBuilds(pageInfo);
// Then
assertEquals(0, builds.getTotalHits());
}
use of org.jboss.pnc.spi.coordinator.BuildTask in project pnc by project-ncl.
the class BuildProviderImplTest method shouldGetGraphWithDependencies.
@Test
public void shouldGetGraphWithDependencies() {
// With
Integer buildSetTaskId = 1;
BuildSetTask buildSetTask = mock(BuildSetTask.class);
when(buildSetTask.getId()).thenReturn(buildSetTaskId);
BuildTask task = mockBuildTaskWithSet(buildSetTask);
BuildTask taskDep = mockBuildTaskWithSet(buildSetTask);
BuildTask taskDepDep = mockBuildTaskWithSet(buildSetTask);
when(task.getDependencies()).thenReturn(asSet(taskDep));
when(taskDep.getDependencies()).thenReturn(asSet(taskDepDep));
// When
Graph<Build> graph = provider.getBuildGraphForGroupBuild(Integer.toString(buildSetTaskId));
// Then
assertThat(graph.getVertices()).hasSize(3);
List<String> buildTaskIDsOrderedByBCName = Stream.of(task, taskDep, taskDepDep).sorted(Comparator.comparing(t -> t.getBuildConfigurationAudited().getName())).map(t -> t.getId()).collect(Collectors.toList());
assertThat(graph.getVertices().values().stream().map(Vertex::getName)).containsExactlyElementsOf(buildTaskIDsOrderedByBCName);
}
Aggregations