Intro example

I created a "new" example (I named it ”0-intro”) in the JNC example collection folder. The example has been tested with ConfD 5.2.1 as NETCONF server, although any NETCONF server will work. Hence, the example serves as a very good introductory example, especially for ConfD users as ConfD is pre-integrated.  

Besides the porting work, I only found and corrected a small annoying detail in the jnc.py script, it made the last character in a name in the YANG module into a lowercase char if it happened to be in uppercase. Not part of the naming convention for Java AFAIK.

E.g. "leaf-list domainA” became ”leaf-list domaina”  

Short demo:
tailf@ncsvm:~/JNC-master/examples/0-intro$ cd confd; make stop clean all start; cd -; ant clean compile run
/home/tailf/confd-5.2.1/bin/confd --stop || true
connection refused (stop)
rm -rf *.o *.a *.xso *.fxs *.xsd *.log confderr.log.* *.db *.ccl \
host.key host.cert *_proto.h running.invalid global.data _tmp* \
aaa_cdb.* ./confd-cdb ssh-keydir etc localhost.access
rm *.log 2>/dev/null
make: [clean] Error 1 (ignored)
/home/tailf/confd-5.2.1/bin/confdc --java-package com.example.test -c hosts.yang
cp /home/tailf/confd-5.2.1/etc/confd/ietf-inet-types.fxs ietf-inet-types.fxs
/home/tailf/confd-5.2.1/bin/confdc -f /home/tailf/confd-5.2.1/etc/confd/ietf-inet-types.fxs \
--emit-xsd hosts.xsd hosts.fxs
ln -s /home/tailf/confd-5.2.1/etc/confd/ssh ssh-keydir
mkdir -p ./confd-cdb
cp /home/tailf/confd-5.2.1/var/confd/cdb/aaa_init.xml ./confd-cdb
cp hosts.xml ./confd-cdb
Build complete
echo "#!/bin/sh  " > /tmp/action_script.sh 
echo "echo res MYRES" >> /tmp/action_script.sh 
echo "exit 0  " >> /tmp/action_script.sh 
chmod +x /tmp/action_script.sh
/home/tailf/confd-5.2.1/bin/confd --addloadpath /home/tailf/confd-5.2.1/etc/confd -c confd.conf 
/home/tailf/JNC-master/examples/0-intro
Buildfile: /home/tailf/JNC-master/examples/0-intro/build.xml

clean:

generate:
    [mkdir] Created dir: /home/tailf/JNC-master/examples/0-intro/src/gen
    [mkdir] Created dir: /home/tailf/JNC-master/examples/0-intro/src/gen/com
    [mkdir] Created dir: /home/tailf/JNC-master/examples/0-intro/src/gen/com/example
    [mkdir] Created dir: /home/tailf/JNC-master/examples/0-intro/src/gen/com/example/test
    [mkdir] Created dir: /home/tailf/JNC-master/examples/0-intro/src/gen/com/example/test/inet

compile:
    [mkdir] Created dir: /home/tailf/JNC-master/examples/0-intro/build/classes
    [javac] Compiling 65 source files to /home/tailf/JNC-master/examples/0-intro/build/classes
    [javac] Creating empty /home/tailf/JNC-master/examples/0-intro/build/classes/gen/com/example/test/hosts/package-info.class
    [javac] Creating empty /home/tailf/JNC-master/examples/0-intro/build/classes/gen/com/example/test/ietfInetTypes/package-info.class
    [javac] Creating empty /home/tailf/JNC-master/examples/0-intro/build/classes/gen/com/example/test/hosts/hosts/package-info.class
    [javac] Creating empty /home/tailf/JNC-master/examples/0-intro/build/classes/gen/com/example/test/inet/ietfInetTypes/package-info.class
    [javac] Creating empty /home/tailf/JNC-master/examples/0-intro/build/classes/gen/com/example/test/tailfCommon/package-info.class

generate:

compile:
    [javac] Compiling 21 source files to /home/tailf/JNC-master/examples/0-intro/build/classes
    [javac] Creating empty /home/tailf/JNC-master/examples/0-intro/build/classes/gen/com/example/test/inet/ietfInetTypes/package-info.class

