-
Notifications
You must be signed in to change notification settings - Fork 21
feat: pipeline_tree静态检查增强 --story=130810130 #683
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
guohelu
wants to merge
3
commits into
TencentBlueKing:develop
Choose a base branch
from
guohelu:develop_0413
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| """ | ||
| TencentBlueKing is pleased to support the open source community by making | ||
| 蓝鲸流程引擎服务 (BlueKing Flow Engine Service) available. | ||
| Copyright (C) 2024 THL A29 Limited, | ||
| a Tencent company. All rights reserved. | ||
| Licensed under the MIT License (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at http://opensource.org/licenses/MIT | ||
| 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. | ||
| We undertake not to change the open source license (MIT license) applicable | ||
| to the current version of the project delivered to anyone in the future. | ||
| """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| """ | ||
| TencentBlueKing is pleased to support the open source community by making | ||
| 蓝鲸流程引擎服务 (BlueKing Flow Engine Service) available. | ||
| Copyright (C) 2024 THL A29 Limited, | ||
| a Tencent company. All rights reserved. | ||
| Licensed under the MIT License (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at http://opensource.org/licenses/MIT | ||
| 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. | ||
|
|
||
| We undertake not to change the open source license (MIT license) applicable | ||
|
|
||
| to the current version of the project delivered to anyone in the future. | ||
| """ | ||
|
|
||
| from django.apps import AppConfig | ||
|
|
||
|
|
||
| class PipelineValidateConfig(AppConfig): | ||
| default_auto_field = "django.db.models.BigAutoField" | ||
| name = "bkflow.pipeline_validate" | ||
| label = "pipeline_validate" | ||
| verbose_name = "流程校验" | ||
|
|
||
| def ready(self): | ||
| # 导入 validators 包,触发所有校验类的加载与注册 | ||
| import bkflow.pipeline_validate.validators # noqa |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| """ | ||
| TencentBlueKing is pleased to support the open source community by making | ||
| 蓝鲸流程引擎服务 (BlueKing Flow Engine Service) available. | ||
| Copyright (C) 2024 THL A29 Limited, | ||
| a Tencent company. All rights reserved. | ||
| Licensed under the MIT License (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at http://opensource.org/licenses/MIT | ||
| 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. | ||
|
|
||
| We undertake not to change the open source license (MIT license) applicable | ||
|
|
||
| to the current version of the project delivered to anyone in the future. | ||
| """ | ||
| from typing import Optional | ||
|
|
||
| from pipeline.exceptions import PipelineException | ||
|
|
||
| from bkflow.constants import ValidateType | ||
|
|
||
|
|
||
| class ValidatorHandler: | ||
| """校验器处理器""" | ||
|
|
||
| __hub = {} | ||
|
|
||
| @classmethod | ||
| def register(cls, validator_cls) -> None: | ||
| """注册校验器类""" | ||
| if validator_cls.name is None: | ||
| raise ValueError(f"校验器 {validator_cls.__name__} 的 name 属性不能为 None") | ||
| if validator_cls.name in cls.__hub: | ||
| existing_cls = cls.__hub[validator_cls.name] | ||
| raise ValueError(f"校验器名称 '{validator_cls.name}' 已被 {existing_cls.__name__} 注册,") | ||
| cls.__hub[validator_cls.name] = validator_cls | ||
|
|
||
| @classmethod | ||
| def validate(cls, web_pipeline_tree: dict, validate_type: Optional[ValidateType] = None): | ||
| validators_to_run = [] | ||
| for validator_name, validator_cls in cls.__hub.items(): | ||
| # 获取校验器的类型 | ||
| validator_validate_type = getattr(validator_cls, "validate_type", None) | ||
|
|
||
| if validate_type is None: | ||
| # 默认行为:执行所有校验器 | ||
| validators_to_run.append((validator_name, validator_cls)) | ||
| elif validator_validate_type in [validate_type.value, ValidateType.GENERAL.value]: | ||
| # 指定类型:执行匹配类型和通用类型的校验器 | ||
| validators_to_run.append((validator_name, validator_cls)) | ||
|
|
||
| for validator_name, validator_cls in validators_to_run: | ||
| result = validator_cls.validate(web_pipeline_tree) | ||
| if not result.is_valid: | ||
| raise PipelineException(result.error) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| """ | ||
| TencentBlueKing is pleased to support the open source community by making | ||
| 蓝鲸流程引擎服务 (BlueKing Flow Engine Service) available. | ||
| Copyright (C) 2024 THL A29 Limited, | ||
| a Tencent company. All rights reserved. | ||
| Licensed under the MIT License (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at http://opensource.org/licenses/MIT | ||
| 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. | ||
|
|
||
| We undertake not to change the open source license (MIT license) applicable | ||
|
|
||
| to the current version of the project delivered to anyone in the future. | ||
| """ | ||
|
|
||
| from bkflow.pipeline_validate.validators.general import PipelineTreeValidator # noqa | ||
| from bkflow.pipeline_validate.validators.task import ( # noqa | ||
| ContextHydrateValidator, | ||
| MakoKeywordValidator, | ||
| ) | ||
| from bkflow.pipeline_validate.validators.template import ( # noqa | ||
| ConstantsKeyPatternValidator, | ||
| ConstantsSourceInfoValidator, | ||
| MutualExclusionValidator, | ||
| OutputsKeyPatternValidator, | ||
| SchemaValidator, | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| """ | ||
| TencentBlueKing is pleased to support the open source community by making | ||
| 蓝鲸流程引擎服务 (BlueKing Flow Engine Service) available. | ||
| Copyright (C) 2024 THL A29 Limited, | ||
| a Tencent company. All rights reserved. | ||
| Licensed under the MIT License (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at http://opensource.org/licenses/MIT | ||
| 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. | ||
|
|
||
| We undertake not to change the open source license (MIT license) applicable | ||
|
|
||
| to the current version of the project delivered to anyone in the future. | ||
| """ | ||
| from typing import Dict | ||
|
|
||
| from bkflow.pipeline_validate.handler import ValidatorHandler | ||
|
|
||
|
|
||
| class ValidatorResult: | ||
| def __init__(self, is_valid: bool, error: str = None): | ||
| self.is_valid = is_valid | ||
| self.error = error | ||
|
|
||
|
|
||
| class BasePipelineValidator: | ||
| name = None | ||
| validate_type = None | ||
|
|
||
| def __init_subclass__(cls, *args, **kwargs): | ||
| super().__init_subclass__(*args, **kwargs) | ||
|
|
||
| # 检查继承的类中是否有 validate 方法 | ||
| if not hasattr(cls, "validate"): | ||
| raise ValueError(f"[{cls.__name__}] Missing required method: validate") | ||
|
|
||
| necessary_attrs = ["name", "validate_type"] | ||
| for attr in necessary_attrs: | ||
| if not hasattr(cls, attr) or getattr(cls, attr) is None: | ||
| raise ValueError(f"[{cls.__name__}] Missing required attribute: {attr}") | ||
|
|
||
| ValidatorHandler.register(cls) | ||
|
|
||
| @classmethod | ||
| def validate(cls, web_pipeline_tree: Dict) -> ValidatorResult: | ||
| raise NotImplementedError("子类必须实现 validate 方法") | ||
|
|
||
|
|
||
| def _get_constant_display_name(const: dict, key: str) -> str: | ||
| """获取变量的显示名称,优先使用 name 字段""" | ||
| name = const.get("name", "") | ||
| if name: | ||
| return f"「{name}」({key})" | ||
| return f"「{key}」" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| """ | ||
| TencentBlueKing is pleased to support the open source community by making | ||
| 蓝鲸流程引擎服务 (BlueKing Flow Engine Service) available. | ||
| Copyright (C) 2024 THL A29 Limited, | ||
| a Tencent company. All rights reserved. | ||
| Licensed under the MIT License (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at http://opensource.org/licenses/MIT | ||
| 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. | ||
|
|
||
| We undertake not to change the open source license (MIT license) applicable | ||
|
|
||
| to the current version of the project delivered to anyone in the future. | ||
| """ | ||
| from pipeline.validators import validate_pipeline_tree | ||
|
|
||
| from bkflow.constants import ValidateType | ||
| from bkflow.pipeline_validate.validators.base import ( | ||
| BasePipelineValidator, | ||
| ValidatorResult, | ||
| ) | ||
|
|
||
|
|
||
| class PipelineTreeValidator(BasePipelineValidator): | ||
| name = "pipeline_tree_validator" | ||
| validate_type = ValidateType.GENERAL.value | ||
|
|
||
| @classmethod | ||
| def validate(cls, web_pipeline_tree: dict) -> ValidatorResult: | ||
| try: | ||
| validate_pipeline_tree(web_pipeline_tree, cycle_tolerate=True) | ||
| return ValidatorResult(is_valid=True) | ||
| except Exception as e: | ||
| error_message = f"流程树校验失败: {str(e)}" | ||
| return ValidatorResult(is_valid=False, error=error_message) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.