Search in sources :

Example 1 with DistBuildService

use of com.facebook.buck.distributed.DistBuildService in project buck by facebook.

the class DistBuildStatusCommand method runWithoutHelp.

@Override
public int runWithoutHelp(CommandRunnerParams params) throws IOException, InterruptedException {
    StampedeId stampedeId = getStampedeId();
    Console console = params.getConsole();
    ObjectMapper objectMapper = params.getObjectMapper().copy();
    objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
    objectMapper.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET);
    try (DistBuildService service = DistBuildFactory.newDistBuildService(params)) {
        BuildJob buildJob = service.getCurrentBuildJobState(getStampedeId());
        objectMapper.writeValue(console.getStdOut(), buildJob);
        console.getStdOut().println();
        console.printSuccess(String.format("Successfully fetched the build status for [%s].", stampedeId));
        return 0;
    }
}
Also used : StampedeId(com.facebook.buck.distributed.thrift.StampedeId) Console(com.facebook.buck.util.Console) BuildJob(com.facebook.buck.distributed.thrift.BuildJob) DistBuildService(com.facebook.buck.distributed.DistBuildService) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with DistBuildService

use of com.facebook.buck.distributed.DistBuildService in project buck by facebook.

the class BuildCommand method executeDistributedBuild.

private int executeDistributedBuild(final CommandRunnerParams params, ActionAndTargetGraphs graphs, final WeightedListeningExecutorService executorService) throws IOException, InterruptedException {
    // Distributed builds serialize and send the unversioned target graph,
    // and then deserialize and version remotely.
    TargetGraphAndBuildTargets targetGraphAndBuildTargets = graphs.unversionedTargetGraph;
    ProjectFilesystem filesystem = params.getCell().getFilesystem();
    FileHashCache fileHashCache = params.getFileHashCache();
    DistBuildTypeCoercerFactory typeCoercerFactory = new DistBuildTypeCoercerFactory(params.getObjectMapper());
    ParserTargetNodeFactory<TargetNode<?, ?>> parserTargetNodeFactory = DefaultParserTargetNodeFactory.createForDistributedBuild(new ConstructorArgMarshaller(typeCoercerFactory), new TargetNodeFactory(typeCoercerFactory));
    DistBuildTargetGraphCodec targetGraphCodec = new DistBuildTargetGraphCodec(params.getObjectMapper(), parserTargetNodeFactory, new Function<TargetNode<?, ?>, Map<String, Object>>() {

        @Nullable
        @Override
        public Map<String, Object> apply(TargetNode<?, ?> input) {
            try {
                return params.getParser().getRawTargetNode(params.getBuckEventBus(), params.getCell().getCell(input.getBuildTarget()), false, /* enableProfiling */
                executorService, input);
            } catch (BuildFileParseException e) {
                throw new RuntimeException(e);
            }
        }
    }, targetGraphAndBuildTargets.getBuildTargets().stream().map(t -> t.getFullyQualifiedName()).collect(Collectors.toSet()));
    BuildJobState jobState = computeDistributedBuildJobState(targetGraphCodec, params, targetGraphAndBuildTargets, graphs.actionGraph, executorService);
    if (distributedBuildStateFile != null) {
        Path stateDumpPath = Paths.get(distributedBuildStateFile);
        BuildJobStateSerializer.serialize(jobState, filesystem.newFileOutputStream(stateDumpPath));
        return 0;
    } else {
        BuckVersion buckVersion = getBuckVersion();
        Preconditions.checkArgument(params.getInvocationInfo().isPresent());
        try (DistBuildService service = DistBuildFactory.newDistBuildService(params);
            DistBuildLogStateTracker distBuildLogStateTracker = DistBuildFactory.newDistBuildLogStateTracker(params.getInvocationInfo().get().getLogDirectoryPath(), filesystem)) {
            DistBuildClientExecutor build = new DistBuildClientExecutor(jobState, service, distBuildLogStateTracker, 1000, /* millisBetweenStatusPoll */
            buckVersion);
            int exitCode = build.executeAndPrintFailuresToEventBus(executorService, filesystem, fileHashCache, params.getBuckEventBus());
            // TODO(shivanker): Add a flag to disable building, and only fetch from the cache.
            if (exitCode == 0) {
                exitCode = executeLocalBuild(params, graphs.actionGraph, executorService);
            }
            return exitCode;
        }
    }
}
Also used : Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) FileHashCache(com.facebook.buck.util.cache.FileHashCache) TargetNode(com.facebook.buck.rules.TargetNode) BuildJobState(com.facebook.buck.distributed.thrift.BuildJobState) BuildFileParseException(com.facebook.buck.json.BuildFileParseException) DistBuildService(com.facebook.buck.distributed.DistBuildService) ConstructorArgMarshaller(com.facebook.buck.rules.ConstructorArgMarshaller) BuckVersion(com.facebook.buck.distributed.thrift.BuckVersion) TargetNodeFactory(com.facebook.buck.rules.TargetNodeFactory) DefaultParserTargetNodeFactory(com.facebook.buck.parser.DefaultParserTargetNodeFactory) ParserTargetNodeFactory(com.facebook.buck.parser.ParserTargetNodeFactory) DistBuildClientExecutor(com.facebook.buck.distributed.DistBuildClientExecutor) DistBuildTargetGraphCodec(com.facebook.buck.distributed.DistBuildTargetGraphCodec) DistBuildLogStateTracker(com.facebook.buck.distributed.DistBuildLogStateTracker) DistBuildTypeCoercerFactory(com.facebook.buck.distributed.DistBuildTypeCoercerFactory) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) TargetGraphAndBuildTargets(com.facebook.buck.rules.TargetGraphAndBuildTargets) Nullable(javax.annotation.Nullable)

Example 3 with DistBuildService

use of com.facebook.buck.distributed.DistBuildService 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)

Aggregations

DistBuildService (com.facebook.buck.distributed.DistBuildService)3 BuildJobState (com.facebook.buck.distributed.thrift.BuildJobState)2 Console (com.facebook.buck.util.Console)2 DistBuildClientExecutor (com.facebook.buck.distributed.DistBuildClientExecutor)1 DistBuildLogStateTracker (com.facebook.buck.distributed.DistBuildLogStateTracker)1 DistBuildSlaveExecutor (com.facebook.buck.distributed.DistBuildSlaveExecutor)1 DistBuildTargetGraphCodec (com.facebook.buck.distributed.DistBuildTargetGraphCodec)1 DistBuildTypeCoercerFactory (com.facebook.buck.distributed.DistBuildTypeCoercerFactory)1 BuckVersion (com.facebook.buck.distributed.thrift.BuckVersion)1 BuildJob (com.facebook.buck.distributed.thrift.BuildJob)1 StampedeId (com.facebook.buck.distributed.thrift.StampedeId)1 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)1 BuildFileParseException (com.facebook.buck.json.BuildFileParseException)1 DefaultParserTargetNodeFactory (com.facebook.buck.parser.DefaultParserTargetNodeFactory)1 ParserTargetNodeFactory (com.facebook.buck.parser.ParserTargetNodeFactory)1 ConstructorArgMarshaller (com.facebook.buck.rules.ConstructorArgMarshaller)1 SourcePath (com.facebook.buck.rules.SourcePath)1 TargetGraphAndBuildTargets (com.facebook.buck.rules.TargetGraphAndBuildTargets)1 TargetNode (com.facebook.buck.rules.TargetNode)1 TargetNodeFactory (com.facebook.buck.rules.TargetNodeFactory)1