Skip to content

Commit

Permalink
marklogic-community#661: added more robustness, and made eval work ag…
Browse files Browse the repository at this point in the history
…ainst ml8
  • Loading branch information
grtjn committed Jun 9, 2017
1 parent f2ebad2 commit f156aaa
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions deploy/lib/server_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2412,8 +2412,10 @@ def execute_query_5(query, properties = {})
# 4. Any database
if properties[:db_name] != nil
db_id = get_db_id(properties[:db_name])
logger.warn "WARN: No Database with name #{properties[:db_name]} found" if db_id.nil?
elsif properties[:app_name] != nil
sid = get_sid(properties[:app_name])
logger.warn "WARN: No App-Server with name #{properties[:app_name]} found" if sid.nil?
else
sid = get_sid("Manage")
end
Expand Down Expand Up @@ -2454,8 +2456,10 @@ def execute_query_7(query, properties = {})
# 4. Any database
if properties[:db_name] != nil
db_id = get_db_id(properties[:db_name])
logger.warn "WARN: No Database with name #{properties[:db_name]} found" if db_id.nil?
elsif properties[:app_name] != nil
sid = get_sid(properties[:app_name])
logger.warn "WARN: No App-Server with name #{properties[:app_name]} found" if sid.nil?
else
sid = get_sid("Manage")
end
Expand Down Expand Up @@ -2487,11 +2491,22 @@ def execute_query_7(query, properties = {})
end

def execute_query_8(query, properties = {})
# check input like in older versions
if properties[:db_name] != nil
db_id = get_db_id(properties[:db_name])
raise ExitException.new("No Database with name #{properties[:db_name]} found") if db_id.nil?
elsif properties[:app_name] != nil
sid = get_sid(properties[:app_name])
raise ExitException.new("No Server with name #{properties[:app_name]} found") if sid.nil?
end

headers = {
"Content-Type" => "application/x-www-form-urlencoded"
}
params = {}

# If app_name is specified, wrap the eval in an xdmp:eval to create an eval context
# that matches that of the selected app-server
if properties[:app_name] != nil
params[:xquery] = %Q{
xquery version "1.0-ml";
Expand All @@ -2506,7 +2521,10 @@ def execute_query_8(query, properties = {})
let $modules-id := xdmp:server-modules-database($server-id)
let $xquery-version := xdmp:server-default-xquery-version($server-id)
let $modules-root := xdmp:server-root($server-id)
let $default-coordinate-system := xdmp:server-coordinate-system($server-id)
let $default-coordinate-system :=
(: xdmp:server-coordinate-system not supported in ML8 and older :)
for $f in fn:function-lookup(xs:QName("xdmp:server-coordinate-system"), 1)
return $f($server-id)
return
<options xmlns="xdmp:eval">{
if ($database-id eq xdmp:database()) then ()
Expand Down Expand Up @@ -2540,11 +2558,13 @@ def execute_query_8(query, properties = {})
)
}
else
# No app_name, just run the straight query
params[:xquery] = query
end

if properties[:db_name] != nil
params[:database] = properties[:db_name]
# Pass through selected database if specified, otherwise run against App-Services
if properties[:db_name] != nil
params[:database] = properties[:db_name]
end
end

r = go "#{@protocol}://#{@hostname}:#{@qconsole_port}/v1/eval", "post", headers, params
Expand Down

0 comments on commit f156aaa

Please sign in to comment.