Skip to content

Commit

Permalink
Modification to the Fix for Issue marklogic-community#223 also Fixes …
Browse files Browse the repository at this point in the history
…Issue marklogic-community#298

Improved the fix for Issue marklogic-community#223 based on feedback received.
Also fixes Issue marklogic-community#298 since it protects against the error condition.
In addition some of the Capture help content was clarified to reflect the implementation.
  • Loading branch information
alencruz committed Mar 31, 2015
1 parent 3fc118e commit 6a04f76
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 39 deletions.
12 changes: 9 additions & 3 deletions deploy/lib/Help.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def self.usage
Bootstrapping commands (with environment):
bootstrap Configures your application on the given environment
capture Captures the source code of an existing App Builder application
capture Captures the source code and if applicable the REST configuration of an existing application
clean Removes all files from the cpf, modules, or content databases on the given environment
credentials Configures user and password for the given environment
info Returns settings for the given environment
Expand Down Expand Up @@ -459,11 +459,17 @@ def self.upgrade
def self.capture
<<-DOC.strip_heredoc
Usage: ml {env} capture --modules-db=[name of modules database]
Captures the source for an existing application
modules-db: (required)
The modules database of the application.
ml {env} capture --app-builder=[name of Application Builder-based application]
Captures the source and REST API configuration for an existing
Application Builder-based application.
modules-db: (required)
The modules database of the App Builder application.
app-builder: (required)
The name of the App Builder application.
DOC
end

Expand Down
64 changes: 28 additions & 36 deletions deploy/lib/server_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -952,23 +952,29 @@ def capture
logger.info "Retrieving source from #{target_db}..."
end

# send the target db, the destination directory, and port to know if REST for ML7+
save_files_to_fs(target_db, "#{tmp_dir}/src", port)

if (port != nil)
# 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']}/")
end

# Make sure REST properties are in accurate format, so you can directly deploy them again..
if (port != nil)
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) }
# 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
end

# If we have an application/custom directory, we've probably done a capture
Expand All @@ -986,7 +992,7 @@ def capture

private

def save_files_to_fs(target_db, target_dir, port)
def save_files_to_fs(target_db, target_dir)
# Get the list of URIs. We get them in order because Ruby's Dir.mkdir
# command doesn't have a -p option (create parent).
dirs = execute_query %Q{
Expand Down Expand Up @@ -1032,26 +1038,12 @@ def save_files_to_fs(target_db, target_dir, port)
# create the directory so that it will exist when we try to save files
Dir.mkdir("#{target_dir}" + uri)
else
# check type, if REST use that endpoint, otherwise use a query
if (port != nil)
r = go("#{@protocol}://#{@hostname}:#{@bootstrap_port}/qconsole/endpoints/view.xqy?dbid=#{db_id}&uri=#{uri}", "get")
file_content = r.body
else
# Note : There are limitations to doing it this way for non REST DBs; only text files are captured (xqy, html, etc..)
# other types such as images or java scripts will not be grabbed. Also this method is slower than REST or XCC.
r = execute_query %Q{
fn:doc("#{uri}")
},
{ :db_name => target_db }
response_hash = JSON.parse("#{r.body}").each do |r|
file_content = r['result']
end
end
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}", "get")
file_content = r.body
File.open("#{target_dir}#{uri}", 'wb') { |file| file.write(file_content) }
end
end
end

end

# Note: this is the beginning of a feature; not really useful yet. What we want is to specify one or more app servers,
Expand Down

0 comments on commit 6a04f76

Please sign in to comment.