A method and device for discovering resource relationships in a graph database
By updating resource nodes and intermediate node information in the graph database, and retrieving and updating query conditions according to the rule type, the real-time and accuracy problems of resource relationship discovery in the graph database are solved, and the maintenance of the configuration management database system is simplified.
Patent Information
- Application Number
- CN202311244459.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-25
- Publication Date
- 2025-08-08
- Estimated Expiration
- 2043-09-25
AI Technical Summary
The existing technology lacks real-time discovery scheme for resource relationships in graph databases, resulting in inaccurate query results after resource relationship changes, and the integrated relationship discovery software in the configuration management database system increases system complexity.
By updating the changing resource nodes and intermediate resource node information in the graph database, searching and updating query conditions according to the rule type, obtaining and supplementing resource relationships, ensuring the accuracy and real-timeness of the query, avoiding additional integrated software.
Real-time accurate query of resource relationships in graph databases, simplifies the maintenance of configuration management database systems, and reduces system complexity.
Smart Images

Figure CN117290550B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a method and device for discovering resource relationships in a graph database. Background Art
[0002] A graph database is a new type of database based on graph theory. Its data storage structure and data query methods are both based on graph theory. In graph theory, the basic elements of a graph are nodes and edges. In a graph database, these correspond to resource nodes (also called resource instances) and the resource relationships between two resource nodes. Two resource nodes and the resource relationships between them form a path, and resource relationships can also be viewed as edges connecting two resource nodes.
[0003] To facilitate the management of resource relationships within graph databases, resource relationship discovery within the graph database is necessary. In a CMDB system, key management areas include resource instances and the relationships between them. Resource relationship discovery involves discovering the relationships between these resource instances so that they can be incorporated into the CMDB for management. Due to the large number of resource relationships, complex connections, and variability, resource relationship discovery becomes a management challenge for CMDB systems. Currently, resource relationship discovery schemes in graph databases first collect basic information about resource nodes, analyze this basic information, and then calculate the resource relationships between resource nodes to discover the resource relationships. The discovered resource relationships are then stored. However, the resource relationships discovered in this method only represent the connectivity between resource nodes at the time the resource relationships were calculated. This resource relationship discovery scheme is not real-time, and changes in resource relationships may result in incorrect resource relationships subsequently queried in the graph database. Summary of the Invention
[0004] The present application provides a method and device for discovering resource relationships in a graph database, which can support the synchronization of queried resource relationships with resource relationships in the graph database, ensuring the accuracy and real-time nature of the queried resource relationships.
[0005] In a first aspect, a method for discovering resource relationships in a graph database is provided, the method comprising:
[0006] When a resource relationship in the graph database changes, updating the changed first resource node and the first intermediate resource node information associated with the first resource node in the graph database;
[0007] Obtaining a first query condition related to the first resource node, and if the first query condition includes a first relationship type, searching at least one rule according to the first relationship type;
[0008] If a target rule is retrieved according to the first relationship type, the first query condition is updated to a second query condition according to the target rule, wherein the target rule includes a first rule, the first rule is used to associate the first relationship type, the types of two resource nodes located at both ends of the first path, and the intermediate information of the first path, the two resource nodes include a first resource node, the first intermediate resource node is located between the two resource nodes, the first relationship type is used to identify a first resource relationship, the first resource relationship is a resource relationship between the two resource nodes, the intermediate information includes the type of the first intermediate resource node, or the intermediate information includes the type of each resource node in the first path and the resource relationship between each two adjacent resource nodes;
[0009] Performing a query in the graph database according to the second query condition to obtain a first target path that meets the query condition, where the first target path includes a first resource node at one end, a first intermediate resource node, and a second resource node at the other end;
[0010] A first resource relationship is added between the first resource node and the second resource node at both ends of the first target path, and the added first target path is sent.
[0011] In a feasible design, sending the supplemented first target path includes:
[0012] Storing the supplemented first target path in the cache;
[0013] Send the supplemented first target path;
[0014] The first target path in the cache is deleted, so that in the next calculation process of the resource relationship associated with the first resource node, the resource relationship associated with the first resource node is recalculated to obtain the latest first target path.
[0015] In one possible design, before sending the supplemented first target path, the method further includes:
[0016] The resource nodes other than the first resource node and the second resource node at both ends of the first target path are deleted, and the resource relationships other than the first resource relationship are deleted.
[0017] In a feasible design, if the number of rules included in the target rule is equal to 1, the first query condition is updated to the second query condition according to the target rule, including:
[0018] Delete the first relationship type in the first query condition;
[0019] The types of the two resource nodes located at both ends of the first path in the target rule and the intermediate information of the first path are added to the first query condition to generate a second query condition.
[0020] In a feasible design, if the number of rules included in the target rule is greater than 1, the first query condition is updated to the second query condition according to the target rule, including:
[0021] Deleting the first relationship type associated with each rule;
[0022] Use the OR logical relationship to splice each rule that has been deleted to update the target rule;
[0023] Delete the first relationship type in the first query condition;
[0024] The updated target rule is added to the first query condition to generate a second query condition.
[0025] In a feasible design, if the first query condition does not include any relationship type, the method further includes:
[0026] Query the graph database according to the first query condition to obtain a second target path;
[0027] Send the second target path.
[0028] In a feasible design, if no rule is retrieved according to the first relationship type, the method further includes:
[0029] Sending first indication information, where the first indication information is used to indicate that content of the first query condition is incorrect.
[0030] In a feasible design, when a resource relationship in a graph database changes, updating the changed first resource node and the first intermediate resource node information associated with the first resource node in the graph database includes:
[0031] When a resource node is newly added, a newly added first resource node is created according to the structure of the resource model, an association relationship is created with a first intermediate resource node associated with the first resource node, and resource node information corresponding to the first resource node is created, including the type of the resource node, the attributes of the resource node, the type of the intermediate resource node associated with the resource node, and the resource relationship between the resource node and the intermediate resource node, wherein the starting resource node or the ending resource node in the association path of one or more intermediate resource nodes is the first resource node; or;
[0032] When the resource relationship of a resource node changes, the changed first resource node and the association relationship with the associated first intermediate resource node are updated, and the type of the resource node corresponding to the first resource node, the attributes of the resource node, the type of the intermediate resource node associated with the resource node, and the resource relationship between the resource node and the intermediate resource node are updated accordingly.
[0033] In one possible design, the method further includes:
[0034] Add nodes that can act as resource connection intermediaries in the resource model as intermediate resource nodes;
[0035] According to the structure of the resource model, each resource node is created, an association relationship between each resource node and an associated intermediate resource node is created, and resource node information corresponding to each resource node is created.
[0036] In a second aspect, a device for discovering resource relationships in a graph database is provided, the device comprising:
[0037] A resource node construction module is used to update the changed first resource node and the first intermediate resource node information associated with the first resource node in the graph database when the resource relationship in the graph database changes;
[0038] a resource relationship discovery module, configured to obtain a first query condition related to a first resource node, and if the first query condition includes a first relationship type, search at least one rule according to the first relationship type;
[0039] The resource relationship discovery module is further configured to, if a target rule is retrieved according to the first relationship type, update the first query condition to a second query condition according to the target rule, wherein the target rule includes a first rule, the first rule is used to associate the first relationship type, the types of two resource nodes located at both ends of the first path, and the intermediate information of the first path, the two resource nodes include a first resource node, the first intermediate resource node is located between the two resource nodes, the first relationship type is used to identify the first resource relationship, the first resource relationship is a resource relationship between the two resource nodes, the intermediate information includes the type of the first intermediate resource node, or the intermediate information includes the type of each resource node in the first path, and the resource relationship between each two adjacent resource nodes;
[0040] The resource relationship discovery module is further configured to query the graph database according to the second query condition to obtain a first target path that satisfies the query condition, a first resource node at one end, a first intermediate resource node, and a second resource node at the other end;
[0041] The resource relationship discovery module is further configured to supplement the first resource relationship between two resource nodes at both ends of the first target path and send the supplemented first target path.
[0042] In the current resource relationship discovery method, after completing resource relationship discovery and storing resource relationships, the resource relationships cannot be updated. If new resource nodes and resource relationships corresponding to the resource nodes are added to the graph database later, the stored resource relationships will be inconsistent with the actual resource relationships, which may cause subsequent users to query the resource relationships in the graph database to be incorrect.
[0043] In the above-described embodiment of the present application, after the first resource node is added to the graph database, the first resource relationship corresponding to the first resource node can be discovered using rules. First, a first query condition is obtained. If the first query condition includes a first relationship type and a target rule is retrieved based on the first relationship type, the first query condition is updated to a second query condition based on the target rule. The target rule includes a first rule that associates the first relationship type, the types of the two resource nodes at both ends of the first path, and the intermediate information of the first path. The two resource nodes include the first resource node, and the first intermediate resource node is located between the two resource nodes. The first relationship type is used to identify the first resource relationship. The first resource relationship is a resource relationship between two resource nodes. The intermediate information includes the type of the first intermediate resource node, or the intermediate information includes the types of each resource node in the first path and the resource relationship between each adjacent two resource nodes, which is a basic resource relationship. Therefore, the updated second query condition can include various information about the path corresponding to the first resource relationship to be discovered. Since the first resource relationship corresponding to the first relationship type to be discovered is not a basic resource relationship, the intermediate information of the path in the second query condition helps the graph database query the path consisting of the basic resource relationships equivalent to the first resource relationship. The path includes a first target path, which includes a newly added first resource node and a first intermediate resource node. Then, the first resource relationship is added to the first target path, thereby completing the discovery of the resource relationship of the newly added resource node or the changed resource node.
[0044] In the above method, since the intermediate information is defined based on the basic resource relationship between two adjacent resource nodes, and the resource nodes in the graph database are stored based on the basic resource relationship. Therefore. When the resource nodes or resource relationships in the graph database change, when the resource relationships in the graph database are queried again, this solution will calculate based on the changed basic resource relationships and generate the latest first resource relationship corresponding to the first relationship type. Therefore, this application can support the synchronization of the queried first resource relationship with the basic resource relationship in the graph database, ensuring the accuracy and real-time nature of the queried first resource relationship.
[0045] Furthermore, in the above example of this application, by defining rules, the information in the retrieved target rule is added to the original first query condition to generate a second query condition. Since the second query condition differs from the first query condition only in content and not in form, the original query method in the graph database can be used, with minimal impact on the original query method.
[0046] Graph databases are currently commonly used in Configuration Management Database (CMDB) systems. Discovering resource relationships within a graph database using a CMDB system typically involves using established resource relationship discovery software, such as Application Performance Management (APM). However, this approach requires integrating the corresponding software or modules within the CMDB system, making the CMDB system bulky and complex, inconvenient to maintain, and increasing the difficulty of promoting its widespread use.
[0047] The method of the above solution of the present application can be integrated into the CMDB system without the need to integrate other relationship discovery software. The solution of the present application only collects basic resource relationship data in a simple way, thereby adding new resource nodes to the graph database. Simple methods include manual maintenance, resource management input, or basic collection script discovery. The embodiments of the present application do not require the integration of corresponding software or modules in the CMDB system. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] In order to more clearly illustrate the technical solution of the present application, the following is a brief introduction to the drawings required for use in the embodiments. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0049] Figure 1 This is a schematic diagram of an application scenario of a method for discovering resource relationships in a graph database provided by an exemplary embodiment of the present application;
[0050] Figure 2 This is a schematic flow chart of a method for discovering resource relationships in a graph database provided by an exemplary embodiment of the present application;
[0051] Figure 3 This is a schematic diagram of resource nodes and resource relationships in a graph database provided by an exemplary embodiment of the present application;
[0052] Figure 4 This is a schematic diagram of resource nodes and resource relationships in another example of a graph database provided by an exemplary embodiment of the present application;
[0053] Figure 5 This is a schematic diagram of resource nodes and resource relationships in another example of a graph database provided by an exemplary embodiment of the present application;
[0054] Figure 6 This is a schematic diagram of a device for discovering resource relationships in a graph database provided by an exemplary embodiment of the present application. DETAILED DESCRIPTION
[0055] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0056] Figure 1 This is a schematic diagram of an application scenario of a method for discovering resource relationships in a graph database provided by an exemplary embodiment of the present application. For example, Figure 1 As shown, server 120 deploys a Configuration Management Database (CMDB) system, which uses a graph database to store resource nodes and the resource relationships between them. Terminal 110 sends a resource relationship query request to the CMDB system, and the CMDB system provides terminal 110 with services such as querying and discovering resource relationships in the graph database.
[0057] Figure 2 This is a schematic flow chart of a method for discovering resource relationships in a graph database provided by an exemplary embodiment of the present application. The method can be applied to electronic devices (such as servers, etc.). Figure 2 As shown, the method includes the following steps:
[0058] S210 , when a resource relationship in a graph database changes, updating the changed first resource node and information of a first intermediate resource node associated with the first resource node in the graph database.
[0059] Specifically, data from the first resource node can be collected through data acquisition and updated accordingly in the graph database resources. Alternatively, resource nodes can be manually created or modified in the graph database. For example, the collected server data includes the server's Internet Protocol (IP) address. The first resource node is constructed based on the collected data from the first resource node.
[0060] In a feasible design, adding a new first resource node to the graph database based on the collected data of the first resource node is achieved by the following method:
[0061] Based on the collected data of the first resource node and the content of the resource model structure definition, the first resource node is added or changed in the graph database. When the resource relationship in the graph database changes, the changed first resource node and the first intermediate resource node information associated with the first resource node are updated in the graph database, including:
[0062] When a resource node is newly added, a newly added first resource node is created according to the structure of the resource model, an association relationship is created with a first intermediate resource node associated with the first resource node, and resource node information corresponding to the first resource node is created, including the type of the resource node, the attributes of the resource node, the type of the intermediate resource node associated with the resource node, and the resource relationship between the resource node and the intermediate resource node, wherein the starting resource node or the ending resource node in the association path of one or more intermediate resource nodes is the first resource node; or;
[0063] When the resource relationship of a resource node changes, the changed first resource node and the association relationship with the associated first intermediate resource node are updated, and the type of the resource node corresponding to the first resource node, the attributes of the resource node, the type of the intermediate resource node associated with the resource node, and the resource relationship between the resource node and the intermediate resource node are updated accordingly.
[0064] Exemplarily, the content of the resource model structure definition includes one or more of the following information:
[0065] The type of the target resource node, the attributes of the target resource node, the types of the intermediate resource nodes associated with the target resource node, and the resource relationship between the target resource node and the intermediate resource nodes, where the intermediate resource node is used to associate the starting resource node and the ending resource node in the path, and the target resource node is the starting resource node or the ending resource node.
[0066] The type of the resource node includes, but is not limited to, one or more of the following types: port type, switch type, server type, and link type.
[0067] In this embodiment, before the above steps, the method also includes: adding a node that can serve as a resource connection intermediary in the resource model as an intermediate resource node; creating each resource node according to the structure of the resource model, creating an association relationship between each resource node and the associated intermediate resource node, and creating resource node information corresponding to each resource node.
[0068] Designing a middleman node as an intermediate resource node in the model specifically includes: adding a node in the resource model that can serve as a resource connection middleman, such as IP resources, port resources, link resources, etc. When defining a common resource model, it is necessary to define the relationship between the common model and these middleman resources. For example, when defining a server type model, the IP attribute of the server must be defined as a reference type, and a resource instance of the IP type must be referenced. When generating a server instance, first check whether the corresponding IP instance already exists. If so, assign a value to the IP field of this server instance and create a relationship between the server instance and the IP instance; if the IP instance does not exist, first create this IP instance, then assign the IP to the IP field of this server instance and create a relationship between the server instance and the IP instance. When a resource instance has a relationship with multiple middlemen, a relationship is created between the resource instance and each node of these middlemen. The type of the intermediate resource node can be IP, port or link, or other types, which are not limited in this application. The first intermediate resource node can be understood as a certain intermediate resource node.
[0069] It should be noted that the present application associates the starting resource node and the ending resource node of the path through one or more intermediate resource nodes, so that the subsequent use of rules can convert each intermediate resource node into a resource relationship between the starting resource node and the ending resource node, thereby completing the discovery of the resource relationship corresponding to the starting resource node or the ending resource node. The types of intermediate resource nodes newly proposed in this application also need to be defined in the resource model. In this application, the types of intermediate resource nodes include not only the types of resource nodes defined in the existing resource model, but also IP types and other types that are not defined as resource nodes in the existing resource model. The resource nodes defined in the existing resource model are all devices with entities, while the types of intermediate resource nodes defined in this application are not limited to devices with entities, and can also be network nodes without entities, such as IPs, etc., which can be defined as needed.
[0070] The attributes of a resource node are characteristics determined by the type of the resource node. For example, the attributes of a switch-type resource may include: Media Access Control (MAC) address, manufacturer, device model, hardware identifier, serial number, IP address, purchase date, and person in charge.
[0071] The resource relationships between the target resource node and each intermediate resource node include, for example, the parent-child relationship between network devices and network interfaces, the parent-child relationship between Windows operating systems and file systems, the ownership relationship between virtual machines and corresponding physical machines, the connection relationship between servers and network devices, and the reference relationship between servers and IP resource nodes.
[0072] A resource node is a specific entity defined by the resource type defined in a resource model. For example, [192.168.172.118] is an instance of a resource node in a resource model of type [IP], and [Server A of a certain enterprise] is an instance of a resource model of type [Server]. In a graph database, resource nodes are stored as resource node instances, and the relationship between two resource nodes is a resource relationship. For simplicity, this application will refer to resource nodes as instances.
[0073] Reference type: A logical concept within the attributes of a resource node in a resource model. A resource node's reference type indicates that the current resource node references another resource node. In implementation, this attribute records the instance identifier of the referenced object and establishes a relationship between the current instance and the referenced instance.
[0074] The resource nodes stored in the graph database and the resource relationships between resource nodes are all created based on the content defined in the resource model. For example, when defining a server-type resource model (referred to as the server model for short), the IP attribute of the server model needs to be defined as a reference type, and the resource node of the IP type needs to be referenced. When generating a server instance, first check whether the corresponding IP instance already exists in the graph database. If so, assign a value to the IP field of this server instance and create a resource relationship between the server instance and the IP instance; if the IP instance does not exist in the graph database, first create this IP instance, then assign the IP to the IP field of this server instance, and create a resource relationship between the server instance and this IP instance.
[0075] The following combination Figure 3 Introduce the intermediate resource nodes:
[0076] like Figure 3 As shown, the first path (including resource node A, the first resource relationship, and resource node B) and the second path (including resource node A, resource relationship a, resource node C, resource relationship b, and resource node B) are both used to connect resource node A and resource node B. Resource node C is an intermediate resource node and is associated with both resource node A and resource node B.
[0077] It can be seen that the first and second paths are equivalent. The first resource relationship of the second path implicitly includes all resource relationships of the first path. This can also be understood as the first resource relationship generalizing resource relationships a and b in the first path. In other words, the first and second paths are actually both part of the third path. Each intermediate resource node acts as a "middleman" connecting the two resource nodes at either end of the path.
[0078] This application associates the two resource nodes at both ends of the path through the intermediate resource node, and calculates the resource relationship between the two resource nodes at both ends of the path through rules. Based on this, this application exemplifies the following method of defining rules:
[0079] Define a rule as a 4-tuple:
[0080] (1) Relation Type, denoted as RT;
[0081] (2) Start resource node type (Start Type), denoted as ST;
[0082] (3) Intermediary resource node type, or the type of each resource node in the path and the resource relationship between two adjacent resource nodes (also known as connection order), denoted as I;
[0083] (4) End resource node type (End Type), denoted as ET.
[0084] The relationship type identifies the resource relationship between the starting resource node and the ending resource node. The starting resource node and the ending resource node are located at the ends of the path. The intermediate resource node is used to associate the starting resource node and the ending resource node.
[0085] Relationship types include parent-child, reference, deployed on, connected, managed, virtualized, or owned. For example, the relationship type between a server instance and an Internet Protocol (IP) instance is "reference," the relationship type between a database instance and a server instance is "deployed on," the relationship type between an operating system instance and a file system instance is "parent-child," and the relationship type between a network device instance and a network interface instance is "parent-child." Other relationship types are not described in detail in this application.
[0086] It should be understood that because the types of intermediate resource nodes in this application are richer than those defined in existing resource models, the types of relationships between resource nodes in this application are also richer than those in existing resource models, such as "reference," "belongs to," and "manage." Relationship types can also be designed based on actual needs.
[0087] For example, when the rule includes the intermediate resource node type, taking the type as IP, the rule can be:
[0088] RULE(deployed on, [database], [IP], [server]). This rule indicates that a database-type resource node is connected to a server-type resource node by referencing an IP resource node. This is equivalent to a resource relationship in which a database-type resource node is deployed on a server-type resource node.
[0089] When the rule includes the type and connection order of each resource node, taking the path {(Type [Department])-[Management]->(Type [Business System])<-[Attribution]-(Type [Application Service])} as an example, the rule is:
[0090] RULE(Management, Type [Person in Charge], {(Type [Department])-[Management]->(Type [Business System])<-[Attribution]-(Type [Application Service])}, Type [Server]).
[0091] It should be noted that when a path includes multiple intermediate resource nodes, the portion marked "I" in the rule refers to the type of each resource node in the path and the resource relationship between two adjacent resource nodes. When a path includes one intermediate resource node, the portion marked "I" in the rule can be the resource node type, or the type of each resource node in the path and the resource relationship between two adjacent resource nodes.
[0092] For example, a list of at least one rule is defined as a rule set, and the rule set can be identified as: List<RULE(RT,ST,I,ET)> .
[0093] It can be seen that the rules defined in the above example associate the relationship type, starting node type, ending node type, and intermediate resource node (intermediary) type of the first resource relationship or the type and connection order of each resource node in the path, so that when the resource relationship is subsequently queried according to the first query condition and the first query condition includes the first relationship type, the path equivalent to the first resource relationship corresponding to the first relationship type can be calculated according to the rules.
[0094] Based on the above rule definition method, if a rule uses n intermediate resource node types, all of these intermediate resource node types must be included in the resource model's resource node type definition. In other words, when defining a common resource model, you must define the resource relationship between the common model and these intermediate resource nodes. If a resource instance has relationships with multiple intermediate resource nodes, you must create a corresponding resource relationship between the resource instance and each of these intermediate resource nodes.
[0095] Based on this, the types of resource nodes and the relationships between resource nodes in the created graph database can match at least one rule, so that resource relationships in the graph database can be subsequently queried and discovered according to the at least one rule.
[0096] In a feasible design, the present application also provides an example of a method for determining at least one rule: determining at least one rule according to user needs.
[0097] For example, for a resource manager, the resource manager's need is to focus on the management relationship between personnel and resources. Based on this, the rule can be defined as RULE (management, ....), that is, the rule is defined to associate the relationship type "management" with a path equivalent to the path of the corresponding resource relationship.
[0098] For another example, system operation and maintenance personnel need to pay attention to the deployment relationship of the database. They can define a rule RULE (deployed on, ...), that is, define a rule for associating the relationship type "deployed on" with a path equivalent to the path of the corresponding resource relationship.
[0099] S220: Acquire a first query condition related to the first resource node. If the first query condition includes a first relationship type, search in at least one rule according to the first relationship type.
[0100] Among them, the first query condition is used to query the resource relationship in the graph database, and the first relationship type is a certain relationship type.
[0101] Exemplarily, the first query condition includes at least one condition, and during the retrieval process of the target rule, the conditions in the first query condition are concatenated into a query statement character string.
[0102] In a feasible design, if the first query condition does not include any relationship type, the method further includes:
[0103] Query the graph database according to the first query condition to obtain a second target path;
[0104] Send the second target path.
[0105] That is, if the first query condition does not include any relationship type, the query is directly performed in the graph database according to the first query condition to obtain the second target path without performing the relationship discovery steps such as S130 to S150.
[0106] In a feasible design, if no rule is retrieved according to the first relationship type, the method further includes:
[0107] Sending first indication information, where the first indication information is used to indicate that content of the first query condition is incorrect.
[0108] In the above example, if no rule is retrieved according to the first relationship type, it means that the content of the first query condition is incorrect, and the first indication information is sent to the terminal 110 so that the terminal 110 can re-determine and re-send the first query condition.
[0109] S230: If a target rule is retrieved according to the first relationship type, the first query condition is updated to a second query condition according to the target rule.
[0110] The target rule includes at least one rule, each of which is used to associate a relationship type, the types of two resource nodes at both ends of a path, and intermediate information of the path. The path includes at least one intermediate resource node. The at least one intermediate resource node is used to associate the types of two resource nodes at both ends of the path. The relationship type is used to identify the resource relationship between the two resource nodes at both ends of the path. The intermediate information includes the type of the intermediate resource node, or the intermediate information includes the type of each resource node in the path and the resource relationship between each adjacent two resource nodes.
[0111] A first rule is included in the target rule. The first rule is used to associate a first relationship type, the types of two resource nodes located at both ends of a first path, and intermediate information of the first path. The two resource nodes include a first resource node, a first intermediate resource node is located between the two resource nodes, the first relationship type is used to identify a first resource relationship, the first resource relationship is a resource relationship between the two resource nodes, and the intermediate information includes the type of the first intermediate resource node, or the intermediate information includes the type of each resource node in the first path and the resource relationship between each two adjacent resource nodes.
[0112] The resource nodes at both ends of a path in different first rules may have different resource nodes other than the first resource node. That is, for a newly added first resource node, there may be one or more paths including the first resource relationship. The newly added first resource node may be the starting resource node or the ending resource node of the path. The path includes at least one intermediate resource node, and the at least one intermediate resource node includes the first intermediate resource node.
[0113] In a feasible design, if the target rule includes one rule, the first query condition is updated to the second query condition according to the target rule in the following manner:
[0114] Delete the first relationship type in the first query condition;
[0115] The types of the two resource nodes located at both ends of the first path in the target rule and the intermediate information of the first path are added to the first query condition to generate a second query condition.
[0116] The above example deletes the first relationship type in the first query condition so that the graph database can search based on the types of the two resource nodes at both ends of the first path and the intermediate information of the first path, thereby avoiding errors in querying the first target path due to the inability to identify the first relationship type in the graph database.
[0117] In a feasible design, if the target rule includes multiple rules, the first query condition is updated to the second query condition according to the target rule in the following manner:
[0118] Deleting the first relationship type associated with each rule;
[0119] Use the OR logical relationship to splice each rule that has been deleted to update the target rule;
[0120] Delete the first relationship type in the first query condition;
[0121] The updated target rule is added to the first query condition to generate a second query condition.
[0122] For example, the first target rule includes two rules: RULE1 (RT1, ST1, I1, ET1) and RULE2 (RT2, ST2, I2, ET2). "ST1, I1, ET1" in RULE1 and "ST2, I2, ET2" in RULE2 are connected using an OR relationship and added to the first query condition. The first relationship type in the first query condition is then deleted.
[0123] The above example connects the information of the first path of each rule using an “or relationship” so that a path that meets each rule can be searched in the graph database, thereby obtaining a complete query result.
[0124] S240: Query the graph database according to the second query condition to obtain a first target path that meets the query condition.
[0125] The first target path includes a first resource node and a first intermediate resource node. There may be multiple first target paths, which are all paths that meet the conditions and have a first resource relationship with the first resource node. The first intermediate resource nodes included in each first target path are one or more intermediate resource nodes associated with the first resource node. It should be understood that the first target path may also include other intermediate resource nodes. That is, the first resource node forms the first target path with the second resource node at the other end through multiple intermediate resource nodes.
[0126] Exemplarily, the first target path may be displayed to the user in the form of resource nodes and edges, thereby achieving a view query effect.
[0127] S250: Supplement a first resource relationship between two resource nodes at both ends of each path, and send the supplemented first target path.
[0128] In a feasible design, since the terminal 110 may only need to obtain the two resource nodes located at both ends and the first resource relationship between the two, and does not need other information in the path, before sending the supplemented first target path, the method further includes:
[0129] The resource nodes other than the first resource node and the second resource node at both ends of the first target path are deleted, and the resource relationships other than the first resource relationship are deleted.
[0130] In one possible design, the supplemented first target path is sent as follows:
[0131] Storing the supplemented first target path in the cache;
[0132] Send the supplemented first target path;
[0133] The first target path in the cache is deleted, so that in the next calculation process of the resource relationship associated with the first resource node, the resource relationship associated with the first resource node is recalculated to obtain the latest first target path.
[0134] In the above example, after sending the first target path to the terminal, the query result of the newly discovered first resource relationship for the first resource node is not persistently stored, so that the query result of the newly discovered first resource relationship for the first resource node is obtained through real-time calculation each time the resource relationship is queried, further improving the real-time performance of the query result.
[0135] As can be seen from the above example of the resource relationship discovery method, this application first defines the type of resource node that acts as a "middleman" in the resource model, and defines at least one rule based on the resource model. In the process of resource relationship query, the target rule is found through the first relationship type, and the path equivalent to the first resource relationship corresponding to the first relationship type in the graph database is queried through the "middleman" information in the target rule. Then, the first resource relationship is added to the queried path to complete the discovery of the first resource relationship.
[0136] For example, a first resource node of database type is added to the graph database, and the first resource node is associated with a first intermediate resource node of IP type, and the first intermediate resource node is associated with a second resource node of server type. In the process of resource relationship discovery, the target rule RULE searched for according to the first relationship type "deployed on" is (deployed on, [database], [IP], [server]). After adding the information other than the relationship type in the target rule to the first query condition, various paths in which the resource relationship between the database and the server is "deployed on" can be obtained. Then, at least one intermediate resource node in each path, and the resource relationship associated with each intermediate resource node, are replaced with the first resource relationship "deployed on". As shown Figure 4 As shown in the figure, a certain path A found includes database 01, IP [192.168.192.10] and server A, the resource relationship-association relationship between database 01 and IP [192.168.192.10], and the resource relationship-association relationship between server A and IP [192.168.192.10]. The intermediate resource node that acts as the "middleman" in this path is removed, and the first resource relationship "deployed at" obtained by calculation is added. The new path B obtained is as follows Figure 5 The diagram includes database 01, server A, and a first resource relationship - deployed on.
[0137] In the current resource relationship discovery method, after completing resource relationship discovery and storing resource relationships, the resource relationships cannot be updated. If new resource nodes and resource relationships corresponding to the resource nodes are added to the graph database later, the stored resource relationships will be inconsistent with the actual resource relationships, which may cause subsequent users to query the resource relationships in the graph database to be incorrect.
[0138] In the above-described embodiment of the present application, after the first resource node is added to the graph database, the first resource relationship corresponding to the first resource node can be discovered using rules. First, a first query condition is obtained. If the first query condition includes a first relationship type and a target rule is retrieved based on the first relationship type, the first query condition is updated to a second query condition based on the target rule. The target rule includes a first rule that associates the first relationship type, the types of the two resource nodes at both ends of the first path, and the intermediate information of the first path. The two resource nodes include the first resource node, and the first intermediate resource node is located between the two resource nodes. The first relationship type is used to identify the first resource relationship. The first resource relationship is a resource relationship between two resource nodes. The intermediate information includes the type of the first intermediate resource node, or the intermediate information includes the types of each resource node in the first path and the resource relationship between each adjacent two resource nodes, which is a basic resource relationship. Therefore, the updated second query condition can include various information about the path corresponding to the first resource relationship to be discovered. Since the first resource relationship corresponding to the first relationship type to be discovered is not a basic resource relationship, the intermediate information of the path in the second query condition helps the graph database query the path consisting of the basic resource relationships equivalent to the first resource relationship. The path includes a first target path, which includes a newly added first resource node and a first intermediate resource node. Then, the first resource relationship is added to the first target path, thereby completing the discovery of the resource relationship of the newly added resource node or the changed resource node.
[0139] In the above method, since the intermediate information is defined based on the basic resource relationship between two adjacent resource nodes, and the resource nodes in the graph database are stored based on the basic resource relationship. Therefore. When the resource nodes or resource relationships in the graph database change, when the resource relationships in the graph database are queried again, this solution will calculate based on the changed basic resource relationships and generate the latest first resource relationship corresponding to the first relationship type. Therefore, this application can support the synchronization of the queried first resource relationship with the basic resource relationship in the graph database, ensuring the accuracy and real-time nature of the queried first resource relationship.
[0140] Furthermore, in the above example of this application, by defining rules, the information in the retrieved target rule is added to the original first query condition to generate a second query condition. Since the second query condition differs from the first query condition only in content and not in form, the original query method in the graph database can be used, with minimal impact on the original query method.
[0141] Graph databases are currently commonly used in Configuration Management Database (CMDB) systems. Discovering resource relationships within a graph database using a CMDB system typically involves using established resource relationship discovery software, such as Application Performance Management (APM). However, this approach requires integrating the corresponding software or modules within the CMDB system, making the CMDB system bulky and complex, inconvenient to maintain, and increasing the difficulty of promoting its widespread use.
[0142] The method of the above solution of the present application can be integrated into the CMDB system without the need to integrate other relationship discovery software. The solution of the present application only collects basic resource relationship data in a simple way, thereby adding new resource nodes to the graph database. Simple methods include manual maintenance, resource management input, or basic collection script discovery. The embodiments of the present application do not require the integration of corresponding software or modules in the CMDB system.
[0143] The resource relationship discovery method for the database based on this implementation can query the resource relationships defined based on rules in the graph database just like querying ordinary relationships, thereby achieving the effect of database view query. This method supports dynamic data updates and does not require the integration of special resource relationship discovery software or systems. This method has the advantages of having little impact on the original query method and dynamically updating results. Resource data with a specific model structure stored in a graph database is dynamically generated and returned through customized query rules and result conversion of resource association relationship queries. This allows resource relationships to be discovered based only on the basic attributes of resources without the need to integrate other external systems, and solves the problem that resource association relationships cannot be dynamically updated with resources.
[0144] Based on the above resource relationship discovery method, such as Figure 6 As shown, the present application also provides a device for discovering resource relationships in a graph database, the device comprising:
[0145] A resource node construction module is used to update the changed first resource node and the first intermediate resource node information associated with the first resource node in the graph database when the resource relationship in the graph database changes;
[0146] a resource relationship discovery module, configured to obtain a first query condition related to a first resource node, and if the first query condition includes a first relationship type, search at least one rule according to the first relationship type;
[0147] The resource relationship discovery module is further configured to, if a target rule is retrieved according to the first relationship type, update the first query condition to a second query condition according to the target rule, wherein the target rule includes a first rule, the first rule is used to associate the first relationship type, the types of two resource nodes located at both ends of the first path, and the intermediate information of the first path, the two resource nodes include a first resource node, the first intermediate resource node is located between the two resource nodes, the first relationship type is used to identify the first resource relationship, the first resource relationship is a resource relationship between the two resource nodes, the intermediate information includes the type of the first intermediate resource node, or the intermediate information includes the type of each resource node in the first path, and the resource relationship between each two adjacent resource nodes;
[0148] The resource relationship discovery module is further configured to query the graph database according to the second query condition to obtain a first target path that satisfies the query condition, a first resource node at one end, a first intermediate resource node, and a second resource node at the other end;
[0149] The resource relationship discovery module is further configured to supplement the first resource relationship between two resource nodes at both ends of the first target path and send the supplemented first target path.
[0150] In a feasible design, the resource relationship discovery module sends the supplemented first target path in the following manner:
[0151] Storing the supplemented first target path in the cache;
[0152] Send the supplemented first target path;
[0153] The first target path in the cache is deleted, so that in the next calculation process of the resource relationship associated with the first resource node, the resource relationship associated with the first resource node is recalculated to obtain the latest first target path.
[0154] In a feasible design, before sending the supplemented first target path, the resource relationship discovery module is further used to delete resource nodes in the first target path except the first resource node and the second resource node at both ends, and delete resource relationships other than the first resource relationship.
[0155] In a feasible design, if the number of rules included in the target rule is equal to 1, the resource relationship discovery module is implemented in the following manner to update the first query condition to the second query condition according to the target rule:
[0156] Delete the first relationship type in the first query condition;
[0157] The types of the two resource nodes located at both ends of the first path in the target rule and the intermediate information of the first path are added to the first query condition to generate a second query condition.
[0158] In a feasible design, if the number of rules included in the target rule is greater than 1, the resource relationship discovery module is implemented in the following manner to update the first query condition to the second query condition according to the target rule:
[0159] Delete the first relationship type associated with each rule;
[0160] Use the OR logical relationship to splice each rule that has been deleted to update the target rule;
[0161] Delete the first relationship type in the first query condition;
[0162] The updated target rule is added to the first query condition to generate a second query condition.
[0163] In a feasible design, if the first query condition does not include any relationship type, the resource relationship discovery module is further used to query the graph database according to the first query condition to obtain the second target path; and send the second target path.
[0164] In a feasible design, if no rule is retrieved according to the first relationship type, the resource relationship discovery module is further used to send a first indication message, where the first indication message is used to indicate that the content of the first query condition is incorrect.
[0165] In a feasible design, the resource node construction module is implemented in the following manner: when a resource relationship in the graph database changes, information about the changed first resource node and the first intermediate resource node associated with the first resource node is updated in the graph database:
[0166] When a resource node is newly added, a newly added first resource node is created according to the structure of the resource model, an association relationship between the newly added first resource node and the associated first intermediate resource node is created, and resource node information corresponding to the first resource node is created, including the type of the resource node, the attributes of the resource node, the type of the intermediate resource node associated with the resource node, and the resource relationship between the resource node and the intermediate resource node, wherein the starting resource node or the ending resource node in the association path of one or more of the intermediate resource nodes is the first resource node; or;
[0167] When the resource relationship of a resource node changes, the changed first resource node and the association relationship with the associated first intermediate resource node are updated, and the type of the resource node corresponding to the first resource node, the attributes of the resource node, the type of the intermediate resource node associated with the resource node, and the resource relationship between the resource node and the intermediate resource node are updated accordingly.
[0168] In a feasible design, the resource node construction module is further used to add a node that can act as a resource connection middleman in the resource model as an intermediate resource node;
[0169] According to the structure of the resource model, each resource node is created, an association relationship between each resource node and an associated intermediate resource node is created, and resource node information corresponding to each resource node is created.
[0170] For other implementation methods and effects of the device, please refer to the embodiment of the method for discovering resource relationships in a graph database, which will not be repeated here.
[0171] The basic principles of the present application have been described above in conjunction with specific embodiments. However, it should be noted that the advantages, strengths, and effects mentioned in this application are merely illustrative and not restrictive, and it should not be assumed that these advantages, strengths, and effects are required of each embodiment of this application. In addition, the specific details disclosed above are merely illustrative and facilitating understanding, and are not restrictive. The above details do not limit this application to necessarily being implemented using the above specific details.
[0172] It should be understood that although the steps in the flowcharts of the accompanying drawings are shown in sequence as indicated by the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some of the steps in the flowcharts of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a portion of the sub-steps or stages of other steps.
[0173] The block diagrams of the devices, devices, equipment, and systems involved in this application are merely illustrative examples and are not intended to require or imply that they must be connected, arranged, or configured in the manner shown in the block diagrams. As will be appreciated by those skilled in the art, these devices, devices, equipment, and systems can be connected, arranged, or configured in any manner. Words such as "include," "comprise," "have," and the like are open-ended words, meaning "including but not limited to," and can be used interchangeably therewith. The words "or" and "and" used herein refer to the words "and / or" and can be used interchangeably therewith, unless the context clearly indicates otherwise. The word "such as" used herein refers to the phrase "such as but not limited to," and can be used interchangeably therewith.
[0174] It should also be noted that in the apparatus, device, and method of the present application, each component or each step can be decomposed and / or recombined, and such decomposition and / or recombination should be regarded as equivalent solutions of the present application.
[0175] The above description of the disclosed aspects is provided to enable any person skilled in the art to make or use the present application. Various modifications to these aspects will be readily apparent to those skilled in the art, and the general principles defined herein may be applied to other aspects without departing from the scope of the present application. Therefore, the present application is not intended to be limited to the aspects shown herein, but rather to be accorded the widest scope consistent with the principles and novel features disclosed herein.
[0176] The above description has been provided for the purpose of illustration and description. Furthermore, this description is not intended to limit the embodiments of the present application to the forms disclosed herein. Although a number of example aspects and embodiments have been discussed above, those skilled in the art will recognize certain variations, modifications, alterations, additions, and sub-combinations thereof.
Claims
1. A method for discovering resource relationships in a graph database, characterized in that: The method comprises: When the resource relationship in the graph database changes, updating the changed first resource node and the first intermediate resource node information associated with the first resource node in the graph database; Obtaining a first query condition related to the first resource node, and if the first query condition includes a first relationship type, searching at least one rule according to the first relationship type; If a target rule is retrieved according to the first relationship type, the first query condition is updated to a second query condition according to the target rule, wherein the target rule includes a first rule, the first rule is used to associate the first relationship type, the types of two resource nodes located at both ends of a first path, and intermediate information of the first path, the two resource nodes include the first resource node, the first intermediate resource node is located between the two resource nodes, the first relationship type is used to identify a first resource relationship, the first resource relationship is a resource relationship between the two resource nodes, and the intermediate information includes the type of the first intermediate resource node, or the intermediate information includes the type of each resource node in the first path and the resource relationship between each two adjacent resource nodes; Performing a query in the graph database according to the second query condition to obtain a first target path that meets the query condition, where the first target path includes the first resource node at one end, the first intermediate resource node, and the second resource node at the other end; The first resource relationship is supplemented between the first resource node and the second resource node at both ends of the first target path, and the supplemented first target path is sent.
2. The method according to claim 1, characterized in that The sending the supplemented first target path includes: Storing the supplemented first target path in a cache; sending the supplemented first target path; The first target path in the cache is deleted so that the resource relationship associated with the first resource node can be recalculated during the next calculation of the resource relationship associated with the first resource node to obtain the latest first target path.
3. The method according to claim 1 or 2, characterized in that Before sending the supplemented first target path, the method further includes: Delete resource nodes other than the first resource node and the second resource node located at both ends of the first target path, and delete resource relationships other than the first resource relationship.
4. The method according to claim 1 or 2, characterized in that If the number of rules included in the target rule is equal to 1, updating the first query condition to a second query condition according to the target rule includes: Deleting the first relationship type in the first query condition; The types of the two resource nodes located at both ends of the first path in the target rule and the intermediate information of the first path are added to the first query condition to generate a second query condition.
5. The method according to claim 1 or 2, characterized in that If the target rule includes more than one rule, updating the first query condition to a second query condition according to the target rule includes: deleting the first relationship type associated with each rule; Using an OR logical relationship to splice each of the deleted rules to update the target rule; Deleting the first relationship type in the first query condition; The updated target rule is added to the first query condition to generate a second query condition.
6. The method according to claim 1 or 2, characterized in that If the first query condition does not include any relationship type, the method further includes: Searching the graph database according to the first query condition to obtain a second target path; The second target path is sent.
7. The method according to claim 1 or 2, characterized in that If no rule is retrieved according to the first relationship type, the method further includes: Sending first indication information, where the first indication information is used to indicate that content of the first query condition is incorrect.
8. The method according to claim 1 or 2, characterized in that When the resource relationship in the graph database changes, updating the changed first resource node and the first intermediate resource node information associated with the first resource node in the graph database includes: When a new resource node is added, according to the structure of the resource model, a newly added first resource node is created, an association relationship of a first intermediate resource node associated with the first resource node is created, and resource node information corresponding to the first resource node is created, including the type of the resource node, the attributes of the resource node, the type of the intermediate resource node associated with the resource node, and the resource relationship between the resource node and the intermediate resource node, wherein the starting resource node or the ending resource node in the association path of one or more of the intermediate resource nodes is the first resource node; or; When the resource relationship of a resource node changes, the changed first resource node and the association relationship with the associated first intermediate resource node are updated, and the type of the resource node corresponding to the first resource node, the attributes of the resource node, the type of the intermediate resource node associated with the resource node, and the resource relationship between the resource node and the intermediate resource node are updated accordingly.
9. The method according to claim 8, characterized in that The method further comprises: Add nodes that can act as resource connection intermediaries in the resource model as intermediate resource nodes; According to the structure of the resource model, each resource node is created, an association relationship between each resource node and an associated intermediate resource node is created, and resource node information corresponding to each resource node is created.
10. A device for discovering resource relationships in a graph database, characterized in that: The device comprises: A resource node construction module, configured to update information of a changed first resource node and a first intermediate resource node associated with the first resource node in the graph database when a resource relationship in the graph database changes; a resource relationship discovery module, configured to obtain a first query condition related to the first resource node, and if the first query condition includes a first relationship type, search at least one rule according to the first relationship type; The resource relationship discovery module is also used to, if a target rule is retrieved according to the first relationship type, update the first query condition to a second query condition according to the target rule, wherein the target rule includes a first rule, the first rule is used to associate the first relationship type, the types of two resource nodes located at both ends of the first path and the intermediate information of the first path, the two resource nodes include the first resource node, the first intermediate resource node is located between the two resource nodes, the first relationship type is used to identify a first resource relationship, the first resource relationship is a resource relationship between the two resource nodes, the intermediate information includes the type of the first intermediate resource node, or the intermediate information includes the type of each resource node in the first path and the resource relationship between each two adjacent resource nodes; The resource relationship discovery module is further configured to query the graph database according to the second query condition to obtain a first target path that satisfies the query condition, the first resource node at one end, the first intermediate resource node, and the second resource node at the other end; The resource relationship discovery module is further configured to supplement the first resource relationship between the two resource nodes at both ends of the first target path, and send the supplemented first target path.
Citation Information
Patent Citations
Permission management method and system based on graph database
CN112507354A
Resource topological graph generation method and device, electronic equipment and readable storage medium
CN116166737A