Search code examples
javasesameallegrographfederated

Federated store with repositories from different server


I want to create an abstract repository to a federated store in AllegroGraph.

I can connect to the repositories stored on different server. But when I try to combine them using federate function, it throws an error that it cannot find the repository on the second server.

I found the same question in this link but it doesn't help. Any hints?

This is my code:

AGServer server = new AGServer(SERVER_URL, USERNAME, PASSWORD);
AGServer server2 = new AGServer(SERVER_URL2, USERNAME2, PASSWORD2);
println("Available catalogs: " + server.listCatalogs());
AGRepositoryConnection custCon = server.createRepositoryConnection("repo1", CATALOG_ID, false);
AGRepositoryConnection supCon = server2.createRepositoryConnection("repo2", CATALOG_ID, false);
AGAbstractRepository rainbowRepo = server2.federate(custCon.getRepository(), supCon.getRepository());

rainbowRepo.initialize();
AGRepositoryConnection rainbowConn = rainbowRepo.getConnection();

Solution

  • SailRepository class implements FederatedServiceResolverClient for the federation context, so u can use the class SailRepository to add a federated store with different repositories :

    AGServer server = new AGServer(SERVER_URL, USERNAME, PASSWORD);
    AGServer server2 = new AGServer(SERVER_URL2, USERNAME2, PASSWORD2);
    
    AGRepository repo1 = server.getCatalog(CATALOG_ID).openRepository("repo1");
    AGRepository repo2 = server2.getCatalog(CATALOG_ID).openRepository("repo2");
    
    Federation federation = new Federation();
    federation.addMember(repo1);
    federation.addMember(repo2);
    federation.setReadOnly(true); 
    
    SailRepository rainbowRepo  = new SailRepository(federation);
    rainbowRepo .initialize();
    
    SailRepositoryConnection rainbowConn  =  rainbowRepo .getConnection(); //for querying and updating the contents of the repository.