use of org.apache.rya.mongodb.instance.MongoRyaInstanceDetailsRepository in project incubator-rya by apache.
the class MongoGetInstanceDetails method getDetails.
@Override
public Optional<RyaDetails> getDetails(final String ryaInstanceName) throws InstanceDoesNotExistException, RyaClientException {
requireNonNull(ryaInstanceName);
// Ensure the Rya instance exists.
if (!instanceExists.exists(ryaInstanceName)) {
throw new InstanceDoesNotExistException(String.format("There is no Rya instance named '%s'.", ryaInstanceName));
}
// If the instance has details, then return them.
final RyaDetailsRepository detailsRepo = new MongoRyaInstanceDetailsRepository(adminClient, ryaInstanceName);
try {
return Optional.of(detailsRepo.getRyaInstanceDetails());
} catch (final NotInitializedException e) {
return Optional.absent();
} catch (final RyaDetailsRepositoryException e) {
throw new RyaClientException("Could not fetch the Rya instance's details.", e);
}
}
use of org.apache.rya.mongodb.instance.MongoRyaInstanceDetailsRepository in project incubator-rya by apache.
the class MongoPcjIndexSetProvider method hasRyaDetails.
private boolean hasRyaDetails() {
final StatefulMongoDBRdfConfiguration mongoConf = (StatefulMongoDBRdfConfiguration) conf;
final RyaDetailsRepository detailsRepo = new MongoRyaInstanceDetailsRepository(mongoConf.getMongoClient(), mongoConf.getRyaInstanceName());
try {
detailsRepo.getRyaInstanceDetails();
return true;
} catch (final RyaDetailsRepositoryException e) {
return false;
}
}
use of org.apache.rya.mongodb.instance.MongoRyaInstanceDetailsRepository in project incubator-rya by apache.
the class MongoPcjStorageIT method listResults.
@Test
public void listResults() throws Exception {
try (final PrecomputedJoinStorage pcjStorage = new MongoPcjStorage(getMongoClient(), conf.getRyaInstanceName())) {
final MongoRyaInstanceDetailsRepository detailsRepo = new MongoRyaInstanceDetailsRepository(getMongoClient(), conf.getRyaInstanceName());
detailsRepo.initialize(RyaDetails.builder().setRyaInstanceName(conf.getRyaInstanceName()).setRyaVersion("test").setEntityCentricIndexDetails(new EntityCentricIndexDetails(false)).setTemporalIndexDetails(new TemporalIndexDetails(false)).setFreeTextDetails(new FreeTextIndexDetails(false)).setProspectorDetails(new ProspectorDetails(Optional.absent())).setJoinSelectivityDetails(new JoinSelectivityDetails(Optional.absent())).setPCJIndexDetails(PCJIndexDetails.builder().setEnabled(true)).build());
// Create a PCJ.
final String sparql = "SELECT * WHERE { ?a <http://isA> ?b }";
final String pcjId = pcjStorage.createPcj(sparql);
// Add some binding sets to it.
final Set<VisibilityBindingSet> visiSets = new HashSet<>();
final Set<BindingSet> expectedResults = new HashSet<>();
final MapBindingSet aliceBS = new MapBindingSet();
aliceBS.addBinding("a", new URIImpl("http://Alice"));
aliceBS.addBinding("b", new URIImpl("http://Person"));
visiSets.add(new VisibilityBindingSet(aliceBS, ""));
expectedResults.add(aliceBS);
final MapBindingSet charlieBS = new MapBindingSet();
charlieBS.addBinding("a", new URIImpl("http://Charlie"));
charlieBS.addBinding("b", new URIImpl("http://Comedian"));
visiSets.add(new VisibilityBindingSet(charlieBS, ""));
expectedResults.add(charlieBS);
pcjStorage.addResults(pcjId, visiSets);
// List the results that were stored.
final Set<BindingSet> results = new HashSet<>();
try (CloseableIterator<BindingSet> resultsIt = pcjStorage.listResults(pcjId)) {
while (resultsIt.hasNext()) {
results.add(resultsIt.next());
}
}
assertEquals(expectedResults, results);
}
}
use of org.apache.rya.mongodb.instance.MongoRyaInstanceDetailsRepository in project incubator-rya by apache.
the class MongoPcjStorageIT method dropPCJ.
@Test
public void dropPCJ() throws Exception {
try (final PrecomputedJoinStorage pcjStorage = new MongoPcjStorage(getMongoClient(), conf.getRyaInstanceName())) {
final MongoRyaInstanceDetailsRepository detailsRepo = new MongoRyaInstanceDetailsRepository(getMongoClient(), conf.getRyaInstanceName());
detailsRepo.initialize(RyaDetails.builder().setRyaInstanceName(conf.getRyaInstanceName()).setRyaVersion("test").setEntityCentricIndexDetails(new EntityCentricIndexDetails(false)).setTemporalIndexDetails(new TemporalIndexDetails(false)).setFreeTextDetails(new FreeTextIndexDetails(false)).setProspectorDetails(new ProspectorDetails(Optional.absent())).setJoinSelectivityDetails(new JoinSelectivityDetails(Optional.absent())).setPCJIndexDetails(PCJIndexDetails.builder().setEnabled(true)).build());
// Create a PCJ.
final String pcjId = pcjStorage.createPcj("SELECT * WHERE { ?a <http://isA> ?b } ");
// Delete the PCJ that was just created.
pcjStorage.dropPcj(pcjId);
// Ensure the Rya details have been updated to no longer include the PCJ's ID.
final ImmutableMap<String, PCJDetails> detailsMap = detailsRepo.getRyaInstanceDetails().getPCJIndexDetails().getPCJDetails();
assertFalse(detailsMap.containsKey(pcjId));
}
}
use of org.apache.rya.mongodb.instance.MongoRyaInstanceDetailsRepository in project incubator-rya by apache.
the class MongoPcjStorageIT method purge.
@Test
public void purge() throws Exception {
try (final PrecomputedJoinStorage pcjStorage = new MongoPcjStorage(getMongoClient(), conf.getRyaInstanceName())) {
final MongoRyaInstanceDetailsRepository detailsRepo = new MongoRyaInstanceDetailsRepository(getMongoClient(), conf.getRyaInstanceName());
detailsRepo.initialize(RyaDetails.builder().setRyaInstanceName(conf.getRyaInstanceName()).setRyaVersion("test").setEntityCentricIndexDetails(new EntityCentricIndexDetails(false)).setTemporalIndexDetails(new TemporalIndexDetails(false)).setFreeTextDetails(new FreeTextIndexDetails(false)).setProspectorDetails(new ProspectorDetails(Optional.absent())).setJoinSelectivityDetails(new JoinSelectivityDetails(Optional.absent())).setPCJIndexDetails(PCJIndexDetails.builder().setEnabled(true)).build());
// Create a PCJ.
final String sparql = "SELECT * WHERE { ?a <http://isA> ?b }";
final String pcjId = pcjStorage.createPcj(sparql);
// Add some binding sets to it.
final Set<VisibilityBindingSet> expectedResults = new HashSet<>();
final MapBindingSet aliceBS = new MapBindingSet();
aliceBS.addBinding("a", new URIImpl("http://Alice"));
aliceBS.addBinding("b", new URIImpl("http://Person"));
expectedResults.add(new VisibilityBindingSet(aliceBS, ""));
final MapBindingSet charlieBS = new MapBindingSet();
charlieBS.addBinding("a", new URIImpl("http://Charlie"));
charlieBS.addBinding("b", new URIImpl("http://Comedian"));
expectedResults.add(new VisibilityBindingSet(charlieBS, ""));
pcjStorage.addResults(pcjId, expectedResults);
// Purge the PCJ.
pcjStorage.purge(pcjId);
// List the results that were stored.
final Set<BindingSet> results = new HashSet<>();
try (CloseableIterator<BindingSet> resultsIt = pcjStorage.listResults(pcjId)) {
while (resultsIt.hasNext()) {
results.add(resultsIt.next());
}
}
assertTrue(results.isEmpty());
// Make sure the PCJ metadata was updated.
final PcjMetadata metadata = pcjStorage.getPcjMetadata(pcjId);
final Set<VariableOrder> varOrders = new ShiftVarOrderFactory().makeVarOrders(sparql);
final PcjMetadata expectedMetadata = new PcjMetadata(sparql, 0L, varOrders);
assertEquals(expectedMetadata, metadata);
}
}
Aggregations