Skip to content

Commit

Permalink
added fixity metrics to describe response
Browse files Browse the repository at this point in the history
  • Loading branch information
fasseg committed May 16, 2013
1 parent e7bfc9c commit 9daa136
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
Expand Up @@ -11,8 +11,6 @@

import javax.ws.rs.core.Response;

import com.hp.hpl.jena.graph.Node;
import com.hp.hpl.jena.update.GraphStore;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
Expand All @@ -22,6 +20,9 @@
import org.fcrepo.test.util.TestHelpers;
import org.junit.Test;

import com.hp.hpl.jena.graph.Node;
import com.hp.hpl.jena.update.GraphStore;

public class FedoraNodesIT extends AbstractResourceIT {

@Test
Expand Down Expand Up @@ -119,7 +120,21 @@ public void testGetRepositoryGraph() throws Exception {

}

@Test
@Test
public void testGetDescribeRepositoryRDFJSON() throws Exception {
final HttpGet getObjMethod =
new HttpGet(serverAddress + "");
getObjMethod.addHeader("Accept", "application/n-triples");
final HttpResponse response = client.execute(getObjMethod);
assertEquals(200, response.getStatusLine().getStatusCode());
final GraphStore graphStore = TestHelpers.parseTriples(response.getEntity().getContent());
logger.debug("Retrieved repository graph:\n" + graphStore.toString());

assertTrue("expected to find the root node data", graphStore.contains(Node.ANY, Node.ANY, Node.createURI("info:fedora/fedora-system:def/internal#primaryType"), Node.createLiteral("mode:root")));

}

@Test
public void testGetObjectGraph() throws Exception {
client.execute(postObjMethod("FedoraDescribeTestGraph"));
final HttpGet getObjMethod =
Expand Down
17 changes: 17 additions & 0 deletions fcrepo-kernel/src/main/java/org/fcrepo/utils/JcrRdfTools.java
Expand Up @@ -3,6 +3,7 @@
import static org.slf4j.LoggerFactory.getLogger;

import java.util.Set;
import java.util.SortedMap;

import javax.jcr.Node;
import javax.jcr.Property;
Expand All @@ -17,10 +18,12 @@

import org.fcrepo.rdf.GraphSubjects;
import org.fcrepo.services.LowLevelStorageService;
import org.fcrepo.services.RepositoryService;
import org.modeshape.jcr.api.JcrConstants;
import org.modeshape.jcr.api.NamespaceRegistry;
import org.slf4j.Logger;

import com.codahale.metrics.Counter;
import com.google.common.collect.BiMap;
import com.google.common.collect.ImmutableBiMap;
import com.hp.hpl.jena.datatypes.RDFDatatype;
Expand Down Expand Up @@ -138,6 +141,7 @@ public static Model getJcrPropertiesModel(
if (node.getPrimaryNodeType().getName().equals("mode:root")){
/* a rdf description of the root node */
logger.debug("Creating RDF response for repository description");
addRepositoryMetricsToModel(factory, node, model);
}

addJcrPropertiesToModel(factory, node, model);
Expand All @@ -151,6 +155,19 @@ public static Model getJcrPropertiesModel(
return model;
}

/**
* @param factory
* @param node
* @param model
*/
private static void addRepositoryMetricsToModel(GraphSubjects factory,
Node node, Model model) throws RepositoryException{
SortedMap<String, Counter> counters = RepositoryService.getMetrics().getCounters();
model.add(factory.getGraphSubject(node),model.createProperty("info:fedora/fedora-system:def/internal#numFixityChecks"), ResourceFactory.createTypedLiteral(counters.get("org.fcrepo.services.LowLevelStorageService.fixity-check-counter").getCount()));
model.add(factory.getGraphSubject(node),model.createProperty("info:fedora/fedora-system:def/internal#numFixityErrors"), ResourceFactory.createTypedLiteral(counters.get("org.fcrepo.services.LowLevelStorageService.fixity-error-counter").getCount()));
model.add(factory.getGraphSubject(node),model.createProperty("info:fedora/fedora-system:def/internal#numFixityRepaired"), ResourceFactory.createTypedLiteral(counters.get("org.fcrepo.services.LowLevelStorageService.fixity-repaired-counter").getCount()));
}

private static void addJcrContentLocationInformationToModel(
final GraphSubjects factory, final Node node,
final Model model) throws RepositoryException {
Expand Down

0 comments on commit 9daa136

Please sign in to comment.