问题
I'm trying to create an abstract repository for doing a federal search on Allegro Graph. I'm able to connect to the repositories stored on different server. However, when I tried to combined them using the federate, it throws an error that it cannot find the repo on the second server. Is there a way to combined two repositories stored on different server into an abstract repository where a federal search can be done?
AGServer server = new AGServer(SERVER_URL1, USERNAME1, PASSWORD1);
AGRepository repo1 = server.getRootCatalog().openRepository(REPO1);
AGServer server2 = new AGServer(SERVER_URL2, USERNAME2, PASSWORD2);
AGRepository repo2 = server2.getRootCatalog().openRepository(REPO2);
System.out.println(repo1.getConnection().size());
System.out.println(repo2.getConnection().size());
AGAbstractRepository combinedRepo = server.federate(repo1, repo2);
combinedRepo.initialize();
combinedRepo.getConnection(); //this return an exception
Exception in thread "main" org.openrdf.repository.RepositoryException: org.openrdf.repository.RepositoryException: Repository not found with ID: REPO2
at com.franz.agraph.repository.AGCatalog.openRepository(AGCatalog.java:264)
...
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: org.openrdf.repository.RepositoryException: Repository not found with ID: REPO2
at com.franz.agraph.repository.AGCatalog.openRepository(AGCatalog.java:260)
... 6 more
TIA
回答1:
The Sesame framework supports a Federation Sail
which you can use to wrap several Sesame repositories (living in different servers/locations) into one virtual store. You could try and use that instead of using Allegrograph's bespoke federation code (which seems geared to multiple repositories on a single server only):
// create your AG repositories the same way
AGServer server = new AGServer(SERVER_URL1, USERNAME1, PASSWORD1);
AGRepository repo1 = server.getRootCatalog().openRepository(REPO1);
AGServer server2 = new AGServer(SERVER_URL2, USERNAME2, PASSWORD2);
AGRepository repo2 = server2.getRootCatalog().openRepository(REPO2);
// Use a Sesame Federation to combine them
org.openrdf.sail.federation.Federation federation = new Federation();
federation.addMember(repo1);
federation.addMember(repo2);
federation.setReadOnly(true); // assuming you only use it for query
Repository combinedRepo = new SailRepository(federation);
combinedRepo.initialize();
(ObDisclaimer: above code written from the top of my head, I may have overlooked a required config detail to get this to work - but you get the gist hopefully)
An alternative is that you work with SPARQL's support for federation, via the SERVICE clause. This will require that each repository you want to query is accessible via HTTP as a SPARQL endpoint though.
回答2:
I was able to make a federated repository using the AGServer of Allegro Graph. Here's how I did it for those who might find it helpful:
AGVirtualRepository s = server2.virtualRepository("<http://<ip address>:10035/repositories/repo1> + <http://<ip address>:10035/repositories/repo2>");
AGRepositoryConnection combinedConn = s.getConnection();
来源:https://stackoverflow.com/questions/21846073/allegro-graph-federate-repositories-located-on-different-server