private static Metric resultSetToMetric(ResultSet rs) throws SQLException { Metric metric = new Metric(); metric.setGroup(rs.getString("metric_group")); metric.setName(rs.getString("metric_name")); metric.setType(MetricTypeEnum.valueOf(rs.getString("metric_type"))); metric.setValue(rs.getString("metric_value")); return metric; }
/** * Existence checker for group * * @see Metric.Fields#group */ public boolean hasGroup() { return contains(FIELD_Group); }
private void addMetricToBatch(PreparedStatement upsertStatement, Metric metric, String id) throws SQLException { Preconditions.checkArgument(!Strings.isNullOrEmpty(id)); Preconditions.checkArgument(metric.hasGroup()); Preconditions.checkArgument(metric.hasName()); Preconditions.checkArgument(metric.hasType()); Preconditions.checkArgument(metric.hasValue()); int index = 0; upsertStatement.setString(++index, id); upsertStatement.setString(++index, metric.getGroup()); upsertStatement.setString(++index, metric.getName()); upsertStatement.setString(++index, metric.getType().name()); upsertStatement.setString(++index, metric.getValue()); upsertStatement.addBatch(); }
private static boolean existsMetric(Connection connection, String template, String id, Metric metric) throws SQLException { Preconditions.checkArgument(!Strings.isNullOrEmpty(id)); Preconditions.checkArgument(metric.hasGroup()); Preconditions.checkArgument(metric.hasName()); Preconditions.checkArgument(metric.hasType()); try (PreparedStatement queryStatement = connection.prepareStatement(template)) { int index = 0; queryStatement.setString(++index, id); queryStatement.setString(++index, metric.getGroup()); queryStatement.setString(++index, metric.getName()); queryStatement.setString(++index, metric.getType().name()); try (ResultSet resultSet = queryStatement.executeQuery()) { return resultSet.next(); } } }
private static void updateMetric(Connection connection, String template, String id, Metric metric, boolean insert) throws SQLException { Preconditions.checkArgument(!Strings.isNullOrEmpty(id)); Preconditions.checkArgument(metric.hasGroup()); Preconditions.checkArgument(metric.hasName()); Preconditions.checkArgument(metric.hasType()); Preconditions.checkArgument(metric.hasValue()); try (PreparedStatement updateStatement = connection.prepareStatement(template)) { int index = 0; if (insert) { updateStatement.setString(++index, id); updateStatement.setString(++index, metric.getGroup()); updateStatement.setString(++index, metric.getName()); updateStatement.setString(++index, metric.getType().name()); updateStatement.setString(++index, metric.getValue()); } else { updateStatement.setString(++index, metric.getValue()); updateStatement.setString(++index, id); updateStatement.setString(++index, metric.getGroup()); updateStatement.setString(++index, metric.getName()); updateStatement.setString(++index, metric.getType().name()); } updateStatement.executeUpdate(); } }
private Metric resultSetToMetric(ResultSet rs) throws SQLException { Metric metric = new Metric(); metric.setGroup(rs.getString("metric_group")); metric.setName(rs.getString("metric_name")); metric.setType(MetricTypeEnum.valueOf(rs.getString("metric_type"))); metric.setValue(rs.getString("metric_value")); return metric; }
/** * Existence checker for name * * @see Metric.Fields#name */ public boolean hasName() { return contains(FIELD_Name); }
Metric counter = new Metric(); counter.setGroup(MetricGroup.JOB.name()); counter.setName(entry.getKey()); counter.setType(MetricTypeEnum.valueOf(GobblinMetrics.MetricType.COUNTER.name())); counter.setValue(Long.toString(((Counter) entry.getValue()).getCount())); metricArray.add(counter); Metric meter = new Metric(); meter.setGroup(MetricGroup.JOB.name()); meter.setName(entry.getKey()); meter.setType(MetricTypeEnum.valueOf(GobblinMetrics.MetricType.METER.name())); meter.setValue(Double.toString(((Meter) entry.getValue()).getMeanRate())); metricArray.add(meter); Metric gauge = new Metric(); gauge.setGroup(MetricGroup.JOB.name()); gauge.setName(entry.getKey()); gauge.setType(MetricTypeEnum.valueOf(GobblinMetrics.MetricType.GAUGE.name())); gauge.setValue(((Gauge<?>) entry.getValue()).getValue().toString()); metricArray.add(gauge);
/** * Existence checker for type * * @see Metric.Fields#type */ public boolean hasType() { return contains(FIELD_Type); }
Metric counter = new Metric(); counter.setGroup(MetricGroup.TASK.name()); counter.setName(entry.getKey()); counter.setType(MetricTypeEnum.valueOf(GobblinMetrics.MetricType.COUNTER.name())); counter.setValue(Long.toString(((Counter) entry.getValue()).getCount())); metricArray.add(counter); Metric meter = new Metric(); meter.setGroup(MetricGroup.TASK.name()); meter.setName(entry.getKey()); meter.setType(MetricTypeEnum.valueOf(GobblinMetrics.MetricType.METER.name())); meter.setValue(Double.toString(((Meter) entry.getValue()).getMeanRate())); metricArray.add(meter); Metric gauge = new Metric(); gauge.setGroup(MetricGroup.TASK.name()); gauge.setName(entry.getKey()); gauge.setType(MetricTypeEnum.valueOf(GobblinMetrics.MetricType.GAUGE.name())); gauge.setValue(((Gauge<?>) entry.getValue()).getValue().toString()); metricArray.add(gauge);
/** * Existence checker for value * * @see Metric.Fields#value */ public boolean hasValue() { return contains(FIELD_Value); }