Skip to content

Commit

Permalink
Merge pull request #175 from alex-smile/update_system_doc_category
Browse files Browse the repository at this point in the history
update system/doc-category manage
  • Loading branch information
alex-smile authored Mar 13, 2020
2 parents 98af7a3 + 1a42b30 commit 8680c9f
Show file tree
Hide file tree
Showing 10 changed files with 172 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ def get_client_by_request(request, **kwargs):
:param request: 一个django request实例
:returns: 一个初始化好的ComponentClint对象
"""

if request.user.is_authenticated():
is_authenticated = request.user.is_authenticated
if callable(is_authenticated):
is_authenticated = is_authenticated()
if is_authenticated:
bk_token = request.COOKIES.get('bk_token', '')
else:
bk_token = ''
Expand Down
63 changes: 15 additions & 48 deletions paas-ce/paas/esb/common/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
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.
""" # noqa
from django.utils.translation import ugettext_lazy as _
from enum import Enum

from common.base_utils import FancyDict

Expand All @@ -32,50 +32,17 @@
))


BK_SYSTEMS = {
'BK_LOGIN': {
'name': 'BK_LOGIN',
'label': _(u'蓝鲸统一登录'),
'remark': u'蓝鲸统一登录,管理用户登录验证,及用户信息',
},
'BK_PAAS': {
'name': 'BK_PAAS',
'label': _(u'蓝鲸开发者中心'),
'remark': u'蓝鲸开发者中心',
},
'CC': {
'name': 'CC',
'label': _(u'蓝鲸配置平台'),
'remark': u'蓝鲸配置平台是一款面向应用的CMDB,在ITIL体系里,CMDB是构建其它流程的基石,而在蓝鲸智云体系里,配置平台就扮演着基石的角色,为应用提供了各种运维场景的配置数据服务。',
},
'GSE': {
'name': 'GSE',
'label': _(u'蓝鲸管控平台'),
'remark': u'蓝鲸管控平台',
},
'JOB': {
'name': 'JOB',
'label': _(u'蓝鲸作业平台'),
'remark': u'作业平台(Job)是一套基于蓝鲸智云管控平台Agent管道之上的基础操作平台,具备大并发处理能力;除了支持脚本执行、文件拉取/分发、定时任务等一系列可实现的基础运维场景以外,还运用流程化的理念很好的将零碎的单个任务组装成一个作业流程;而每个任务都可做为一个原子节点,提供给其它系统和平台调度,实现调度自动化。', # noqa
},
'CMSI': {
'name': 'CMSI',
'label': _(u'蓝鲸消息管理'),
'remark': u'蓝鲸消息管理,用于支持向用户发送多种类型的消息,包括邮件、短信、语音通知等',
},
'SOPS': {
'name': 'SOPS',
'label': _(u'标准运维'),
'remark': u'标准运维',
},
'MONITOR': {
'name': 'MONITOR',
'label': _(u'蓝鲸监控'),
'remark': u'蓝鲸监控',
},
'ESB': {
'name': 'ESB',
'label': u'API网关',
'remark': u'API网关',
},
}
class CacheTimeLevel(Enum):

CACHE_TIME_SHORT = 5 * 60
CACHE_TIME_MEDIUM = 3600
CACHE_TIME_LONG = 24 * 3600


CACHE_MAXSIZE = 2000


class FunctionControllerCodeEnum(Enum):

SKIP_USER_AUTH = "user_auth::skip_user_auth"
JWT_KEY = "jwt::private_public_key"
3 changes: 3 additions & 0 deletions paas-ce/paas/esb/components/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,15 @@ def get_request_info(self):

if self.dest_http_method == 'GET':
params, data = params, None
headers = {}
else:
params, data = None, json.dumps(params)
headers = {'Content-Type': 'application/json'}
return {
'path': path,
'params': params,
'data': data,
'headers': headers,
}

def get_extra_param_fields(self):
Expand Down
110 changes: 110 additions & 0 deletions paas-ce/paas/esb/components/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# -*- coding: utf-8 -*-
"""
Tencent is pleased to support the open source community by making 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community Edition) available.
Copyright (C) 2017-2018 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.
""" # noqa
from enum import Enum
from django.utils.translation import ugettext_lazy as _


