Figured it out.

Had to call xdmp:foreign-cluster-status() and extract the database id from
the list of databases it returns.

Code below is based mostly from
*/opt/MarkLogic/Admin/lib/dbrep-configure-2-form.xqy* .

Regards,
Danny

==============================================================

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 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,
"my-dev-cluster")
let $host-id := local:get-local-bootstrap-host($config)
let $fc-status := xdmp:foreign-cluster-status($host-id,
xs:unsignedLong($foreign-cluster-id))
return

$fc-status/fc:foreign-databases/fc:foreign-database[fc:foreign-database-name
eq 'my-database']

On Tue, Oct 14, 2014 at 11:16 AM, Danny Sinang <[email protected]> wrote:

> I'm trying to write an XQUERY script to configure our production cluster
> (running ML 7.0-3) to replicate some of its databases to a new dev cluster.
>
> My plan is to loop through the names of the production databases that I
> want replicated and call :
>
> *1. admin:database-foreign-replica($foreign-cluster-id, $foreign-db-id) *
> and
> *2. admin:database-set-foreign-replicas () *
>
> for each database.
>
> Question is, how do I determine *$foreign-db-id* at runtime ? I know
> before-hand its name (the same as the production database name), but I
> can't seem to find the right function to use to  get the ID of that
> "foreign" database.
>
> Any ideas ?
>
> There is of course the option of me running a script on the dev cluster to
> generated the db IDs and copying them over to my master cluster script as
> hardcoded values, but I'm trying to avoid hardcoding as much as possible.
>
> Regards,
> Danny
>
>
>
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to