Skip to content

ModuleExecutor Tool

Mads Hansen edited this page Jan 2, 2020 · 3 revisions

Sometimes, a two or more staged CoRB job with both a selector and transform isn't necessary to get the job done. Sometimes, only a single query needs to be executed and the output captured to file. Maybe even to execute only a single query with no output captured? In these cases, the ModuleExecutor Tool can be used to quickly and efficiently execute your XQuery or JavaScript files.

Like CoRB, with version 8 (or higher) of the MarkLogic XCC Connection JAR in your classpath, the ModuleExecutor Tool can run JavaScript queries against a MarkLogic 8 (or later) server.

So how does the ModuleExecutor Tool differ from CoRB? The key differences are:

  • There is only one stage in the process so it can only run one query unlike CoRB which is multi staged (init, pre-batch, uri-module, process-module, post-batch)
  • It is a single threaded application

That's it. Doesn't seem like a lot but it actually limits its functionality significantly. So what does the ModuleExecutor Tool have in common with CoRB? Quite a bit:

  • Runs either XQuery or Javascript
  • Supports encryption of passwords using Jasypt
  • Can capture query output to file
  • Can pass custom external variables to the script
  • Supports either ADHOC queries or queries deployed to a modules database
  • Can be configured using:
    • command line program arguments
    • command line -D properties
    • a properties file
    • a combination of any of these

So how do you use it?

For convenience, it can be configured using the same techniques as CoRB provides and using the same parameter names. The big difference is that there are far fewer parameters needed and there is a different class used for its execution (com.marklogic.developer.corb.ModuleExecutor).

The following parameters are supported and can be used in the same ways as described above for CoRB:

  • PROCESS-MODULE
  • PROCESS-MODULE.customVariableNameExample
  • MODULES-DATABASE
  • MODULES-ROOT
  • DECRYPTER
  • XCC-CONNECTION-URI
  • XCC-USERNAME
  • XCC-PASSWORD
  • XCC-HOSTNAME
  • XCC-PORT
  • EXPORT-FILE-DIR
  • EXPORT-FILE-NAME

The following are example usages from a Windows console:

Usage 1
java -cp pathToXCC.jar:pathToCORB.jar com.marklogic.developer.corb.ModuleExecutor  
        xcc://user:password@host:port/[ database ]
        xqueryOrJavascriptModuleName moduleRootName modulesDatabaseName  
        c:\\myPath\\to\\file\\directory\\myFileName
Usage 2
java -cp pathToXCC.jar:pathToCORB.jar
        -DXCC-CONNECTION-URI=xcc://user:password@host:port/[ database ]
        -DPROCESS-MODULE=module-name.xqy
        -DPROCESS-MODULE.collectionName=myCollectionName
        com.marklogic.developer.corb.ModuleExecutor
Usage 3
java -cp pathToXCC.jar:pathToCORB.jar:pathToJasypt.jar
        -DOPTIONS-FILE=myJob.properties
        com.marklogic.developer.corb.ModuleExecutor

Where myJob.properties has:

MODULES-DATABASE=My-Modules
DECRYPTER=com.marklogic.developer.corb.JasyptDecrypter
PROCESS-MODULE=/test/HelloWorld.xqy
PROCESS-MODULE.lastName=Smith
PROCESS-MODULE.collectionName=myCollectionName
EXPORT-FILE-NAME=C:\\Users\\jon.smith\\Documents\\runXQueryOutput.log
XCC-CONNECTION-URI=ENC(fslfuoifsdofjjwfckmeflkjlj377239843u)
Usage 4
java -cp pathToXCC.jar:pathToCORB.jar:pathToJasypt.jar
        -DOPTIONS-FILE=myJob.properties
        com.marklogic.developer.corb.ModuleExecutor ENC(fslfuoifsdofjjwfckmeflkjlj377239843u)