class SystemDocCategoryEnum(Enum):
DEFAULT = u'默认分类'
USER_BASE_SERVICE = u'基础用户服务'
CONFIG_SERVICE = u'配置管理'
HOST_MANAGEMENT = u'主机管控'
MANAGEMENT_TOOLS = u'管理工具'


SYSTEM_DOC_CATEGORY = [
{
'name': 'default',
'label': SystemDocCategoryEnum.DEFAULT.value,
'priority': 1,
'systems': [],
},
{
'name': 'user_base_service',
'label': SystemDocCategoryEnum.USER_BASE_SERVICE.value,
'priority': 10,
'systems': [],
},
{
'name': 'config_service',
'label': SystemDocCategoryEnum.CONFIG_SERVICE.value,
'priority': 20,
'systems': [],
},
{
'name': 'host_management',
'label': SystemDocCategoryEnum.HOST_MANAGEMENT.value,
'priority': 30,
'systems': [],
},
{
'name': 'management_tools',
'label': SystemDocCategoryEnum.MANAGEMENT_TOOLS.value,
'priority': 50,
'systems': [],
},
]


BK_SYSTEMS = {
'BK_LOGIN': {
'name': 'BK_LOGIN',
'label': _(u'蓝鲸统一登录'),
'remark': _(u'蓝鲸统一登录,管理用户登录验证,及用户信息'),
'doc_category': SystemDocCategoryEnum.USER_BASE_SERVICE.value,
},
'BK_PAAS': {
'name': 'BK_PAAS',
'label': _(u'蓝鲸开发者中心'),
'remark': _(u'蓝鲸开发者中心'),
'doc_category': SystemDocCategoryEnum.USER_BASE_SERVICE.value,
},
'CC': {
'name': 'CC',
'label': _(u'蓝鲸配置平台'),
'remark': _(u'蓝鲸配置平台是一款面向应用的CMDB,在ITIL体系里,CMDB是构建其它流程的基石,而在蓝鲸智云体系里,配置平台就扮演着基石的角色,为应用提供了各种运维场景的配置数据服务。'),
'doc_category': SystemDocCategoryEnum.CONFIG_SERVICE.value,
},
'GSE': {
'name': 'GSE',
'label': _(u'蓝鲸管控平台'),
'remark': _(u'蓝鲸管控平台'),
'doc_category': SystemDocCategoryEnum.HOST_MANAGEMENT.value,
},
'JOB': {
'name': 'JOB',
'label': _(u'蓝鲸作业平台'),
'remark': _(u'作业平台(Job)是一套基于蓝鲸智云管控平台Agent管道之上的基础操作平台,具备大并发处理能力;除了支持脚本执行、文件拉取/分发、定时任务等一系列可实现的基础运维场景以外,还运用流程化的理念很好的将零碎的单个任务组装成一个作业流程;而每个任务都可做为一个原子节点,提供给其它系统和平台调度,实现调度自动化。'), # noqa
'doc_category': SystemDocCategoryEnum.HOST_MANAGEMENT.value,
},
'CMSI': {
'name': 'CMSI',
'label': _(u'蓝鲸消息管理'),
'remark': _(u'蓝鲸消息管理,用于支持向用户发送多种类型的消息,包括邮件、短信、语音通知等'),
'doc_category': SystemDocCategoryEnum.USER_BASE_SERVICE.value,
},
'SOPS': {
'name': 'SOPS',
'label': _(u'标准运维'),
'remark': _(u'标准运维'),
'doc_category': SystemDocCategoryEnum.MANAGEMENT_TOOLS.value,
},
'MONITOR': {
'name': 'MONITOR',
'label': _(u'蓝鲸监控'),
'remark': _(u'蓝鲸监控'),
'doc_category': SystemDocCategoryEnum.MANAGEMENT_TOOLS.value,
},
'ESB': {
'name': 'ESB',
'label': _(u'API网关'),
'remark': _(u'API网关'),
'doc_category': SystemDocCategoryEnum.MANAGEMENT_TOOLS.value,
},
}
6 changes: 2 additions & 4 deletions paas-ce/paas/esb/configs/default_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
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.
""" # noqa
"""项目 settings 配置模板
"""

# Generic Django project settings
DEBUG = False
Expand All @@ -22,19 +24,15 @@
}
}


# Log settings
LOG_LEVEL = 'INFO'

# esb app_token
ESB_TOKEN = '41f076b7-afce-46eb-9e85-dab245eb0931'

# Third party system host

# paas host
PAAS_HOST = 'http://127.0.0.1:8001'

# Third party system host
# host for bk login
HOST_BK_LOGIN = 'http://127.0.0.1:8003'

Expand Down
2 changes: 1 addition & 1 deletion paas-ce/paas/esb/esb/bkcore/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from django.db import models
from django.utils import timezone

from common.constants import BK_SYSTEMS
from components.constants import BK_SYSTEMS


class ComponentSystem(models.Model):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,29 @@ def handle(self, *args, **options):
self.force = options['force']
self.warning_msgs = []

self.update_doc_category()
self.update_systems()
self.update_channels()
self.update_doc_category()
self.update_buffet_components()
self.update_system_doc_category()

for msg in self.warning_msgs:
logger.warning(msg)
logger.info('Sync system/channels done')

def update_systems(self):
default_update_fields = ['label', 'remark', 'interface_admin']
default_update_fields = ['label', 'remark', 'interface_admin', 'doc_category_id']
force_update_fields = ['execute_timeout', 'query_timeout']

doc_categories = self.get_doc_categories()

conf_client = conf_tools.ConfClient()
for system in conf_client.systems:
# 将系统配置中系统文档名称转换为系统分类ID
doc_category = doc_categories.get(system.get('doc_category'))
if doc_category:
system['doc_category_id'] = doc_category.id

component_system, created = ComponentSystem.objects.get_or_create(
name=system['name'],
defaults=self.get_by_fields(system, default_update_fields + force_update_fields)
Expand All @@ -73,7 +81,11 @@ def update_channels(self):

conf_client = conf_tools.ConfClient()
for system_name, channels in conf_client.channels.items():
system = ComponentSystem.objects.get(name=system_name)
try:
system = ComponentSystem.objects.get(name=system_name)
except ComponentSystem.DoesNotExist:
logger.warning('system %s does not exist, channels will not sync to db', system_name)
continue
for channel in channels:
is_hidden = channel.get('is_hidden', False)
is_deprecated = channel.get('is_deprecated', False)
Expand Down Expand Up @@ -122,12 +134,20 @@ def update_channels(self):
def update_doc_category(self):
conf_client = conf_tools.ConfClient()
for system_doc_category in conf_client.system_doc_category:
doc_category, created = SystemDocCategory.objects.get_or_create(
SystemDocCategory.objects.get_or_create(
name=system_doc_category['label'],
defaults={
'priority': system_doc_category['priority'],
}
)

def update_system_doc_category(self):
conf_client = conf_tools.ConfClient()
for system_doc_category in conf_client.system_doc_category:
# update_doc_category 已创建文档分类
doc_category = SystemDocCategory.objects.get(
name=system_doc_category['label'],
)
ComponentSystem.objects.filter(doc_category_id__isnull=True)\
.filter(name__in=system_doc_category['systems'])\
.update(doc_category_id=doc_category.id)
Expand Down Expand Up @@ -170,6 +190,12 @@ def update_buffet_components(self):
obj.__dict__.update(self.get_by_fields(component, force_update_fields))
obj.save()

def get_doc_categories(self):
return {
category.name: category
for category in SystemDocCategory.objects.all()
}

def get_by_fields(self, obj, fields):
return dict([
(field, obj[field])
Expand Down
5 changes: 2 additions & 3 deletions paas-ce/paas/esb/esb/management/utils/conf_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
import os
from importlib import import_module

from common.constants import BK_SYSTEMS
from components.constants import BK_SYSTEMS, SYSTEM_DOC_CATEGORY
from components.esb_conf import CUSTOM_APIS_REL_PATH
from esb.utils import fpath_to_module, config
from esb.utils.confapis import get_confapis_manager
from esb.management.utils import constants
from .channel_tools import ChannelClient
try:
from esb.management.utils import ee_constants as x_constants
Expand Down Expand Up @@ -57,7 +56,7 @@ def buffet_components(self):

@property
def default_system_doc_category(self):
return getattr(constants, 'SYSTEM_DOC_CATEGORY', [])
return SYSTEM_DOC_CATEGORY

@property
def default_systems(self):
Expand Down
Loading

0 comments on commit 8680c9f

Please sign in to comment.