Search in sources :

Example 6 with JsonObject

use of org.apache.jena.atlas.json.JsonObject in project jena by apache.

the class TestAdmin method checkJsonStatsOne.

private static void checkJsonStatsOne(JsonValue v) {
    checkJsonStatsCounters(v);
    JsonObject obj1 = v.getAsObject().get("endpoints").getAsObject();
    for (String srvName : obj1.keys()) {
        JsonObject obj2 = obj1.get(srvName).getAsObject();
        assertTrue(obj2.hasKey("description"));
        assertTrue(obj2.hasKey("operation"));
        checkJsonStatsCounters(obj2);
    }
}
Also used : JsonObject(org.apache.jena.atlas.json.JsonObject)

Example 7 with JsonObject

use of org.apache.jena.atlas.json.JsonObject in project jena by apache.

the class TestAdmin method server_1.

// --- Server status 
@Test
public void server_1() {
    JsonValue jv = httpGetJson(ServerCtl.urlRoot() + "$/" + opServer);
    JsonObject obj = jv.getAsObject();
    // Now optional : assertTrue(obj.hasKey(JsonConst.admin)) ;
    assertTrue(obj.hasKey(JsonConst.datasets));
    assertTrue(obj.hasKey(JsonConst.uptime));
    assertTrue(obj.hasKey(JsonConst.startDT));
}
Also used : JsonValue(org.apache.jena.atlas.json.JsonValue) JsonObject(org.apache.jena.atlas.json.JsonObject) Test(org.junit.Test)

Example 8 with JsonObject

use of org.apache.jena.atlas.json.JsonObject in project jena by apache.

the class StatsServlet method statsJSON.

private void statsJSON(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    ServletOutputStream out = resp.getOutputStream();
    resp.setContentType(WebContent.contentTypeJSON);
    resp.setCharacterEncoding(WebContent.charsetUTF8);
    /*
         * { "server" : ....   
         *    "datasets" : {
         *       "ds1": { counters... }
         *       GSP stucture?
         *         
         */
    JsonObject obj = new JsonObject();
    JsonObject datasets = new JsonObject();
    JsonObject server = new JsonObject();
    server.put("host", req.getLocalName() + ":" + req.getLocalPort());
    for (String ds : DatasetRegistry.get().keys()) statsJSON(datasets, ds);
    obj.put("server", server);
    obj.put("datasets", datasets);
    JSON.write(out, obj);
    out.flush();
}
Also used : ServletOutputStream(javax.servlet.ServletOutputStream) JsonObject(org.apache.jena.atlas.json.JsonObject)

Example 9 with JsonObject

use of org.apache.jena.atlas.json.JsonObject in project jena by apache.

the class StatsServlet method statsJSON.

private void statsJSON(JsonObject datasets, String ds) {
    DatasetRef desc = DatasetRegistry.get().get(ds);
    JsonObject stats = new JsonObject();
    datasets.put(ds, stats);
    stats.put(CounterName.Requests.name(), desc.getCounters().value(CounterName.Requests));
    stats.put(CounterName.RequestsGood.name(), desc.getCounters().value(CounterName.RequestsGood));
    stats.put(CounterName.RequestsBad.name(), desc.getCounters().value(CounterName.RequestsBad));
    JsonObject services = new JsonObject();
    // There can be several endpoints for one service.
    for (ServiceRef srvRef : desc.getServiceRefs()) {
        JsonObject epStats = new JsonObject();
        statsJSON(epStats, srvRef);
        services.put(srvRef.name, epStats);
        JsonArray endpoints = new JsonArray();
        epStats.put("endpoints", endpoints);
        for (String ep : srvRef.endpoints) {
            endpoints.add(ep);
        }
    }
    stats.put("services", services);
}
Also used : JsonArray(org.apache.jena.atlas.json.JsonArray) JsonObject(org.apache.jena.atlas.json.JsonObject)

Example 10 with JsonObject

use of org.apache.jena.atlas.json.JsonObject in project jena by apache.

the class StoreParamsCodec method encodeToJson.

public static JsonObject encodeToJson(StoreParams params) {
    JsonBuilder builder = new JsonBuilder();
    // "StoreParams" is an internal alignment marker - not in the JSON.
    builder.startObject("StoreParams");
    encode(builder, key(fFileMode), params.getFileMode().name());
    encode(builder, key(fBlockSize), params.getBlockSize());
    encode(builder, key(fBlockReadCacheSize), params.getBlockReadCacheSize());
    encode(builder, key(fBlockWriteCacheSize), params.getBlockWriteCacheSize());
    encode(builder, key(fNode2NodeIdCacheSize), params.getNode2NodeIdCacheSize());
    encode(builder, key(fNodeId2NodeCacheSize), params.getNodeId2NodeCacheSize());
    encode(builder, key(fNodeMissCacheSize), params.getNodeMissCacheSize());
    encode(builder, key(fIndexNode2Id), params.getIndexNode2Id());
    encode(builder, key(fIndexId2Node), params.getIndexId2Node());
    encode(builder, key(fPrimaryIndexTriples), params.getPrimaryIndexTriples());
    encode(builder, key(fTripleIndexes), params.getTripleIndexes());
    encode(builder, key(fPrimaryIndexQuads), params.getPrimaryIndexQuads());
    encode(builder, key(fQuadIndexes), params.getQuadIndexes());
    encode(builder, key(fPrimaryIndexPrefix), params.getPrimaryIndexPrefix());
    encode(builder, key(fPrefixIndexes), params.getPrefixIndexes());
    encode(builder, key(fIndexPrefix), params.getIndexPrefix());
    encode(builder, key(fPrefixNode2Id), params.getPrefixNode2Id());
    encode(builder, key(fPrefixId2Node), params.getPrefixId2Node());
    builder.finishObject("StoreParams");
    return (JsonObject) builder.build();
}
Also used : JsonBuilder(org.apache.jena.atlas.json.JsonBuilder) JsonObject(org.apache.jena.atlas.json.JsonObject)

Aggregations

JsonObject (org.apache.jena.atlas.json.JsonObject)23 Test (org.junit.Test)8 BaseTest (org.apache.jena.atlas.junit.BaseTest)7 StoreParams (org.apache.jena.tdb.setup.StoreParams)5 JsonValue (org.apache.jena.atlas.json.JsonValue)4 OutputStream (java.io.OutputStream)3 JsonArray (org.apache.jena.atlas.json.JsonArray)3 JsonString (org.apache.jena.atlas.json.JsonString)2 ActionErrorException (org.apache.jena.fuseki.servlets.ActionErrorException)2 ValidationAction (org.apache.jena.fuseki.validation.json.ValidationAction)2 Model (org.apache.jena.rdf.model.Model)2 JsonLDWriteContext (org.apache.jena.riot.JsonLDWriteContext)2 BufferedOutputStream (java.io.BufferedOutputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 ServletOutputStream (javax.servlet.ServletOutputStream)1 JsonBuilder (org.apache.jena.atlas.json.JsonBuilder)1 Node (org.apache.jena.graph.Node)1 Resource (org.apache.jena.rdf.model.Resource)1 LabelToNode (org.apache.jena.riot.lang.LabelToNode)1