Function calculation platform operation method, device, equipment and storage medium

By introducing source code compilation components on the function computing platform, dynamically compiling and building function images, users' needs for local compilation and packaging are solved, and the cost reduction and unified experience are achieved.

CN114546400BActive Publication Date: 2025-07-29CHINA MERCHANTS BANK
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210139815.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-02-15
Publication Date
2025-07-29
Estimated Expiration
2042-02-15

AI Technical Summary

Technical Problem

When existing functional computing platforms support certain languages, they require users to compile and package locally, resulting in high usage costs and poor experience.

Method used

By adding source code compilation components to the function computing platform, dynamically compile function source code to generate bytecode files, and build function images to automatically complete the compilation and packaging process.

Benefits of technology

Reduces user usage costs, improves deployment efficiency, makes the experience of different programming languages consistent, and reduces the steps and time of manual participation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114546400B_ABST
    Figure CN114546400B_ABST
Patent Text Reader

Abstract

The present invention discloses a method, apparatus, device and storage medium for running a function computing platform, belonging to the technical field of cloud services. In the present invention, by receiving function source code, when the function source code is of a target language type, it is compiled by a source code compilation component to obtain a bytecode file, and a corresponding function image is constructed, and the function image corresponding to the function source code is deployed and run through a cluster management background. The present invention changes the work of compiling and packaging function source code by the user locally to automatic processing by the function computing platform, thereby simplifying the process of the user publishing function source code, reducing the user's usage cost, and enabling the user to have a consistent experience when publishing functions in different programming languages on the platform.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of cloud services, and particularly to a method, device, equipment, and storage medium for running a function computing platform. Background Art

[0002] In the era of cloud computing, a large number of concepts in the form of XaaS have emerged. From IaaS (Infrastructure as a Service), PaaS (Platform as a Service), SaaS (Software as a Service) to CaaS (Containers as a Service) led by container cloud, and then to the popular microservices architecture, they are all trying to abstract various software and hardware resources, etc. into a service for developers to use, so that they no longer have to worry about infrastructure, resource requirements, middleware, etc., and can better focus on their business while reducing mental burden.

[0003] However, for current function computing platforms in the industry, when supporting some languages, users need to first compile and package the source code in a specified format locally, and then upload the packaged file to the platform for deployment and operation. For example, for the function as a service (FaaS) function computing platform, when supporting the Java language, users need to compile and package locally according to the platform requirements format, and only relatively professional technical personnel can use the FaaS function computing platform to deploy functions. Therefore, when users use existing function computing platforms to run some functions, the usage cost is relatively high and the experience is poor. Summary of the Invention

[0004] The main purpose of the present invention is to provide a method, device, equipment, and storage medium for running a function computing platform, aiming to solve the problem that it is time-consuming and laborious to publish function source code on the function computing platform.

[0005] To achieve the above purpose, the present invention provides a method for running a function computing platform, and the method for running the function computing platform includes the following steps:

[0006] Obtain function source code;

[0007] When the function source code is of a target language type, dynamically compile the function source code through a source code compilation component to obtain a bytecode file;

[0008] Based on the bytecode file, construct a function image corresponding to the function source code;

[0009] Upload the function image to the cluster management background and deploy and run it through the cluster management background.

[0010] Optionally, before the step of obtaining the source code of the function, the method further includes:

[0011] Obtaining first definition data of the input stream of the source code file and second definition data of the output stream of the result file;

[0012] Based on the first definition data and the second definition data, constructing a file manager, where the file manager is a part of the source code compilation component.

[0013] Optionally, when the target language type is a Java function, before the step of obtaining the source code of the function, the method further includes:

[0014] Creating a custom class loader, where the custom class loader is used to temporarily store the compiled Java bytecode and generate subsequent class files;

[0015] Obtaining a dynamic compilation toolkit;

[0016] Creating a dependency package retriever, where the dependency package retriever is used to retrieve dependency packages during dynamic compilation;

[0017] Creating an exception listener, where the exception listener is used to capture exception information and return the exception information to the user;

[0018] Based on the exception listener, the custom class loader, the dependency package retriever, and the dynamic compilation toolkit, constructing the source code compilation component.

[0019] Optionally, after the step of obtaining the source code of the function, the method further includes:

[0020] Obtaining an identification field in the source code of the function;

[0021] Based on the identification field, determining whether the source code of the function is of the target language type.

[0022] Optionally, before the step of dynamically compiling the source code of the function through the source code compilation component to obtain a bytecode file when the source code of the function is of the target language type, the method further includes:

[0023] Creating a temporary file directory corresponding to the source code of the function, where the temporary file directory is used to store intermediate files generated by compiling the source code of the function.

[0024] Optionally, the step of constructing a function image corresponding to the source code of the function based on the bytecode file includes:

[0025] Obtaining a specified directory;

[0026] Based on the specified directory, package the bytecode file according to the specified directory and generate a package file.

[0027] Read the package file in the form of a byte array to obtain package data;

[0028] Based on the package data, construct a function image corresponding to the function source code

[0029] Optionally, after the step of reading the package file in the form of a byte array to obtain package data, the method further includes:

[0030] Delete the intermediate file and the package file.

[0031] Optionally, the step of when the function source code is of the target language type, dynamically compile the function source code through a source code compilation component to obtain a bytecode file includes:

