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

Fixes for #8, #83, #176, #207, #209, #210, #211, #212, #214, #216, #217 #221

Merged
merged 30 commits into from
Apr 28, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
6eb605c
Improved self-test for MarkLogic 7
grtjn Apr 17, 2014
1c7d901
Merge remote-tracking branch 'upstream/dev' into dev
grtjn Apr 22, 2014
bc550aa
Fix for #210: new usage when running ml from roxy root
grtjn Apr 22, 2014
90046d9
Fix for #176: improved Roxy documentation
grtjn Apr 22, 2014
4d645b7
Removed usage as explicit command
grtjn Apr 22, 2014
4c3abb2
Removed usage as explicit command
grtjn Apr 22, 2014
8ca73ad
Fix for #207: used eval instead of xdmp:user to get scheduled user
grtjn Apr 22, 2014
f059a25
Initial attempt on #8: capturing the full environment ml-config with …
grtjn Apr 22, 2014
0256097
Added JSON Parsing on response bodies for ML 7
grtjn Apr 23, 2014
095e5bf
Extended ml7-config.xml self-test data with non-default values, schem…
grtjn Apr 23, 2014
7fad34a
Fixes for #209, #211, #212: enabled appserver settings validation, an…
grtjn Apr 23, 2014
fa6bf5d
Fix for #214: allowing --server-version param for self-test
grtjn Apr 24, 2014
6bf917f
Extra log line showing test version
grtjn Apr 24, 2014
ca268f2
Added mimetype sample to ml-config sample
grtjn Apr 24, 2014
2b2a3e7
Added version check to module-locations (#209), removed server settin…
grtjn Apr 24, 2014
4de7a2f
Fix for #216 and #217: exit early at ml new failure, and --fork optio…
grtjn Apr 24, 2014
6f34ea6
Added --fork to upgrade as well (#217)
grtjn Apr 24, 2014
31cf816
Merge remote-tracking branch 'upstream/dev' into dev
grtjn Apr 24, 2014
124ed96
Removed roxy dir check from ml, improved ml help a bit
grtjn Apr 25, 2014
9edac78
Improved ml self-test param handling (#214)
grtjn Apr 25, 2014
6752925
Fix for #83: ask confirmation for running ml new from a Roxy project
grtjn Apr 25, 2014
ceaf451
Normalized indentation in ml.bat
grtjn Apr 25, 2014
e9c917b
Synching ml changes with ml.bat
grtjn Apr 25, 2014
5696a58
Synched changes for #217 with ml.bat
grtjn Apr 25, 2014
c1e4994
Synched changes for #214 with ml.bat
grtjn Apr 25, 2014
3879a8c
Synched changes for #83 with ml.bat
grtjn Apr 25, 2014
447eb32
Added a TODO in ml.bat for issue #216
grtjn Apr 25, 2014
7034b8b
Reverted unwanted and non-relevant changes (#176)
grtjn Apr 25, 2014
504ebb0
Reverted unwanted and non-relevant changes (#176)
grtjn Apr 25, 2014
292f87b
Merge remote-tracking branch 'upstream/dev' into dev
grtjn Apr 25, 2014
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
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# http://editorconfig.org
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
20 changes: 20 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"browser": true,
"camelcase": true,
"curly": true,
"eqeqeq": true,
"immed": true,
"indent": 2,
"latedef": true,
"newcap": true,
"quotmark": "single",
"undef": true,
"unused": "vars",
"strict": true,
"trailing": true,
"globals": {
"angular": false,
"google": false,
"$": false
}
}
68 changes: 36 additions & 32 deletions deploy/lib/Help.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,40 @@ class Help
def self.usage
<<-DOC.strip_heredoc

Usage: ml ENVIRONMENT COMMAND [ARGS]

Deployment Commands:
init Creates configuration files for you to customize
initcpf Creates cpf configuration files for you to customize
info Return settings for a given environment
credentials Configures user and password for a given environment
bootstrap Configures your application on the MarkLogic server
wipe Remove your configuration from the MarkLogic server
restart Restart your MarkLogic server
deploy Loads modules, data, cpf configuration into the server
load Loads a file or folder into the server
clean Removes all files from the cpf, modules, or content databases
info Prints the environment-specific configuration information
test Runs xquery unit tests
recordloader Runs RecordLoader
xqsync Runs XQSync
corb Runs Corb

Roxy Scaffolding commands:
create Creates a controller or view or model
index Adds an index to the configuration
extend Create a REST API service extension
transform Create a REST API transformation

Other commands:
upgrade Upgrades the Roxy files
capture Capture the source code of an existing App Builder application

All commands can be run with -h for more information.

Usage:
ml [ENVIRONMENT] COMMAND [ARGS]

Generic commands (no environment):
init Creates configuration files for you to customize
initcpf Creates cpf configuration files for you to customize
jar Creates a Roxy jar
new Creates a new project directory structure
upgrade Upgrades the Roxy files

Scaffolding commands (no environment):
create Creates a controller, model, test or layout
index Adds an index to the configuration
extend Creates a REST API service extension
transform Creates a REST API transformation

Bootstrapping commands (with environment):
bootstrap Configures your application on the given environment
capture Captures the source code of an existing App Builder 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
restart Restarts the given environment
wipe Removes your application from the given environment

Deployment commands (with environment):
corb Runs Corb against the given environment
deploy Loads modules, data, cpf configuration into the given environment
load Loads a file or folder into the given environment
recordloader Runs RecordLoader against the given environment
test Runs xquery unit tests against the given environment
xqsync Runs XQSync against the given environment

All commands can be run with -h or --help for more information. Leave out environment..
DOC
end

Expand Down Expand Up @@ -453,7 +456,8 @@ def self.jar
end

def self.doHelp(logger, command, error_message = nil)
logger.error "#{error_message}\n" if error_message
logger.info "" if error_message
logger.error "#{error_message}" if error_message
logger.info Help.send(command)
end
end
7 changes: 6 additions & 1 deletion deploy/lib/ml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ def need_help?

ARGV << '--help' if ARGV.empty?

if ARGV.length == 1 && need_help?
Help.doHelp(@logger, :usage)
exit
end

@profile = find_arg(['-p', '--profile'])
if @profile then
begin
Expand Down Expand Up @@ -127,7 +132,7 @@ def need_help?
:logger => @logger
).send(command)
else
Help.doHelp(@logger, :usage)
Help.doHelp(@logger, :usage, "Unknown command #{command}!")
break
end
end
Expand Down
99 changes: 70 additions & 29 deletions deploy/lib/server_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -439,15 +439,27 @@ def validate_install
logger.info "code: #{r.code.to_i}"
logger.info r.body

if r.body.match("<error:error")
if r.body.match('"result":"<error:error')
JSON.parse(r.body).each do |item|
logger.error item['result']
end
result = false
elsif r.body.match("<error:error")
logger.error r.body
result = false
else
logger.info "... Validation SUCCESS"
result = true
end
rescue Net::HTTPFatalError => e
logger.error e.response.body
if e.response.body.match('"result":"<error:error')
JSON.parse(e.response.body).each do |item|
logger.error item['result']
end
result = false
else
logger.error e.response.body
end
logger.error "... Validation FAILED"
result = false
end
Expand Down Expand Up @@ -709,40 +721,47 @@ def credentials
end

def capture

if @properties['ml.app-type'] != 'rest'
raise ExitException.new("This is a #{@properties['ml.app-type']} application; capture only works for app-type=rest")
end

full_config = find_arg(['--full-ml-config'])
target_db = find_arg(['--modules-db'])

if target_db == nil
raise HelpException.new("capture", "modules-db is required")

# check params
if full_config == nil && target_db == nil
raise HelpException.new("capture", "either full-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")
end

tmp_dir = Dir.mktmpdir
logger.debug "using temp dir " + tmp_dir
logger.info "Retrieving source and REST config from #{target_db}..."
# retrieve full setup config from environment
if full_config != nil
capture_environment_config
end

save_files_to_fs(target_db, "#{tmp_dir}/src")
# retrieve modules from selected database from environment
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']}/")

# If we have an application/custom directory, we've probably done a capture
# before. Don't overwrite that directory. Kill the downloaded custom directory
# to avoid overwriting.
if Dir.exists? "#{@properties["ml.xquery.dir"]}/application/custom"
FileUtils.rm_rf("#{tmp_dir}/src/application/custom")
end

# 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']}/")
FileUtils.cp_r("#{tmp_dir}/src/.", @properties["ml.xquery.dir"])

# If we have an application/custom directory, we've probably done a capture
# before. Don't overwrite that directory. Kill the downloaded custom directory
# to avoid overwriting.
if Dir.exists? "#{@properties["ml.xquery.dir"]}/application/custom"
FileUtils.rm_rf("#{tmp_dir}/src/application/custom")
FileUtils.rm_rf(tmp_dir)
end

FileUtils.cp_r("#{tmp_dir}/src/.", @properties["ml.xquery.dir"])

FileUtils.rm_rf(tmp_dir)
end

private
Expand Down Expand Up @@ -801,6 +820,28 @@ def save_files_to_fs(target_db, target_dir)

end

def capture_environment_config
raise ExitException.new("Capture requires the target environment's hostname to be defined") unless @hostname.present?

logger.info "Capturing configuration of MarkLogic on #{@hostname}..."
setup = File.read(ServerConfig.expand_path("#{@@path}/lib/xquery/setup.xqy"))
r = execute_query %Q{#{setup} setup:get-configuration((), (), (), (), (), ())}

if r.body.match("error log")
logger.error r.body
logger.error "... Capture FAILED"
return false
else
JSON.parse(r.body).each do |item|
contents = item['result']
name = "#{@properties["ml.config.file"].sub( %r{.xml}, '' )}-#{@properties["ml.environment"]}.xml"
File.open(name, 'w') { |file| file.write(contents) }
logger.info("... Captured full configuration into #{name}")
end
return true
end
end

# Build an array of role/capability objects.
def permissions(role, capabilities)
if capabilities.is_a?(Array)
Expand Down
5 changes: 3 additions & 2 deletions deploy/lib/upgrader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def upgrade_base(tmp_dir)
end

def upgrade(args)
fork = find_arg(['--fork']) || 'marklogic'
branch = find_arg(['--branch'])
raise HelpException.new("upgrade", "Missing branch name") unless branch

Expand All @@ -62,11 +63,11 @@ def upgrade(args)
confirm = gets.chomp

if confirm.match(/^y(es)?$/i)
@logger.info "Upgrading to the #{branch} branch"
@logger.info "Upgrading to the #{branch} branch from #{fork}/roxy"
tmp_dir = Dir.mktmpdir

@logger.info "Cloning Roxy in a temp directory..."
system("git clone git://github.com/marklogic/roxy.git -b #{branch} #{tmp_dir}")
system("git clone git://github.com/#{fork}/roxy.git -b #{branch} #{tmp_dir}")

@logger.info "Upgrading base project files\n"
upgrade_base(tmp_dir)
Expand Down
Loading