cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
216
Views
0
Helpful
7
Replies
Beginner

NSO - how to see in Java code if the user performed a "commit dry-run"

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

1 ACCEPTED SOLUTION

Accepted Solutions
Beginner

Re: NSO - how to see in Java code if the user performed a "commit dry-run"

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.

 

7 REPLIES 7
Cisco Employee

Re: NSO - how to see in Java code if the user performed a "commit dry-run"

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? 

Beginner

Re: NSO - how to see in Java code if the user performed a "commit dry-run"

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.

Beginner

Re: NSO - how to see in Java code if the user performed a "commit dry-run"

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.

 

Beginner

Re: NSO - how to see in Java code if the user performed a "commit dry-run"

Ok, understood. Thank you very much for your help!

Beginner

Re: NSO - how to see in Java code if the user performed a "commit dry-run"

Rethinking my first reply I edited it with more information.

Beginner

Re: NSO - how to see in Java code if the user performed a "commit dry-run"

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?

Cisco Employee

Re: NSO - how to see in Java code if the user performed a "commit dry-run"

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.