[go: up one dir, main page]

CN112235311A - OVSDB client code automatic generation method, system, device and medium - Google Patents

OVSDB client code automatic generation method, system, device and medium Download PDF

Info

Publication number
CN112235311A
CN112235311A CN202011127502.2A CN202011127502A CN112235311A CN 112235311 A CN112235311 A CN 112235311A CN 202011127502 A CN202011127502 A CN 202011127502A CN 112235311 A CN112235311 A CN 112235311A
Authority
CN
China
Prior art keywords
code
file
schema file
ovsdb
database
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202011127502.2A
Other languages
Chinese (zh)
Other versions
CN112235311B (en
Inventor
余兆国
沈洋
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Zijinshan Laboratory
Original Assignee
Network Communication and Security Zijinshan Laboratory
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Network Communication and Security Zijinshan Laboratory filed Critical Network Communication and Security Zijinshan Laboratory
Priority to CN202011127502.2A priority Critical patent/CN112235311B/en
Publication of CN112235311A publication Critical patent/CN112235311A/en
Application granted granted Critical
Publication of CN112235311B publication Critical patent/CN112235311B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/22Parsing or analysis of headers
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/34Graphical or visual programming
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/44Encoding

Landscapes

  • Engineering & Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computer Security & Cryptography (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

本发明公开了一种OVSDB客户端代码自动生成方法、系统、设备及介质,方法包括:获取待解析的Schema文件并进行合法性检查;定义解析后的数据格式,将合法的Schema文件中的内容解析到该数据格式中;基于解析后的数据生成数据库Go语言代码,包括:结合模板代码文件生成公共代码;结合模板代码文件生成每个表项的代码;对生成的代码进行格式化。本发明使用预先写好的模板代码文件生成所有代码,通过生成OVSDB各表项增删改查API避免用户直接构造数据库操作代码,使用结构化的表项数据避免非结构化的字符串映射,降低了Go语言项目集成OVSDB的难度,增加了代码可读性和可维护性。

Figure 202011127502

The invention discloses an OVSDB client code automatic generation method, system, equipment and medium. The method includes: acquiring a schema file to be parsed and checking the validity; defining a parsed data format, and converting the content in the valid schema file Parse into the data format; generate database Go language code based on the parsed data, including: generating common code in combination with template code files; generating code for each table item in combination with template code files; formatting the generated code. The present invention uses pre-written template code files to generate all codes, avoids users to directly construct database operation codes by generating OVSDB table item addition, deletion, modification and query API, uses structured table item data to avoid unstructured string mapping, and reduces The difficulty of integrating OVSDB in Go language projects increases code readability and maintainability.

Figure 202011127502

Description

OVSDB client code automatic generation method, system, device and medium
Technical Field
The invention belongs to the field of SDN (software defined network) and databases, and particularly relates to an OVSDB client code automatic generation method, system, equipment and medium.
Background
Protocols in an SDN network may be divided into management plane protocols and control plane protocols by function. The SDN controller is used as a boundary, and the interface can be divided into a south interface and a north interface according to the hierarchy of the programmable interfaces. The OpenFlow protocol is strictly a control-layer southbound interface protocol, and the OVSDB management protocol is a management-layer southbound interface protocol.
The OVSDB Management Protocol (Open vSwitch Database Management Protocol) was originally proposed by VMware corporation, and an Open Virtual Switch Database (OVSDB) responsible for managing an Open-source software switch (OpenvSwitch, OVS) is an SDN Management Protocol for implementing programmable access and configuration Management of a virtual switch. The OVSDB management protocol defines a set of RPC interfaces, and a user can manage the OVSDB in a remote calling mode, and mainly comprises a communication protocol (JSON-RPC) method and supported OVSDB operation. The OVS is a main application of the OVSDB, the data mode of the OVSDB is defined by OVSDB Schema (DB-SCHEMA), the switch supports data interaction with the controller through the OVSDB, the data are stored in the OVSDB database in the form of tables, the tables are OVSDB Schema tables, and when the switch and the controller are both OVSDB clients (communicating with an ovsddb database server through an ovsddb management protocol), rows can be added in the tables, and addition, deletion and modification of the rows can be subscribed.
With the development of SDN and virtualization technologies, virtual switches have gradually replaced some traditional hardware switches by virtue of flexible, elastic, and economical characteristics, and occupy a place in a data center network. The OVSDB also optimizes and strengthens and supplements the function short boards continuously, such as safety, compatibility to a protocol stack, disaster tolerance, escape and the like. The OVSDB is used as a database to define a database table structure and the table item relationship of each member based on the Schema of the JSON format, and the characteristics of supporting RPC interface access and the like can also be widely applied as a general database.
The OVSDB management protocol in the prior art has the following problems:
1. the operation of a large amount of hard codes and high repeatability of the database exists, and the operation is complicated and easy to make mistakes;
2. in the service development stage, the table entry fields of the database are newly and frequently modified, codes needing to be modified can not be found in time, and BUGs are left;
3. the ovsdb-client operation command line needs to construct a database operation by itself, and is troublesome to use and cannot realize the rapid generation of test data.
Currently, OVSDB is integrated within OVS projects using c language to implement its server code and client code.
Disclosure of Invention
The purpose of the invention is as follows: aiming at the problems in the prior art, the invention discloses a method, a system, equipment and a medium for automatically generating OVSDB client codes, which automatically generate the Go language codes of a defined related database by using a database Schema file, wherein the Go language codes comprise client connection, each table item operation API, a table item data structure and related member range definition, thereby reducing the complexity of using OVSDB by Go language users and improving the readability and maintainability of the codes.
The technical scheme is as follows: the invention adopts the following technical scheme: an OVSDB client code automatic generation method is characterized by comprising the following steps:
s1, obtaining a Schema file to be analyzed, and checking the validity of the Schema file, wherein the Schema file defines attributes including the attributes of the database and the attributes of each item in the database;
s2, defining the analyzed data format, and analyzing the content in the legal Schema file into the data format to obtain the analyzed data;
s3, generating a database Go language code based on the analyzed data and a template code file, wherein the template code file comprises a pre-generated code template, and the method comprises the following steps:
s31, traversing the analyzed data, and generating a public code by combining the template code file according to the database attribute;
s32, traversing the analyzed data, and generating an API code of each table entry by combining the template code file according to the attributes of each table entry;
and S33, formatting the public codes and the API codes of each table entry to obtain the final database Go language codes.
Preferably, in step S1, the checking the validity of the Schema file includes the operations of: checking whether the Schema file exists and whether the Schema file is opened and read normally; checking whether the content of the Schema file conforms to Json format grammar; checking whether relevant keywords in the contents of the Schema file conform to RFC7047 specifications; it is checked whether the Schema file can be created as a temporary database file using the ovsdb-tool.
Preferably, if the validity check of the Schema file is passed, deleting the temporary database file; and if the legality check of the Schema file fails, returning specific error information and guiding a developer to position and modify the Schema file.
Preferably, in step S2, the parsed data format is defined according to the RFC7047 specification.
Preferably, in step S2, the Go standard library json deserialization function is called to parse the content in the Schema file into the defined data format.
Preferably, before executing step S31, a storage path directory of the generated code is created, and if the directory already exists, the old file in the directory is cleared.
Preferably, step S33 includes the operations of: formatting the code by using a gofmt tool, wherein line feed, blank space and bracket matching are included; and formatting the code by using a goimport tool, and importing the dependency package.
An OVSDB client code automatic generation system, comprising:
a validity checking module: the method comprises the steps that the method is used for obtaining a Schema file to be analyzed and carrying out validity check on the Schema file, wherein the Schema file defines attributes comprising attributes of a database and attributes of each item in the database;
an analysis module: defining an analyzed data format, and analyzing the content in a legal Schema file into the data format to obtain analyzed data;
a code generation module: generating a database Go language code based on the analyzed data and a template code file, wherein the template code file comprises a pre-generated code template, and the method comprises the following steps:
a common code generation module: traversing the analyzed data, and generating a public code by combining a template code file according to the database attribute;
the table entry code generation module: traversing the analyzed data, and generating an API code of each table entry by combining the template code file according to the attribute of each table entry;
a formatting module: and formatting the public codes and the API codes of each table entry to obtain the final Go language code of the database.
Preferably, the legality checking module for legality checking the Schema file includes: whether the Schema file is normally opened and read, whether the Schema file content conforms to Json format syntax, whether related keywords in the Schema file content conform to RFC7047 specifications and whether the Schema file can be created into a temporary database file by using an ovsdb-tool.
Preferably, if the Schema file passes the validity check, the validity check module deletes the temporary database file; and if the Schema file fails to pass the validity check, the validity check module returns specific error information and guides a developer to position and modify the Schema file.
Preferably, the parsing module defines the parsed data format according to RFC7047 specifications.
Preferably, the parsing module calls a Go standard library json deserialization function to parse the content in the Schema file into the defined data format.
Preferably, the code generation module further comprises a directory creation module for creating a storage path directory of the generated code and clearing an old file under the directory if the directory already exists.
Preferably, the formatting module performs operations comprising: formatting the code by using a gofmt tool, wherein line feed, blank space and bracket matching are included; and formatting the code by using a goimport tool, and importing the dependency package.
An OVSDB client code automatic generation device comprises a processor, a memory and a computer program which is stored on the memory and can run on the processor, and is characterized in that the processor realizes any one of the OVSDB client code automatic generation methods when executing the program.
A computer-readable storage medium having stored thereon a computer program, wherein the program, when executed by a processor, implements any of the above OVSDB client code automatic generation methods.
Has the advantages that: the invention has the following beneficial effects:
according to the invention, the Go Json analysis packet deserialization OVSDB Schema file is used for extracting detailed information of a key database, database table entries, table entry fields and the like, classifying the OVSDB database, generating all codes by using a pre-written template code file, increasing and deleting the search API by generating each table entry of the OVSDB to avoid a user from directly constructing database operation codes, and using the structured table entry data to avoid unstructured character string mapping, so that the difficulty of integrating the OVSDB with the Go language item is reduced, and the code readability and maintainability are increased.
Drawings
FIG. 1 is a flow chart of the automatic generation of code of the present invention;
FIG. 2 is a flow of validity checking for Schema files in the present invention;
FIG. 3 is a data format after Json parsing in the present invention;
FIG. 4 is a supported API list of various table entries in the present invention.
Detailed Description
The present invention will be further described with reference to the accompanying drawings.
The invention discloses an OVSDB client code automatic generation method, which uses a Go Json analysis packet deserialization OVSDB Schema file to extract detailed information of a key database, database table items, table item fields and the like, classifies the OVSDB database, and generates all codes by using a pre-written template code file, wherein the code generation process is shown as figure 1 and comprises the following steps:
step S1, checking the validity of Schema file
The method comprises the steps of firstly obtaining an OVSDB Schema file to be analyzed, wherein the Schema file is a set of database objects, the table item structure, the attribute and the relation among all table items in a database are defined according to service requirements, the content comprises a database name, a database version number, a table item name and information of all table items, and the information of all table items comprises the maximum line number, the data type, the persistence attribute, the maximum and minimum value, the length range, the value range and the like of fields in the table items.
Then, as shown in fig. 2, the method performs validity check on the Schema file, and includes the following steps:
step S11, checking whether the Schema file exists and whether the Schema file is opened and read normally;
step S12, after the check of step S11 is passed, checking whether the content of the Schema file conforms to Json format grammar;
after the check of the step S13 and the step S12 are passed, whether the related keywords in the content of the Schema file conform to the RFC7047 specification is checked;
step S14, after the check of step S13 is passed, checking whether the Schema file can be created as a temporary database file by using an ovsdb-tool;
and step S15 and step S14, the validity check of the Schema file is finished, the temporary database file is deleted, and the subsequent flow is entered.
In steps S11 to S14, if any step fails, i.e., the check fails, then specific error information is returned and the developer is guided to locate and modify the Schema file.
After the Schema file is modified, the code is regenerated, and the modification of the related code can be checked by a compiler or even an editor.
Step S2, Json analysis
And step S21, defining the data format after Json analysis according to the RFC7047 specification.
In an embodiment of the present invention, as shown in fig. 3, the parsed data is stored in the structure database schema for further processing.
And step S22, calling a Go standard library json deserialization method Unmarshal to analyze the Schema file content into a database Schema structure body to obtain analyzed data.
The structure database schema includes: database name, database version number and each table entry substructure TableSchema; each table entry substructure, TableSchema, includes: the index of the specific table entry, the maximum line number, whether the attribute of the root table entry is present or not and the substructures of the fields are ColumnSchema; each field substructure, ColumnSchema, includes: the data type of the specific field and the field persistence attribute, and the data type of the specific field may be interger, string, uuid, and the like.
Extracting a key value pair from the Schema file, wherein the key is the name of a field type in the Schema file, the value is the value of a specific field type extracted from the Schema file, processing the conversion from an unstructured key value pair (mapping) to a structure (struct) by using a reflection mechanism provided by a go language, and the specific method is that a structure generated by definition is used for obtaining the type of a structure member of the structure through reflection, and traversing the structure member to obtain a corresponding value from the unstructured key value pair according to the type of the structure member and writing the corresponding value into a structure variable.
The table entry according to the RFC specification sometimes cannot completely satisfy the service requirement, so the attribute of the table entry needs to be expanded. For example: adding default value attributes to some fields in the table entry, obtaining the default values in the analysis process and generating corresponding constants, and directly writing the constants into the table entry in the subsequent codes; the expanding method is that a json map label is added in the specific field attribute of the entry in the Schema file to describe the default value attribute, for example, 1000 is added in the max _ number field attribute, and the default value of the maximum value in the entry is 1000.
For each table entry in the database, distinguishing the table entry into three types, namely Global table entry, Root entry and non-Root table entry, according to the attribute of the table entry, wherein:
global table entry: the maximum line number is 1, one table line is in the whole state, and an index is not required to be defined and is used for storing system or service global information;
root table entry: the root attribute is true, an index needs to be defined, other table entries can be referred, and most APIs are supported;
non-Root table entry: must be referenced by at least one other entry and does not support a separate create-delete operation.
The APIs that are respectively and specifically supportable by Global, Root and non-Root entries are shown in fig. 3.
Step S3, code generation
Generating a database Go language code based on the analyzed data and a template code file, wherein the template code file comprises a pre-generated code template, and the method comprises the following steps:
step S31 is to create a storage path directory for the generated code, and if the directory already exists, the old file is emptied.
Step S32, generating related public codes by combining the template code file according to the database attributes and storing the related public codes into a single go file, wherein the steps comprise: defining database names and table entry names; the database client is connected with an initialization function; common constants and functions; initializing a database default value map; OVSDB Transact operates common functions, etc.
The public code comprises a public function and a non-public function, wherein the name of the public function is unchanged, and the public function can be directly generated by copying a template code file; the name of the non-public function changes according to the content of the Schema file, and the non-public function can be generated by modifying part of the content in the template code file, for example, modifying part of character strings and numerical values.
Step S33, traversing all the entries, generating an API code for each entry by combining the template code file according to the maximum number of lines and whether the entry attribute is root, where the API code provides a general function set, and developing the corresponding entry by calling the API code, including: a table entry data structure; defining table entry fields; table entry index data structures (there may be multiple sets); the definition of the maximum and minimum value range of the int type field; enumerating type acquirable value definitions; adding, deleting, modifying, checking, traversing and clearing an API function; appropriate annotations are generated for the derivable variables or functions.
And storing the API codes of the table entries into the source files of the respective table entries, namely table _ table.
For different types of entries, different API code templates exist in the template code file, and the API codes of corresponding entries can be generated by replacing corresponding character strings in the template codes according to attributes such as the names of the parsed entries, the types of the fields and the like.
Step S34, formatting the code, including the operations of:
formatting all generated codes by using a gofmt tool to enable the codes to have a uniform format (including line feed, blank space, bracket matching and the like);
and (5) importing the dependency package by using a goimport tool, and formatting the codes again to obtain the final Go language codes of the database.
In the codes generated by the method, the OVSDB allows the table entry to define a plurality of combined indexes, and does not limit the modification of the index field, and the value of the index field is specified when the table entry is added in actual use and is not modified subsequently; all non-global entries specify at least one index.
For fields of an array type, members within the table entry structure are optimized to be of a base type when no maximum minimum value is specified or a maximum value of 1 is specified, while preserving their update operations.
With respect to floating point numbers, OVSDB json definable primitive data types include "real", all data types are converted to float64 type at the time of json resolution, which needs to be converted to int type.
The data select operations conditions support further operators "<", "<" = "," =, "> =", and ">", and the state also supports operations such as "+ =", "- =", "/=", or "% =" for numbers, which do not have a currently common API, and can be implemented using a packaged muterows function.
The following is illustrated by means of specific examples:
1. firstly, a database Schema file is required to be stored as a file name of ovsdb.
{
"name": "OVS_DB",
"tables": {
"Table_A": {
"columns": {
"name": {"type": "string"},
"num_id_1": {"type": "integer"},
"enable": {"type": "boolean"},
"reftable": {
"type": {"key": {"type": "uuid", "refTable": "Table_B"},
"min": 0, "max": "unlimited"}},
"set": {
"type": {"key": {"type": "string", "enum": ["set",
["physical_port", "lag", "vlan", "bridge_domain", "sub_port"]],
"default": "physical_port"}, "min": 1, "max": 128}},
"number": {
"type": {"key": {"type": "integer", "minInteger": 0, "maxInteger": 4294967295, "default": 1000}, "min": 0, "max": 1}},
"map": {
"type": {"key": "string", "value": "string",
"min": 0, "max": "unlimited"}}},
"indexes": [["name"], ["name", "num_id_1"]],
"isRoot": true},
"Table_B": {
"columns": {
"name": {"type": "string"},
"enable": {
"type": {"key": {"type": "boolean", "default": true}, "min": 0, "max": 1}}},
"indexes": [["name"]],
"isRoot": false},
"Table_Global": {
"columns": {
"name": {"type": "string"},
"set": {
"type": {"key": {"type": "string"}, "min": 1, "max": 128}},
"map": {
"type": {"key": "string", "value": "string",
"min": 0, "max": "unlimited"}}},
"maxRows": 1,
"isRoot": true}
},
"version": "1.0.0"
}
2. The code automatic generation method is executed: checking the legality of the Schema file, performing Json analysis on the content of the Schema file, generating a Go language code of a database by combining a template code file, and formatting the Go language code:
go run odbgen.go -f ovsdb.ovsschema
3. the generated Go code is checked under the project lib/odbapi/ovsdb catalog.
An example of service development using the generated Go code in the project is as follows:
initializing database client connection:
ovsdb.InitOvsdb(addrStr)
creating a table item:
tableA := ovsdb.TableTableA{
Name: “A1”,
NumID1: “8”,
Enable: true,
Number:11111,
}
tableAUUID, err := ovsdb.TableAAdd(tableA)
setting a table entry field:
ovsdb.TableASetField(indexA, ovsdb.TableAFieldSet, “A100”)
ovsdb.TableASetField(indexA,ovsdb.TableAFieldNumber, 33333)
acquiring a table entry:
indexA := ovsdb.TableAIndex{
Name: “A1”,
}
tableA, err := ovsdb.TableAGetByIndex(indexA)
traversing the database:
func printA(tableA TableA){
fmt.printf(“A: %v\n”, tableA)
}
ovsdb.TableAIterator(printA)
deleting the emptying data:
ovsdb.TableADelByIndex(indexA)
ovsdb.TableAClear()
the invention discloses an OVSDB client code automatic generation system, which comprises:
a validity checking module: the method comprises the steps that the method is used for obtaining a Schema file to be analyzed and carrying out validity check on the Schema file, wherein the Schema file defines attributes comprising attributes of a database and attributes of each item in the database;
an analysis module: defining an analyzed data format according to RFC7047 specifications, and analyzing the contents in a legal Schema file into the data format to obtain analyzed data;
a code generation module: generating a database Go language code based on the analyzed data and a template code file, wherein the template code file comprises a pre-generated code template, and the method comprises the following steps:
the directory creating module is used for creating a storage path directory for generating codes, and clearing the old files in the directory if the directory exists;
a common code generation module: traversing the analyzed data, and generating a public code by combining a template code file according to the database attribute;
the table entry code generation module: traversing the analyzed data, generating an API code of each table entry by combining the template code file according to the attribute of each table entry, and storing the API code of each table entry as a go source file independent of the table entry;
a formatting module: and formatting the public codes and the API codes of each table entry to obtain the final Go language code of the database.
The legality checking module is used for carrying out legality checking on the Schema file and comprises the following steps: whether the Schema file is normally opened and read, whether the Schema file content conforms to Json format syntax, whether related keywords in the Schema file content conform to RFC7047 specifications and whether the Schema file can be created into a temporary database file by using an ovsdb-tool. If the Schema file passes the validity check, the validity check module deletes the temporary database file; and if the Schema file fails to pass the validity check, the validity check module returns specific error information and guides a developer to position and modify the Schema file.
The analysis module defines the analyzed data format according to the RFC7047 specification, and calls a Go standard library json deserialization function to analyze the content in the Schema file to the data format.
The formatting module performs operations comprising: the gofmt tool formats the codes, including line feed, space and bracket matching; and formatting the code by using a goimport tool, and importing the dependency package.
The invention discloses an OVSDB client code automatic generation device, which comprises a processor, a memory and a computer program which is stored on the memory and can run on the processor, wherein the processor realizes the OVSDB client code automatic generation method when executing the program.
The invention discloses a computer readable storage medium, which stores a computer program, and the program realizes the OVSDB client code automatic generation method when being executed by a processor.
The above description is only of the preferred embodiments of the present invention, and it should be noted that: it will be apparent to those skilled in the art that various modifications and adaptations can be made without departing from the principles of the invention and these are intended to be within the scope of the invention.

Claims (16)

1.一种OVSDB客户端代码自动生成方法,其特征在于,包括如下步骤:1. an OVSDB client code automatic generation method, is characterized in that, comprises the steps: S1、获取待解析的Schema文件,并对Schema文件进行合法性检查,Schema文件中定义了包括数据库的属性和数据库中各表项的属性;S1. Obtain the schema file to be parsed, and check the validity of the schema file. The schema file defines attributes including database attributes and attributes of each table item in the database; S2、定义解析后的数据格式,将合法的Schema文件中的内容解析到该数据格式中,得到解析后的数据;S2. Define the parsed data format, parse the content in the legal Schema file into the data format, and obtain the parsed data; S3、基于解析后的数据和模板代码文件生成数据库Go语言代码,其中模板代码文件中包括预先生成的代码模板,包括步骤:S3. Generate database Go language code based on the parsed data and template code file, wherein the template code file includes a pre-generated code template, including steps: S31、遍历解析后的数据,根据数据库属性,结合模板代码文件生成公共代码;S31, traverse the parsed data, and generate public code according to the database attribute and in combination with the template code file; S32、遍历解析后的数据,根据各表项属性,结合模板代码文件生成每个表项的API代码;S32, traverse the parsed data, and generate the API code of each table item according to the attributes of each table item and combined with the template code file; S33、对公共代码和每个表项的API代码进行格式化,得到最终的数据库Go语言代码。S33. Format the common code and the API code of each table item to obtain the final database Go language code. 2.根据权利要求1所述的一种OVSDB客户端代码自动生成方法,其特征在于,步骤S1中,对Schema文件进行合法性检查包括操作:检查Schema文件是否存在以及打开和读取是否正常;检查Schema文件内容是否符合Json格式语法;检查Schema文件内容中的相关关键字是否符合RFC7047规范;检查是否能够使用ovsdb-tool工具将Schema文件创建为临时数据库文件。2. a kind of OVSDB client code automatic generation method according to claim 1, is characterized in that, in step S1, Schema file is carried out legitimacy check and comprises operation: check whether Schema file exists and whether opening and reading are normal; Check whether the content of the schema file conforms to the Json format syntax; check whether the relevant keywords in the content of the schema file conform to the RFC7047 specification; check whether the ovsdb-tool tool can be used to create the schema file as a temporary database file. 3.根据权利要求2所述的一种OVSDB客户端代码自动生成方法,其特征在于,若Schema文件进行合法性检查通过,删除临时数据库文件;若Schema文件进行合法性检查未通过,返回具体错误信息并指导开发人员定位修改Schema文件。3. a kind of OVSDB client code automatic generation method according to claim 2, is characterized in that, if Schema file carries out legality check and passes, delete temporary database file; If Schema file carries out legality check and fails, return concrete error information and guide developers to locate and modify Schema files. 4.根据权利要求1所述的一种OVSDB客户端代码自动生成方法,其特征在于,步骤S2中,根据RFC7047规范定义解析后的数据格式。4. The method for automatically generating an OVSDB client code according to claim 1, wherein in step S2, the parsed data format is defined according to the RFC7047 specification. 5.根据权利要求1所述的一种OVSDB客户端代码自动生成方法,其特征在于,步骤S2中,调用Go标准库json反序列化函数将Schema文件中的内容解析到定义的数据格式中。5. A kind of OVSDB client code automatic generation method according to claim 1, is characterized in that, in step S2, call Go standard library json deserialization function to parse the content in Schema file into the defined data format. 6.根据权利要求1所述的一种OVSDB客户端代码自动生成方法,其特征在于,执行步骤S31前,创建生成代码的存放路径目录,若该目录已存在则清空该目录下的旧文件。6. A kind of OVSDB client code automatic generation method according to claim 1, it is characterized in that, before executing step S31, create the storage path directory of the generated code, if this directory already exists, then clear the old files under this directory. 7.根据权利要求1所述的一种OVSDB客户端代码自动生成方法,其特征在于,步骤S33包括操作:使用gofmt工具对代码进行格式化,包括换行、空格、括号匹配;使用goimport工具对代码进行格式化,导入依赖包。7. a kind of OVSDB client code automatic generation method according to claim 1, is characterized in that, step S33 comprises operation: use gofmt tool to format code, comprise line break, space, bracket matching; Use goimport tool to code Format and import dependent packages. 8.一种OVSDB客户端代码自动生成系统,其特征在于,包括:8. an OVSDB client code automatic generation system, is characterized in that, comprises: 合法性检查模块:用于获取待解析的Schema文件,并对Schema文件进行合法性检查,Schema文件中定义了包括数据库的属性和数据库中各表项的属性;Validity check module: used to obtain the schema file to be parsed, and check the validity of the schema file. The schema file defines attributes including the database attributes and the attributes of each table item in the database; 解析模块:定义解析后的数据格式,将合法的Schema文件中的内容解析到该数据格式中,得到解析后的数据;Parsing module: Define the parsed data format, parse the content of the legal Schema file into the data format, and obtain the parsed data; 代码生成模块:基于解析后的数据和模板代码文件生成数据库Go语言代码,其中模板代码文件中包括预先生成的代码模板,包括:Code generation module: Generate database Go language code based on the parsed data and template code files, where the template code files include pre-generated code templates, including: 公共代码生成模块:遍历解析后的数据,根据数据库属性,结合模板代码文件生成公共代码;Public code generation module: traverse the parsed data, generate public code according to the database attributes, combined with the template code file; 表项代码生成模块:遍历解析后的数据,根据各表项属性,结合模板代码文件生成每个表项的API代码;Table item code generation module: traverse the parsed data, generate the API code of each table item according to the properties of each table item, combined with the template code file; 格式化模块:对公共代码和每个表项的API代码进行格式化,得到最终的数据库Go语言代码。Formatting module: Format the common code and the API code of each table item to get the final database Go language code. 9.根据权利要求8所述的一种OVSDB客户端代码自动生成系统,其特征在于,合法性检查模块对Schema文件进行合法性检查包括:Schema文件的打开和读取是否正常、Schema文件内容是否符合Json格式语法、Schema文件内容中的相关关键字是否符合RFC7047规范、是否能够使用ovsdb-tool工具将Schema文件创建为临时数据库文件。9. a kind of OVSDB client code automatic generation system according to claim 8, is characterized in that, legitimacy checking module to Schema file includes: whether opening and reading of Schema file are normal, whether the content of Schema file is normal or not. Comply with the Json format syntax, whether the relevant keywords in the content of the schema file conform to the RFC7047 specification, and whether the ovsdb-tool tool can be used to create the schema file as a temporary database file. 10.根据权利要求9所述的一种OVSDB客户端代码自动生成系统,其特征在于,若Schema文件进行合法性检查通过,合法性检查模块删除临时数据库文件;若Schema文件进行合法性检查未通过,合法性检查模块返回具体错误信息并指导开发人员定位修改Schema文件。10. a kind of OVSDB client code automatic generation system according to claim 9, is characterized in that, if Schema file carries out legality check and passes, and legality check module deletes temporary database file; If Schema file carries out legality check and fails to pass , the validity check module returns specific error information and guides developers to locate and modify the Schema file. 11.根据权利要求8所述的一种OVSDB客户端代码自动生成系统,其特征在于,解析模块根据RFC7047规范定义解析后的数据格式。11. The OVSDB client code automatic generation system according to claim 8, wherein the parsing module defines the parsed data format according to the RFC7047 specification. 12.根据权利要求8所述的一种OVSDB客户端代码自动生成系统,其特征在于,解析模块调用Go标准库json反序列化函数将Schema文件中的内容解析到定义的数据格式中。12. An OVSDB client code automatic generation system according to claim 8, wherein the parsing module calls the Go standard library json deserialization function to parse the content in the Schema file into a defined data format. 13.根据权利要求8所述的一种OVSDB客户端代码自动生成系统,其特征在于,代码生成模块还包括目录创建模块,创建生成代码的存放路径目录,若该目录已存在则清空该目录下的旧文件。13. a kind of OVSDB client code automatic generation system according to claim 8, is characterized in that, code generation module also comprises catalogue creation module, creates the storage path catalogue of generation code, if this catalogue already exists, then clear under this catalogue of old documents. 14.根据权利要求8所述的一种OVSDB客户端代码自动生成系统,其特征在于,格式化模块执行包括以下操作:使用gofmt工具对代码进行格式化,包括换行、空格、括号匹配;使用goimport工具对代码进行格式化,导入依赖包。14. a kind of OVSDB client code automatic generation system according to claim 8, it is characterised in that the format module execution comprises the following operations: use gofmt tool to format code, including line feed, space, bracket matching; use goimport The tool formats the code and imports the dependencies. 15.一种OVSDB客户端代码自动生成设备,包括处理器、存储器及存储在存储器上并可在处理器上运行的计算机程序,其特征在于,所述处理器执行所述程序时实现权利要求1~7中任意一项所述OVSDB客户端代码自动生成方法。15. A device for automatically generating OVSDB client code, comprising a processor, a memory and a computer program stored in the memory and running on the processor, wherein the processor implements claim 1 when executing the program The OVSDB client code automatic generation method described in any one of ~7. 16.一种计算机可读存储介质,其上存储有计算机程序,其特征在于,该程序被处理器执行时实现权利要求1~7中任意一项所述OVSDB客户端代码自动生成方法。16 . A computer-readable storage medium on which a computer program is stored, characterized in that, when the program is executed by a processor, the method for automatically generating OVSDB client code according to any one of claims 1 to 7 is implemented.
CN202011127502.2A 2020-10-20 2020-10-20 OVSDB client code automatic generation method, system, device and medium Active CN112235311B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011127502.2A CN112235311B (en) 2020-10-20 2020-10-20 OVSDB client code automatic generation method, system, device and medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011127502.2A CN112235311B (en) 2020-10-20 2020-10-20 OVSDB client code automatic generation method, system, device and medium

Publications (2)

Publication Number Publication Date
CN112235311A true CN112235311A (en) 2021-01-15
CN112235311B CN112235311B (en) 2022-08-05

Family

ID=74117533

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011127502.2A Active CN112235311B (en) 2020-10-20 2020-10-20 OVSDB client code automatic generation method, system, device and medium

Country Status (1)

Country Link
CN (1) CN112235311B (en)

Cited By (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113791769A (en) * 2021-09-23 2021-12-14 上海淇玥信息技术有限公司 Data value taking method and device for complex structure and electronic equipment
CN114201229A (en) * 2021-11-04 2022-03-18 智新控制系统有限公司 LIN configuration code automatic generation method, system and computer readable storage medium
CN114356341A (en) * 2022-01-04 2022-04-15 腾讯科技(成都)有限公司 A data processing method, device, equipment, storage medium and product
CN114995796A (en) * 2022-05-30 2022-09-02 宁波三星医疗电气股份有限公司 A-XDR (advanced data reduction) coding message processing method, storage medium and electronic equipment
CN115129714A (en) * 2022-06-24 2022-09-30 上交所技术有限责任公司 A data table generation method based on intrusive container and code generation technology
CN115495442A (en) * 2022-11-16 2022-12-20 深圳市明源云采购科技有限公司 Database operation file generation method, device, equipment and storage medium
CN116719866A (en) * 2023-05-09 2023-09-08 上海银满仓数字科技有限公司 Multi-format data self-adaptive distribution method and system

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109039701A (en) * 2018-06-25 2018-12-18 烽火通信科技股份有限公司 The method and system of a variety of way to manages of the network equipment based on MIB database
US20190280924A1 (en) * 2018-03-12 2019-09-12 Stellar Cyber, Inc. Configuration management using ovsdb protocol
EP3675423A1 (en) * 2018-12-26 2020-07-01 Juniper Networks, Inc. Cloud network having multiple protocols using virtualization overlays across physical and virtualized workloads

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20190280924A1 (en) * 2018-03-12 2019-09-12 Stellar Cyber, Inc. Configuration management using ovsdb protocol
CN109039701A (en) * 2018-06-25 2018-12-18 烽火通信科技股份有限公司 The method and system of a variety of way to manages of the network equipment based on MIB database
EP3675423A1 (en) * 2018-12-26 2020-07-01 Juniper Networks, Inc. Cloud network having multiple protocols using virtualization overlays across physical and virtualized workloads

Cited By (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113791769A (en) * 2021-09-23 2021-12-14 上海淇玥信息技术有限公司 Data value taking method and device for complex structure and electronic equipment
CN114201229A (en) * 2021-11-04 2022-03-18 智新控制系统有限公司 LIN configuration code automatic generation method, system and computer readable storage medium
CN114201229B (en) * 2021-11-04 2024-04-05 智新控制系统有限公司 LIN configuration code automatic generation method, system and computer readable storage medium
CN114356341A (en) * 2022-01-04 2022-04-15 腾讯科技(成都)有限公司 A data processing method, device, equipment, storage medium and product
CN114995796A (en) * 2022-05-30 2022-09-02 宁波三星医疗电气股份有限公司 A-XDR (advanced data reduction) coding message processing method, storage medium and electronic equipment
CN115129714A (en) * 2022-06-24 2022-09-30 上交所技术有限责任公司 A data table generation method based on intrusive container and code generation technology
CN115129714B (en) * 2022-06-24 2025-06-06 上交所技术有限责任公司 A data table generation method based on intrusive container and code generation technology
CN115495442A (en) * 2022-11-16 2022-12-20 深圳市明源云采购科技有限公司 Database operation file generation method, device, equipment and storage medium
CN115495442B (en) * 2022-11-16 2023-08-04 深圳市明源云采购科技有限公司 Database operation file generation method, device, equipment and storage medium
CN116719866A (en) * 2023-05-09 2023-09-08 上海银满仓数字科技有限公司 Multi-format data self-adaptive distribution method and system
CN116719866B (en) * 2023-05-09 2024-02-13 上海银满仓数字科技有限公司 Multi-format data self-adaptive distribution method and system

Also Published As

Publication number Publication date
CN112235311B (en) 2022-08-05

Similar Documents

Publication Publication Date Title
CN112235311A (en) OVSDB client code automatic generation method, system, device and medium
US12204528B2 (en) Converting database language statements between dialects
CN106934062B (en) Implementation method and system for querying elastic search
US9009195B2 (en) Software framework that facilitates design and implementation of database applications
US8332828B2 (en) System for translating diverse programming languages
US9086931B2 (en) System for translating diverse programming languages
US9965259B2 (en) System for translating diverse programming languages
US8656372B2 (en) System for translating diverse programming languages
CN102375826B (en) Structured query language script analysis method, device and system
US9940392B2 (en) Performing an object relational model query against a database that includes fields defined at runtime
US20040158820A1 (en) System for generating an application framework and components
US20070239762A1 (en) Automated interactive visual mapping utility and method for transformation and storage of XML data
US10083016B1 (en) Procedurally specifying calculated database fields, and populating them
US7143108B1 (en) Apparatus and method for deletion of objects from an object-relational system in a customizable and database independent manner
US20150261507A1 (en) Validating sql queries in a report
US7509335B2 (en) System and method for extensible Java Server Page resource management
US7509248B2 (en) Generic persistence engine
CN114356964A (en) Data lineage construction method, device, storage medium and electronic device
CN114764558B (en) SQL dialect conversion method, device, system and storage medium
US20070277164A1 (en) Searching computer programs that use different semantics
JP2002527814A (en) Component-based source code generator
US10540157B2 (en) Systems to remove object relational mappings from a software project
US7657869B2 (en) Integration of external tools into an existing design environment
CN117632999A (en) SQL-based code conversion method, device, equipment and medium
CN116955314A (en) Unified database maintenance and control methods, devices, equipment and storage media

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
CP03 Change of name, title or address
CP03 Change of name, title or address

Address after: No. 9 Mozhou East Road, Nanjing City, Jiangsu Province, 211111

Patentee after: Zijinshan Laboratory

Country or region after: China

Address before: No. 9 Mozhou East Road, Jiangning Economic Development Zone, Jiangning District, Nanjing City, Jiangsu Province

Patentee before: Purple Mountain Laboratories

Country or region before: China