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

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

FlavioA
Level 1
Level 1

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

uavsec001
Level 1
Level 1

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.

 

View solution in original post

7 Replies 7

hniska
Cisco Employee
Cisco Employee

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? 

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.

uavsec001
Level 1
Level 1

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.

 

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

Rethinking my first reply I edited it with more information.

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?

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.

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the NSO Developer community: