Microservice execution method and device, equipment and storage medium
By distributing blueprint scripts in the host execution cluster and executing them by slave nodes, the problems of low operation and maintenance efficiency, high error rate and low reuse rate in the existing technology are solved, and efficient and accurate service deployment and reuse are achieved.
Patent Information
- Application Number
- CN202311797431.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-25
- Publication Date
- 2025-06-27
AI Technical Summary
In the prior art, the operation and maintenance process is low, the error rate is high, and the host operation and maintenance reuse rate is low, making it difficult to achieve efficient deployment and execution of cluster component services.
By obtaining service execution instructions, querying the blueprint script, and distributing the blueprint script to the slave node in the host execution cluster through the master node, the slave node directly executes the corresponding operations corresponding to the blueprint script.
It reduces the communication overhead between the master node and the slave node, improves execution efficiency and accuracy, and realizes service reuse and efficient deployment.
Smart Images

Figure CN120215959A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of communication technologies, and in particular, to a method, apparatus, device, and storage medium for executing microservices. Background Art
[0002] In the processes of project management, program development, etc., it is necessary to perform systematic operation and maintenance on a large number of hosts, so as to deploy corresponding component services into a cluster of each host for execution.
[0003] In the prior art, deploying a cluster usually requires logging in to each host one by one and executing command operations. The operation and maintenance process of logging in to and operating on each host one by one is inefficient, and it is easy to perform single logging in and execution operations on different hosts, resulting in errors. At the same time, it is also difficult to reuse the executed services in other hosts, which is not convenient for the efficient deployment and execution of component services in the cluster. Summary of the Invention
[0004] The present invention provides a method, apparatus, device, and storage medium for executing microservices to solve the technical problems of low efficiency, high error rate, and low reuse rate of host operation and maintenance in the prior art.
[0005] To solve the above technical problems, an embodiment of the present invention provides a method for executing microservices, including:
[0006] Obtain a service execution instruction;
[0007] According to the service execution instruction, query a corresponding blueprint script, and call a master node in a host execution cluster to save the blueprint script; wherein, the blueprint script is a service execution file, and the host execution cluster includes a master node and slave nodes, and the master node is communicatively connected to the slave nodes;
[0008] Distribute the blueprint script to corresponding slave nodes in the host execution cluster through the master node, so that the slave nodes execute operations corresponding to the blueprint script.
[0009] As a preferred solution, the step of according to the service execution instruction, querying a corresponding blueprint script, and calling a master node in a host execution cluster to save the blueprint script includes:
[0010] According to the service execution instruction, query a corresponding blueprint script from a blueprint list; wherein, the service execution instruction corresponds to one or more blueprint scripts, and the blueprint list stores several blueprint scripts;
[0011] According to the blueprint script, determine the master nodes in the host pool and the slave nodes for executing the blueprint script, and use them as a host execution cluster; wherein, the host pool includes several master nodes and several slave nodes, and each master node can communicate with any slave node.
[0012] Call the Hypertext Transfer Protocol interface to request the configuration module of the master node, so as to establish communication with the master node, and after establishing communication, send the blueprint script to the master node for storage.
[0013] As a preferred solution, the master node distributes the blueprint script to the corresponding slave nodes in the host execution cluster, so that the slave nodes execute the operations corresponding to the blueprint script, including:
[0014] Parse the blueprint script through the master node to obtain the slave node corresponding to each execution of the blueprint script.
[0015] According to the slave host corresponding to each execution of the blueprint script, distribute the blueprint script to the slave nodes in the host execution cluster, so that each slave node sequentially completes the corresponding blueprint script under the control of the master node.
[0016] As a preferred solution, the step of distributing the blueprint script to the slave nodes in the host execution cluster according to the slave host corresponding to each execution of the blueprint script, so that each slave node sequentially completes the corresponding blueprint script under the control of the master node, specifically is:
[0017] According to the slave host corresponding to each execution of the blueprint script and the preset execution timing sequence of each blueprint script, package the blueprint script into a command set, and send the command set to the master node; wherein, each blueprint script in the command set corresponds to a slave host for execution.
[0018] Parse the command set through the master node, and distribute the blueprint script to their corresponding slave hosts respectively.
[0019] Through the master node, according to the preset execution timing sequence of each blueprint script, control the order of the blueprint scripts executed by each slave node until all the blueprint scripts in the command set are executed by the corresponding slave nodes.
[0020] As a preferred solution, the step of controlling the order of the blueprint scripts executed by each slave node through the master node according to the preset execution timing sequence of each blueprint script until all the blueprint scripts in the command set are executed by the corresponding slave nodes, specifically is:
[0021] The master node controls the execution order of the blueprint scripts executed by each slave node according to the preset execution time sequence of each blueprint script, so that whenever a slave host finishes executing the corresponding blueprint script, the master node controls the slave node corresponding to the next blueprint script to execute its corresponding blueprint script according to the order of the blueprint script executed by the current slave node in the command set, until all the blueprint scripts in the command set are executed by the corresponding slave nodes.
[0022] As a preferred solution, it further includes:
[0023] When each slave node executes the corresponding blueprint script, each executing slave node sends intermediate information to the cache database, so that the cache database caches the intermediate information; wherein, each slave node has corresponding intermediate information, and the intermediate information includes the slave host status data when the slave node executes the corresponding blueprint script.
[0024] After a preset time has passed, the master node pulls the cached intermediate information from the cache database and restores the intermediate information.
[0025] As a preferred solution, the blueprint script is stored in a blueprint list; the construction method of the blueprint list includes:
[0026] According to a number of preset service operation information, corresponding directories are created respectively, and initial blueprint scripts are constructed according to the directories; wherein, each directory corresponds to an initial blueprint script, and each service operation information corresponds to a directory and an initial blueprint script.
[0027] The execution codes corresponding to each service operation information are respectively encapsulated in the corresponding initial blueprint scripts, thereby constructing the blueprint scripts; wherein, each blueprint script has a corresponding service operation information and its execution code.
[0028] All the blueprint scripts are integrated to obtain the blueprint list.
[0029] Correspondingly, the present invention further provides an execution device for microservices, including: a response module, a blueprint script module, and an operation module;
[0030] The response module is used to obtain a service execution instruction;
[0031] The blueprint script module is used to query the corresponding blueprint script according to the service execution instruction, and call the master node in the host execution cluster to save the blueprint script; wherein, the blueprint script is a service execution file, and the host execution cluster includes a master node and slave nodes, and the master node is communicatively connected to the slave nodes.
[0032] The execution module is configured to distribute the blueprint script to corresponding slave nodes in the host execution cluster through the master node, so that the slave nodes execute the operations corresponding to the blueprint script.
[0033] Correspondingly, the present invention further provides a terminal device, including a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor. When the processor executes the computer program, the execution method of the microservice described in any one of the above is implemented.
[0034] Correspondingly, the present invention further provides a computer-readable storage medium. The computer-readable storage medium includes a stored computer program. When the computer program runs, it controls the device where the computer-readable storage medium is located to execute the execution method of the microservice described in any one of the above.
[0035] Compared with the prior art, the embodiments of the present invention have the following beneficial effects:
[0036] The technical solution of the present invention distributes the blueprint script to the slave nodes in the host execution cluster to execute operations, avoiding the overhead of communication connections between the master node and each slave node, thereby reducing network latency and data transmission volume, improving the overall execution efficiency. At the same time, since the slave nodes directly execute the operations corresponding to the blueprint script, the interference of intermediate links is reduced, and the execution accuracy is improved. The collaborative work between slave nodes also helps to improve the overall execution accuracy. By distributing the blueprint script to the slave nodes to execute operations, service reuse is achieved. When the user requests the same service again, the result can be directly obtained from the slave node that has already executed the service, without having to re-execute the entire service process, thereby improving the service reuse rate. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] Figure 1 : It is a step flowchart of an execution method of a microservice provided by an embodiment of the present invention;
[0038] Figure 2 : It is a schematic diagram of a host pool provided by an embodiment of the present invention;
[0039] Figure 3 : It is a schematic diagram of a command set stage provided by an embodiment of the present invention;
[0040] Figure 4 : It is a schematic diagram of a blueprint script provided by an embodiment of the present invention;
[0041] Figure 5 : It is a structural diagram of a microservice execution system provided by an embodiment of the present invention;
[0042] Figure 6: Structural diagram of an execution device for a microservice provided by an embodiment of the present invention. Detailed implementation manners
[0043] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.
[0044] Embodiment 1
[0045] Please refer to Figure 1 , an execution method for a microservice provided by an embodiment of the present invention, including the following steps S101-S103:
[0046] Step S101: Obtain a service execution instruction.
[0047] In this embodiment, by responding to the user's click operation, a service execution instruction is generated on the terminal. Among them, the terminal can be an electronic terminal device such as a computer, a mobile phone, or a tablet computer. In order to respond to the user's click operation, a UI interface for user operation needs to be designed. This UI interface should be able to display various function options and receive user input and feedback. Exemplarily, optional operations include, but are not limited to, deploying a cluster, collecting real-time information of the cluster, uninstalling the cluster, and scaling the cluster. At the same time, when the user clicks on a certain function option, a corresponding service execution instruction needs to be generated according to the user's selection, which is achieved by writing an instruction algorithm to convert the user's input into a service execution instruction that the system can understand and execute.
[0048] Step S102: According to the service execution instruction, query the corresponding blueprint script, and call the master node in the host execution cluster to save the blueprint script; wherein, the blueprint script is a service execution file, and the host execution cluster includes a master node and a slave node, and the master node is communicatively connected to the slave node.
[0049] As an implementation solution, the querying the corresponding blueprint script according to the service execution instruction and calling the master node in the host execution cluster to save the blueprint script includes:
[0050] According to the service execution instruction, query the corresponding blueprint script from the blueprint list; wherein, there is one or more blueprint scripts corresponding to the service execution instruction, and several blueprint scripts are stored in the blueprint list; according to the blueprint script, determine the master node in the host pool and the slave nodes for executing the blueprint script, and use them as the host execution cluster; wherein, the host pool includes several master nodes and several slave nodes, and each master node can communicate with any slave node; call the Hypertext Transfer Protocol interface to request the configuration module of the master node, so as to establish communication with the master node, and after establishing communication, send the blueprint script to the master node for storage. Further, after the blueprint script is saved on the master node, the master node calls the HTTPS interface of the slave node, so that the slave node executes the execution commands in the blueprint script, and the execution commands can be in the python, shell or sls format.
[0051] In this embodiment, through the service execution instruction, an algorithm for matching query needs to be designed to determine the corresponding blueprint script, and this query algorithm should be able to handle the situation of multiple blueprint scripts and return the blueprint script that best matches the service execution instruction. In addition, a host pool needs to be maintained, which contains several master nodes and slave nodes. Each master node can communicate with any slave node. The management of the host pool includes operations such as adding, deleting and updating master nodes and slave nodes. At the same time, through the configuration module interface, communication can be established with the master node, and the Hypertext Transfer Protocol (HTTPS) interface needs to be called to request the configuration module of the master node, and this interface should be able to provide the authentication and authorization information required for communicating with the master node.
[0052] In this implementation, the microservice module will call the HTTPS interface to request the salt module (corresponding to the master node), so that after the salt module and the salt-minion (corresponding to the slave node) perform HTTPS interface authentication, the salt module will call the blueprint script that needs to be executed and pass the blueprint script into the salt-master (the master node using salt communication). Among them, each master node and slave node has a corresponding identity identifier. When the microservice calls the blueprint script and generates the corresponding command set stage, at the same time, the identity identifiers of the master node and slave node that the command set stage needs to call the blueprint script to execute are stored in the command set stage; so that the required master node can be called through the command set stage. The master node completes the call of the microservice module through the authentication of the key, and obtains the required slave node by parsing the command set stage by the master node. During the process of the master node calling the slave node for communication connection, it is necessary to use the keys stored in the master node and slave node to implement authentication through the HTTPS interface to determine the identities of the slave node and the master node; among them, each master node and each slave node locally stores the keys for authentication identity recognition.
[0053] Further, please refer to Figure 2 , the operation and maintenance monitoring platform needs to manage and control thousands of machines, deploy clusters, and collect host information. It is necessary to install the minion (unique identifier used to mark the host) service on all hosts in advance, which can be used for remote communication by the master node to call the service module and execute basic operation script commands. The minnion service can be installed through ssh communication or manually log in to the machine and enter the username and password to log in for service installation. If salt is not considered or the usage conditions are not met, directly connecting to the linux server through ssh in the microservice can also achieve the same operation. Among them, salt communication executes remote commands and configuration management through the communication between the saltmaster (master node, i.e., control node) and the salt minion (slave node, i.e., controlled node). The working mode of salt is to generate control execution instructions on the control node and then pass the instructions to the controlled node for execution.
[0054] In this embodiment, the storage and management of the blueprint script need to be designed with a blueprint list for storage and management, which can be implemented through a database or other data storage solutions. The blueprint list should contain several blueprint scripts, and each blueprint script corresponds to a unique identifier. After establishing communication with the master node, the blueprint script needs to be sent to the master node for storage, which can be achieved by calling the configuration module interface of the master node.
[0055] It can be understood that by matching the service execution instructions with the blueprint scripts, different blueprint scripts can be selected according to different requirements to perform corresponding operations, which improves the flexibility of the system and enables the system to better adapt to different application scenarios. By combining the master node and the slave nodes into a host execution cluster, the architecture of the system is simplified, making the system more modular and scalable, and facilitating management and upgrade. And by distributing the blueprint scripts to the slave nodes in the master node to perform operations, parallel execution of services can be achieved, thereby improving the throughput and response speed of the system, and thus enhancing the overall performance. Furthermore, by separating the management of the blueprint scripts from the host execution cluster, the complexity of the system is reduced, making the system easier to maintain and upgrade, and at the same time reducing the complexity of the system.
[0056] Step S103: Through the master node, distribute the blueprint script to the corresponding slave nodes in the host execution cluster so that the slave nodes execute the operations corresponding to the blueprint script.
[0057] As an implementation, the step of distributing the blueprint script to the corresponding slave nodes in the host execution cluster through the master node so that the slave nodes execute the operations corresponding to the blueprint script includes:
[0058] Parse the blueprint script through the master node to obtain the slave node corresponding to each execution of the blueprint script; according to the slave host corresponding to each execution of the blueprint script, distribute the blueprint script to the slave nodes in the host execution cluster so that each slave node completes the corresponding blueprint script in sequence under the control of the master node.
[0059] In this embodiment, the master node needs to parse the blueprint to determine the slave node corresponding to each execution of the blueprint, which can be achieved by writing a parsing algorithm to convert the configuration information in the blueprint into instructions that the system can understand and execute. At the same time, in order to manage the host execution cluster, a host cluster, that is, a host pool, needs to be maintained, which contains several master nodes and slave nodes. Each master node can communicate with any slave node. The management of the host cluster includes operations such as adding, deleting, and updating master nodes and slave nodes. And through the blueprint distribution mechanism, according to the slave host corresponding to each execution of the blueprint obtained by parsing, a distribution mechanism is required to distribute the blueprint to the slave nodes in the host cluster, which can be achieved by defining distribution policies and algorithms to ensure that each slave node can obtain the correct blueprint. For the operations of the slave nodes, once the slave node receives the blueprint sent by the master node, it will execute the operations specified in the blueprint, which may involve calling other microservices, accessing the database, etc.
[0060] In this embodiment, since the slave nodes in the host execution cluster can execute multiple service operations simultaneously, parallel execution of services can be achieved, which can further improve the throughput and efficiency of the system. By dispersing the operations of service execution to the slave nodes in the host execution cluster, the load pressure on a single server is alleviated, and the complexity of the system is simplified. At the same time, through centralized management and distribution of blueprints, the maintainability and scalability of the system are also improved. By matching the service execution instructions with the blueprints, different blueprints can be selected according to different requirements to execute corresponding operations, which improves the flexibility of the system and enables the system to better adapt to different application scenarios. And by parsing the blueprints on the master node and distributing them to the corresponding slave nodes for operation execution, the possibility of human errors can be reduced. Since the master node is responsible for parsing and distributing the blueprints, and the slave nodes are only responsible for operation execution, the interaction links between the master node and the slave nodes are reduced, and the probability of errors is lowered.
[0061] As an implementation solution, for the slave host corresponding to each blueprint script during execution, the blueprint script is distributed to the slave nodes in the host execution cluster, so that each slave node, under the control of the master node, sequentially completes the corresponding blueprint script. Specifically:
[0062] According to the slave host corresponding to each blueprint script during execution and the preset execution time sequence of each blueprint script, the blueprint scripts are packaged into a command set, and the command set is sent to the master node; wherein, each blueprint script in the command set corresponds to a slave host for execution; the master node parses the command set and distributes the blueprint scripts to their corresponding slave hosts respectively; the master node controls the execution order of the blueprint scripts by each slave node according to the preset execution time sequence of each blueprint script until all the blueprint scripts in the command set are executed by the corresponding slave nodes.
[0063] In this embodiment, please refer to Figure 3 , the command set stage consists of several blueprint scripts combined with their corresponding execution time sequences. The blueprint scripts support upstream and downstream dependencies. Among them, the execution of the service consists of the command set stage. One stage can consist of multiple blueprints. Among them, blueprint script A can be the upstream of blueprint script B. After blueprint script A is executed, blueprint script B is then executed, or blueprint script A and blueprint script C are executed concurrently. Until the entire stage is fully executed, a common operation and maintenance operation such as a service installation and deployment or information collection can be completely presented.
[0064] In this embodiment, for the parsing of blueprint scripts, the master node needs to parse each blueprint script to determine its corresponding slave host and preset execution timing, which is achieved by writing a parsing algorithm to convert the configuration information in the blueprint script into instructions that the system can understand and execute. At the same time, according to the slave host and preset execution timing corresponding to each blueprint script, the blueprint scripts need to be packaged into a command set to ensure that each slave host can obtain the correct instructions and execution order, and the packaged command set is sent to the master node. Among them, this can be achieved by using network communication protocols (such as TCP / IP, HTTP protocol) to ensure that the master node can receive and process instructions from the slave nodes.
[0065] In this embodiment, by writing a parsing algorithm, the master node needs to parse the received command set and distribute the blueprint scripts to their corresponding slave hosts respectively. Among them, the instructions and execution order are converted into operations that the system can understand and execute. Furthermore, the master node needs to control the execution order of the blueprint scripts executed by the slave nodes according to the preset execution timing of each blueprint script to ensure that the slave nodes execute the instructions in a predetermined order.
[0066] In this embodiment, by matching the service execution instructions with the blueprint scripts, different blueprint scripts can be selected according to different requirements to perform corresponding operations, which improves the flexibility of the system and enables the system to better adapt to different application scenarios. By packaging the blueprint scripts into a command set and sending the command set to the master node, the complexity of the system is simplified. At the same time, through centralized management and distribution of the command set, the maintainability and scalability of the system are also improved. And by parsing the command set on the master node and controlling the execution order of the slave nodes, it can be ensured that each slave node executes the instructions in a predetermined order, thereby reducing the probability of errors. Furthermore, by distributing the blueprint scripts to the corresponding slave nodes to perform operations, parallel execution of services can be achieved, which can further improve the throughput and response speed of the system.
[0067] As an implementation scheme, the master node controls the execution order of the blueprint scripts executed by each slave node according to the preset execution timing of each blueprint script until all the blueprint scripts in the command set are executed by the corresponding slave nodes. Specifically:
[0068] The master node controls the execution order of the blueprint scripts executed by each slave node according to the preset execution timing of each blueprint script, so that whenever a slave host finishes executing the corresponding blueprint script, the master node controls the slave node corresponding to the next blueprint script to execute its corresponding blueprint script according to the order of the blueprint script currently executed by the slave node in the command set until all the blueprint scripts in the command set are executed by the corresponding slave nodes.
[0069] As an implementation, the execution method further includes:
[0070] When each slave node executes the corresponding blueprint script, each executing slave node sends intermediate information to the cache database so that the cache database caches the intermediate information; wherein, each slave node has corresponding intermediate information, and the intermediate information includes the slave host status data of the slave node when executing the corresponding blueprint script; after every preset time, the master node pulls the cached intermediate information from the cache database and restores the intermediate information.
[0071] In this embodiment, the master node needs to control the execution order of the slave nodes according to the preset execution timing of each blueprint script to ensure that the slave nodes execute instructions in a predetermined order. After the slave node finishes executing the corresponding blueprint script, it notifies the master node, that is, when the slave node finishes executing the corresponding blueprint script, it sends a notification to the master node through a certain communication mechanism (such as a message queue), informing the master node of the order of the blueprint script currently executed by the slave node in the command set. The master node executes the next blueprint script according to the order of the slave nodes. Among them, the execution task can be cached in the cache database Redis by the slave node and pulled by the master node, or the master node can receive the notification from the slave node. In the first way, after the slave node executes the task of the blueprint script assigned by the master node, it generates an execution task jobID. After the execution task of the slave node is completed, it saves the execution task jobID and the return result into the cache database redis, and the master node will regularly obtain the return result of the slave node jobId from redis. Among them, the master node can pull the return result of the slave node, which means that the execution task of the slave node has been completed. If there is no result within the timeout period, it means that the execution has timed out; in the other way, after the master node receives the notification from the slave node, according to the order of the blueprint script currently executed by the slave node in the command set, it controls the slave node corresponding to the next blueprint script to execute its corresponding blueprint script to ensure that the slave nodes execute instructions in a predetermined order. Finally, check whether all blueprint scripts have been executed. The master node needs to regularly check whether all blueprint scripts in the command set have been executed. This can be achieved through a monitoring program to ensure that the slave nodes execute instructions in a predetermined order until all blueprint scripts have been executed.
[0072] In this embodiment, the preset time can be set according to actual monitoring requirements. The master node communicates with each slave node (minion), executes the blueprint script commands on each slave node, and stores the intermediate results generated by executing the blueprint in the cache database, enabling the microservice module to pull them at regular intervals and perform status echo, so that users can clearly see which stage of the blueprint each host node has executed to, what the corresponding status is, and whether it is successful or failed.
[0073] In this embodiment, the intermediate information of each slave node should include the slave host status data when it executes the corresponding blueprint script. These status data can include metrics such as CPU usage, memory usage, and disk space, so that the master node can understand the running status of the slave node.
[0074] In this embodiment, the slave node sends intermediate information to the master node when executing the blueprint script, and the master node caches this information and performs echo after the preset time. This can improve the flexibility and reliability of the system while simplifying the complexity of the system.
[0075] As an implementation solution, the blueprint script is stored in the blueprint list; the construction method of the blueprint list includes:
[0076] According to a number of preset service operation information, create corresponding directories respectively, and construct the initial blueprint script according to the directories; where each directory corresponds to an initial blueprint script, and each service operation information corresponds to a directory and an initial blueprint script; encapsulate the execution code corresponding to each service operation information into the corresponding initial blueprint script respectively, thereby constructing the blueprint script; where each blueprint script has a corresponding service operation information and its execution code; integrate all the blueprint scripts to obtain the blueprint list.
[0077] In this embodiment, in order to reduce repetitive operations and improve convenience, operations such as deploying cluster services (yum install, decompressing tar.gz packages for installation, rpm installation), collecting information (ps - ef, ss - nltp, top), and starting and stopping services (bin / start.sh, stop.sh, restart.sh) are integrated and uniformly managed in the blueprint. Among them, corresponding business logics can be developed in the blueprint through python, sls, shell scripts, etc., that is, the steps executed by the slave node after receiving the corresponding blueprint script, including but not limited to downloading files, modifying configuration files, installing dependent environments, moving packages to specified paths, decompressing packages, specifying start, stop, and other commands.
[0078] In this embodiment, according to a number of preset service operation information, corresponding directories are created respectively, which can be implemented by using file system operations to ensure that each directory corresponds to one service operation information. Furthermore, an initial blueprint script is constructed. The initial blueprint script is constructed according to the directory, and the execution code in each directory is encapsulated into an initial blueprint script. At the same time, the execution code is encapsulated. The execution code corresponding to each service operation information is respectively encapsulated in the corresponding initial blueprint script. Among them, this can be achieved by writing the execution code into the corresponding initial blueprint script file. Finally, by integrating all the blueprint scripts, a blueprint list is constructed.
[0079] Implementing the above embodiment has the following effects:
[0080] The technical solution of the present invention distributes the blueprint script to the slave nodes in the host cluster to execute operations, avoiding the overhead of communication connections between the master node and each slave node. Thus, network latency and data transmission volume can be reduced, and the overall execution efficiency can be improved. At the same time, since the slave nodes directly execute the operations corresponding to the blueprint script, the interference of intermediate links is reduced, and the execution accuracy is improved. The collaborative work between the slave nodes also helps to improve the overall execution accuracy. By distributing the blueprint script to the slave nodes to execute operations, service reuse is achieved. When the user requests the same service again, the result can be directly obtained from the slave node that has executed the service, without having to re-execute the entire service process, thereby improving the service reuse rate.
[0081] Embodiment 2
[0082] Please refer to Figure Figure 5 , which is an execution system of the microservice provided by the present invention, used to execute the microservice execution method of Embodiment 1, including: a front-end module, a Spring microservice module, and a host pool.
[0083] Among them, the front-end module is used to receive the user's click operation on the UI interface and generate a corresponding instruction to execute the specified service for the click. The front-end module includes service instructions such as deploying the cluster, collecting real-time information of the cluster, uninstalling the cluster, and scaling the cluster.
[0084] The Spring microservice module includes a service module server-model, a blueprint list, and an execution module action-model. Among them, the service module server-model is used to receive specified service instructions and then query a specified blueprint in the blueprint list according to the instructions. Among them, the blueprint list stores several blueprint scripts. Among them, the blueprint scripts include tasks such as issuing an ES version package, modifying the ES configuration file, starting a specified ES role, forming an ES cluster service, issuing a hadoop configuration file, starting a specified hadoop service role, forming a hadoop cluster service, uninstalling the cluster, and obtaining service information. The execution module action-model is used to call the master host A and then save the blueprint script in the master host A.
[0085] The host pool includes several host nodes. Among them, there can be one or more master nodes. Each master node can communicate with one or more minion slave nodes, and one minion slave node can also be connected to multiple master nodes to execute the stage tasks of different master nodes.
[0086] Embodiment III
[0087] Please refer to Figure 6 , which provides an execution device for a microservice according to the present invention, including: a response module 201, a blueprint script module 202, and an operation module 203;
[0088] The response module 201 is used to obtain a service execution instruction;
[0089] The blueprint script module 202 is used to query a corresponding blueprint script according to the service execution instruction and call the master node in the host execution cluster to save the blueprint script; among them, the blueprint script is a service execution file, and the host execution cluster includes a master node and a slave node, and the master node is communicatively connected to the slave node;
[0090] The execution module 203 is used to distribute the blueprint script to the corresponding slave nodes in the host execution cluster through the master node so that the slave nodes execute the operations corresponding to the blueprint script.
[0091] As a preferred solution, the step of querying a corresponding blueprint script according to the service execution instruction and calling the master node in the host execution cluster to save the blueprint script includes:
[0092] Querying a corresponding blueprint script from the blueprint list according to the service execution instruction; among them, there is one blueprint script or multiple blueprint scripts corresponding to the service execution instruction, and several blueprint scripts are stored in the blueprint list;
[0093] According to the blueprint script, determine the master nodes in the host pool and the slave nodes for executing the blueprint script, and use them as a host execution cluster; wherein, the host pool includes several master nodes and several slave nodes, and each master node can communicate with any slave node.
[0094] Call the Hypertext Transfer Protocol interface to request the configuration module of the master node, so as to establish communication with the master node, and after establishing communication, send the blueprint script to the master node for storage.
[0095] As a preferred solution, the master node distributes the blueprint script to the corresponding slave nodes in the host execution cluster, so that the slave nodes execute the operations corresponding to the blueprint script, including:
[0096] Parse the blueprint script through the master node to obtain the slave node corresponding to each execution of the blueprint script;
[0097] According to the slave host corresponding to each execution of the blueprint script, distribute the blueprint script to the slave nodes in the host execution cluster, so that each slave node sequentially completes the corresponding blueprint script under the control of the master node.
[0098] As a preferred solution, the step of distributing the blueprint script to the slave nodes in the host execution cluster according to the slave host corresponding to each execution of the blueprint script, so that each slave node sequentially completes the corresponding blueprint script under the control of the master node, specifically is:
[0099] According to the slave host corresponding to each execution of the blueprint script and the preset execution time sequence of each blueprint script, pack the blueprint script into a command set, and send the command set to the master node; wherein, each blueprint script in the command set corresponds to a slave host for execution;
[0100] Parse the command set through the master node, and distribute the blueprint scripts to their corresponding slave hosts respectively;
[0101] Through the master node, according to the preset execution time sequence of each blueprint script, control the order of the blueprint scripts executed by each slave node until all the blueprint scripts in the command set are executed by the corresponding slave nodes.
[0102] As a preferred solution, the step of controlling the order of the blueprint scripts executed by each slave node through the master node according to the preset execution time sequence of each blueprint script until all the blueprint scripts in the command set are executed by the corresponding slave nodes, specifically is:
[0103] The master node controls the execution order of the blueprint scripts executed by each slave node according to the preset execution timing of each blueprint script, so that whenever a slave host finishes executing the corresponding blueprint script, the master node controls the slave node corresponding to the next blueprint script to execute its corresponding blueprint script according to the order of the blueprint script executed by the current slave node in the command set, until all the blueprint scripts in the command set are executed by the corresponding slave nodes.
[0104] As a preferred solution, it further includes:
[0105] When each slave node executes the corresponding blueprint script, each executing slave node sends intermediate information to the cache database to enable the cache database to cache the intermediate information; wherein, each slave node has corresponding intermediate information, and the intermediate information includes the slave host status data of the slave node when executing the corresponding blueprint script.
[0106] After a preset time has passed, the master node pulls the cached intermediate information from the cache database and presents the intermediate information.
[0107] As a preferred solution, the blueprint script is stored in a blueprint list; the construction method of the blueprint list includes:
[0108] According to a number of preset service operation information, corresponding directories are created respectively, and initial blueprint scripts are constructed according to the directories; wherein, each directory corresponds to an initial blueprint script, and each service operation information corresponds to a directory and an initial blueprint script.
[0109] The execution codes corresponding to each service operation information are respectively encapsulated in the corresponding initial blueprint scripts, thereby constructing the blueprint scripts; wherein, each blueprint script has a corresponding service operation information and its execution code.
[0110] All the blueprint scripts are integrated to obtain the blueprint list.
[0111] Those skilled in the art can clearly understand that for the convenience and conciseness of description, the specific working process of the device described above can refer to the corresponding process in the foregoing method embodiment, and will not be elaborated herein.
[0112] Implementing the above embodiments has the following effects:
[0113] The technical solution of the present invention distributes the blueprint script to the slave nodes in the host cluster for operation, avoiding the overhead of communication connections between the master node and each slave node, thereby reducing network latency and data transfer volume, improving the overall execution efficiency. At the same time, since the slave nodes directly execute the operations corresponding to the blueprint script, the interference of intermediate links is reduced, and the execution accuracy is improved. The collaborative work between the slave nodes also helps to improve the overall execution accuracy. By distributing the blueprint script to the slave nodes for operation, service reuse is achieved. When the user requests the same service again, the result can be directly obtained from the slave node that has executed the service, without having to re-execute the entire service process, thereby improving the service reuse rate.
[0114] Embodiment 4
[0115] Correspondingly, the present invention also provides a terminal device, including: a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor. When the processor executes the computer program, the execution method of the microservice described in any one of the above embodiments is implemented.
[0116] The terminal device of this embodiment includes: a processor, a memory, and a computer program and computer instructions stored in the memory and executable on the processor. When the processor executes the computer program, each step in Embodiment 1 above is implemented, such as Figure 1 the steps S101 to S103 shown. Alternatively, when the processor executes the computer program, the functions of each module / unit in the above device embodiment are implemented, such as executing module 203.
[0117] Exemplarily, the computer program can be divided into one or more modules / units. The one or more modules / units are stored in the memory and executed by the processor to complete the present invention. The one or more modules / units can be a series of computer program instruction segments capable of performing specific functions, and this instruction segment is used to describe the execution process of the computer program in the terminal device. For example, the execution module 203 is used to distribute the blueprint script to the corresponding slave nodes in the host execution cluster through the master node, so that the slave nodes execute the operations corresponding to the blueprint script.
[0118] The terminal device can be a computing device such as a desktop computer, a notebook, a palm computer, and a cloud server. The terminal device may include, but is not limited to, a processor and a memory. Those skilled in the art can understand that the schematic diagram is only an example of the terminal device, and does not constitute a limitation on the terminal device. It may include more or fewer components than shown in the figure, or combine some components, or different components. For example, the terminal device may further include input / output devices, network access devices, a bus, etc.
[0119] The so-called processor may be a Central Processing Unit (CPU), or may also be other general-purpose processors, Digital Signal Processors (DSPs), Application Specific Integrated Circuits (ASICs), Field-Programmable Gate Arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc. The processor is the control center of the terminal device and connects all parts of the entire terminal device using various interfaces and lines.
[0120] The memory can be used to store the computer program and / or module. The processor realizes various functions of the terminal device by running or executing the computer program and / or module stored in the memory, and by calling the data stored in the memory. The memory may mainly include a program storage area and a data storage area. Among them, the program storage area can store an operating system, application programs required for at least one function, etc.; the data storage area can store data created according to the use of the mobile terminal, etc. In addition, the memory may include high-speed random access memory, and may also include non-volatile memory, such as hard disks, memory, plug-in hard disks, Smart Media Cards (SMCs), Secure Digital (SD) cards, Flash Cards, at least one magnetic disk storage device, flash device, or other volatile solid-state storage devices.
[0121] Among them, if the modules / units integrated in the terminal device are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on such an understanding, to implement all or part of the processes in the above-mentioned embodiment methods of the present invention, it can also be completed by instructing relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium. When the computer program is executed by a processor, the steps of the above-mentioned various method embodiments can be implemented. Among them, the computer program includes computer program code, and the computer program code can be in the form of source code, object code, executable file or some intermediate form, etc. The computer-readable medium can include: any entity or device capable of carrying the computer program code, recording medium, USB flash drive, mobile hard disk, magnetic disk, optical disc, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), electrical carrier signal, telecommunication signal, and software distribution medium, etc. It should be noted that the content included in the computer-readable medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, the computer-readable medium does not include electrical carrier signals and telecommunication signals.
[0122] Embodiment Five
[0123] Correspondingly, the present invention also provides a computer-readable storage medium, and the computer-readable storage medium includes a stored computer program. Among them, when the computer program runs, it controls the device where the computer-readable storage medium is located to execute the execution method of the microservice described in any one of the above embodiments.
[0124] The above-mentioned specific embodiments have further elaborated on the purpose, technical solutions, and beneficial effects of the present invention. It should be understood that the above-mentioned are only specific embodiments of the present invention and are not used to limit the protection scope of the present invention. In particular, it is pointed out that for those skilled in the art, any modifications, equivalent replacements, improvements, etc. made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A method for executing a microservice, characterized in that, Including: Obtain a service execution instruction; According to the service execution instruction, query the corresponding blueprint script, and call the master node in the host execution cluster to save the blueprint script; wherein, the blueprint script is a service execution file, and the host execution cluster includes a master node and slave nodes, and the master node is communicatively connected to the slave nodes; Through the master node, distribute the blueprint script to the corresponding slave nodes in the host execution cluster, so that the slave nodes perform the operations corresponding to the blueprint script.
2. The execution method of a microservice according to claim 1, characterized in that, The step of querying the corresponding blueprint script according to the service execution instruction and calling the master node in the host execution cluster to save the blueprint script includes: According to the service execution instruction, query the corresponding blueprint script from the blueprint list; wherein, one or more blueprint scripts correspond to the service execution instruction, and several blueprint scripts are stored in the blueprint list; According to the blueprint script, determine the master node in the host pool and the slave nodes for executing the blueprint script, and use them as the host execution cluster; wherein, the host pool includes several master nodes and several slave nodes, and the host execution cluster includes one master node and one or more slave nodes, and each master node can communicate with any one of the slave nodes; Call the configuration module of the master node through the Hypertext Transfer Protocol interface, so as to establish communication with the master node, and after establishing communication, send the blueprint script to the master node for saving.
3. The execution method of a microservice according to claim 2, characterized in that, The step of distributing the blueprint script to the corresponding slave nodes in the host execution cluster through the master node, so that the slave nodes perform the operations corresponding to the blueprint script includes: Parse the blueprint script through the master node to obtain the slave nodes corresponding to each execution of the blueprint script; According to the slave hosts corresponding to each execution of the blueprint script, distribute the blueprint script to the slave nodes in the host execution cluster, so that each slave node completes the corresponding blueprint script in sequence under the control of the master node.
4. The execution method of a microservice according to claim 3, characterized in that The step of distributing the blueprint script to the slave nodes in the host execution cluster according to the slave hosts corresponding to each execution of the blueprint script, so that each slave node completes the corresponding blueprint script in sequence under the control of the master node is specifically: According to the slave hosts corresponding to each execution of the blueprint script and the preset execution timing sequence of each blueprint script, pack the blueprint script into a command set, and send the command set to the master node; wherein, each blueprint script in the command set corresponds to a slave host for execution; Parse the command set through the master node, and distribute the blueprint script to their corresponding slave hosts respectively; Through the master node, control the execution order of the blueprint scripts of each slave node according to the preset execution timing sequence of each blueprint script, until all the blueprint scripts in the command set are executed by the corresponding slave nodes.
5. The execution method of a microservice according to claim 4, characterized in that, The master node controls the execution order of the blueprint scripts executed by each slave node according to the preset execution timing of each blueprint script until all the blueprint scripts in the command set are executed by the corresponding slave nodes. Specifically: The master node controls the execution order of the blueprint scripts executed by each slave node according to the preset execution timing of each blueprint script, so that whenever a slave host finishes executing the corresponding blueprint script, the master node controls the slave node corresponding to the next blueprint script to execute its corresponding blueprint script according to the order of the blueprint script executed by the current slave node in the command set until all the blueprint scripts in the command set are executed by the corresponding slave nodes.
6. A method for executing a microservice according to any one of claims 1-5, characterized in that, It further includes: When each slave node executes the corresponding blueprint script, each executing slave node sends intermediate information to the cache database so that the cache database caches the intermediate information; wherein, each slave node has corresponding intermediate information, and the intermediate information includes the slave host status data when the slave node executes the corresponding blueprint script. After a preset time has passed, the master node pulls the cached intermediate information from the cache database and presents the intermediate information.
7. The execution method of a microservice according to claim 1, characterized in that, The blueprint scripts are stored in a blueprint list; the method for constructing the blueprint list includes: According to a number of preset service operation information, corresponding directories are created respectively, and initial blueprint scripts are constructed according to the directories; wherein, each directory corresponds to an initial blueprint script, and each service operation information corresponds to a directory and an initial blueprint script. The execution codes corresponding to each service operation information are respectively encapsulated in the corresponding initial blueprint scripts, thereby constructing the blueprint scripts; wherein, each blueprint script has a corresponding service operation information and its execution code. All the blueprint scripts are integrated to obtain the blueprint list.
8. An execution device for a microservice, characterized in that, It includes: A response module, a blueprint script module, and an operation module; The response module is used to obtain a service execution instruction. The blueprint script module is used to query the corresponding blueprint script according to the service execution instruction and call the master node in the host execution cluster to save the blueprint script; wherein, the blueprint script is a service execution file, and the host execution cluster includes a master node and slave nodes, and the master node is communicatively connected to the slave nodes. The execution module is used to distribute the blueprint script to the corresponding slave nodes in the host execution cluster through the master node so that the slave nodes execute the operations corresponding to the blueprint script.
9. A terminal device, characterized in that, It includes a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor. When the processor executes the computer program, it implements the execution method of the microservice according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes a stored computer program. When the computer program runs, it controls the device where the computer-readable storage medium is located to execute the execution method of the microservice according to any one of claims 1 to 7.