[0032] When the function source code is of the target language type, send a compilation request to the source code compilation component, and the source code compilation component can receive one or more compilation requests;

[0033] Based on the compilation request, dynamically compile the function source code through the source code compilation component to obtain a bytecode file.

[0034] In addition, to achieve the above object, the present invention further provides a function computing platform operating device, and the device includes:

[0035] An acquisition module for acquiring function source code;

[0036] A compilation module for, when the function source code is of the target language type, dynamically compile the function source code through a source code compilation component to obtain a bytecode file;

[0037] An image construction module for constructing a function image corresponding to the function source code based on the bytecode file;

[0038] A deployment module for uploading the function image to a cluster management background and deploying and running it through the cluster management background.

[0039] Optionally, the acquisition module is further configured to:

[0040] Obtain first definition data of a source code file input stream and second definition data of a result file output stream;

[0041] Based on the first definition data and the second definition data, construct a file manager, and the file manager is a part of the source code compilation component.

[0042] Optionally, the acquisition module is further configured to:

[0043] Create a custom class loader which is used to temporarily store the compiled Java bytecode and generate subsequent class files;

[0044] Obtain a dynamic compilation toolkit;

[0045] Create a dependency package retriever which is used to retrieve dependency packages during dynamic compilation;

[0046] Create an exception listener which is used to capture exception information and return the exception information to the user;

[0047] Build the source code compilation component based on the exception listener, the custom class loader, the dependency package retriever, and the dynamic compilation toolkit.

[0048] Optionally, the compilation module is further used for:

[0049] Obtain the identification field in the function source code;

[0050] Based on the identification field, determine whether the function source code is of the target language type.

[0051] Optionally, the compilation module is further used for:

[0052] Create a temporary file directory corresponding to the function source code, which is used to store the intermediate files generated by the compilation of the function source code.

[0053] Optionally, the compilation module is further used for:

[0054] Obtain a specified directory;

[0055] Based on the specified directory, package the bytecode files according to the specified directory and generate a package file.

[0056] Read the package file in the form of a byte array to obtain package data;

[0057] Based on the package data, build a function image corresponding to the function source code.

[0058] Optionally, the compilation module is further used for:

[0059] Delete the intermediate files and the package file.

[0060] Optionally, the compilation module is further used for:

[0061] When the function source code is of the target language type, send a compilation request to the source code compilation component, and the source code compilation component can receive one or more compilation requests;

[0062] Based on the compilation request, the source code compilation component dynamically compiles the function source code to obtain a bytecode file.

[0063] In addition, to achieve the above object, the present invention further provides a function computing platform operating device, the device includes: a memory, a processor, and a function computing platform operating program stored on the memory and executable on the processor, the function computing platform operating program is configured to implement the steps of the function computing platform operating method as described above.

[0064] In addition, to achieve the above object, the present invention further provides a storage medium, on which a function computing platform operating program is stored, and when the function computing platform operating program is executed by a processor, it implements the steps of the function computing platform operating method as described above.

[0065] The embodiments of the present invention disclose a function computing platform operating method, device, equipment and storage medium. The present invention receives a function source code. If the function source code is a function of the target language type, it is compiled by a source code compilation component to obtain a bytecode file, and a corresponding function image is constructed, and the function image is deployed and run through a cluster management background. The present invention mainly adds a component for dynamically compiling and packaging the function source code on the function computing platform, and hands over the work that originally needed to be preprocessed by the user locally to the platform to automatically complete, so as to achieve the purpose of reducing the user's usage cost and being consistent with the usage experience of other programming languages. BRIEF DESCRIPTION OF THE DRAWINGS

[0066] Figure 1 is a schematic structural diagram of a function computing platform operating device in the hardware operating environment involved in the embodiment of the present invention;

[0067] Figure 2 is a schematic flowchart of the first embodiment of the function computing platform operating method of the present invention;

[0068] Figure 3 is a system architecture diagram of the FaaS platform supporting the Java function runtime in an embodiment of the function computing platform operating method of the present invention;

[0069] Figure 4 is a flowchart of the deployment and operation of a Java function in an embodiment of the function computing platform operating method of the present invention;

[0070] Figure 5 is a schematic flowchart of constructing a file manager in an embodiment of the function computing platform operating method of the present invention;

[0071] Figure 6 is an architecture diagram of a Java source code dynamic compilation component in an embodiment of the function computing platform operating method of the present invention.

[0072] Figure 7 A flowchart for determining whether the function source code is of the target language type according to an embodiment of the method for operating a function computing platform of the present invention;

[0073] Figure 8 A dynamic compilation flowchart according to an embodiment of the method for operating a function computing platform of the present invention;

[0074] Figure 9 A schematic diagram of functional modules according to an embodiment of the method for operating a function computing platform of the present invention.

[0075] The implementation, functional features and advantages of the present invention will be further described with reference to the embodiments and the accompanying drawings. Detailed implementation manners

[0076] It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.

[0077] Referring to Figure 1 , Figure 1 A schematic structural diagram of a function computing platform operating device for the hardware operating environment involved in the embodiment solution of the present invention.

