-
Notifications
You must be signed in to change notification settings - Fork 26
Description
I have successfully deployed the newest commit in the deploy branch of Knix on my local machine with ansible.
In my deployment, I tried several simple Java functions and found them works fine. However, when I try to execute some Java functions with maven dependency as described in the java tutorials, I found things not that simple.
This is my Java Function's source code:
import org.microfunctions.mfnapi.MicroFunctionsAPI;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
public class Test
{
public Object handle(Object event, MicroFunctionsAPI context)
{
String jsonString = (String)event;
JsonParser parser = new JsonParser();
JsonObject jsonObject = parser.parse(jsonString).getAsJsonObject();
return jsonObject.toString();
}
}
And this is the associated pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.knix</groupId>
<artifactId>example_maven</artifactId>
<version>1.0.0</version>
<name>JavaRequestHandlerMavenTest</name>
<url>https://knix.io/</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.2</version>
</dependency>
</dependencies>
</project>
I created a function named Test with the code and pom.xml mentioned above with the web interface, and use the Test function for testing.
I successfully passed the preparing function phase, found the microfn/sandbox_java
container running.
However, when I tried execute the function, I got the following exception in the execution log:
[2023-04-05 13:28:34.675] [INFO] [0l] [Test] [FunctionWorker] Started:Test, user: xxxxxxx, workflow: 833a372ca348a098b47d2562a46e591b, sandbox: 833a372ca348a098b47d2562a46e591b, pid: 151
[2023-04-05 13:29:07.352] [ERROR] [d752c5f1d3b511edaa890242ac110003] [Test] Child exception: com/google/gson/JsonParser
Traceback (most recent call last):
File "/opt/mfn/FunctionWorker/python/FunctionWorker.py", line 460, in _fork_and_handle_message
function_output = self._state_utils.exec_function_catch_retry(self._function_runtime, exec_arguments, self._sapi)
File "/opt/mfn/FunctionWorker/python/StateUtils.py", line 389, in exec_function_catch_retry
ret_value = self._exec_function(runtime, exec_arguments, sapi)
File "/opt/mfn/FunctionWorker/python/StateUtils.py", line 310, in _exec_function
raise Exception(error_type)
Exception: com/google/gson/JsonParser
It seems that the java executor cannot find the classes of the gson package.