xintongsong commented on code in PR #60:
URL: https://github.com/apache/flink-agents/pull/60#discussion_r2206102961


##########
e2e-test/test-scripts/test-data/placeholder.txt:
##########
@@ -0,0 +1,18 @@
+#
+#   Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you under the Apache License, Version 2.0 (the
+#  "License"); you may not use this file except in compliance
+#  with the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+# limitations under the License.
+#
+#

Review Comment:
   What is this?



##########
plan/src/test/java/org/apache/flink/agents/plan/compatibility/CreateJavaAgentPlanFromJson.java:
##########
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.agents.plan.compatibility;
+
+import org.apache.flink.agents.plan.Action;
+import org.apache.flink.agents.plan.AgentPlan;
+import org.apache.flink.agents.plan.PythonFunction;
+import 
org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/** Utils for testing agent plan compatibility between Python and Java. */
+public class CreateJavaAgentPlanFromJson {
+
+    /** Test creating Java AgentPlan from Python AgentPlan json. */
+    public static void main(String[] args) throws IOException {
+        String agentJsonFile = args[0];
+        String json = Files.readString(Paths.get(agentJsonFile));
+        AgentPlan agentPlan = new ObjectMapper().readValue(json, 
AgentPlan.class);
+        assertEquals(2, agentPlan.getActions().size());
+
+        // Check the first action
+        assertTrue(agentPlan.getActions().containsKey("first_action"));
+        Action firstAction = agentPlan.getActions().get("first_action");
+        assertInstanceOf(PythonFunction.class, firstAction.getExec());
+        assertEquals(
+                List.of("flink_agents.api.event.InputEvent"), 
firstAction.getListenEventTypes());

Review Comment:
   How do we make sure these assertions are aligned with the python agent plan? 
I don't have a good idea to provide guarantees for this. But I think at least 
we can have some plans dedicated for compatibility checks, rather than reusing 
the examples which might be modified for any other purpose.



##########
e2e-test/test-scripts/test_agent_plan_compatibility.sh:
##########
@@ -0,0 +1,71 @@
+#
+#   Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you under the Apache License, Version 2.0 (the
+#  "License"); you may not use this file except in compliance
+#  with the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+# limitations under the License.
+#
+#
+
+root_dir=$(pwd)
+
+echo $root_dir
+
+jar_path=$root_dir/e2e-test/agent-plan-compatibility-test/target/flink-agents-agent-plan-compatibility-tests-0.1-SNAPSHOT.jar
+
+python_script_path=$root_dir/python/flink_agents/plan/tests/compatibility
+
+data_path=$root_dir/e2e-test/test-scripts/test-data
+
+function test_create_java_agent_from_python_agent_json {
+  json_path=$data_path/python_agent.json

Review Comment:
   Should not create temporal files in source directories.



##########
tools/build.sh:
##########
@@ -0,0 +1,25 @@
+#    Licensed to the Apache Software Foundation (ASF) under one
+#   or more contributor license agreements.  See the NOTICE file
+#   distributed with this work for additional information
+#   regarding copyright ownership.  The ASF licenses this file
+#   to you under the Apache License, Version 2.0 (the
+#   "License"); you may not use this file except in compliance
+#   with the License.  You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#  limitations under the License.
+#
+
+# build java
+mvn clean package -DskipTests
+
+# build python
+cd python
+pip install -e .[dev]

Review Comment:
   Why not using uv, which is marked as the recommended way in README.md



##########
e2e-test/test-scripts/test_agent_plan_compatibility.sh:
##########
@@ -0,0 +1,71 @@
+#
+#   Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you under the Apache License, Version 2.0 (the
+#  "License"); you may not use this file except in compliance
+#  with the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+# limitations under the License.
+#
+#
+
+root_dir=$(pwd)
+
+echo $root_dir
+
+jar_path=$root_dir/e2e-test/agent-plan-compatibility-test/target/flink-agents-agent-plan-compatibility-tests-0.1-SNAPSHOT.jar

Review Comment:
   1. hardcoded version
   2. Should not assume `target/` is created



##########
plan/src/test/java/org/apache/flink/agents/plan/compatibility/GenerateAgentPlanJson.java:
##########
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.agents.plan.compatibility;
+
+import org.apache.flink.agents.api.Event;
+import org.apache.flink.agents.api.InputEvent;
+import org.apache.flink.agents.api.context.RunnerContext;
+import org.apache.flink.agents.plan.Action;
+import org.apache.flink.agents.plan.AgentPlan;
+import org.apache.flink.agents.plan.JavaFunction;
+import 
org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper;
+
+import java.io.BufferedWriter;
+import java.io.FileWriter;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/** Utils for generating agent plan json. */
+public class GenerateAgentPlanJson {
+    private static class MyEvent extends Event {}
+
+    private static class MyAction extends Action {
+
+        public static void doNothing(Event event, RunnerContext context) {
+            // No operation
+        }
+
+        public MyAction() throws Exception {
+            super(
+                    "MyAction",
+                    new JavaFunction(
+                            MyAction.class.getName(),
+                            "doNothing",
+                            new Class[] {Event.class, RunnerContext.class}),
+                    List.of(InputEvent.class.getName(), 
MyEvent.class.getName()));
+        }
+    }
+
+    /** Generate agent plan json. */
+    public static void main(String[] args) throws Exception {
+        String jsonPath = args[0];
+        JavaFunction function1 =
+                new JavaFunction(
+                        "org.apache.flink.agents.plan.TestAction",
+                        "legal",
+                        new Class[] {InputEvent.class, RunnerContext.class});
+        JavaFunction function2 =
+                new JavaFunction(
+                        MyAction.class.getName(),
+                        "doNothing",
+                        new Class[] {Event.class, RunnerContext.class});
+
+        // Create Actions
+        Action action1 = new Action("first_action", function1, 
List.of(InputEvent.class.getName()));
+        Action action2 =
+                new Action(
+                        "second_action",
+                        function2,
+                        List.of(InputEvent.class.getName(), 
MyEvent.class.getName()));
+
+        // Create a map of actions
+        Map<String, Action> actions = new HashMap<>();
+        actions.put(action1.getName(), action1);
+        actions.put(action2.getName(), action2);
+
+        // Create a map of event trigger actions
+        Map<String, List<Action>> actionsByEvent = new HashMap<>();
+        actionsByEvent.put(InputEvent.class.getName(), List.of(action1, 
action2));
+        actionsByEvent.put(MyEvent.class.getName(), List.of(action2));
+
+        // Create a AgentPlan with both actions and event trigger actions
+        AgentPlan agentPlan = new AgentPlan(actions, actionsByEvent);

Review Comment:
   I think we can create the plan based on the latest java api ( #62 )



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@flink.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to