WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 32bbbad

Browse files
committed
[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 apache#40 we try to create both user and tenant vis cli instead of auto create
1 parent 7722a63 commit 32bbbad

32 files changed

+134
-112
lines changed

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

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import click
2+
3+
from pydolphinscheduler import configuration
4+
from pydolphinscheduler.models.tenant import Tenant
5+
6+
7+
@click.help_option()
8+
def tenants() -> click.group:
9+
"""Users subcommand group."""
10+
11+
12+
@click.group()
13+
def tenants() -> click.group:
14+
"""Users subcommand group."""
15+
16+
17+
@tenants.command()
18+
@click.option(
19+
"-n", "--name", "name",
20+
required=True,
21+
type=str,
22+
)
23+
@click.option(
24+
"-q", "--queue-name", "queue_name",
25+
required=True,
26+
type=str,
27+
)
28+
@click.option(
29+
"-d", "--description", "description",
30+
required=True,
31+
type=str,
32+
)
33+
def create(name, queue_name, description):
34+
tenant = Tenant.get(name)
35+
if tenant:
36+
click.echo(f"Tenant with name {name} already exists.", err=True)
37+
new_tenant = Tenant.create(name, queue_name, description)
38+
click.echo(f"Tenant {new_tenant.name} had been created.")
39+
40+
41+
@tenants.command()
42+
@click.option(
43+
"-n", "--name", "name",
44+
required=True,
45+
type=str,
46+
)
47+
def delete(name):
48+
tenant = Tenant.delete(name)
49+
if not tenant:
50+
click.echo(f"Tenant with name {name} not exists.", err=True)
51+
click.echo(f"Tenant: {tenant}.")
52+
53+
54+
@tenants.command()
55+
@click.option(
56+
"-n", "--name", "name",
57+
required=True,
58+
type=str,
59+
)
60+
def get(name):
61+
tenant = Tenant.get(name)
62+
if not tenant:
63+
click.echo(f"Tenant with name {name} not exists.", err=True)
64+
click.echo(f"Tenant: {tenant}.")

src/pydolphinscheduler/cli/users.py

Whitespace-only changes.

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: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,15 @@ java_gateway:
3939
default:
4040
# Default value for dolphinscheduler's user object
4141
user:
42-
name: userPythonGateway
42+
name: userPythonGateway1
4343
password: userPythonGateway
4444
45-
tenant: tenant_pydolphin
45+
tenant: zhongjiajie
4646
phone: 11111111111
4747
state: 1
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}"

0 commit comments

Comments
 (0)