@Test public void testOneGroupOneCounterToJson() throws SerializationException { Counters counters = new Counters(); counters.incrCounter("SomeCounterGroupName", "SomeCounterName", 3); String json = MapRedStatsLogModule.toJson(counters); assertEquals( "[{\"groupName\":\"SomeCounterGroupName\",\"counters\":[{\"counterNa" + "me\":\"SomeCounterName\",\"value\":3}]}]", json); }
@VisibleForTesting static String toJson(Counters counters) throws SerializationException { ArrayNode countersJsonNode = JsonNodeFactory.instance.arrayNode(); ArrayNode groupsJsonNode = JsonNodeFactory.instance.arrayNode(); for (Group group: counters) { for (Counters.Counter counter: group) { ObjectNode counterJsonNode = JsonNodeFactory.instance.objectNode(); counterJsonNode.put("counterName", counter.getName()) .put("value", counter.getValue()); countersJsonNode.add(counterJsonNode); } ObjectNode groupJsonNode = JsonNodeFactory.instance.objectNode(); groupJsonNode.put("groupName", group.getDisplayName()) .put("counters", countersJsonNode); groupsJsonNode.add(groupJsonNode); } ObjectMapper mapper = new ObjectMapper(); try { return mapper.writeValueAsString(groupsJsonNode); } catch (JsonProcessingException e) { throw new SerializationException(e); } }
MapRedStatsLogModule extends BaseLogModule { @VisibleForTesting static String toJson(Counters counters) throws SerializationException { ArrayNode countersJsonNode = JsonNodeFactory.instance.arrayNode(); ArrayNode groupsJsonNode = JsonNodeFactory.instance.arrayNode(); for (Group group: counters) { for (Counters.Counter counter: group) { ObjectNode counterJsonNode = JsonNodeFactory.instance.objectNode(); counterJsonNode.put("counterName", counter.getName()) .put("value", counter.getValue()); countersJsonNode.add(counterJsonNode); } ObjectNode groupJsonNode = JsonNodeFactory.instance.objectNode(); groupJsonNode.put("groupName", group.getDisplayName()) .put("counters", countersJsonNode); groupsJsonNode.add(groupJsonNode); } ObjectMapper mapper = new ObjectMapper(); try { return mapper.writeValueAsString(groupsJsonNode); } catch (JsonProcessingException e) { throw new SerializationException(e); } } }
MapRedStatsLogModule extends BaseLogModule { @VisibleForTesting static String toJson(Counters counters) throws SerializationException { ArrayNode countersJsonNode = JsonNodeFactory.instance.arrayNode(); ArrayNode groupsJsonNode = JsonNodeFactory.instance.arrayNode(); for (Group group: counters) { for (Counters.Counter counter: group) { ObjectNode counterJsonNode = JsonNodeFactory.instance.objectNode(); counterJsonNode.put("counterName", counter.getName()) .put("value", counter.getValue()); countersJsonNode.add(counterJsonNode); } ObjectNode groupJsonNode = JsonNodeFactory.instance.objectNode(); groupJsonNode.put("groupName", group.getDisplayName()) .put("counters", countersJsonNode); groupsJsonNode.add(groupJsonNode); } ObjectMapper mapper = new ObjectMapper(); try { return mapper.writeValueAsString(groupsJsonNode); } catch (JsonProcessingException e) { throw new SerializationException(e); } } MapRedStatsLogModule(final Connection connection,
                              final SessionStateLite sessionStateLite,
                              long auditLogId); }
MapRedStatsLogModule extends BaseLogModule { @VisibleForTesting static String toJson(Counters counters) throws SerializationException { ArrayNode countersJsonNode = JsonNodeFactory.instance.arrayNode(); ArrayNode groupsJsonNode = JsonNodeFactory.instance.arrayNode(); for (Group group: counters) { for (Counters.Counter counter: group) { ObjectNode counterJsonNode = JsonNodeFactory.instance.objectNode(); counterJsonNode.put("counterName", counter.getName()) .put("value", counter.getValue()); countersJsonNode.add(counterJsonNode); } ObjectNode groupJsonNode = JsonNodeFactory.instance.objectNode(); groupJsonNode.put("groupName", group.getDisplayName()) .put("counters", countersJsonNode); groupsJsonNode.add(groupJsonNode); } ObjectMapper mapper = new ObjectMapper(); try { return mapper.writeValueAsString(groupsJsonNode); } catch (JsonProcessingException e) { throw new SerializationException(e); } } MapRedStatsLogModule(final Connection connection,
                              final SessionStateLite sessionStateLite,
                              long auditLogId); void run(); }
MapRedStatsLogModule extends BaseLogModule { @VisibleForTesting static String toJson(Counters counters) throws SerializationException { ArrayNode countersJsonNode = JsonNodeFactory.instance.arrayNode(); ArrayNode groupsJsonNode = JsonNodeFactory.instance.arrayNode(); for (Group group: counters) { for (Counters.Counter counter: group) { ObjectNode counterJsonNode = JsonNodeFactory.instance.objectNode(); counterJsonNode.put("counterName", counter.getName()) .put("value", counter.getValue()); countersJsonNode.add(counterJsonNode); } ObjectNode groupJsonNode = JsonNodeFactory.instance.objectNode(); groupJsonNode.put("groupName", group.getDisplayName()) .put("counters", countersJsonNode); groupsJsonNode.add(groupJsonNode); } ObjectMapper mapper = new ObjectMapper(); try { return mapper.writeValueAsString(groupsJsonNode); } catch (JsonProcessingException e) { throw new SerializationException(e); } } MapRedStatsLogModule(final Connection connection,
                              final SessionStateLite sessionStateLite,
                              long auditLogId); void run(); static final String TABLE_NAME_KEY; }