public void addMetric(TimelineMetric metric) { if (real == null) { metrics.add(metric); } else { real.addMetric(metric); } }
/** * Helper method for reading and deserializing {@link TimelineMetric} objects * using the specified column prefix. The timeline metrics then are added to * the given timeline entity. * * @param entity {@link TimelineEntity} object. * @param result {@link Result} object retrieved from backend. * @param columnPrefix Metric column prefix * @throws IOException if any exception is encountered while reading metrics. */ protected void readMetrics(TimelineEntity entity, Result result, ColumnPrefix<?> columnPrefix) throws IOException { NavigableMap<String, NavigableMap<Long, Number>> metricsResult = ColumnRWHelper.readResultsWithTimestamps( result, columnPrefix, stringKeyConverter); for (Map.Entry<String, NavigableMap<Long, Number>> metricResult: metricsResult.entrySet()) { TimelineMetric metric = new TimelineMetric(); metric.setId(metricResult.getKey()); // Simply assume that if the value set contains more than 1 elements, the // metric is a TIME_SERIES metric, otherwise, it's a SINGLE_VALUE metric TimelineMetric.Type metricType = metricResult.getValue().size() > 1 ? TimelineMetric.Type.TIME_SERIES : TimelineMetric.Type.SINGLE_VALUE; metric.setType(metricType); metric.addValues(metricResult.getValue()); entity.addMetric(metric); } }
for (int i = 1; i <=5; i++) { TimelineEntity entity = createEntity("e" + i, "type"); entity.addMetric(createDummyMetric(ts + i, Long.valueOf(i * 50))); entities.addEntity(entity); for (int i = 1; i <=3; i++) { TimelineEntity entity = createEntity("e" + i, "type"); entity.addMetric(createDummyMetric(System.currentTimeMillis() + i, 50L)); entities.addEntity(entity);
entity2.setType(type2); entity2.setCreatedTime(1425016503000L); entity2.addMetric(metric); te.addEntity(entity2);
@Test public void testPutEntities() throws Exception { TimelineV2Client client = TimelineV2Client.createTimelineClient(ApplicationId.newInstance(0, 1)); try { // Set the timeline service address manually. client.setTimelineCollectorInfo(CollectorInfo.newInstance( collectorManager.getRestServerBindAddress())); client.init(conf); client.start(); TimelineEntity entity = new TimelineEntity(); entity.setType("test entity type"); entity.setId("test entity id"); TimelineMetric metric = new TimelineMetric(TimelineMetric.Type.TIME_SERIES); metric.setId("test metric id"); metric.addValue(1L, 1.0D); metric.addValue(2L, 2.0D); entity.addMetric(metric); client.putEntities(entity); client.putEntitiesAsync(entity); } finally { client.stop(); } }