[0078] As Figure 1 shown, the function computing platform operating device may include: a processor 1001, such as a Central Processing Unit (CPU), a communication bus 1002, a user interface 1003, a network interface 1004, and a memory 1005. Among them, the communication bus 1002 is used to realize the connection and communication between these components. The user interface 1003 may include a display screen (Display) and an input unit such as a keyboard (Keyboard). Optionally, the user interface 1003 may further include a standard wired interface and a wireless interface. The network interface 1004 may optionally include a standard wired interface and a wireless interface (such as a Wireless-FIdelity (WI-FI) interface). The memory 1005 may be a high-speed Random Access Memory (RAM) memory or a stable non-volatile memory (Non-Volatile Memory, NVM), such as a disk memory. Optionally, the memory 1005 may also be a storage device independent of the aforementioned processor 1001.

[0079] Those skilled in the art can understand that Figure 1 the structure shown in

[0080] AsFigure 1 As shown in Figure 1 , the memory 1005, which is a storage medium, may include an operating system, a data storage module, a network communication module, a user interface module, and a function computing platform running program.

[0081] In Figure 1 the function computing platform running device shown in Figure 1 , the network interface 1004 is mainly used for data communication with other devices; the user interface 1003 is mainly used for data interaction with users; the processor 1001 and the memory 1005 in the asset level prediction device of the present invention may be arranged in the function computing platform running device, and the function computing platform running device calls the function computing platform running program stored in the memory 1005 through the processor 1001 and executes the function computing platform running method provided by the embodiments of the present invention.

[0082] Embodiments of the present invention provide a function computing platform running method. Referring to Figure 2 , Figure 2 it is a flowchart of the first embodiment of a function computing platform running method of the present invention.

[0083] In this embodiment, the function computing platform running method includes:

[0084] Step S10, receive a function source code; obtain the function source code;

[0085] Step S20, when the function source code is of a target language type, dynamically compile the function source code through a source code compilation component to obtain a bytecode file;

[0086] Step S30, build a function image corresponding to the function source code based on the bytecode file;

[0087] Step S40, upload the function image to a cluster management background and deploy and run it through the cluster management background.

[0088] In this embodiment, in order to solve the problem that when uploading function source code for applications on some function computing platforms, there are many steps that require a lot of manual participation, which is time-consuming and laborious, the method for running a function computing platform of the present invention is proposed. Usually, the cloud platform submits the entire application, while this embodiment is directed to a function computing platform that receives only the function source code and does not contain information such as configuration files. For example: The Function as a service (FaaS) function computing platform is also the FaaS function computing platform. The characteristic of FaaS is that the application logic units in FaaS can all be regarded as a function. Developers only focus on how to implement these logics without having to consider performance optimization in advance, so that the work focuses on this function rather than the overall application. In a general function computing platform, developers directly provide services externally by writing, running, and managing one or more functions, and allow the functions to be called in multiple ways such as microservices, HTTP interfaces, and event source triggers. This can reduce the time cost of traditional application release and deployment, and greatly reduce the time cost of developers outside of code development. However, when deploying some functions, there will be a problem that the submitted function source code cannot be directly deployed by the function computing platform, such as Java and other languages with the same problem. In the prior art, before a Java function is deployed on the FaaS platform, the user needs to compile and package it locally according to the platform requirements format. When the user writes functions in interpreted languages such as Python and NodeJs on the FaaS platform, there is no need for local compilation and packaging. The function source code can be directly submitted on the platform for deployment and operation, and the user experience is inconsistent with that of Java functions. Therefore, this embodiment provides a mechanism for automatically compiling, packaging, and deploying functions on a function computing platform, which eliminates the need for the user to compile and package the source code locally, reduces the user's usage cost, and improves the deployment efficiency.

[0089] The following is a detailed description of each step:

[0090] Step S10, obtain the function source code;

[0091] In one embodiment, the function source code is obtained. It can be understood that when the user submits the function source code on the function computing platform, the function computing platform receives this function source code. Specifically, the user imports the function source code at the user function input end, or directly writes the code on the platform and then imports it from the user function input end. It should be noted that the function computing platform can support the uploading or writing of one or more source codes, and the functions of the function computing platform can be increased or decreased according to actual needs without affecting the implementation of this embodiment. Since there are the above problems when directly uploading the source code in the Java language and it is widely used, in this embodiment, the function computing platform needs to support at least the writing or uploading of Java functions.

[0092] Step S20, when the function source code is of the target language type, compile the function source code through the source code compilation component to obtain a bytecode file;

[0093] In one embodiment, when the function source code is of the target language type, compile the function source code through the source code compilation component to obtain a bytecode file. Among them, the bytecode file is a binary file containing an executable program, consisting of a sequence of op code / data pairs. Taking the target language type as a Java function as an example, compile the function source code through the Java source code compilation component to generate a bytecode file. It should be noted that according to the characteristics of Java functions, as long as the corresponding platform is equipped with a specific Java runtime environment, Java programs can run. Although the internal implementation details of the Java virtual machines on each platform are different, the bytecode content they execute is the same. Java needs to be compiled into a.class file by Javac and then translated and run by the jvm. When the Java source code is successfully compiled into bytecode, if you want to run it on different platforms, there is no need to compile it again. That is to say, the Java source code only needs to be compiled once to run everywhere. This is the idea of "Write Once, Run Anywhere". Among them, a Java function is an independent code block defined in a class to implement a certain function. Therefore, compiling the Java source code into a bytecode file enables the uploaded Java source code to run in various environments. To compile a Java function, you can use the tool package (tools) provided by Java itself. For example, JavaCompiler can be used to compile the Java function. Therefore, the tool package can be connected in the Java source code compilation component. In addition, for other types of functions with similar characteristics, compilation can also be achieved by connecting the tool package.

