cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1641
Views
5
Helpful
1
Replies

when we call actions defined in leaf from rest api getting transactions -1 where when we trigger action from cli works fine

mitshett
Cisco Employee
Cisco Employee

 

 

below is method written to perform action in NSO

@ActionCallback(callPoint="SFP-Advanced-ping", callType=ActionCBType.ACTION)
public ConfXMLParam[] ping(DpActionTrans trans, ConfTag name,
ConfObject[] kp, ConfXMLParam[] params)
throws DpCallbackException {
int tid = trans.getTransaction();

try {
String virtualDeviceName = maapi.getElem(tid, "/services/cloud{%x}/device", kp[0]).toString();
maapi.attach(tid, 0, trans.getUserInfo().getUserId());
ConfPath actionPath = new ConfPath("/devices/device{%x}/live- status/ios-stats:exec/ios-stats:ping", virtualDeviceName);
String ip = params[0].getValue().toString();
ConfList args = new ConfList();
args.addElem(new ConfBuf(ip));
ConfXMLParam[] p = new ConfXMLParam[] { new ConfXMLParamValue("ios-stats", "args", args) };
ConfXMLParam[] actionResult = maapi.requestAction(p, actionPath.toString());
String status = actionResult[0].getValue().toString(); LOGGER.debug("PING:\n" + status);
params = new ConfXMLParam[] { new ConfXMLParamValue(SFPAdvanced.prefix, "result", new ConfBuf(status)) };
maapi.detach(tid); 

} catch (IOException e) {
// TODO Auto-generated catch block

} catch (ConfException e) {
// TODO Auto-generated catch block

}catch (Exception e) {
throw new DpCallbackException("ping failed", e);
}
return params; 




}

 

 

 

below is logs when action is triggered from rest api call

 

com.tailf.maapi.MaapiException: No such transaction

        at com.tailf.maapi.MaapiException.mk(MaapiException.java:61)

        at com.tailf.maapi.MaapiException.mk(MaapiException.java:50)

        at com.tailf.maapi.Maapi.attach(Maapi.java:980)

        at com.example.SFPAdvanced.SFPAdvancedRFS.offlineConfigGeneration(SFPAdvancedRFS.java:184)

        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

        at java.lang.reflect.Method.invoke(Method.java:498)

        at com.tailf.dp.annotations.ActionCallbackProxy.action(ActionCallbackProxy.java:125)

        at com.tailf.dp.DpActionTrans.protoCallback(DpActionTrans.java:319)

        at com.tailf.dp.DpActionTrans.read(DpActionTrans.java:223)

        at com.tailf.dp.DpActionTrans.run(DpActionTrans.java:128)

        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)

        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)

        at java.lang.Thread.run(Thread.java:748)

        at com.tailf.dp.DpThread.run(DpThread.java:41)

 ---------
can you please guide me what is the issue
1 Accepted Solution

Accepted Solutions

Jan Lindblad
Cisco Employee
Cisco Employee

I saw you already got a reply about how to start a transaction, so that is good. I will just comment here that when an rpc is invoked, that is not starting a transaction. So when the RESTCONF (or legacy REST) request comes in, it has to start one if it needs a transaction to do what it needs to do.

 

In the CLI, the CLI has already started a transaction on behalf of the user. A read-only transaction in oper mode, and a read-write transaction in config mode. If your action code starts a transaction, that will go outside the CLI transaction, which may or may not be what you want. If you want to update the user's transaction and let the user commit the change as part of his transaction, you could detect that situation with getTransaction, and if there is one, use it.

 

View solution in original post

1 Reply 1

Jan Lindblad
Cisco Employee
Cisco Employee

I saw you already got a reply about how to start a transaction, so that is good. I will just comment here that when an rpc is invoked, that is not starting a transaction. So when the RESTCONF (or legacy REST) request comes in, it has to start one if it needs a transaction to do what it needs to do.

 

In the CLI, the CLI has already started a transaction on behalf of the user. A read-only transaction in oper mode, and a read-write transaction in config mode. If your action code starts a transaction, that will go outside the CLI transaction, which may or may not be what you want. If you want to update the user's transaction and let the user commit the change as part of his transaction, you could detect that situation with getTransaction, and if there is one, use it.