Skip to content

Commit 1acaf89

Browse files
authored
[impv] Remove tenant define is workflow (#54)
* [impv] Remove tenant define is workflow current tenant in workflow only work when the first time user do not exist, when user change the tenant in workflow but tenant exist, it will be ignore, so we try to remove it from workflow, and in #40 we try to create both user and tenant vis cli instead of auto create
1 parent 7722a63 commit 1acaf89

32 files changed

Lines changed: 23 additions & 146 deletions

UPDATING.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ It started after version 2.0.5 released
2424

2525
## Main
2626

27+
* Remove attribute tenant from pydolphinscheduler.core.workflow.workflow ([#54](https://github.com/apache/dolphinscheduler-sdk-python/pull/54))
28+
and please change tenant name in ``config.yaml`` in ``PYDS_HOME``
29+
30+
## 4.0.0
31+
2732
* Change Task attr ``timeout`` type from int to timedelta and use timeout determine attr ``timeout_flag`` value ([#41](https://github.com/apache/dolphinscheduler-sdk-python/pull/41))
2833
* Remove the spark version of spark task ([#11860](https://github.com/apache/dolphinscheduler/pull/11860)).
2934
* Change class name from process definition to workflow ([#26](https://github.com/apache/dolphinscheduler-sdk-python/pull/26))

docs/source/concept.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,12 @@ Tenant
8080
~~~~~~
8181

8282
Tenant is the user who run task command in machine or in virtual machine. it could be assign by simple string.
83+
You should change the tenant value to exists tenant in your host, it config in `config.yaml` in your pydolphinscheduler
84+
``PYDS_HOME``, or via :doc:`CLI <cli>`
8385

84-
.. code-block:: python
86+
.. code-block:: bash
8587
86-
#
87-
workflow = Workflow(name="workflow tenant", tenant="tenant_exists")
88+
pydolphinscheduler config --set default.user.tenant <YOUR-TENANT-NAME>
8889
8990
.. note::
9091

docs/source/config.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,6 @@ All environment variables as below, and you could modify their value via `Bash <
101101
+------------------+------------------------------------+---------------------------------------------------------------------------------------------------------------------+
102102
| | ``PYDS_WORKFLOW_PROJECT`` | Default workflow project name, will use its value when workflow does not specify the attribute ``project``. |
103103
+ +------------------------------------+---------------------------------------------------------------------------------------------------------------------+
104-
| | ``PYDS_WORKFLOW_TENANT`` | Default workflow tenant, will use its value when workflow does not specify the attribute ``tenant``. |
105-
+ +------------------------------------+---------------------------------------------------------------------------------------------------------------------+
106104
| Default Workflow | ``PYDS_WORKFLOW_USER`` | Default workflow user, will use its value when workflow does not specify the attribute ``user``. |
107105
+ +------------------------------------+---------------------------------------------------------------------------------------------------------------------+
108106
| | ``PYDS_WORKFLOW_QUEUE`` | Default workflow queue, will use its value when workflow does not specify the attribute ``queue``. |

examples/yaml_define/tutorial.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ workflow:
2020
name: "tutorial"
2121
schedule: "0 0 0 * * ? *"
2222
start_time: "2021-01-01"
23-
tenant: "tenant_exists"
2423
release_state: "offline"
2524
run: true
2625

src/pydolphinscheduler/configuration.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ def get_bool(val: Any) -> bool:
184184
"PYDS_USER_PASSWORD", configs.get("default.user.password")
185185
)
186186
USER_EMAIL = os.environ.get("PYDS_USER_EMAIL", configs.get("default.user.email"))
187+
USER_TENANT = os.environ.get("PYDS_USER_STATE", configs.get("default.user.tenant"))
187188
USER_PHONE = str(os.environ.get("PYDS_USER_PHONE", configs.get("default.user.phone")))
188189
USER_STATE = get_int(
189190
os.environ.get("PYDS_USER_STATE", configs.get("default.user.state"))
@@ -193,9 +194,6 @@ def get_bool(val: Any) -> bool:
193194
WORKFLOW_PROJECT = os.environ.get(
194195
"PYDS_WORKFLOW_PROJECT", configs.get("default.workflow.project")
195196
)
196-
WORKFLOW_TENANT = os.environ.get(
197-
"PYDS_WORKFLOW_TENANT", configs.get("default.workflow.tenant")
198-
)
199197
WORKFLOW_USER = os.environ.get(
200198
"PYDS_WORKFLOW_USER", configs.get("default.workflow.user")
201199
)

src/pydolphinscheduler/core/default_config.yaml

Lines changed: 0 additions & 58 deletions
This file was deleted.

src/pydolphinscheduler/core/workflow.py

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from pydolphinscheduler.core.resource_plugin import ResourcePlugin
2828
from pydolphinscheduler.exceptions import PyDSParamException, PyDSTaskNoFoundException
2929
from pydolphinscheduler.java_gateway import gateway
30-
from pydolphinscheduler.models import Base, Project, Tenant, User
30+
from pydolphinscheduler.models import Base, Project, User
3131
from pydolphinscheduler.utils.date import MAX_DATETIME, conv_from_str, conv_to_schedule
3232

3333

@@ -87,7 +87,6 @@ class Workflow(Base):
8787
_KEY_ATTR = {
8888
"name",
8989
"project",
90-
"tenant",
9190
"release_state",
9291
"param",
9392
}
@@ -96,7 +95,6 @@ class Workflow(Base):
9695
"name",
9796
"description",
9897
"_project",
99-
"_tenant",
10098
"worker_group",
10199
"warning_type",
102100
"warning_group_id",
@@ -120,7 +118,6 @@ def __init__(
120118
timezone: Optional[str] = configuration.WORKFLOW_TIME_ZONE,
121119
user: Optional[str] = configuration.WORKFLOW_USER,
122120
project: Optional[str] = configuration.WORKFLOW_PROJECT,
123-
tenant: Optional[str] = configuration.WORKFLOW_TENANT,
124121
worker_group: Optional[str] = configuration.WORKFLOW_WORKER_GROUP,
125122
warning_type: Optional[str] = configuration.WORKFLOW_WARNING_TYPE,
126123
warning_group_id: Optional[int] = 0,
@@ -140,7 +137,6 @@ def __init__(
140137
self.timezone = timezone
141138
self._user = user
142139
self._project = project
143-
self._tenant = tenant
144140
self.worker_group = worker_group
145141
self.warning_type = warning_type
146142
if warning_type.strip().upper() not in ("FAILURE", "SUCCESS", "ALL", "NONE"):
@@ -178,16 +174,6 @@ def __enter__(self) -> "Workflow":
178174
def __exit__(self, exc_type, exc_val, exc_tb) -> None:
179175
WorkflowContext.delete()
180176

181-
@property
182-
def tenant(self) -> Tenant:
183-
"""Get attribute tenant."""
184-
return Tenant(self._tenant)
185-
186-
@tenant.setter
187-
def tenant(self, tenant: Tenant) -> None:
188-
"""Set attribute tenant."""
189-
self._tenant = tenant.name
190-
191177
@property
192178
def project(self) -> Project:
193179
"""Get attribute project."""
@@ -204,7 +190,7 @@ def user(self) -> User:
204190
205191
For now we just get from python models but not from java gateway models, so it may not correct.
206192
"""
207-
return User(name=self._user, tenant=self._tenant)
193+
return User(name=self._user)
208194

209195
@staticmethod
210196
def _parse_datetime(val: Any) -> Any:
@@ -438,7 +424,6 @@ def submit(self) -> int:
438424
self.execution_type,
439425
self.timeout,
440426
self.worker_group,
441-
self._tenant,
442427
self.release_state,
443428
# TODO add serialization function
444429
json.dumps(self.task_relation_json),

src/pydolphinscheduler/default_config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ default:
4848
# Default value for dolphinscheduler's workflow object
4949
workflow:
5050
project: project-pydolphin
51-
tenant: tenant_pydolphin
5251
user: userPythonGateway
5352
queue: queuePythonGateway
5453
worker_group: default

src/pydolphinscheduler/examples/bulk_create_example.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131

3232
NUM_WORKFLOWS = 10
3333
NUM_TASKS = 5
34-
# Make sure your tenant exists in your operator system
35-
TENANT = "exists_tenant"
3634
# Whether task should dependent on pre one or not
3735
# False will create workflow with independent task, while True task will dependent on pre-task and dependence
3836
# link like `pre_task -> current_task -> next_task`, default True
@@ -41,7 +39,7 @@
4139
for wf in range(0, NUM_WORKFLOWS):
4240
workflow_name = f"workflow:{wf}"
4341

44-
with Workflow(name=workflow_name, tenant=TENANT) as workflow:
42+
with Workflow(name=workflow_name) as workflow:
4543
for t in range(0, NUM_TASKS):
4644
task_name = f"task:{t}-{workflow_name}"
4745
command = f"echo This is task {task_name}"

src/pydolphinscheduler/examples/multi_resources_example.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262

6363
with Workflow(
6464
name="multi_resources_example",
65-
tenant="tenant_exists",
6665
# [start create_new_resources]
6766
resource_list=[
6867
Resource(

0 commit comments

Comments
 (0)