[0094] Step S30, based on the bytecode file, construct a function image corresponding to the function source code;

[0095] In one embodiment, a function image corresponding to the function source code is constructed based on the bytecode file. It can be understood that a function image is required to be deployed into a container for application. Therefore, it is necessary to construct a function image corresponding to the function source code based on the bytecode file. Taking a Java function as an example, the compiled bytecode file is packaged into a JAR file. A JAR file is an archive file constructed in the ZIP format with the file extension.jar. Combining the JAR file and the JDK together creates a container image. The JDK is a software development kit for the Java language, mainly used for Java applications on mobile devices and embedded devices. The JDK is the core of the entire Java development, and it includes the Java runtime environment (JVM + Java system libraries) and Java tools. Specifically, the Docker command is used to create an image from the Dockerfile and the locally built JAR file is used.

[0096] Step S40, upload the function image to the cluster management background and deploy and run it through the cluster management background.

[0097] In one embodiment, the function image is uploaded to the cluster management background, and the function is deployed and run through the cluster management background. It can be understood that the underlying cluster of the function computing platform receives the image and can deploy it after getting the image. However, the image itself does not provide function calls. Therefore, it also needs to be deployed into the container of the application. It is equivalent that the image itself is static and becomes active after deployment. In this embodiment, by deploying the function image into the application container, the process from the function source code to the application is realized, and the customer can set multiple triggers to determine when the function runs. When the event condition is met, the function will be triggered to run. For example, if it is necessary to perform an operation on data at a certain fixed time point, a trigger is set to trigger the function function regularly. Optionally, after deployment, the cluster management background will return a message indicating success or failure of the deployment, enabling the user to receive feedback in a timely manner.

[0098] As Figure 3 shown, Figure 3 is a schematic diagram of the system architecture of the FaaS platform supporting the Java function runtime in one embodiment of the method for running the function computing platform of the present invention. In this embodiment, the function computing platform is the FaaS function computing platform, and the target language type is the Java function. The entire platform system includes four parts: the FaaS underlying cluster, the FaaS cluster management background, the user function input end, and the Java source code compilation component. The logical architecture relationship of the four parts is as follows:

[0099] The user submits the function source code at the function input end. After the FaaS cluster management background receives the source code, if it is a Java function, the source code is submitted to the Java source code compilation component. This component compiles and packages the source code in accordance with the specified format, and then the package file is returned to the FaaS cluster management background in the form of bytecode. Finally, the FaaS management background calls the underlying FaaS cluster operation instructions to deploy and run the Java function. Among them, the FaaS underlying cluster includes multiple containers, and the image is built layer by layer. Only the top layer is readable and writable, that is, the readable and writable layer, and the following is immutable.

[0100] Refer to Figure 4 , Figure 4 is the function deployment and operation flowchart of an embodiment of the function calculation platform operation method of the present invention. In this embodiment, the target language type is taken as a Java function for example. After the user submits the function source code, the function source code is received, and it is judged whether the function source code is a Java function. If it is judged to be a Java function, a compilation request is sent to the Java source code compilation component. Through the Java source code compilation component, the function source code is compiled to obtain a bytecode file. Based on the bytecode file, a function image corresponding to the function source code is built, and the function image is uploaded to the function as a service FaaS cluster management background, and the underlying FaaS cluster operation instructions are called through the FaaS cluster management background to deploy and run.

[0101] In this embodiment, by obtaining the function source code, when the function source code is of the target language type, the function source code is compiled through the source code compilation component to obtain a bytecode file, and then according to the bytecode file, a function image corresponding to the function source code is built. After that, the function image is uploaded to the cluster management background and deployed and run through the cluster management background, which can automatically deploy and run the function source code uploaded by developers and provide more convenient services for developers.

[0102] Furthermore, based on the first embodiment of the function calculation platform operation method of the present invention, the second embodiment of the function calculation platform operation method of the present invention is proposed.

[0103] Refer to Figure 5 , Figure 5 is the schematic flowchart of building a file manager in an embodiment of the function calculation platform operation method of the present invention. The difference between the second embodiment of the function calculation platform operation method of the present invention and the first embodiment of the function calculation platform operation method of the present invention is that before the step of receiving the function source code, the method further includes:

[0104] Step S11, obtaining the first defined data of the source code file input stream and the second defined data of the result file output stream;

[0105] Step S12: Based on the first definition data and the second definition data, construct a file manager.

[0106] In one embodiment, define the source code file input stream, that is, define the input source of the source code file to confirm the source of the source code file, and define the result file output stream, that is, define the location where the result file is to be output. It can be understood that the platform needs to know where the function source code comes from or how it is obtained. Therefore, the first definition data of the source code file input stream is the data that defines the file input location, method, etc. The result file is the file generated by compilation. For example, the JAR package generated after compiling and finally packaging the uploaded Java function source code. However, the system definitely cannot directly transfer this JAR package file but needs to convert this JAR package file into a data stream for transmission. Therefore, define the file output stream, and the corresponding definition file is the second definition data. First, obtain the first definition data and the second data, and then construct a file manager to manage the input and output files.

