use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper in project buck by facebook.
the class RunShTestAndRecordResultStep method execute.
@Override
public StepExecutionResult execute(ExecutionContext context) throws IOException, InterruptedException {
TestResultSummary summary;
if (context.getPlatform() == Platform.WINDOWS) {
// Ignore sh_test on Windows.
summary = new TestResultSummary(getShortName(), "sh_test", /* type */
ResultType.SUCCESS, /* duration*/
0, /* message */
"sh_test ignored on Windows", /* stacktrace */
null, /* stdout */
null, /* stderr */
null);
} else {
ShellStep test = new ShellStep(filesystem.getRootPath()) {
boolean timedOut = false;
@Override
public String getShortName() {
return pathToShellScript.toString();
}
@Override
protected ImmutableList<String> getShellCommandInternal(ExecutionContext context) {
return ImmutableList.<String>builder().add(pathToShellScript.toString()).addAll(args).build();
}
@Override
public ImmutableMap<String, String> getEnvironmentVariables(ExecutionContext context) {
return ImmutableMap.<String, String>builder().put("NO_BUCKD", "1").putAll(env).build();
}
@Override
protected boolean shouldPrintStderr(Verbosity verbosity) {
// Do not stream this output because we want to capture it.
return false;
}
@Override
public StepExecutionResult execute(ExecutionContext context) throws IOException, InterruptedException {
StepExecutionResult executionResult = super.execute(context);
if (timedOut) {
throw new HumanReadableException("Timed out running test: " + testCaseName + ", with exitCode: " + executionResult.getExitCode());
}
return executionResult;
}
@Override
protected Optional<Consumer<Process>> getTimeoutHandler(final ExecutionContext context) {
return Optional.of(process -> timedOut = true);
}
@Override
protected Optional<Long> getTimeout() {
return testRuleTimeoutMs;
}
@Override
protected boolean shouldPrintStdout(Verbosity verbosity) {
// Do not stream this output because we want to capture it.
return false;
}
};
StepExecutionResult executionResult = test.execute(context);
// Write test result.
boolean isSuccess = executionResult.isSuccess();
summary = new TestResultSummary(getShortName(), "sh_test", /* type */
isSuccess ? ResultType.SUCCESS : ResultType.FAILURE, test.getDuration(), /* message */
null, /* stacktrace */
null, test.getStdout(), test.getStderr());
}
ObjectMapper mapper = context.getObjectMapper();
try (OutputStream outputStream = filesystem.newFileOutputStream(pathToTestResultFile)) {
mapper.writeValue(outputStream, summary);
}
// should be zero.
return StepExecutionResult.SUCCESS;
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper 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 org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper in project buck by facebook.
the class AuditRulesCommand method printRulesToStdout.
private void printRulesToStdout(CommandRunnerParams params, List<Map<String, Object>> rawRules, final Predicate<String> includeType) throws IOException {
Iterable<Map<String, Object>> filteredRules = FluentIterable.from(rawRules).filter(rawRule -> {
String type = (String) rawRule.get(BuckPyFunction.TYPE_PROPERTY_NAME);
return includeType.apply(type);
});
PrintStream stdOut = params.getConsole().getStdOut();
if (json) {
Map<String, Object> rulesKeyedByName = new HashMap<>();
for (Map<String, Object> rawRule : filteredRules) {
String name = (String) rawRule.get("name");
Preconditions.checkNotNull(name);
rulesKeyedByName.put(name, Maps.filterValues(rawRule, v -> shouldInclude(v)));
}
// We create a new JsonGenerator that does not close the stream.
ObjectMapper mapper = params.getObjectMapper();
JsonFactory factory = mapper.getFactory();
try (JsonGenerator generator = factory.createGenerator(stdOut).disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET).useDefaultPrettyPrinter()) {
mapper.writeValue(generator, rulesKeyedByName);
}
stdOut.print('\n');
} else {
for (Map<String, Object> rawRule : filteredRules) {
printRuleAsPythonToStdout(stdOut, rawRule);
}
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper in project buck by facebook.
the class OfflineScribeLogger method sendStoredLogs.
private synchronized void sendStoredLogs() {
ImmutableSortedSet<Path> logsPaths;
try {
if (!filesystem.isDirectory(logDir)) {
// No logs to submit to Scribe.
return;
}
logsPaths = filesystem.getMtimeSortedMatchingDirectoryContents(logDir, LOGFILE_PATTERN);
} catch (Exception e) {
LOG.error(e, "Fetching stored logs list failed.");
return;
}
long totalBytesToSend = 0;
for (Path logPath : logsPaths) {
// Sending should be ceased if storing has been initiated or closing was started.
if (startedStoring || startedClosing) {
break;
}
// Get iterator.
Iterator<ScribeData> it;
File logFile;
try {
logFile = logPath.toFile();
totalBytesToSend += logFile.length();
if (totalBytesToSend > maxScribeOfflineLogsBytes) {
LOG.warn("Total size of offline logs exceeds the limit. Ceasing to send them to Scribe.");
return;
}
InputStream logFileStream;
try {
logFileStream = new BufferedInputStream(new FileInputStream(logFile), BUFFER_SIZE);
} catch (FileNotFoundException e) {
LOG.info(e, "There was a problem getting stream for logfile: %s. Likely logfile was resent and" + "deleted by a concurrent Buck command.", logPath);
continue;
}
it = new ObjectMapper().readValues(new JsonFactory().createParser(logFileStream), ScribeData.class);
} catch (Exception e) {
LOG.error(e, "Failed to initiate reading from: %s. File may be corrupted.", logPath);
continue;
}
// Read and submit.
int scribeLinesInFile = 0;
List<ListenableFuture<Void>> logFutures = new LinkedList<>();
Map<String, CategoryData> logReadData = new HashMap<>();
try {
boolean interrupted = false;
// Read data and build per category clusters - dispatch if needed.
while (it.hasNext()) {
if (startedStoring || startedClosing) {
interrupted = true;
break;
}
ScribeData newData = it.next();
// Prepare map entry for new data (dispatch old data if needed).
if (!logReadData.containsKey(newData.getCategory())) {
logReadData.put(newData.getCategory(), new CategoryData());
}
CategoryData categoryData = logReadData.get(newData.getCategory());
if (categoryData.getLinesBytes() > CLUSTER_DISPATCH_SIZE) {
logFutures.add(scribeLogger.log(newData.getCategory(), categoryData.getLines()));
categoryData.clearData();
}
// Add new data to the cluster for the category.
for (String line : newData.getLines()) {
categoryData.addLine(line);
scribeLinesInFile++;
}
}
// Send remaining data from per category clusters.
if (!interrupted) {
for (Map.Entry<String, CategoryData> logReadDataEntry : logReadData.entrySet()) {
if (startedStoring || startedClosing) {
interrupted = true;
break;
}
List<String> categoryLines = logReadDataEntry.getValue().getLines();
if (categoryLines.size() > 0) {
logFutures.add(scribeLogger.log(logReadDataEntry.getKey(), categoryLines));
}
}
}
if (interrupted) {
LOG.info("Stopped while sending from offline log (it will not be removed): %s.", logPath);
logFutures.clear();
break;
}
} catch (Exception e) {
LOG.error(e, "Error while reading offline log from: %s. This log will not be removed now. If this " + "error reappears in further runs, the file may be corrupted and should be deleted. ", logPath);
logFutures.clear();
continue;
} finally {
logReadData.clear();
}
// Confirm data was successfully sent and remove logfile.
try {
Futures.allAsList(logFutures).get(LOG_TIMEOUT, LOG_TIMEOUT_UNIT);
totalBytesResent.inc(logFile.length());
totalLinesResent.inc(scribeLinesInFile);
logfilesResent.inc();
try {
filesystem.deleteFileAtPathIfExists(logPath);
} catch (Exception e) {
LOG.error(e, "Failed to remove successfully resent offline log. Stopping sending.");
break;
}
} catch (Exception e) {
LOG.info("Failed to send all data from offline log: %s. Log will not be removed.", logPath);
// Do not attempt to send data from further logfiles - likely there are network issues.
break;
} finally {
logFutures.clear();
}
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper in project pinot by linkedin.
the class TableViews method getTableState.
// we use name "view" to closely match underlying names and to not
// confuse with table state of enable/disable
private Representation getTableState(String tableName, String view, TableType tableType) {
TableView tableView;
if (view.equalsIgnoreCase(IDEALSTATE)) {
tableView = getTableIdealState(tableName, tableType);
} else if (view.equalsIgnoreCase(EXTERNALVIEW)) {
tableView = getTableExternalView(tableName, tableType);
} else {
return responseRepresentation(Status.CLIENT_ERROR_BAD_REQUEST, "{\"error\" : \"Bad view name: " + view + ". Expected idealstate or externalview\" }");
}
if (tableView.offline == null && tableView.realtime == null) {
return responseRepresentation(Status.CLIENT_ERROR_NOT_FOUND, "{\"error\" : \"Table not found}");
}
ObjectMapper mapper = new ObjectMapper();
try {
String response = mapper.writeValueAsString(tableView);
return responseRepresentation(Status.SUCCESS_OK, response);
} catch (JsonProcessingException e) {
LOGGER.error("Failed to serialize {} for table {}", tableName, view, e);
return responseRepresentation(Status.SERVER_ERROR_INTERNAL, "{\"error\": \"Error serializing response\"}");
}
}
Aggregations