I'd be very interested in knowing how you pull it off. I spent quite a bit of time trying to get mine to work, but ran into a situation where Database Replication was enabled, but the master (in my case, PROD) cluster can't determine the forest it's supposed to replicate to on the replica (DEV) cluster.
Below are the scripts I ran on my Prod and Dev cluster. After studying how the ML Admin UI does it, looking at the underlying code, and realizing how much checking and switching back and forth between clusters was needed, I decided to just go with this plan (though I haven't found the time to push through with it) : Write a local Python app that : 1. Makes an HTTP call to generate list of databases to be replicated, along with all the necessary ID’s (local and foreign cluster id’s and database id’s) 2. For each database, b. Opens a new browser tab c. makes an HTTP call to port 8001 to dbrep-configure-local-check-go.xqy and pass in all the parameters it needs. In each tab, you will be : 1. redirected to page on the replica cluster 2. asked to click on button 3. redirected to master cluster with replication already configured =========================================================================== (: Code I ran on my master cluster :) xquery version "1.0-ml"; import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy"; declare namespace hs="http://marklogic.com/xdmp/status/host"; declare namespace fc="http://marklogic.com/xdmp/status/foreign-cluster"; declare variable $DATABASE-TABLE := <databases> <database name="myDB1" /> <database name="myDB2" /> <database name="myDB3" /> </databases>; declare function local:get-local-bootstrap-host($config){ let $bootstrap-hosts := admin:cluster-get-xdqp-bootstrap-hosts($config) return if(fn:count($bootstrap-hosts) eq 0) then fn:error((),"ADMIN-NOBOOTSTRAPHOSTCONFIGURED",()) else let $first-available-host := (xdmp:host-status($bootstrap-hosts)[fn:not(fn:exists(hs:error))]/hs:host-id)[1] return if(fn:exists($first-available-host)) then $first-available-host else fn:error((),"ADMIN-NOBOOTSTRAPHOSTONLINE",()) }; let $config := admin:get-configuration() let $foreign-cluster-id := admin:cluster-get-foreign-cluster-id($config, "myDevCluster") let $host-id := local:get-local-bootstrap-host($config) let $fc-status := xdmp:foreign-cluster-status($host-id, xs:unsignedLong($foreign-cluster-id)) let $_ := for $db in $DATABASE-TABLE/database let $foreign-db-name := fn:string($db/@name) let $foreign-db-id := xs:unsignedLong($fc-status/fc:foreign-databases/fc:foreign-database[fc:foreign-database-name eq $foreign-db-name]/fc:foreign-database-id/string()) let $foreign-replica-config := admin:database-foreign-replica($foreign-cluster-id, $foreign-db-id, fn:true(), 300) let $new-config := admin:database-add-foreign-replicas($config, xdmp:database($foreign-db-name), $foreign-replica-config) return xdmp:set($config, $new-config) return admin:save-configuration ($config) ================================================================================= (: Code I ran on the replica cluster :) xquery version "1.0-ml"; import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy"; declare namespace hs="http://marklogic.com/xdmp/status/host"; declare namespace fc="http://marklogic.com/xdmp/status/foreign-cluster"; declare variable $DATABASE-TABLE := <databases> <database name="myDB1" /> <database name="myDB2" /> <database name="myDB3" /> </databases>; declare function local:get-local-bootstrap-host($config){ let $bootstrap-hosts := admin:cluster-get-xdqp-bootstrap-hosts($config) return if(fn:count($bootstrap-hosts) eq 0) then fn:error((),"ADMIN-NOBOOTSTRAPHOSTCONFIGURED",()) else let $first-available-host := (xdmp:host-status($bootstrap-hosts)[fn:not(fn:exists(hs:error))]/hs:host-id)[1] return if(fn:exists($first-available-host)) then $first-available-host else fn:error((),"ADMIN-NOBOOTSTRAPHOSTONLINE",()) }; let $config := admin:get-configuration() let $foreign-cluster-id := admin:cluster-get-foreign-cluster-id($config, "myProdCluster") let $host-id := local:get-local-bootstrap-host($config) let $fc-status := xdmp:foreign-cluster-status($host-id, xs:unsignedLong($foreign-cluster-id)) let $_ := for $db in $DATABASE-TABLE/database let $foreign-db-name := fn:string($db/@name) let $foreign-db-id := xs:unsignedLong($fc-status/fc:foreign-databases/fc:foreign-database[fc:foreign-database-name eq $foreign-db-name]/fc:foreign-database-id/string()) let $foreign-master-config := admin:database-foreign-master($foreign-cluster-id, $foreign-db-id, fn:true()) let $new-config := admin:database-set-foreign-master($config, xdmp:database($foreign-db-name), $foreign-master-config) return xdmp:set($config, $new-config) return admin:save-configuration ($config) On Fri, Oct 31, 2014 at 10:43 AM, Whitby, Rob <[email protected]> wrote: > Thanks Jim, > > Think I was missing the part that you had to call that function on the > local and the foreign cluster. > > Rob > > > From: James Fuller <[email protected]> > Reply-To: MarkLogic Developer Discussion <[email protected]> > Date: Friday, 31 October 2014 14:38 > To: MarkLogic Developer Discussion <[email protected]> > Subject: Re: [MarkLogic Dev General] scripting database replication > > umm, I mean > > http://docs.marklogic.com/admin:foreign-cluster-create > > gives an example, > > you need to do this on each cluster (supplied with the details of the > other cluster). > > hope that is clear, J > > > On Fri, Oct 31, 2014 at 3:33 PM, James Fuller <[email protected] > > wrote: > >> http://docs.marklogic.com/guide/admin-api/cluster#chapter >> >> also in v8 you will have pure REST way of doing this. >> >> hth (and hope all is well with you), J >> >> On Fri, Oct 31, 2014 at 3:31 PM, Whitby, Rob <[email protected]> >> wrote: >> >>> Are there any sample xquery or shell scripts for coupling to a >>> foreign cluster and configuring database replication? Can’t find anything >>> in the docs except using the admin ui. >>> >>> Thanks >>> Rob >>> >>> >>> _______________________________________________ >>> General mailing list >>> [email protected] >>> http://developer.marklogic.com/mailman/listinfo/general >>> >>> >> > > _______________________________________________ > General mailing list > [email protected] > http://developer.marklogic.com/mailman/listinfo/general > >
_______________________________________________ General mailing list [email protected] http://developer.marklogic.com/mailman/listinfo/general