[0107] Step S12: Based on the first definition data and the second definition data, construct a file manager, and the file manager is a part of the source code compilation component.

[0108] In one embodiment, construct a file manager according to the first definition data and the second definition data set by the user or preset. The file manager is a key component that connects the entire process. Whether it is the input source code, the intermediate generated temporary files, or the final result data stream, they are all considered files in the system. The file manager is responsible for connecting the entire process, including defining how to receive the source code file, how to generate intermediate temporary files, and how to process the final result file, which all fall within the scope of business of the file manager.

[0109] Further, in one embodiment, when the target language type is a Java function, before the step of obtaining the function source code, the method further includes:

[0110] Step S13: Create a custom class loader, and the custom class loader is used to temporarily store the compiled Java bytecode and generate subsequent class files;

[0111] In one embodiment, before the step of sending a compilation request to the Java source code compilation component, it is also necessary to construct the Java source code compilation component, wherein a custom class loader needs to be created. Loading refers to reading the class file of a class into memory and creating a java.lang.Class object for it. That is to say, when any class is used in the program, the system will create a java.lang.Class object for it. The loading of classes is completed by the class loader, and the class loader is usually provided by the JVM. The JVM is the Java virtual machine, which is a virtual computer used to execute Java bytecode (in binary form). The JVM loads Java applications through the class loader (Class Loader) and executes them through the Java API. After compilation, a bytecode will be obtained, and then a.class file needs to be created, and then the bytecode will be written into the.class file.

[0112] Step S14, obtain the dynamic compilation toolkit;

[0113] In one embodiment, before sending the compilation request, it is also necessary to obtain the dynamic compilation toolkit. The "tools" required for dynamic compilation are stored in the tools.jar package, which can implement the compilation of Java source code and help expand static applications. The main classes provided in this package can obtain the source code from Java String, StringBuffer or other CharSequences and compile it.

[0114] Step S15, create a dependency package retriever, where the dependency package retriever is used to retrieve dependency packages during dynamic compilation;

[0115] In one embodiment, a dependency package retriever is created. It can be understood that implementing the dynamic compilation of Java functions not only requires the toolkit, but also other related dependency packages. Usually, the dependency package files are packaged into JAR packages. The dependency package retriever is to tell the compiler where to find these dependent JAR packages during dynamic compilation.

[0116] Step S16, create an exception listener, where the exception listener is used to capture exception information and return the exception information to the user;

[0117] In one embodiment, before sending a compilation request to the Java source code dynamic compilation component, it is also necessary to create an exception listener. It can be understood that exceptions may occur during the execution of any system. This listener is to capture the exception information when the system encounters an exception and return this exception information to the user so that the user knows what the exception is, etc. Thus, the monitoring and management of exception information are realized. Therefore, in this embodiment, by setting up an exception listener, the management and monitoring of the compilation process are realized.

[0118] Step S17, construct the Java source code dynamic compilation component based on the file manager, the exception listener, the custom class loader, the dependency package retriever, and the dynamic compilation toolkit.

[0119] In one embodiment, the file manager, the exception listener, the custom class loader, the dependency package retriever, and the dynamic compilation toolkit are combined as the Java source code dynamic compilation component. It can be understood that each of the file manager, the exception listener, the custom class loader, the dependency package retriever, and the dynamic compilation toolkit has its own role in the compilation process.

[0120] Refer to Figure 6 for the description of this embodiment. Figure 6 FIG. is the architecture diagram of the source code compilation component of an embodiment of the method for running a function computing platform according to the present invention. In this embodiment, a Java source code dynamic compilation component capable of performing Java function compilation is taken as an example. The Java source code dynamic compilation component in this embodiment is one kind of the source code dynamic compilation component. The Java source code dynamic compilation component includes a file manager, an exception listener, and a custom dynamic compiler. The custom dynamic compiler includes a dependency package retriever and a dynamic compilation toolkit. In addition, a custom class loader is not shown in the figure. In this embodiment, the compilation process of the Java source code is as follows: First, obtain the jar package through the dependency package retriever, then compile it through the dynamic compilation toolkit to obtain the bytecode file, and cache the bytecode file through the custom class loader, as well as generate the subsequent class file.

[0121] In this embodiment, by obtaining the first defined data of the source code file input stream and the second defined data of the result file output stream, and constructing the file manager according to the first defined data and the second defined data, the process management from the input to the output of the function source code is realized. And when the target language type is a Java function, by creating a custom class loader, an exception listener, a dependency package retriever, and a dynamic compilation toolkit, and combining them to construct the source code compilation component, and realizing the automatic compilation of the Java function source code on the platform, the efficiency of platform deployment and operation when the user submits the Java function source code is improved.

[0122] Refer to Figure 7 , Figure 7 is the flow diagram for determining whether the function source code is of the target language type in an embodiment of the method for running a function computing platform according to the present invention. Further, based on the first and second embodiments of the method for running a function computing platform according to the present invention, the third embodiment of the method for running a function computing platform according to the present invention is proposed.

