cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
952
Views
5
Helpful
3
Replies

How can I invoke a user defined action inside NSO service in java?

GBiscardi
Level 1
Level 1

Hi all,

in a NSO java service I need to call a user defined action with a number of parameters, in order to manage action outputs inside the service.

Could anyone suggest me an example or a tutorial to do this?

Thanks everyone who could help me.

3 Replies 3

Michael Maddern
Cisco Employee
Cisco Employee

Hi,

It depends how the action is implemented, but it's not usually possible to invoke an action directly from the create method because most actions start their own transaction (but the create method is already running inside a transaction which has acquired the transaction lock). The best way to run actions from your service is to use Nano services (these are explained in detail in the Development guide).

The Development Guide (version 5.5, at least) does not go into enough detail, though.  For example, it does nothing to explain the answers to the following questions:

1) How can the action (aka a "post action") callback function know what service, service instance, component instance and component state called it?

2) How can the action callback function get its input from the service/component/state?

3) How can some component/state of the service be made aware of the action's output?

4) What is the "ncs:result-expr" yang parameter for and how does it work in conjunction with post actions?

u.avsec
Spotlight
Spotlight

Hey,

best you could do is grab a developer guide and search for 'NAVU Action Execution'.

Snippet from there:

NavuContext context = new NavuContext(maapi);
 context.startRunningTrans(Conf.MODE_READ);
 NavuContainer base = new NavuContainer(context);
 NavuContainer ncs = base.container(new Ncs().hash());
 /*
 * Execute ping on all devices with the interface module.
 */
 for (NavuNode node: ncs.container(Ncs._devices_).
 select("device/.*/config/interface/.*")) {
 NavuContainer if = (NavuContainer)node;
 NavuAction ping = if.action(interfaces.i_ping_test_);
 /*
 * Execute action.
 */
 ConfXMLParamResult[] result = ping.call(new ConfXMLParam[] {
 new ConfXMLParamValue(new interfaces().hash(),
 interfaces._ttl,
 new ConfInt64(64))};
 //or we could execute it with XML-String
 result = ping.call("<if:ttl>64</if:ttl>");
 /*
 * Output the result of the action.
 */
 System.out.println("result_ip: "+
 ((ConfXMLParamValue)result[1]).getValue().toString());
 System.out.println("result_ival:" +
 ((ConfXMLParamValue)result[2]).getValue().toString());
 }
 .....
 context.finishClearTrans();

(Poor paste formatting)

Slightly above this snippet in the guide there is a corresponding yang.

 

Also, **bleep**, I am happy I don't have to work with java anymore