use of org.apache.avro.io.JsonEncoder in project databus by linkedin.
the class ContainerStatsRequestProcessor method processOutboundTrafficClientStats.
private void processOutboundTrafficClientStats(DatabusRequest request) throws IOException, RequestProcessingException {
String category = request.getParams().getProperty(DatabusRequest.PATH_PARAM_NAME);
String prefix = "outbound/client/";
String client = category.substring(prefix.length());
ContainerTrafficTotalStats clientStats = _containerStatsCollector.getOutboundClientStats(client);
if (null == clientStats) {
throw new InvalidRequestParamValueException(request.getName(), prefix, client);
}
JsonEncoder jsonEncoder = clientStats.createJsonEncoder(Channels.newOutputStream(request.getResponseContent()));
clientStats.toJson(jsonEncoder, null);
if (request.getRequestType() == HttpMethod.PUT || request.getRequestType() == HttpMethod.POST) {
enableOrResetStatsMBean(clientStats, request);
}
}
use of org.apache.avro.io.JsonEncoder in project databus by linkedin.
the class ContainerStatsRequestProcessor method processOutboundTrafficTotalStats.
private void processOutboundTrafficTotalStats(DatabusRequest request) throws IOException {
ContainerTrafficTotalStatsMBean outboundTrafficTotalStatsMBean = _containerStatsCollector.getOutboundTrafficTotalStats();
if (null == outboundTrafficTotalStatsMBean)
return;
//String json = outboundTrafficTotalStatsMBean.toJson();
JsonEncoder jsonEncoder = outboundTrafficTotalStatsMBean.createJsonEncoder(Channels.newOutputStream(request.getResponseContent()));
outboundTrafficTotalStatsMBean.toJson(jsonEncoder, null);
if (request.getRequestType() == HttpMethod.PUT || request.getRequestType() == HttpMethod.POST) {
enableOrResetStatsMBean(outboundTrafficTotalStatsMBean, request);
}
}
use of org.apache.avro.io.JsonEncoder in project databus by linkedin.
the class AvroJsonDtailPrinter method printGenericRecord.
/**
* @see com.linkedin.databus2.tools.dtail.GenericRecordDtailPrinter#printGenericRecord(org.apache.avro.generic.GenericRecord)
*/
@Override
public ConsumerCallbackResult printGenericRecord(GenericRecord r) {
ConsumerCallbackResult result = ConsumerCallbackResult.SUCCESS;
try {
//eventDecoder.dumpEventValueInJSON(e, _out);
JsonEncoder jsonEnc = _jsonEncoders.get(r.getSchema());
if (null == jsonEnc) {
jsonEnc = new JsonEncoder(r.getSchema(), _out);
_jsonEncoders.put(r.getSchema(), jsonEnc);
}
GenericDatumWriter<GenericRecord> datumWriter = _jsonWriters.get(r.getSchema());
if (null == datumWriter) {
datumWriter = new GenericDatumWriter<GenericRecord>(r.getSchema());
_jsonWriters.put(r.getSchema(), datumWriter);
}
datumWriter.write(r, jsonEnc);
jsonEnc.flush();
_out.write('\n');
} catch (RuntimeException re) {
LOG.error("event dump error: " + re.getMessage(), re);
result = ConsumerCallbackResult.ERROR;
} catch (IOException ioe) {
LOG.error("event dump error: " + ioe.getMessage(), ioe);
result = ConsumerCallbackResult.ERROR;
}
return result;
}
use of org.apache.avro.io.JsonEncoder in project databus by linkedin.
the class DataGenerator method printAvroJson.
private static void printAvroJson(GenericRecord record, OutputStream outs) throws IOException {
JsonEncoder jsonEnc = new JsonEncoder(record.getSchema(), outs);
GenericDatumWriter<GenericRecord> datumWriter = new GenericDatumWriter<GenericRecord>(record.getSchema());
datumWriter.write(record, jsonEnc);
jsonEnc.flush();
}
use of org.apache.avro.io.JsonEncoder in project databus by linkedin.
the class AvroConverter method convert.
public void convert(InputStream in, OutputStream out) throws IOException {
JsonGenerator jsonGenerator = (new JsonFactory()).createJsonGenerator(new OutputStreamWriter(out));
if (AvroFormat.JSON == _outputFormat)
jsonGenerator.useDefaultPrettyPrinter();
List<GenericRecord> result = convert(in);
Encoder outputEncoder = (AvroFormat.BINARY == _outputFormat) ? new BinaryEncoder(out) : new JsonEncoder(_outputSchema, jsonGenerator);
GenericDatumWriter<GenericRecord> genericWriter = new GenericDatumWriter<GenericRecord>(_outputSchema);
for (GenericRecord r : result) {
genericWriter.write(r, outputEncoder);
}
outputEncoder.flush();
out.flush();
}
Aggregations