Search in sources :

Example 1 with StampedeId

use of com.facebook.buck.distributed.thrift.StampedeId 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 StampedeId

use of com.facebook.buck.distributed.thrift.StampedeId in project buck by facebook.

the class DistBuildFactory method createDistBuildExecutor.

public static DistBuildSlaveExecutor createDistBuildExecutor(BuildJobState jobState, CommandRunnerParams params, WeightedListeningExecutorService executorService, DistBuildService service, DistBuildMode mode, int coordinatorPort, Optional<StampedeId> stampedeId, Optional<Path> globalCacheDir) throws IOException {
    DistBuildState state = DistBuildState.load(Optional.of(params.getBuckConfig()), jobState, params.getCell(), params.getKnownBuildRuleTypesFactory());
    Preconditions.checkArgument(state.getCells().size() > 0);
    // Create a cache factory which uses a combination of the distributed build config,
    // overridden with the local buck config (i.e. the build slave).
    Cell rootCell = Preconditions.checkNotNull(state.getCells().get(0));
    ArtifactCacheFactory distBuildArtifactCacheFactory = params.getArtifactCacheFactory().cloneWith(rootCell.getBuckConfig());
    DistBuildSlaveExecutor executor = new DistBuildSlaveExecutor(DistBuildExecutorArgs.builder().setBuckEventBus(params.getBuckEventBus()).setPlatform(params.getPlatform()).setClock(params.getClock()).setArtifactCache(distBuildArtifactCacheFactory.newInstance(true)).setState(state).setObjectMapper(params.getObjectMapper()).setRootCell(params.getCell()).setParser(params.getParser()).setExecutorService(executorService).setActionGraphCache(params.getActionGraphCache()).setCacheKeySeed(params.getBuckConfig().getKeySeed()).setConsole(params.getConsole()).setProvider(new MultiSourceContentsProvider(service, globalCacheDir)).setExecutors(params.getExecutors()).setDistBuildMode(mode).setCoordinatorPort(coordinatorPort).setStampedeId(stampedeId.orElse(new StampedeId().setId("LOCAL_FILE"))).setVersionedTargetGraphCache(params.getVersionedTargetGraphCache()).build());
    return executor;
}
Also used : MultiSourceContentsProvider(com.facebook.buck.distributed.MultiSourceContentsProvider) StampedeId(com.facebook.buck.distributed.thrift.StampedeId) DistBuildState(com.facebook.buck.distributed.DistBuildState) Cell(com.facebook.buck.rules.Cell) ArtifactCacheFactory(com.facebook.buck.artifact_cache.ArtifactCacheFactory) DistBuildSlaveExecutor(com.facebook.buck.distributed.DistBuildSlaveExecutor)

Example 3 with StampedeId

use of com.facebook.buck.distributed.thrift.StampedeId in project buck by facebook.

the class AbstractDistBuildCommand method getStampedeIdOptional.

public Optional<StampedeId> getStampedeIdOptional() {
    if (stampedeId == null) {
        return Optional.empty();
    }
    StampedeId stampedeId = new StampedeId();
    stampedeId.setId(this.stampedeId);
    return Optional.of(stampedeId);
}
Also used : StampedeId(com.facebook.buck.distributed.thrift.StampedeId)

Example 4 with StampedeId

use of com.facebook.buck.distributed.thrift.StampedeId in project buck by facebook.

the class DistBuildClientExecutor method executeAndPrintFailuresToEventBus.

