项目作者: maseev

项目描述 :
Java to YANG translator
高级语言: Java
项目地址: git://github.com/maseev/jyang.git
创建时间: 2017-02-10T09:34:36Z
项目社区:https://github.com/maseev/jyang

开源协议:MIT License

下载


JYANG

Build Status
Coverage Status

Java To YANG Translator

JYANG is a Java to YANG Translator.
The main goal of this project is to translate your NETCONF RPCs written in Java to YANG.

How to build

  • Clone this repository
  • Run ./gradlew clean install in the project folder to build the project and install it to the local
    Maven repository

How to use

Add jyang as a dependency:

Maven
  1. <dependency>
  2. <groupId>io.github.maseev</groupId>
  3. <artifactId>jyang</artifactId>
  4. <version>1.0</version>
  5. </dependency>
Gradle
  1. compile group: 'io.github.maseev', name: 'jyang', version: '1.0'

Add a @NetconfEndpoint annotation on your Java class and a @NetconfProcedure annotation on
your Java methods. Notice that you can alter your endpoint and procedure names by specifying the
annotations value fields. Otherwise, class and method names will be used as endpoint and
procedure names accordingly:

  1. public class UserDTO {
  2. private int id;
  3. private String name;
  4. // constructors, getters, setters ...
  5. }
  6. @MapsTo(UserDTO.class)
  7. public class User {
  8. private int id;
  9. private String name;
  10. // constructors, getters, setters ...
  11. }
  12. @NetconfEndpoint("users")
  13. public class UserEndpoint {
  14. @NetconfProcedure("getbyId")
  15. public User getUser(final String id) {
  16. // your implementation goes here ...
  17. }
  18. }

Also, notice that you can alter your incoming parameter types as well as return type by using
@MapsTo annotation.

Use the following code snippet in order to translate a NETCONF endpoint we defined earlier into
a YANG model:

  1. Pair pair = new Translator().translateEndpoint(UserEndpoint.class);
  2. Module module =
  3. new Module("user", "user endpoint YANG model", "namespace", "user",
  4. new Revision(new Date(), "Initial model revision"));
  5. module.getGroupings().addAll(pair.getGroupings());
  6. module.getRpcs().addAll(pair.getRpcs());
  7. try (BufferedWriter writer = new BufferedWriter(new FileWriter("user.yang"))) {
  8. writer.write(TemplateUtil.transform(module, "templates/module.mustache"));
  9. }

Your YANG model will look like very similar to this:

  1. module user {
  2. namespace "namespace";
  3. prefix "user";
  4. revision "2017-03-03" {
  5. description "Initial model revision";
  6. }
  7. typedef char {
  8. type string {
  9. length "1";
  10. }
  11. }
  12. typedef timestamp {
  13. type uint32;
  14. }
  15. typedef double {
  16. type decimal64 {
  17. fraction-digits 8;
  18. }
  19. }
  20. typedef float {
  21. type binary {
  22. length "32";
  23. }
  24. }
  25. grouping UserDTO {
  26. leaf id {
  27. type int32;
  28. }
  29. leaf name {
  30. type string;
  31. }
  32. }
  33. rpc users.getbyId {
  34. input {
  35. leaf String {
  36. type string;
  37. }
  38. }
  39. output {
  40. container UserDTO {
  41. uses UserDTO;
  42. }
  43. }
  44. }
  45. }