[0123] The difference between the third embodiment of the method for running a function computing platform and the first and second embodiments of the method for running a function computing platform is that after the step of obtaining the function source code, the method further includes:

[0124] Step S21, obtaining an identification field in the function source code;

[0125] Step S22, based on the identification field, determining whether the function source code is of a target language type.

[0126] In one embodiment, an identification field in the function source code is obtained, and based on the identification field, it is determined whether the function source code is of a target language type. It can be understood that after the function source code is obtained, it is judged whether it is of a target language type. If so, it is compiled, because code of different language types needs to be compiled differently, so it needs to be judged. If it is not of a target language type, no compilation operation is required. Usually, when the user submits the source code, there is another field used to identify which language this source code belongs to. Therefore, the identification field is obtained, and it is judged whether the identification field is an identification of the target language type. For example, if the Java source code needs to be compiled, it is judged whether it is an identification field of Java. It should be noted that in order to ensure that there is an identification field in the function source code, a prompt can be given at the input end, prompting the user to add an identification field when submitting the source code, such as: identified as programming language types such as Java, Python, Nodejs, etc. This embodiment realizes the screening of the function source code by automatically judging whether the function source code is of a target language type, avoiding using function source code of other incorrect types for subsequent steps, improving the accuracy of the function-as-a-service function platform service. There is no need to manually open the function source code for inspection, which also improves the efficiency of the entire process of Java function compilation and deployment, and improves the functionality of the function-as-a-service function platform.

[0127] Further, in one embodiment, before the step of dynamically compiling the function source code into a bytecode file through a source code compilation component when the function source code is of a target language type, the method further includes:

[0128] Step S23, creating a temporary file directory corresponding to the function source code, where the temporary file directory is used to store intermediate files generated by compiling the function source code.

[0129] In one embodiment, after the step of sending a compilation request to the source code compilation component, a temporary file directory corresponding to the function source code is created. It can be understood that since multiple users may submit source code for compilation at the same time point, some intermediate files will be generated during the compilation process. Therefore, it is necessary to store different intermediate files for source code compilation in different directories, otherwise they may be mixed together and cause exceptions. Such exceptions caused by the simultaneous operation of multiple users are concurrent exceptions. Therefore, in this embodiment, by creating a temporary file directory, concurrent exceptions can be avoided.

[0130] Further, in one embodiment, the step of constructing a function image corresponding to the function source code based on the bytecode file includes:

[0131] Step S31, obtain a specified directory;

[0132] Step S32, based on the specified directory, package the bytecode file according to the specified directory and generate a package file.

[0133] Step S33, read the package file in the form of a byte array to obtain package data;

[0134] Step S34, based on the package data, construct a function image corresponding to the function source code.

[0135] It is understandable that after compilation is completed, the data will finally be returned to other systems (or components, modules), and these other systems will parse this file and finally deploy it, etc. The specified directory is the final file directory format agreed upon by my dynamic compilation system and that parsing system. Although the user only uploads the source code, the final system will also add some other files outside of these source codes, such as configuration files, etc. These multiple files need to be organized according to certain rules. For example, file a is placed in directory xxx, file b is placed in directory yyy, etc. This needs to be agreed upon with the parsing program first. Therefore, it is necessary to obtain the specified directory, and based on the specified directory, package the bytecode files according to the specified directory and generate a package file. In this embodiment, the bytecode files are packaged according to the agreed-upon file organization rules, and a package file is generated. Then, the package file is read in the form of a byte array to obtain the package data. A byte array is just a memory area that contains a group of consecutive (side-by-side) bytes, and a byte array can be used to store a collection of binary data. Usually, one byte is 8 bits (binary data). Among them, an array is a form in programming that organizes several variables of the same type in an ordered form for convenient processing. The collection of these sequentially arranged homogeneous data elements is called an array. That is, convert the package file into binary numbers, for example, using ByteArrayOutputStream. Therefore, reading the package file in the form of a byte array to obtain the package data facilitates subsequent data transmission. Further, a function image is constructed based on the package data.

[0136] Further, in one embodiment, after the step of reading the package file in the form of a byte array to obtain the package data, the method further includes:

[0137] Step S331, delete the intermediate file and the package file.

[0138] In one embodiment, after obtaining the package data, the intermediate file and the package file are deleted. The temporarily generated intermediate files and the directories created to store these intermediate files will finally be deleted, and the package file from which the data has been read will also be deleted. Because ultimately only the package data is needed to construct the function image and complete the application of the function, deleting the intermediate file and the package file can reduce system redundancy and improve the operating efficiency of the function computing platform.

[0139] Further, in one embodiment, the step of dynamically compiling the function source code to obtain bytecode files through the source code compilation component when the function source code is of the target language type includes:

[0140] Step S24, when the function source code is of the target language type, send a compilation request to the source code compilation component, and the source code compilation component can receive one or more compilation requests;

[0141] Step S25: Based on the compilation request, use the source code compilation component to dynamically compile the function source code to obtain a bytecode file.

