cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1823
Views
0
Helpful
1
Replies

How to get dry-run output in java code

mdfaizan
Cisco Employee
Cisco Employee

I am trying to load merge my XML payload using maapi, and next i need to fetch dry-run output.

 

i tested with setting one key of leaf and tried action call on services but it giving me null and exception.

 

private String[] NSO_USER_GROUPS = new String[] { "admin", "ncsadmin" };

Socket s = new Socket("127.0.0.1", Conf.NCS_PORT);
Maapi maapi = new Maapi(s);
maapi.startUserSession(trans.getUserInfo().getUserName(), InetAddress.getLocalHost(), "maapi", NSO_USER_GROUPS, MaapiUserSessionFlag.PROTO_TCP);
int th = maapi.startTrans(Conf.DB_RUNNING, Conf.MODE_READ_WRITE);
NavuContext context = new NavuContext(maapi, th);
NavuContainer root = new NavuContainer(context);


root.container("http://com/cisco/abc").list("my-list").safeCreate("abc");

ConfXMLParam[] abc = root.container("http://tail-f.com/ns/ncs").container("services").action("commit-dry-run").call();

ConfObject abcd = abc[0].getValue();
System.out.println("********** " + abcd);

 

ncs-java log:

 

********** null
Error: com.tailf.maapi.MaapiException: badstate
com.tailf.maapi.MaapiException: badstate
at com.tailf.maapi.MaapiException.mk(MaapiException.java:61)
at com.tailf.maapi.MaapiException.mk(MaapiException.java:50)
at com.tailf.maapi.Maapi.abortTrans(Maapi.java:1522)

 

 

what is correct way to invoke dry-run action from java.

1 Reply 1

lmanor
Cisco Employee
Cisco Employee
Hello,
 
Been a while since I've used java but I've done this in the past:
 
The commit-dry-run can be called with maapi.requestActionTh() (note that you need to use the method that takes transaction handler, because this action requires transaction context):
 
    ConfXMLParam[] dryRunOutput = maapi.requestActionTh(
            th, new ConfXMLParam[0], "/services/commit-dry-run");
 
You may also want to specify the outformat (xml, cli, native) as an input parameter:
    ConfXMLParam[] dryRunInput = new ConfXMLParam[] {
       new ConfXMLParamValue("ncs", "outformat",
                             new ConfEnumeration(Ncs._outformat_xml))
    };
    ConfXMLParam[] dryRunOutput = maapi.requestActionTh(
            th, dryRunInput, "/services/commit-dry-run”);
 
The Ncs._outformat_xml is the code-name for xml format enum (prepended with _) in the YANG model:
    // tailf-ncs-common.yang
    typedef outformat3 {
      type enumeration {
        enum cli {
          tailf:code-name outformat_cli;
          description
            "NCS CLI curly bracket format.";
        }
        enum xml {
          tailf:code-name outformat_xml;
          description
            "NETCONF XML edit-config format, i.e., the edit-config that
             would be applied locally (at NCS) to get a config
             that is equal to that of the managed device.";
        }
        enum native {
          tailf:code-name outformat_native;
          description
            "The actual data in native format that would be sent to
             the device";
        }
      }
    }
 
See tailf-ncs-services.yang and tailf-ncs-devices.yang (in <nso-distro-install>/src/ncs/yang) for the format of the data output form the action.
 
-Larry