Closed quantang closed 5 years ago
Hi @quantang
I don't see any issues with your code so I'll try to replicate that pattern.
But I do have some suggestions on how you can condense the logic.
For one, the latest yang-js does not require a function for binding.
You can simply do something like:
const model = Yang.import(schema).bind({
'feature(AMF)': true,
'feature(VLAN)': true
}).eval({
'ietf-network:network': {}
});
It's possible the .access is resolving something unintended? But you don't need to access a specific module in order to set the data. As long as the datapath is in one of the "schema" import dependency chain, it should do what you expect.
BTW, latest yang-js also creates a parent Store
instance attached to the model so you can also check the model.store to see if it got applied there.
Another possibility is that ietf-network
module actually isn't one of the import dependencies of the at-network-topology-v1.yang
?
Before, we used to allow .access() to get to the "store" which was attached to the Model class constructor. But this is no longer the case. Each Yang.import or such are disconnected from each other and there is no longer a Singleton Store where all models live.
Take a look at Store.coffee for how to work with multiple peer modules.
Just realized new Store
isn't well documented. Should make it into .litcoffee at some point...
Here's an example:
const store = new Store('my-awesome-store');
store.add(Yang.import('ietf-network').bind({ }));
store.add(Yang.import('some-other')));
store.set({
// data for any of the schemas you've added
});
Hope this helps.
This pattern allows you to evaluate the same schema against different data without clobbering shared module dependencies.
Hi @saintkepha,
I tried it in some different ways and found something interesting:
const store = new Yang.Store());
store.add(
Yang.import(schema)
// .bind({
// 'feature(AMF)': () => {},
// }),
);
store.set({
'ietf-network:networks': {},
});
console.log('model:', store.in('ietf-network:networks').toJSON());
console.log('store:', store.toJSON());
Any idea?
Here is the error:
2019-02-22 16:01:50+1300: YangService:initialize { Error: issue executing registered function binding during get(): this.binding.call is not a function
at Model.Property.error (/home/quant/Projects_bak/vistamanager/node_modules/yang-js/lib/property.js:435:15)
at Model.Property.get (/home/quant/Projects_bak/vistamanager/node_modules/yang-js/lib/property.js:273:24)
at Model.<anonymous> (/home/quant/Projects_bak/vistamanager/node_modules/yang-js/lib/property.js:479:25)
at Model.Property.toJSON (/home/quant/Projects_bak/vistamanager/node_modules/yang-js/lib/property.js:481:10)
at Store.toJSON (/home/quant/Projects_bak/vistamanager/node_modules/yang-js/lib/store.js:113:22)
at Function.YangService.loadYangSchema (/home/quant/Projects_bak/vistamanager/dist/yang/yangService.js:88:37)
at Function.<anonymous> (/home/quant/Projects_bak/vistamanager/dist/yang/yangService.js:67:30)
at step (/home/quant/Projects_bak/vistamanager/dist/yang/yangService.js:32:23)
at Object.next (/home/quant/Projects_bak/vistamanager/dist/yang/yangService.js:13:53)
at /home/quant/Projects_bak/vistamanager/dist/yang/yangService.js:7:71
at new Promise (<anonymous>)
at __awaiter (/home/quant/Projects_bak/vistamanager/dist/yang/yangService.js:3:12)
at Function.YangService.initialize (/home/quant/Projects_bak/vistamanager/dist/yang/yangService.js:63:16)
at new YangService (/home/quant/Projects_bak/vistamanager/dist/yang/yangService.js:57:25)
at new AmfYangDelegate (/home/quant/Projects_bak/vistamanager/dist/yang/amfYangDelegate.js:44:28)
at new GuestDeviceDelegate (/home/quant/Projects_bak/vistamanager/dist/data/topologyRepo/guestDeviceDelegate.js:49:28)
uri: undefined,
src:
{ name: 'at-network-topology-v1',
kind: 'module',
xpath: '/',
schema:
{ 'yang-version': '1',
namespace: 'urn:atl:params:xml:ns:yang:at-network-topology',
prefix: 'atnt',
import: [Object],
organization: 'Allied Telesis',
description:
'This module define the model for the Allied Telesis network topology.',
revision: [Object],
typedef: [Object],
feature: [Object],
grouping: [Object],
augment: [Object] },
active: true,
changed: true,
readonly: false },
ctx:
TypeError: this.binding.call is not a function
at Model.Property.get (/home/quant/Projects_bak/vistamanager/node_modules/yang-js/lib/property.js:270:33)
at Model.<anonymous> (/home/quant/Projects_bak/vistamanager/node_modules/yang-js/lib/property.js:479:25)
at Model.Property.toJSON (/home/quant/Projects_bak/vistamanager/node_modules/yang-js/lib/property.js:481:10)
at Store.toJSON (/home/quant/Projects_bak/vistamanager/node_modules/yang-js/lib/store.js:113:22)
at Function.YangService.loadYangSchema (/home/quant/Projects_bak/vistamanager/dist/yang/yangService.js:88:37)
at Function.<anonymous> (/home/quant/Projects_bak/vistamanager/dist/yang/yangService.js:67:30)
at step (/home/quant/Projects_bak/vistamanager/dist/yang/yangService.js:32:23)
at Object.next (/home/quant/Projects_bak/vistamanager/dist/yang/yangService.js:13:53)
at /home/quant/Projects_bak/vistamanager/dist/yang/yangService.js:7:71
at new Promise (<anonymous>)
at __awaiter (/home/quant/Projects_bak/vistamanager/dist/yang/yangService.js:3:12)
at Function.YangService.initialize (/home/quant/Projects_bak/vistamanager/dist/yang/yangService.js:63:16)
at new YangService (/home/quant/Projects_bak/vistamanager/dist/yang/yangService.js:57:25)
at new AmfYangDelegate (/home/quant/Projects_bak/vistamanager/dist/yang/amfYangDelegate.js:44:28)
at new GuestDeviceDelegate (/home/quant/Projects_bak/vistamanager/dist/data/topologyRepo/guestDeviceDelegate.js:49:28)
at new MongoTopologyRepository (/home/quant/Projects_bak/vistamanager/dist/data/mongoTopologyRepository.js:384:34) }
Hmm it's an interesting issue since Store simply calls model.toJSON() and attaches key/value to a new empty object. There must be something wrong with how feature elements are treated - it must be trying to get() and using the binding as a getter function. I'll take a closer look shortly.
Best, Peter On Thu, Feb 21, 2019 at 7:08 PM Quan Tang notifications@github.com wrote:
Hi @saintkepha https://github.com/saintkepha,
I tried it in some different ways and found something interesting:
const store = new Yang.Store()); store.add( Yang.import(schema) // .bind({ // 'feature(AMF)': () => {}, // }), ); store.set({ 'ietf-network:networks': {}, }); console.log('model:', store.in('ietf-network:networks').toJSON()); console.log('store:', store.toJSON());
- If the bind() function is skipped, both the console.log will look good (except the feature related data is missing).
- If the bind() function is called, the second console.log will be an error. No matter I pass the feature(AMF) with a function or true value.
Any idea?
Here is the error:
2019-02-22 16:01:50+1300: YangService:initialize { Error: issue executing registered function binding during get(): this.binding.call is not a function at Model.Property.error (/home/quant/Projects_bak/vistamanager/node_modules/yang-js/lib/property.js:435:15) at Model.Property.get (/home/quant/Projects_bak/vistamanager/node_modules/yang-js/lib/property.js:273:24) at Model.
(/home/quant/Projects_bak/vistamanager/node_modules/yang-js/lib/property.js:479:25) at Model.Property.toJSON (/home/quant/Projects_bak/vistamanager/node_modules/yang-js/lib/property.js:481:10) at Store.toJSON (/home/quant/Projects_bak/vistamanager/node_modules/yang-js/lib/store.js:113:22) at Function.YangService.loadYangSchema (/home/quant/Projects_bak/vistamanager/dist/yang/yangService.js:88:37) at Function. (/home/quant/Projects_bak/vistamanager/dist/yang/yangService.js:67:30) at step (/home/quant/Projects_bak/vistamanager/dist/yang/yangService.js:32:23) at Object.next (/home/quant/Projects_bak/vistamanager/dist/yang/yangService.js:13:53) at /home/quant/Projects_bak/vistamanager/dist/yang/yangService.js:7:71 at new Promise ( ) at awaiter (/home/quant/Projects_bak/vistamanager/dist/yang/yangService.js:3:12) at Function.YangService.initialize (/home/quant/Projects_bak/vistamanager/dist/yang/yangService.js:63:16) at new YangService (/home/quant/Projects_bak/vistamanager/dist/yang/yangService.js:57:25) at new AmfYangDelegate (/home/quant/Projects_bak/vistamanager/dist/yang/amfYangDelegate.js:44:28) at new GuestDeviceDelegate (/home/quant/Projects_bak/vistamanager/dist/data/topologyRepo/guestDeviceDelegate.js:49:28) uri: undefined, src: { name: 'at-network-topology-v1', kind: 'module', xpath: '/', schema: { 'yang-version': '1', namespace: 'urn:atl:params:xml:ns:yang:at-network-topology', prefix: 'atnt', import: [Object], organization: 'Allied Telesis', description: 'This module define the model for the Allied Telesis network topology.', revision: [Object], typedef: [Object], feature: [Object], grouping: [Object], augment: [Object] }, active: true, changed: true, readonly: false }, ctx: TypeError: this.binding.call is not a function at Model.Property.get (/home/quant/Projects_bak/vistamanager/node_modules/yang-js/lib/property.js:270:33) at Model. (/home/quant/Projects_bak/vistamanager/node_modules/yang-js/lib/property.js:479:25) at Model.Property.toJSON (/home/quant/Projects_bak/vistamanager/node_modules/yang-js/lib/property.js:481:10) at Store.toJSON (/home/quant/Projects_bak/vistamanager/node_modules/yang-js/lib/store.js:113:22) at Function.YangService.loadYangSchema (/home/quant/Projects_bak/vistamanager/dist/yang/yangService.js:88:37) at Function. awaiter (/home/quant/Projects_bak/vistamanager/dist/yang/yangService.js:3:12) at Function.YangService.initialize (/home/quant/Projects_bak/vistamanager/dist/yang/yangService.js:63:16) at new YangService (/home/quant/Projects_bak/vistamanager/dist/yang/yangService.js:57:25) at new AmfYangDelegate (/home/quant/Projects_bak/vistamanager/dist/yang/amfYangDelegate.js:44:28) at new GuestDeviceDelegate (/home/quant/Projects_bak/vistamanager/dist/data/topologyRepo/guestDeviceDelegate.js:49:28) at new MongoTopologyRepository (/home/quant/Projects_bak/vistamanager/dist/data/mongoTopologyRepository.js:384:34) }(/home/quant/Projects_bak/vistamanager/dist/yang/yangService.js:67:30) at step (/home/quant/Projects_bak/vistamanager/dist/yang/yangService.js:32:23) at Object.next (/home/quant/Projects_bak/vistamanager/dist/yang/yangService.js:13:53) at /home/quant/Projects_bak/vistamanager/dist/yang/yangService.js:7:71 at new Promise ( ) at — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/corenova/yang-js/issues/84#issuecomment-466257331, or mute the thread https://github.com/notifications/unsubscribe-auth/AA6KbGN1PNjrzx3H6YRgyCrZAHVUMf2zks5vP18WgaJpZM4bGjuL .
-- Peter Lee Chief Executive Officer Corenova Technologies, Inc. +1-310-400-6450 linkedin.com/in/peter-k-lee
I believe this issue should be resolved... Please reopen if not the case.
Hello @saintkepha,
I just got back on YANG schema related work and want to update my yang-js library to the latest version. However, I am not sure whether I am using it in the wrong way, as my code cannot work with the latest version.
Could you help me take a look where would be the problem?
Here is what my code looks like before:
My expectation is it will initialize my model with the 'ietf-network:networks' attribute, which is the root of my data. However, when I try to call the get() function, it always returns empty.
Here is my sample data structure:
Any idea? Cheers.