[0142] In one embodiment, if it is determined that the function source code is of the target language type, a compilation request is sent to the source code compilation component. It can be understood that after determining that the received function source code is of the target language type and needs to be compiled, a compilation request is sent to the source code compilation component that provides the compilation service. After receiving the compilation request, the source code compilation component performs the operations required for compilation. By receiving the compilation request, the source code compilation component can form a corresponding relationship with the function source code for which compilation is requested. Since there may be requests for compiling multiple function source codes simultaneously in the system, after receiving the compilation request, the source code compilation component compiles the function source codes separately. For example, create a corresponding file storage location for the Java function requested for compilation. In this way, when multiple Java functions are received on the platform simultaneously, they can be compiled simultaneously, improving the compilation efficiency and reducing the occurrence of exceptions.

[0143] Refer to Figure 8 , Figure 8 is the dynamic compilation flowchart of an embodiment of the method for running the function calculation platform of the present invention. Taking the target language type as a Java function and the function calculation platform as a FaaS function calculation platform as an example, first, define the input stream of the source code file and the output stream of the result file before compilation, construct a file manager to manage the input and output files, then receive the function source code, and determine whether it is Java source code (i.e., the target language type) by obtaining the identification field. If so, create a request-specific target temporary file directory to avoid concurrent exceptions. At the same time, obtain a custom class loader and define a dependency package retriever as the Java source code dynamic compilation component (i.e., the source code compilation component) for subsequent compilation. Then, perform dynamic compilation through the Java source code dynamic compilation component to generate a bytecode file (class file), then package the bytecode file according to the specified directory to obtain a package file (JAR package), and then read the JAR package data in the form of a byte group. After reading, delete the intermediate files and the JAR package. Through the automatic compilation and packaging mechanism of Java source code on the FaaS function platform provided by this patent, it not only ensures that users have the same experience as programming languages such as Python and Nodejs when publishing functions, but also reduces the redundancy of the platform and improves the accuracy.

[0144] In this embodiment, by obtaining the identification field in the function source code, it is determined whether the function source code is of the target language type according to the identification field; after it is determined to be of the target language type, a compilation request is sent to the source code compilation component to form a corresponding relationship between the function source code and the source code compilation component; a temporary file directory corresponding to the function source code is also created before compilation to store intermediate files, and the bytecode files are packaged and stored in accordance with the specified directory, making the entire process more orderly, reducing the possibility of errors, and avoiding concurrent exceptions; after obtaining the package data, the intermediate files and package files are deleted to reduce the system data storage pressure and release the storage space.

[0145] The present invention also provides a function computing platform operating device. As Figure 9 shown, Figure 9 This is a schematic diagram of the functional modules of an embodiment of the function computing platform operating method of the present invention.

[0146] The function computing platform operating device of the present invention includes:

[0147] An obtaining module 10, configured to obtain function source code;

[0148] A compiling module 20, configured to dynamically compile the function source code through a source code compilation component to obtain a bytecode file when the function source code is of the target language type;

[0149] An image building module 30, configured to build a function image corresponding to the function source code based on the bytecode file;

[0150] A deployment module 40, configured to upload the function image to the cluster management background and deploy and run it through the cluster management background.

[0151] Optionally, the obtaining module is further configured to:

[0152] Obtain the first definition data of the source code file input stream and the second definition data of the result file output stream;

[0153] Based on the first definition data and the second definition data, build a file manager, and the file manager is a part of the source code compilation component.

[0154] Optionally, the obtaining module is further configured to:

[0155] Create a custom class loader, and the custom class loader is used to temporarily store the compiled Java bytecode and generate subsequent class files;

[0156] Obtain a dynamic compilation toolkit;

[0157] Create a dependency package retriever, and the dependency package retriever is used to retrieve dependency packages during dynamic compilation;

[0158] Create an exception listener, which is used to capture exception information and return the exception information to the user;

[0159] Build the source code compilation component based on the exception listener, the custom class loader, the dependency package retriever, and the dynamic compilation toolkit.

[0160] Optionally, the compilation module is further configured to:

[0161] Obtain the identification field in the function source code;

[0162] Based on the identification field, determine whether the function source code is of the target language type.

[0163] Optionally, the compilation module is further configured to:

[0164] Create a temporary file directory corresponding to the function source code, which is used to store the intermediate files generated by compiling the function source code.

[0165] Optionally, the compilation module is further configured to:

[0166] Obtain a specified directory;

[0167] Based on the specified directory, package the bytecode files according to the specified directory and generate a package file.

[0168] Read the package file in the form of a byte array to obtain package data;

[0169] Based on the package data, build a function image corresponding to the function source code.

[0170] Optionally, the compilation module is further configured to:

[0171] Delete the intermediate files and the package file.

[0172] Optionally, the compilation module is further configured to:

[0173] When the function source code is of the target language type, send a compilation request to the source code compilation component, and the source code compilation component can receive one or more compilation requests;

[0174] Based on the compilation request, through the source code compilation component, dynamically compile the function source code to obtain a bytecode file.

[0175] The present invention also provides a storage medium.

[0176] The function computing platform running program is stored on the storage medium of the present invention, and when the function computing platform running program is executed by a processor, the steps of the function computing platform running method as described above are implemented.

[0177] Among them, when the function computing platform running program running on the processor is executed, the implemented method can refer to the various embodiments of the function computing platform running method of the present invention, which will not be elaborated here.

