08-23-2019 02:38 AM
Hello everyone,
I would like my service to execute some specific lines of Java code if the user running the service performs a "commit dry-run", otherwise if the user performs a "commit" I would like him to do other ones, and if he performs a "commit dry-run" followed but a "commit", I want my code to execute other lines of code.
How can these pieces of information be obtained in the Java code?
I am probably wrong (because I'm new with NSO and Java coding) but I was thinking to use the method "confirmedCommitInProgress()" for"Maapi" class:
Socket s = new Socket("localhost", Conf.CONF_PORT);
Maapi maapi = new Maapi(s);
int commitInProgress = maapi.confirmedCommitInProgress();
// other lines here
Even if this is right, I still don't know how to discriminate between "commit" and "commit dry-run".
Thank you in advance for any help
Solved! Go to Solution.
08-23-2019 03:29 AM - edited 08-23-2019 04:52 AM
Hi,
Java APIs can differentiate only between create, update and delete (com.tailf.dp.services.ServiceOperationType). I haven't noticed an option to differentiate between commit and commit dry-run yet (after all the commit dry-run is expected to show you exactly what commit will actually do without doing it so IMO it would be contra productive to allow altering one of the two).
EDIT:
Seems that someone beat me to it.
In your second case where you want to interact with external DB it would be better that you use the Reactive FASTMAP behavior as handling the external allocations during the create is not a good idea (it can introduce long waiting times if external DB is busy for example.). In this case however dry-run will not work completely.
EDIT EDIT:
Perhaps not reactive FASTMAP in traditional sense; you could use a subscriber code/kicker that would call an action which would write the parameter into the external DB once the real commit happens. Subscriber/kicker would wait for the CDB node of the service being created in the CDB.
08-23-2019 03:06 AM
Hi!
Its not possible discern if it is a dry-run or not. And wouldn't that be kind of lying to the user if you send other commands to the device than what the dry-run showed?
08-23-2019 03:14 AM
Hello,
thank you very much for your quick answer.
It's not that I want to execute other configurations or something like that; inside my Java code, I'm performing a REST call to write a parameter to an external database. My problem is that if the user performs a "commit dry-run" and then a "commit", my code writes the parameter twice on the database. I wanted to know how to discern from "commit" and "commit dry-run" to avoid this behaviour and make the REST call only if he performs "commit".
Hope I've clarified the issue. Thank you again.
08-23-2019 03:29 AM - edited 08-23-2019 04:52 AM
Hi,
Java APIs can differentiate only between create, update and delete (com.tailf.dp.services.ServiceOperationType). I haven't noticed an option to differentiate between commit and commit dry-run yet (after all the commit dry-run is expected to show you exactly what commit will actually do without doing it so IMO it would be contra productive to allow altering one of the two).
EDIT:
Seems that someone beat me to it.
In your second case where you want to interact with external DB it would be better that you use the Reactive FASTMAP behavior as handling the external allocations during the create is not a good idea (it can introduce long waiting times if external DB is busy for example.). In this case however dry-run will not work completely.
EDIT EDIT:
Perhaps not reactive FASTMAP in traditional sense; you could use a subscriber code/kicker that would call an action which would write the parameter into the external DB once the real commit happens. Subscriber/kicker would wait for the CDB node of the service being created in the CDB.
08-23-2019 03:52 AM
Ok, understood. Thank you very much for your help!
08-23-2019 04:07 AM - edited 08-23-2019 04:53 AM
Rethinking my first reply I edited it with more information.
08-23-2019 07:31 AM
Thank you very much, but I have no idea how to create it. Could you please indicate me some documentation where I can study and learn something about it?
08-23-2019 08:41 AM
Depending on what you want to do there are a few options. In the majority of the cases you want a new NED in which case you should definitely talk to your Cisco account team.
In some other cases what you want is to interface with something like an IPAM system and then something like an external allocation can work, that is described here: https://github.com/NSO-developer/external-id-allocation
But, if what you need is full CRUD, a NED is usually the way to go.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide