Skip to content

Commit

Permalink
Merge pull request #3061 from jsonwan/github_perf/global_config
Browse files Browse the repository at this point in the history
perf: 升级工具支持输出平台信息全局配置JSON文件 #2999
  • Loading branch information
jsonwan authored Jun 20, 2024
2 parents 842d749 + c43a999 commit 614d2a5
Show file tree
Hide file tree
Showing 27 changed files with 606 additions and 231 deletions.
6 changes: 6 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,9 @@ echo $BK_CMDB_MONGODB_<tab>补全。

### 3.6.x -> 3.7.x
需要在更新Job后执行一次升级工具,用于为存量的作业模板/执行方案/定时任务/IP白名单中的主机数据添加hostId,以及迁移对所有业务生效的IP白名单数据。

### 3.7.x -> 3.8.x
无需执行升级工具。

### 3.8.x -> 3.9.x
需要在更新Job后执行一次升级工具,用于导出已配置的平台信息数据(title/footer/助手链接等),从3.9.3版本开始,作业平台改为使用基于BK-REPO的全局配置统一方案,升级任务运行后会输出平台信息全局配置base.js文件,以便于迁移之前用户已通过页面【平台管理-全局设置-平台信息】配置的数据:将该任务生成的base.js文件导入BK-REPO中(若已存在则覆盖),路径取值与chart values的bkSharedResUrl、bkSharedBaseJsPath配置项保持一致,默认为:${当前环境部署的BK-REPO根地址}/generic/blueking/bk-config/bk_job/base.js。
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import com.tencent.bk.job.common.util.json.JsonUtils;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Tag;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
Expand Down Expand Up @@ -108,6 +109,7 @@ public class ArtifactoryClient {
public static final String URL_CREATE_REPO = "/repository/api/repo/create";
public static final String URL_CHECK_REPO_EXIST = "/repository/api/repo/exist/{projectId}/{repoName}";

@Getter
private final String baseUrl;
private final String username;
private final String password;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ public class RelatedUrlKeys {
public static final String KEY_BK_DOC_JOB_ROOT_URL = "BK_DOC_JOB_ROOT_URL";
// 问题反馈
public static final String KEY_BK_FEED_BACK_ROOT_URL = "BK_FEED_BACK_ROOT_URL";
// 全局配置(title/footer/name/logo/产品商标)相关的前端资源文件base.js基础地址
public static final String KEY_BK_SHARED_RES_BASE_JS_URL = "BK_SHARED_RES_BASE_JS_URL";
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@

package com.tencent.bk.job.manage.api.web;

import com.tencent.bk.job.common.annotation.CompatibleImplementation;
import com.tencent.bk.job.common.annotation.WebAPI;
import com.tencent.bk.job.common.constant.CompatibleType;
import com.tencent.bk.job.common.model.Response;
import com.tencent.bk.job.manage.model.web.vo.globalsetting.AccountNameRulesWithDefaultVO;
import com.tencent.bk.job.manage.model.web.vo.globalsetting.NotifyChannelWithIconVO;
Expand Down Expand Up @@ -113,6 +115,8 @@ Response<String> getCMDBAppIndexUrl(
);


@CompatibleImplementation(name = "platform_info", deprecatedVersion = "3.10.x", type = CompatibleType.DEPLOY,
explain = "发布完成后可以删除")
@ApiOperation(value = "获取渲染后的平台设置", produces = "application/json")
@GetMapping("/platformInfo")
Response<PlatformInfoVO> getRenderedPlatformInfo();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@

package com.tencent.bk.job.manage.api.web;

import com.tencent.bk.job.common.annotation.CompatibleImplementation;
import com.tencent.bk.job.common.annotation.WebAPI;
import com.tencent.bk.job.common.constant.CompatibleType;
import com.tencent.bk.job.common.model.Response;
import com.tencent.bk.job.manage.model.web.request.globalsetting.AccountNameRulesReq;
import com.tencent.bk.job.manage.model.web.request.globalsetting.FileUploadSettingReq;
Expand All @@ -36,7 +38,6 @@
import com.tencent.bk.job.manage.model.web.vo.globalsetting.AccountNameRulesWithDefaultVO;
import com.tencent.bk.job.manage.model.web.vo.globalsetting.FileUploadSettingVO;
import com.tencent.bk.job.manage.model.web.vo.globalsetting.NotifyChannelWithIconVO;
import com.tencent.bk.job.manage.model.web.vo.globalsetting.PlatformInfoVO;
import com.tencent.bk.job.manage.model.web.vo.globalsetting.PlatformInfoWithDefaultVO;
import com.tencent.bk.job.manage.model.web.vo.notify.ChannelTemplateDetailWithDefaultVO;
import com.tencent.bk.job.manage.model.web.vo.notify.ChannelTemplateStatusVO;
Expand All @@ -48,7 +49,6 @@
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
Expand Down Expand Up @@ -233,17 +233,8 @@ Response<FileUploadSettingVO> getFileUploadSettings(
String username
);

@ApiOperation(value = "设置平台信息", produces = "application/json")
@PutMapping("/platformInfo")
Response<PlatformInfoVO> savePlatformInfo(
@ApiParam(value = "用户名,网关自动传入", required = true)
@RequestHeader("username")
String username,
@ApiParam(value = "设置平台信息请求体", required = true)
@RequestBody
PlatformInfoVO platformInfoVO
);

@CompatibleImplementation(name = "platform_info", deprecatedVersion = "3.10.x", type = CompatibleType.DEPLOY,
explain = "发布完成后可以删除")
@ApiOperation(value = "获取平台信息-包含默认配置", produces = "application/json")
@GetMapping("/platformInfoWithDefault")
Response<PlatformInfoWithDefaultVO> getPlatformInfoWithDefault(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available.
*
* Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
*
* BK-JOB蓝鲸智云作业平台 is licensed under the MIT License.
*
* License for BK-JOB蓝鲸智云作业平台:
* --------------------------------------------------------------------
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of
* the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/

package com.tencent.bk.job.manage.model.migration;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
public class BkPlatformInfo {

@JsonProperty("bkAppCode")
private String bkAppCode = "bk_job";

@JsonProperty("name")
private String name = "蓝鲸作业平台";

@JsonProperty("nameEn")
private String nameEn = "JOB";

@JsonProperty("appLogo")
private String appLogo = "bk_job.png";

@JsonProperty("favIcon")
private String favIcon = "bk_job.png";

@JsonProperty("helperText")
private String helperText = "联系BK助手";

@JsonProperty("helperTextEn")
private String helperTextEn = "Contact BK Assistant";

@JsonProperty("helperLink")
private String helperLink = "wxwork://message/?username=BK%E5%8A%A9%E6%89%8B";

@JsonProperty("brandImg")
private String brandImg = "brand_img.png";

@JsonProperty("brandImgEn")
private String brandImgEn = "brand_img.png";

@JsonProperty("brandName")
private String brandName = "腾讯蓝鲸智云";

@JsonProperty("brandNameEn")
private String brandNameEn = "BlueKing";

@JsonProperty("footerInfo")
private String footerInfo = "[技术支持](https://wpa1.qq.com/KziXGWJs?_type=wpa&qidian=true) | [社区论坛](https://bk" +
".tencent.com/s-mart/community/) | [产品官网](https://bk.tencent.com/index/)";

@JsonProperty("footerInfoEn")
private String footerInfoEn = "[Support](https://wpa1.qq.com/KziXGWJs?_type=wpa&qidian=true) | [Forum](https://bk" +
".tencent.com/s-mart/community/) | [Official](https://bk.tencent.com/index/)";

@JsonProperty("footerCopyright")
private String footerCopyright = "Copyright © 2012 Tencent BlueKing. All Rights Reserved. {{version}}";
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import com.tencent.bk.job.manage.api.inner.ServiceGlobalSettingsResource;
import com.tencent.bk.job.manage.model.inner.ServiceFileUploadSettingDTO;
import com.tencent.bk.job.manage.model.web.vo.globalsetting.FileUploadSettingVO;
import com.tencent.bk.job.manage.service.GlobalSettingsService;
import com.tencent.bk.job.manage.service.globalsetting.GlobalSettingsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,15 @@
import com.tencent.bk.job.manage.migration.UpdateAppIdForWhiteIpMigrationTask;
import com.tencent.bk.job.manage.model.dto.ResourceTagDTO;
import com.tencent.bk.job.manage.model.migration.AddHostIdMigrationReq;
import com.tencent.bk.job.manage.model.migration.BkPlatformInfo;
import com.tencent.bk.job.manage.model.migration.MigrationRecordsResult;
import com.tencent.bk.job.manage.model.migration.SetBizSetMigrationStatusReq;
import com.tencent.bk.job.manage.model.migration.UpdateAppIdForWhiteIpMigrationReq;
import com.tencent.bk.job.manage.service.globalsetting.BkPlatformInfoService;
import com.tencent.bk.job.manage.service.impl.BizSetService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -65,6 +68,7 @@ public class MigrationResource {
private final UpdateAppIdForWhiteIpMigrationTask updateAppIdForWhiteIpMigrationTask;
private final AddHostIdForWhiteIpMigrationTask addHostIdForWhiteIpMigrationTask;
private final AppScopeMappingService appScopeMappingService;
private final BkPlatformInfoService bkPlatformInfoService;

@Autowired
public MigrationResource(
Expand All @@ -74,14 +78,16 @@ public MigrationResource(
AddHostIdForTemplateAndPlanMigrationTask addHostIdForTemplateAndPlanMigrationTask,
UpdateAppIdForWhiteIpMigrationTask updateAppIdForWhiteIpMigrationTask,
AddHostIdForWhiteIpMigrationTask addHostIdForWhiteIpMigrationTask,
AppScopeMappingService appScopeMappingService) {
AppScopeMappingService appScopeMappingService,
BkPlatformInfoService bkPlatformInfoService) {
this.encryptDbAccountPasswordMigrationTask = encryptDbAccountPasswordMigrationTask;
this.resourceTagsMigrationTask = resourceTagsMigrationTask;
this.bizSetService = bizSetService;
this.addHostIdForTemplateAndPlanMigrationTask = addHostIdForTemplateAndPlanMigrationTask;
this.updateAppIdForWhiteIpMigrationTask = updateAppIdForWhiteIpMigrationTask;
this.addHostIdForWhiteIpMigrationTask = addHostIdForWhiteIpMigrationTask;
this.appScopeMappingService = appScopeMappingService;
this.bkPlatformInfoService = bkPlatformInfoService;
}

/**
Expand Down Expand Up @@ -151,4 +157,12 @@ public Response<String> addHostIdMigrationTask(@RequestBody AddHostIdMigrationRe
Response.buildCommonFailResp(ErrorCode.MIGRATION_FAIL, new String[]{"AddHostIdMigrationTask",
JsonUtils.toJson(results)});
}

/**
* 获取蓝鲸统一规范的平台配置信息
*/
@GetMapping("/action/getBkPlatformInfo")
public Response<BkPlatformInfo> getBkPlatformInfo() {
return Response.buildSuccessResp(bkPlatformInfoService.getCurrentBkPlatformInfo());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
import com.tencent.bk.job.manage.model.web.vo.UploadLocalFileResultVO;
import com.tencent.bk.job.manage.model.web.vo.UploadTargetVO;
import com.tencent.bk.job.manage.model.web.vo.globalsetting.FileUploadSettingVO;
import com.tencent.bk.job.manage.service.GlobalSettingsService;
import com.tencent.bk.job.manage.service.globalsetting.GlobalSettingsService;
import io.netty.util.internal.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import com.tencent.bk.job.manage.model.web.vo.globalsetting.NotifyChannelWithIconVO;
import com.tencent.bk.job.manage.model.web.vo.globalsetting.PlatformInfoVO;
import com.tencent.bk.job.manage.service.ApplicationService;
import com.tencent.bk.job.manage.service.GlobalSettingsService;
import com.tencent.bk.job.manage.service.globalsetting.GlobalSettingsService;
import com.tencent.bk.job.manage.service.PublicScriptService;
import lombok.extern.slf4j.Slf4j;
import org.jooq.tools.StringUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,12 @@
import com.tencent.bk.job.manage.model.web.vo.globalsetting.AccountNameRulesWithDefaultVO;
import com.tencent.bk.job.manage.model.web.vo.globalsetting.FileUploadSettingVO;
import com.tencent.bk.job.manage.model.web.vo.globalsetting.NotifyChannelWithIconVO;
import com.tencent.bk.job.manage.model.web.vo.globalsetting.PlatformInfoVO;
import com.tencent.bk.job.manage.model.web.vo.globalsetting.PlatformInfoWithDefaultVO;
import com.tencent.bk.job.manage.model.web.vo.notify.ChannelTemplateDetailWithDefaultVO;
import com.tencent.bk.job.manage.model.web.vo.notify.ChannelTemplateStatusVO;
import com.tencent.bk.job.manage.model.web.vo.notify.NotifyBlackUserInfoVO;
import com.tencent.bk.job.manage.model.web.vo.notify.UserVO;
import com.tencent.bk.job.manage.service.GlobalSettingsService;
import com.tencent.bk.job.manage.service.globalsetting.GlobalSettingsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
Expand Down Expand Up @@ -197,14 +196,6 @@ public Response<FileUploadSettingVO> getFileUploadSettings(String username) {
return Response.buildSuccessResp(globalSettingsService.getFileUploadSettings());
}

@Override
@AuditEntry(actionId = ActionId.GLOBAL_SETTINGS)
public Response<PlatformInfoVO> savePlatformInfo(String username,
@AuditRequestBody PlatformInfoVO platformInfoVO) {
PlatformInfoVO updatedPlatformInfo = globalSettingsService.savePlatformInfo(username, platformInfoVO);
return Response.buildSuccessResp(updatedPlatformInfo);
}

@Override
@AuditEntry(actionId = ActionId.GLOBAL_SETTINGS)
@ActionAuditRecord(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ public class JobManageConfig {
@Value("${bk.feedback.root:}")
private String bkFeedBackRoot;

@Value("${bk.sharedResUrl:}")
private String bkSharedResUrl;

@Value("${bk.sharedBaseJsPath:/bk_job/base.js}")
private String bkSharedBaseJsPath;

@Value("${bk.ce.root:https://bk.tencent.com}")
private String bkCERoot;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import com.tencent.bk.job.manage.model.web.request.notify.NotifyPoliciesCreateUpdateReq;
import com.tencent.bk.job.manage.model.web.request.notify.ResourceStatusChannel;
import com.tencent.bk.job.manage.model.web.request.notify.TriggerPolicy;
import com.tencent.bk.job.manage.service.GlobalSettingsService;
import com.tencent.bk.job.manage.service.globalsetting.GlobalSettingsService;
import com.tencent.bk.job.manage.service.NotifyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available.
*
* Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
*
* BK-JOB蓝鲸智云作业平台 is licensed under the MIT License.
*
* License for BK-JOB蓝鲸智云作业平台:
* --------------------------------------------------------------------
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of
* the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/

package com.tencent.bk.job.manage.service.globalsetting;

import com.tencent.bk.job.manage.model.migration.BkPlatformInfo;

public interface BkPlatformInfoService {
/**
* 获取当前使用的蓝鲸平台信息
*
* @return 当前使用的蓝鲸平台信息
*/
BkPlatformInfo getCurrentBkPlatformInfo();
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* IN THE SOFTWARE.
*/

package com.tencent.bk.job.manage.service;
package com.tencent.bk.job.manage.service.globalsetting;

import com.tencent.bk.job.manage.api.common.constants.OSTypeEnum;
import com.tencent.bk.job.manage.model.web.request.globalsetting.AccountNameRule;
Expand Down Expand Up @@ -75,14 +75,6 @@ public interface GlobalSettingsService {

FileUploadSettingVO getFileUploadSettings();

/**
* 全局设置-平台信息-保存
*
* @param username 用户名
* @param platformInfoVO 平台信息
*/
PlatformInfoVO savePlatformInfo(String username, PlatformInfoVO platformInfoVO);

/**
* 获取渲染之后的平台信息
*
Expand Down
Loading

0 comments on commit 614d2a5

Please sign in to comment.