Search code examples
spring-xd

SpringXD: How to make a job definition in seprate lines


I have a job definition that is very long. I wonder if there is a way to separate it into multiple lines for easy reading. I have tried with '\' or '\n' but they all failed on job creation, for example:

    xd:>job create --name myHttpJob --definition "httpJob \n
          job create --name myHttpJob --definition "httpJob \n
                                                ^
           Cannot have an unbalanced number of quotation marks
    xd:>--listeners=disable" --deploy
       Command '--listeners=disable" --deploy' not found (for assistance press TAB)

    xd:>job create --name myHttpJob --definition "httpJob \
         job create --name myHttpJob --definition "httpJob \
                                               ^
          Ran out of input in escape sequence
    xd:>--listeners=disable" --deploy
      Command '--listeners=disable" --deploy' not found (for assistance press TAB)

Solution

  • Hopefully, this still helps someone out there. I don't think you'll be able to separate the command into multiple lines with the current version of the xd-shell but what I do is I externalize the whole process by using a shell script to do the whole process. This is useful if you need to run the same or similar commands several times and your command can be parameterized. Below is a sample of what your shell script will contain (let's call the file myxdshellfile.sh). I have similar scripts for all my custom module upload/deploy/definition and streams as well. If you set it up well, you can parameterize it for deployment into different environments and pass the environment as an input arg.

    echo -n -e " \
    job create --name ${module}_${version} \
    --definition \"${moduleDefinition} \
    --restartable=false \
    --dateFormat=yyyy-MM-dd \
    --makeUnique=true \
    --partitionResultsTimeout=7200000 \
    \
    --jdbcDriver=com.mysql.jdbc.Driver \
    --jdbcUser=${user} \
    --jdbcPassword=${pwd} \
    --jdbcUrl=jdbc:mysql://${dbhost} \
    \
    --version=${version} \
    \
    \"
    " > "$cmdfile"
    
    #write string to file
    echo -e -n .${shellpath}/shell/bin/xd-shell --cmdfile ${cmdfile}
    
    #see what's in the file
    cat ${cmdfile}
    
    #execute spring-xd shell
    bash ${shellpath}/shell/bin/xd-shell --cmdfile ${cmdfile}