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

Fixing Issue #223 Capture modules for any app type #356

Merged
Merged
Show file tree
Hide file tree
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
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
54 changes: 33 additions & 21 deletions deploy/lib/server_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -933,9 +933,7 @@ def capture

# check params
if full_config == nil && config == nil && target_db == nil
raise HelpException.new("capture", "either full-ml-config, ml-config or modules-db is required")
elsif target_db != nil && @properties['ml.app-type'] != 'rest'
raise ExitException.new("This is a #{@properties['ml.app-type']} application; capture modules only works for app-type=rest")
raise HelpException.new("capture", "either full-ml-config, ml-config, app-builder or modules-db is required")
end

# retrieve full setup config from environment
Expand All @@ -947,22 +945,36 @@ def capture
if target_db != nil
tmp_dir = Dir.mktmpdir
logger.debug "using temp dir " + tmp_dir
logger.info "Retrieving source and REST config from #{target_db}..."

save_files_to_fs(target_db, "#{tmp_dir}/src")

# 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..
if (port != nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice way to solve capturing non-REST modules..

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) }
logger.info "Retrieving source and REST config from #{target_db}..."
else
logger.info "Retrieving source from #{target_db}..."
end

# 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 Down Expand Up @@ -1026,12 +1038,12 @@ def save_files_to_fs(target_db, target_dir)
# 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.open("#{target_dir}#{uri}", 'wb') { |file| file.write(r.body) }
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