use of com.facebook.buck.distributed.thrift.BuildJobStateTargetGraph in project buck by facebook.
the class DistBuildServiceTest method canUploadTargetGraph.
@Test
public void canUploadTargetGraph() throws IOException, ExecutionException, InterruptedException {
Capture<FrontendRequest> request = EasyMock.newCapture();
FrontendResponse response = new FrontendResponse();
response.setType(FrontendRequestType.STORE_BUILD_GRAPH);
response.setWasSuccessful(true);
EasyMock.expect(frontendService.makeRequest(EasyMock.capture(request))).andReturn(response).once();
EasyMock.replay(frontendService);
BuildJobState buildJobState = new BuildJobState();
List<BuildJobStateFileHashes> fileHashes = new ArrayList<>();
buildJobState.setFileHashes(fileHashes);
BuildJobStateTargetGraph graph = new BuildJobStateTargetGraph();
graph.setNodes(new ArrayList<BuildJobStateTargetNode>());
BuildJobStateTargetNode node1 = new BuildJobStateTargetNode();
node1.setRawNode("node1");
BuildJobStateTargetNode node2 = new BuildJobStateTargetNode();
node2.setRawNode("node1");
graph.addToNodes(node1);
graph.addToNodes(node2);
buildJobState.setTargetGraph(graph);
StampedeId stampedeId = new StampedeId();
stampedeId.setId("check-id");
distBuildService.uploadTargetGraph(buildJobState, stampedeId, executor).get();
Assert.assertTrue(request.getValue().isSetType());
Assert.assertEquals(request.getValue().getType(), FrontendRequestType.STORE_BUILD_GRAPH);
Assert.assertTrue(request.getValue().isSetStoreBuildGraphRequest());
Assert.assertTrue(request.getValue().getStoreBuildGraphRequest().isSetStampedeId());
Assert.assertEquals(request.getValue().getStoreBuildGraphRequest().getStampedeId(), stampedeId);
Assert.assertTrue(request.getValue().getStoreBuildGraphRequest().isSetBuildGraph());
BuildJobState sentState = BuildJobStateSerializer.deserialize(request.getValue().getStoreBuildGraphRequest().getBuildGraph());
Assert.assertTrue(buildJobState.equals(sentState));
}
use of com.facebook.buck.distributed.thrift.BuildJobStateTargetGraph in project buck by facebook.
the class DistBuildTargetGraphCodec method dump.
public BuildJobStateTargetGraph dump(Collection<TargetNode<?, ?>> targetNodes, Function<Path, Integer> cellIndexer) {
BuildJobStateTargetGraph result = new BuildJobStateTargetGraph();
for (TargetNode<?, ?> targetNode : targetNodes) {
Map<String, Object> rawTargetNode = nodeToRawNode.apply(targetNode);
ProjectFilesystem projectFilesystem = targetNode.getFilesystem();
BuildJobStateTargetNode remoteNode = new BuildJobStateTargetNode();
remoteNode.setCellIndex(cellIndexer.apply(projectFilesystem.getRootPath()));
remoteNode.setBuildTarget(encodeBuildTarget(targetNode.getBuildTarget()));
try {
remoteNode.setRawNode(objectMapper.writeValueAsString(rawTargetNode));
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
result.addToNodes(remoteNode);
}
return result;
}
use of com.facebook.buck.distributed.thrift.BuildJobStateTargetGraph in project buck by facebook.
the class DistBuildTargetGraphCodec method createTargetGraph.
public TargetGraphAndBuildTargets createTargetGraph(BuildJobStateTargetGraph remoteTargetGraph, Function<Integer, Cell> cellLookup) throws IOException {
ImmutableMap.Builder<BuildTarget, TargetNode<?, ?>> targetNodeIndexBuilder = ImmutableMap.builder();
ImmutableSet.Builder<BuildTarget> buildTargetsBuilder = ImmutableSet.builder();
for (BuildJobStateTargetNode remoteNode : remoteTargetGraph.getNodes()) {
Cell cell = cellLookup.apply(remoteNode.getCellIndex());
ProjectFilesystem projectFilesystem = cell.getFilesystem();
BuildTarget target = decodeBuildTarget(remoteNode.getBuildTarget(), cell);
if (topLevelTargets.contains(target.getFullyQualifiedName())) {
buildTargetsBuilder.add(target);
}
@SuppressWarnings("unchecked") Map<String, Object> rawNode = objectMapper.readValue(remoteNode.getRawNode(), Map.class);
Path buildFilePath = projectFilesystem.resolve(target.getBasePath()).resolve(cell.getBuildFileName());
TargetNode<?, ?> targetNode = parserTargetNodeFactory.createTargetNode(cell, buildFilePath, target, rawNode, input -> SimplePerfEvent.scope(Optional.empty(), input));
targetNodeIndexBuilder.put(targetNode.getBuildTarget(), targetNode);
}
ImmutableSet<BuildTarget> buildTargets = buildTargetsBuilder.build();
Preconditions.checkArgument(topLevelTargets.size() == buildTargets.size());
ImmutableMap<BuildTarget, TargetNode<?, ?>> targetNodeIndex = targetNodeIndexBuilder.build();
MutableDirectedGraph<TargetNode<?, ?>> mutableTargetGraph = new MutableDirectedGraph<>();
for (TargetNode<?, ?> targetNode : targetNodeIndex.values()) {
mutableTargetGraph.addNode(targetNode);
for (BuildTarget dep : targetNode.getDeps()) {
mutableTargetGraph.addEdge(targetNode, Preconditions.checkNotNull(targetNodeIndex.get(dep)));
}
}
// TODO(tophyr): make this work with TargetGroups
TargetGraph targetGraph = new TargetGraph(mutableTargetGraph, targetNodeIndex, ImmutableSet.of());
return TargetGraphAndBuildTargets.builder().setTargetGraph(targetGraph).addAllBuildTargets(buildTargets).build();
}
Aggregations