Search in sources :

Example 1 with JsonEncoder

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);
    }
}
Also used : JsonEncoder(org.apache.avro.io.JsonEncoder) ContainerTrafficTotalStats(com.linkedin.databus2.core.container.monitoring.mbean.ContainerTrafficTotalStats)

Example 2 with JsonEncoder

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);
    }
}
Also used : ContainerTrafficTotalStatsMBean(com.linkedin.databus2.core.container.monitoring.mbean.ContainerTrafficTotalStatsMBean) JsonEncoder(org.apache.avro.io.JsonEncoder)

Example 3 with JsonEncoder

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;
}
Also used : JsonEncoder(org.apache.avro.io.JsonEncoder) ConsumerCallbackResult(com.linkedin.databus.client.pub.ConsumerCallbackResult) IOException(java.io.IOException) GenericRecord(org.apache.avro.generic.GenericRecord)

Example 4 with JsonEncoder

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();
}
Also used : JsonEncoder(org.apache.avro.io.JsonEncoder) GenericDatumWriter(org.apache.avro.generic.GenericDatumWriter) GenericRecord(org.apache.avro.generic.GenericRecord)

Example 5 with JsonEncoder

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();
}
Also used : BinaryEncoder(org.apache.avro.io.BinaryEncoder) JsonEncoder(org.apache.avro.io.JsonEncoder) Encoder(org.apache.avro.io.Encoder) BinaryEncoder(org.apache.avro.io.BinaryEncoder) JsonEncoder(org.apache.avro.io.JsonEncoder) JsonFactory(org.codehaus.jackson.JsonFactory) JsonGenerator(org.codehaus.jackson.JsonGenerator) OutputStreamWriter(java.io.OutputStreamWriter) GenericDatumWriter(org.apache.avro.generic.GenericDatumWriter) GenericRecord(org.apache.avro.generic.GenericRecord)

Aggregations

JsonEncoder (org.apache.avro.io.JsonEncoder)8 IOException (java.io.IOException)3 GenericDatumWriter (org.apache.avro.generic.GenericDatumWriter)3 GenericRecord (org.apache.avro.generic.GenericRecord)3 ContainerTrafficTotalStatsMBean (com.linkedin.databus2.core.container.monitoring.mbean.ContainerTrafficTotalStatsMBean)2 JsonFactory (org.codehaus.jackson.JsonFactory)2 JsonGenerator (org.codehaus.jackson.JsonGenerator)2 ConsumerCallbackResult (com.linkedin.databus.client.pub.ConsumerCallbackResult)1 ContainerTrafficTotalStats (com.linkedin.databus2.core.container.monitoring.mbean.ContainerTrafficTotalStats)1 SchemaId (com.linkedin.databus2.schemas.SchemaId)1 VersionedSchema (com.linkedin.databus2.schemas.VersionedSchema)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 ByteBuffer (java.nio.ByteBuffer)1 Schema (org.apache.avro.Schema)1 GenericDatumReader (org.apache.avro.generic.GenericDatumReader)1 BinaryEncoder (org.apache.avro.io.BinaryEncoder)1 Encoder (org.apache.avro.io.Encoder)1 JsonGenerationException (org.codehaus.jackson.JsonGenerationException)1