public int executeAndPrintFailuresToEventBus(final WeightedListeningExecutorService executorService, ProjectFilesystem projectFilesystem, FileHashCache fileHashCache, BuckEventBus eventBus) throws IOException, InterruptedException {
    BuildJob job = distBuildService.createBuild();
    final StampedeId id = job.getStampedeId();
    LOG.info("Created job. Build id = " + id.getId());
    logDebugInfo(job);
    List<ListenableFuture<Void>> asyncJobs = new LinkedList<>();
    LOG.info("Uploading local changes.");
    asyncJobs.add(distBuildService.uploadMissingFiles(buildJobState.fileHashes, executorService));
    LOG.info("Uploading target graph.");
    asyncJobs.add(distBuildService.uploadTargetGraph(buildJobState, id, executorService));
    LOG.info("Uploading buck dot-files.");
    asyncJobs.add(distBuildService.uploadBuckDotFiles(id, projectFilesystem, fileHashCache, executorService));
    try {
        Futures.allAsList(asyncJobs).get();
    } catch (ExecutionException e) {
        LOG.error("Upload failed.");
        throw new RuntimeException(e);
    }
    distBuildService.setBuckVersion(id, buckVersion);
    LOG.info("Set Buck Version. Build status: " + job.getStatus().toString());
    job = distBuildService.startBuild(id);
    LOG.info("Started job. Build status: " + job.getStatus().toString());
    logDebugInfo(job);
    Stopwatch stopwatch = Stopwatch.createStarted();
    // Keep polling until the build is complete or failed.
    do {
        job = distBuildService.getCurrentBuildJobState(id);
        LOG.info("Got build status: " + job.getStatus().toString());
        DistBuildStatus distBuildStatus = prepareStatusFromJob(job).setETAMillis(MAX_BUILD_DURATION_MILLIS - stopwatch.elapsed(TimeUnit.MILLISECONDS)).build();
        eventBus.post(new DistBuildStatusEvent(distBuildStatus));
        List<LogLineBatchRequest> newLogLineRequests = distBuildLogStateTracker.createRealtimeLogRequests(job.getSlaveInfoByRunId().values());
        MultiGetBuildSlaveRealTimeLogsResponse slaveLogsResponse = distBuildService.fetchSlaveLogLines(job.stampedeId, newLogLineRequests);
        distBuildLogStateTracker.processStreamLogs(slaveLogsResponse.getMultiStreamLogs());
        try {
            // TODO(shivanker): Get rid of sleeps in methods which we want to unit test
            Thread.sleep(millisBetweenStatusPoll);
        } catch (InterruptedException e) {
            LOG.error(e, "BuildStatus polling sleep call has been interrupted unexpectedly.");
        }
    } while (!(job.getStatus().equals(BuildStatus.FINISHED_SUCCESSFULLY) || job.getStatus().equals(BuildStatus.FAILED)));
    try {
        MultiGetBuildSlaveLogDirResponse logDirsResponse = distBuildService.fetchBuildSlaveLogDir(job.stampedeId, distBuildLogStateTracker.runIdsToMaterializeLogDirsFor(job.slaveInfoByRunId.values()));
        distBuildLogStateTracker.materializeLogDirs(logDirsResponse.getLogDirs());
    } catch (IOException ex) {
        LOG.error(ex);
    }
    LOG.info("Build was " + (job.getStatus().equals(BuildStatus.FINISHED_SUCCESSFULLY) ? "" : "not ") + "successful!");
    logDebugInfo(job);
    DistBuildStatus distBuildStatus = prepareStatusFromJob(job).setETAMillis(0).build();
    eventBus.post(new DistBuildStatusEvent(distBuildStatus));
    return job.getStatus().equals(BuildStatus.FINISHED_SUCCESSFULLY) ? 0 : 1;
}
Also used : LogLineBatchRequest(com.facebook.buck.distributed.thrift.LogLineBatchRequest) MultiGetBuildSlaveRealTimeLogsResponse(com.facebook.buck.distributed.thrift.MultiGetBuildSlaveRealTimeLogsResponse) MultiGetBuildSlaveLogDirResponse(com.facebook.buck.distributed.thrift.MultiGetBuildSlaveLogDirResponse) Stopwatch(com.google.common.base.Stopwatch) IOException(java.io.IOException) LinkedList(java.util.LinkedList) StampedeId(com.facebook.buck.distributed.thrift.StampedeId) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) BuildJob(com.facebook.buck.distributed.thrift.BuildJob) ExecutionException(java.util.concurrent.ExecutionException)

