diff --git a/src/backend/commons/cmdb-sdk-model/src/main/java/com/tencent/bk/job/common/cc/model/BusinessInfoDTO.java b/src/backend/commons/cmdb-sdk-model/src/main/java/com/tencent/bk/job/common/cc/model/BusinessInfoDTO.java index a264ea114a..bfc3b8c029 100644 --- a/src/backend/commons/cmdb-sdk-model/src/main/java/com/tencent/bk/job/common/cc/model/BusinessInfoDTO.java +++ b/src/backend/commons/cmdb-sdk-model/src/main/java/com/tencent/bk/job/common/cc/model/BusinessInfoDTO.java @@ -30,29 +30,45 @@ import lombok.ToString; /** - * @description - * @date 2019/3/4 + * 业务DTO */ @Getter @Setter @ToString public class BusinessInfoDTO { + /** + * 业务ID + */ @JsonProperty("bk_biz_id") private Long bizId; + /** + * 业务名称 + */ @JsonProperty("bk_biz_name") private String bizName; + /** + * 业务运维 + */ @JsonProperty("bk_biz_maintainer") private String maintainers; + /** + * 开发商账号 + */ @JsonProperty("bk_supplier_account") private String supplierAccount; + /** + * 表示业务类型 + */ @JsonProperty("default") private Integer defaultApp; + /** + * 业务所在时区 + */ @JsonProperty("time_zone") private String timezone; - @JsonProperty("bk_operate_dept_id") - private Long operateDeptId; - @JsonProperty("bk_operate_dept_name") - private String operateDeptName; + /** + * 业务语言 + */ @JsonProperty("language") private String language; } diff --git a/src/backend/commons/cmdb-sdk-model/src/main/java/com/tencent/bk/job/common/cc/model/bizset/BasicBizSet.java b/src/backend/commons/cmdb-sdk-model/src/main/java/com/tencent/bk/job/common/cc/model/bizset/BasicBizSet.java deleted file mode 100644 index b2c0d8e6f8..0000000000 --- a/src/backend/commons/cmdb-sdk-model/src/main/java/com/tencent/bk/job/common/cc/model/bizset/BasicBizSet.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.tencent.bk.job.common.cc.model.bizset; - -import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import lombok.ToString; - -/** - * 基础业务集信息,用于生成更新CMDB业务集ID的Json数据文件 - */ -@Setter -@Getter -@AllArgsConstructor -@NoArgsConstructor -@ToString -public class BasicBizSet { - @JsonProperty("biz_set_id") - private Long id; - - @JsonProperty("biz_set_name") - private String name; -} diff --git a/src/backend/commons/cmdb-sdk-model/src/main/java/com/tencent/bk/job/common/cc/model/bizset/BatchUpdateBizSetData.java b/src/backend/commons/cmdb-sdk-model/src/main/java/com/tencent/bk/job/common/cc/model/bizset/BatchUpdateBizSetData.java deleted file mode 100644 index 27d0a82b9c..0000000000 --- a/src/backend/commons/cmdb-sdk-model/src/main/java/com/tencent/bk/job/common/cc/model/bizset/BatchUpdateBizSetData.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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.common.cc.model.bizset; - -import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; - -/** - * CMDB接口请求实体类,用于批量更新业务集 - */ -@Setter -@Getter -@ToString -public class BatchUpdateBizSetData { - - /** - * 业务集字段集合 - */ - @JsonProperty("bk_biz_set_attr") - private BizSetAttr attr; - - /** - * 业务集的业务选择范围 - */ - @JsonProperty("bk_scope") - private BizSetScope scope; - -} diff --git a/src/backend/commons/cmdb-sdk-model/src/main/java/com/tencent/bk/job/common/cc/model/bizset/BatchUpdateBizSetReq.java b/src/backend/commons/cmdb-sdk-model/src/main/java/com/tencent/bk/job/common/cc/model/bizset/BatchUpdateBizSetReq.java deleted file mode 100644 index 98ffb19002..0000000000 --- a/src/backend/commons/cmdb-sdk-model/src/main/java/com/tencent/bk/job/common/cc/model/bizset/BatchUpdateBizSetReq.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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.common.cc.model.bizset; - -import com.fasterxml.jackson.annotation.JsonProperty; -import com.tencent.bk.job.common.esb.model.EsbReq; -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; - -import java.util.List; - -/** - * CMDB接口请求实体类,用于批量更新业务集 - */ -@Setter -@Getter -@ToString -public class BatchUpdateBizSetReq extends EsbReq { - - /** - * 业务集ID列表 - */ - @JsonProperty("bk_biz_set_ids") - private List bizSetIds; - - /** - * 要更新的业务集数据 - */ - @JsonProperty("data") - private BatchUpdateBizSetData data; - -} diff --git a/src/backend/commons/cmdb-sdk-model/src/main/java/com/tencent/bk/job/common/cc/model/bizset/BizSetAttr.java b/src/backend/commons/cmdb-sdk-model/src/main/java/com/tencent/bk/job/common/cc/model/bizset/BizSetAttr.java deleted file mode 100644 index f8d9890d90..0000000000 --- a/src/backend/commons/cmdb-sdk-model/src/main/java/com/tencent/bk/job/common/cc/model/bizset/BizSetAttr.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * 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.common.cc.model.bizset; - -import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.Builder; -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; - -/** - * CMDB接口请求实体类,定义业务集字段 - */ -@Builder -@Setter -@Getter -@ToString -public class BizSetAttr { - - /** - * ID - */ - @JsonProperty("bk_biz_set_id") - private long id; - - /** - * 名称 - */ - @JsonProperty("bk_biz_set_name") - private String name; - - /** - * 描述 - */ - @JsonProperty("bk_biz_set_desc") - private String desc; - - /** - * 运维人员 - */ - @JsonProperty("bk_biz_maintainer") - private String maintainer; - - /** - * 供应商 - */ - @JsonProperty("bk_supplier_account") - private String supplierAccount; - - /** - * 时区 - */ - @JsonProperty("time_zone") - private String timeZone; - - /** - * 语言 - */ - private String language; - -} diff --git a/src/backend/commons/cmdb-sdk-model/src/main/java/com/tencent/bk/job/common/cc/model/bizset/BizSetInfo.java b/src/backend/commons/cmdb-sdk-model/src/main/java/com/tencent/bk/job/common/cc/model/bizset/BizSetInfo.java index 6c10bc515a..d99c0513ef 100644 --- a/src/backend/commons/cmdb-sdk-model/src/main/java/com/tencent/bk/job/common/cc/model/bizset/BizSetInfo.java +++ b/src/backend/commons/cmdb-sdk-model/src/main/java/com/tencent/bk/job/common/cc/model/bizset/BizSetInfo.java @@ -81,12 +81,6 @@ public class BizSetInfo { @JsonProperty("bk_supplier_account") private String supplierAccount; - /** - * 运维部门ID - */ - @JsonProperty("bk_operate_dept_id") - private Long operateDeptId; - /** * 时区 */ diff --git a/src/backend/commons/cmdb-sdk-model/src/main/java/com/tencent/bk/job/common/cc/model/bizset/CreateBizSetReq.java b/src/backend/commons/cmdb-sdk-model/src/main/java/com/tencent/bk/job/common/cc/model/bizset/CreateBizSetReq.java deleted file mode 100644 index 830d3030ca..0000000000 --- a/src/backend/commons/cmdb-sdk-model/src/main/java/com/tencent/bk/job/common/cc/model/bizset/CreateBizSetReq.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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.common.cc.model.bizset; - -import com.fasterxml.jackson.annotation.JsonProperty; -import com.tencent.bk.job.common.esb.model.EsbReq; -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; - -/** - * CMDB接口请求实体类,用于创建业务集 - */ -@Setter -@Getter -@ToString -public class CreateBizSetReq extends EsbReq { - - /** - * 业务集字段集合 - */ - @JsonProperty("bk_biz_set_attr") - private BizSetAttr attr; - - /** - * 业务集的业务选择范围 - */ - @JsonProperty("bk_scope") - private BizSetScope scope; - -} diff --git a/src/backend/commons/cmdb-sdk-model/src/main/java/com/tencent/bk/job/common/cc/model/bizset/SearchBizSetReq.java b/src/backend/commons/cmdb-sdk-model/src/main/java/com/tencent/bk/job/common/cc/model/bizset/SearchBizSetReq.java index 11a062d875..a2ebcf6e96 100644 --- a/src/backend/commons/cmdb-sdk-model/src/main/java/com/tencent/bk/job/common/cc/model/bizset/SearchBizSetReq.java +++ b/src/backend/commons/cmdb-sdk-model/src/main/java/com/tencent/bk/job/common/cc/model/bizset/SearchBizSetReq.java @@ -51,7 +51,7 @@ public class SearchBizSetReq extends EsbReq { * 查询字段 */ private List fields = Arrays.asList("bk_biz_set_id", "bk_biz_set_name", "bk_biz_set_desc", - "bk_biz_maintainer", "bk_supplier_account", "bk_operate_dept_id", "create_time", "last_time", "time_zone", + "bk_biz_maintainer", "bk_supplier_account", "create_time", "last_time", "time_zone", "language", "bk_scope"); /** diff --git a/src/backend/commons/cmdb-sdk-model/src/main/java/com/tencent/bk/job/common/cc/model/result/BizEventDetail.java b/src/backend/commons/cmdb-sdk-model/src/main/java/com/tencent/bk/job/common/cc/model/result/BizEventDetail.java index 1d15f167ff..2205294bb0 100644 --- a/src/backend/commons/cmdb-sdk-model/src/main/java/com/tencent/bk/job/common/cc/model/result/BizEventDetail.java +++ b/src/backend/commons/cmdb-sdk-model/src/main/java/com/tencent/bk/job/common/cc/model/result/BizEventDetail.java @@ -25,8 +25,6 @@ package com.tencent.bk.job.common.cc.model.result; import com.fasterxml.jackson.annotation.JsonProperty; -import com.tencent.bk.job.common.cc.util.VersionCompatUtil; -import com.tencent.bk.job.common.constant.AppTypeEnum; import com.tencent.bk.job.common.constant.ResourceScopeTypeEnum; import com.tencent.bk.job.common.model.dto.ApplicationDTO; import com.tencent.bk.job.common.model.dto.ResourceScope; @@ -45,16 +43,10 @@ public class BizEventDetail { private Long bizId; @JsonProperty("bk_biz_name") private String appName; - @JsonProperty("bk_biz_maintainer") - private String maintainers; @JsonProperty("bk_supplier_account") private String supplierAccount; @JsonProperty("time_zone") private String timezone; - @JsonProperty("bk_operate_dept_id") - private Long operateDeptId; - @JsonProperty("bk_operate_dept_name") - private String operateDeptName; @JsonProperty("language") private String language; @@ -62,12 +54,9 @@ public static ApplicationDTO toAppInfoDTO(BizEventDetail bizEventDetail) { ApplicationDTO applicationDTO = new ApplicationDTO(); applicationDTO.setScope(new ResourceScope(ResourceScopeTypeEnum.BIZ, String.valueOf(bizEventDetail.getBizId()))); - applicationDTO.setAppType(AppTypeEnum.NORMAL); applicationDTO.setName(bizEventDetail.getAppName()); - applicationDTO.setMaintainers(VersionCompatUtil.convertMaintainers(bizEventDetail.getMaintainers())); applicationDTO.setBkSupplierAccount(bizEventDetail.getSupplierAccount()); applicationDTO.setTimeZone(bizEventDetail.getTimezone()); - applicationDTO.setOperateDeptId(bizEventDetail.getOperateDeptId()); applicationDTO.setLanguage(bizEventDetail.getLanguage()); return applicationDTO; } diff --git a/src/backend/commons/cmdb-sdk-model/src/main/java/com/tencent/bk/job/common/cc/model/result/BizSetEventDetail.java b/src/backend/commons/cmdb-sdk-model/src/main/java/com/tencent/bk/job/common/cc/model/result/BizSetEventDetail.java index f7669a01a0..1db627a2fa 100644 --- a/src/backend/commons/cmdb-sdk-model/src/main/java/com/tencent/bk/job/common/cc/model/result/BizSetEventDetail.java +++ b/src/backend/commons/cmdb-sdk-model/src/main/java/com/tencent/bk/job/common/cc/model/result/BizSetEventDetail.java @@ -26,8 +26,6 @@ import com.fasterxml.jackson.annotation.JsonProperty; -import com.tencent.bk.job.common.cc.util.VersionCompatUtil; -import com.tencent.bk.job.common.constant.AppTypeEnum; import com.tencent.bk.job.common.constant.ResourceScopeTypeEnum; import com.tencent.bk.job.common.model.dto.ApplicationDTO; import com.tencent.bk.job.common.model.dto.ResourceScope; @@ -79,10 +77,8 @@ public ApplicationDTO toApplicationDTO() { ApplicationDTO applicationDTO = new ApplicationDTO(); ResourceScope resourceScope = new ResourceScope(ResourceScopeTypeEnum.BIZ_SET, String.valueOf(bizSetId)); applicationDTO.setScope(resourceScope); - applicationDTO.setAppType(AppTypeEnum.APP_SET); applicationDTO.setName(bizSetName); applicationDTO.setBkSupplierAccount(supplierAccount); - applicationDTO.setMaintainers(VersionCompatUtil.convertMaintainers(maintainers)); applicationDTO.setTimeZone(timezone); applicationDTO.setLanguage(language); return applicationDTO; diff --git a/src/backend/commons/cmdb-sdk-model/src/main/java/com/tencent/bk/job/common/cc/util/VersionCompatUtil.java b/src/backend/commons/cmdb-sdk-model/src/main/java/com/tencent/bk/job/common/cc/util/VersionCompatUtil.java deleted file mode 100644 index 7d34ded66b..0000000000 --- a/src/backend/commons/cmdb-sdk-model/src/main/java/com/tencent/bk/job/common/cc/util/VersionCompatUtil.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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.common.cc.util; - -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; - -@Slf4j -public class VersionCompatUtil { - - /* - * 转换maintainers,对接CC3.0之后maintainer用","分隔,CC2.0使用";"分隔;需要兼容 - */ - public static String convertMaintainers(String maintainers) { - if (StringUtils.isBlank(maintainers)) { - return ""; - } - String[] maintainerArray = maintainers.split("[,;]"); - StringBuilder sb = new StringBuilder(); - for (String maintainer : maintainerArray) { - if (StringUtils.isNotBlank(maintainer)) { - sb.append(maintainer).append(";"); - } else { - log.info("ignore an empty maintainer:{}", maintainer); - } - } - String newMaintainers = sb.toString(); - newMaintainers = newMaintainers.substring(0, newMaintainers.length() - 1); - return newMaintainers; - } -} diff --git a/src/backend/commons/cmdb-sdk/src/main/java/com/tencent/bk/job/common/cc/sdk/BizCmdbClient.java b/src/backend/commons/cmdb-sdk/src/main/java/com/tencent/bk/job/common/cc/sdk/BizCmdbClient.java index 206e7ebd44..a4a5d24bbb 100644 --- a/src/backend/commons/cmdb-sdk/src/main/java/com/tencent/bk/job/common/cc/sdk/BizCmdbClient.java +++ b/src/backend/commons/cmdb-sdk/src/main/java/com/tencent/bk/job/common/cc/sdk/BizCmdbClient.java @@ -77,8 +77,6 @@ import com.tencent.bk.job.common.cc.model.result.SearchCloudAreaResult; import com.tencent.bk.job.common.cc.model.result.SearchDynamicGroupResult; import com.tencent.bk.job.common.cc.util.TopologyUtil; -import com.tencent.bk.job.common.cc.util.VersionCompatUtil; -import com.tencent.bk.job.common.constant.AppTypeEnum; import com.tencent.bk.job.common.constant.ErrorCode; import com.tencent.bk.job.common.constant.ResourceScopeTypeEnum; import com.tencent.bk.job.common.esb.config.EsbConfig; @@ -777,12 +775,9 @@ public List getAllBizApps() { private ApplicationDTO convertToAppInfo(BusinessInfoDTO businessInfo) { ApplicationDTO appInfo = new ApplicationDTO(); appInfo.setName(businessInfo.getBizName()); - appInfo.setMaintainers(VersionCompatUtil.convertMaintainers(businessInfo.getMaintainers())); appInfo.setBkSupplierAccount(businessInfo.getSupplierAccount()); appInfo.setTimeZone(businessInfo.getTimezone()); appInfo.setScope(new ResourceScope(ResourceScopeTypeEnum.BIZ, businessInfo.getBizId().toString())); - appInfo.setAppType(AppTypeEnum.NORMAL); - appInfo.setOperateDeptId(businessInfo.getOperateDeptId()); appInfo.setLanguage(businessInfo.getLanguage()); return appInfo; } @@ -1157,7 +1152,7 @@ public List getObjAttributeList(String objId) { } @Override - public Set getAppUsersByRole(Long bizId, String role) { + public Set listUsersByRole(Long bizId, String role) { CcCountInfo searchResult; GetAppReq req = makeBaseReqByWeb(GetAppReq.class, null, defaultUin, defaultSupplierAccount); Map condition = new HashMap<>(); @@ -1201,7 +1196,7 @@ public Set getAppUsersByRole(Long bizId, String role) { } @Override - public List getAppRoleList() { + public List listRoles() { List esbObjAttributeDTO = getObjAttributeList("biz"); return esbObjAttributeDTO.stream().filter(it -> it.getBkPropertyGroup().equals("role") @@ -1299,8 +1294,8 @@ public ResourceWatchResult getHostRelationEvents(Long s public ResourceWatchResult getAppEvents(Long startTime, String cursor) { ResourceWatchReq req = makeBaseReqByWeb( ResourceWatchReq.class, null, defaultUin, defaultSupplierAccount); - req.setFields(Arrays.asList("bk_biz_id", "bk_biz_name", "bk_biz_maintainer", "bk_supplier_account", - "time_zone", "bk_operate_dept_id", "bk_operate_dept_name", "language")); + req.setFields(Arrays.asList("bk_biz_id", "bk_biz_name", "bk_supplier_account", + "time_zone", "language")); req.setResource("biz"); req.setCursor(cursor); req.setStartTime(startTime); diff --git a/src/backend/commons/cmdb-sdk/src/main/java/com/tencent/bk/job/common/cc/sdk/BizSetCmdbClient.java b/src/backend/commons/cmdb-sdk/src/main/java/com/tencent/bk/job/common/cc/sdk/BizSetCmdbClient.java index 147c32c044..e1094d8c5e 100644 --- a/src/backend/commons/cmdb-sdk/src/main/java/com/tencent/bk/job/common/cc/sdk/BizSetCmdbClient.java +++ b/src/backend/commons/cmdb-sdk/src/main/java/com/tencent/bk/job/common/cc/sdk/BizSetCmdbClient.java @@ -27,9 +27,11 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.tencent.bk.job.common.cc.config.CmdbConfig; import com.tencent.bk.job.common.cc.model.bizset.BizInfo; +import com.tencent.bk.job.common.cc.model.bizset.BizSetFilter; import com.tencent.bk.job.common.cc.model.bizset.BizSetInfo; import com.tencent.bk.job.common.cc.model.bizset.BizSetScope; import com.tencent.bk.job.common.cc.model.bizset.Page; +import com.tencent.bk.job.common.cc.model.bizset.Rule; import com.tencent.bk.job.common.cc.model.bizset.SearchBizInBusinessReq; import com.tencent.bk.job.common.cc.model.bizset.SearchBizInBusinessSetResp; import com.tencent.bk.job.common.cc.model.bizset.SearchBizSetReq; @@ -46,11 +48,16 @@ import com.tencent.bk.job.common.exception.InternalException; import com.tencent.bk.job.common.util.http.HttpHelperFactory; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.http.client.methods.HttpPost; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; import java.util.List; +import java.util.Set; /** * cmdb API Client - 业务集相关 @@ -116,7 +123,7 @@ public List searchAllBizSet() { int start = 0; List bizSetInfoList = new ArrayList<>(); while (start < bizSetCount) { - bizSetInfoList.addAll(searchBizSet(start, limit)); + bizSetInfoList.addAll(searchBizSet(null, start, limit)); start += limit; } return bizSetInfoList; @@ -125,16 +132,19 @@ public List searchAllBizSet() { /** * 查询业务集信息 * + * @param filter 查询条件 + * @param start 分页起始 + * @param limit 每页大小 * @return 业务集信息列表 */ - private List searchBizSet(int start, int limit) { + private List searchBizSet(BizSetFilter filter, int start, int limit) { SearchBizSetReq req = makeCmdbBaseReq(SearchBizSetReq.class); Page page = new Page(); page.setEnableCount(false); page.setStart(start); page.setLimit(limit); req.setPage(page); - req.setFilter(null); + req.setFilter(filter); try { EsbResp resp = getEsbRespByReq( HttpPost.METHOD_NAME, @@ -225,7 +235,7 @@ private List searchBizInBizSet(long bizSetId, int start, int limit) { } @Override - public List getAllBizSetApps() { + public List listAllBizSets() { List bizSetInfoList = searchAllBizSet(); bizSetInfoList.parallelStream().forEach(bizSetInfo -> { // 查询业务集下包含的子业务(全业务除外) @@ -287,4 +297,43 @@ public ResourceWatchResult getBizSetRelationEvents(Lo throw new InternalException(e, ErrorCode.CMDB_API_DATA_ERROR, null); } } + + @Override + public Set listUsersByRole(Long bizSetId, String role) { + if (!"bk_biz_maintainer".equals(role)) { + log.warn("Unavailable role for biz set! role: {}", role); + return Collections.emptySet(); + } + + BizSetInfo bizSet = queryBizSet(bizSetId); + if (bizSet == null) { + log.warn("BizSet: {} is not exist", bizSetId); + return Collections.emptySet(); + } + + Set userSet = new HashSet<>(); + String maintainers = bizSet.getMaintainer(); + if (StringUtils.isNotEmpty(maintainers)) { + for (String user : maintainers.split(",")) { + if (StringUtils.isNotBlank(user)) { + userSet.add(user); + } + } + } + + return userSet; + } + + @Override + public BizSetInfo queryBizSet(Long bizSetId) { + BizSetFilter filter = new BizSetFilter(); + filter.setCondition("AND"); + Rule bizSetIdRule = new Rule(); + bizSetIdRule.setField("bk_biz_set_id"); + bizSetIdRule.setOperator("equal"); + bizSetIdRule.setValue(bizSetId); + filter.setRules(Collections.singletonList(bizSetIdRule)); + List results = searchBizSet(filter, 0, 1); + return CollectionUtils.isEmpty(results) ? null : results.get(0); + } } diff --git a/src/backend/commons/cmdb-sdk/src/main/java/com/tencent/bk/job/common/cc/sdk/IBizCmdbClient.java b/src/backend/commons/cmdb-sdk/src/main/java/com/tencent/bk/job/common/cc/sdk/IBizCmdbClient.java index 6e1769b716..e91c0141ac 100644 --- a/src/backend/commons/cmdb-sdk/src/main/java/com/tencent/bk/job/common/cc/sdk/IBizCmdbClient.java +++ b/src/backend/commons/cmdb-sdk/src/main/java/com/tencent/bk/job/common/cc/sdk/IBizCmdbClient.java @@ -192,15 +192,15 @@ public interface IBizCmdbClient { /** * 根据cmdb业务角色获取人员 * - * @param appId 业务ID + * @param bizId cmdb业务ID * @param role 业务角色 */ - Set getAppUsersByRole(Long appId, String role); + Set listUsersByRole(Long bizId, String role); /** * 获取CMDB业务角色列表 */ - List getAppRoleList(); + List listRoles(); /** * 批量获取topo节点层级 diff --git a/src/backend/commons/cmdb-sdk/src/main/java/com/tencent/bk/job/common/cc/sdk/IBizSetCmdbClient.java b/src/backend/commons/cmdb-sdk/src/main/java/com/tencent/bk/job/common/cc/sdk/IBizSetCmdbClient.java index 78223bfd04..898b138465 100644 --- a/src/backend/commons/cmdb-sdk/src/main/java/com/tencent/bk/job/common/cc/sdk/IBizSetCmdbClient.java +++ b/src/backend/commons/cmdb-sdk/src/main/java/com/tencent/bk/job/common/cc/sdk/IBizSetCmdbClient.java @@ -30,18 +30,27 @@ import com.tencent.bk.job.common.cc.model.result.ResourceWatchResult; import java.util.List; +import java.util.Set; /** * CMDB业务集相关接口 */ public interface IBizSetCmdbClient { + /** + * 查询业务集 + * + * @param bizSetId 业务集ID + * @return 业务集 + */ + BizSetInfo queryBizSet(Long bizSetId); + /** * 从CC获取所有业务集信息 * * @return 业务集列表 */ - List getAllBizSetApps(); + List listAllBizSets(); /** * 根据游标获取业务集事件 @@ -60,4 +69,12 @@ public interface IBizSetCmdbClient { * @return 事件 */ ResourceWatchResult getBizSetRelationEvents(Long startTime, String cursor); + + /** + * 根据cmdb业务角色获取人员 + * + * @param bizId cmdb业务ID + * @param role 业务角色 + */ + Set listUsersByRole(Long bizId, String role); } diff --git a/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message.properties b/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message.properties index eae1187105..64e364fc41 100644 --- a/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message.properties +++ b/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message.properties @@ -171,7 +171,7 @@ 1244024=保存文件到本地失败 1244025=任务被丢弃 1244026=非法的滚动策略 -1244027=滚动批次不能大于{} +1244027=滚动批次不能大于{0} ## 业务错误-定时任务(job-crontab) 1245006=定时任务执行时间已失效 diff --git a/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_en.properties b/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_en.properties index 214192eb6e..e52b9b5399 100644 --- a/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_en.properties +++ b/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_en.properties @@ -171,7 +171,7 @@ 1244024=Fail to save file to local 1244025=Task abandoned 1244026=Invalid rolling strategy -1244027=Rolling batch can not be greater than {} +1244027=Rolling batch can not be greater than {0} ## Business error - job-crontab 1245006=Cron job execution time already passed diff --git a/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_en_US.properties b/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_en_US.properties index 214192eb6e..e52b9b5399 100644 --- a/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_en_US.properties +++ b/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_en_US.properties @@ -171,7 +171,7 @@ 1244024=Fail to save file to local 1244025=Task abandoned 1244026=Invalid rolling strategy -1244027=Rolling batch can not be greater than {} +1244027=Rolling batch can not be greater than {0} ## Business error - job-crontab 1245006=Cron job execution time already passed diff --git a/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_zh.properties b/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_zh.properties index eae1187105..64e364fc41 100644 --- a/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_zh.properties +++ b/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_zh.properties @@ -171,7 +171,7 @@ 1244024=保存文件到本地失败 1244025=任务被丢弃 1244026=非法的滚动策略 -1244027=滚动批次不能大于{} +1244027=滚动批次不能大于{0} ## 业务错误-定时任务(job-crontab) 1245006=定时任务执行时间已失效 diff --git a/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_zh_CN.properties b/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_zh_CN.properties index eae1187105..64e364fc41 100644 --- a/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_zh_CN.properties +++ b/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_zh_CN.properties @@ -171,7 +171,7 @@ 1244024=保存文件到本地失败 1244025=任务被丢弃 1244026=非法的滚动策略 -1244027=滚动批次不能大于{} +1244027=滚动批次不能大于{0} ## 业务错误-定时任务(job-crontab) 1245006=定时任务执行时间已失效 diff --git a/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/constant/AppTypeEnum.java b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/constant/AppTypeEnum.java deleted file mode 100644 index c016e36cdf..0000000000 --- a/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/constant/AppTypeEnum.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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.common.constant; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonValue; - -/** - * 业务类型 - */ -public enum AppTypeEnum { - /** - * 普通业务 - */ - NORMAL(1), - /** - * 业务集 - */ - APP_SET(2), - /** - * 全业务 - */ - ALL_APP(3); - @JsonValue - private int type; - - AppTypeEnum(int type) { - this.type = type; - } - - @JsonCreator(mode = JsonCreator.Mode.DELEGATING) - public static AppTypeEnum valueOf(int type) { - for (AppTypeEnum appType : values()) { - if (appType.type == type) { - return appType; - } - } - return null; - } - - public int getValue() { - return type; - } -} diff --git a/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/model/dto/ApplicationDTO.java b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/model/dto/ApplicationDTO.java index c6923df651..b9e7bdc59a 100644 --- a/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/model/dto/ApplicationDTO.java +++ b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/model/dto/ApplicationDTO.java @@ -26,13 +26,12 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; -import com.tencent.bk.job.common.annotation.CompatibleImplementation; -import com.tencent.bk.job.common.constant.AppTypeEnum; import com.tencent.bk.job.common.constant.ResourceScopeTypeEnum; import lombok.Data; import lombok.NoArgsConstructor; import lombok.extern.slf4j.Slf4j; +import java.util.Collections; import java.util.List; /** @@ -85,30 +84,6 @@ public class ApplicationDTO { */ private ApplicationAttrsDO attrs; - /** - * 初始运维部门Id - */ - @CompatibleImplementation(explain = "兼容字段,等业务集全部迁移到cmdb之后可以删除", version = "3.6.x") - private Long operateDeptId; - - /** - * cmdb业务/业务集运维 - */ - @CompatibleImplementation(explain = "兼容字段,等业务集全部迁移到cmdb之后可以删除", version = "3.6.x") - private String maintainers; - - /** - * 业务集子业务ID - */ - @CompatibleImplementation(explain = "兼容字段,等业务集全部迁移到cmdb之后可以删除", version = "3.6.x") - private List subBizIds; - - /** - * 业务类型 - */ - @CompatibleImplementation(explain = "兼容字段,等业务集全部迁移到cmdb之后可以删除", version = "3.6.x") - private AppTypeEnum appType; - @JsonIgnore public boolean isBiz() { return scope != null && scope.getType() == ResourceScopeTypeEnum.BIZ; @@ -144,13 +119,10 @@ public Long getBizIdIfBizApp() { } public List getSubBizIds() { - // 业务集已迁移到cmdb if (attrs != null) { - return attrs.getSubBizIds(); + return attrs.getSubBizIds() == null ? Collections.emptyList() : attrs.getSubBizIds(); } else { - // 业务集还未迁移到cmdb,继续使用原来Job业务集配置的子业务;兼容方法,理论上不应该发生调用,此处日志仅用于排查,后续删除 - log.info("Get sub biz ids using field subBizIds"); - return subBizIds; + return Collections.emptyList(); } } diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/dao/FileAgentTaskDAO.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/dao/FileAgentTaskDAO.java index 51bdc7914f..c788a5fe46 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/dao/FileAgentTaskDAO.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/dao/FileAgentTaskDAO.java @@ -146,12 +146,18 @@ AgentTaskDTO getAgentTaskByHostId(Long stepInstanceId, Integer executeCount, Int boolean isStepInstanceRecordExist(long stepInstanceId); /** - * 更新Agent任务实际执行的步骤重试次数 + * 批量更新AgentTask的字段 * - * @param stepInstanceId 步骤实例ID - * @param batch 滚动执行批次;传入null将忽略该条件 - * @param actualExecuteCount Agent任务实际执行的步骤重试次数 + * @param stepInstanceId 条件 - 步骤实例ID + * @param executeCount 条件 - 重试次数 + * @param batch 条件 - 滚动执行批次;传入null将忽略该条件 + * @param actualExecuteCount 值 - Agent任务实际执行的步骤重试次数;如果传入null,则不更新 + * @param gseTaskId 值 - Agent任务对应的GSE_TASK_ID;如果传入null,则不更新 */ - void updateActualExecuteCount(long stepInstanceId, Integer batch, int actualExecuteCount); + void updateAgentTaskFields(long stepInstanceId, + int executeCount, + Integer batch, + Integer actualExecuteCount, + Long gseTaskId); } diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/dao/ScriptAgentTaskDAO.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/dao/ScriptAgentTaskDAO.java index a3ac236249..cd723f3ff4 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/dao/ScriptAgentTaskDAO.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/dao/ScriptAgentTaskDAO.java @@ -145,11 +145,17 @@ List listAgentTasks(Long stepInstanceId, boolean isStepInstanceRecordExist(long stepInstanceId); /** - * 更新Agent任务实际执行的步骤重试次数 + * 批量更新AgentTask的字段 * - * @param stepInstanceId 步骤实例ID - * @param batch 滚动执行批次;传入null将忽略该条件 - * @param actualExecuteCount Agent任务实际执行的步骤重试次数 + * @param stepInstanceId 条件 - 步骤实例ID + * @param executeCount 条件 - 重试次数 + * @param batch 条件 - 滚动执行批次;传入null将忽略该条件 + * @param actualExecuteCount 值 - Agent任务实际执行的步骤重试次数;如果传入null,则不更新 + * @param gseTaskId 值 - Agent任务对应的GSE_TASK_ID;如果传入null,则不更新 */ - void updateActualExecuteCount(long stepInstanceId, Integer batch, int actualExecuteCount); + void updateAgentTaskFields(long stepInstanceId, + int executeCount, + Integer batch, + Integer actualExecuteCount, + Long gseTaskId); } diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/dao/impl/FileAgentTaskDAOImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/dao/impl/FileAgentTaskDAOImpl.java index a9654186a5..80c3038a14 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/dao/impl/FileAgentTaskDAOImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/dao/impl/FileAgentTaskDAOImpl.java @@ -42,6 +42,8 @@ import org.jooq.SelectSeekStep1; import org.jooq.TableField; import org.jooq.UpdateConditionStep; +import org.jooq.UpdateSetMoreStep; +import org.jooq.UpdateSetStep; import org.jooq.generated.tables.GseFileAgentTask; import org.jooq.generated.tables.records.GseFileAgentTaskRecord; import org.springframework.beans.factory.annotation.Autowired; @@ -50,6 +52,7 @@ import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.List; import static com.tencent.bk.job.common.constant.Order.DESCENDING; @@ -318,6 +321,10 @@ private AgentTaskDTO extract(Record record) { @Override public List listAgentTasksByGseTaskId(Long gseTaskId) { + if (gseTaskId == null || gseTaskId <= 0) { + return Collections.emptyList(); + } + List agentTaskList = new ArrayList<>(); Result result = CTX.select(ALL_FIELDS) @@ -350,11 +357,34 @@ public boolean isStepInstanceRecordExist(long stepInstanceId) { } @Override - public void updateActualExecuteCount(long stepInstanceId, Integer batch, int actualExecuteCount) { + public void updateAgentTaskFields(long stepInstanceId, + int executeCount, + Integer batch, + Integer actualExecuteCount, + Long gseTaskId) { + UpdateSetStep updateSetStep = CTX.update(T_GSE_FILE_AGENT_TASK); + boolean needUpdate = false; + if (actualExecuteCount != null) { + updateSetStep = updateSetStep.set(T_GSE_FILE_AGENT_TASK.ACTUAL_EXECUTE_COUNT, + actualExecuteCount.shortValue()); + needUpdate = true; + } + if (gseTaskId != null) { + updateSetStep = updateSetStep.set(T_GSE_FILE_AGENT_TASK.GSE_TASK_ID, gseTaskId); + needUpdate = true; + } + + if (!needUpdate) { + return; + } + + UpdateSetMoreStep updateSetMoreStep = + (UpdateSetMoreStep) updateSetStep; + UpdateConditionStep updateConditionStep = - CTX.update(T_GSE_FILE_AGENT_TASK) - .set(T_GSE_FILE_AGENT_TASK.ACTUAL_EXECUTE_COUNT, (short) actualExecuteCount) - .where(T_GSE_FILE_AGENT_TASK.STEP_INSTANCE_ID.eq(stepInstanceId)); + updateSetMoreStep + .where(T_GSE_FILE_AGENT_TASK.STEP_INSTANCE_ID.eq(stepInstanceId)) + .and(T_GSE_FILE_AGENT_TASK.EXECUTE_COUNT.eq((short) executeCount)); if (batch != null) { updateConditionStep.and(T_GSE_FILE_AGENT_TASK.BATCH.eq(batch.shortValue())); } diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/dao/impl/ScriptAgentTaskDAOImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/dao/impl/ScriptAgentTaskDAOImpl.java index 415f7c6819..43674c6265 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/dao/impl/ScriptAgentTaskDAOImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/dao/impl/ScriptAgentTaskDAOImpl.java @@ -42,6 +42,8 @@ import org.jooq.SelectSeekStep1; import org.jooq.TableField; import org.jooq.UpdateConditionStep; +import org.jooq.UpdateSetMoreStep; +import org.jooq.UpdateSetStep; import org.jooq.generated.tables.GseScriptAgentTask; import org.jooq.generated.tables.records.GseScriptAgentTaskRecord; import org.springframework.beans.factory.annotation.Autowired; @@ -50,6 +52,7 @@ import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.List; import static com.tencent.bk.job.common.constant.Order.DESCENDING; @@ -329,6 +332,10 @@ private AgentTaskDTO extract(Record record) { @Override public List listAgentTasksByGseTaskId(Long gseTaskId) { + if (gseTaskId == null || gseTaskId <= 0) { + return Collections.emptyList(); + } + List agentTaskList = new ArrayList<>(); Result result = CTX.select(ALL_FIELDS) @@ -358,12 +365,36 @@ public boolean isStepInstanceRecordExist(long stepInstanceId) { return CTX.fetchExists(T_GSE_SCRIPT_AGENT_TASK, T_GSE_SCRIPT_AGENT_TASK.STEP_INSTANCE_ID.eq(stepInstanceId)); } + @Override - public void updateActualExecuteCount(long stepInstanceId, Integer batch, int actualExecuteCount) { + public void updateAgentTaskFields(long stepInstanceId, + int executeCount, + Integer batch, + Integer actualExecuteCount, + Long gseTaskId) { + UpdateSetStep updateSetStep = CTX.update(T_GSE_SCRIPT_AGENT_TASK); + boolean needUpdate = false; + if (actualExecuteCount != null) { + updateSetStep = updateSetStep.set(T_GSE_SCRIPT_AGENT_TASK.ACTUAL_EXECUTE_COUNT, + actualExecuteCount.shortValue()); + needUpdate = true; + } + if (gseTaskId != null) { + updateSetStep = updateSetStep.set(T_GSE_SCRIPT_AGENT_TASK.GSE_TASK_ID, gseTaskId); + needUpdate = true; + } + + if (!needUpdate) { + return; + } + + UpdateSetMoreStep updateSetMoreStep = + (UpdateSetMoreStep) updateSetStep; + UpdateConditionStep updateConditionStep = - CTX.update(T_GSE_SCRIPT_AGENT_TASK) - .set(T_GSE_SCRIPT_AGENT_TASK.ACTUAL_EXECUTE_COUNT, (short) actualExecuteCount) - .where(T_GSE_SCRIPT_AGENT_TASK.STEP_INSTANCE_ID.eq(stepInstanceId)); + updateSetMoreStep + .where(T_GSE_SCRIPT_AGENT_TASK.STEP_INSTANCE_ID.eq(stepInstanceId)) + .and(T_GSE_SCRIPT_AGENT_TASK.EXECUTE_COUNT.eq((short) executeCount)); if (batch != null) { updateConditionStep.and(T_GSE_SCRIPT_AGENT_TASK.BATCH.eq(batch.shortValue())); } diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/listener/GseStepEventHandler.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/listener/GseStepEventHandler.java index 29b4e1e48f..cfbb83fb42 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/listener/GseStepEventHandler.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/listener/GseStepEventHandler.java @@ -249,51 +249,66 @@ private void saveGseAgentTasksForStartStep(Long gseTaskId, int executeCount = stepInstance.getExecuteCount(); int batch = stepInstance.getBatch(); - if (needInitAgentTasksWhenStartStep(stepInstance)) { - List agentTasks = new ArrayList<>(); - - if (stepInstance.isRollingStep() && stepInstance.isFirstRollingBatch()) { - // 如果是第一批次的执行,需要初始化所有批次的agent任务(查询需要) - if (rollingConfig.isBatchRollingStep(stepInstanceId)) { - List serverBatchList = - rollingConfig.getConfigDetail().getHostsBatchList(); - serverBatchList.forEach(serverBatch -> { - Integer actualExecuteCount = serverBatch.getBatch() == 1 ? executeCount : null; - agentTasks.addAll(buildGseAgentTasks(stepInstanceId, - executeCount, actualExecuteCount, serverBatch.getBatch(), gseTaskId, - serverBatch.getHosts(), AgentTaskStatusEnum.WAITING)); - }); - } else { - // 暂时不支持,滚动执行二期需求 - log.warn("All rolling step is not supported!"); - throw new NotImplementedException("All rolling step is not supported", - ErrorCode.NOT_SUPPORT_FEATURE); - } - } else { - agentTasks.addAll(buildGseAgentTasks(stepInstanceId, executeCount, executeCount, batch, + if (stepInstance.isRollingStep()) { + // 滚动步骤 + saveGseAgentTasksForStartRollingStep(gseTaskId, stepInstance, rollingConfig); + } else { + // 普通步骤,启动的时候需要初始化所有AgentTask + List agentTasks = new ArrayList<>( + buildGseAgentTasks(stepInstanceId, executeCount, executeCount, batch, gseTaskId, stepInstance.getTargetServers().getIpList(), AgentTaskStatusEnum.WAITING)); - } + saveAgentTasks(stepInstance, agentTasks); + } + } - // 无效主机 - if (CollectionUtils.isNotEmpty(stepInstance.getTargetServers().getInvalidIpList())) { - agentTasks.addAll(buildGseAgentTasks(stepInstanceId, executeCount, executeCount, batch, - 0L, stepInstance.getTargetServers().getInvalidIpList(), AgentTaskStatusEnum.HOST_NOT_EXIST)); + /** + * 启动滚动执行步骤的时候保存 GSE Agent 任务 + * + * @param gseTaskId GSE任务ID + * @param stepInstance 步骤实例 + * @param rollingConfig 滚动配置 + */ + private void saveGseAgentTasksForStartRollingStep(Long gseTaskId, + StepInstanceDTO stepInstance, + RollingConfigDTO rollingConfig) { + long stepInstanceId = stepInstance.getId(); + int executeCount = stepInstance.getExecuteCount(); + int batch = stepInstance.getBatch(); + if (stepInstance.isFirstRollingBatch()) { + // 如果是第一批次的执行,需要提前初始化所有批次的agent任务(作业详情查询主机任务列表需要) + List agentTasks = new ArrayList<>(); + if (rollingConfig.isBatchRollingStep(stepInstanceId)) { + List serverBatchList = + rollingConfig.getConfigDetail().getHostsBatchList(); + serverBatchList.forEach(serverBatch -> { + agentTasks.addAll( + buildGseAgentTasks( + stepInstanceId, + executeCount, + serverBatch.getBatch() == 1 ? executeCount : null, + serverBatch.getBatch(), + serverBatch.getBatch() == 1 ? gseTaskId : 0, + serverBatch.getHosts(), + AgentTaskStatusEnum.WAITING) + ); + }); + saveAgentTasks(stepInstance, agentTasks); + } else { + // 暂时不支持,滚动执行二期需求 + log.warn("All rolling step is not supported!"); + throw new NotImplementedException("All rolling step is not supported", + ErrorCode.NOT_SUPPORT_FEATURE); } - saveAgentTasks(stepInstance, agentTasks); } else { - // 仅更新 AgentTask 的 actualExecuteCount + // 滚动执行步骤除了第一批次,后续的批次仅更新 AgentTask 的 actualExecuteCount、gse_task_id if (stepInstance.isScriptStep()) { - scriptAgentTaskService.updateActualExecuteCount(stepInstanceId, batch, executeCount); + scriptAgentTaskService.updateAgentTaskFields(stepInstanceId, executeCount, batch, executeCount, + gseTaskId); } else if (stepInstance.isFileStep()) { - fileAgentTaskService.updateActualExecuteCount(stepInstanceId, batch, executeCount); + fileAgentTaskService.updateAgentTaskFields(stepInstanceId, executeCount, batch, executeCount, + gseTaskId); } } - - } - - private boolean needInitAgentTasksWhenStartStep(StepInstanceBaseDTO stepInstance) { - // 步骤启动阶段(非滚动步骤启动、滚动步骤的第一批次启动),需要初始化所有AgentTask - return !stepInstance.isRollingStep() || stepInstance.isFirstRollingBatch(); } private List buildGseAgentTasks(long stepInstanceId, diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/result/FileResultHandleTask.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/result/FileResultHandleTask.java index 9b7489098a..370bb26fde 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/result/FileResultHandleTask.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/result/FileResultHandleTask.java @@ -652,11 +652,11 @@ private void recordDownloadFileFail(CopyFileRsp copyFileRsp, new ServiceFileTaskLogDTO( FileDistModeEnum.DOWNLOAD.getValue(), destAgentTask.getHostId(), - agentIdHostMap.get(destAgentTask.getAgentId()).getIp(), + agentIdHostMap.get(destAgentTask.getAgentId()).toCloudIp(), taskResult.getStandardDestFilePath(), sourceAgentTask.getHostId(), - agentIdHostMap.get(sourceAgentTask.getAgentId()).getIp(), - agentIdHostMap.get(sourceAgentTask.getAgentId()).getIp(), + agentIdHostMap.get(sourceAgentTask.getAgentId()).toCloudIp(), + agentIdHostMap.get(sourceAgentTask.getAgentId()).getDisplayIp(), taskResult.getStandardSourceFilePath(), taskResult.getStandardSourceFilePath() == null ? null : sourceFileDisplayMap.get(taskResult.getStandardSourceFilePath()), null, @@ -734,7 +734,7 @@ private void dealUploadFail(CopyFileRsp copyFileRsp, Map listAgentTaskDetail(StepInstanceBaseDTO stepInstance, int getActualSuccessExecuteCount(long stepInstanceId, String cloudIp); /** - * 更新Agent任务实际执行的步骤重试次数 + * 批量更新AgentTask的字段 * - * @param stepInstanceId 步骤实例ID - * @param batch 滚动执行批次;传入null将忽略该条件 - * @param actualExecuteCount Agent任务实际执行的步骤重试次数 + * @param stepInstanceId 条件 - 步骤实例ID + * @param executeCount 条件 - 重试次数 + * @param batch 条件 - 滚动执行批次;传入null将忽略该条件 + * @param actualExecuteCount 值 - Agent任务实际执行的步骤重试次数;如果传入null,则不更新 + * @param gseTaskId 值 - Agent任务对应的GSE_TASK_ID;如果传入null,则不更新 */ - void updateActualExecuteCount(long stepInstanceId, Integer batch, int actualExecuteCount); + void updateAgentTaskFields(long stepInstanceId, + int executeCount, + Integer batch, + Integer actualExecuteCount, + Long gseTaskId); } diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/FileAgentTaskServiceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/FileAgentTaskServiceImpl.java index 7b3c126731..a199304d75 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/FileAgentTaskServiceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/FileAgentTaskServiceImpl.java @@ -235,7 +235,11 @@ private boolean isStepInstanceRecordExist(long stepInstanceId) { } @Override - public void updateActualExecuteCount(long stepInstanceId, Integer batch, int actualExecuteCount) { - fileAgentTaskDAO.updateActualExecuteCount(stepInstanceId, batch, actualExecuteCount); + public void updateAgentTaskFields(long stepInstanceId, + int executeCount, + Integer batch, + Integer actualExecuteCount, + Long gseTaskId) { + fileAgentTaskDAO.updateAgentTaskFields(stepInstanceId, executeCount, batch, actualExecuteCount, gseTaskId); } } diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/LogServiceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/LogServiceImpl.java index e4f135f71e..7647e6c621 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/LogServiceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/LogServiceImpl.java @@ -173,18 +173,18 @@ public ScriptHostLogContent getScriptHostLogContent(long stepInstanceId, int exe stepInstanceId, actualExecuteCount, batch, host); throw new InternalException(resp.getCode()); } - return convertToScriptIpLogContent(resp.getData(), agentTask); + return convertToScriptIpLogContent(stepInstanceId, executeCount, resp.getData(), agentTask); } - private ScriptHostLogContent convertToScriptIpLogContent(ServiceHostLogDTO logDTO, AgentTaskDTO gseTaskIpLog) { - if (logDTO == null) { - return null; - } - AgentTaskStatusEnum agentTaskStatus = gseTaskIpLog.getStatus(); - String scriptContent = logDTO.getScriptLog() != null ? + private ScriptHostLogContent convertToScriptIpLogContent(long stepInstanceId, int executeCount, + ServiceHostLogDTO logDTO, AgentTaskDTO agentTask) { + // 日志是否拉取完成 + boolean isFinished = agentTask.getStatus().isFinished(); + String scriptContent = logDTO != null && logDTO.getScriptLog() != null ? logDTO.getScriptLog().getContent() : ""; - return new ScriptHostLogContent(logDTO.getStepInstanceId(), logDTO.getExecuteCount(), logDTO.getHostId(), - logDTO.getIp(), scriptContent, agentTaskStatus.isFinished()); + Long hostId = logDTO != null ? logDTO.getHostId() : null; + String ip = logDTO != null ? logDTO.getIp() : null; + return new ScriptHostLogContent(stepInstanceId, executeCount, hostId, ip, scriptContent, isFinished); } @Override diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/ScriptAgentTaskServiceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/ScriptAgentTaskServiceImpl.java index 2feef5a2e1..0a9656d90b 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/ScriptAgentTaskServiceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/ScriptAgentTaskServiceImpl.java @@ -95,7 +95,7 @@ public AgentTaskDTO getAgentTaskByHost(StepInstanceBaseDTO stepInstance, } else if (StringUtils.isNotEmpty(host.toCloudIp())) { // 根据ip查询的模式,有两种情况,数据可能在gse_script_agent_task/gse_task_ip_log表中,优先查询gse_script_agent_task HostDTO queryHost = getStepHostByIp(stepInstance, host.toCloudIp()); - if (queryHost != null) { + if (queryHost != null && queryHost.getHostId() != null) { agentTask = scriptAgentTaskDAO.getAgentTaskByHostId(stepInstance.getId(), executeCount, batch, queryHost.getHostId()); } else { @@ -196,7 +196,11 @@ private boolean isStepInstanceRecordExist(long stepInstanceId) { } @Override - public void updateActualExecuteCount(long stepInstanceId, Integer batch, int actualExecuteCount) { - scriptAgentTaskDAO.updateActualExecuteCount(stepInstanceId, batch, actualExecuteCount); + public void updateAgentTaskFields(long stepInstanceId, + int executeCount, + Integer batch, + Integer actualExecuteCount, + Long gseTaskId) { + scriptAgentTaskDAO.updateAgentTaskFields(stepInstanceId, executeCount, batch, actualExecuteCount, gseTaskId); } } diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceApplicationResource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceApplicationResource.java index 66b3c876e5..a44508eaf1 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceApplicationResource.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceApplicationResource.java @@ -97,10 +97,6 @@ ServiceApplicationDTO queryAppByScope(@ApiParam(value = "资源范围类型", al @ApiParam(value = "资源范围ID", required = true) @PathVariable("scopeId") String scopeId); - @GetMapping("/app/{appId}/permission") - InternalResponse checkAppPermission(@PathVariable("appId") Long appId, - @RequestParam("username") String username); - @ApiOperation(value = "获取业务列表", produces = "application/json") @GetMapping("/app/list") InternalResponse> listApps( diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceHostResource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceHostResource.java index e34f1095c6..eb527ba3e2 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceHostResource.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceHostResource.java @@ -24,10 +24,8 @@ package com.tencent.bk.job.manage.api.inner; -import com.tencent.bk.job.common.annotation.CompatibleImplementation; import com.tencent.bk.job.common.annotation.InternalAPI; import com.tencent.bk.job.common.model.InternalResponse; -import com.tencent.bk.job.common.model.dto.HostDTO; import com.tencent.bk.job.manage.model.inner.ServiceHostDTO; import com.tencent.bk.job.manage.model.inner.ServiceHostStatusDTO; import com.tencent.bk.job.manage.model.inner.ServiceListAppHostResultDTO; @@ -73,21 +71,6 @@ InternalResponse> getHostStatusByIp( @RequestBody ServiceGetHostStatusByIpReq req ); - /** - * 检查主机是否在业务下 - * - * @param appId Job业务ID - * @param req 请求 - * @return 非法的主机 - */ - @ApiOperation(value = "检查主机是否在业务下", produces = "application/json") - @PostMapping("/app/{appId}/host/checkAppHosts") - @CompatibleImplementation(name = "rolling_execution", explain = "兼容方法,发布完成之后删除", version = "3.6.x") - InternalResponse> checkAppHosts( - @PathVariable("appId") Long appId, - @RequestBody ServiceCheckAppHostsReq req - ); - /** * 获取业务下的主机并返回主机详情 * diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/inner/resp/ServiceApplicationDTO.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/inner/resp/ServiceApplicationDTO.java index 18b8c8abf5..b51aad50cb 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/inner/resp/ServiceApplicationDTO.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/inner/resp/ServiceApplicationDTO.java @@ -24,18 +24,12 @@ package com.tencent.bk.job.manage.model.inner.resp; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.tencent.bk.job.common.annotation.CompatibleImplementation; import com.tencent.bk.job.common.constant.ResourceScopeTypeEnum; -import com.tencent.bk.job.common.model.dto.ApplicationDTO; -import com.tencent.bk.job.common.model.dto.ResourceScope; import com.tencent.bk.job.manage.model.inner.ServiceApplicationAttrsDTO; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; -import java.util.List; - /** * 业务 */ @@ -62,35 +56,14 @@ public class ServiceApplicationDTO { @ApiModelProperty("业务名称") private String name; - /** - * 业务类型 - */ - @ApiModelProperty("业务类型") - @CompatibleImplementation(explain = "兼容字段,等发布完成之后可以删除", version = "3.5.x") - private Integer appType; - /** * 运维 */ private String maintainers; - /** - * 子业务 - */ - @ApiModelProperty("子业务ID") - @CompatibleImplementation(explain = "兼容字段,等发布完成之后可以删除", version = "3.5.x") - @JsonProperty("subAppIds") - private List subBizIds; - @ApiModelProperty("开发商") private String owner; - /** - * 初始运维部门Id - */ - @CompatibleImplementation(explain = "兼容字段,等发布完成之后可以删除", version = "3.5.x") - private Long operateDeptId; - /** * 时区 */ @@ -106,47 +79,6 @@ public class ServiceApplicationDTO { */ private ServiceApplicationAttrsDTO attrs; - /** - * 将服务间调用的业务对象转为通用Job业务对象 - * - * @param serviceAppDTO 服务间调用业务对象 - * @return 通用Job业务对象 - */ - public static ApplicationDTO toApplicationInfoDTO(ServiceApplicationDTO serviceAppDTO) { - ApplicationDTO applicationInfo = new ApplicationDTO(); - applicationInfo.setId(serviceAppDTO.getId()); - applicationInfo.setName(serviceAppDTO.getName()); - applicationInfo.setScope(new ResourceScope(serviceAppDTO.getScopeType(), serviceAppDTO.getScopeId())); - applicationInfo.setSubBizIds(serviceAppDTO.getSubBizIds()); - applicationInfo.setLanguage(serviceAppDTO.getLanguage()); - return applicationInfo; - } - - /** - * 将通用Job业务对象转为服务间调用的业务对象 - * - * @param appDTO 通用Job业务对象 - * @return 服务间调用业务对象 - */ - public static ServiceApplicationDTO fromApplicationDTO(ApplicationDTO appDTO) { - if (appDTO == null) { - return null; - } - ServiceApplicationDTO app = new ServiceApplicationDTO(); - app.setId(appDTO.getId()); - app.setSubBizIds(appDTO.getSubBizIds()); - app.setName(appDTO.getName()); - app.setScopeType(appDTO.getScope().getType().getValue()); - app.setScopeId(appDTO.getScope().getId()); - app.setOwner(appDTO.getBkSupplierAccount()); - app.setTimeZone(appDTO.getTimeZone()); - // 暂时保留appType/maintainers/operateDeptId三个参数 - app.setAppType(appDTO.getAppType().getValue()); - app.setMaintainers(appDTO.getMaintainers()); - app.setOperateDeptId(appDTO.getOperateDeptId()); - return app; - } - public boolean isBiz() { return ResourceScopeTypeEnum.BIZ.getValue().equals(scopeType); } diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/tmp/TmpAddAppSetRequest.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/tmp/TmpAddAppSetRequest.java deleted file mode 100644 index b187f43847..0000000000 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/tmp/TmpAddAppSetRequest.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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.tmp; - -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; - -/** - * 新增业务集请求 - */ -@Data -@ApiModel("新增业务集请求") -public class TmpAddAppSetRequest { - - @ApiModelProperty("业务ID") - private Long id; - - /** - * 业务名称 - */ - @ApiModelProperty("业务名称") - private String name; - - /** - * 运维 - */ - private String maintainers; - - /** - * 子业务 - */ - @ApiModelProperty("子业务ID") - private String subAppIds; - - @ApiModelProperty("是否是动态业务集") - private boolean dynamicAppSet = false; - - /** - * 时区 - */ - private String timeZone; - - /** - * 组织架构ID - */ - @ApiModelProperty("组织架构ID") - private Long deptId; -} diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/tmp/TmpUpdateAppSetRequest.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/tmp/TmpUpdateAppSetRequest.java deleted file mode 100644 index 0cf3983cd4..0000000000 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/tmp/TmpUpdateAppSetRequest.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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.tmp; - -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; - -/** - * 更新业务集请求 - */ -@Data -@ApiModel("更新业务集请求") -public class TmpUpdateAppSetRequest { - - @ApiModelProperty("业务集ID") - private Long appId; - - /** - * 新增运维 - */ - @ApiModelProperty("新增运维") - private String addMaintainers; - - /** - * 删除运维 - */ - @ApiModelProperty("删除运维") - private String delMaintainers; - - /** - * 新增子业务 - */ - @ApiModelProperty("新增子业务") - private String addSubBizIds; - - /** - * 删除子业务 - */ - @ApiModelProperty("删除子业务") - private String delSubBizIds; -} diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/impl/ServiceApplicationResourceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/impl/ServiceApplicationResourceImpl.java index d7ae084df2..3320570261 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/impl/ServiceApplicationResourceImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/impl/ServiceApplicationResourceImpl.java @@ -91,11 +91,7 @@ private ServiceApplicationDTO convertToServiceApp(ApplicationDTO appInfo) { app.setScopeType(appInfo.getScope().getType().getValue()); app.setScopeId(appInfo.getScope().getId()); app.setName(appInfo.getName()); - app.setAppType(appInfo.getAppType().getValue()); - app.setSubBizIds(appInfo.getSubBizIds()); - app.setMaintainers(appInfo.getMaintainers()); app.setOwner(appInfo.getBkSupplierAccount()); - app.setOperateDeptId(appInfo.getOperateDeptId()); app.setTimeZone(appInfo.getTimeZone()); app.setLanguage(appInfo.getLanguage()); if (appInfo.getAttrs() != null) { @@ -136,14 +132,6 @@ public List listAppsByAppIds(String appIds) { return applications.stream().map(this::convertToServiceApp).collect(Collectors.toList()); } - @Override - public InternalResponse checkAppPermission(Long appId, String username) { - if (appId == null || appId < 0) { - return InternalResponse.buildSuccessResp(false); - } - return InternalResponse.buildSuccessResp(applicationService.checkAppPermission(appId, username)); - } - @Override public InternalResponse> listApps(String scopeType) { List appList = applicationService.listAllApps(); diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/impl/ServiceHostResourceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/impl/ServiceHostResourceImpl.java index bf5a55d7fb..981bfdf060 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/impl/ServiceHostResourceImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/impl/ServiceHostResourceImpl.java @@ -148,12 +148,6 @@ public InternalResponse> getHostStatusByIp(Long appId return InternalResponse.buildSuccessResp(hostStatusDTOList); } - @Override - public InternalResponse> checkAppHosts(Long appId, - ServiceCheckAppHostsReq req) { - return InternalResponse.buildSuccessResp(hostService.checkAppHosts(appId, req.getHosts())); - } - @Override public InternalResponse batchGetAppHosts(Long appId, ServiceCheckAppHostsReq req) { diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/common/TopologyHelper.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/common/TopologyHelper.java index 0a7078c94b..51ce2551f2 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/common/TopologyHelper.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/common/TopologyHelper.java @@ -330,21 +330,7 @@ public List getBizSetSubBizIds(ApplicationDTO appInfo) { if (appInfo.isAllBizSet()) { return applicationDAO.listAllBizAppBizIds(); } else if (appInfo.isBizSet()) { - List subAppIds = appInfo.getSubBizIds(); - // 兼容发布过程中未完成子业务字段同步的部门型业务集 - Long optDeptId = appInfo.getOperateDeptId(); - if (CollectionUtils.isEmpty(subAppIds) && optDeptId != null) { - // 使用OperateDeptId - subAppIds = applicationDAO.getBizIdsByOptDeptId(optDeptId); - } else { - // subAppIds与OperateDeptId同时生效 - if (optDeptId != null) { - subAppIds.addAll(applicationDAO.getBizIdsByOptDeptId(optDeptId)); - } - } - // 去重 - subAppIds = new ArrayList<>(new HashSet<>(subAppIds)); - return subAppIds; + return appInfo.getSubBizIds(); } else { FormattingTuple msg = MessageFormatter.format( "app {} is not bizSet app, please check, detail:{}", diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/ApplicationDAO.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/ApplicationDAO.java index 6c7ff60aef..ff36c50c7c 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/ApplicationDAO.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/ApplicationDAO.java @@ -24,8 +24,6 @@ package com.tencent.bk.job.manage.dao; -import com.tencent.bk.job.common.annotation.CompatibleImplementation; -import com.tencent.bk.job.common.constant.AppTypeEnum; import com.tencent.bk.job.common.constant.ResourceScopeTypeEnum; import com.tencent.bk.job.common.model.dto.ApplicationDTO; import com.tencent.bk.job.common.model.dto.ResourceScope; @@ -43,8 +41,6 @@ public interface ApplicationDAO { ApplicationDTO getAppById(long appId); - List getBizIdsByOptDeptId(Long optDeptId); - List listAppsByAppIds(List appIdList); List listBizAppsByBizIds(Collection bizIdList); @@ -59,15 +55,10 @@ public interface ApplicationDAO { List listAllBizSetAppsWithDeleted(); - @CompatibleImplementation(explain = "兼容方法,等业务集全部迁移到cmdb之后可以删除", version = "3.6.x") - List listAppsByType(AppTypeEnum appType); - List listAppsByScopeType(ResourceScopeTypeEnum scopeType); Long insertApp(DSLContext dslContext, ApplicationDTO applicationDTO); - Long insertAppWithSpecifiedAppId(DSLContext dslContext, ApplicationDTO applicationDTO); - int updateApp(DSLContext dslContext, ApplicationDTO applicationDTO); /** @@ -88,10 +79,6 @@ public interface ApplicationDAO { */ int deleteAppByIdSoftly(DSLContext dslContext, long appId); - int updateMaintainers(long appId, String maintainers); - - int updateSubBizIds(long appId, String subBizIds); - Integer countApps(); Integer countBizSetAppsWithDeleted(); diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/impl/ApplicationDAOImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/impl/ApplicationDAOImpl.java index d8e5943d3b..c6c694517f 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/impl/ApplicationDAOImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/impl/ApplicationDAOImpl.java @@ -24,7 +24,6 @@ package com.tencent.bk.job.manage.dao.impl; -import com.tencent.bk.job.common.constant.AppTypeEnum; import com.tencent.bk.job.common.constant.Bool; import com.tencent.bk.job.common.constant.ErrorCode; import com.tencent.bk.job.common.constant.ResourceScopeTypeEnum; @@ -33,12 +32,10 @@ import com.tencent.bk.job.common.model.dto.ApplicationDTO; import com.tencent.bk.job.common.model.dto.ResourceScope; import com.tencent.bk.job.common.util.json.JsonUtils; -import com.tencent.bk.job.manage.common.util.JooqDataTypeUtil; import com.tencent.bk.job.manage.dao.ApplicationDAO; import lombok.extern.slf4j.Slf4j; import lombok.val; import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang3.StringUtils; import org.jooq.Condition; import org.jooq.DSLContext; import org.jooq.Record; @@ -55,8 +52,6 @@ import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; -import java.util.LinkedList; import java.util.List; import java.util.stream.Collectors; @@ -72,12 +67,8 @@ public class ApplicationDAOImpl implements ApplicationDAO { T_APP.BK_SCOPE_TYPE, T_APP.BK_SCOPE_ID, T_APP.APP_NAME, - T_APP.MAINTAINERS, T_APP.BK_SUPPLIER_ACCOUNT, - T_APP.APP_TYPE, - T_APP.SUB_APP_IDS, T_APP.TIMEZONE, - T_APP.BK_OPERATE_DEPT_ID, T_APP.LANGUAGE, T_APP.IS_DELETED, T_APP.ATTRS @@ -125,54 +116,20 @@ public static ApplicationDTO extract(Record record) { String scopeId = record.get(T_APP.BK_SCOPE_ID); applicationDTO.setScope(new ResourceScope(scopeType, scopeId)); applicationDTO.setName(record.get(T_APP.APP_NAME)); - applicationDTO.setMaintainers(record.get(T_APP.MAINTAINERS)); applicationDTO.setBkSupplierAccount(record.get(T_APP.BK_SUPPLIER_ACCOUNT)); - applicationDTO.setAppType(AppTypeEnum.valueOf(record.get(T_APP.APP_TYPE))); - applicationDTO.setSubBizIds(splitSubBizIds(record.get(T_APP.SUB_APP_IDS))); applicationDTO.setTimeZone(record.get(T_APP.TIMEZONE)); - applicationDTO.setOperateDeptId(record.get(T_APP.BK_OPERATE_DEPT_ID)); applicationDTO.setLanguage(record.get(T_APP.LANGUAGE)); applicationDTO.setAttrs(JsonUtils.fromJson(record.get(T_APP.ATTRS), ApplicationAttrsDO.class)); applicationDTO.setDeleted(Bool.isTrue(record.get(T_APP.IS_DELETED).byteValue())); return applicationDTO; } - private static List splitSubBizIds(String bizIdsStr) { - List bizIdList = new LinkedList<>(); - if (StringUtils.isNotBlank(bizIdsStr)) { - for (String bizIdStr : bizIdsStr.split("[,;]")) { - if (StringUtils.isNotBlank(bizIdStr)) { - bizIdList.add(Long.valueOf(bizIdStr)); - } - } - - } - return bizIdList; - } - private List getBasicNotDeletedConditions() { List conditions = new ArrayList<>(); conditions.add(T_APP.IS_DELETED.eq(UByte.valueOf(0))); return conditions; } - @Override - public List getBizIdsByOptDeptId(Long optDeptId) { - List conditions = getBasicNotDeletedConditions(); - conditions.add(T_APP.BK_SCOPE_TYPE.eq(ResourceScopeTypeEnum.BIZ.getValue())); - if (optDeptId == null) { - conditions.add(T_APP.BK_OPERATE_DEPT_ID.isNull()); - } else { - conditions.add(T_APP.BK_OPERATE_DEPT_ID.eq(optDeptId)); - } - val records = context.select(T_APP.BK_SCOPE_ID).from(T_APP).where(conditions).fetch(); - if (records.isEmpty()) { - return Collections.emptyList(); - } else { - return records.map(it -> Long.parseLong(it.component1())); - } - } - private List listAppsByConditions(List conditions) { if (conditions == null) { conditions = new ArrayList<>(); @@ -246,13 +203,6 @@ public List listAllBizSetAppsWithDeleted() { return listAppsByConditions(conditions); } - @Override - public List listAppsByType(AppTypeEnum appType) { - List conditions = getBasicNotDeletedConditions(); - conditions.add(T_APP.APP_TYPE.eq((byte) appType.getValue())); - return listAppsByConditions(conditions); - } - @Override public List listAppsByScopeType(ResourceScopeTypeEnum scopeType) { List conditions = getBasicNotDeletedConditions(); @@ -262,20 +212,11 @@ public List listAppsByScopeType(ResourceScopeTypeEnum scopeType) @Override public Long insertApp(DSLContext dslContext, ApplicationDTO applicationDTO) { - val subBizIds = applicationDTO.getSubBizIds(); - String subBizIdsStr = null; - if (subBizIds != null) { - subBizIdsStr = subBizIds.stream().map(Object::toString).collect(Collectors.joining(";")); - } ResourceScope scope = applicationDTO.getScope(); val query = dslContext.insertInto(T_APP, T_APP.APP_NAME, - T_APP.APP_TYPE, T_APP.BK_SUPPLIER_ACCOUNT, - T_APP.MAINTAINERS, - T_APP.SUB_APP_IDS, T_APP.TIMEZONE, - T_APP.BK_OPERATE_DEPT_ID, T_APP.LANGUAGE, T_APP.BK_SCOPE_TYPE, T_APP.BK_SCOPE_ID, @@ -283,12 +224,8 @@ public Long insertApp(DSLContext dslContext, ApplicationDTO applicationDTO) { T_APP.IS_DELETED ).values( applicationDTO.getName(), - (byte) (applicationDTO.getAppType().getValue()), applicationDTO.getBkSupplierAccount(), - applicationDTO.getMaintainers(), - subBizIdsStr, applicationDTO.getTimeZone(), - applicationDTO.getOperateDeptId(), applicationDTO.getLanguage(), scope == null ? null : scope.getType().getValue(), scope == null ? null : scope.getId(), @@ -311,69 +248,14 @@ val record = query.returning(T_APP.APP_ID).fetchOne(); } } - @Override - public Long insertAppWithSpecifiedAppId(DSLContext dslContext, - ApplicationDTO applicationDTO) { - val subBizIds = applicationDTO.getSubBizIds(); - String subBizIdsStr = null; - if (subBizIds != null) { - subBizIdsStr = subBizIds.stream().map(Object::toString).collect(Collectors.joining(";")); - } - ResourceScope scope = applicationDTO.getScope(); - val query = dslContext.insertInto(T_APP, - T_APP.APP_ID, - T_APP.APP_NAME, - T_APP.APP_TYPE, - T_APP.BK_SUPPLIER_ACCOUNT, - T_APP.MAINTAINERS, - T_APP.SUB_APP_IDS, - T_APP.TIMEZONE, - T_APP.BK_OPERATE_DEPT_ID, - T_APP.LANGUAGE, - T_APP.BK_SCOPE_TYPE, - T_APP.BK_SCOPE_ID, - T_APP.ATTRS, - T_APP.IS_DELETED - ).values( - JooqDataTypeUtil.buildULong(applicationDTO.getId()), - applicationDTO.getName(), - (byte) (applicationDTO.getAppType().getValue()), - applicationDTO.getBkSupplierAccount(), - applicationDTO.getMaintainers(), - subBizIdsStr, - applicationDTO.getTimeZone(), - applicationDTO.getOperateDeptId(), - applicationDTO.getLanguage(), - scope == null ? null : scope.getType().getValue(), - scope == null ? null : scope.getId(), - applicationDTO.getAttrs() == null ? null : JsonUtils.toJson(applicationDTO.getAttrs()), - UByte.valueOf(Bool.FALSE.getValue()) - ); - try { - query.execute(); - } catch (Exception e) { - log.info("Fail to insertAppInfo:SQL={}", query.getSQL(ParamType.INLINED), e); - } - return applicationDTO.getId(); - } - @Override public int updateApp(DSLContext dslContext, ApplicationDTO applicationDTO) { - List subBizIds = applicationDTO.getSubBizIds(); - String subBizIdsStr = null; - if (subBizIds != null) { - subBizIdsStr = subBizIds.stream().map(Object::toString).collect(Collectors.joining(",")); - } val query = dslContext.update(T_APP) .set(T_APP.APP_NAME, applicationDTO.getName()) .set(T_APP.BK_SUPPLIER_ACCOUNT, applicationDTO.getBkSupplierAccount()) - .set(T_APP.MAINTAINERS, applicationDTO.getMaintainers()) - .set(T_APP.SUB_APP_IDS, subBizIdsStr) .set(T_APP.TIMEZONE, applicationDTO.getTimeZone()) - .set(T_APP.BK_OPERATE_DEPT_ID, applicationDTO.getOperateDeptId()) .set(T_APP.LANGUAGE, applicationDTO.getLanguage()) .set(T_APP.ATTRS, applicationDTO.getAttrs() == null ? null : JsonUtils.toJson(applicationDTO.getAttrs())) - .set(T_APP.APP_TYPE, (byte) applicationDTO.getAppType().getValue()) .where(T_APP.APP_ID.eq(ULong.valueOf(applicationDTO.getId()))); return query.execute(); } @@ -402,22 +284,6 @@ public int deleteAppByIdSoftly(DSLContext dslContext, long appId) { return affectedNum; } - @Override - public int updateMaintainers(long appId, String maintainers) { - return context.update(T_APP) - .set(T_APP.MAINTAINERS, maintainers) - .where(T_APP.APP_ID.eq(ULong.valueOf(appId))) - .execute(); - } - - @Override - public int updateSubBizIds(long appId, String subBizIds) { - return context.update(T_APP) - .set(T_APP.SUB_APP_IDS, subBizIds) - .where(T_APP.APP_ID.eq(ULong.valueOf(appId))) - .execute(); - } - @Override public Integer countApps() { return context.selectCount() diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/model/db/CacheAppDO.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/model/db/CacheAppDO.java index 25041c95e6..f4d242bd79 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/model/db/CacheAppDO.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/model/db/CacheAppDO.java @@ -24,23 +24,21 @@ package com.tencent.bk.job.manage.model.db; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; -import com.tencent.bk.job.common.annotation.CompatibleImplementation; -import com.tencent.bk.job.common.constant.AppTypeEnum; import com.tencent.bk.job.common.model.dto.ApplicationAttrsDO; import com.tencent.bk.job.common.model.dto.ApplicationDTO; import com.tencent.bk.job.common.model.dto.ResourceScope; import lombok.Getter; import lombok.Setter; -import java.util.List; - /** * Redis 缓存业务DO */ @Getter @Setter @JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonIgnoreProperties(ignoreUnknown = true) public class CacheAppDO { /** * 业务ID @@ -62,30 +60,6 @@ public class CacheAppDO { */ private String name; - /** - * 业务类型 - */ - @CompatibleImplementation(explain = "兼容字段,等业务集全部迁移到cmdb之后可以删除", version = "3.6.x") - private Integer appType; - - /** - * 子业务 - */ - @CompatibleImplementation(explain = "兼容字段,等业务集全部迁移到cmdb之后可以删除", version = "3.6.x") - private List subBizIds; - - /** - * 业务运维 - */ - @CompatibleImplementation(explain = "兼容字段,等业务集全部迁移到cmdb之后可以删除", version = "3.6.x") - private String maintainers; - - /** - * 临时字段-业务初始部门ID - */ - @CompatibleImplementation(explain = "兼容字段,等业务集全部迁移到cmdb之后可以删除", version = "3.6.x") - private Long operateDeptId; - /** * 业务属性 */ @@ -100,10 +74,6 @@ public static CacheAppDO fromApplicationDTO(ApplicationDTO application) { cacheAppDO.setScopeType(application.getScope().getType().getValue()); cacheAppDO.setScopeId(application.getScope().getId()); cacheAppDO.setName(application.getName()); - cacheAppDO.setAppType(application.getAppType().getValue()); - cacheAppDO.setMaintainers(application.getMaintainers()); - cacheAppDO.setSubBizIds(application.getSubBizIds()); - cacheAppDO.setOperateDeptId(application.getOperateDeptId()); cacheAppDO.setAttrs(application.getAttrs()); return cacheAppDO; } @@ -116,10 +86,6 @@ public static ApplicationDTO toApplicationDTO(CacheAppDO cacheAppDO) { application.setId(cacheAppDO.getId()); application.setScope(new ResourceScope(cacheAppDO.getScopeType(), cacheAppDO.getScopeId())); application.setName(cacheAppDO.getName()); - application.setAppType(AppTypeEnum.valueOf(cacheAppDO.getAppType())); - application.setMaintainers(cacheAppDO.getMaintainers()); - application.setSubBizIds(cacheAppDO.getSubBizIds()); - application.setOperateDeptId(cacheAppDO.getOperateDeptId()); application.setAttrs(cacheAppDO.getAttrs()); return application; } diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/ApplicationService.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/ApplicationService.java index 0dc0614391..a44989035a 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/ApplicationService.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/ApplicationService.java @@ -24,7 +24,6 @@ package com.tencent.bk.job.manage.service; -import com.tencent.bk.job.common.annotation.CompatibleImplementation; import com.tencent.bk.job.common.constant.ResourceScopeTypeEnum; import com.tencent.bk.job.common.exception.NotFoundException; import com.tencent.bk.job.common.model.dto.ApplicationDTO; @@ -145,18 +144,6 @@ public interface ApplicationService { */ List listAllApps(); - /** - * 判断用户是否有业务权限 - *

- * 接入权限中心后不应使用本接口 - * - * @param appId 业务 ID - * @param username 用户名 - * @return 是否有业务权限 - */ - @CompatibleImplementation(explain = "兼容方法,等业务集全部迁移到cmdb之后可以删除", version = "3.6.x") - boolean checkAppPermission(long appId, String username); - /** * 创建业务 * diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/HostService.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/HostService.java index d2b110243b..dc8d80da12 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/HostService.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/HostService.java @@ -183,19 +183,6 @@ AgentStatistics getAgentStatistics(String username, void fillAgentStatus(List hosts); - Boolean existsHost(Long bizId, String ip); - - /** - * 检查主机是否在业务下 - * - * TMP: 兼容方法,发布完成之后删除 - * - * @param appId Job业务ID - * @param hosts 被检查的主机 - * @return 非法的主机 - */ - List checkAppHosts(Long appId, List hosts); - /** * 获取业务下的主机 * diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/AppRoleServiceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/AppRoleServiceImpl.java index 17be0646bc..740b15acbe 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/AppRoleServiceImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/AppRoleServiceImpl.java @@ -25,6 +25,7 @@ package com.tencent.bk.job.manage.service.impl; import com.tencent.bk.job.common.cc.model.AppRoleDTO; +import com.tencent.bk.job.common.cc.sdk.BizSetCmdbClient; import com.tencent.bk.job.common.cc.sdk.CmdbClientFactory; import com.tencent.bk.job.common.cc.sdk.IBizCmdbClient; import com.tencent.bk.job.common.constant.ResourceScopeTypeEnum; @@ -34,14 +35,11 @@ import com.tencent.bk.job.manage.service.AppRoleService; import com.tencent.bk.job.manage.service.ApplicationService; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; -import java.util.Arrays; import java.util.Collections; -import java.util.HashSet; import java.util.List; import java.util.Set; @@ -50,33 +48,31 @@ public class AppRoleServiceImpl implements AppRoleService { private final ApplicationService applicationService; + private final BizSetCmdbClient bizSetCmdbClient; @Autowired - public AppRoleServiceImpl(@Lazy ApplicationService applicationService) { + public AppRoleServiceImpl(@Lazy ApplicationService applicationService, + BizSetCmdbClient bizSetCmdbClient) { this.applicationService = applicationService; + this.bizSetCmdbClient = bizSetCmdbClient; } @Override public List listAppRoles(String lang) { IBizCmdbClient bizCmdbClient = CmdbClientFactory.getCmdbClient(lang); - return bizCmdbClient.getAppRoleList(); + return bizCmdbClient.listRoles(); } @Override public Set listAppUsersByRole(Long appId, String role) { - ApplicationDTO applicationDTO = applicationService.getAppByAppId(appId); - ResourceScope scope = applicationDTO.getScope(); + ApplicationDTO application = applicationService.getAppByAppId(appId); + ResourceScope scope = application.getScope(); if (scope.getType() == ResourceScopeTypeEnum.BIZ) { IBizCmdbClient bizCmdbClient = CmdbClientFactory.getCmdbClient(JobContextUtil.getUserLang()); - return bizCmdbClient.getAppUsersByRole(appId, role); + return bizCmdbClient.listUsersByRole(Long.valueOf(scope.getId()), role); } else if (scope.getType() == ResourceScopeTypeEnum.BIZ_SET) { // 业务集当前只支持运维人员 - if ("bk_biz_maintainer".equals(role)) { - String maintainerStr = applicationDTO.getMaintainers(); - if (StringUtils.isNotBlank(maintainerStr)) { - return new HashSet<>(Arrays.asList(maintainerStr.split("[,;]"))); - } - } + return bizSetCmdbClient.listUsersByRole(Long.valueOf(scope.getId()), role); } else { log.warn("Not supported resourceScope:{}", scope); } diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/ApplicationServiceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/ApplicationServiceImpl.java index f1a2f9aae6..9b3abe25ee 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/ApplicationServiceImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/ApplicationServiceImpl.java @@ -35,7 +35,6 @@ import com.tencent.bk.job.manage.service.AccountService; import com.tencent.bk.job.manage.service.ApplicationService; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.jooq.DSLContext; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -228,40 +227,6 @@ public List listAllApps() { return applicationDAO.listAllApps(); } - @Override - public boolean checkAppPermission(long appId, String username) { - if (StringUtils.isBlank(username)) { - return false; - } - username = username.trim(); - ApplicationDTO appInfo = getAppByAppId(appId); - if (log.isDebugEnabled()) { - log.debug("Get app info for {}|{}", appId, appInfo); - } - if (appInfo == null) { - log.warn("Check app permission, app[{}] is not exist!", appId); - return false; - } - String maintainers = appInfo.getMaintainers(); - if (log.isDebugEnabled()) { - log.debug("Checking app {} user {}|{}", appId, username, maintainers); - } - if (StringUtils.isNotBlank(maintainers)) { - for (String maintainer : maintainers.split("[,;]")) { - if (StringUtils.isBlank(maintainer)) { - continue; - } - if (log.isDebugEnabled()) { - log.debug("Checking...|{}|{}|{}", appId, username, maintainer); - } - if (username.equals(maintainer.trim())) { - return true; - } - } - } - return false; - } - @Override public void updateApp(ApplicationDTO application) { log.info("Update app: {}", JsonUtils.toJson(application)); diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/HostServiceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/HostServiceImpl.java index 63d4560a03..f4d2b3d673 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/HostServiceImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/HostServiceImpl.java @@ -505,10 +505,6 @@ public List getAppDynamicGroupList(String username, @Override public List getBizDynamicGroupHostList(String username, Long bizId, List dynamicGroupIdList) { - ApplicationDTO applicationInfo = applicationService.getAppByScope( - new ResourceScope(ResourceScopeTypeEnum.BIZ, bizId.toString()) - ); - String maintainer = applicationInfo.getMaintainers().split("[,;]")[0]; Map ccGroupInfoMap = new HashMap<>(); Map> bizId2GroupIdMap = new HashMap<>(); @@ -716,11 +712,6 @@ public void fillAgentStatus(List hosts) { } } - @Override - public Boolean existsHost(Long bizId, String ip) { - return applicationHostDAO.existsHost(dslContext, bizId, ip); - } - @Override public CcTopologyNodeVO listAppTopologyHostCountTree(String username, AppResourceScope appResourceScope) { @@ -1291,51 +1282,6 @@ public AgentStatistics getAgentStatistics(String username, Long appId, AgentStat return new AgentStatistics(normalCount, abnormalCount); } - @Override - public List checkAppHosts(Long appId, - List hosts) { - ApplicationDTO application = applicationService.getAppByAppId(appId); - - if (application.isAllBizSet()) { - // cmdb全业务包含了所有业务下的主机,不需要再判断 - return Collections.emptyList(); - } - - List includeBizIds = buildIncludeBizIdList(application); - if (CollectionUtils.isEmpty(includeBizIds)) { - log.warn("App do not contains any biz, appId:{}", appId); - return hosts; - } - - List hostsInOtherApp = new ArrayList<>(); - List notExistHosts = new ArrayList<>(); - - // 从缓存中查询主机信息,并判断主机是否在业务下 - checkCachedHosts(hosts, includeBizIds, hostsInOtherApp, notExistHosts); - - // 如果主机不在缓存中,那么从已同步到Job的主机中查询 - if (CollectionUtils.isNotEmpty(notExistHosts)) { - log.info("Hosts not in cached, check hosts by synced hosts. notCacheHosts: {}", notExistHosts); - checkSyncHosts(includeBizIds, hostsInOtherApp, notExistHosts); - } - - // 如果主机不在已同步到Job的主机中, 那么从cmdb直接查询 - if (CollectionUtils.isNotEmpty(notExistHosts)) { - log.info("Hosts not synced, check hosts by cmdb. notSyncedHosts: {}", notExistHosts); - checkHostsFromCmdb(includeBizIds, hostsInOtherApp, notExistHosts); - } - - List invalidHosts = new ArrayList<>(); - if (CollectionUtils.isNotEmpty(notExistHosts) || CollectionUtils.isNotEmpty(hostsInOtherApp)) { - invalidHosts.addAll(notExistHosts.stream().map(HostDTO::fromCloudIp).collect(Collectors.toList())); - invalidHosts.addAll(hostsInOtherApp.stream() - .map(host -> new HostDTO(host.getBkCloudId(), host.getIp())).collect(Collectors.toList())); - log.info("Contains invalid hosts, appId: {}, notExistHosts: {}, hostsInOtherApp: {}", - appId, notExistHosts, hostsInOtherApp); - } - return invalidHosts; - } - private List buildIncludeBizIdList(ApplicationDTO application) { List bizIdList = new ArrayList<>(); if (application.isBiz()) { diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/sync/BizSetEventWatcher.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/sync/BizSetEventWatcher.java index 15d7966eee..7fb06b3827 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/sync/BizSetEventWatcher.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/sync/BizSetEventWatcher.java @@ -98,7 +98,6 @@ private void updateBizSetProps(ApplicationDTO originApp, ApplicationDTO updateAp originApp.setName(updateApp.getName()); originApp.setBkSupplierAccount(updateApp.getBkSupplierAccount()); originApp.setLanguage(updateApp.getLanguage()); - originApp.setMaintainers(updateApp.getMaintainers()); originApp.setTimeZone(updateApp.getTimeZone()); } diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/sync/BizSetRelationEventWatcher.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/sync/BizSetRelationEventWatcher.java index 376202cea1..b8e4b963b0 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/sync/BizSetRelationEventWatcher.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/sync/BizSetRelationEventWatcher.java @@ -68,7 +68,6 @@ protected void handleEvent(ResourceEvent event) { if (cacheApplication == null || cacheApplication.isDeleted()) { return; } - cacheApplication.setSubBizIds(latestSubBizIds); ApplicationAttrsDO attrs = cacheApplication.getAttrs(); if (attrs != null) { attrs.setSubBizIds(latestSubBizIds); diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/sync/BizSetSyncService.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/sync/BizSetSyncService.java index 4020e5fa3f..9017f5591f 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/sync/BizSetSyncService.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/sync/BizSetSyncService.java @@ -28,7 +28,6 @@ import com.tencent.bk.job.common.cc.model.bizset.BizSetInfo; import com.tencent.bk.job.common.cc.model.bizset.BizSetScope; import com.tencent.bk.job.common.cc.sdk.IBizSetCmdbClient; -import com.tencent.bk.job.common.constant.AppTypeEnum; import com.tencent.bk.job.common.constant.ResourceScopeTypeEnum; import com.tencent.bk.job.common.model.dto.ApplicationAttrsDO; import com.tencent.bk.job.common.model.dto.ApplicationDTO; @@ -81,7 +80,7 @@ public void syncBizSetFromCMDB() { return; } log.info("[{}] Begin to sync bizSet from cmdb", Thread.currentThread().getName()); - List ccBizSets = bizSetCmdbClient.getAllBizSetApps(); + List ccBizSets = bizSetCmdbClient.listAllBizSets(); if (log.isInfoEnabled()) { log.info("Sync cmdb bizSet result: {}", JsonUtils.toJson(ccBizSets)); } @@ -180,18 +179,14 @@ private ApplicationDTO convertBizSetToApplication(BizSetInfo bizSetInfo) { ApplicationDTO appInfoDTO = new ApplicationDTO(); appInfoDTO.setBkSupplierAccount(bizSetInfo.getSupplierAccount()); appInfoDTO.setName(bizSetInfo.getName()); - appInfoDTO.setMaintainers(bizSetInfo.getMaintainer()); - appInfoDTO.setOperateDeptId(bizSetInfo.getOperateDeptId()); appInfoDTO.setTimeZone(bizSetInfo.getTimezone()); BizSetScope scope = bizSetInfo.getScope(); ApplicationAttrsDO attrs = new ApplicationAttrsDO(); if (scope != null && scope.isMatchAll()) { // 全业务 - appInfoDTO.setAppType(AppTypeEnum.ALL_APP); attrs.setMatchAllBiz(true); } else { // 普通业务集 - appInfoDTO.setAppType(AppTypeEnum.APP_SET); attrs.setMatchAllBiz(false); if (CollectionUtils.isNotEmpty(bizSetInfo.getBizList())) { attrs.setSubBizIds(bizSetInfo.getBizList().stream().map(BizInfo::getId).collect(Collectors.toList())); diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/sync/BizWatchThread.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/sync/BizWatchThread.java index 1434482b1a..0aec6549b2 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/sync/BizWatchThread.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/sync/BizWatchThread.java @@ -237,7 +237,6 @@ private void updateBizProps(ApplicationDTO originApp, ApplicationDTO updateApp) originApp.setName(updateApp.getName()); originApp.setBkSupplierAccount(updateApp.getBkSupplierAccount()); originApp.setLanguage(updateApp.getLanguage()); - originApp.setMaintainers(updateApp.getMaintainers()); originApp.setTimeZone(updateApp.getTimeZone()); } } diff --git a/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/client/EsbCmdbClient.java b/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/client/EsbCmdbClient.java deleted file mode 100644 index 2abfed73c3..0000000000 --- a/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/client/EsbCmdbClient.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * 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.upgrader.client; - -import com.fasterxml.jackson.core.type.TypeReference; -import com.tencent.bk.job.common.cc.model.bizset.BatchUpdateBizSetReq; -import com.tencent.bk.job.common.cc.model.bizset.BizSetFilter; -import com.tencent.bk.job.common.cc.model.bizset.BizSetInfo; -import com.tencent.bk.job.common.cc.model.bizset.CreateBizSetReq; -import com.tencent.bk.job.common.cc.model.bizset.Page; -import com.tencent.bk.job.common.cc.model.bizset.Rule; -import com.tencent.bk.job.common.cc.model.bizset.SearchBizSetReq; -import com.tencent.bk.job.common.cc.model.bizset.SearchBizSetResp; -import com.tencent.bk.job.common.esb.model.EsbReq; -import com.tencent.bk.job.common.esb.model.EsbResp; -import com.tencent.bk.job.common.esb.sdk.AbstractEsbSdkClient; -import lombok.extern.slf4j.Slf4j; -import org.apache.http.client.methods.HttpPost; - -import java.util.ArrayList; -import java.util.List; - -@Slf4j -public class EsbCmdbClient extends AbstractEsbSdkClient { - - private final String cmdbSupplierAccount; - - private static final String FIELD_KEY_BIZ_SET_ID = "bk_biz_set_id"; - - private static final String SEARCH_BUSINESS_SET = "/api/c/compapi/v2/cc/list_business_set/"; - private static final String CREATE_BUSINESS_SET = "/api/c/compapi/v2/cc/create_business_set/"; - private static final String BATCH_UPDATE_BUSINESS_SET = "/api/c/compapi/v2/cc/batch_update_business_set/"; - - public EsbCmdbClient(String esbHostUrl, - String appCode, - String appSecret, - String lang, - String cmdbSupplierAccount) { - super(esbHostUrl, appCode, appSecret, lang, false); - this.cmdbSupplierAccount = cmdbSupplierAccount; - } - - public T makeCmdbBaseReq(Class reqClass) { - return makeBaseReqByWeb(reqClass, null, "admin", cmdbSupplierAccount); - } - - /** - * 根据Id查询业务集信息 - * - * @param id 业务集id - * @return 业务集信息 - */ - public List searchBizSetById(Long id) { - SearchBizSetReq req = makeCmdbBaseReq(SearchBizSetReq.class); - req.setPage(new Page()); - BizSetFilter filter = new BizSetFilter(); - filter.setCondition(BizSetFilter.CONDITION_AND); - List rules = new ArrayList<>(); - rules.add(new Rule(FIELD_KEY_BIZ_SET_ID, Rule.OPERATOR_EQUAL, id)); - filter.setRules(rules); - req.setFilter(filter); - EsbResp resp = getEsbRespByReq( - HttpPost.METHOD_NAME, - SEARCH_BUSINESS_SET, - req, - new TypeReference>() { - }); - if (!resp.getResult() || resp.getData() == null) { - return null; - } - return resp.getData().getBizSetList(); - } - - /** - * 创建业务集 - * - * @param createBizSetReq 业务集信息 - * @return 业务集id - */ - public Long createBizSet(CreateBizSetReq createBizSetReq) { - EsbResp resp = getEsbRespByReq( - HttpPost.METHOD_NAME, - CREATE_BUSINESS_SET, - createBizSetReq, - new TypeReference>() { - }); - return resp.getData(); - } - - /** - * 批量更新业务集 - * - * @param batchUpdateBizSetReq 业务集更新请求信息 - * @return 业务集id - */ - public Boolean batchUpdateBizSet(BatchUpdateBizSetReq batchUpdateBizSetReq) { - EsbResp resp = getEsbRespByReq( - HttpPost.METHOD_NAME, - BATCH_UPDATE_BUSINESS_SET, - batchUpdateBizSetReq, - new TypeReference>() { - }); - return resp.getResult(); - } - -} diff --git a/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/model/AppInfo.java b/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/model/AppInfo.java index b59460d2cb..90d9a98f19 100644 --- a/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/model/AppInfo.java +++ b/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/model/AppInfo.java @@ -24,17 +24,11 @@ package com.tencent.bk.job.upgrader.model; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.tencent.bk.job.common.annotation.CompatibleImplementation; -import com.tencent.bk.job.common.constant.AppTypeEnum; -import com.tencent.bk.job.common.constant.ResourceScopeTypeEnum; import com.tencent.bk.job.common.model.dto.ApplicationAttrsDO; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; -import java.util.List; - @Data @NoArgsConstructor @AllArgsConstructor @@ -57,28 +51,13 @@ public class AppInfo { */ private String name; - /** - * 业务类型 - */ - private Integer appType; - /** * 运维 */ private String maintainers; - /** - * 子业务 - */ - private List subAppIds; - private String owner; - /** - * 初始运维部门Id - */ - private Long operateDeptId; - /** * 时区 */ @@ -94,18 +73,4 @@ public class AppInfo { */ private ApplicationAttrsDO attrs; - /** - * 是否是全业务 - */ - @CompatibleImplementation(explain = "兼容方法,等业务集全部迁移到cmdb之后需要移除对appType的判断", version = "3.6.x") - @JsonIgnore - public boolean isAllBizSet() { - return appType == AppTypeEnum.ALL_APP.getValue() - || (ResourceScopeTypeEnum.BIZ_SET.getValue().equals(scopeType) - && attrs != null && attrs.getMatchAllBiz() != null && attrs.getMatchAllBiz()); - } - - public String getIdAndName() { - return "(" + getId() + "," + getName() + ")"; - } } diff --git a/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/task/BizSetAuthMigrationTask.java b/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/task/BizSetAuthMigrationTask.java deleted file mode 100644 index 1d439be52c..0000000000 --- a/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/task/BizSetAuthMigrationTask.java +++ /dev/null @@ -1,349 +0,0 @@ -/* - * 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.upgrader.task; - -import com.fasterxml.jackson.core.type.TypeReference; -import com.google.common.base.Charsets; -import com.tencent.bk.job.common.iam.client.EsbIamClient; -import com.tencent.bk.job.common.iam.dto.BatchAuthByPathReq; -import com.tencent.bk.job.common.iam.dto.EsbIamAction; -import com.tencent.bk.job.common.iam.dto.EsbIamBatchAuthedPolicy; -import com.tencent.bk.job.common.iam.dto.EsbIamBatchPathResource; -import com.tencent.bk.job.common.iam.dto.EsbIamPathItem; -import com.tencent.bk.job.common.iam.dto.EsbIamSubject; -import com.tencent.bk.job.common.util.json.JsonUtils; -import com.tencent.bk.job.upgrader.anotation.ExecuteTimeEnum; -import com.tencent.bk.job.upgrader.anotation.RequireTaskParam; -import com.tencent.bk.job.upgrader.anotation.UpgradeTask; -import com.tencent.bk.job.upgrader.anotation.UpgradeTaskInputParam; -import com.tencent.bk.job.upgrader.client.JobClient; -import com.tencent.bk.job.upgrader.model.AppInfo; -import com.tencent.bk.job.upgrader.task.param.JobManageServerAddress; -import com.tencent.bk.job.upgrader.task.param.ParamNameConsts; -import io.micrometer.core.instrument.util.IOUtils; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang3.StringUtils; - -import java.io.InputStream; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.stream.Collectors; - -/** - * 账号使用权限迁移任务 - */ -@Slf4j -@RequireTaskParam(value = { - @UpgradeTaskInputParam(value = JobManageServerAddress.class) -}) -@UpgradeTask( - dataStartVersion = "3.0.0.0", - targetVersion = "3.5.0", - targetExecuteTime = ExecuteTimeEnum.MAKE_UP) -public class BizSetAuthMigrationTask extends BaseUpgradeTask { - - private static final String PLACEHOLDER_BIZ_SET_ID = "{{biz_set_id}}"; - private static final String PLACEHOLDER_BIZ_SET_NAME = "{{biz_set_name}}"; - - private JobClient jobManageClient; - private EsbIamClient esbIamClient; - private List bizSetAppInfoList; - private Map bizSetAppInfoMap; - - private String getJobHostUrlByAddress(String address) { - if (!address.startsWith("http://") && !address.startsWith("https://")) { - address = "http://" + address; - } - return address; - } - - public BizSetAuthMigrationTask(Properties properties) { - super(properties); - } - - @Override - public void init() { - String jobAuthToken = getJobAuthToken(); - jobManageClient = new JobClient( - getJobHostUrlByAddress((String) getProperties().get(ParamNameConsts.INPUT_PARAM_JOB_MANAGE_SERVER_ADDRESS)), - jobAuthToken - ); - this.bizSetAppInfoList = getAllBizSetAppInfoFromManage(); - bizSetAppInfoMap = new HashMap<>(); - bizSetAppInfoList.forEach(appInfo -> { - bizSetAppInfoMap.put(appInfo.getId(), appInfo.getName()); - }); - } - - private EsbIamClient getEsbIamClient() { - Properties properties = getProperties(); - if (esbIamClient == null) { - esbIamClient = new EsbIamClient( - (String) properties.get(ParamNameConsts.CONFIG_PROPERTY_ESB_SERVICE_URL), - (String) properties.get(ParamNameConsts.CONFIG_PROPERTY_APP_CODE), - (String) properties.get(ParamNameConsts.CONFIG_PROPERTY_APP_SECRET), - false - ); - } - return esbIamClient; - } - - private List getAllBizSetAppInfoFromManage() { - try { - return jobManageClient.listBizSetApps(); - } catch (Exception e) { - log.error("Fail to get normal apps from job-manage, please confirm job-manage version>=3.3.5.0"); - throw e; - } - } - - /** - * 调用权限中心接口进行批量授权 - * - * @param esbIamSubject 授权对象 - * @param actions 授权操作列表 - * @param resourceList 批量依赖资源路径 - * @return 是否授权成功 - */ - private boolean batchAuth(EsbIamSubject esbIamSubject, - List actions, - List resourceList) { - try { - List batchAuthedPolicy = getEsbIamClient().batchAuthByPath(actions, - esbIamSubject, resourceList, null); - log.info("batchAuthedPolicy={}", JsonUtils.toJson(batchAuthedPolicy)); - return true; - } catch (Exception e) { - log.error("Fail to auth subject {} to {}", JsonUtils.toJson(esbIamSubject), JsonUtils.toJson(actions), e); - return false; - } - } - - public void printSeparateLine() { - log.info("=================================================="); - } - - private void resetResourceListTpl(List reqList) { - fillResourceListTpl(reqList, PLACEHOLDER_BIZ_SET_ID, PLACEHOLDER_BIZ_SET_NAME); - } - - private void fillResourceListTpl(List reqlist, - String bizSetId, - String bizSetName) { - for (BatchAuthByPathReq batchAuthByPathReq : reqlist) { - List resourceList = batchAuthByPathReq.getResources(); - for (EsbIamBatchPathResource esbIamBatchPathResource : resourceList) { - List> paths = esbIamBatchPathResource.getPaths(); - if (CollectionUtils.isEmpty(paths)) { - continue; - } - for (List path : paths) { - if (CollectionUtils.isEmpty(path)) { - continue; - } - for (EsbIamPathItem esbIamPathItem : path) { - esbIamPathItem.setId(bizSetId); - esbIamPathItem.setName(bizSetName); - } - } - } - } - } - - private void recordAuthActionResult(boolean result, - List successActionList, - List failedActionList, - String maintainer, - String bizSetAppStr, - BatchAuthByPathReq req) { - if (result) { - log.info( - "[Action] Success to auth maintainer:{}, app:{}, actions:{}", - maintainer, - bizSetAppStr, - JsonUtils.toJson(req.getActions()) - ); - successActionList.addAll( - req.getActions().parallelStream() - .map(EsbIamAction::getId) - .collect(Collectors.toList()) - ); - } else { - log.warn( - "[Action] Fail to auth maintainer:{}, app:{}, actions:{}, resources:{}", - maintainer, - bizSetAppStr, - JsonUtils.toJson(req.getActions()), - JsonUtils.toJson(req.getResources()) - ); - failedActionList.addAll( - req.getActions().parallelStream() - .map(EsbIamAction::getId) - .collect(Collectors.toList()) - ); - } - } - - private void recordAuthMaintainerResult(List failedActionList, - List successMaintainerList, - List failedMaintainerList, - String maintainer, - int successActionCount, - int actionCount, - String bizSetAppStr) { - // 所有Action全部授权成功 - if (failedActionList.isEmpty()) { - successMaintainerList.add(maintainer); - log.info( - "[Maintainer] Success to auth maintainer:{} to {} actions of app {}", - maintainer, - successActionCount, - bizSetAppStr - ); - } else { - failedMaintainerList.add(maintainer); - log.warn( - "[Maintainer] Fail to auth maintainer:{} to {}/{} actions of app {}, failed actions:{}", - maintainer, - failedActionList, - actionCount, - bizSetAppStr, - JsonUtils.toJson(failedActionList) - ); - } - } - - private void recordAuthBizSetResult(List failedMaintainerList, - List successBizSetList, - List failedBizSetList, - int successMaintainerCount, - int maintainerCount, - String bizSetAppStr) { - if (failedMaintainerList.isEmpty()) { - successBizSetList.add(bizSetAppStr); - log.info( - "[BizSet] Success to auth {} maintainers of app {}", - successMaintainerCount, - bizSetAppStr - ); - } else { - failedBizSetList.add(bizSetAppStr); - log.warn( - "[BizSet] Fail to auth {}/{} maintainers of app {}, failed maintainers:{}", - failedMaintainerList.size(), - maintainerCount, - bizSetAppStr, - JsonUtils.toJson(failedMaintainerList) - ); - } - } - - private void showGlobalAuthResult(List failedBizSetList, - List successBizSetList) { - if (failedBizSetList.isEmpty()) { - log.info( - "[Global] Success to auth {} bizSetApps", - successBizSetList.size() - ); - } else { - log.warn( - "[Global] Fail to auth {}/{} bizSetApps, failed bizSetApps:{}", - failedBizSetList.size(), - bizSetAppInfoList.size(), - JsonUtils.toJson(failedBizSetList) - ); - } - } - - @Override - public int execute(String[] args) { - log.info(getName() + " for version " + getTargetVersion() + " begin to run..."); - // 1.权限模板数据读取 - String bizSetTplFileName = "biz_set_auth_template.json"; - InputStream ins = getClass().getClassLoader().getResourceAsStream(bizSetTplFileName); - String authTemplateStr = IOUtils.toString(ins, Charsets.UTF_8); - List reqList = JsonUtils.fromJson( - authTemplateStr, new TypeReference>() { - }); - log.info("{} auth request template(s) loaded", reqList.size()); - printSeparateLine(); - log.info("Begin to auth according to job app info:"); - // 2.业务集运维人员授权 - List successBizSetList = new ArrayList<>(); - List failedBizSetList = new ArrayList<>(); - for (AppInfo bizSetAppInfo : bizSetAppInfoList) { - resetResourceListTpl(reqList); - fillResourceListTpl(reqList, bizSetAppInfo.getId().toString(), bizSetAppInfo.getName()); - String maintainerStr = bizSetAppInfo.getMaintainers(); - if (StringUtils.isBlank(maintainerStr)) { - log.warn( - "maintainer is blank, app:{},{}, ignore", - bizSetAppInfo.getId(), - bizSetAppInfo.getName() - ); - continue; - } - String[] maintainers = maintainerStr.split("[,;]"); - List maintainerList = new ArrayList<>(); - for (String maintainer : maintainers) { - if (!maintainerList.contains(maintainer)) { - maintainerList.add(maintainer); - } - } - List successMaintainerList = new ArrayList<>(); - List failedMaintainerList = new ArrayList<>(); - for (String maintainer : maintainerList) { - EsbIamSubject esbIamSubject = new EsbIamSubject("user", maintainer); - List successActionList = new ArrayList<>(); - List failedActionList = new ArrayList<>(); - int actionCount = 0; - for (BatchAuthByPathReq req : reqList) { - actionCount += req.getActions().size(); - boolean result = batchAuth(esbIamSubject, req.getActions(), req.getResources()); - recordAuthActionResult( - result, successActionList, failedActionList, - maintainer, bizSetAppInfo.getIdAndName(), req - ); - } - recordAuthMaintainerResult( - failedActionList, successMaintainerList, failedMaintainerList, - maintainer, successActionList.size(), actionCount, bizSetAppInfo.getIdAndName() - ); - } - recordAuthBizSetResult( - failedMaintainerList, successBizSetList, failedBizSetList, - successMaintainerList.size(), maintainerList.size(), bizSetAppInfo.getIdAndName() - ); - } - showGlobalAuthResult(failedBizSetList, successBizSetList); - log.info("auth bizSetApps finished!"); - printSeparateLine(); - return 0; - } -} diff --git a/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/task/BizSetCreateMigrationTask.java b/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/task/BizSetCreateMigrationTask.java deleted file mode 100644 index 073576d774..0000000000 --- a/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/task/BizSetCreateMigrationTask.java +++ /dev/null @@ -1,311 +0,0 @@ -/* - * 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.upgrader.task; - -import com.tencent.bk.job.common.cc.model.bizset.BasicBizSet; -import com.tencent.bk.job.common.cc.model.bizset.BatchUpdateBizSetData; -import com.tencent.bk.job.common.cc.model.bizset.BatchUpdateBizSetReq; -import com.tencent.bk.job.common.cc.model.bizset.BizSetAttr; -import com.tencent.bk.job.common.cc.model.bizset.BizSetFilter; -import com.tencent.bk.job.common.cc.model.bizset.BizSetInfo; -import com.tencent.bk.job.common.cc.model.bizset.BizSetScope; -import com.tencent.bk.job.common.cc.model.bizset.CreateBizSetReq; -import com.tencent.bk.job.common.cc.model.bizset.Rule; -import com.tencent.bk.job.common.constant.AppTypeEnum; -import com.tencent.bk.job.common.constant.JobConstants; -import com.tencent.bk.job.common.util.FileUtil; -import com.tencent.bk.job.common.util.json.JsonUtils; -import com.tencent.bk.job.upgrader.anotation.ExecuteTimeEnum; -import com.tencent.bk.job.upgrader.anotation.RequireTaskParam; -import com.tencent.bk.job.upgrader.anotation.UpgradeTask; -import com.tencent.bk.job.upgrader.anotation.UpgradeTaskInputParam; -import com.tencent.bk.job.upgrader.client.EsbCmdbClient; -import com.tencent.bk.job.upgrader.client.JobClient; -import com.tencent.bk.job.upgrader.model.AppInfo; -import com.tencent.bk.job.upgrader.task.param.JobManageServerAddress; -import com.tencent.bk.job.upgrader.task.param.ParamNameConsts; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; -import org.slf4j.helpers.FormattingTuple; -import org.slf4j.helpers.MessageFormatter; -import org.springframework.util.CollectionUtils; - -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.InputStream; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Properties; - -/** - * 业务集、全业务向CMDB迁移的资源创建任务 - */ -@Slf4j -@RequireTaskParam(value = { - @UpgradeTaskInputParam(value = JobManageServerAddress.class) -}) -@UpgradeTask( - dataStartVersion = "3.0.0.0", - targetVersion = "3.5.0", - targetExecuteTime = ExecuteTimeEnum.AFTER_UPDATE_JOB) -public class BizSetCreateMigrationTask extends BaseUpgradeTask { - - private JobClient jobManageClient; - - private EsbCmdbClient esbCmdbClient; - private List bizSetAppInfoList; - - private String getJobHostUrlByAddress(String address) { - if (!address.startsWith("http://") && !address.startsWith("https://")) { - address = "http://" + address; - } - return address; - } - - public BizSetCreateMigrationTask(Properties properties) { - super(properties); - } - - @Override - public void init() { - String appCode = (String) properties.get(ParamNameConsts.CONFIG_PROPERTY_APP_CODE); - String appSecret = (String) properties.get(ParamNameConsts.CONFIG_PROPERTY_APP_SECRET); - String esbBaseUrl = (String) properties.get(ParamNameConsts.CONFIG_PROPERTY_ESB_SERVICE_URL); - String cmdbSupplierAccount = - (String) properties.get(ParamNameConsts.CONFIG_PROPERTY_CMDB_DEFAULT_SUPPLIER_ACCOUNT); - String jobAuthToken = getJobAuthToken(); - jobManageClient = new JobClient( - getJobHostUrlByAddress((String) properties.get(ParamNameConsts.INPUT_PARAM_JOB_MANAGE_SERVER_ADDRESS)), - jobAuthToken - ); - esbCmdbClient = new EsbCmdbClient(esbBaseUrl, appCode, appSecret, "zh-cn", cmdbSupplierAccount); - // 从job-manage拉取业务集/全业务信息 - this.bizSetAppInfoList = getAllBizSetAppInfoFromManage(); - } - - private List getAllBizSetAppInfoFromManage() { - try { - return jobManageClient.listBizSetApps(); - } catch (Exception e) { - log.error("Fail to get special apps from job-manage, please confirm job-manage version>=3.5.0.0"); - throw e; - } - } - - /** - * 为业务集构造选择业务的过滤条件 - * - * @param appInfo 业务集信息 - * @return 过滤条件 - */ - private BizSetFilter buildAppSetFilter(AppInfo appInfo) { - BizSetFilter filter = new BizSetFilter(); - filter.setCondition(BizSetFilter.CONDITION_AND); - - List rules = new ArrayList<>(); - // 指定所有子业务ID - List subAppIds = appInfo.getSubAppIds(); - if (subAppIds == null) { - subAppIds = new ArrayList<>(); - } - // 指定业务所属部门ID - Long operateDeptId = appInfo.getOperateDeptId(); - // 空业务集 - if (CollectionUtils.isEmpty(subAppIds) && operateDeptId == null) { - Rule subAppIdsRule = new Rule(); - subAppIdsRule.setField("bk_biz_id"); - subAppIdsRule.setOperator(Rule.OPERATOR_IN); - subAppIdsRule.setValue(subAppIds); - rules.add(subAppIdsRule); - filter.setRules(rules); - return filter; - } - if (!CollectionUtils.isEmpty(subAppIds)) { - Rule subAppIdsRule = new Rule(); - subAppIdsRule.setField("bk_biz_id"); - subAppIdsRule.setOperator(Rule.OPERATOR_IN); - subAppIdsRule.setValue(subAppIds); - rules.add(subAppIdsRule); - } - if (operateDeptId != null) { - Rule operateDeptIdRule = new Rule(); - operateDeptIdRule.setField("bk_operate_dept_id"); - operateDeptIdRule.setOperator(Rule.OPERATOR_IN); - operateDeptIdRule.setValue(Collections.singletonList(operateDeptId)); - rules.add(operateDeptIdRule); - } - - filter.setRules(rules); - return filter; - } - - /** - * 构造符合CMDB规则的运维人员字段 - * - * @param rawStr Job原始运维人员字段 - * @return 符合CMDB规则的运维人员字段 - */ - private String buildMaintainerStr(String rawStr) { - String[] maintainers = rawStr.split("[,;]"); - return String.join(",", maintainers); - } - - /** - * 获取业务集最终在CMDB中的ID,用于判定存在性决定是否创建 - * - * @param appInfo 业务信息 - * @return 业务集ID - */ - private long getFinalBizSetId(AppInfo appInfo) { - if (StringUtils.isNotBlank(appInfo.getScopeId())) { - return Long.parseLong(appInfo.getScopeId()); - } - return appInfo.getId(); - } - - /** - * 调用CMDB接口更新业务集属性信息 - * - * @param attr 业务集属性 - * @param scope 业务选择范围 - * @return 是否成功更新 - */ - private Boolean updateBizSet(BizSetAttr attr, BizSetScope scope) { - BatchUpdateBizSetReq batchUpdateBizSetReq = esbCmdbClient.makeCmdbBaseReq(BatchUpdateBizSetReq.class); - batchUpdateBizSetReq.setBizSetIds(Collections.singletonList(attr.getId())); - BatchUpdateBizSetData data = new BatchUpdateBizSetData(); - data.setAttr(attr); - data.setScope(scope); - batchUpdateBizSetReq.setData(data); - return esbCmdbClient.batchUpdateBizSet(batchUpdateBizSetReq); - } - - /** - * 根据Job中现存业务集/全业务信息向CMDB创建业务集/全业务 - * - * @param appInfo 业务集/全业务信息 - * @return 业务集是否已存在于CMDB中 - */ - private boolean createOrUpdateCMDBResourceForApp(AppInfo appInfo) { - CreateBizSetReq createBizSetReq = esbCmdbClient.makeCmdbBaseReq(CreateBizSetReq.class); - String desc = "Auto created by bk-job migration"; - String supplierAccount = (String) properties.get(ParamNameConsts.CONFIG_PROPERTY_CMDB_DEFAULT_SUPPLIER_ACCOUNT); - BizSetAttr attr = BizSetAttr.builder() - .id(getFinalBizSetId(appInfo)) - .name(appInfo.getName()) - .desc(desc) - .maintainer(buildMaintainerStr(appInfo.getMaintainers())) - .timeZone(appInfo.getTimeZone()) - .language(appInfo.getLanguage()) - .supplierAccount(supplierAccount) - .build(); - createBizSetReq.setAttr(attr); - BizSetScope scope = new BizSetScope(); - if (appInfo.isAllBizSet()) { - // 全业务 - scope.setMatchAll(true); - scope.setFilter(null); - } else if (appInfo.getAppType() == AppTypeEnum.APP_SET.getValue()) { - // 普通业务集 - scope.setMatchAll(false); - scope.setFilter(buildAppSetFilter(appInfo)); - } else { - log.warn("Not support app type:{}", appInfo.getAppType()); - return false; - } - createBizSetReq.setScope(scope); - try { - List bizSetList = esbCmdbClient.searchBizSetById(attr.getId()); - if (CollectionUtils.isEmpty(bizSetList)) { - Long bizSetId = esbCmdbClient.createBizSet(createBizSetReq); - if (bizSetId != null && bizSetId > 0) { - log.info("bizSet {} created", bizSetId); - } else { - log.warn("fail to create bizSet {}", attr.getId()); - return false; - } - } else { - if (attr.getId() == JobConstants.DEFAULT_ALL_BIZ_SET_ID) { - // CMDB内置的全业务,不更新 - log.info("bizSet {} is all-business bizSet created by cmdb, ignore", attr.getId()); - } else { - // 更新业务集 - log.info("bizSet {} already exists, update:{}", attr.getId(), updateBizSet(attr, scope)); - } - } - return true; - } catch (Exception e) { - FormattingTuple msg = MessageFormatter.format("Fail to create bizSet {}", createBizSetReq); - log.error(msg.getMessage(), e); - return false; - } - } - - @Override - public int execute(String[] args) { - log.info(getName() + " for version " + getTargetVersion() + " begin to run..."); - List successfulBizSetList = new ArrayList<>(); - List failedBizSetList = new ArrayList<>(); - int successCount = 0; - for (AppInfo appInfo : bizSetAppInfoList) { - BasicBizSet bizSet = new BasicBizSet(getFinalBizSetId(appInfo), appInfo.getName()); - // 1.调用CMDB接口创建业务集/全业务 - if (createOrUpdateCMDBResourceForApp(appInfo)) { - successCount += 1; - successfulBizSetList.add(bizSet); - } else { - failedBizSetList.add(bizSet); - } - } - if (successCount == bizSetAppInfoList.size()) { - log.info("all {} bizSets migrated to CMDB", successCount); - } else { - log.warn( - "{}/{} bizSets migrated to CMDB, please check log to confirm failed bizSets", - successCount, - bizSetAppInfoList.size() - ); - log.warn("Failed bizSets:{}", JsonUtils.toJson(failedBizSetList)); - } - // 2.生成更新CMDB数据库的业务集信息Json文件 - String content = JsonUtils.toJson(successfulBizSetList); - InputStream ins = new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8)); - try { - File targetFile = new File("biz_set_list.json"); - FileUtil.writeInsToFile(ins, targetFile.getAbsolutePath()); - log.info("biz_set_list.json generated, please save it to continue the next step! path:{}", - targetFile.getAbsolutePath()); - } catch (InterruptedException e) { - log.error("Fail to gen biz_set_list.json", e); - return 1; - } - if (!failedBizSetList.isEmpty()) { - return 1; - } - return 0; - } -} diff --git a/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/task/BizSetMigrationStatusUpdateTask.java b/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/task/BizSetMigrationStatusUpdateTask.java deleted file mode 100644 index 9e3cc47309..0000000000 --- a/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/task/BizSetMigrationStatusUpdateTask.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * 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.upgrader.task; - -import com.tencent.bk.job.upgrader.anotation.ExecuteTimeEnum; -import com.tencent.bk.job.upgrader.anotation.RequireTaskParam; -import com.tencent.bk.job.upgrader.anotation.UpgradeTask; -import com.tencent.bk.job.upgrader.anotation.UpgradeTaskInputParam; -import com.tencent.bk.job.upgrader.client.JobClient; -import com.tencent.bk.job.upgrader.task.param.JobManageServerAddress; -import com.tencent.bk.job.upgrader.task.param.ParamNameConsts; -import lombok.extern.slf4j.Slf4j; - -import java.util.Properties; - -/** - * 业务集、全业务向CMDB迁移完成后的迁移状态更新任务 - */ -@Slf4j -@RequireTaskParam(value = { - @UpgradeTaskInputParam(value = JobManageServerAddress.class) -}) -@UpgradeTask( - dataStartVersion = "3.0.0.0", - targetVersion = "3.5.0", - targetExecuteTime = ExecuteTimeEnum.MAKE_UP) -public class BizSetMigrationStatusUpdateTask extends BaseUpgradeTask { - - private JobClient jobManageClient; - - private String getJobHostUrlByAddress(String address) { - if (!address.startsWith("http://") && !address.startsWith("https://")) { - address = "http://" + address; - } - return address; - } - - public BizSetMigrationStatusUpdateTask(Properties properties) { - super(properties); - } - - @Override - public void init() { - String jobAuthToken = getJobAuthToken(); - jobManageClient = new JobClient( - getJobHostUrlByAddress((String) properties.get(ParamNameConsts.INPUT_PARAM_JOB_MANAGE_SERVER_ADDRESS)), - jobAuthToken - ); - } - - @Override - public int execute(String[] args) { - log.info(getName() + " for version " + getTargetVersion() + " begin to run..."); - boolean status = true; - try { - if (args.length >= 4) { - status = Boolean.parseBoolean(args[3].trim().toLowerCase()); - log.info("status from param:{}", status); - } - } catch (Exception e) { - log.warn("Fail to parse status from param:{}", args[3]); - return 1; - } - try { - log.info("try to set bizSet migration status:{}", status); - jobManageClient.setBizSetMigrationStatus(status); - } catch (Exception e) { - log.error("Fail to update migration status", e); - return 1; - } - return 0; - } -} diff --git a/support-files/kubernetes/charts/bk-job/Chart.yaml b/support-files/kubernetes/charts/bk-job/Chart.yaml index ffbb65825a..5877da16b4 100644 --- a/support-files/kubernetes/charts/bk-job/Chart.yaml +++ b/support-files/kubernetes/charts/bk-job/Chart.yaml @@ -2,8 +2,8 @@ apiVersion: v2 name: "bk-job" description: The BK-JOB is a ops script management and execution system with the capability of dealing with multiple tasks simultaneously. type: application -version: 0.3.0-rc.25 -appVersion: "3.6.0-rc.25" +version: 0.3.0-rc.29 +appVersion: "3.6.0-rc.29" dependencies: - name: common diff --git a/support-files/kubernetes/charts/bk-job/values.yaml b/support-files/kubernetes/charts/bk-job/values.yaml index 8e01316cd1..6b2a048825 100644 --- a/support-files/kubernetes/charts/bk-job/values.yaml +++ b/support-files/kubernetes/charts/bk-job/values.yaml @@ -655,7 +655,7 @@ gatewayConfig: image: registry: hub.bktencent.com repository: blueking/job-gateway - tag: 3.6.0-rc.25 + tag: 3.6.0-rc.29 pullPolicy: IfNotPresent pullSecrets: [] replicaCount: 1 @@ -743,7 +743,7 @@ manageConfig: image: registry: hub.bktencent.com repository: blueking/job-manage - tag: 3.6.0-rc.25 + tag: 3.6.0-rc.29 pullPolicy: IfNotPresent pullSecrets: [] replicaCount: 1 @@ -801,7 +801,7 @@ executeConfig: image: registry: hub.bktencent.com repository: blueking/job-execute - tag: 3.6.0-rc.25 + tag: 3.6.0-rc.29 pullPolicy: IfNotPresent pullSecrets: [] replicaCount: 1 @@ -852,7 +852,7 @@ crontabConfig: image: registry: hub.bktencent.com repository: blueking/job-crontab - tag: 3.6.0-rc.25 + tag: 3.6.0-rc.29 pullPolicy: IfNotPresent pullSecrets: [] replicaCount: 1 @@ -912,7 +912,7 @@ logsvrConfig: image: registry: hub.bktencent.com repository: blueking/job-logsvr - tag: 3.6.0-rc.25 + tag: 3.6.0-rc.29 pullPolicy: IfNotPresent pullSecrets: [] replicaCount: 1 @@ -967,7 +967,7 @@ backupConfig: image: registry: hub.bktencent.com repository: blueking/job-backup - tag: 3.6.0-rc.25 + tag: 3.6.0-rc.29 pullPolicy: IfNotPresent pullSecrets: [] replicaCount: 1 @@ -1017,7 +1017,7 @@ analysisConfig: image: registry: hub.bktencent.com repository: blueking/job-analysis - tag: 3.6.0-rc.25 + tag: 3.6.0-rc.29 pullPolicy: IfNotPresent pullSecrets: [] replicaCount: 1 @@ -1067,7 +1067,7 @@ fileGatewayConfig: image: registry: hub.bktencent.com repository: blueking/job-file-gateway - tag: 3.6.0-rc.25 + tag: 3.6.0-rc.29 pullPolicy: IfNotPresent pullSecrets: [] replicaCount: 1 @@ -1117,7 +1117,7 @@ fileWorkerConfig: image: registry: hub.bktencent.com repository: blueking/job-file-worker - tag: 3.6.0-rc.25 + tag: 3.6.0-rc.29 pullPolicy: IfNotPresent pullSecrets: [] replicaCount: 1 @@ -1190,7 +1190,7 @@ frontendConfig: image: registry: hub.bktencent.com repository: blueking/job-frontend - tag: 3.6.0-rc.25 + tag: 3.6.0-rc.29 pullPolicy: IfNotPresent pullSecrets: [] replicaCount: 1 @@ -1251,7 +1251,7 @@ migration: # 镜像拉取仓库组织与镜像名称 repository: "blueking/job-migration" # 镜像标签 - tag: 3.6.0-rc.25 + tag: 3.6.0-rc.29 # 镜像拉取策略 pullPolicy: IfNotPresent