Disclosure of Invention
The invention provides a service-oriented architecture module program generation method and device, which are used for solving the problems that a large amount of repeated handwriting codes are required for SOA architecture module program development and the development period is long in the prior art.
The invention provides a module program generating method facing to a service architecture, which comprises the following steps:
Analyzing a first preset declaration file corresponding to a module program, and acquiring key variables of keywords declared in the first declaration file, wherein the key variables represent unique fields in common program segments of different module programs;
and inserting the key variables into corresponding reserved positions in a pre-designed program template to generate a module program.
According to the method for generating the module program of the service-oriented architecture provided by the invention, the key variables are inserted into corresponding reserved positions in a pre-designed program template to generate the module program, and the method comprises the following steps:
searching placeholders corresponding to the key variables in the program template according to the key words, wherein each reserved position is provided with the placeholder;
replacing the placeholders with the key variables until all placeholders are replaced;
and receiving an instruction for renaming the program template, and generating the module program after renaming.
According to the method for generating the module program of the service-oriented architecture, before analyzing the first preset declaration file corresponding to the module program and acquiring the key variable of the key word declared in the first declaration file, the method further comprises the following steps:
analyzing a pre-configured second plaintext, and acquiring starting configuration information and connection relations corresponding to each module program declared in the second plaintext;
Generating a starting configuration file of a corresponding module program according to the starting configuration information;
Generating a theme file of a corresponding module program according to the connection relation, wherein the theme file comprises a theme key and a theme value of the connection relation, the key variables in the first statement file comprise the theme key and the theme key type,
The starting configuration file is used for being called by a system process to start a module program in the starting configuration file, a reading function used for reading a corresponding theme file when the module program is started is arranged in the program template, and the reading function is used for reading a theme value corresponding to the theme key in the theme file so that the module program can create an instance of a connection relation according to the theme value and the type of the theme key.
According to the method for generating the module program of the service-oriented architecture, the keywords in the first statement file further comprise selectable items of whether the theme value in the connection relation is selectable, a judging function is arranged in the program template, and the judging function is used for judging whether the module program is normally started or not under the condition that the theme value is not read when the module program is started according to the actual value of the key variable of the selectable items, if the actual value of the key variable is true, the program module is normally started, and if the actual value of the key variable is false, the program module cannot be started.
According to the method for generating the module program facing the service architecture, the judging function is further used for starting the error reporting and prompting the theme key corresponding to the default theme value when judging that the module program cannot be started normally because the theme value is not read.
According to the module program generating method of the service-oriented architecture, key variables in the first declaration file further comprise transmission data types of connection relations.
The invention also provides a module program generating device facing to the service architecture, which comprises:
The first declaration file analysis unit is used for analyzing a first declaration file which is pre-configured and corresponds to the module program, and acquiring key variables of keywords declared in the first declaration file, wherein the key variables represent unique fields in common program segments of different module programs;
and the module program generating unit is used for inserting the key variables into corresponding reserved positions in a pre-designed program template so as to generate a module program.
The invention also provides an electronic device, which comprises a memory, a processor and a computer program stored on the memory and capable of running on the processor, wherein the processor realizes the module program generating method of the service-oriented architecture when executing the program.
The present invention also provides a non-transitory computer readable storage medium having stored thereon a computer program which, when executed by a processor, implements a module program generating method of a service oriented architecture as described in any of the above.
The invention also provides a computer program product comprising a computer program which when executed by a processor implements a module program generation method of a service oriented architecture as described in any of the above.
The method and the device for generating the module program facing the service architecture acquire the keywords declared in the first declaration file by analyzing the preconfigured first declaration file corresponding to the module program, the keywords represent the unique fields in the common program segments of different module programs, and the keywords are inserted into the corresponding reserved positions in the predesigned program template to generate the module program. Therefore, a developer only needs to configure the first declaration file when developing the module program, then automatically generates the module program, and only needs to develop a core algorithm part in the module program subsequently, thereby greatly reducing the code quantity of the module program development and shortening the development period.
Detailed Description
For the purpose of making the objects, technical solutions and advantages of the present invention more apparent, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings, and it is apparent that the described embodiments are some embodiments of the present invention, not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
The method for generating the module program of the service-oriented architecture provided by the embodiment of the invention, as shown in fig. 1, comprises the following steps:
Step S110, a first declaration file corresponding to the module program is analyzed, and key variables of keywords declared in the first declaration file are obtained, wherein the key variables represent unique fields in a common program section of different module programs, namely different fields in the common program section. In this embodiment, the first declaration file is designed by adopting a YAML (Yet Another Markup Language) declaration programming manner, specifically, in practical application, the first declaration file is named as base yaml file, the base yaml file provides specific configurable keywords for a developer, the developer configures specific values corresponding to the keywords, namely key variables, and the keywords can be detected from grammar so as to be capable of resolving the key variables from base yaml files. The configurable keywords in the base yaml document include unique fields in the common program segment of the SOA architecture module program, for example, the autopilot system, and the keywords include keywords of timing tasks, diagnostics, metrics, and connection relationship (i.e., io) data segments, etc.
And step S120, inserting the key variables into corresponding reserved positions in a pre-designed program template to generate a module program. The program template is a template of a module program, and common program segments of all module programs in a system (such as an automatic driving system) are arranged in the program template. Taking a C++ program as an example, the program templates comprise 2 C++ program templates, namely a header file program template and a source file program template. And if the key variables corresponding to the key words in the different first declaration files are different, and the different key variables are inserted into the program template, different module programs are generated. It should be noted that the module program generated here is not a module program with complete functions, but only a common program segment in the module program is generated by adopting a mode of YAML declarative configuration programming, so that the code amount of a developer is reduced, and the developer continues to develop on the basis of the generated module program, for example, inherits the module program and realizes the service-related algorithm of the most core of the developer.
According to the module program generating method of the service-oriented architecture, a first declaration file corresponding to a module program is analyzed, a value corresponding to a keyword declared in the first declaration file is obtained, the key variable represents a unique field in a common program section of different module programs, and the value corresponding to the key variable is inserted into a corresponding reserved position in a pre-designed program template to generate the module program. Therefore, a developer only needs to configure the first declaration file when developing the module program, then automatically generates the module program, and only needs to develop a core algorithm part in the module program subsequently, thereby greatly reducing the code quantity of the module program development and shortening the development period.
In this embodiment, step S120 includes:
And searching placeholders corresponding to the key variables in the program template according to the keywords, wherein each reserved position is provided with the placeholders, and specifically, the placeholders can be in the following form of "# # # keywords" # # ", as long as the symbols in the placeholders are not symbols with special meanings in the program language. By setting the placeholder at the reserved position, the position to be replaced by the keyword can be conveniently and rapidly searched according to the keyword.
And replacing the placeholders by the key variables, and replacing the "#" keyword "# #" by the key variables until all the placeholders are replaced.
And receiving an instruction for renaming the program template, renaming to generate the module program, changing the suffix name of the program template of the header file into.h for the C++ program, and changing the suffix name of the program template of the source file into.cc for the program template of the source file.
In this embodiment, before step S110, the method further includes:
Analyzing a second preset plaintext, and acquiring starting configuration information and connection relations corresponding to each module program stated in the second plaintext. Similar to the first declaration file, the second declaration file is designed in a YAML declaration programming manner, specifically, in practical application, the second declaration file may be named as a startup YAML file, and the startup YAML file may be used for a developer to configure startup configuration information when each module program is started, and a connection relationship, where the connection relationship is a publish-subscribe relationship and a client-server relationship in an SOA architecture. The startup yaml file is configured with startup configuration information of all module programs in the whole system and corresponding connection relations, and the startup configuration information comprises basic information such as module program names (or IDs).
And generating a starting configuration file of the corresponding module program according to the starting configuration information, wherein the starting configuration file also comprises the name (or ID) of the module program and basic information required during starting.
Generating a theme file of a corresponding module program according to the connection relation, wherein each module program corresponds to one theme file respectively, the theme file comprises a theme key and a theme value of the connection relation, the key variables comprise the theme key and the theme key type, namely, the key variable of the key word of the connection relation in the first statement file is consistent with the theme key, and the theme key type indicates which connection relation of the module program belongs to a publisher, a subscriber, a client or a server respectively.
The starting configuration file is used for being called by a system process (such as a management process of an automatic driving system) to start a module program in the starting configuration file, specifically, the system process acquires a module program name and a basic information pair required in starting from the starting configuration file, and starts the module program according to the basic information pair. The program template is provided with a reading function for reading the corresponding theme file when the module program is started, and the module program generated after the step S120 also comprises the reading function because the reading function is arranged in the program template, and the reading function is used for reading the theme value corresponding to the theme key in the theme file so that the module program creates an instance of the connection relation according to the theme value and the type of the theme key. Examples of connection relationships include a publish-subscribe relationship instance and a client-server relationship instance.
Because the starting sequence of each module program in one system (such as an automatic driving system) has a certain logic association, the starting configuration information of all the module programs is configured in a starting yaml file, so that the unified configuration of a developer is facilitated. In addition, in one system, the overall topological relation of the publish-subscribe (many-to-many relation) relation is complex, the connection relation is uniformly configured in the second plaintext, and if the publish-subscribe relation or the client-server relation is changed, the code is not required to be manually changed, and only the second plaintext is required to be uniformly modified. For example, to add a subscription relationship, a corresponding topic key value pair (i.e., topic key and topic value) may be added to the start yaml file, and a name relationship data segment may be added to the module base yaml file, and after re-executing steps S110 and S120, the module program may be regenerated.
In this embodiment, the keywords in the first declaration file further include an optional item of whether the theme value in the connection relationship is optional, and the program template is provided with a judging function, where the judging function is configured to judge whether the module program is normally started or not when the module program is started according to the actual value of the key variable of the optional item, if the actual value of the key variable is true, the program module is normally started, and if the actual value of the key variable is false, the program module cannot be started. Specifically, if the actual value of the key variable of the selectable item is True, the key value of the connection relation in the second plaintext is allowed to be opposite to the default theme value, the module program may not create an instance of the connection relation corresponding to the default theme value after being started, and the starting of the module program is not affected, if the actual value of the key variable of the selectable item is False, the default theme value is not allowed, and if the default theme value exists in the theme file, the module program cannot be started. Because the selectable option of whether the theme value in the connection relation is selectable is configured, when one connection relation is wanted to be removed, the theme key value pair can be removed from the starting yaml file, if the actual value of the key variable of the corresponding selectable option in the module base yaml file is True, at this time, the starting yaml file is only needed to be parsed again, that is, the S110 is executed, the module program is not needed to be regenerated, and the maintenance of the module program is facilitated.
Further, the judging function is further used for starting to report errors and prompting the topic key corresponding to the default topic value when judging that the module program cannot be started normally because the module program does not read the topic value, so that when the starting fails, a developer can quickly locate an error point and timely configure the default topic value in the second plaintext.
In this embodiment, the key variables in the first declaration file further include a transmission data type of a connection relationship, and when changing the transmission data type of a publish-subscribe or client-server relationship, only the key variables corresponding to the transmission data type key of the connection relationship in the base yaml file of the module program need to be changed, and the module program is regenerated without changing the code if step S120 is executed again.
In a specific application, the method for generating the module program of the service-oriented architecture can be implemented by adopting a SDK (Software Development Kit) framework. The following two tables present partial contents of a second declaration file (startup yaml file) and a first declaration file (base yaml file), where the first declaration file only shows keywords of a connection (i.e., io) data segment.
Table 1 Start yaml File
Table 2 base yaml File
In table 1, start configuration information and connection relation of a module program mobileye are shown, wherein content above connection is start configuration information, and is used for generating a start configuration file corresponding to the module, processor represents starting the module program in main processor 1, args represents related parameters of main processor 1, and param is basic information at the time of starting the module program, and the basic information is from mobileye _config.yaml file.
The following contents of connection are connection relations and are used for generating a theme file corresponding to the module program, and the module program comprises four pairs of connection relations:
localization_result:localization_result1;
perception_result:perception_result1;
relative_motion_result:relative_motion_result1;
smart_camera_front_result:smart_camera_front_result1。
each set of connection relations consists of key-value pairs (keys: topic key, value: topic value), localisation_result represents topic key, localisation_result 1 represents topic value.
The mobileye module program has four pairs of connection relationships, who are publish-subscribe relationships and who are client-server relationships, which cannot be distinguished at present, and base yaml files (io: type field distinction) to a specific module program are required to be distinguished.
Table 2 lists some of the keys of the io data segment in the base yaml file.
The key name is a key for starting the connection relation topic key in yaml files, and the corresponding key variable is a topic key, for example, topic key localization_result. And mobileye, the module program can acquire the topic value corresponding to the topic key from the topic file according to the key variable localization_result of the name key.
Keyword type, which is a keyword representing the type of connection relation configured in the startup yaml file, and corresponding key variables include publicher (publishing instance type), subscore (subscribing instance type), client (client instance type) and service (server instance type).
Keyword schema-keywords of transmission data types between publish-subscribe and client-server relationship, corresponding key variables are transmission data types.
Keyword optional, namely starting key words of selectable options of whether the topic values of the connection relations in the yaml files are selectable, wherein the corresponding key variables are Ture or False.
The service architecture-oriented module program generating device provided by the invention is described below, and the service architecture-oriented module program generating device described below and the service architecture-oriented module program generating method described above can be referred to correspondingly.
As shown in fig. 2, the module program generating device for a service oriented architecture provided by the present invention includes:
the first declaration file parsing unit 210 is configured to parse a first declaration file configured in advance and corresponding to a module program, and obtain key variables of keywords declared in the first declaration file, where the key variables represent unique fields in common program segments of different module programs.
And a module program generating unit 220, configured to insert the key variable into a corresponding reserved position in a pre-designed program template, so as to generate a module program.
According to the module program generating device of the service-oriented architecture, the value corresponding to the keyword declared in the first declaration file is obtained through analyzing the preconfigured first declaration file corresponding to the module program, the key variable represents the unique field in the common program section of different module programs, and the value corresponding to the key variable is inserted into the corresponding reserved position in the predesigned program template to generate the module program. Thus, a developer only needs to configure the first declaration file when developing the module program, then automatically generates the module program, and only needs to develop a core algorithm part in the module program subsequently, thereby greatly reducing the code quantity of the module program development and shortening the development period
Alternatively, the module program generating unit 220 includes:
And the placeholder searching unit is used for searching placeholders corresponding to the key variables in the program template according to the key words, and each reserved position is provided with the placeholder.
And the placeholder replacing unit is used for replacing the placeholders by the key variables until all the placeholders are replaced.
And the rename instruction receiving unit is used for receiving the instruction renaming the program template and generating the module program after renaming.
Optionally, the module program generating device of the service oriented architecture further includes:
the second plaintext file analyzing unit is used for analyzing the preconfigured second plaintext file and acquiring starting configuration information and connection relations corresponding to each module program stated in the second plaintext file.
And the starting configuration file generating unit is used for generating a starting configuration file of the corresponding module program according to the starting configuration information.
The theme file generation unit is used for generating a theme file of the corresponding module program according to the connection relation, wherein the theme file comprises a theme key and a theme value of the connection relation, and the key variables in the first statement file comprise the theme key and the theme key type.
The starting configuration file is used for being called by a system process to start a module program in the starting configuration file, a reading function used for reading a corresponding theme file when the module program is started is arranged in the program template, and the reading function is used for reading a theme value corresponding to the theme key in the theme file so that the module program can create an instance of a connection relation according to the theme value and the type of the theme key.
Optionally, the keywords in the first declaration file further include an optional item of whether the theme value in the connection relation is optional, a judging function is set in the program template, and the judging function is used for judging whether the module program is normally started or not under the condition that the theme value is not read when the module program is started according to the actual value of the key variable of the optional item, if the actual value of the key variable is true, the program module is normally started, and if the actual value of the key variable is false, the program module cannot be started.
Optionally, the judging function is further used for starting to report errors and prompting a theme key corresponding to the default theme value when judging that the module program fails to read the theme value and cannot be started normally.
Optionally, the key variable in the first declaration file further includes a transmission data type of the connection relationship.
Fig. 3 illustrates a physical schematic diagram of an electronic device, which may include a processor 310, a communication interface (Communications Interface), a memory 330, and a communication bus 340, as shown in fig. 3, where the processor 310, the communication interface 320, and the memory 330 communicate with each other via the communication bus 340. Processor 310 may invoke logic instructions in memory 330 to perform a service-oriented architecture module program generation method comprising:
Analyzing a first preset declaration file corresponding to a module program, and acquiring key variables of keywords declared in the first declaration file, wherein the key variables represent unique fields in common program segments of different module programs.
And inserting the key variables into corresponding reserved positions in a pre-designed program template to generate a module program.
The module program generating device of the service-oriented architecture provided by the invention acquires the keywords declared in the first declaration file through analyzing the preconfigured first declaration file corresponding to the module program, wherein the keywords represent the unique fields in the common program segments of different module programs, and inserts the keywords into the corresponding reserved positions in the predesigned program template to generate the module program. Therefore, a developer only needs to configure the first declaration file when developing the module program, then automatically generates the module program, and only needs to develop a core algorithm part in the module program subsequently, thereby greatly reducing the code quantity of the module program development and shortening the development period.
Further, the logic instructions in the memory 330 described above may be implemented in the form of software functional units and may be stored in a computer-readable storage medium when sold or used as a stand-alone product. Based on this understanding, the technical solution of the present invention may be embodied essentially or in a part contributing to the prior art or in a part of the technical solution, in the form of a software product stored in a storage medium, comprising several instructions for causing a computer device (which may be a personal computer, a server, a network device, etc.) to perform all or part of the steps of the method according to the embodiments of the present invention. The storage medium includes a U disk, a removable hard disk, a Read-Only Memory (ROM), a random access Memory (RAM, random Access Memory), a magnetic disk, an optical disk, or other various media capable of storing program codes.
In another aspect, the present invention also provides a computer program product, where the computer program product includes a computer program, where the computer program can be stored on a non-transitory computer readable storage medium, and when the computer program is executed by a processor, the computer can execute a method for generating a module program of a service oriented architecture provided by the above methods, and the method includes:
Analyzing a first preset declaration file corresponding to a module program, and acquiring key variables of keywords declared in the first declaration file, wherein the key variables represent unique fields in common program segments of different module programs.
And inserting the key variables into corresponding reserved positions in a pre-designed program template to generate a module program.
In yet another aspect, the present invention also provides a non-transitory computer readable storage medium having stored thereon a computer program which, when executed by a processor, is implemented to perform a method of generating a module program for a service oriented architecture provided by the above methods, the method comprising:
Analyzing a first preset declaration file corresponding to a module program, and acquiring key variables of keywords declared in the first declaration file, wherein the key variables represent unique fields in common program segments of different module programs.
And inserting the key variables into corresponding reserved positions in a pre-designed program template to generate a module program.
The apparatus embodiments described above are merely illustrative, wherein the elements illustrated as separate elements may or may not be physically separate, and the elements shown as elements may or may not be physical elements, may be located in one place, or may be distributed over a plurality of network elements. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment. Those of ordinary skill in the art will understand and implement the present invention without undue burden.
From the above description of the embodiments, it will be apparent to those skilled in the art that the embodiments may be implemented by means of software plus necessary general hardware platforms, or of course may be implemented by means of hardware. Based on this understanding, the foregoing technical solution may be embodied essentially or in a part contributing to the prior art in the form of a software product, which may be stored in a computer readable storage medium, such as ROM/RAM, a magnetic disk, an optical disk, etc., including several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute the method described in the respective embodiments or some parts of the embodiments.
It should be noted that the above-mentioned embodiments are merely for illustrating the technical solution of the present invention, and not for limiting the same, and although the present invention has been described in detail with reference to the above-mentioned embodiments, it should be understood by those skilled in the art that the technical solution described in the above-mentioned embodiments may be modified or some technical features may be equivalently replaced, and these modifications or substitutions do not make the essence of the corresponding technical solution deviate from the spirit and scope of the technical solution of the embodiments of the present invention.