Running jarchi in batch mode

Started by vegardv, September 20, 2019, 13:42:59 PM

Previous topic - Next topic

vegardv

I have written some scripts which creates/updates some archimate models from our CMDB. I would like to run these scripts periodically in batch mode. Preferably without any GUI so that in can be run like a cron job.
Is this possible?


Phil Beauvoir

If you value and use Archi please consider making a donation! https://www.archimatetool.com/donate

vegardv

Fantastic!
Next question: Can I supply arguments to the jscript on the command line?

Phil Beauvoir

> Can I supply arguments to the jscript on the command line?

No. It just runs the script.
If you value and use Archi please consider making a donation! https://www.archimatetool.com/donate

Jean-Baptiste Sarrodie

Hi,

Quote from: Phil Beauvoir on September 23, 2019, 07:45:49 AM
> Can I supply arguments to the jscript on the command line?

No. It just runs the script.

A workaround is to have your jArchi script load another script which only sets up some parameters. This script can easily be created by another batch before.

Regards,

JB
If you value and use Archi please consider making a donation! https://www.archimatetool.com/donate

Phil Beauvoir

Quote from: Jean-Baptiste Sarrodie on September 23, 2019, 17:29:02 PM
Hi,

Quote from: Phil Beauvoir on September 23, 2019, 07:45:49 AM
> Can I supply arguments to the jscript on the command line?

No. It just runs the script.

A workaround is to have your jArchi script load another script which only sets up some parameters. This script can easily be created by another batch before.

Regards,

JB

There you see. I knew there were some smart people around here.  ;)
If you value and use Archi please consider making a donation! https://www.archimatetool.com/donate

Jean-Baptiste Sarrodie

September 23, 2019, 18:33:24 PM #6 Last Edit: February 13, 2020, 14:29:23 PM by Jean-Baptiste Sarrodie
Hi,

Quote from: Phil Beauvoir on September 23, 2019, 17:33:35 PM
There you see. I knew there were some smart people around here.  ;)

8)

Even smarter (but not tested): as one can use Java classes inside jArchi, it should be possible (from within jArchi) to access the command line used when starting Archi, so in theory one could read CLI parameters and act accordingly.

Regards,

JB
If you value and use Archi please consider making a donation! https://www.archimatetool.com/donate

vegardv

February 13, 2020, 14:18:08 PM #7 Last Edit: February 13, 2020, 14:36:57 PM by vegardv
Quote from: Phil Beauvoir on September 20, 2019, 13:44:10 PM
Yes, by using the ACLI. See https://github.com/archimatetool/archi/wiki/Archi-Command-Line-Interface

So, I am still playing around with jArchi scripting, attempting
to automate some model generation in batch mode. We also use the
collaboration plugin for versioning. Via the CLI I can clone and
load a model like this:

xvfb-run archi -application com.archimatetool.commandline.app -consoleLog -nosplash \
  --modelrepository.cloneModel my-git-repo-url \
  --modelrepository.identityFile my-ssh-id-file \
  --modelrepository.passFile secret-passphrase-file \
  --modelrepository.loadModel "My model"

 
I have created some jArchi scripts that queries some REST-like
APIs provided by our CMDB-system, and automatically updates the
loaded model.

Combining a script 'tmp.ajs' that will update the model, I can write a
command that will clone the model from a repo, load it, update it via
a jArchi script, and finally save the resulting updated
model. Example:

  xvfb-run archi -application com.archimatetool.commandline.app -consoleLog -nosplash \
  --modelrepository.cloneModel my-git-repo-url \
  --modelrepository.identityFile my-ssh-id-file \
  --modelrepository.passFile secret-passphrase-file \
  --modelrepository.loadModel "My model" \
  --script tmp.ajs \
  --saveModel "updated-model.archimate"

This works fine. I end up with a file which contains the updated
model, but this model is not "connected to" the repo.

When using the collaboration plugin, it seems like the model is
temporarily saved into '.git/temp.archimate'. I wonder if I can simply
save the model directly into '.git/temp.archimate' using a command like
above. Then I can use the GUI to load this file and manually perform
the Commit and Publish operations.

I guess what I would like to see is some CLI options like:
--modelrepository.commit
--modelrepository.push

This would allow me to keep the model automatically updated in a batch
script, but still allowing manual updating via the same repo. Is this
feasible?

I realize that commiting and pushing may result in conflicts which is
not easily handled via the CLI.


Jean-Baptiste Sarrodie

Hi,

Quote from: vegardv on February 13, 2020, 14:18:08 PM
When using the collaboration plugin, it seems like the model is
temporarily saved into '.git/temp.archimate'. I wonder if I can simply
save the model directly into '.git/temp.archimate' using a command like
above. Then I can use the GUI to load this file and manually perform
the Commit and Publish operations.

Short answer: this will work ;-)
Long answer: when commiting through the GUI, Archi opens the temp.archimate file (if it wasn't already opened), delete everything in the (git) working tree, export the content as a set of XML files, then does the commit itself. So if you change this temp.archimate file (whatever way you change it) it will works.

Quote from: vegardv on February 13, 2020, 14:18:08 PM
I guess what I would like to see is some CLI options like:
--modelrepository.commit
--modelrepository.push

That would be good, can you please open a GitHub issue for that on the plugin repo: https://github.com/archimatetool/archi-modelrepository-plugin/issues

Regards,

JB
If you value and use Archi please consider making a donation! https://www.archimatetool.com/donate

vegardv


vegardv

Quote from: vegardv on February 14, 2020, 06:44:23 AM


Issue created: https://github.com/archimatetool/archi-modelrepository-plugin/issues/121

I appreciate that this change requires extensive rewriting. I have commented on the issue, suggesting that maybe it is easier to implement a CLI-option to save the model as a set of XML files, ready to be Git added, commited, and pushed. The git operations can be performed outside of Archi.

Jean-Baptiste Sarrodie

Hi,


Quote from: vegardv on February 19, 2020, 09:55:48 AM
The git operations can be performed outside of Archi.

No, this is not possible: this would most certainly lead to a model which is screwed and won't be usable anymore. This has been explained several time on the forum and GitHub.

Regards,

JB
If you value and use Archi please consider making a donation! https://www.archimatetool.com/donate

AlexL

February 27, 2020, 09:40:39 AM #12 Last Edit: February 27, 2020, 09:42:12 AM by AlexL
Following the topic, is there any convienent way to pass arguments to jArchi script when calling it in a batch or GUI mode ?
Would be good enough to have a way like using argparase for js. For example https://www.npmjs.com/package/argparse

Phil Beauvoir

February 27, 2020, 10:55:15 AM #13 Last Edit: February 27, 2020, 11:20:45 AM by Phil Beauvoir
What arguments are we talking about? Do we mean the ones passed via the ACLI as in the following -myArg "HelloWord"?

Archi -application com.archimatetool.commandline.app -consoleLog -nosplash --script.runScript "MyScript.ajs" -myArg "HelloWord"

If so, these can be accessed from jArchi with the following:

var args = Java.type("org.eclipse.core.runtime.Platform").getApplicationArgs()

This returns an object with the args.
If you value and use Archi please consider making a donation! https://www.archimatetool.com/donate

AlexL

Thanks, that's good enough. But I mean a call more like this:
Archi -application com.archimatetool.commandline.app -consoleLog -nosplash --script.runScript "MyScript.ajs --flag-a -A ValOfA --an-argument argVal positional_argument"

Will examplegiven  work for it?

And one more thing to mention. If script is called from CLI by another script (shell for example) what will be it's working directory ? Same as parent batch?