[0178] It should be noted that in this article, the term "including", "comprising" or any other variant thereof is intended to cover non-exclusive inclusion, so that a process, method, article or system including a series of elements not only includes those elements, but also includes other elements not expressly listed, or further includes elements inherent to such process, method, article or system. Without further limitation, an element defined by the statement "including one..." does not exclude the existence of another identical element in the process, method, article or system including that element.

[0179] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages and disadvantages of the embodiments.

[0180] Through the description of the above embodiments, those skilled in the art can clearly understand that the above embodiment methods can be implemented by means of software plus a necessary general hardware platform. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium as described above (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to enable a terminal device (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods described in the various embodiments of the present invention.

[0181] The above are only the preferred embodiments of the present invention, and do not limit the patent scope of the present invention accordingly. Any equivalent structure or equivalent process transformation made by using the description of the specification and drawings of the present invention, or directly or indirectly applied in other related technical fields, shall be equally included in the patent protection scope of the present invention.

Claims

1. A method for operating a function computing platform, characterized in that, The function computing platform operation method includes the following steps: Get the function source code; When the function source code is in the target language type, compiling the function source code to obtain a bytecode file through a source code compilation component, wherein the source code compilation component is used to compile one or more function source codes; Based on the bytecode file, construct a function image corresponding to the function source code; Upload the function image to the cluster management backend and deploy and run it through the cluster management backend; When the target language type is a Java function, before the step of obtaining the function source code, the method further includes: Create a custom class loader, which is used to temporarily store compiled Java bytecode and generate subsequent class files; Get the dynamic compilation toolkit; Creating a dependency package retriever, wherein the dependency package retriever is used to retrieve dependency packages during dynamic compilation; Create an exception listener, which is used to capture exception information and return the exception information to the user; Constructing the source code compilation component based on the exception listener, the custom class loader, the dependency package retriever and the dynamic compilation toolkit; Before the step of dynamically compiling the function source code by a source code compilation component to obtain a bytecode file when the function source code is in the target language type, the method further includes: Create a temporary file directory corresponding to the function source code, and the temporary file directory is used to store intermediate files generated by compiling the function source code.

2. The method for operating a function computing platform according to claim 1, wherein, Before the step of obtaining the function source code, the method further includes: Obtain first definition data of a source file input stream and second definition data of a result file output stream; A file manager is constructed based on the first definition data and the second definition data, where the file manager is a part of a source code compilation component.

3. The function computing platform operation method according to claim 1, wherein: After the step of obtaining the function source code, the method further includes: Obtaining an identification field in the function source code; Based on the identification field, it is determined whether the function source code is of the target language type.

4. The method for operating a function computing platform according to claim 1, wherein, The step of constructing a function image corresponding to the function source code based on the bytecode file includes: Get the specified directory; Based on the specified directory, packaging the bytecode file according to the specified directory and generating a package file; Read the package file in the form of a byte array to obtain package data; Based on the package data, a function image corresponding to the function source code is constructed.

5. The method for operating a function computing platform according to claim 4, wherein, After the step of reading the package file in the form of a byte array to obtain the package data, the method further comprises: Delete the intermediate file and the package file.

6. The function computing platform operation method according to claim 1, wherein: When the function source code is in the target language type, the step of dynamically compiling the function source code by a source code compilation component to obtain a bytecode file includes: When the function source code is in the target language type, a compilation request is sent to a source code compilation component, and the source code compilation component can receive one or more compilation requests; Based on the compilation request, the function source code is dynamically compiled by the source code compilation component to obtain a bytecode file.

7. A function computing platform operation device, characterized in that: The device comprises: Get module, used to get function source code; A compilation module, configured to dynamically compile the function source code to obtain a bytecode file through a source code compilation component when the function source code is in the target language type, wherein the source code compilation component is configured to compile one or more function source codes; An image building module, configured to build a function image corresponding to the function source code based on the bytecode file; A deployment module is used to upload the function image to the cluster management backend and deploy and run it through the cluster management backend; The acquisition module, when the target language type is a Java function, is further configured to create a custom class loader before acquiring the function source code, wherein the custom class loader is configured to temporarily store the compiled Java bytecode and generate subsequent class files; Get the dynamic compilation toolkit; Creating a dependency package retriever, wherein the dependency package retriever is used to retrieve dependency packages during dynamic compilation; Create an exception listener, which is used to capture exception information and return the exception information to the user; Constructing the source code compilation component based on the exception listener, the custom class loader, the dependency package retriever and the dynamic compilation toolkit; The compilation module is also used to create a temporary file directory corresponding to the function source code before the step of dynamically compiling the function source code through the source code compilation component to obtain the bytecode file when the function source code is of the target language type. The temporary file directory is used to store the intermediate files generated by the function source code compilation.

8. A function computing platform operation device, characterized in that: The device includes: a memory, a processor, and a function computing platform running program stored in the memory and executable on the processor, wherein the function computing platform running program is configured to implement the steps of the function computing platform running method according to any one of claims 1 to 6.

9. A storage medium, characterized in that: The storage medium stores a function computing platform operating program, and when the function computing platform operating program is executed by the processor, the steps of the function computing platform operating method according to any one of claims 1 to 6 are implemented.

Citation Information

Patent Citations

  • Cloud platform-based software development method, cloud platform, device and medium

    CN109240662A

  • Logic code running method and device, computer equipment and storage medium

    CN112698921A