run:
     [copy] Copying 1 file to /home/tailf/JNC-master/examples/0-intro
     [java] In MAIN
     [java] TEST 1
     [java] <hosts xmlns="http://acme.com/ns/simple/1.0" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
     [java]   <host>
     [java]     <name>cecilia</name>
     [java]     <enabled>true</enabled>
     [java]     <numberOfServers>5</numberOfServers>
     [java]   </host>
     [java]   <host>
     [java]     <name>ellen</name>
     [java]     <enabled>true</enabled>
     [java]     <numberOfServers>100</numberOfServers>
     [java]   </host>
     [java]   <host>
     [java]     <name>joe</name>
     [java]     <enabled>true</enabled>
     [java]     <numberOfServers>5</numberOfServers>
     [java]   </host>
     [java]   <host>
     [java]     <name>vera</name>
     [java]     <enabled>false</enabled>
     [java]     <numberOfServers>42</numberOfServers>
     [java]     <domainA>455</domainA>
     [java]     <domainB>a</domainB>
     [java]   </host>
     [java] </hosts>
     [java] 
     [java] TEST 2
     [java] Resulting config:
     [java] <hosts xmlns="http://acme.com/ns/simple/1.0" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
     [java]   <host>
     [java]     <name>cecilia</name>
     [java]     <enabled>true</enabled>
     [java]     <numberOfServers>5</numberOfServers>
     [java]   </host>
     [java]   <host>
     [java]     <name>ellen</name>
     [java]     <enabled>true</enabled>
     [java]     <numberOfServers>100</numberOfServers>
     [java]   </host>
     [java]   <host>
     [java]     <name>joe</name>
     [java]     <enabled>true</enabled>
     [java]     <numberOfServers>5</numberOfServers>
     [java]   </host>
     [java]   <host>
     [java]     <name>vera</name>
     [java]     <enabled>false</enabled>
     [java]     <numberOfServers>42</numberOfServers>
     [java]     <domainA>455</domainA>
     [java]     <domainB>a</domainB>
     [java]   </host>
     [java] </hosts>
     [java] 
     [java] TEST 3
     [java] Resulting config:
     [java] <hosts xmlns="http://acme.com/ns/simple/1.0" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
     [java]   <host>
     [java]     <name>cecilia</name>
     [java]     <enabled>true</enabled>
     [java]     <numberOfServers>5</numberOfServers>
     [java]   </host>
     [java]   <host>
     [java]     <name>ellen</name>
     [java]     <enabled>true</enabled>
     [java]     <numberOfServers>100</numberOfServers>
     [java]   </host>
     [java]   <host>
     [java]     <name>joe</name>
     [java]     <enabled>true</enabled>
     [java]     <numberOfServers>5</numberOfServers>
     [java]   </host>
     [java]   <host>
     [java]     <name>vera</name>
     [java]     <enabled>false</enabled>
     [java]     <numberOfServers>42</numberOfServers>
     [java]     <domainA>455</domainA>
     [java]     <domainB>a</domainB>
     [java]   </host>
     [java] </hosts>
     [java] 
     [java] TEST 4
     [java] cecilia
     [java] ellen
     [java] joe
     [java] vera
     [java] TEST 5
     [java] <hosts xmlns="http://acme.com/ns/simple/1.0" xmlns:simple="http://acme.com/ns/simple/1.0">
     [java]   <host nc:operation="delete">
     [java]     <name>Jupiter</name>
     [java]   </host>
     [java]   <host nc:operation="delete">
     [java]     <name>Saturn</name>
     [java]   </host>
     [java] </hosts>
     [java] 
     [java] TEST 6
     [java] <hosts xmlns="http://acme.com/ns/simple/1.0" xmlns:simple="http://acme.com/ns/simple/1.0">
     [java]   <host>
     [java]     <name>Jupiter</name>
     [java]   </host>
     [java]   <host>
     [java]     <name>Saturn</name>
     [java]   </host>
     [java] </hosts>
     [java] 
     [java] TEST 7
     [java] Config With vera  
     [java] <hosts xmlns="http://acme.com/ns/simple/1.0" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
     [java]   <host>
     [java]     <name>cecilia</name>
     [java]     <enabled>true</enabled>
     [java]     <numberOfServers>5</numberOfServers>
     [java]   </host>
     [java]   <host>
     [java]     <name>ellen</name>
     [java]     <enabled>true</enabled>
     [java]     <numberOfServers>100</numberOfServers>
     [java]   </host>
     [java]   <host>
     [java]     <name>joe</name>
     [java]     <enabled>true</enabled>
     [java]     <numberOfServers>5</numberOfServers>
     [java]   </host>
     [java]   <host>
     [java]     <name>vera</name>
     [java]     <enabled>false</enabled>
     [java]     <numberOfServers>42</numberOfServers>
     [java]     <domainA>455</domainA>
     [java]     <domainB>a</domainB>
     [java]   </host>
     [java] </hosts>
     [java] 
     [java] Config Without vera  
     [java] <hosts xmlns="http://acme.com/ns/simple/1.0" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
     [java]   <host>
     [java]     <name>cecilia</name>
     [java]     <enabled>true</enabled>
     [java]     <numberOfServers>5</numberOfServers>
     [java]   </host>
     [java]   <host>
     [java]     <name>ellen</name>
     [java]     <enabled>true</enabled>
     [java]     <numberOfServers>100</numberOfServers>
     [java]   </host>
     [java]   <host>
     [java]     <name>joe</name>
     [java]     <enabled>true</enabled>
     [java]     <numberOfServers>5</numberOfServers>
     [java]   </host>
     [java] </hosts>
     [java] 
     [java] TEST 8
     [java] Config With vera  
     [java] <hosts xmlns="http://acme.com/ns/simple/1.0" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
     [java]   <host>
     [java]     <name>cecilia</name>
     [java]     <enabled>true</enabled>
     [java]     <numberOfServers>5</numberOfServers>
     [java]   </host>
     [java]   <host>
     [java]     <name>ellen</name>
     [java]     <enabled>true</enabled>
     [java]     <numberOfServers>100</numberOfServers>
     [java]   </host>
     [java]   <host>
     [java]     <name>joe</name>
     [java]     <enabled>true</enabled>
     [java]     <numberOfServers>5</numberOfServers>
     [java]   </host>
     [java] </hosts>
     [java] 
     [java] errorCode and opaqueData = rpc-reply error: <rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="12">
     [java]   <rpc-error>
     [java]     <error-type>application</error-type>
     [java]     <error-tag>data-missing</error-tag>
     [java]     <error-severity>error</error-severity>
     [java]     <nc:error-path xmlns:simple="http://acme.com/ns/simple/1.0" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
     [java]     /nc:rpc/nc:edit-config/nc:config/simple:hosts/simple:host[simple:name='vera_noExists']
     [java]   </nc:error-path>
     [java]     <error-info>
     [java]       <bad-element>host</bad-element>
     [java]     </error-info>
     [java]   </rpc-error>
     [java] </rpc-reply>
     [java] 
     [java] 
     [java] TEST 9
     [java] Create vera  
     [java] <hosts xmlns="http://acme.com/ns/simple/1.0" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
     [java]   <host>
     [java]     <name>cecilia</name>
     [java]     <enabled>true</enabled>
     [java]     <numberOfServers>5</numberOfServers>
     [java]   </host>
     [java]   <host>
     [java]     <name>ellen</name>
     [java]     <enabled>true</enabled>
     [java]     <numberOfServers>100</numberOfServers>
     [java]   </host>
     [java]   <host>
     [java]     <name>joe</name>
     [java]     <enabled>true</enabled>
     [java]     <numberOfServers>5</numberOfServers>
     [java]   </host>
     [java] </hosts>
     [java] 
     [java] TEST 10
     [java] Data = <hosts xmlns="http://acme.com/ns/simple/1.0">
     [java]   <sys>
     [java]     <restart>
     [java]       <mode>mymode</mode>
     [java]       <debug/>    </restart>
     [java]   </sys>
     [java] </hosts>
     [java] 
     [java] Reply = <data>
     [java]   <hosts xmlns="http://acme.com/ns/simple/1.0">
     [java]     <sys>
     [java]       <restart>
     [java]         <res>MYRES</res>
     [java]       </restart>
     [java]     </sys>
     [java]   </hosts>
     [java] </data>
     [java] 
     [java] TEST 11
     [java] Create vera space 
     [java] <hosts xmlns="http://acme.com/ns/simple/1.0" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
     [java]   <host>
     [java]     <name>cecilia</name>
     [java]     <enabled>true</enabled>
     [java]     <numberOfServers>5</numberOfServers>
     [java]   </host>
     [java]   <host>
     [java]     <name>ellen</name>
     [java]     <enabled>true</enabled>
     [java]     <numberOfServers>100</numberOfServers>
     [java]   </host>
     [java]   <host>
     [java]     <name>joe</name>
     [java]     <enabled>true</enabled>
     [java]     <numberOfServers>5</numberOfServers>
     [java]   </host>
     [java]   <host>
     [java]     <name>vera</name>
     [java]     <numberOfServers>0</numberOfServers>
     [java]   </host>
     [java] </hosts>
     [java] 
     [java] OK

BUILD SUCCESSFUL
Total time: 9 seconds