/** * Converts the given iterator of our point class to protocol buffers and compresses (gzip) it. * * @param metricDataPoints - the list with points */ public static byte[] to(Iterator<Point> metricDataPoints) { return to(metricDataPoints, ALMOST_EQUALS_OFFSET_MS); }
/** * Adds the points (compressed byte array) to the given builder * * @param decompressedBytes the compressed bytes holding the data points * @param timeSeriesStart the start of the time series * @param timeSeriesEnd the end of the time series * @param builder the time series builder */ public static void from(final InputStream decompressedBytes, long timeSeriesStart, long timeSeriesEnd, MetricTimeSeries.Builder builder) { from(decompressedBytes, timeSeriesStart, timeSeriesEnd, timeSeriesStart, timeSeriesEnd, builder); }
/** * Sets the new t for the point. Checks which t was set. * * @param builder the point builder * @param newOffset the new offset */ private static void setT(SimpleProtocolBuffers.Point.Builder builder, long newOffset) { if (safeLongToUInt(newOffset)) { if (builder.hasTintBP()) { builder.setTintBP((int) newOffset); } if (builder.hasTint()) { builder.setTint((int) newOffset); } } else { if (builder.hasTlongBP()) { builder.setTlongBP(newOffset); } if (builder.hasTlong()) { builder.setTlong(newOffset); } } }
SimpleProtocolBuffers.Point.Builder point = SimpleProtocolBuffers.Point.newBuilder(); SimpleProtocolBuffers.Points.Builder points = SimpleProtocolBuffers.Points.newBuilder(); point.clear(); point.setVIndex(valueIndex.get(currentValue)); } else { valueIndex.put(currentValue, index); point.setV(currentValue); points.addP(point.build()); } else { long calcPoint = calcPoint(startDate, points.getPList(), almostEquals); if (safeLongToUInt(offsetToEnd)) { points.addP(point.setTint((int) offsetToEnd).build()); } else { points.addP(point.setTlong(offsetToEnd).build()); long avgPerDelta = (long) Math.ceil((double) offsetToEnd * -1 + almostEquals / (double) (points.getPCount() - 1)); for (int i = 1; i < points.getPCount(); i++) { SimpleProtocolBuffers.Point mod = points.getP(i); long t = getT(mod); SimpleProtocolBuffers.Point.Builder modPoint = mod.toBuilder(); setT(modPoint, newOffset); mod = modPoint.build();
SimpleProtocolBuffers.Points protocolBufferPoints = SimpleProtocolBuffers.Points.parseFrom(decompressedBytes); List<SimpleProtocolBuffers.Point> pList = protocolBufferPoints.getPList(); lastOffset = calculatePoint(p, lastOffset); calculatedPointDate += lastOffset; if (p.hasVIndex()) { value = pList.get(p.getVIndex()).getV(); } else { value = p.getV();
private void fromJson(BinaryTimeSeries binaryTimeSeries, long queryStart, long queryEnd, MetricTimeSeries.Builder builder) { String jsonString = binaryTimeSeries.get(DATA_AS_JSON_FIELD).toString(); //Second deserialize JsonKassiopeiaSimpleSerializer serializer = new JsonKassiopeiaSimpleSerializer(); serializer.fromJson(jsonString.getBytes(Charset.forName(JsonKassiopeiaSimpleSerializer.UTF_8)), queryStart, queryEnd, builder); }
private static long calcPoint(long startDate, List<SimpleProtocolBuffers.Point> pList, long almostEquals) { long lastOffset = almostEquals; long calculatedPointDate = startDate; for (int i = 1; i < pList.size(); i++) { SimpleProtocolBuffers.Point p = pList.get(i); lastOffset = calculatePoint(p, lastOffset); calculatedPointDate += lastOffset; } return calculatedPointDate; }
/** * Adds the points (compressed byte array) to the given builder * * @param decompressedBytes the compressed bytes holding the data points * @param timeSeriesStart the start of the time series * @param timeSeriesEnd the end of the time series * @param builder the time series builder */ public static void from(final InputStream decompressedBytes, long timeSeriesStart, long timeSeriesEnd, long almost_equals_ms, MetricTimeSeries.Builder builder) { from(decompressedBytes, timeSeriesStart, timeSeriesEnd, timeSeriesStart, timeSeriesEnd, almost_equals_ms, builder); }
@Override public BinaryTimeSeries to(MetricTimeSeries timeSeries) { LOGGER.debug("Converting {} to BinaryTimeSeries", timeSeries); BinaryTimeSeries.Builder builder = new BinaryTimeSeries.Builder(); //serialize byte[] serializedPoints = ProtoBufKassiopeiaSimpleSerializer.to(timeSeries.points().iterator()); byte[] compressedPoints = Compression.compress(serializedPoints); //Add the minimum required fields builder.start(timeSeries.getStart()) .end(timeSeries.getEnd()) .data(compressedPoints); //Currently we only have a metric builder.field(MetricTSSchema.METRIC, timeSeries.getMetric()); //Add a list of user defined attributes timeSeries.attributes().forEach(builder::field); return builder.build(); } }
/** * Adds the points (compressed byte array) to the given builder * * @param decompressedBytes the compressed bytes holding the data points * @param timeSeriesStart the start of the time series * @param timeSeriesEnd the end of the time series * @param from including points from * @param to including points to * @param builder the time series builder */ public static void from(final InputStream decompressedBytes, long timeSeriesStart, long timeSeriesEnd, long from, long to, MetricTimeSeries.Builder builder) { from(decompressedBytes, timeSeriesStart, timeSeriesEnd, from, to, ALMOST_EQUALS_OFFSET_MS, builder); }
private void fromProtocolBuffers(BinaryTimeSeries binaryTimeSeries, long queryStart, long queryEnd, MetricTimeSeries.Builder builder) { final InputStream decompressed = Compression.decompressToStream(binaryTimeSeries.getPoints()); ProtoBufKassiopeiaSimpleSerializer.from(decompressed, binaryTimeSeries.getStart(), binaryTimeSeries.getEnd(), queryStart, queryEnd, builder); }