Skip to content
This repository was archived by the owner on Nov 9, 2022. It is now read-only.

Fixed #298 and #452: made capturing modules more robust #482

Merged
merged 1 commit into from
Aug 17, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 51 additions & 41 deletions deploy/lib/server_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1237,26 +1237,27 @@ def capture
# send the target db, and the destination directory
save_files_to_fs(target_db, "#{tmp_dir}/src")

# check if this is a REST project to capture REST configuration
if (port != nil)

# make sure that REST options directory exists
if Dir.exists? @properties['ml.rest-options.dir']

# set up the options
FileUtils.cp_r(
"#{tmp_dir}/src/#{@properties['ml.group']}/" + target_db.sub("-modules", "") + "/rest-api/.",
@properties['ml.rest-options.dir']
)
FileUtils.rm_rf("#{tmp_dir}/src/#{@properties['ml.group']}/")

# Make sure REST properties are in accurate format, so you can directly deploy them again..
r = go("http://#{@hostname}:#{port}/v1/config/properties", "get")
r.body = parse_json(r.body)
File.open("#{@properties['ml.rest-options.dir']}/properties.xml", 'wb') { |file| file.write(r.body) }
else
raise HelpException.new("capture", "attempting --app-builder REST capture into non-REST project, you may try capture with --modules-db to only capture modules without the REST configuration")
end
# check if this is a REST project to capture REST configuration
if (port != nil)

# make sure that REST options directory exists
if Dir.exists? @properties['ml.rest-options.dir']

# set up the options
FileUtils.cp_r(
"#{tmp_dir}/src/#{@properties['ml.group']}/" + target_db.sub("-modules", "") + "/rest-api/.",
@properties['ml.rest-options.dir']
)
FileUtils.rm_rf("#{tmp_dir}/src/#{@properties['ml.group']}/")

# Make sure REST properties are in accurate format, so you can directly deploy them again..
r = go("http://#{@hostname}:#{port}/v1/config/properties", "get")
r.body = parse_json(r.body)
File.open("#{@properties['ml.rest-options.dir']}/properties.xml", 'wb') { |file| file.write(r.body) }

else
raise HelpException.new("capture", "attempting --app-builder REST capture into non-REST project, you may try capture with --modules-db to only capture modules without the REST configuration")
end
end

# If we have an application/custom directory, we've probably done a capture
Expand Down Expand Up @@ -1298,9 +1299,18 @@ def save_files_to_fs(target_db, target_dir)
dirs = execute_query %Q{
xquery version "1.0-ml";

for $uri in cts:uris()
order by $uri
return $uri
try {
for $uri in cts:uris()
order by $uri
return $uri

} catch ($ignore) {
(: In case URI lexicon has not been enabled :)
for $doc in collection()
let $uri := xdmp:node-uri($doc)
order by $uri
return $uri
}
},
{ :db_name => target_db }

Expand All @@ -1312,16 +1322,16 @@ def save_files_to_fs(target_db, target_dir)
if ['5', '6'].include? @properties['ml.server-version']
# In ML5 and ML6, the response was a bunch of text. Split on the newlines.
dirs.body.split(/\r?\n/).each do |uri|
if (uri.end_with?("/"))
# create the directory so that it will exist when we try to save files
Dir.mkdir("#{target_dir}" + uri)
else
r = execute_query %Q{
fn:doc("#{uri}")
},
{ :db_name => target_db }

File.open("#{target_dir}#{uri}", 'wb') { |file| file.write(r.body) }
r = execute_query %Q{
fn:doc("#{uri}")
},
{ :db_name => target_db }

path = "#{target_dir}#{uri}"
parentdir = File.dirname path
FileUtils.mkdir_p(parentdir) unless File.exists?(parentdir)
if ! uri.end_with?("/")
File.open("#{path}", 'wb') { |file| file.write(r.body) }
end
end
else
Expand All @@ -1334,14 +1344,14 @@ def save_files_to_fs(target_db, target_dir)

JSON.parse(dirs.body).each do |item|
uri = item['result']
if (uri.end_with?("/"))
# create the directory so that it will exist when we try to save files
Dir.mkdir("#{target_dir}" + uri)
else
r = go("#{@protocol}://#{@hostname}:#{@bootstrap_port}/qconsole/endpoints/view.xqy?dbid=#{db_id}&uri=#{uri}", "get")
file_content = r.body
File.open("#{target_dir}#{uri}", 'wb') { |file| file.write(file_content) }
end
r = go("#{@protocol}://#{@hostname}:#{@bootstrap_port}/qconsole/endpoints/view.xqy?dbid=#{db_id}&uri=#{URI.escape(uri).gsub(/\$/, '%24')}", "get")

path = "#{target_dir}#{uri}"
parentdir = File.dirname path
FileUtils.mkdir_p(parentdir) unless File.exists?(parentdir)
if ! uri.end_with?("/")
File.open("#{path}", 'wb') { |file| file.write(r.body) }
end
end
end
end
Expand Down