You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by xt...@apache.org on 2026/04/02 09:12:47 UTC
(flink-agents) branch main updated: Support custom job names (#570)
This is an automated email from the ASF dual-hosted git repository.
xtsong pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/flink-agents.git
The following commit(s) were added to refs/heads/main by this push:
new 09f5f826 Support custom job names (#570)
09f5f826 is described below
commit 09f5f826cbf809c2ab060c567cb9ee9818915f83
Author: JennyChen <je...@163.com>
AuthorDate: Thu Apr 2 17:12:41 2026 +0800
Support custom job names (#570)
---
.../agents/api/AgentsExecutionEnvironment.java | 10 +++++++++
python/flink_agents/api/execution_environment.py | 2 +-
.../runtime/local_execution_environment.py | 2 +-
.../runtime/remote_execution_environment.py | 4 ++--
.../tests/test_remote_execution_environment.py | 26 ++++++++++++++++++++++
.../runtime/env/RemoteExecutionEnvironment.java | 5 +++++
.../env/RemoteExecutionEnvironmentTest.java | 21 +++++++++++++++++
7 files changed, 66 insertions(+), 4 deletions(-)
diff --git a/api/src/main/java/org/apache/flink/agents/api/AgentsExecutionEnvironment.java b/api/src/main/java/org/apache/flink/agents/api/AgentsExecutionEnvironment.java
index 07f5474f..37f2c3dc 100644
--- a/api/src/main/java/org/apache/flink/agents/api/AgentsExecutionEnvironment.java
+++ b/api/src/main/java/org/apache/flink/agents/api/AgentsExecutionEnvironment.java
@@ -197,6 +197,16 @@ public abstract class AgentsExecutionEnvironment {
*/
public abstract void execute() throws Exception;
+ /**
+ * Execute agent pipeline with a given job name.
+ *
+ * <p>This method triggers the execution of the configured agent pipeline with the specified job
+ * name.
+ *
+ * @param jobName The name for the Flink job.
+ */
+ public abstract void execute(String jobName) throws Exception;
+
/**
* Register resource to agents execution environment.
*
diff --git a/python/flink_agents/api/execution_environment.py b/python/flink_agents/api/execution_environment.py
index 11de9ab2..d9cdeff1 100644
--- a/python/flink_agents/api/execution_environment.py
+++ b/python/flink_agents/api/execution_environment.py
@@ -233,7 +233,7 @@ class AgentsExecutionEnvironment(ABC):
"""
@abstractmethod
- def execute(self) -> None:
+ def execute(self, job_name: str | None = None) -> None:
"""Execute agent individually."""
def add_resource(
diff --git a/python/flink_agents/runtime/local_execution_environment.py b/python/flink_agents/runtime/local_execution_environment.py
index 63930ef7..4ed7bd3a 100644
--- a/python/flink_agents/runtime/local_execution_environment.py
+++ b/python/flink_agents/runtime/local_execution_environment.py
@@ -119,7 +119,7 @@ class LocalExecutionEnvironment(AgentsExecutionEnvironment):
self.__runner = runner
self.__output = output
- def execute(self) -> None:
+ def execute(self, job_name: str | None = None) -> None:
"""Execute agent individually."""
if self.__executed:
err_msg = (
diff --git a/python/flink_agents/runtime/remote_execution_environment.py b/python/flink_agents/runtime/remote_execution_environment.py
index c34a7e83..134365c6 100644
--- a/python/flink_agents/runtime/remote_execution_environment.py
+++ b/python/flink_agents/runtime/remote_execution_environment.py
@@ -264,9 +264,9 @@ class RemoteExecutionEnvironment(AgentsExecutionEnvironment):
msg = "RemoteExecutionEnvironment does not support from_list."
raise NotImplementedError(msg)
- def execute(self) -> None:
+ def execute(self, job_name: str | None = None) -> None:
"""Execute agent."""
- self.__env.execute()
+ self.__env.execute(job_name=job_name)
def __load_config_from_flink_conf_dir(self) -> None:
diff --git a/python/flink_agents/runtime/tests/test_remote_execution_environment.py b/python/flink_agents/runtime/tests/test_remote_execution_environment.py
index 7cdef485..51482f04 100644
--- a/python/flink_agents/runtime/tests/test_remote_execution_environment.py
+++ b/python/flink_agents/runtime/tests/test_remote_execution_environment.py
@@ -173,6 +173,32 @@ def test_remote_execution_environment_prioritizes_legacy_config() -> None:
os.environ["FLINK_CONF_DIR"] = original_env
+def test_execute_with_job_name() -> None:
+ """Test that execute() passes job_name to StreamExecutionEnvironment."""
+ mock_stream_env = MagicMock()
+
+ with patch(
+ "flink_agents.runtime.remote_execution_environment.StreamExecutionEnvironment"
+ ):
+ remote_env = RemoteExecutionEnvironment(env=mock_stream_env)
+ remote_env.execute(job_name="my-test-job")
+
+ mock_stream_env.execute.assert_called_once_with(job_name="my-test-job")
+
+
+def test_execute_without_job_name() -> None:
+ """Test execute() passes None to StreamExecutionEnvironment when no job_name."""
+ mock_stream_env = MagicMock()
+
+ with patch(
+ "flink_agents.runtime.remote_execution_environment.StreamExecutionEnvironment"
+ ):
+ remote_env = RemoteExecutionEnvironment(env=mock_stream_env)
+ remote_env.execute()
+
+ mock_stream_env.execute.assert_called_once_with(job_name=None)
+
+
def _verify_config(config: AgentConfiguration) -> None:
assert config.get_str("database.host") == "localhost"
assert config.get_int("database.port") == 5432
diff --git a/runtime/src/main/java/org/apache/flink/agents/runtime/env/RemoteExecutionEnvironment.java b/runtime/src/main/java/org/apache/flink/agents/runtime/env/RemoteExecutionEnvironment.java
index c1294b31..f8542001 100644
--- a/runtime/src/main/java/org/apache/flink/agents/runtime/env/RemoteExecutionEnvironment.java
+++ b/runtime/src/main/java/org/apache/flink/agents/runtime/env/RemoteExecutionEnvironment.java
@@ -98,6 +98,11 @@ public class RemoteExecutionEnvironment extends AgentsExecutionEnvironment {
env.execute();
}
+ @Override
+ public void execute(String jobName) throws Exception {
+ env.execute(jobName);
+ }
+
@SuppressWarnings("unchecked")
public static AgentConfiguration loadAgentConfiguration(String configDir) {
try {
diff --git a/runtime/src/test/java/org/apache/flink/agents/runtime/env/RemoteExecutionEnvironmentTest.java b/runtime/src/test/java/org/apache/flink/agents/runtime/env/RemoteExecutionEnvironmentTest.java
index 4784a287..0bb09df6 100644
--- a/runtime/src/test/java/org/apache/flink/agents/runtime/env/RemoteExecutionEnvironmentTest.java
+++ b/runtime/src/test/java/org/apache/flink/agents/runtime/env/RemoteExecutionEnvironmentTest.java
@@ -17,7 +17,10 @@
*/
package org.apache.flink.agents.runtime.env;
+import org.apache.flink.agents.api.AgentsExecutionEnvironment;
import org.apache.flink.agents.plan.AgentConfiguration;
+import org.apache.flink.api.common.JobExecutionResult;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
@@ -29,6 +32,10 @@ import java.util.UUID;
import static org.apache.flink.agents.runtime.env.RemoteExecutionEnvironment.FLINK_CONF_FILENAME;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
public class RemoteExecutionEnvironmentTest {
@TempDir private File tmpDir;
@@ -74,4 +81,18 @@ public class RemoteExecutionEnvironmentTest {
AgentConfiguration conf = RemoteExecutionEnvironment.loadAgentConfiguration(null);
assertThat(conf.getConfData()).isEmpty();
}
+
+ @Test
+ void testExecuteWithCustomJobNameDelegatesToStreamExecutionEnvironment() throws Exception {
+ StreamExecutionEnvironment flinkEnv = mock(StreamExecutionEnvironment.class);
+ when(flinkEnv.execute(anyString())).thenReturn(mock(JobExecutionResult.class));
+
+ AgentsExecutionEnvironment agentsEnv =
+ AgentsExecutionEnvironment.getExecutionEnvironment(flinkEnv);
+
+ String customJobName = "my-custom-agents-job";
+ agentsEnv.execute(customJobName);
+
+ verify(flinkEnv).execute(customJobName);
+ }
}