use of org.codehaus.jettison.json.JSONWriter in project stdlib by petergeneric.
the class LogSerialiser method toJson.
public String toJson(final Collection<LogLineTableEntity> results) {
try {
StringWriter sw = new StringWriter(4096);
JSONWriter w = new JSONWriter(sw);
w.array();
for (LogLineTableEntity line : results) write(w, line);
w.endArray();
return sw.toString();
} catch (JSONException e) {
throw new RuntimeException("Error serialising lines to JSON: " + e.getMessage(), e);
}
}
use of org.codehaus.jettison.json.JSONWriter in project vespa by vespa-engine.
the class ContentClusterHtmlRendrerTest method before.
@Before
public void before() throws JSONException, ParseException {
final ClusterState state = new ClusterState("version:34633 bits:24 distributor:211 storage:211");
final EventLog eventLog = new EventLog(new FakeTimer(), null);
final VdsClusterHtmlRendrer.Table table = rendrer.createNewClusterHtmlTable(clusterName, slobrokGeneration);
final ContentCluster contentCluster = mock(ContentCluster.class);
for (int x = 0; x < 10; x++) {
NodeInfo nodeInfo = new DistributorNodeInfo(contentCluster, x, "dist " + x, null);
final Writer writer = new StringWriter();
new JSONWriter(writer).object().key("vtag").object().key("version").value("release1" + (x == 2 ? "bad" : "")).endObject().endObject();
nodeInfo.setHostInfo(HostInfo.createHostInfo(writer.toString()));
distributorNodeInfoByIndex.put(x, nodeInfo);
}
storageNodeInfoByIndex.put(2, new StorageNodeInfo(contentCluster, 2, false, "storage" + 2, null));
ClusterStatsAggregator statsAggregator = new ClusterStatsAggregator(Sets.newHashSet(2), Sets.newHashSet(2));
table.renderNodes(storageNodeInfoByIndex, distributorNodeInfoByIndex, new FakeTimer(), state, statsAggregator, 1.0, 10, eventLog, "pathPrefix", "name");
final StringBuilder stringBuilder = new StringBuilder();
table.addTable(stringBuilder, 34);
result = stringBuilder.toString();
}
Aggregations