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

Commit

Permalink
Merge pull request #356 from alencruz/223-Capture-modules-any-app-type
Browse files Browse the repository at this point in the history
Fixing Issue #223 Capture modules for any app type
  • Loading branch information
grtjn committed Apr 14, 2015
2 parents 128590f + 6a04f76 commit deac106
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 24 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 @@ -473,11 +473,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 @@ -1079,9 +1079,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 @@ -1093,22 +1091,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)
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 @@ -1190,12 +1202,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

0 comments on commit deac106

Please sign in to comment.