diff --git a/deploy/default.properties b/deploy/default.properties index 40d5a6a6..1786914f 100644 --- a/deploy/default.properties +++ b/deploy/default.properties @@ -206,3 +206,8 @@ mlcp-vmargs=-Xmx512m # Temporary fix to support MarkLogic 8 EA2 # evaler-port=7998 + +# +# List of MarkLogic system databases, for replication +# +system-dbs=App-Services,Documents,Extensions,Fab,Last-Login,Meters,Modules,Schemas,Security,Triggers diff --git a/deploy/lib/server_config.rb b/deploy/lib/server_config.rb index 067584cf..40d810d1 100644 --- a/deploy/lib/server_config.rb +++ b/deploy/lib/server_config.rb @@ -536,9 +536,76 @@ def config def bootstrap raise ExitException.new("Bootstrap requires the target environment's hostname to be defined") unless @hostname.present? - logger.info "Bootstrapping your project into MarkLogic #{@properties['ml.server-version']} on #{@hostname}..." + internals = find_arg(['--replicate-internals']) + if internals + + nr = find_arg(['--nr-replicas']) + if nr + nr = nr.to_i + else + nr = 2 + end + + # check cluster size + r = execute_query %Q{ fn:count(xdmp:hosts()) } + r.body = parse_json(r.body) + raise ExitException.new("Increase nr-replicas, minimum is 1") if nr < 1 + raise ExitException.new("Adding #{nr} replicas to internals requires at least a #{nr + 1} node cluster") if r.body.to_i <= nr + + logger.info "Bootstrapping replicas for #{@properties['ml.system-dbs']} on #{@hostname}..." + + # build custom ml-config + assigns = '' + internals = @properties['ml.system-dbs'].split ',' + internals.each do |db| + repnames = '' + repassigns = '' + (1..nr).each do |i| + repnames = repnames + %Q{ + #{db}-rep#{i}} + repassigns = repassigns + %Q{ + + #{db}-rep#{i} + } + end + + assigns = assigns + %Q{ + + + + #{db} + #{repnames} + + #{repassigns}} + end + databases = '' + internals.each do |db| + databases = databases + %Q{ + + + + #{db} + + + + } + end + config = %Q{ + + #{assigns} + + #{databases} + + + } + logger.debug config + else + logger.info "Bootstrapping your project into MarkLogic #{@properties['ml.server-version']} on #{@hostname}..." + config = get_config + end + setup = File.read(ServerConfig.expand_path("#{@@path}/lib/xquery/setup.xqy")) - r = execute_query %Q{#{setup} setup:do-setup(#{get_config})} + r = execute_query %Q{#{setup} setup:do-setup(#{config})} logger.debug "code: #{r.code.to_i}" r.body = parse_json(r.body) @@ -585,6 +652,7 @@ def wipe end appbuilder = find_arg(['--app-builder']) + internals = find_arg(['--internal-replicas']) setup = File.read(ServerConfig.expand_path("#{@@path}/lib/xquery/setup.xqy")) if (appbuilder != nil) @@ -611,7 +679,7 @@ def wipe } - else + elsif (internals == nil) databases = find_arg(['--databases']) || '##none##' forests = find_arg(['--forests']) || '##none##' servers = find_arg(['--servers']) || '##none##' @@ -649,8 +717,42 @@ def wipe end end - #logger.debug %Q{#{setup} setup:do-wipe(#{config})} - r = execute_query %Q{#{setup} setup:do-wipe(#{config})} + if (internals != nil) + logger.info "Wiping replicas for #{@properties['ml.system-dbs']} from #{@hostname}.." + r = execute_query %Q{ + xquery version "1.0-ml"; + + import module namespace admin = "http://marklogic.com/xdmp/admin" + at "/MarkLogic/admin.xqy"; + + let $admin-config := admin:get-configuration() + let $replicas := + for $forest-name in (#{quote_arglist(@properties['ml.system-dbs'])}) + let $forest-id := admin:forest-get-id($admin-config, $forest-name) + for $replica in admin:forest-get-replicas($admin-config, $forest-id) + return ( + xdmp:set( + $admin-config, + admin:forest-remove-replica($admin-config, $forest-id, $replica) + ), + $replica + ) + let $_ := + for $replica in $replicas + return xdmp:set( + $admin-config, + admin:forest-delete($admin-config, $replica, fn:true()) + ) + return + if (admin:save-configuration-without-restart($admin-config)) then + "(note: restart required)" + else () + + } + else + #logger.debug %Q{#{setup} setup:do-wipe(#{config})} + r = execute_query %Q{#{setup} setup:do-wipe(#{config})} + end logger.debug "code: #{r.code.to_i}" r.body = parse_json(r.body)