02-26-2021 05:08 AM
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.
03-15-2021 01:50 PM
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).
04-22-2022 10:37 AM
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?
04-22-2022 11:29 AM
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
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