Search in sources :

Example 1 with JSONWriter

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);
    }
}
Also used : JSONWriter(org.codehaus.jettison.json.JSONWriter) StringWriter(java.io.StringWriter) LogLineTableEntity(com.peterphi.servicemanager.service.logging.LogLineTableEntity) JSONException(org.codehaus.jettison.json.JSONException)

Example 2 with JSONWriter

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();
}
Also used : JSONWriter(org.codehaus.jettison.json.JSONWriter) ClusterState(com.yahoo.vdslib.state.ClusterState) VdsClusterHtmlRendrer(com.yahoo.vespa.clustercontroller.core.status.statuspage.VdsClusterHtmlRendrer) StringWriter(java.io.StringWriter) JSONWriter(org.codehaus.jettison.json.JSONWriter) StringWriter(java.io.StringWriter) Writer(java.io.Writer) Before(org.junit.Before)

Aggregations

StringWriter (java.io.StringWriter)2 JSONWriter (org.codehaus.jettison.json.JSONWriter)2 LogLineTableEntity (com.peterphi.servicemanager.service.logging.LogLineTableEntity)1 ClusterState (com.yahoo.vdslib.state.ClusterState)1 VdsClusterHtmlRendrer (com.yahoo.vespa.clustercontroller.core.status.statuspage.VdsClusterHtmlRendrer)1 Writer (java.io.Writer)1 JSONException (org.codehaus.jettison.json.JSONException)1 Before (org.junit.Before)1