cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
797
Views
0
Helpful
2
Replies

Unable to read elements from NavuLeafList after maapi transaction finishes

rkudumul
Cisco Employee
Cisco Employee

Hi,

Started maapi transaction in read mode and fetched device specific service instances and stored that data in global variable and finished transaction.

Passing this variable to different method argument and trying to read that but am getting exception "com.tailf.navu.NavuException: com.tailf.maapi.MaapiException: /ncs:devices/device{ios0}/service-list: No such transaction"

Sample Code:
private NavuLeafList servicesLeafList = null;
public NavuLeafList method1(String device)
{
NavuLeafList servicesLeafList = null;
try{
int th = maapi.startTrans2(Conf.DB_RUNNING, Conf.MODE_READ, trans.getUserInfo().getUserId());
NavuContext context = new NavuContext(maapi, th);
NavuContainer ncsRoot = new NavuContainer(context).container(Ncs.hash);
servicesLeafList = ncsRoot.container(Ncs._devices_).list(Ncs._device_).elem(device).leafList("service-list");
maapi.finishTrans(th);
}catch(Exception e){}
return servicesLeafList;
}
public void method2(NavuLeafList servicesLeafList)
{
LOGGER.info("Service List::"+servicesLeafList.elements().size()); // Exception throwing
}

ncs-java-vm.log:
com.tailf.navu.NavuException: com.tailf.maapi.MaapiException: /ncs:devices/device{ios0}/service-list: No such transaction
at com.tailf.navu.NavuContextBase.getElem(NavuContextBase.java:872)
at com.tailf.navu.NavuContext.getElem(NavuContext.java:1001)
at com.tailf.navu.NavuLeaf.refresh(NavuLeaf.java:573)
at com.tailf.navu.NavuLeafList.elements(NavuLeafList.java:368)
at com.cisco.casb.rfs.deviceoffboard.DeviceOffBoard.deviceOffboard(DeviceOffBoard.java:61)
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:315)
at com.tailf.dp.DpActionTrans.read(DpActionTrans.java:221)
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)
Caused by: com.tailf.maapi.MaapiException: /ncs:devices/device{ios0}/service-list: No such transaction
at com.tailf.maapi.MaapiException.mk(MaapiException.java:61)
at com.tailf.maapi.Maapi.safeGetElem(Maapi.java:2785)
at com.tailf.maapi.Maapi.safeGetElem(Maapi.java:2823)
at com.tailf.navu.NavuContextBase.getElem(NavuContextBase.java:861)

 

We did temp fix to avoid above exception. Read navuleaflist elements before finishing maapi transaction. 

servicesLeafList = ncsRoot.container(Ncs._devices_).list(Ncs._device_).elem(device).leafList("service-list");
//below line of code added to avoid exception
Collection<ConfValue> confValue = servicesLeafList.elements();
maapi.finishTrans(th);

 

Any guidance is appreciated.

 

Thanks 

Ramathulasi

1 Accepted Solution

Accepted Solutions

Hi,

Thanks for the quick reply.

I have implemented the below option and it is working fine.

  1. Restructure code to do all the work within the read transaction - usually simplest and most robust

View solution in original post

2 Replies 2

snovello
Cisco Employee
Cisco Employee

Hello Ramuthalasi,

what you see there is a feature of transactiions. A transaction gives a consistent snapshot of a DB at one point in time. Closing the transaction signals that you have read all you wanted and are no longer interested. All those Navu objects become unuseable at that point as you have seen.

 

You have 2 options

  1. Restructure code to do all the work within the read transaction - usually simplest and most robust
  2. Copy whatever you need in your own objects and then close the transaction - used in  cases where consistency is not so important, you will program be acting on old information, but that information was consistent at one point in time.

If you are wondering which to take just go for 1, 2 is just there for completeness.

Hi,

Thanks for the quick reply.

I have implemented the below option and it is working fine.

  1. Restructure code to do all the work within the read transaction - usually simplest and most robust