cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Announcements
662
Views
0
Helpful
2
Replies
mitshett
Cisco Employee

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

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)

1 ACCEPTED SOLUTION

Accepted Solutions
mvolf
Cisco Employee

That's because actions invoked from CLI are associated with existing user session and transaction, for other northbound interfaces there is no such session. You can test the transaction handle provided in the context, if it is -1, you can't attach to it and need to start your session and transaction.

View solution in original post

2 REPLIES 2
mvolf
Cisco Employee

That's because actions invoked from CLI are associated with existing user session and transaction, for other northbound interfaces there is no such session. You can test the transaction handle provided in the context, if it is -1, you can't attach to it and need to start your session and transaction.

View solution in original post

@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;




}


above is the code where DpActionTrans class we are getting transaction id but when this action is triggered from rest api call i see -1 is the transaction id .....Can you please guide me how to start transaction and session ? what are the api to do that