use of com.facebook.buck.distributed.thrift.BuildJobState 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.BuildJobState in project buck by facebook.
the class DistBuildRunCommand method runWithoutHelp.
@Override
public int runWithoutHelp(CommandRunnerParams params) throws IOException, InterruptedException {
Stopwatch stopwatch = Stopwatch.createStarted();
Console console = params.getConsole();
try (DistBuildService service = DistBuildFactory.newDistBuildService(params)) {
Pair<BuildJobState, String> jobStateAndBuildName = getBuildJobStateAndBuildName(params.getCell().getFilesystem(), console, service);
BuildJobState jobState = jobStateAndBuildName.getFirst();
String buildName = jobStateAndBuildName.getSecond();
console.getStdOut().println(String.format("BuildJob depends on a total of [%d] input deps.", jobState.getFileHashesSize()));
try (CommandThreadManager pool = new CommandThreadManager(getClass().getName(), getConcurrencyLimit(params.getBuckConfig()))) {
DistBuildSlaveExecutor distBuildExecutor = DistBuildFactory.createDistBuildExecutor(jobState, params, pool.getExecutor(), service, Preconditions.checkNotNull(distBuildMode), coordinatorPort, getStampedeIdOptional(), getGlobalCacheDirOptional());
int returnCode = distBuildExecutor.buildAndReturnExitCode();
if (returnCode == 0) {
console.printSuccess(String.format("Successfully ran distributed build [%s] in [%d millis].", buildName, stopwatch.elapsed(TimeUnit.MILLISECONDS)));
} else {
console.printErrorText("Failed distributed build [%s] in [%d millis].", buildName, stopwatch.elapsed(TimeUnit.MILLISECONDS));
}
return returnCode;
}
}
}
use of com.facebook.buck.distributed.thrift.BuildJobState in project buck by facebook.
the class DistBuildFileHashesIntegrationTest method crossCellDoesNotCauseAbsolutePathSrcs.
@Test
public void crossCellDoesNotCauseAbsolutePathSrcs() throws Exception {
ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "cross_cell", temporaryFolder);
workspace.setUp();
ProjectFilesystem rootFs = new ProjectFilesystem(temporaryFolder.getRoot().toAbsolutePath().resolve("root_cell"));
ProjectFilesystem secondaryFs = new ProjectFilesystem(temporaryFolder.getRoot().toAbsolutePath().resolve("secondary_cell"));
BuckConfig rootCellConfig = FakeBuckConfig.builder().setFilesystem(rootFs).setSections("[repositories]", "cross_cell_secondary = " + secondaryFs.getRootPath().toAbsolutePath()).build();
Cell rootCell = new TestCellBuilder().setBuckConfig(rootCellConfig).setFilesystem(rootFs).build();
TypeCoercerFactory typeCoercerFactory = new DefaultTypeCoercerFactory(ObjectMappers.newDefaultInstance());
ConstructorArgMarshaller constructorArgMarshaller = new ConstructorArgMarshaller(typeCoercerFactory);
Parser parser = new Parser(new BroadcastEventListener(), rootCellConfig.getView(ParserConfig.class), typeCoercerFactory, constructorArgMarshaller);
TargetGraph targetGraph = parser.buildTargetGraph(BuckEventBusFactory.newInstance(), rootCell, /* enableProfiling */
false, MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor()), ImmutableSet.of(BuildTargetFactory.newInstance(rootFs.getRootPath(), "//:libA")));
DistBuildTargetGraphCodec targetGraphCodec = DistBuildStateTest.createDefaultCodec(rootCell, Optional.of(parser));
BuildJobState dump = DistBuildState.dump(new DistBuildCellIndexer(rootCell), createDistBuildFileHashes(targetGraph, rootCell), targetGraphCodec, targetGraph, ImmutableSet.of(BuildTargetFactory.newInstance(rootFs.getRootPath(), "//:libA")));
assertNotNull(dump);
assertEquals(2, dump.getFileHashesSize());
List<BuildJobStateFileHashes> sortedHashes = dump.getFileHashes().stream().sorted(Comparator.comparingInt(BuildJobStateFileHashes::getCellIndex)).collect(Collectors.toList());
BuildJobStateFileHashes rootCellHashes = sortedHashes.get(0);
assertEquals(1, rootCellHashes.getEntriesSize());
assertEquals("A.java", rootCellHashes.getEntries().get(0).getPath().getPath());
BuildJobStateFileHashes secondaryCellHashes = sortedHashes.get(1);
assertEquals(1, secondaryCellHashes.getEntriesSize());
assertEquals("B.java", secondaryCellHashes.getEntries().get(0).getPath().getPath());
}
use of com.facebook.buck.distributed.thrift.BuildJobState in project buck by facebook.
the class DistBuildFileHashesIntegrationTest method symlinkPathsRecordedInRootCell.
@Test
public void symlinkPathsRecordedInRootCell() throws Exception {
Assume.assumeTrue(Platform.detect() != Platform.WINDOWS);
ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "symlink", temporaryFolder);
workspace.setUp();
ProjectFilesystem rootFs = new ProjectFilesystem(temporaryFolder.getRoot().toAbsolutePath().resolve("root_cell"));
Path absSymlinkFilePath = rootFs.resolve("../" + SYMLINK_FILE_NAME);
Path symLinkPath = rootFs.resolve(SYMLINK_FILE_NAME);
rootFs.createSymLink(symLinkPath, absSymlinkFilePath, false);
BuckConfig rootCellConfig = FakeBuckConfig.builder().setFilesystem(rootFs).build();
Cell rootCell = new TestCellBuilder().setBuckConfig(rootCellConfig).setFilesystem(rootFs).build();
TypeCoercerFactory typeCoercerFactory = new DefaultTypeCoercerFactory(ObjectMappers.newDefaultInstance());
ConstructorArgMarshaller constructorArgMarshaller = new ConstructorArgMarshaller(typeCoercerFactory);
Parser parser = new Parser(new BroadcastEventListener(), rootCellConfig.getView(ParserConfig.class), typeCoercerFactory, constructorArgMarshaller);
TargetGraph targetGraph = parser.buildTargetGraph(BuckEventBusFactory.newInstance(), rootCell, /* enableProfiling */
false, MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor()), ImmutableSet.of(BuildTargetFactory.newInstance(rootFs.getRootPath(), "//:libA")));
DistBuildTargetGraphCodec targetGraphCodec = DistBuildStateTest.createDefaultCodec(rootCell, Optional.of(parser));
BuildJobState dump = DistBuildState.dump(new DistBuildCellIndexer(rootCell), createDistBuildFileHashes(targetGraph, rootCell), targetGraphCodec, targetGraph, ImmutableSet.of(BuildTargetFactory.newInstance(rootFs.getRootPath(), "//:libA")));
assertNotNull(dump);
assertEquals(1, dump.getFileHashesSize());
BuildJobStateFileHashes rootCellHashes = dump.getFileHashes().get(0);
assertEquals(2, rootCellHashes.getEntriesSize());
BuildJobStateFileHashEntry symLinkEntry = rootCellHashes.getEntries().stream().filter(x -> x.isSetRootSymLink()).findFirst().get();
String expectedPath = temporaryFolder.getRoot().resolve(SYMLINK_FILE_NAME).toAbsolutePath().toString();
assertEquals(MorePaths.pathWithUnixSeparators(expectedPath), symLinkEntry.getRootSymLinkTarget().getPath());
assertEquals(SYMLINK_FILE_NAME, symLinkEntry.getRootSymLink().getPath());
BuildJobStateFileHashEntry relPathEntry = rootCellHashes.getEntries().stream().filter(x -> !x.isPathIsAbsolute()).findFirst().get();
assertEquals("A.java", relPathEntry.getPath().getPath());
}
use of com.facebook.buck.distributed.thrift.BuildJobState in project buck by facebook.
the class DistBuildStateTest method canReconstructConfig.
@Test
public void canReconstructConfig() throws IOException, InterruptedException {
ProjectFilesystem filesystem = createJavaOnlyFilesystem("/saving");
Config config = new Config(ConfigBuilder.rawFromLines());
BuckConfig buckConfig = new BuckConfig(config, filesystem, Architecture.detect(), Platform.detect(), ImmutableMap.<String, String>builder().putAll(System.getenv()).put("envKey", "envValue").build(), new DefaultCellPathResolver(filesystem.getRootPath(), config));
Cell rootCellWhenSaving = new TestCellBuilder().setFilesystem(filesystem).setBuckConfig(buckConfig).build();
BuildJobState dump = DistBuildState.dump(new DistBuildCellIndexer(rootCellWhenSaving), emptyActionGraph(), createDefaultCodec(rootCellWhenSaving, Optional.empty()), createTargetGraph(filesystem), ImmutableSet.of(BuildTargetFactory.newInstance(filesystem.getRootPath(), "//:dummy")));
Cell rootCellWhenLoading = new TestCellBuilder().setFilesystem(createJavaOnlyFilesystem("/loading")).build();
DistBuildState distributedBuildState = DistBuildState.load(Optional.empty(), dump, rootCellWhenLoading, knownBuildRuleTypesFactory);
ImmutableMap<Integer, Cell> cells = distributedBuildState.getCells();
assertThat(cells, Matchers.aMapWithSize(1));
assertThat(cells.get(0).getBuckConfig(), Matchers.equalTo(buckConfig));
}
Aggregations