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 #626 from hansenmc/issue521
Browse files Browse the repository at this point in the history
Fixing Issue #521: support custom properties for CoRB2
  • Loading branch information
grtjn committed Jul 19, 2016
2 parents 7f625f8 + 4e1ab2a commit 54c1f74
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 29 deletions.
20 changes: 9 additions & 11 deletions deploy/lib/Help.rb
Original file line number Diff line number Diff line change
Expand Up @@ -398,30 +398,28 @@ def self.corb
<<-DOC.strip_heredoc
Usage: ml {env} corb [options]
See: http://marklogic.github.com/corb/index.html
Runs CoRB2 with given command-line options against the selected environment.
CoRB2 options may be specified on the commandline using either -- or -D prefix.
Required options:
--modules=/path/to/modules.xqy # the xquery module to process the data
For example, the OPTIONS-FILE option can be specified as:
--options-file=/path/to/options.properties
-DOPTIONS-FILE=/path/to/options.properties
(Only one of the following is required)
--collection=collection-name # the name of a collection to process
--uris=/path/to/uris-module.xqy # path to a uris module
CoRB2 supports options files natively using the --OPTIONS-FILE parameter.
Corb Options:
--threads=1 # the thread count to use
--root=/ # the root of the modules database
--install=false # whether or not to install (default: false)
See: https://github.com/marklogic/corb2
General options:
-v, [--verbose] # Verbose output
-h, [--help] # Shows this help
DOC
end

def self.mlcp
<<-DOC.strip_heredoc
Usage: ml {env} mlcp [options]
Runs MLCP with given command-line options agains selected environment.
Runs MLCP with given command-line options against selected environment.
MLCP supports options files natively using the -options_file parameter.
The path to the MLCP options file must be an absolute path or a relative
path from the root of the project directory.
Expand Down
Binary file removed deploy/lib/java/corb.jar
Binary file not shown.
Binary file added deploy/lib/java/marklogic-corb-2.3.1.jar
Binary file not shown.
Binary file removed deploy/lib/java/marklogic-xcc-8.0-1.jar
Binary file not shown.
Binary file added deploy/lib/java/marklogic-xcc-8.0.5.jar
Binary file not shown.
75 changes: 57 additions & 18 deletions deploy/lib/server_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1142,38 +1142,77 @@ def corb
password_prompt
encoded_password = url_encode(@ml_password)
connection_string = %Q{xcc://#{@properties['ml.user']}:#{encoded_password}@#{@properties['ml.server']}:#{@properties['ml.xcc-port']}/#{@properties['ml.content-db']}}
collection_name = find_arg(['--collection']) || '""'
xquery_module = find_arg(['--modules'])
uris_module = find_arg(['--uris']) || '""'

options = Hash.new("")
# handle Roxy convention for CoRB properties first
process_module = find_arg(['--modules']) || ''
process_module = process_module.reverse.chomp("/").reverse
if !process_module.blank?
options["PROCESS-MODULE"] = process_module
end

raise HelpException.new("corb", "modules is required") if xquery_module.blank?
raise HelpException.new("corb", "uris or collection is required ") if uris_module == '""' && collection_name == '""'
collection_name = find_arg(['--collection']) || ''
if !collection_name.blank?
options["COLLECTION-NAME"] = collection_name
# when COLLECTION-NAME is specified, assume CoRB 1.0 convention,
# and set URIS-MODULE with an inline module to return the URIs of all docs in the specified collection(s)
options["URIS-MODULE"] = "INLINE-XQUERY|xquery version '1.0-ml'; declare variable \\$URIS as xs:string external; let \\$uris := cts:uris('', ('document'), cts:collection-query(\\$URIS)) return (count(\\$uris), \\$uris)"
end

xquery_module = xquery_module.reverse.chomp("/").reverse
uris_module = uris_module.reverse.chomp("/").reverse
thread_count = find_arg(['--threads']) || "1"
uris_module = find_arg(['--uris']) || ''
uris_module = uris_module.reverse.chomp('/').reverse
if !uris_module.blank?
options["URIS-MODULE"] = uris_module
end

thread_count = find_arg(['--threads'])
thread_count = thread_count.to_i
module_root = find_arg(['--root']) || '"/"'
modules_database = @properties['ml.modules-db']
install = find_arg(['--install']) == "true" || uris_module == '""'
if thread_count > 0
options["THREAD-COUNT"] = thread_count
end

module_root = find_arg(['--root']) || ''
if !module_root.blank?
options["MODULE-ROOT"] = module_root
end

modules_database = @properties['ml.modules-db'] || ''
if !modules_database.blank?
options["MODULES-DATABASE"] = modules_database
end

# collect options with either "--" or "-D" prefix, and normalize options to be UPPER-CASE
optionArgPattern = /^(--|-D)(.*?)="?(.*)"?/
ARGV.each do |arg|
if arg.match(optionArgPattern)
matches = arg.match(optionArgPattern).to_a
options[matches[2].upcase] = matches[3]
end
end

# we have normalized the options, now clear the args
ARGV.clear

# collect options and set as Java system properties switches
systemProperties = options.delete_if{ |key, value| value.blank? }
.map{ |key, value| "-D#{key}=\"#{value}\""}
.join(' ')

# Find the jars
corb_file = find_jar("corb")
xcc_file = find_jar("xcc")
corb_file = find_jar('corb')
xcc_file = find_jar('xcc')

runme = %Q{java -cp #{corb_file}#{path_separator}#{xcc_file} #{systemProperties} com.marklogic.developer.corb.Manager #{connection_string}}
logger.debug runme

if install
if options.fetch("INSTALL", false)
# If we're installing, we need to change directories to the source
# directory, so that the xquery_modules will be visible with the
# same path that will be used to see it in the modules database.
Dir.chdir(@properties['ml.xquery.dir']) do
runme = %Q{java -cp #{corb_file}#{path_separator}#{xcc_file} com.marklogic.developer.corb.Manager #{connection_string} #{collection_name} #{xquery_module} #{thread_count} #{uris_module} #{module_root} #{modules_database} #{install}}
logger.info runme
`#{runme}`
end
else
runme = %Q{java -cp #{corb_file}#{path_separator}#{xcc_file} com.marklogic.developer.corb.Manager #{connection_string} #{collection_name} #{xquery_module} #{thread_count} #{uris_module} #{module_root} #{modules_database} #{install}}
logger.info runme
`#{runme}`
end
end
Expand Down

0 comments on commit 54c1f74

Please sign in to comment.