You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by zh...@apache.org on 2023/10/12 14:14:34 UTC
[dolphinscheduler-sdk-python] branch 4.0.x updated: fix: Resource config error and failed workflow run (#116)
This is an automated email from the ASF dual-hosted git repository.
zhongjiajie pushed a commit to branch 4.0.x
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler-sdk-python.git
The following commit(s) were added to refs/heads/4.0.x by this push:
new 8fb5d64 fix: Resource config error and failed workflow run (#116)
8fb5d64 is described below
commit 8fb5d64e9bd842c4f2e16f53d2c956a38a711e5c
Author: Jay Chung <zh...@gmail.com>
AuthorDate: Thu Oct 12 22:14:27 2023 +0800
fix: Resource config error and failed workflow run (#116)
---
src/pydolphinscheduler/constants.py | 2 +-
src/pydolphinscheduler/core/resource.py | 8 ++++----
src/pydolphinscheduler/core/task.py | 10 ++++------
tests/core/test_task.py | 12 ++++++------
tests/integration/test_resources.py | 6 ------
5 files changed, 15 insertions(+), 23 deletions(-)
diff --git a/src/pydolphinscheduler/constants.py b/src/pydolphinscheduler/constants.py
index 1a5e11f..385e78f 100644
--- a/src/pydolphinscheduler/constants.py
+++ b/src/pydolphinscheduler/constants.py
@@ -112,7 +112,7 @@ class Time(str):
class ResourceKey(str):
"""Constants for key of resource."""
- NAME = "resourceName"
+ ID = "id"
class Symbol(str):
diff --git a/src/pydolphinscheduler/core/resource.py b/src/pydolphinscheduler/core/resource.py
index 3925fb5..b7717fc 100644
--- a/src/pydolphinscheduler/core/resource.py
+++ b/src/pydolphinscheduler/core/resource.py
@@ -55,9 +55,9 @@ class Resource(Base):
)
return gateway.query_resources_file_info(self.user_name, self.name)
- def get_fullname_from_database(self):
- """Get resource fullname from java gateway."""
- return self.get_info_from_database().getFullName()
+ def get_id_from_database(self):
+ """Get resource id from java gateway."""
+ return self.get_info_from_database().getId()
def create_or_update_resource(self):
"""Create or update resource via java gateway."""
@@ -65,7 +65,7 @@ class Resource(Base):
raise PyDSParamException(
"`user_name` and `content` are required when create or update resource from python gate."
)
- return gateway.create_or_update_resource(
+ gateway.create_or_update_resource(
self.user_name,
self.name,
self.description,
diff --git a/src/pydolphinscheduler/core/task.py b/src/pydolphinscheduler/core/task.py
index ef1c52d..e8902c7 100644
--- a/src/pydolphinscheduler/core/task.py
+++ b/src/pydolphinscheduler/core/task.py
@@ -262,11 +262,9 @@ class Task(Base):
for res in self._resource_list:
if isinstance(res, str):
resources.add(
- Resource(
- name=res, user_name=self.user_name
- ).get_fullname_from_database()
+ Resource(name=res, user_name=self.user_name).get_id_from_database()
)
- elif isinstance(res, dict) and ResourceKey.NAME in res:
+ elif isinstance(res, dict) and res.get(ResourceKey.ID) is not None:
warnings.warn(
"""`resource_list` should be defined using List[str] with resource paths,
the use of ids to define resources will be remove in version 3.2.0.
@@ -274,8 +272,8 @@ class Task(Base):
DeprecationWarning,
stacklevel=2,
)
- resources.add(res.get(ResourceKey.NAME))
- return [{ResourceKey.NAME: r} for r in resources]
+ resources.add(res.get(ResourceKey.ID))
+ return [{ResourceKey.ID: r} for r in resources]
@property
def user_name(self) -> Optional[str]:
diff --git a/tests/core/test_task.py b/tests/core/test_task.py
index 9781b6e..8c4b0b6 100644
--- a/tests/core/test_task.py
+++ b/tests/core/test_task.py
@@ -147,7 +147,7 @@ def test_task_timeout(value: timedelta, expect: Tuple[int, str]):
},
{
"localParams": ["foo", "bar"],
- "resourceList": [{"resourceName": 1}],
+ "resourceList": [{"id": 1}],
"dependence": {"foo", "bar"},
"waitStartTimeout": {"foo", "bar"},
"conditionResult": {"foo": ["bar"]},
@@ -156,7 +156,7 @@ def test_task_timeout(value: timedelta, expect: Tuple[int, str]):
],
)
@patch(
- "pydolphinscheduler.core.resource.Resource.get_fullname_from_database",
+ "pydolphinscheduler.core.resource.Resource.get_id_from_database",
return_value=1,
)
@patch(
@@ -481,11 +481,11 @@ def test_task_obtain_res_plugin_exception(m_get_content, m_code_version, attr):
[
(
["/dev/test.py"],
- [{"resourceName": 1}],
+ [{"id": 1}],
),
(
- ["/dev/test.py", {"resourceName": 2}],
- [{"resourceName": 1}, {"resourceName": 2}],
+ ["/dev/test.py", {"id": 2}],
+ [{"id": 1}, {"id": 2}],
),
],
)
@@ -494,7 +494,7 @@ def test_task_obtain_res_plugin_exception(m_get_content, m_code_version, attr):
return_value=(123, 1),
)
@patch(
- "pydolphinscheduler.core.resource.Resource.get_fullname_from_database",
+ "pydolphinscheduler.core.resource.Resource.get_id_from_database",
return_value=1,
)
@patch(
diff --git a/tests/integration/test_resources.py b/tests/integration/test_resources.py
index a8fd8f7..ee1d99d 100644
--- a/tests/integration/test_resources.py
+++ b/tests/integration/test_resources.py
@@ -45,9 +45,6 @@ def tmp_user():
user.delete()
-@pytest.mark.skip(
- "activate it when dolphinscheduler default resource center is local file"
-)
def test_create_or_update(tmp_user):
"""Test create or update resource to java gateway."""
resource = Resource(name=name, content=content, user_name=UNIT_TEST_USER_NAME)
@@ -56,9 +53,6 @@ def test_create_or_update(tmp_user):
assert result.getAlias() == name
-@pytest.mark.skip(
- "activate it when dolphinscheduler default resource center is local file"
-)
def test_get_resource_info(tmp_user):
"""Test get resource info from java gateway."""
resource = Resource(name=name, user_name=UNIT_TEST_USER_NAME)