diff --git a/config/default.py b/config/default.py index cbfce85c0a..71d04329bb 100644 --- a/config/default.py +++ b/config/default.py @@ -57,7 +57,7 @@ 'gcloud.periodictask', 'pipeline', 'pipeline.component_framework', - 'pipeline.variables', + 'pipeline.variable_framework', 'pipeline.engine', 'pipeline.log', 'pipeline.contrib.statistics', diff --git a/frontend/desktop/src/api/index.js b/frontend/desktop/src/api/index.js index da4e2d5772..6944aa9ea2 100644 --- a/frontend/desktop/src/api/index.js +++ b/frontend/desktop/src/api/index.js @@ -157,7 +157,7 @@ const api = { * 获取自定义全局变量列表 */ getCustomVarCollection () { - const prefixUrl = this.getPrefix('query_custom_variables_collection') + const prefixUrl = this.getPrefix('variable') const opts = { method: 'GET', url: prefixUrl @@ -1291,14 +1291,14 @@ const api = { } return request(opts) }, - + /** * 查询业务在 CMDB 的主机 * @param {Array} filels 主机查询字段 */ loadHostInCC (fields) { const prefixUrl = this.getPrefix('cc_search_host') - + const opts = { method: 'GET', url: prefixUrl, @@ -1313,7 +1313,7 @@ const api = { */ loadTopoTreeInCC () { const prefixUrl = this.getPrefix('cc_search_topo_tree') - + const opts = { method: 'GET', url: prefixUrl @@ -1325,7 +1325,7 @@ const api = { */ loadTopoModelInCC () { const prefixUrl = this.getPrefix('cc_get_mainline_object_topo') - + const opts = { method: 'GET', url: prefixUrl diff --git a/frontend/desktop/src/api/urls.js b/frontend/desktop/src/api/urls.js index 7f511c9332..bd8cb0970f 100644 --- a/frontend/desktop/src/api/urls.js +++ b/frontend/desktop/src/api/urls.js @@ -81,7 +81,6 @@ export function getUrlSetting (SITE_URL, BIZ_CC_ID) { taskCreateMethod: SITE_URL + 'taskflow/api/get_task_create_method/', cc_search_host: SITE_URL + 'pipeline/cc_search_host/' + BIZ_CC_ID + '/', cc_search_topo_tree: SITE_URL + 'pipeline/cc_search_topo_tree/' + BIZ_CC_ID + '/', - cc_get_mainline_object_topo: SITE_URL + 'pipeline/cc_get_mainline_object_topo/' + BIZ_CC_ID + '/', - query_custom_variables_collection: SITE_URL + 'pipeline/query_custom_variables_collection/' + cc_get_mainline_object_topo: SITE_URL + 'pipeline/cc_get_mainline_object_topo/' + BIZ_CC_ID + '/' } } diff --git a/frontend/desktop/src/pages/template/TemplateEdit/index.vue b/frontend/desktop/src/pages/template/TemplateEdit/index.vue index 6b4e00e4f8..d8fc8f5ff5 100644 --- a/frontend/desktop/src/pages/template/TemplateEdit/index.vue +++ b/frontend/desktop/src/pages/template/TemplateEdit/index.vue @@ -357,28 +357,24 @@ this.customVarCollectionLoading = true try { const customVarCollection = await this.loadCustomVarCollection() - if (customVarCollection.result) { - const listData = [ - { - name: gettext('普通变量'), - children: [] - }, - { - name: gettext('元变量'), - children: [] - } - ] - customVarCollection.data.forEach(item => { - if (item.type === 'general') { - listData[0].children.push(item) - } else { - listData[1].children.push(item) - } - }) - this.variableTypeList = listData - } else { - errorHandler(customVarCollection, this) - } + const listData = [ + { + name: gettext('普通变量'), + children: [] + }, + { + name: gettext('元变量'), + children: [] + } + ] + customVarCollection.forEach(item => { + if (item.type === 'general') { + listData[0].children.push(item) + } else { + listData[1].children.push(item) + } + }) + this.variableTypeList = listData } catch (e) { errorHandler(e, this) } finally { @@ -521,7 +517,7 @@ atomGrouped[index].list.push(item) } }) - + this.subAtomGrouped = atomGrouped }, toggleSettingPanel (isSettingPanelShow) { diff --git a/frontend/desktop/src/store/modules/template.js b/frontend/desktop/src/store/modules/template.js index 4f47e83fe8..59680dcf26 100644 --- a/frontend/desktop/src/store/modules/template.js +++ b/frontend/desktop/src/store/modules/template.js @@ -741,7 +741,7 @@ const template = { return api.getTemplateData(data).then(response => response.data) }, loadCustomVarCollection () { - return api.getCustomVarCollection().then(response => response.data) + return api.getCustomVarCollection().then(response => response.data.objects) }, // 保存模板数据 saveTemplateData ({ state }, { templateId, ccId, common }) { diff --git a/gcloud/webservice3/resources.py b/gcloud/webservice3/resources.py index 71e47c421c..cc73b76ae3 100644 --- a/gcloud/webservice3/resources.py +++ b/gcloud/webservice3/resources.py @@ -31,8 +31,7 @@ from pipeline.component_framework.library import ComponentLibrary from pipeline.component_framework.models import ComponentModel -from pipeline.core.data.library import VariableLibrary -from pipeline.models import VariableModel +from pipeline.variable_framework.models import VariableModel from gcloud import exceptions from gcloud.core.models import Business from gcloud.core.utils import ( @@ -340,7 +339,7 @@ class ComponentModelResource(ModelResource): null=True) class Meta: - queryset = ComponentModel.objects.filter(status=1).order_by('name') + queryset = ComponentModel.objects.filter(status=True).order_by('name') resource_name = 'component' excludes = ['status', 'id'] detail_uri_name = 'code' @@ -376,27 +375,32 @@ def alter_detail_data_to_serialize(self, request, data): class VariableModelResource(ModelResource): + name = fields.CharField( + attribute='name', + readonly=True, + null=True) + form = fields.CharField( + attribute='form', + readonly=True, + null=True) + type = fields.CharField( + attribute='type', + readonly=True, + null=True) + tag = fields.CharField( + attribute='tag', + readonly=True, + null=True) + meta_tag = fields.CharField( + attribute='meta_tag', + readonly=True, + null=True) + class Meta: - queryset = VariableModel.objects.filter(status=1) + queryset = VariableModel.objects.filter(status=True) resource_name = 'variable' excludes = ['status', 'id'] detail_uri_name = 'code' ordering = ['id'] authorization = ReadOnlyAuthorization() limit = 0 - - def alter_list_data_to_serialize(self, request, data): - for bundle in data['objects']: - var = VariableLibrary.get_var_class(bundle.data['code']) - bundle.data['form'] = var.form - - return data - - def alter_detail_data_to_serialize(self, request, data): - bundle = data - var = VariableLibrary.get_var_class(bundle.data['code']) - is_meta = request.GET.get('meta', False) - form = getattr(var, 'meta_form') if bool(int(is_meta)) else var.form - bundle.data['form'] = form - - return data diff --git a/pipeline/admin.py b/pipeline/admin.py index 11771bb8c3..2161853434 100644 --- a/pipeline/admin.py +++ b/pipeline/admin.py @@ -31,10 +31,3 @@ class PipelineInstanceAdmin(admin.ModelAdmin): list_filter = ['is_started', 'is_finished', 'is_deleted'] search_fields = ['name'] raw_id_fields = ['template', 'snapshot', 'execution_snapshot'] - - -@admin.register(models.VariableModel) -class VariableModelAdmin(admin.ModelAdmin): - list_display = ['id', 'code', 'status'] - list_filter = ['status'] - search_fields = ['code', 'status'] diff --git a/pipeline/core/data/var.py b/pipeline/core/data/var.py index c51a7d4638..d0dfcbb1c3 100644 --- a/pipeline/core/data/var.py +++ b/pipeline/core/data/var.py @@ -116,7 +116,7 @@ def __new__(cls, name, bases, attrs): raise exceptions.ConstantReferenceException("LazyVariable %s: code can't be empty." % new_class.__name__) - pre_variable_register.send(sender=LazyVariable, variable_cls=new_class, variable_code=new_class.code) + pre_variable_register.send(sender=LazyVariable, variable_cls=new_class) library.VariableLibrary.variables[new_class.code] = new_class diff --git a/pipeline_plugins/variables/query/api.py b/pipeline/migrations/0019_delete_variablemodel.py similarity index 69% rename from pipeline_plugins/variables/query/api.py rename to pipeline/migrations/0019_delete_variablemodel.py index 78687c85c9..d19a2490ab 100644 --- a/pipeline_plugins/variables/query/api.py +++ b/pipeline/migrations/0019_delete_variablemodel.py @@ -11,16 +11,19 @@ specific language governing permissions and limitations under the License. """ -from django.http import JsonResponse -from django.views.decorators.http import require_GET +from __future__ import unicode_literals -from pipeline_plugins.variables.query import constants +from django.db import migrations -@require_GET -def query_custom_variables_collection(request): - ctx = { - 'result': True, - 'data': constants.VARIABLES_COLLECTION - } - return JsonResponse(ctx) +class Migration(migrations.Migration): + + dependencies = [ + ('pipeline', '0018_set_has_subprocess'), + ] + + operations = [ + migrations.DeleteModel( + name='VariableModel', + ), + ] diff --git a/pipeline/models.py b/pipeline/models.py index 17dfed1582..8f4cee4c30 100644 --- a/pipeline/models.py +++ b/pipeline/models.py @@ -775,20 +775,3 @@ def calculate_tree_info(self, save=False): if save: self.save() - - -class VariableModel(models.Model): - """ - 注册的变量 - """ - code = models.CharField(_(u"变量编码"), max_length=255, unique=True) - status = models.BooleanField(_(u"变量是否可用"), default=True) - - class Meta: - verbose_name = _(u"Variable变量") - verbose_name_plural = _(u"Variable变量") - ordering = ['-id'] - app_label = 'pipeline' - - def __unicode__(self): - return self.code diff --git a/pipeline_plugins/variables/query/constants.py b/pipeline/variable_framework/__init__.py similarity index 75% rename from pipeline_plugins/variables/query/constants.py rename to pipeline/variable_framework/__init__.py index 8aec3e1ca7..774b1d4dd3 100644 --- a/pipeline_plugins/variables/query/constants.py +++ b/pipeline/variable_framework/__init__.py @@ -11,10 +11,4 @@ specific language governing permissions and limitations under the License. """ -import importlib - -from django.conf import settings - -site_constants = importlib.import_module('pipeline_plugins.variables.query.sites.%s.constants' % settings.RUN_VER) - -VARIABLES_COLLECTION = getattr(site_constants, 'VARIABLES_COLLECTION') +default_app_config = 'pipeline.variable_framework.apps.VariableFrameworkConfig' diff --git a/pipeline/variable_framework/admin.py b/pipeline/variable_framework/admin.py new file mode 100644 index 0000000000..271f4936ee --- /dev/null +++ b/pipeline/variable_framework/admin.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +""" +Tencent is pleased to support the open source community by making 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community +Edition) available. +Copyright (C) 2017-2019 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. +""" + +from django.contrib import admin + +from pipeline.variable_framework import models + + +@admin.register(models.VariableModel) +class VariableModelAdmin(admin.ModelAdmin): + list_display = ['id', 'code', 'status'] + search_fields = ['code'] + list_filter = ['status'] diff --git a/pipeline/variables/apps.py b/pipeline/variable_framework/apps.py similarity index 79% rename from pipeline/variables/apps.py rename to pipeline/variable_framework/apps.py index eeaa93d4bc..5f32aa3708 100644 --- a/pipeline/variables/apps.py +++ b/pipeline/variable_framework/apps.py @@ -18,20 +18,20 @@ from pipeline.utils.register import autodiscover_collections -class VariablesConfig(AppConfig): - name = 'pipeline.variables' - verbose_name = 'PipelineVariables' +class VariableFrameworkConfig(AppConfig): + name = 'pipeline.variable_framework' + verbose_name = 'PipelineVariableFramework' def ready(self): """ - @summary: 注册公共部分和OPEN_VER下的变量到数据库 + @summary: 注册公共部分和RUN_VER下的变量到数据库 @return: """ - from pipeline.variables.signals.handlers import * # noqa + from pipeline.variable_framework.signals.handlers import * # noqa for path in settings.VARIABLE_AUTO_DISCOVER_PATH: autodiscover_collections(path) - from pipeline.models import VariableModel + from pipeline.variable_framework.models import VariableModel from pipeline.core.data.library import VariableLibrary try: VariableModel.objects.exclude(code__in=VariableLibrary.variables.keys()).update(status=False) diff --git a/pipeline/variable_framework/migrations/0001_initial.py b/pipeline/variable_framework/migrations/0001_initial.py new file mode 100644 index 0000000000..b45ef25f55 --- /dev/null +++ b/pipeline/variable_framework/migrations/0001_initial.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- +""" +Tencent is pleased to support the open source community by making 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community +Edition) available. +Copyright (C) 2017-2019 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. +""" + +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='VariableModel', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('code', models.CharField(max_length=255, unique=True, verbose_name='\u53d8\u91cf\u7f16\u7801')), + ('status', models.BooleanField(default=True, verbose_name='\u53d8\u91cf\u662f\u5426\u53ef\u7528')), + ], + options={ + 'verbose_name': 'Variable\u53d8\u91cf', + 'verbose_name_plural': 'Variable\u53d8\u91cf', + }, + ), + ] diff --git a/pipeline/variables/signals/__init__.py b/pipeline/variable_framework/migrations/__init__.py similarity index 100% rename from pipeline/variables/signals/__init__.py rename to pipeline/variable_framework/migrations/__init__.py diff --git a/pipeline/variable_framework/models.py b/pipeline/variable_framework/models.py new file mode 100644 index 0000000000..fca37e844c --- /dev/null +++ b/pipeline/variable_framework/models.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +""" +Tencent is pleased to support the open source community by making 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community +Edition) available. +Copyright (C) 2017-2019 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. +""" + +from django.db import models +from django.utils.translation import ugettext_lazy as _ + +from pipeline.core.data.library import VariableLibrary + + +class VariableModel(models.Model): + """ + 注册的变量 + """ + code = models.CharField(_(u"变量编码"), max_length=255, unique=True) + status = models.BooleanField(_(u"变量是否可用"), default=True) + + class Meta: + verbose_name = _(u"Variable变量") + verbose_name_plural = _(u"Variable变量") + + def __unicode__(self): + return self.code + + def get_class(self): + return VariableLibrary.get_var_class(self.code) + + @property + def name(self): + return self.get_class().name + + @property + def form(self): + return self.get_class().form + + @property + def type(self): + return self.get_class().type + + @property + def tag(self): + return self.get_class().tag + + @property + def meta_tag(self): + return getattr(self.get_class(), 'meta_tag') diff --git a/pipeline/variables/__init__.py b/pipeline/variable_framework/signals/__init__.py similarity index 92% rename from pipeline/variables/__init__.py rename to pipeline/variable_framework/signals/__init__.py index 618942a038..90524bb0e7 100644 --- a/pipeline/variables/__init__.py +++ b/pipeline/variable_framework/signals/__init__.py @@ -10,5 +10,3 @@ 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. """ - -default_app_config = 'pipeline.variables.apps.VariablesConfig' diff --git a/pipeline/variables/signals/handlers.py b/pipeline/variable_framework/signals/handlers.py similarity index 90% rename from pipeline/variables/signals/handlers.py rename to pipeline/variable_framework/signals/handlers.py index 011edfa2cc..4521843818 100644 --- a/pipeline/variables/signals/handlers.py +++ b/pipeline/variable_framework/signals/handlers.py @@ -14,14 +14,14 @@ from django.dispatch import receiver from django.db.utils import ProgrammingError from pipeline.core.data.var import LazyVariable -from pipeline.models import VariableModel +from pipeline.variable_framework.models import VariableModel from pipeline.core.signals import pre_variable_register @receiver(pre_variable_register, sender=LazyVariable) -def pre_variable_register_handler(sender, variable_code, variable_cls, **kwargs): +def pre_variable_register_handler(sender, variable_cls, **kwargs): try: - obj, created = VariableModel.objects.get_or_create(code=variable_code, + obj, created = VariableModel.objects.get_or_create(code=variable_cls.code, defaults={ 'status': __debug__, }) diff --git a/pipeline_plugins/variables/collections/common.py b/pipeline_plugins/variables/collections/common.py index 1b19ca329b..21cb761d29 100644 --- a/pipeline_plugins/variables/collections/common.py +++ b/pipeline_plugins/variables/collections/common.py @@ -13,6 +13,8 @@ import logging +from django.utils.translation import ugettext_lazy as _ + from pipeline.conf import settings from pipeline.core.data.var import ( SpliceVariable, @@ -29,26 +31,41 @@ class CommonPlainVariable(SpliceVariable): class Input(CommonPlainVariable): code = 'input' + name = _(u"输入框") + type = 'general' + tag = 'input.input' form = '%svariables/%s.js' % (settings.STATIC_URL, code) class Textarea(CommonPlainVariable): code = 'textarea' + name = _(u"文本框") + type = 'general' + tag = 'textarea.textarea' form = '%svariables/%s.js' % (settings.STATIC_URL, code) class Datetime(CommonPlainVariable): code = 'datetime' + name = _(u"日期时间") + type = 'general' + tag = 'datetime.datetime' form = '%svariables/%s.js' % (settings.STATIC_URL, code) class Int(CommonPlainVariable): code = 'int' + name = _(u"整数") + type = 'general' + tag = 'int.int' form = '%svariables/%s.js' % (settings.STATIC_URL, code) class Password(LazyVariable): code = 'password' + name = _(u"密码") + type = 'general' + tag = 'password.password' form = '%svariables/%s.js' % (settings.STATIC_URL, code) def get_value(self): @@ -57,6 +74,10 @@ def get_value(self): class Select(LazyVariable): code = 'select' + name = _(u"下拉框") + type = 'meta' + tag = 'select.select' + meta_tag = 'select.select_meta' form = '%svariables/%s.js' % (settings.STATIC_URL, code) def get_value(self): diff --git a/pipeline_plugins/variables/collections/sites/open/cc.py b/pipeline_plugins/variables/collections/sites/open/cc.py index bac102f205..d249e729d9 100644 --- a/pipeline_plugins/variables/collections/sites/open/cc.py +++ b/pipeline_plugins/variables/collections/sites/open/cc.py @@ -14,6 +14,8 @@ import logging import re +from django.utils.translation import ugettext_lazy as _ + from pipeline.conf import settings from pipeline_plugins.cmdb_ip_picker.utils import get_ip_picker_result from pipeline_plugins.components.utils import ( @@ -27,7 +29,10 @@ class VarIpPickerVariable(LazyVariable): - code = 'var_ip_picker' + code = 'ip' + name = _(u"IP选择器(简单版)") + type = 'general' + tag = 'var_ip_picker.ip_picker' form = '%svariables/sites/%s/var_ip_picker.js' % (settings.STATIC_URL, settings.RUN_VER) def get_value(self): @@ -76,7 +81,10 @@ def get_value(self): class VarCmdbIpSelector(LazyVariable): - code = 'var_cmdb_ip_selector' + code = 'ip_selector' + name = _(u"IP选择器") + type = 'general' + tag = 'var_cmdb_ip_selector.ip_selector' form = '%svariables/sites/%s/var_cmdb_ip_selector.js' % (settings.STATIC_URL, settings.RUN_VER) def get_value(self): diff --git a/pipeline_plugins/variables/query/sites/open/constants.py b/pipeline_plugins/variables/query/sites/open/constants.py deleted file mode 100644 index 787f8b07ec..0000000000 --- a/pipeline_plugins/variables/query/sites/open/constants.py +++ /dev/null @@ -1,67 +0,0 @@ -# -*- coding: utf-8 -*- -""" -Tencent is pleased to support the open source community by making 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community -Edition) available. -Copyright (C) 2017-2019 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. -""" - -from django.utils.translation import ugettext_lazy as _ - - -VARIABLES_COLLECTION = [ - { - 'name': _(u"输入框"), - 'key': 'input', - 'type': 'general', - 'tag': 'input.input' - }, - { - 'name': _(u"文本框"), - 'key': 'textarea', - 'type': 'general', - 'tag': 'textarea.textarea' - }, - { - 'name': _(u"日期时间"), - 'key': 'datetime', - 'type': 'general', - 'tag': 'datetime.datetime' - }, - { - 'name': _(u"整数"), - 'key': 'int', - 'type': 'general', - 'tag': 'int.int' - }, - { - 'name': _(u"IP选择器(简单版)"), - 'key': 'ip', - 'type': 'general', - 'tag': 'ip_picker.ip_picker' - }, - { - 'name': _(u"IP选择器"), - 'key': 'ip_selector', - 'type': 'general', - 'tag': 'ip_selector.ip_selector' - }, - { - 'name': _(u"密码"), - 'key': 'password', - 'type': 'general', - 'tag': 'password.password' - }, - { - 'name': _(u"下拉框"), - 'key': 'select', - 'type': 'meta', - 'tag': 'select.select', - 'meta_tag': 'select.select_meta' - }, -] diff --git a/pipeline_plugins/variables/urls.py b/pipeline_plugins/variables/urls.py index 4ad3e1ae46..1c56d14760 100644 --- a/pipeline_plugins/variables/urls.py +++ b/pipeline_plugins/variables/urls.py @@ -11,11 +11,4 @@ specific language governing permissions and limitations under the License. """ -# -*- coding: utf-8 -*- -from django.conf.urls import url - -from pipeline_plugins.variables.query import api - -urlpatterns = [ - url(r'^query_custom_variables_collection/$', api.query_custom_variables_collection), -] +urlpatterns = []