Multi-level configuration management method
By adopting a multi-level configuration management method in configuration management, hierarchical relationships of configuration items are constructed and stored in a relational database, the problem of difficult configuration relationships under the flat configuration management method is solved, and effective management of complex configurations and improved system scalability and operation efficiency are achieved.
Patent Information
- Application Number
- CN202411571471.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-06
- Publication Date
- 2025-02-25
AI Technical Summary
The existing flat configuration management method cannot effectively reflect the hierarchical relationship and nested structure of configuration items, making it difficult to visually display and manage the dependencies and hierarchical relationships between configuration items.
Using a multi-level configuration management method, by inserting array symbols and type attributes into the configuration name, hierarchical relationships of configuration items are constructed and configuration items are stored in a relational database, effectively managing multi-level configuration files.
It realizes intuitive display and management of hierarchical relationships and dependencies of configuration items, adapts to complex system architectures and business scenarios, simplifies operation and maintenance and configuration release, and improves the scalability and operation efficiency of the system.
Smart Images

Figure HDA0005120567460000011 
Figure HDA0005120567460000012 
Figure HDA0005120567460000021
Abstract
Description
Technical Field
[0001] The present invention relates to the field of software configuration management, and in particular to a multi-level configuration management method. Background Art
[0002] Existing configuration management systems, particularly open-source configuration centers such as Apache Zookeeper and etcd, are widely used in distributed systems to manage configuration files and parameters. These systems typically adopt a flat configuration management approach, where all configuration items are stored in a flat structure as key-value pairs. However, as system complexity increases, configuration files in actual production environments often adopt complex hierarchical structures, such as XML and JSON files. Mature application systems often choose configuration files in formats such as JSON and XML for the following reasons: 1. Structured Data: Both JSON and XML are structured data formats that clearly represent nested and hierarchical relationships, making them suitable for complex configurations. 2. Widespread Support: Most programming languages and frameworks support parsing JSON and XML, facilitating cross-platform and cross-language use. 3. Readability: JSON is relatively concise and easy to read and write, while XML offers good scalability and descriptiveness, making it suitable for large and complex configurations. These files contain nested configuration items and multi-level parameter settings, which cannot be reflected in flat configuration files. This makes it impossible to intuitively display and manage the dependencies and hierarchical relationships between configuration items, making flat management methods face many challenges when dealing with these complex configurations.
[0003] The configuration file usually contains the following information: database connection information (such as URL, username, password), network service port, cache settings, log level, API key of third-party service, system environment variables. This invention is based on relational database and Golang language implementation, and realizes the effective management of multi-level configuration files by flattening the configuration items. The pe.CreateAttr method in this invention refers to https: / / pkg.go.dev / github.com / beevik / etree#Element.CreateAttr;pe.AddChild method reference https: / / pkg.go.dev / github.com / beevik / etree#Element.AddChild, etree.NewDocumentWithRoot method reference https: / / pkg.go.dev / github.com / beevik / etree#NewDocumentWithRoot, WriteToString method reference https: / / pkg.go.dev / github.com / beevik / etree#Document.WriteToString . Summary of the Invention
[0004] The existing technology has the problem that flat configuration items cannot reflect their hierarchical relationships and nested structures, which makes it impossible to intuitively display and manage the dependencies and hierarchical relationships between configuration items, making the flat management method face many challenges when dealing with these complex configurations.
[0005] In order to solve the above problems, the present invention provides a multi-level configuration management method, the specific steps are as follows:
[0006] Step S1: store configuration items;
[0007] Step S1-1: storing XML nodes;
[0008] Step S1-1-1: Build configuration name;
[0009] Insert array symbols into the configuration name, and selectively add % or array symbols [n] to the configuration item name to record the hierarchical relationship according to the configuration item type;
[0010] When the configuration item type is an XML attribute, insert a % symbol in the configuration name;
[0011] When the configuration item type is an XML node, the array symbol [n] needs to be spliced;
[0012] For XML root node: the configuration name is the XML node name;
[0013] For XML non-root nodes: the configuration name is the value of the concatenation of the configuration item name of the upper-level XML node and the current XML node name [n], where n is an integer starting from 0 and records the number of child nodes of the upper-level node that the current node is.
[0014] For XML attributes: the configuration name is the value of the configuration item name of the XML node to which it belongs, followed by % and the current attribute name;
[0015] Step S1-1-2: Build configuration item value;
[0016] Store the values of XML nodes and XML attributes;
[0017] For an XML node with child nodes: the value of the configuration item is empty;
[0018] For an XML node without child nodes: the value of the configuration item is the value of the XML node;
[0019] For XML attributes: the value of the configuration item is the value of the XML attribute;
[0020] In XML, an element is the most basic building block, usually starting with a <tag> and ending with < / tag>. Attributes are used to provide additional descriptive information for these elements. They do not appear in the content part of the element but are placed inside the start tag of the element in the format key = "value".
[0021] For example: <person name = "John" age = "30">;
[0022] Here, name and age are XML attributes, and John and 30 are their values.
[0023] Step S1-1-3: Add a type attribute to mark the type of the configuration;
[0024] The type attribute includes: element represents an XML node, and attribute represents an XML attribute;
[0025] Step S1-1-4: The XML format configuration file is as follows:
[0026] <root><serverid=”1”> <ip> 127.0.0.1< / ip> <serverid=”2”> <ip> 127.0.0.2< / ip> < / root> ;
[0027] Among them, root is the root node, the configuration item name is root, and the value is empty;
[0028] server is the first child node of root, the configuration item name is root[0]server, and the value is empty;
[0029] id is an attribute of server, the configuration item name is root[0]server%id, and the value is 1;
[0030] ip is the first child node of server, the configuration item name is root[0]server[0]ip, and the value is 127.0.0.1;
[0031] server is the second child node of root, the configuration item name is root[1]server, and the value is empty;
[0032] id is an attribute of server, the configuration item name is root[1]server%id, and the value is 2;
[0033] ip is the first child node of server, the configuration item name is root[0]server[1]ip, and the value is 127.0.0.2;
[0034] The transformed configuration file is represented as:
[0035] Configuration name: server; Configuration value: empty; Configuration item type: element;
[0036] Configuration name: server[0]ip; Configuration value: 127.0.0.1; Configuration item type: element;
[0037] Step S1-2: Store JSON key-value pairs;
[0038] Step S1-2-1: Build configuration name;
[0039] According to the configuration item type, optionally add % or array symbol [n] to the configuration item name to record the hierarchical relationship;
[0040] Selectivity is determined by the configuration item type of the upper element:
[0041] The upper element type is an object. Inserting a % symbol in the configuration name indicates that the current element is a property of the object.
[0042] The upper element type is an array, and [n] is inserted in the configuration name to indicate that the current element is the nth child element of the array;
[0043] For elements in an array, the configuration name is the name of the upper-layer element configuration item concatenated with [n], where n is an integer starting from 0 and records the index of the current element in the array.
[0044] If the element type is object or array, the value of the configuration item is empty, otherwise the value of the configuration item is the value of the element;
[0045] Step S1-2-2: Add a type attribute to mark the configuration type;
[0046] Type attributes include: object represents a JSON object, array represents an array in JSON, string represents a string in JSON, number represents a number in JSON, and bool represents a Boolean type in JSON;
[0047] Step S1-2-3: The configuration file {"server":{"ip":"127.0.0.1","port":
[8080] }} in JSON format is transformed into the following:
[0048] Configuration name: server; Configuration value: empty; Configuration item type: object;
[0049] Configuration name: server%ip; Configuration value: 127.0.0.1; Configuration item type: string;
[0050] Configuration name: server%port; Configuration value: empty; Configuration item type: array;
[0051] Configuration name: server%port[0]; Configuration value: 8080; Configuration item type: number;
[0052] Step S2: Build the configuration item table config_item;
[0053] Step S2-1: Define a table named Configuration Item and store it in a relational database. The table content includes: field name, field name type, and field name description;
[0054] Field names include: id, namespace_id, key, value, type, line_number, comment, is_deleted, created_at, updated_at, created_user, updated_user;
[0055] Field name types include: number, string, date;
[0056] Field name descriptions include: auto-increment primary key, configuration namespace ID, configuration name, configuration value, configuration item type, sorting order when displayed on the configuration center interface, configuration item description, whether it has been deleted (1 for deleted and 0 for not deleted), creation date, update date, creation user name, and update user name;
[0057] Step S3: Configure the namespace;
[0058] Step S3-1: The configuration namespace consists of multiple configuration items, including namespace name and type. A table named config_namespace is defined and stored in a relational database. The table contains the following contents: field name, field name type, and field name description.
[0059] Field names include: id, env_id, namespace_name, comment, is_deleted, created_at, updated_at, created_user, updated_user, type;
[0060] Field name types include: number, string, date;
[0061] Field name descriptions include: auto-increment primary key, configuration plan ID, configuration namespace name, configuration namespace description, configuration plan deletion status (1 for deleted, 0 for not deleted), configuration plan creation date, configuration plan update date, configuration plan creation user name, configuration plan update user name, configuration plan type (json for JSON file, xml for XML file, kv for non-hierarchical file);
[0062] Based on the above method, the following functions are provided:
[0063] F1: Add, delete, and modify configuration items;
[0064] Configuration items are associated with the namespace primary key through the namespace_id field, enabling the addition, deletion, modification, and query of various types of configuration item entities under the specified namespace;
[0065] F1-1: Add a configuration to the namespace;
[0066] F1-1-1: Clarify the basic information of the target namespace, the configuration to be added, and its upper-layer configuration;
[0067] Target namespace information: The prerequisite for adding a configuration item is to clearly identify the namespace to which the configuration item belongs. This information is obtained by querying the namespace table through SQL. This is the basis for ensuring that the new configuration item can be correctly stored.
[0068] The basic information of the new configuration item includes: the configuration name, configuration value and type of the new configuration item;
[0069] Upper-level configuration items: New configuration items have a hierarchical relationship with existing upper-level configuration items. The upper-level configuration item information, namely the configuration name and hierarchical structure, is also a prerequisite for being known. This is located by querying the configuration item table through SQL.
[0070] F1-1-2: Refer to the configuration item type of the upper-level configuration, concatenate the name of the new configuration with the name of the upper-level configuration, and save the basic information of the new configuration item and the primary key of the target namespace into the config_item table to complete the configuration modification;
[0071] F1-2: Before modifying the configuration, the primary key of the configuration to be modified and the value to be updated are known, and the value is updated using SQL language;
[0072] F1-3: Modify the is_deleted field value in the configuration to be deleted to 1, and then delete the configuration;
[0073] F2: Import configuration file;
[0074] F2-1: JSON type file import;
[0075] F2-1-1: Get the file name, file type, operation time, and operation user information during import, which correspond to the namespace_name, type, created_at, and created_user fields in the config_namespace table, and record the namespace primary key returned by the database;
[0076] F2-1-2: Create an empty root node as the ancestor of all configuration items;
[0077] F2-1-3: Read the contents of the JSON file into memory, load the contents of the JSON file into the program, convert the read JSON string into the Go map type, and use the json.Unmarshal method to parse the JSON data into the map[string]interface{} type. Each attribute of the JSON will be mapped to a key in the map, which is a string, and the corresponding value can be of any type;
[0078] F2-1-4: Traverse the first layer of the map, extracting each key and value in turn: During the traversal process, a key and value are obtained in each loop, and in the Go language, the forrange statement is used to access each pair of keys and values in the map;
[0079] Get the key and value of the first-level element, use the element key as the configuration name, and obtain the element value type through reflection. If the element value type is an object or array, the configuration value is empty. Otherwise, the configuration value is the element value itself. Use the root node as the upper node and store the new configuration in the database using the method in step F1. If the element value type is an object or array, use the current configuration as the upper node and the element value as the new JSON. Repeat steps F2-1-3 and F2-1-4 until all elements are traversed.
[0080] F2-2: XML type file import;
[0081] F2-2-1: Get the file name, file type, operation time, and operation user information during import, which correspond to the namespace_name, type, created_at, and created_user fields in the config_namespace table, and record the namespace primary key returned by the database.
[0082] F2-2-2: Use the XML open source library etree to read the file content into memory according to the DOM tree data structure to obtain the XML root node;
[0083] F2-2-3: Use the root node tag name as the configuration name, and the root node value as the configuration value. If the node is a root node, the upper node is empty. Add the new configuration to the database in the same way as in step F1. Traverse all the attributes of the node. Use the attribute name as the configuration name, use the attribute value as the configuration value, and use the node as the upper node. Add the new configuration to the database in the same way as in step F1. Use the node as the upper node, traverse all the directly subordinate nodes of the node, and repeat steps F2-2-3 until all XML nodes are traversed.
[0084] F3: Configuration release;
[0085] The configuration release table config_release records the latest status of each configuration namespace after release;
[0086] F3-1: Execute the configuration release steps for the specified namespace. The specific steps are as follows:
[0087] F3-1-1: Get all configuration items through the specified namespace primary key;
[0088] F3-1-2: Filter configuration items where the field name is_deleted is 1;
[0089] F3-1-3: Serialize the remaining configuration items into JSON strings. Use the Go standard library encoding / json to serialize data into JSON strings, and use the json.Marshal() function to perform this conversion.
[0090] F3-1-4: Set all past configuration release history as abandoned by the specified namespace primary key, that is, update is_abandon to 1;
[0091] F3-1-5: Integrate the submitted namespace primary key, release name, submission time, and JSON string, and insert them into the config_release table;
[0092] F4: Configuration rollback;
[0093] F4-1: The configuration release table config_release records all release history of the namespace. Configuration rollback can be achieved through the following operations:
[0094] F4-1-1: By using the specified namespace primary key, all matching configuration release histories are set to abandoned, that is, is_abandon is updated to 1, and is_abandon of the specified release version record is updated to 0;
[0095] F5: Displays the configuration status changes within the specified configuration namespace;
[0096] F5-1: The configuration item table config_item records all configuration items in a specified namespace, including newly added, modified, and deleted configuration items. The configuration release table config_release records configuration items in the namespace that are being released. By comparing the data in the two tables, we can calculate which configuration items have been added, modified, or deleted. The specific steps are as follows:
[0097] F5-1-1: By specifying the namespace primary key, configure the release table config_release to obtain the release records in the release process where is_abandon = 0;
[0098] F5-1-2: Deserialize the items field in the release record and load it into memory, which contains all the configuration items currently released, and define it as the array variable releaseItems;
[0099] F5-1-3: Get the latest configuration item from the configuration item table config_item by specifying the namespace primary key and define it as the array variable currentItems;
[0100] F5-1-4: Define the data structure of the configuration tree, a structure that contains the current configuration and a set of sub-configurations;
[0101] F5-1-5: Generate the configuration tree of currentItems;
[0102] Assume that all elements in the array variable currentItems are of the same level. Generate a configuration tree set by traversing the array variable currentItems and creating a new configuration tree node for each element, defined as the array variable treeItems. The current configuration of all elements in the array variable treeItems is the element in currentItems, and all subconfigurations are empty.
[0103] F5-1-6: Generate a hash key using the configuration name and configuration item type of each element in the array variable treeItems, and use the element itself as the hash value to generate the hash table treeItemsMap;
[0104] F5-1-7: Traverse the elements of the array variable treeItems. The configuration name records the hierarchical relationship. Find the upper-level configuration name and type through the configuration name and type of the current element, and generate the upper-level configuration item hash key pk;
[0105] F5-1-8: If pk exists in the hash table treeItemsMap, since treeItemsMap is a hash table and pk is a hash key, the corresponding upper-level configuration item in the hash table can be quickly located based on pk, and the current configuration is added to the sub-configuration of the upper-level configuration and removed from the array variable treeItems. If pk does not exist, the traversal continues;
[0106] F5-1-9: After the traversal is completed, the element retained in the array variable treeItems is the vertex of the configuration tree. The configuration tree of the array variable currentsItem is traversed from the root node. If the element does not exist in the array variable releaseItems, it is marked as a newly added element. If both exist but the values are different, it is marked as a modified element. The array variable releaseItems is traversed. If the element does not exist in the array variable currentsItem, it is marked as a deleted element.
[0107] F6: Provides configuration for application services;
[0108] F6-1: Provide XML configuration;
[0109] F6-1-1: Obtain the release record that is in the process of being released (i.e., is_abandon = 0) from the configuration release table config_release by specifying the namespace primary key;
[0110] F6-1-2: Deserialize the items field in the release record and load it into memory, which is all the configuration items currently released, and define it as the array variable releaseItems;
[0111] F6-1-3: Define the data structure of the configuration tree and generate the releaseItems configuration tree according to F5-1-4;
[0112] F6-1-4: Select the root node in the releaseItems configuration tree as the input parameter and perform the following recursive operations:
[0113] Get the current configuration and sub-configuration in the root node. If the current configuration type is element, create an XML node. Use the open source library etree to define the XML node. The variable name is pe and the type is etree.Document. Iterate through each element in the sub-configuration collection. If the sub-configuration item type is attribute, call the pe.CreateAttr method to add the sub-configuration name and configuration value as XML attributes to the pe node. If the sub-configuration item type is element, use the sub-configuration as the input parameter to repeat the steps in F6-1-4 for the current configuration item type of element, obtain the return value ce, and call the pe.AddChild method to add ce to the child node of pe. Return the node pe. Finally, call etree.NewDocumentWithRoot with pe as the root node to generate the XML document variable d. Call the WriteToString method of d to generate the XML text.
[0114] F6-2: Provide JSON configuration;
[0115] F6-2-1: Obtain the release record in the process of being released with is_abandon=0 from the configuration release table config_release by specifying the namespace primary key;
[0116] F6-2-2: Deserialize the items field in the release record and load it into memory, which is all the configuration items currently released, defined as the array variable releaseItems
[0117] F6-2-3: Define the data structure of the configuration tree and generate the releaseItems configuration tree according to F5-1-4;
[0118] F6-2-4: Select the root node in the releaseItems configuration tree as the input parameter and perform the following recursive operations:
[0119] Get the current configuration and sub-configuration in the node. If the sub-configuration collection length is empty, return the configuration value. If the current configuration type is object, create a hash pm. If the type is arrary, create a slice ps. Iterate over each element in the sub-configuration collection, call recursively, repeat steps F6-2-4, and define the return value as cm. Add cm to pm or ps, return pm or ps, and serialize pm or ps into JSON text.
[0120] F7: Converts the latest configuration status to the original configuration file to provide configuration services for application services;
[0121] F7-1: Switching the application service configuration is achieved by switching the configuration scheme. The table used to record the configuration scheme is the configuration scheme table config_env, which includes: field name, field name type, and field name description;
[0122] Field names include: id, env_name, comment, is_used, is_deleted, created_at, updated_at, created_user, updated_user;
[0123] Field name types include: number, string, date;
[0124] Field name descriptions include: auto-increment primary key, configuration plan name, configuration plan introduction, configuration plan activation status (1 for enabled and 0 for disabled), configuration plan deletion status (1 for deleted and 0 for not deleted), configuration plan creation date, configuration plan update date, configuration plan creation user name, and configuration plan update user name;
[0125] F7-2: Enable the specified configuration scheme;
[0126] F7-2-1: All configuration schemes are set to disabled, i.e. is_used is updated to 0;
[0127] F7-2-2: Update is_used of the specified configuration scheme to 1;
[0128] F7-2-3: Get all namespaces under the specified configuration scheme primary key
[0129] F7-2-4: Provide configuration services to external parties according to the steps in F6.
[0130] Preferably, the array symbol includes: n, where n is a number.
[0131] In a preferred manner, the hierarchical relationship includes: a sequential relationship.
[0132] Preferably, the first-level elements refer to the outermost key-value pairs in the JSON file.
[0133] The beneficial effects of this invention are: Through a multi-level configuration management method, the hierarchical relationships and dependencies of configuration items are intuitively displayed, resolving the difficulty in displaying and managing relationships between configuration items under existing flat configuration management methods. By implementing multi-level management of configuration namespaces and configuration items, the hierarchical structure and dependencies of configuration items at each level are clearly reflected. This approach adapts to complex system architectures and business scenarios, ensuring that dependencies between configuration items are well managed and maintained.
[0134] Simplify operations and configuration releases. A multi-level configuration center management approach simplifies operations and maintenance. By centrally managing configuration items at different levels, the system can quickly make configuration changes or releases, reducing the risks of manual configuration modifications. Furthermore, centralized configuration management improves visualization and version control of configuration items, enhancing the controllability and consistency of the overall configuration.
[0135] Improve system scalability. This approach allows for rapid configuration expansion across different environments (e.g., development, testing, production) or application modules. New modules or services can inherit existing configuration levels or customize them as needed, making the system highly scalable and adaptable to changing business needs.
[0136] Support for distributed and microservice architectures. The multi-tiered configuration center adapts to the complex configuration requirements of distributed systems and microservice architectures. Each service or component can manage its configuration independently, reducing the workload of repeated configuration items.
[0137] Improve system efficiency. By reducing duplicate configurations and optimizing the inheritance and override logic of configuration items, the system's efficiency in loading and parsing configurations can be improved, thereby enhancing overall system performance. Centralized configuration management also helps the system quickly synchronize and implement configuration changes when they occur, reducing system downtime. BRIEF DESCRIPTION OF THE DRAWINGS
[0138] Figure 1 This is a schematic diagram of XML configuration item generation rules of the present invention;
[0139] Figure 2 This is a schematic diagram of the JSON configuration item generation rules of the present invention;
[0140] Figure 3 This is a flow chart of importing configuration files into a configuration center according to the present invention. DETAILED DESCRIPTION
[0141] The specific implementation steps of the present invention include:
[0142] Step S1: store configuration items;
[0143] Step S1-1: storing XML nodes;
[0144] Step S1-1-1: Build configuration name;
[0145] Insert array symbols into the configuration name, and selectively add % or array symbols [n] to the configuration item name to record the hierarchical relationship according to the configuration item type;
[0146] When the configuration item type is an XML attribute, insert a % symbol in the configuration name;
[0147] When the configuration item type is an XML node, the array symbol [n] needs to be spliced;
[0148] For XML root node: the configuration name is the XML node name;
[0149] For XML non-root nodes: the configuration name is the value of the concatenation of the configuration item name of the upper-level XML node and the current XML node name [n], where n is an integer starting from 0 and records the number of child nodes of the upper-level node that the current node is.
[0150] For XML attributes: the configuration name is the value of the configuration item name of the XML node to which it belongs, followed by % and the current attribute name;
[0151] Step S1-1-2: Build configuration item value;
[0152] Store the values of XML nodes and XML attributes;
[0153] For an XML node with child nodes: the value of the configuration item is empty;
[0154] For an XML node without child nodes: the value of the configuration item is the value of the XML node;
[0155] For XML attributes: the value of the configuration item is the value of the XML attribute;
[0156] Step S1-1-3: Add a type attribute to mark the configuration type;
[0157] Type attributes include: element is represented as an XML node, attribute is represented as an XML attribute;
[0158] Step S1-1-4: The XML format configuration file is:
[0159] <root><serverid=”1”> <ip> 127.0.0.1< / ip> <serverid=”2”> <ip> 127.0.0.2< / ip> < / root> ;
[0160] Among them, root is the root node, the configuration item name is root, and the value is empty;
[0161] server is the first child node of root, the configuration item name is root[0]server, and the value is empty;
[0162] id is the attribute of server, the configuration item name is root[0]server%id, and the value is 1;
[0163] ip is the first child node of server, the configuration item name is root[0]server[0]ip, and the value is 127.0.0.1;
[0164] server is the second child node of root, the configuration item name is root[1]server, and the value is empty;
[0165] id is the attribute of server, the configuration item name is root[1]server%id, and the value is 2;
[0166] ip is the first child node of server, the configuration item name is root[0]server[1]ip, and the value is 127.0.0.2;
[0167] The modified configuration file is expressed as:
[0168] Configuration name: server; Configuration value: empty; Configuration item type: element;
[0169] Configuration name: server[0]ip; Configuration value: 127.0.0.1; Configuration item type: element;
[0170] Step S1-2: Store JSON key-value pairs;
[0171] Step S1-2-1: Build configuration name;
[0172] According to the configuration item type, optionally add % or array symbol [n] to the configuration item name to record the hierarchical relationship;
[0173] Selectivity is determined by the configuration item type of the upper element:
[0174] The upper element type is an object. Inserting a % symbol in the configuration name indicates that the current element is a property of the object.
[0175] The upper element type is an array, and [n] is inserted in the configuration name to indicate that the current element is the nth child element of the array;
[0176] For elements in an array, the configuration name is the name of the upper-layer element configuration item concatenated with [n], where n is an integer starting from 0 and records the index of the current element in the array.
[0177] If the element type is object or array, the value of the configuration item is empty, otherwise the value of the configuration item is the value of the element;
[0178] Step S1-2-2: Add a type attribute to mark the configuration type;
[0179] Type attributes include: object represents a JSON object, array represents an array in JSON, string represents a string in JSON, number represents a number in JSON, and bool represents a Boolean type in JSON;
[0180] Step S1-2-3: The configuration file {"server":{"ip":"127.0.0.1","port":
[8080] }} in JSON format is transformed into the following:
[0181] Configuration name: server; Configuration value: empty; Configuration item type: object;
[0182] Configuration name: server%ip; Configuration value: 127.0.0.1; Configuration item type: string;
[0183] Configuration name: server%port; Configuration value: empty; Configuration item type: array;
[0184] Configuration name: server%port[0]; Configuration value: 8080; Configuration item type: number;
[0185] Step S2: Build the configuration item table config_item;
[0186] Step S2-1: Define a table named Configuration Item and store it in a relational database. The table content includes: field name, field name type, and field name description;
[0187] Field names include: id, namespace_id, key, value, type, line_number, comment, is_deleted, created_at, updated_at, created_user, updated_user;
[0188] Field name types include: number, string, date;
[0189] Field name descriptions include: auto-increment primary key, configuration namespace ID, configuration name, configuration value, configuration item type, sorting order when displayed on the configuration center interface, configuration item description, whether it has been deleted (1 for deleted and 0 for not deleted), creation date, update date, creation user name, and update user name;
[0190] Step S3: Configure the namespace;
[0191] Step S3-1: The configuration namespace consists of multiple configuration items, including namespace name and type. A table named config_namespace is defined and stored in a relational database. The table contains the following contents: field name, field name type, and field name description.
[0192] Field names include: id, env_id, namespace_name, comment, is_deleted, created_at, updated_at, created_user, updated_user, type;
[0193] Field name types include: number, string, date;
[0194] Field name descriptions include: auto-increment primary key, configuration plan ID, configuration namespace name, configuration namespace description, configuration plan deletion status (1 for deleted, 0 for not deleted), configuration plan creation date, configuration plan update date, configuration plan creation user name, configuration plan update user name, configuration plan type (json for JSON file, xml for XML file, kv for non-hierarchical file);
[0195] Based on the above method, the following functions are provided:
[0196] F1: Add, delete, and modify configuration items;
[0197] Configuration items are associated with the namespace primary key through the namespace_id field, enabling the addition, deletion, modification, and query of various types of configuration item entities under the specified namespace;
[0198] F1-1: Add a configuration to the namespace;
[0199] F1-1-1: Clarify the basic information of the target namespace, the configuration to be added, and its upper-layer configuration;
[0200] Target namespace information: obtained by querying the namespace table through SQL;
[0201] The basic information of the new configuration item includes: the configuration name, configuration value and type of the new configuration item;
[0202] Upper-level configuration items: New configuration items have a hierarchical relationship with existing upper-level configuration items. The upper-level configuration item information, namely the configuration name and hierarchical structure, is also a prerequisite for being known. This is located by querying the configuration item table through SQL.
[0203] F1-1-2: Refer to the configuration item type of the upper-level configuration, concatenate the name of the new configuration with the name of the upper-level configuration, and save the basic information of the new configuration item and the primary key of the target namespace into the config_item table to complete the configuration modification;
[0204] F1-2: Modify the is_deleted field value in the configuration to be deleted to 1, and then delete the configuration;
[0205] F2: Import configuration file;
[0206] F2-1: JSON type file import;
[0207] F2-1-1: Get the file name, file type, operation time, and operation user information during import, which correspond to the namespace_name, type, created_at, and created_user fields in the config_namespace table, and record the namespace primary key returned by the database;
[0208] F2-1-2: Create an empty root node as the ancestor of all configuration items;
[0209] F2-1-3: Read the contents of the JSON file into memory, load the contents of the JSON file into the program, convert the read JSON string into the Go map type, and use the json.Unmarshal method to parse the JSON data into the map[string]interface{} type. Each attribute of the JSON will be mapped to a key in the map, which is a string, and the corresponding value can be of any type;
[0210] F2-1-4: Traverse the first layer of the map, extracting each key and value in turn: During the traversal process, a key and value are obtained in each loop, and in the Go language, the forrange statement is used to access each pair of keys and values in the map;
[0211] Get the key and value of the first-level element, use the element key as the configuration name, and obtain the element value type through reflection. If the element value type is an object or array, the configuration value is empty. Otherwise, the configuration value is the element value itself. Use the root node as the upper node and store the new configuration in the database using the method in step F1. If the element value type is an object or array, use the current configuration as the upper node and the element value as the new JSON. Repeat steps F2-1-3 and F2-1-4 until all elements are traversed.
[0212] F2-2: XML type file import;
[0213] F2-2-1: Get the file name, file type, operation time, and operation user information during import, which correspond to the namespace_name, type, created_at, and created_user fields in the config_namespace table, and record the namespace primary key returned by the database.
[0214] F2-2-2: Use the XML open source library etree to read the file content into memory according to the DOM tree data structure to obtain the XML root node;
[0215] F2-2-3: Use the root node tag name as the configuration name, and the root node value as the configuration value. If the node is a root node, the upper node is empty. Add the new configuration to the database in the same way as in step F1. Traverse all the attributes of the node. Use the attribute name as the configuration name, use the attribute value as the configuration value, and use the node as the upper node. Add the new configuration to the database in the same way as in step F1. Use the node as the upper node, traverse all the directly subordinate nodes of the node, and repeat steps F2-2-3 until all XML nodes are traversed.
[0216] F3: Configuration release;
[0217] The configuration release table config_release records the latest status of each configuration namespace after release;
[0218] F3-1: Execute the configuration release steps for the specified namespace. The specific steps are as follows:
[0219] F3-1-1: Get all configuration items through the specified namespace primary key;
[0220] F3-1-2: Filter configuration items where the field name is_deleted is 1;
[0221] F3-1-3: Serialize the remaining configuration items into JSON strings. Use the Go standard library encoding / json to serialize data into JSON strings, and use the json.Marshal() function to perform this conversion.
[0222] F3-1-4: Set all past configuration release history as abandoned by the specified namespace primary key, that is, update is_abandon to 1;
[0223] F3-1-5: Integrate the submitted namespace primary key, release name, submission time, and JSON string, and insert them into the config_release table;
[0224] F4: Configuration rollback;
[0225] F4-1: The configuration release table config_release records all release history of the namespace. Configuration rollback can be achieved through the following operations:
[0226] F4-1-1: By using the specified namespace primary key, all matching configuration release histories are set to abandoned, that is, is_abandon is updated to 1, and is_abandon of the specified release version record is updated to 0;
[0227] F5: Displays the configuration status changes within the specified configuration namespace;
[0228] F5-1: The configuration item table config_item records all configuration items in a specified namespace, including newly added, modified, and deleted configuration items. The configuration release table config_release records configuration items in the namespace that are being released. By comparing the data in the two tables, we can calculate which configuration items have been added, modified, or deleted. The specific steps are as follows:
[0229] F5-1-1: By specifying the namespace primary key, configure the release table config_release to obtain the release records in the release process where is_abandon = 0;
[0230] F5-1-2: Deserialize the items field in the release record and load it into memory, which contains all the configuration items currently released, and define it as the array variable releaseItems;
[0231] F5-1-3: Get the latest configuration item from the configuration item table config_item by specifying the namespace primary key and define it as the array variable currentItems;
[0232] F5-1-4: Define the data structure of the configuration tree, a structure that contains the current configuration and a set of sub-configurations;
[0233] F5-1-5: Generate the configuration tree of currentItems;
[0234] Assume that all elements in the array variable currentItems are of the same level. Generate a configuration tree set by traversing the array variable currentItems and creating a new configuration tree node for each element, defined as the array variable treeItems. The current configuration of all elements in the array variable treeItems is the element in currentItems, and all subconfigurations are empty.
[0235] F5-1-6: Generate a hash key using the configuration name and configuration item type of each element in the array variable treeItems, and use the element itself as the hash value to generate the hash table treeItemsMap;
[0236] F5-1-7: Traverse the elements of the array variable treeItems. The configuration name records the hierarchical relationship. Find the upper-level configuration name and type through the configuration name and type of the current element, and generate the upper-level configuration item hash key pk;
[0237] F5-1-8: If pk exists in the hash table treeItemsMap, since treeItemsMap is a hash table and pk is a hash key, the corresponding upper-level configuration item in the hash table can be quickly located based on pk, and the current configuration is added to the sub-configuration of the upper-level configuration and removed from the array variable treeItems. If pk does not exist, the traversal continues;
[0238] F5-1-9: After the traversal is completed, the element retained in the array variable treeItems is the vertex of the configuration tree. The configuration tree of the array variable currentsItem is traversed from the root node. If the element does not exist in the array variable releaseItems, it is marked as a newly added element. If both exist but the values are different, it is marked as a modified element. The array variable releaseItems is traversed. If the element does not exist in the array variable currentsItem, it is marked as a deleted element.
[0239] F6: Provides configuration for application services;
[0240] F6-1: Provide XML configuration;
[0241] F6-1-1: Obtain the release record that is in the process of being released (i.e., is_abandon = 0) from the configuration release table config_release by specifying the namespace primary key;
[0242] F6-1-2: Deserialize the items field in the release record and load it into memory, which is all the configuration items currently released, and define it as the array variable releaseItems;
[0243] F6-1-3: Define the data structure of the configuration tree and generate the releaseItems configuration tree according to F5-1-4;
[0244] F6-1-4: Select the root node in the releaseItems configuration tree as the input parameter and perform the following recursive operations:
[0245] Get the current configuration and sub-configuration in the root node. If the current configuration type is element, create an XML node. Use the open source library etree to define the XML node. The variable name is pe and the type is etree.Document. Iterate through each element in the sub-configuration collection. If the sub-configuration item type is attribute, call the pe.CreateAttr method to add the sub-configuration name and configuration value as XML attributes to the pe node. If the sub-configuration item type is element, use the sub-configuration as the input parameter to repeat the steps in F6-1-4 for the current configuration item type of element, obtain the return value ce, and call the pe.AddChild method to add ce to the child node of pe. Return the node pe. Finally, call etree.NewDocumentWithRoot with pe as the root node to generate the XML document variable d. Call the WriteToString method of d to generate the XML text.
[0246] F6-2: Provide JSON configuration;
[0247] F6-2-1: Obtain the release record in the process of being released with is_abandon=0 from the configuration release table config_release by specifying the namespace primary key;
[0248] F6-2-2: Deserialize the items field in the release record and load it into memory, which is all the configuration items currently released, defined as the array variable releaseItems
[0249] F6-2-3: Define the data structure of the configuration tree and generate the releaseItems configuration tree according to F5-1-4;
[0250] F6-2-4: Select the root node in the releaseItems configuration tree as the input parameter and perform the following recursive operations:
[0251] Get the current configuration and sub-configuration in the node. If the sub-configuration collection length is empty, return the configuration value. If the current configuration type is object, create a hash pm. If the type is arrary, create a slice ps. Iterate over each element in the sub-configuration collection, call recursively, repeat steps F6-2-4, and define the return value as cm. Add cm to pm or ps, return pm or ps, and serialize pm or ps into JSON text.
[0252] F7: Converts the latest configuration status to the original configuration file to provide configuration services for application services;
[0253] F7-1: Switching the application service configuration is achieved by switching the configuration scheme. The table used to record the configuration scheme is the configuration scheme table config_env, which includes: field name, field name type, and field name description;
[0254] Field names include: id, env_name, comment, is_used, is_deleted, created_at, updated_at, created_user, updated_user;
[0255] Field name types include: number, string, date;
[0256] Field name descriptions include: auto-increment primary key, configuration plan name, configuration plan introduction, configuration plan activation status (1 for enabled and 0 for disabled), configuration plan deletion status (1 for deleted and 0 for not deleted), configuration plan creation date, configuration plan update date, configuration plan creation user name, and configuration plan update user name;
[0257] F7-2: Enable the specified configuration scheme;
[0258] F7-2-1: All configuration schemes are set to disabled, i.e. is_used is updated to 0;
[0259] F7-2-2: Update is_used of the specified configuration scheme to 1;
[0260] F7-2-3: Get all namespaces under the specified configuration scheme primary key
[0261] F7-2-4: Provide configuration services to external parties according to the steps in F6.
[0262] Reflection refers to the use of the Go language's reflection mechanism to dynamically inspect and manipulate the types and variable values in a program. The Go language's reflection mechanism allows you to view the type of a variable, obtain its fields, and operate on it at runtime. This is particularly useful for situations where you need to deal with uncertain or dynamic structures, such as processing JSON or other types of dynamic data. When traversing a map, since the values in the map may be of multiple types (such as strings, numbers, arrays, objects, etc.), the reflection mechanism is needed to determine the specific type of each element. If the value of an element is an object (that is, a nested structure or map) or an array (or slice), the configuration value will be set to empty as required. Otherwise, if the element value is a simple type (such as a string, number, Boolean value), the configuration value will be the element value itself.
[0263] A configuration tree is a data structure that is typically used to organize and manage hierarchical relationships of configuration items. The core idea of a configuration tree is to organize configuration items into parent-child hierarchical relationships, where each configuration item (node) can contain multiple sub-configurations (child nodes), and each node contains its own configuration content. This tree structure is characterized by a clear hierarchy, where each node can have its own parent node and child nodes, making it suitable for hierarchical management of complex configurations.
[0264] The present invention includes three key components: configuration items, configuration namespaces, and configuration schemes. It uses three key tables, namely, the configuration item table config_item to record the basic information and hierarchical relationship of configuration items, the configuration namespace table config_namespace to associate multiple configuration items to define a configuration file, and the configuration release history table config_release to record the release history of each namespace.
[0265] The above are only preferred specific embodiments of the present invention, but the scope of protection of the present invention is not limited thereto. Any technician familiar with the technical field can make equivalent replacements or changes based on the technical solutions and inventive concepts of the present invention within the technical scope disclosed in the present invention, and they should be covered by the scope of protection of the present invention.
Claims
1. A multi-level configuration management method, characterized in that: The specific steps are as follows: Step S1: storing configuration items; Step S1-1: storing XML nodes; Step S1-1-1: Build configuration name; Insert an array symbol in the configuration name, and selectively add % or an array symbol [n] to the configuration item name to record the hierarchical relationship according to the configuration item type; When the configuration item type is an XML attribute, insert a % sign in the configuration name; When the configuration item type is an XML node, the array symbol [n] needs to be concatenated; For XML root node: the configuration name is the XML node name; For XML non-root nodes: the configuration name is the value of the concatenation of the configuration item name of the upper-level XML node and the current XML node name [n], where n is an integer, starting from 0, recording the number of child nodes of the upper-level node that the current node is. For XML attributes: the configuration name is the value of the configuration item name of the XML node to which it belongs, concatenated with % and the current attribute name; Step S1-1-2: construct configuration item value; Store the values of XML nodes and XML attributes; For an XML node with child nodes: the value of the configuration item is empty; For an XML node without child nodes: the value of the configuration item is the value of the XML node; For XML attributes: the value of the configuration item is the value of the XML attribute; Step S1-1-3: Add a type attribute to mark the configuration type; Type attributes include: element is represented as an XML node, attribute is represented as an XML attribute; Step S1-1-4: The XML format configuration file is: <root><serverid=”1”> <ip> 127.0.0.1< / ip> <serverid=”2”> <ip> 127.0.0.2< / ip> < / root> ; Among them, root is the root node, the configuration item name is root, and the value is empty; server is the first child node of root, the configuration item name is root[0]server, and the value is empty; id is the attribute of server, the configuration item name is root[0]server%id, and the value is 1; ip is the first child node of server, the configuration item name is root[0]server[0]ip, and the value is 127.0.0.1; server is the second child node of root, the configuration item name is root[1]server, and the value is empty; id is the attribute of server, the configuration item name is root[1]server%id, and the value is 2; ip is the first child node of server, the configuration item name is root[0]server[1]ip, and the value is 127.0.0.2; The modified configuration file is expressed as: Configuration name: server; Configuration value: empty; Configuration item type: element; Configuration name: server[0]ip; Configuration value: 127.0.0.1; Configuration item type: element; Step S1-2: Store JSON key-value pairs; Step S1-2-1: Build configuration name; According to the configuration item type, selectively add % or array symbol [n] to the configuration item name to record the hierarchical relationship; The selectivity is determined by the configuration item type of the upper element: The upper-level element type is an object, and the % symbol is inserted into the configuration name to indicate that the current element is a property of the object; The upper-level element type is an array, and [n] is inserted in the configuration name, indicating that the current element is the nth child element of the array; For elements in an array whose upper-layer element type is an element, the configuration name is the value of the name of the upper-layer element configuration item concatenated with [n], where n is an integer, starting from 0, and records the index of the current element in the array; If the element type is object or array, the value of the configuration item is empty, otherwise the value of the configuration item is the value of the element; Step S1-2-2: Add a type attribute to mark the type of configuration; Type attributes include: object represents a JSON object, array represents an array in JSON, string represents a string in JSON, number represents a number in JSON, and bool represents a Boolean type in JSON; Step S1-2-3: The configuration file in JSON format {"server":{"ip":"127.0.0.1","port":[8080]}} is transformed into the following: Configuration name: server; Configuration value: empty; Configuration item type: object; Configuration name: server%ip; Configuration value: 127.0.0.1; Configuration item type: string; Configuration name: server%port; Configuration value: empty; Configuration item type: array; Configuration name: server%port[0]; Configuration value: 8080; Configuration item type: number; Step S2: construct the configuration item table config_item; Step S2-1: define a table named configuration item and store it in a relational database. The contents of the table include: field name, field name type, and field name description; Field names include: id, namespace_id, key, value, type, line_number, comment, is_deleted, created_at, updated_at, created_user, updated_user; Field name types include: number, string, date; Field name descriptions include: auto-increment primary key, configuration namespace id, configuration name, configuration value, configuration item type, arrangement order when displayed on the configuration center interface, configuration item introduction, whether it has been deleted (1 for deleted and 0 for not deleted), creation date, update date, creation user name, and update user name; Step S3: configure the namespace; Step S3-1: The configuration namespace consists of multiple configuration items, including the namespace name and type. A configuration namespace table named config_namespace is defined and stored in a relational database. The contents of the table include: field name, field name type, and field name description. Field names include: id, env_id, namespace_name, comment, is_deleted, created_at, updated_at, created_user, updated_user, type; Field name types include: number, string, date; Field name descriptions include: auto-increment primary key, configuration scheme id, configuration namespace name, configuration namespace introduction, configuration scheme deletion status, i.e. 1 for deleted and 0 for not deleted, configuration scheme creation date, configuration scheme update date, configuration scheme creation user name, configuration scheme update user name, configuration scheme type: json represents json file, xml represents xml file, kv represents non-hierarchical file; Based on the above method, the following functions are provided: F1: Add, delete, and modify configuration items; The configuration item is associated with the namespace primary key through the namespace_id field, which enables the addition, deletion, modification and query of various types of configuration item entities under the specified namespace; F1-1: Add a configuration to the namespace; F1-1-1: Clarify the basic information of the target namespace, the configuration to be added, and its upper-layer configuration; Target namespace information: obtained by querying the namespace table through SQL; The basic information of the configuration item to be added includes: the configuration name, configuration value and type of the new configuration item; Upper-level configuration items: There is a hierarchical relationship between the new configuration items and the existing upper-level configuration items. The information of the upper-level configuration items, namely the configuration name and hierarchical structure, is also a known prerequisite. The configuration item table is located by querying SQL; F1-1-2: Refer to the configuration item type of the upper-level configuration, concatenate the name of the new configuration with the name of the upper-level configuration, and store the basic information of the configuration item to be added and the primary key of the target namespace into the config_item table to complete the configuration modification; F1-2: Change the is_deleted field value in the configuration to be deleted to 1, and then delete the configuration; F2: Import configuration files; F2-1: JSON type file import; F2-1-1: Get the file name, file type, operation time, and operation user information during import, which correspond to the namespace_name, type, created_at, and created_user fields in the config_namespace table, and record the namespace primary key returned by the database; F2-1-2: Create an empty root node as the ancestor of all configuration items; F2-1-3: Read the JSON file content into memory, load the JSON file content into the program, convert the read JSON string into the map type in Go, and use the json.Unmarshal method to parse the JSON data into the map[string]interface{} type. Each attribute of the JSON will be mapped to a key in the map, that is, a string, and the corresponding value can be of any type; F2-1-4: Traverse the first layer of the map structure, extracting each key and value in turn during the traversal: During the traversal process, a key and value will be obtained in each loop, and in the Go language, the forrange statement is used to access each pair of keys and values in the map; Get the key and value of the first-layer element, use the element key as the name of the configuration, and obtain the type of the element value through reflection. If the element value type is an object or array, the configuration value is empty, otherwise the configuration value is the element value itself, and use the root node as the upper node to store the new configuration in the same way as step F1. If the element value type is an object or array, use the current configuration as the upper node and the element value as the new JSON. Repeat F2-1-3 and F2-1-4 until all elements are traversed; F2-2: XML type file import; F2-2-1: Get the file name, file type, operation time, and operation user information during import, which correspond to the namespace_name, type, created_at, and created_user fields in the config_namespace table, and record the namespace primary key returned by the database. F2-2-2: Use the XML open source library etree to read the file content into memory according to the DOM tree data structure to obtain the XML root node; F2-2-3: Use the root node tag name as the name of the configuration, use the root node value as the configuration value, if the node is the root node, the upper node is empty, add the new configuration to the library in the same way as step F1, traverse all the attributes of the node, use the attribute name as the name of the configuration, use the attribute value as the configuration value, and use the node as the upper node, add the new configuration to the library in the same way as step F1, use the node as the upper node, traverse all the directly subordinate nodes of the node, and repeat the operation of step F2-2-3 until all XML nodes are traversed; F3: Configuration release; The configuration release table config_release records the latest status of each configuration namespace after release; F3-1: Perform configuration publishing steps for the specified namespace. The specific steps are as follows: F3-1-1: Get all configuration items through the specified namespace primary key; F3-1-2: Filter configuration items whose field name is_deleted is 1; F3-1-3: Serialize the remaining configuration items into JSON strings. Use the function of serializing data into JSON strings provided by the Go language standard library encoding / json, and use the json.Marshal() function to perform this conversion. F3-1-4: By specifying the namespace primary key, all past configuration release history is set to abandoned, that is, is_abandon is updated to 1; F3-1-5: Integrate the submitted namespace primary key, release name, submission time and JSON string, and insert them into the config_release table; F4: Configuration rollback; F4-1: The configuration release table config_release records all release history of the namespace. The configuration can be rolled back by the following operations: F4-1-1: By using the specified namespace primary key, all matched configuration release histories are set to be abandoned, that is, is_abandon is updated to 1, and is_abandon of the specified release version record is updated to 0; F5: Displays the configuration status changes in the specified configuration namespace; F5-1: The configuration item table config_item records all configuration items under the specified namespace, including newly added, modified, and deleted configuration items. The configuration release table config_release records the configuration items in the namespace being released. By comparing the data in the two tables, calculate which configurations are added, modified, or deleted. The specific steps are as follows: F5-1-1: By specifying the namespace primary key, configure the release table config_release to obtain the release record in the process of being released with is_abandon=0; F5-1-2: Deserialize the items field in the release record and load it into memory, which is all the configuration items currently released, defined as the array variable releaseItems; F5-1-3: Get the latest configuration item from the configuration item table config_item by specifying the namespace primary key, and define it as the array variable currentItems; F5-1-4: Define the data structure of the configuration tree, a structure containing the current configuration and a set of sub-configurations; F5-1-5: Generate the configuration tree of currentItems; Assume that all elements in the array variable currentItems are of the same level. Generate a configuration tree set by traversing the array variable currentItems and creating a new configuration tree node for each element, defined as the array variable treeItems. The current configuration of all elements in the array variable treeItems is the element in currentItems, and the sub-configurations are all empty. F5-1-6: Generate a hash key using the configuration name and configuration item type of each element in the array variable treeItems, and use the element itself as the hash value to generate a hash table treeItemsMap; F5-1-7: Traverse the elements of the array variable treeItems. The hierarchical relationship is recorded in the configuration name. The upper-level configuration name and type are found through the configuration name and type of the current element, and the upper-level configuration item hash key pk is generated; F5-1-8: If pk exists in the hash table treeItemsMap, since treeItemsMap is a hash table and pk is a hash key, the corresponding upper-level configuration item in the hash table can be quickly located according to pk, and the current configuration is added to the sub-configuration of the upper-level configuration, and this configuration is removed from the array variable treeItems; if pk does not exist, continue traversing; F5-1-9: After the traversal is completed, the element retained in the array variable treeItems is the vertex of the configuration tree. The configuration tree of the array variable currentsItem is traversed from the root node. If the element does not exist in the array variable releaseItems, it is marked as a newly added element. If both exist but the values are different, it is marked as a modified element. The array variable releaseItems is traversed. If the element does not exist in the array variable currentsItem, it is marked as a deleted element. F6: Provides configuration for application services; F6-1: Provide XML configuration; F6-1-1: By specifying the namespace primary key, obtain the release record that is in the process of being released, that is, is_abandon = 0, from the configuration release table config_release; F6-1-2: Deserialize the items field in the release record and load it into memory, which is all the configuration items currently released, defined as the array variable releaseItems; F6-1-3: Define the data structure of the configuration tree and generate the releaseItems configuration tree according to step F5-1-4; F6-1-4: Select the root node in the releaseItems configuration tree as the input parameter and perform the following recursive operations: Get the current configuration and sub-configuration in the root node. If the current configuration type is element, create an XML node. Use the open source library etree to define the XML node. The variable name is pe and the type is etree.Document. Traverse each element in the sub-configuration collection. If the sub-configuration item type is attribute, call the pe.CreateAttr method to add the sub-configuration name and configuration value as XML attributes to the pe node. If the sub-configuration item type is element, use the sub-configuration as an input parameter to repeat the steps in step F6-1-4 for the current configuration item type of element, get the return value ce, and call the pe.AddChild method to add ce to the child node of pe. Return the node pe, and finally call etree.NewDocumentWithRoot with pe as the root node to generate the XML document variable d, and call the WriteToString method of d to generate the XML text. F6-2: Provide JSON configuration; F6-2-1: By specifying the namespace primary key, obtain the release record in the release process with is_abandon=0 from the configuration release table config_release; F6-2-2: Deserialize the items field in the release record and load it into memory, which is all the configuration items currently released, defined as the array variable releaseItems F6-2-3: Define the data structure of the configuration tree and generate the releaseItems configuration tree according to step F5-1-4; F6-2-4: Select the root node in the releaseItems configuration tree as the input parameter and perform the following recursive operations: Get the current configuration and sub-configuration in the node. If the length of the sub-configuration collection is empty, return the configuration value. If the type of the current configuration is object, create a hash pm. If the type is arrary, create a slice ps. Iterate through each element in the sub-configuration collection, call recursively, repeat the F6-2-4 steps, and define the return value as cm. Add cm to pm or ps, return pm or ps, and serialize pm or ps into JSON text. F7: Convert the latest configuration status to the original configuration file to provide configuration services for application services; F7-1: Switching the configuration scheme realizes the switching of the application service configuration. The table used to record the configuration scheme is the configuration scheme table config_env, which includes: field name, field name type, and field name description; Field names include: id, env_name, comment, is_used, is_deleted, created_at, updated_at, created_user, updated_user; Field name types include: number, string, date; Field name descriptions include: auto-increment primary key, configuration plan name, configuration plan introduction, configuration plan activation status (1 means enabled, 0 means not enabled), configuration plan deletion status (1 means deleted, 0 means not deleted), configuration plan creation date, configuration plan update date, configuration plan creation user name, configuration plan update user name; F7-2: Enable the specified configuration scheme; F7-2-1: All configuration schemes are set to disabled, that is, is_used is updated to 0; F7-2-2: Update is_used of the specified configuration scheme to 1; F7-2-3: Get all namespaces under the specified configuration scheme primary key F7-2-4: Provide configuration services to external parties according to step F6.
2. The multi-level configuration management method according to claim 1, characterized in that: Array symbols include: n, where n is a number.
3. The multi-level configuration management method according to claim 1, characterized in that: Hierarchical relationships include: sequential relationships.
4. The multi-level configuration management method according to claim 1, characterized in that: The first-level elements refer to the outermost key-value pairs in the JSON file.