use of com.facebook.buck.distributed.thrift.BuildJob 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;
}
}
use of com.facebook.buck.distributed.thrift.BuildJob 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;
}
use of com.facebook.buck.distributed.thrift.BuildJob in project buck by facebook.
the class DistBuildService method startBuild.
public BuildJob startBuild(StampedeId id) throws IOException {
// Start the build
StartBuildRequest startRequest = new StartBuildRequest();
startRequest.setStampedeId(id);
FrontendRequest request = new FrontendRequest();
request.setType(FrontendRequestType.START_BUILD);
request.setStartBuildRequest(startRequest);
FrontendResponse response = makeRequestChecked(request);
BuildJob job = response.getStartBuildResponse().getBuildJob();
Preconditions.checkState(job.getStampedeId().equals(id));
return job;
}
use of com.facebook.buck.distributed.thrift.BuildJob 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);
}
use of com.facebook.buck.distributed.thrift.BuildJob in project buck by facebook.
the class ThriftUtilTest method testSerializations.
@Test
public void testSerializations() throws IOException {
ImmutableList<Serializer> serializers = ImmutableList.of(new ByteSerializer(), new StreamSerializer());
ImmutableList<Deserializer> deserializers = ImmutableList.of(new ByteSerializer(), new StreamSerializer());
for (Serializer serializer : serializers) {
for (Deserializer deserializer : deserializers) {
for (ThriftProtocol protocol : ThriftProtocol.values()) {
BuildJob expectedJob = createBuildJob();
byte[] data = serializer.serialize(protocol, expectedJob);
BuildJob actualJob = deserializer.deserialize(protocol, data);
Assert.assertEquals(String.format("Serializer=[%s] Deserializer=[%s] Protocol=[%s] Expected=[%s] Actual=[%s]", serializer.getClass().getName(), deserializer.getClass().getName(), protocol.toString(), expectedJob, actualJob), expectedJob, actualJob);
}
}
}
}
Aggregations