From 53fbcb8fcd24720534eba723151be8cade82cd81 Mon Sep 17 00:00:00 2001 From: Geert Josten Date: Thu, 1 Jun 2017 17:10:25 +0200 Subject: [PATCH] Added to #703: making changes backwards-compatible with ML 7 --- deploy/lib/server_config.rb | 52 +++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/deploy/lib/server_config.rb b/deploy/lib/server_config.rb index e7a34156..9cc86d24 100644 --- a/deploy/lib/server_config.rb +++ b/deploy/lib/server_config.rb @@ -543,23 +543,48 @@ def restart_group(group = nil) if group == "cluster" logger.info "Restarting MarkLogic Server cluster of #{@hostname}" - r = go(%Q{http://#{@properties["ml.server"]}:#{@properties["ml.bootstrap-port"]}/manage/v2?format=json}, "post", { - 'Content-Type' => 'application/json' - }, nil, %Q{ - { "operation": "restart-local-cluster" } - }) else logger.info "Restarting MarkLogic Server group #{group}" - r = go(%Q{http://#{@properties["ml.server"]}:#{@properties["ml.bootstrap-port"]}/manage/v2/groups/#{group}?format=json}, "post", { - 'Content-Type' => 'application/json' - }, nil, %Q{ - { "operation": "restart-group" } - }) end - raise ExitException.new(r.body) unless r.code.to_i == 202 + if @server_version > 7 + # MarkLogic 8+, make use of Management REST api and return details of all involved hosts + + if group == "cluster" + r = go(%Q{http://#{@properties["ml.server"]}:#{@properties["ml.bootstrap-port"]}/manage/v2?format=json}, "post", { + 'Content-Type' => 'application/json' + }, nil, %Q{ + { "operation": "restart-local-cluster" } + }) + else + r = go(%Q{http://#{@properties["ml.server"]}:#{@properties["ml.bootstrap-port"]}/manage/v2/groups/#{group}?format=json}, "post", { + 'Content-Type' => 'application/json' + }, nil, %Q{ + { "operation": "restart-group" } + }) + end + + raise ExitException.new(r.body) unless r.code.to_i == 202 + + return JSON.parse(r.body)['restart']['last-startup'] + else + # MarkLogic 7- fallback, restart as before, and only verify restart of bootstrap host - return JSON.parse(r.body)['restart']['last-startup'] + old_timestamp = go(%Q{http://#{@properties["ml.server"]}:8001/admin/v1/timestamp}, "get").body + + logger.debug "this: #{self}" + setup = File.read ServerConfig.expand_path("#{@@path}/lib/xquery/setup.xqy") + r = execute_query %Q{#{setup} setup:do-restart("#{group}")} + logger.debug "code: #{r.code.to_i}" + + r.body = parse_body(r.body) + logger.info r.body + + return [{ + 'host-id' => @properties["ml.server"], + 'value' => old_timestamp + }] + end end def get_host_names @@ -567,7 +592,8 @@ def get_host_names raise ExitException.new(r.body) unless r.code.to_i == 200 - names = {} + names = { @properties["ml.server"] => @properties["ml.server"] } # ml7 fallback + JSON.parse(r.body)['host-default-list']['list-items']['list-item'].each do |host| names[host['idref']] = host['nameref'] end