Example 5 with StampedeId

use of com.facebook.buck.distributed.thrift.StampedeId in project buck by facebook.

the class DistBuildServiceTest method canCreateBuild.

@Test
public void canCreateBuild() throws Exception {
    final String idString = "create id";
    Capture<FrontendRequest> request = EasyMock.newCapture();
    FrontendResponse response = new FrontendResponse();
    response.setType(FrontendRequestType.CREATE_BUILD);
    CreateBuildResponse createBuildResponse = new CreateBuildResponse();
    BuildJob buildJob = new BuildJob();
    StampedeId stampedeId = new StampedeId();
    stampedeId.setId(idString);
    buildJob.setStampedeId(stampedeId);
    createBuildResponse.setBuildJob(buildJob);
    response.setCreateBuildResponse(createBuildResponse);
    response.setWasSuccessful(true);
    EasyMock.expect(frontendService.makeRequest(EasyMock.capture(request))).andReturn(response).once();
    EasyMock.replay(frontendService);
    BuildJob job = distBuildService.createBuild();
    Assert.assertEquals(request.getValue().getType(), FrontendRequestType.CREATE_BUILD);
    Assert.assertTrue(request.getValue().isSetCreateBuildRequest());
    Assert.assertTrue(request.getValue().getCreateBuildRequest().isSetCreateTimestampMillis());
    Assert.assertTrue(job.isSetStampedeId());
    Assert.assertTrue(job.getStampedeId().isSetId());
    Assert.assertEquals(job.getStampedeId().getId(), idString);
}
Also used : CreateBuildResponse(com.facebook.buck.distributed.thrift.CreateBuildResponse) StampedeId(com.facebook.buck.distributed.thrift.StampedeId) FrontendResponse(com.facebook.buck.distributed.thrift.FrontendResponse) FrontendRequest(com.facebook.buck.distributed.thrift.FrontendRequest) BuildJob(com.facebook.buck.distributed.thrift.BuildJob) Test(org.junit.Test)

Aggregations

StampedeId (com.facebook.buck.distributed.thrift.StampedeId)12 BuildJob (com.facebook.buck.distributed.thrift.BuildJob)6 FrontendRequest (com.facebook.buck.distributed.thrift.FrontendRequest)5 Test (org.junit.Test)5 FrontendResponse (com.facebook.buck.distributed.thrift.FrontendResponse)4 ArtifactCacheFactory (com.facebook.buck.artifact_cache.ArtifactCacheFactory)1 DistBuildService (com.facebook.buck.distributed.DistBuildService)1 DistBuildSlaveExecutor (com.facebook.buck.distributed.DistBuildSlaveExecutor)1 DistBuildState (com.facebook.buck.distributed.DistBuildState)1 MultiSourceContentsProvider (com.facebook.buck.distributed.MultiSourceContentsProvider)1 BuildJobState (com.facebook.buck.distributed.thrift.BuildJobState)1 BuildJobStateFileHashes (com.facebook.buck.distributed.thrift.BuildJobStateFileHashes)1 BuildJobStateTargetGraph (com.facebook.buck.distributed.thrift.BuildJobStateTargetGraph)1 BuildJobStateTargetNode (com.facebook.buck.distributed.thrift.BuildJobStateTargetNode)1 BuildStatusResponse (com.facebook.buck.distributed.thrift.BuildStatusResponse)1 CreateBuildResponse (com.facebook.buck.distributed.thrift.CreateBuildResponse)1 LogLineBatchRequest (com.facebook.buck.distributed.thrift.LogLineBatchRequest)1 MultiGetBuildSlaveLogDirResponse (com.facebook.buck.distributed.thrift.MultiGetBuildSlaveLogDirResponse)1 MultiGetBuildSlaveRealTimeLogsResponse (com.facebook.buck.distributed.thrift.MultiGetBuildSlaveRealTimeLogsResponse)1 StartBuildResponse (com.facebook.buck.distributed.thrift.StartBuildResponse)1