Search in sources :

Example 6 with BuildJobState

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));
}
Also used : BuildJobStateTargetNode(com.facebook.buck.distributed.thrift.BuildJobStateTargetNode) BuildJobStateFileHashes(com.facebook.buck.distributed.thrift.BuildJobStateFileHashes) BuildJobStateTargetGraph(com.facebook.buck.distributed.thrift.BuildJobStateTargetGraph) StampedeId(com.facebook.buck.distributed.thrift.StampedeId) FrontendResponse(com.facebook.buck.distributed.thrift.FrontendResponse) BuildJobState(com.facebook.buck.distributed.thrift.BuildJobState) ArrayList(java.util.ArrayList) FrontendRequest(com.facebook.buck.distributed.thrift.FrontendRequest) Test(org.junit.Test)

Example 7 with BuildJobState

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;
        }
    }
}
Also used : Stopwatch(com.google.common.base.Stopwatch) Console(com.facebook.buck.util.Console) BuildJobState(com.facebook.buck.distributed.thrift.BuildJobState) DistBuildService(com.facebook.buck.distributed.DistBuildService) DistBuildSlaveExecutor(com.facebook.buck.distributed.DistBuildSlaveExecutor)

Example 8 with BuildJobState

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());
}
Also used : BroadcastEventListener(com.facebook.buck.event.listener.BroadcastEventListener) BuildJobState(com.facebook.buck.distributed.thrift.BuildJobState) DefaultTypeCoercerFactory(com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory) TargetGraph(com.facebook.buck.rules.TargetGraph) TypeCoercerFactory(com.facebook.buck.rules.coercer.TypeCoercerFactory) DefaultTypeCoercerFactory(com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) Parser(com.facebook.buck.parser.Parser) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) ConstructorArgMarshaller(com.facebook.buck.rules.ConstructorArgMarshaller) BuildJobStateFileHashes(com.facebook.buck.distributed.thrift.BuildJobStateFileHashes) BuckConfig(com.facebook.buck.cli.BuckConfig) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Cell(com.facebook.buck.rules.Cell) ParserConfig(com.facebook.buck.parser.ParserConfig) Test(org.junit.Test)

Example 9 with BuildJobState

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());
}
Also used : Path(java.nio.file.Path) BroadcastEventListener(com.facebook.buck.event.listener.BroadcastEventListener) BuildJobState(com.facebook.buck.distributed.thrift.BuildJobState) DefaultTypeCoercerFactory(com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory) TargetGraph(com.facebook.buck.rules.TargetGraph) TypeCoercerFactory(com.facebook.buck.rules.coercer.TypeCoercerFactory) DefaultTypeCoercerFactory(com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) Parser(com.facebook.buck.parser.Parser) BuildJobStateFileHashEntry(com.facebook.buck.distributed.thrift.BuildJobStateFileHashEntry) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) ConstructorArgMarshaller(com.facebook.buck.rules.ConstructorArgMarshaller) BuildJobStateFileHashes(com.facebook.buck.distributed.thrift.BuildJobStateFileHashes) BuckConfig(com.facebook.buck.cli.BuckConfig) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Cell(com.facebook.buck.rules.Cell) ParserConfig(com.facebook.buck.parser.ParserConfig) Test(org.junit.Test)

Example 10 with BuildJobState

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));
}
Also used : DefaultCellPathResolver(com.facebook.buck.rules.DefaultCellPathResolver) BuckConfig(com.facebook.buck.cli.BuckConfig) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) BuckConfig(com.facebook.buck.cli.BuckConfig) Config(com.facebook.buck.config.Config) ParserConfig(com.facebook.buck.parser.ParserConfig) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) BuildJobState(com.facebook.buck.distributed.thrift.BuildJobState) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Cell(com.facebook.buck.rules.Cell) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) Test(org.junit.Test)

Aggregations

BuildJobState (com.facebook.buck.distributed.thrift.BuildJobState)12 Test (org.junit.Test)8 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)7 BuckConfig (com.facebook.buck.cli.BuckConfig)6 FakeBuckConfig (com.facebook.buck.cli.FakeBuckConfig)6 ParserConfig (com.facebook.buck.parser.ParserConfig)6 Cell (com.facebook.buck.rules.Cell)6 TestCellBuilder (com.facebook.buck.rules.TestCellBuilder)6 Config (com.facebook.buck.config.Config)4 BuildJobStateFileHashes (com.facebook.buck.distributed.thrift.BuildJobStateFileHashes)4 ConstructorArgMarshaller (com.facebook.buck.rules.ConstructorArgMarshaller)4 DefaultCellPathResolver (com.facebook.buck.rules.DefaultCellPathResolver)4 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)4 Path (java.nio.file.Path)4 BroadcastEventListener (com.facebook.buck.event.listener.BroadcastEventListener)3 Parser (com.facebook.buck.parser.Parser)3 TargetGraph (com.facebook.buck.rules.TargetGraph)3 DefaultTypeCoercerFactory (com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory)3 TypeCoercerFactory (com.facebook.buck.rules.coercer.TypeCoercerFactory)3 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)3