Detailed Description
The present invention will be described in further detail with reference to the drawings and examples, in order to make the objects, technical solutions and advantages of the present invention more apparent. It should be understood that the specific embodiments described herein are for purposes of illustration only and are not intended to limit the scope of the invention.
Referring to fig. 1, fig. 1 is a schematic diagram of a network topology of a system for managing component packages of a node package manager according to an embodiment of the present invention. For convenience of explanation, only the portions related to the present embodiment are shown.
The system as shown includes at least one terminal 110, a management server 120, and at least one source server 130, where the NPM package is stored in the source server 130. Terminal 110 includes, but is not limited to, a desktop computer, a notebook computer, and may be other terminals that may develop NPM component packages. The management server 120 may be an nmginx, also known as engine x, which is a high performance hypertext transfer protocol (Hyper Text Transport Protocol, HTTP) server and reverse proxy server.
The terminal 110 may communicate with the management server 120, and the management server 120 may communicate with the origin server.
Alternatively, when the terminal 110 knows the access address of the origin server 130, it can also communicate with the origin server 130.
The method for managing the component packages of the node package manager according to the present invention will be described in detail with reference to fig. 2 and 3, and the process of data interaction among the terminal, the management server and the source server will be described. Specifically, referring to fig. 1, fig. 1 is a flowchart illustrating an implementation of a method for managing a component package of a node package manager according to an embodiment of the present invention. The method of managing component packages of a node package manager as shown may comprise the steps of:
S101: the management server obtains request information sent by a terminal, and sends a control instruction to a source server storing a component package according to attribute information of the component package of a node package manager NPM contained in the request information; the control instruction includes the attribute information; the attribute information includes a unique identification of the component package and a current first version number.
When a developer needs to develop and test the NPM package, after the terminal establishes communication connection with the management server through the access address of the management server, the developer can input or select the unique identifier of the NPM package (NPM package) and the current first version number of the NPM package through the interactive interface displayed by the terminal, and trigger the terminal to generate request information. The first version number of the NPM package refers to the version number of the NPM package that currently needs to be downloaded. The NPM package refers to a package managed by NPM.
The request information is used for requesting to acquire a download address of an NPM component package to be debugged, the request information comprises attribute information of the NPM component package to be debugged and a terminal identifier, and the attribute information of the NPM component package to be debugged comprises a unique identifier of the NPM component package and a current first version number of the NPM component package. The terminal identity is a unique identity of the terminal, e.g. a media access control (Media Access Control, MAC) address. The NPM component package to be debugged refers to the NPM component package which needs to be downloaded and developed and tested by a developer.
The attribute information of the NPM component package to be debugged is used for acquiring the download address of the NPM component package, and the identifier of the terminal is used for returning the download address of the NPM component package to the terminal by the management server.
When the terminal generates the request information, the terminal transmits the generated request information to the management server.
The database of the management server stores the attribute information of the NPM package and the corresponding relation between the download addresses of the NPM package in advance, and the download addresses of the NPM package may be the storage addresses of the NPM package in the source server.
The method comprises the steps that a management server receives request information sent by each terminal, analyzes the request information, and obtains attribute information of NPM component packages contained in each request information from header (header) information of the request information to obtain unique identifiers and current first version numbers of the NPM component packages to be debugged; then, responding to the request information, searching a download address matched with the unique identifier and the current first version number from a database according to the unique identifier of the NPM component package to be debugged and the current first version number contained in the request information, establishing communication connection with the source server according to the matched download address, and sending a control instruction to the source server; the control instruction is used for indicating the source server to create a virtual running environment; the control instruction comprises attribute information of an NPM component package to be debugged; the attribute information includes a unique identification of the component package and a current first version number. The virtual execution environment is used for providing an execution environment for the NPM component package of the new version developed.
It is understood that the number of matched download addresses acquired by the management server may be one or at least two. When at least two matched download addresses are obtained, the management server can send a control instruction to the source server corresponding to the download address according to any one of the download addresses.
For example, when the management server receives first request information sent by the first terminal, a first control instruction is sent to the source server according to attribute information of a first NPM package contained in the first request information, so as to instruct the source server to create a virtual running environment for the first NPM package with a new version according to the first control instruction.
And when the management server receives second request information sent by the second terminal or the first terminal, sending a second control instruction to the source server according to the attribute information of the second NPM component package contained in the second request information so as to instruct the source server to create a virtual running environment for the second NPM component package with the new version according to the second control instruction.
S102: the source server creates a virtual running environment according to the control instruction sent by the management server, and returns a first notification message to the management server, wherein the first notification message comprises an identification of the virtual running environment.
When the source server receives a control instruction sent by the management server, a Docker mirror image is created in the source server for a new version of NPM component package corresponding to the attribute information of the NPM component package contained in the control instruction based on an application container engine Docker grammar, and a virtual running environment is obtained. The virtual operating environment is the same as the real operating environment in the origin server. The identifiers of the virtual running environments respectively created in the source servers can be docker1, docker2, docker3, … … and docker N. dockerN represents the identity of the Nth docker mirror.
After the virtual running environment is created, the source server sends a first notification message identifying that the virtual running environment is successfully created to the management server according to the access address of the management server, wherein the notification message comprises the identification of the created virtual running environment. The created virtual execution environment is used to execute the developed new version of NPM package. Wherein a virtual runtime environment provides a runtime environment for a version of the NPM package.
It can be understood that when the source server fails to create the virtual environment, a notification message for indicating that the virtual running environment is created is returned to the management server, so that when the management server acquires at least two matched download addresses, the control instruction for indicating that the source server corresponding to the download addresses creates the virtual running environment is sent by replacing the download addresses.
S103: the management server stores the attribute information and the identifier of the virtual running environment in an associated mode according to the first notification message, and returns a second notification message to the terminal according to the terminal identifier carried by the request information; the second notification information includes at least a download address of the component package of the first version number.
When receiving a notification message fed back by the source server and used for indicating that the virtual running environment is successfully created, the management server can store attribute information of the NPM component package and identification association of the virtual running environment created in the notification message.
Further, the management server can also store the download address of the NPM component package, the attribute information of the NPM component package and the identifier of the virtual running environment created in the notification message in an associated manner, so that the unique identifier of the NPM component package, the current version number, the download address of the NPM component package and the identifier of the virtual running environment created in the first notification message are stored in an associated manner, and when the management server receives the NPM component package of the new version sent by the terminal, the management server can determine the identifier of the virtual running environment matched with the NPM component package according to the unique identifier of the NPM component package.
It will be appreciated that when there are at least two virtual execution environments that match the unique identification of the NPM package, the management server may select any one of the virtual execution environments that is not used.
It may be understood that the management server may further associate and store the terminal identifier, attribute information of the NPM component package, and an identifier of the virtual running environment, so that when the management server receives the new version of the NPM component package uploaded by the terminal, the management server determines the virtual running environment corresponding to the new version of the NPM component package according to the terminal identifier, the unique identifier of the NPM component package, and the first version number of the downloaded NPM component package.
The management server may transmit the second notification information to the terminal transmitting the request message according to the identification of the terminal in the request message. The second notification information includes at least a download address of the NPM package of the first version number, the download address pointing to an origin server storing the NPM package of the first version. The download address is determined based on the unique identification of the NPM package and the current first version number. The second notification message is used for notifying the terminal to download the NPM component package according to the download address of the component package of the first version number.
When receiving a second notification message sent by the management server, the terminal downloads the NPM component package according to the download address of the NPM component package with the first version number in the second notification message, so that a developer can develop the NPM component package with the first version number on the basis of the NPM with the first version number, and the developer can develop the NPM component package with the new version on the basis of the NPM with the first version number through the interaction interface and trigger an uploading instruction. The terminal acquires the NPM component package of the new version uploaded by the developer and sends the NPM component package to the management server. The uploaded NPM component package includes at least a unique identification of the NPM component package.
S104: and the management server receives the component package uploaded by the terminal after downloading the component package of the first version number according to the download address, and operates the uploaded component package in a target virtual operation environment according to the association relation of the attribute information and the identifier of the virtual operation environment and the attribute information of the uploaded component package.
When the management server acquires the NPM package of the new version, the management server acquires the identification of the target virtual operation environment matched with the attribute information (unique identification and the first version number of the downloaded NPM package) of the uploaded NPM package according to the association relation between the attribute information of the NPM package and the identification of the virtual operation environment, determines the target source server to which the virtual operation environment belongs according to the identification of the target virtual operation environment, establishes communication connection with the target source server according to the access address of the target source server, and therefore stores the NPM package of the new version in the target virtual operation environment in the target source server, and operates the uploaded NPM package in the target virtual operation environment for testing.
It can be understood that when the terminal identifier, the attribute information of the NPM package and the identifier of the virtual running environment are stored in association in the management server, the identifier of the target virtual running environment, which is matched with the attribute information of the NPM package and the terminal identifier of the terminal uploading the NPM package, is obtained according to the association relationship among the terminal identifier, the attribute information of the NPM package and the identifier of the virtual running environment, so that the NPM package of the uploaded new version is stored in the target virtual running environment in the target source server, and the uploaded NPM package can be run in the target virtual running environment and tested.
According to the embodiment of the invention, when parallel development and testing are required to be carried out on the NPM component package, a control instruction is sent to the source server storing the NPM component package through the management server according to the request information sent by the terminal, and the source server is controlled to create a virtual operation environment for the NPM component package so as to operate and test the NPM component package with a new version in the virtual operation environment. By creating a virtual running environment in an original deployed source server according to actual demands, the development and test of multiple sets of parallel running environment supporting NPM component packages can be realized in the same source server without adding a new source server, and the hardware cost and maintenance cost required by deploying the new source server can be saved.
Referring to fig. 3, fig. 3 is a flowchart illustrating an implementation of a method for managing component packages of a node package manager according to another embodiment of the present invention. The method of managing component packages of a node package manager as shown may comprise the steps of:
s201: the management server obtains request information sent by the terminal, and creates a second version number for the component package according to a preset version naming strategy and attribute information of the component package of the node package manager NPM contained in the request information.
When a developer needs to develop and test the NPM package, after the terminal establishes communication connection with the management server through the access address of the management server, the developer can input or select the unique identifier and the current first version number of the NPM package (NPM package) through the interactive interface displayed by the terminal, and trigger the terminal to generate request information. The first version number of the NPM package refers to the version number of the NPM package that currently needs to be downloaded.
The request information is used for requesting to acquire a download address of the NPM component package to be debugged, the request information comprises attribute information of the NPM component package to be debugged and a terminal identifier, and the attribute information of the NPM component package to be debugged comprises a unique identifier and a current first version number. The terminal identity is a unique identity of the terminal, e.g. a media access control (Media Access Control, MAC) address. The NPM component package to be debugged refers to the NPM component package which needs to be downloaded and developed and tested by a developer.
The attribute information of the NPM component package to be debugged is used for acquiring the download address of the NPM component package, and the identifier of the terminal is used for returning the download address of the NPM component package to the terminal by the management server.
When the terminal generates the request information, the terminal transmits the generated request information to the management server.
The database of the management server stores the attribute information of the NPM package and the corresponding relation between the download addresses of the NPM package in advance, and the download addresses of the NPM package may be the storage addresses of the NPM package in the source server.
The method comprises the steps that a management server receives request information sent by each terminal, analyzes the request information, and obtains attribute information of NPM component packages contained in each request information from header (header) information of the request information to obtain unique identifiers and current first version numbers of the NPM component packages to be debugged; and then, respectively determining a second version number of the NPM component package of the updated version for each terminal according to the current first version number and the version naming strategy of the NPM component package, wherein the second version number is the version number of the new NPM component package obtained by developing the NPM component package based on the first version number by a developer. The control instruction sent by the management server further comprises a new version number of the NPM packet, so that when the source server receives the control instruction, a virtual running environment corresponding to the new version number is created.
The second version number is typically higher than the version number of the NPM package stored in the origin server.
It is understood that the number of matched download addresses acquired by the management server may be one or at least two.
S202: sending a control instruction to an origin server storing the component package; the control instruction includes the unique identification and the second version number.
The method comprises the steps that a management server obtains a unique identifier and a current first version number of an NPM component package to be debugged, searches a downloading address matched with the unique identifier and the current first version number from a database, establishes communication connection with a source server according to the matched downloading address, and sends a control instruction to the source server; the control instruction is used for indicating the source server to create a virtual running environment; the control instruction comprises attribute information of an NPM component package to be debugged; the attribute information includes a unique identification of the component package and a current first version number. The virtual execution environment is used for providing an execution environment for the NPM component package of the new version developed.
When at least two matched download addresses are obtained, the management server can send a control instruction to the source server corresponding to the download address according to any one of the download addresses.
For example, when the management server receives first request information sent by the first terminal, a first control instruction is sent to the source server according to attribute information of a first NPM package contained in the first request information, so as to instruct the source server to create a virtual running environment for the first NPM package with a new version according to the first control instruction.
And when the management server receives second request information sent by the second terminal or the first terminal, sending a second control instruction to the source server according to the attribute information of the second NPM component package contained in the second request information so as to instruct the source server to create a virtual running environment for the second NPM component package with the new version according to the second control instruction.
S203: the source server creates a virtual running environment according to the control instruction sent by the management server, and returns a first notification message to the management server, wherein the first notification message comprises an identification of the virtual running environment.
In this embodiment, S203 is the same as S102 in the previous embodiment, and please refer to the description related to S102 in the previous embodiment, which is not repeated here.
Wherein, the source server executes S204 when the virtual running environment is successfully created according to the control instruction.
S204: the management server stores the unique identifier, the second version number contained in the first notification message and the identifier of the virtual running environment in an associated mode according to the first notification message, and returns a second notification message to the terminal according to the terminal identifier carried by the request information; the second notification information includes at least a download address of the component package of the first version number, the second version number.
In this embodiment, S204 is different from the previous embodiment S103 in that the management server stores the unique identifier of the NPM package, the first version number, the second version number, and the identifier of the virtual running environment in association, and the second notification message sent by the management server to the terminal includes the download address of the NPM package of the first version number and the second version number of the NPM package.
Optionally, the second notification message may include a download address of the NPM component package of the first version number, an identification of the virtual execution environment associated with the second version number. The download address of the NPM package of the first version number is used to download the NPM package of the first version and determine an access address of a target source server corresponding to the identifier of the virtual running environment. Typically, the source server storing the NPM package of the first version number and the target server corresponding to the identity of the virtual execution environment associated with the second version number are the same source server.
It will be appreciated that when the source server storing the NPM package of the first version number and the target server corresponding to the identifier of the virtual execution environment associated with the second version number are different source servers, the second notification message may further include the access address of the target source server corresponding to the identifier of the virtual execution environment associated with the second version number
When receiving a second notification message sent by the management server, the terminal downloads the NPM component package according to the download address of the NPM component package with the first version number in the second notification message, so that a developer can develop the NPM component package with the second version based on the NPM with the first version number, set the new version number of the NPM package newly developed as the second version number, and can develop the NPM component package with the second version based on the NPM with the first version number through the interaction interface and trigger an uploading instruction. And the terminal acquires the NPM component package of the second version uploaded by the developer and sends the NPM component package to the management server. The uploaded NPM component package includes a unique identification of the NPM component package and a second version number, and may also include a first version number of the NPM component package.
It can be understood that when the source server receives the control instruction sent by the management server and fails to create the virtual running environment according to the control instruction, a third notification message is returned to the management server; the third notification message is used for identifying failure of creating the virtual running environment and notifying the management server of replacing the source server, so that when the management server obtains at least two download addresses matched with the attribute information of the NPM component package of the first version, the replacement download address sends a control instruction for indicating the source server corresponding to the download address to create the virtual running environment.
S205: and the management server receives the component package uploaded by the terminal after downloading the component package of the first version number according to the downloading address, and operates the uploaded component package in a target virtual operation environment according to the unique identifier, the association relation of the second version number and the identifier of the virtual operation environment and the attribute information of the uploaded component package.
When the management server acquires the NPM package uploaded by the terminal, according to the association relation of the unique identifier of the NPM package, the second version number and the identifier of the virtual operation environment, the management server acquires the identifier of the target virtual operation environment which is matched with the unique identifier contained in the attribute information of the NPM package uploaded by the terminal and the second version number, determines the target source server to which the virtual operation environment belongs according to the identifier of the target virtual operation environment, establishes communication connection with the target source server according to the access address of the target source server, and stores the uploaded NPM package of the second version into the target virtual operation environment in the target source server, and operates the uploaded NPM package in the target virtual operation environment for testing.
In another embodiment, when the second notification message may include the download address of the NPM component package of the first version number, the identification of the virtual execution environment associated with the second version number, S206 may be further included after S204: the target source server receives the component package uploaded by the terminal according to the second notification message, and operates the uploaded component package in a target virtual operation environment according to the unique identifier, the second version number, the association relation among the identifiers of the virtual operation environment and the attribute information carried by the uploaded component package; the uploaded package is developed based on the package of the first version; the target source server is a source server that creates a virtual execution environment corresponding to the identification of the virtual execution environment associated with the second version number.
When receiving a second notification message sent by the management server, the terminal downloads the package of the first version number according to the download address of the NPM package of the first version number contained in the second notification message, so that a developer develops the package of the first version number on the basis of the NPM of the first version number, sets the new version number of the new developed NPM package as a second version number, and can develop the NPM package of the second version on the basis of the NPM of the first version number through the interaction interface and trigger an uploading instruction.
In an embodiment, when the source server storing the NPM package of the first version and the source server creating the virtual running environment of the NPM package of the second version are the same server, when the terminal detects an upload instruction triggered by the developer, the terminal may access the target source server according to the download address of the NPM package of the first version number, upload the NPM package of the new version uploaded by the developer to the target source server, and notify the target source server to store the NPM package of the second version according to the identifier of the virtual running environment associated with the second version number included in the second notification message. The uploaded NPM component package includes a unique identification of the NPM component package and a second version number, and may also include a first version number of the NPM component package.
In another embodiment, when the source server storing the NPM package of the first version and the source server creating the virtual running environment of the NPM package of the second version are different servers, when the terminal detects the uploading instruction triggered by the developer, the terminal obtains the access address of the target source server corresponding to the identifier of the virtual running environment included in the second notification message according to the request to the management server, so that the management server can determine the target source server corresponding to the identifier of the virtual running environment included in the second notification message according to the identifier of the virtual running environment created by each source server, and therefore the access address of the target source server is returned to the terminal.
When the terminal obtains the access address of the source server corresponding to the identifier of the virtual running environment which is associated with the second version number, the terminal accesses the target source server according to the access address of the target source server and uploads the NPM component package newly developed by the developer to the target source server. The NPM component package carries attribute information, wherein the attribute information comprises a unique identifier and a second version number of the NPM component package, and the NPM component package also carries an identifier of a virtual running environment associated with the second version number.
When the target source server acquires the NPM component package uploaded by the terminal, the uploaded NPM component package is stored into a target virtual operation environment corresponding to the carried virtual operation environment identifier, so that the NPM component package is operated and tested in the target virtual operation environment.
Optionally, in order to fully utilize the resources in the source server, avoiding that the virtual running environment that does not need to continue to run the NPM component package occupies the system resources, after S205 or S206, S207 may further include: when the management server detects that the uploaded package is tested, a deletion notification is sent to the source server according to the identifier of the virtual running environment corresponding to the uploaded package; the deletion notification is used for deleting the virtual running environment corresponding to the identifier of the virtual running environment.
For example, when detecting a notification message triggered by a terminal and used for identifying that the test of the uploaded component package is completed (the notification message can be generated by a developer triggering the terminal), the management server determines the identification of the virtual running environment matched with the component package according to the second version information of the component package carried by the notification message, and sends a deletion notification to the source server creating the matched virtual running environment according to the identification of the matched virtual running environment, so that when the source server receives the deletion notification, the source server deletes the corresponding virtual running environment according to the identification of the virtual running environment contained in the deletion notification.
In another embodiment, when the NPM package running in the virtual running environment is preset with a test time, the source server may delete the virtual running environment that improves the running environment for the NPM package when detecting that the current time reaches an end time corresponding to the test time.
According to the embodiment of the invention, when parallel development and testing are required to be carried out on the NPM component package, a control instruction is sent to the source server storing the NPM component package through the management server according to the request information sent by the terminal, and the source server is controlled to create a virtual operation environment for the NPM component package so as to operate and test the NPM component package with a new version in the virtual operation environment. By creating a virtual running environment in an original deployed source server according to actual demands, the development and test of multiple sets of parallel running environment supporting NPM component packages can be realized in one source server without adding a new source server, and the hardware cost and maintenance cost required by deploying the new source server can be saved.
It should be understood that the sequence number of each step in the foregoing embodiment does not mean that the execution sequence of each process should be determined by the function and the internal logic, and should not limit the implementation process of the embodiment of the present invention.
Fig. 4 is a schematic diagram of a server according to an embodiment of the present invention. As shown in fig. 4, the server 4 of this embodiment includes: a processor 40, a memory 41 and a computer program 42 stored in the memory 41 and executable on the processor 40. The steps of the method embodiment of the management node package manager of each server described above are implemented when the processor 40 executes the computer program 42, for example, for a management server, the processor 40 executes steps S101, S103-S104 shown in fig. 2, and for an origin server, the processor 40 executes step S102 shown in fig. 2.
Illustratively, the computer program 42 may be partitioned into one or more units that are stored in the memory 41 and executed by the processor 40 to complete the present invention. The one or more elements may be a series of computer program instruction segments capable of performing a specific function describing the execution of the computer program 42 in the server 4. For example, the computer program 42 may be divided into a script execution unit, an acquisition unit, a merging unit, and a generation unit, each unit specifically functioning as described above.
The server may include, but is not limited to, a processor 40, a memory 41. It will be appreciated by those skilled in the art that fig. 4 is merely an example of a server 4 and is not meant to be limiting as to the server 4, and may include more or fewer components than shown, or may combine certain components, or different components, e.g., the server may also include an input-output server, a network access server, a bus, etc.
The processor 40 may be a central processing unit (Central Processing Unit, CPU), other general purpose processors, digital signal processors (Digital Signal Processor, DSP), application specific integrated circuits (Application Specific Integrated Circuit, ASIC), off-the-shelf programmable gate arrays (Field-Programmable Gate Array, FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, or the like. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
The memory 41 may be an internal storage unit of the server 4, such as a hard disk or a memory of the server 4. The memory 41 may be an external storage server of the server 4, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card) or the like, which are provided on the server 4. Further, the memory 41 may also include both an internal storage unit of the server 4 and an external storage server. The memory 41 is used for storing the computer program as well as other programs and data required by the server. The memory 41 may also be used for temporarily storing data that has been output or is to be output.
The above embodiments are only for illustrating the technical solution of the present invention, and not for limiting the same; although the invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical scheme described in the foregoing embodiments can be modified or some technical features thereof can be replaced by equivalents; such modifications and substitutions do not depart from the spirit and scope of the technical solutions of the embodiments of the present invention, and are intended to be included in the scope of the present invention.