Author Topic: Running jarchi in batch mode  (Read 1516 times)

vegardv

  • Newbie
  • *
  • Posts: 9
Running jarchi in batch mode
« on: September 20, 2019, 14:42:59 PM »
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

  • Administrator
  • Hero Member
  • *****
  • Posts: 1639
  • Code Punk
    • Archi
Re: Running jarchi in batch mode
« Reply #1 on: September 20, 2019, 14:44:10 PM »
If you value and use Archi please consider making a donation! https://www.archimatetool.com/donate

vegardv

  • Newbie
  • *
  • Posts: 9
Re: Running jarchi in batch mode
« Reply #2 on: September 23, 2019, 08:45:12 AM »
Fantastic!
Next question: Can I supply arguments to the jscript on the command line?

Phil Beauvoir

  • Administrator
  • Hero Member
  • *****
  • Posts: 1639
  • Code Punk
    • Archi
Re: Running jarchi in batch mode
« Reply #3 on: September 23, 2019, 08:45:49 AM »
> 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

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 729
  • Archi Evangelist and Contributor. Visionary.
    • About me...
Re: Running jarchi in batch mode
« Reply #4 on: September 23, 2019, 18:29:02 PM »
Hi,

> 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

  • Administrator
  • Hero Member
  • *****
  • Posts: 1639
  • Code Punk
    • Archi
Re: Running jarchi in batch mode
« Reply #5 on: September 23, 2019, 18:33:35 PM »
Hi,

> 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

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 729
  • Archi Evangelist and Contributor. Visionary.
    • About me...
Re: Running jarchi in batch mode
« Reply #6 on: September 23, 2019, 19:33:24 PM »
Hi,

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
« Last Edit: February 13, 2020, 14:29:23 PM by Jean-Baptiste Sarrodie »
If you value and use Archi please consider making a donation! https://www.archimatetool.com/donate

vegardv

  • Newbie
  • *
  • Posts: 9
Re: Running jarchi in batch mode
« Reply #7 on: February 13, 2020, 14:18:08 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.

« Last Edit: February 13, 2020, 14:36:57 PM by vegardv »

Jean-Baptiste Sarrodie

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 729
  • Archi Evangelist and Contributor. Visionary.
    • About me...
Re: Running jarchi in batch mode
« Reply #8 on: February 13, 2020, 14:38:23 PM »
Hi,

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.

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

  • Newbie
  • *
  • Posts: 9
Re: Running jarchi in batch mode
« Reply #9 on: February 14, 2020, 06:44:23 AM »

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


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

vegardv

  • Newbie
  • *
  • Posts: 9
Re: Running jarchi in batch mode
« Reply #10 on: February 19, 2020, 09:55:48 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

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 729
  • Archi Evangelist and Contributor. Visionary.
    • About me...
Re: Running jarchi in batch mode
« Reply #11 on: February 19, 2020, 20:33:45 PM »
Hi,


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

  • Member
  • **
  • Posts: 12
Re: Running jarchi in batch mode
« Reply #12 on: February 27, 2020, 09:40:39 AM »
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
« Last Edit: February 27, 2020, 09:42:12 AM by AlexL »

Phil Beauvoir

  • Administrator
  • Hero Member
  • *****
  • Posts: 1639
  • Code Punk
    • Archi
Re: Running jarchi in batch mode
« Reply #13 on: February 27, 2020, 10:55:15 AM »
What arguments are we talking about? Do we mean the ones passed via the ACLI as in the following -myArg "HelloWord"?

Code: [Select]
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:

Code: [Select]
var args = Java.type("org.eclipse.core.runtime.Platform").getApplicationArgs()
This returns an object with the args.
« Last Edit: February 27, 2020, 11:20:45 AM by Phil Beauvoir »
If you value and use Archi please consider making a donation! https://www.archimatetool.com/donate

AlexL

  • Member
  • **
  • Posts: 12
Re: Running jarchi in batch mode
« Reply #14 on: February 27, 2020, 11:05:05 AM »
Thanks, that's good enough. But I mean a call more like this:
Code: [Select]
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?