Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: 全局设置消息预览在发送失败的情况下仍提示发送成功 #1225 #1257

Merged
merged 7 commits into from
Sep 7, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,11 @@
1211002=CMDB API返回数据异常
1211003=根据动态分组ID查找主机失败,动态分组ID:{0},原因:{1},请确认指定的动态分组在业务下是否存在
1211004=根据业务ID查找动态分组失败,业务ID:{0},原因:{1},请确认指定的业务是否存在动态分组
1213001=PAAS 服务不可用
1213002=PAAS API返回数据异常
1213001=CMSI接口访问异常
1213002=用户管理接口访问异常
1213003=调用CMSI接口获取通知渠道数据异常
1213004=调用CMSI接口发送通知失败,错误码:{0},错误信息:{1}

1214001=ARTIFACTORY API返回数据异常
1214002=制品库中找不到节点:{0},请到制品库核实

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,11 @@
1211002=CMDB API returned data exception
1211003=Fail to find host by dynamic group, id:{0}, reason:{1}, please confirm the specified dynamic group in business
1211004=Fail to find dynamic group by biz, id:{0}, reason:{1}, please confirm dynamic group in the specified business
1213001=PAAS service is unavailable
1213002=PAAS API returned data exception
1213001=Fail to request CMSI API
1213002=Fail to request UserManage API
1213003=CMSI exception when get notify channels
1213004=CMSI exception when send notify, error_code={0}, error_msg={1}

1214001=ARTIFACTORY API returned data exception
1214002=Cannot find node in bkrepo:{0}, please check in bkrepo

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,11 @@
1211002=CMDB API returned data exception
1211003=Fail to find host by dynamic group, id:{0}, reason:{1}, please confirm the specified dynamic group in business
1211004=Fail to find dynamic group by biz, id:{0}, reason:{1}, please confirm dynamic group in the specified business
1213001=PAAS service is unavailable
1213002=PAAS API returned data exception
1213001=Fail to request CMSI API
1213002=Fail to request UserManage API
1213003=CMSI exception when get notify channels
1213004=CMSI exception when send notify, error_code={0}, error_msg={1}

1214001=ARTIFACTORY API returned data exception
1214002=Cannot find node in bkrepo:{0}, please check in bkrepo

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,11 @@
1211002=CMDB API返回数据异常
1211003=根据动态分组ID查找主机失败,动态分组ID:{0},原因:{1},请确认指定的动态分组在业务下是否存在
1211004=根据业务ID查找动态分组失败,业务ID:{0},原因:{1},请确认指定的业务是否存在动态分组
1213001=PAAS 服务不可用
1213002=PAAS API返回数据异常
1213001=CMSI接口访问异常
1213002=用户管理接口访问异常
1213003=调用CMSI接口获取通知渠道数据异常
1213004=调用CMSI接口发送通知失败,错误码:{0},错误信息:{1}

1214001=ARTIFACTORY API返回数据异常
1214002=制品库中找不到节点:{0},请到制品库核实

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,11 @@
1211002=CMDB API返回数据异常
1211003=根据动态分组ID查找主机失败,动态分组ID:{0},原因:{1},请确认指定的动态分组在业务下是否存在
1211004=根据业务ID查找动态分组失败,业务ID:{0},原因:{1},请确认指定的业务是否存在动态分组
1213001=PAAS 服务不可用
1213002=PAAS API返回数据异常
1213001=CMSI接口访问异常
1213002=用户管理接口访问异常
1213003=调用CMSI接口获取通知渠道数据异常
1213004=调用CMSI接口发送通知失败,错误码:{0},错误信息:{1}

1214001=ARTIFACTORY API返回数据异常
1214002=制品库中找不到节点:{0},请到制品库核实

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,12 +388,16 @@ public class ErrorCode {
public static final int FAIL_TO_FIND_DYNAMIC_GROUP_BY_BIZ = 1211004;

// PaaS异常
// PAAS服务不可达 - 地址配置错误或者地址无法正确解析
public static final int PAAS_UNREACHABLE_SERVER = 1213001;
// paas接口返回数据结构异常-一般是被网关防火墙重定向返回统一登录页面
public static final int PAAS_API_DATA_ERROR = 1213002;
// paas通知渠道接口数据获取异常
public static final int PAAS_MSG_CHANNEL_DATA_ERROR = 1213003;
// CMSI接口访问异常
public static final int CMSI_API_ACCESS_ERROR = 1213001;
// 用户管理接口访问异常
public static final int USER_MANAGE_API_ACCESS_ERROR = 1213002;
// 调用CMSI接口获取通知渠道数据异常
public static final int CMSI_MSG_CHANNEL_DATA_ERROR = 1213003;
// 调用CMSI接口发送通知失败,错误码:{0},错误信息:{1}
public static final int CMSI_FAIL_TO_SEND_MSG = 1213004;

// 制品库异常
// Artifactory接口返回数据结构异常
public static final int ARTIFACTORY_API_DATA_ERROR = 1214001;
// 制品库中找不到节点:{0},请到制品库核实
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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.paas.exception;

import com.tencent.bk.job.common.exception.ServiceException;
import com.tencent.bk.job.common.model.error.ErrorType;

public class PaasException extends ServiceException {

public PaasException(ErrorType errorType, Integer errorCode, Object[] errorParams) {
super(errorType, errorCode, errorParams);
}

public PaasException(Throwable cause, ErrorType errorType, Integer errorCode, Object[] errorParams) {
super(cause, errorType, errorCode, errorParams);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import com.tencent.bk.job.common.exception.InternalException;
import com.tencent.bk.job.common.metrics.CommonMetricNames;
import com.tencent.bk.job.common.model.dto.BkUserDTO;
import com.tencent.bk.job.common.model.error.ErrorType;
import com.tencent.bk.job.common.paas.exception.PaasException;
import com.tencent.bk.job.common.paas.metrics.PaaSMetricTags;
import com.tencent.bk.job.common.paas.model.EsbListUsersResult;
import com.tencent.bk.job.common.paas.model.EsbNotifyChannelDTO;
Expand Down Expand Up @@ -113,7 +115,7 @@ public List<BkUserDTO> getUserList(String fields,
} catch (Exception e) {
String errorMsg = "Get " + API_GET_USER_LIST + " error";
log.error(errorMsg, e);
throw new InternalException(errorMsg, e, ErrorCode.PAAS_API_DATA_ERROR);
throw new InternalException(errorMsg, e, ErrorCode.USER_MANAGE_API_ACCESS_ERROR);
} finally {
HttpMetricUtil.clearHttpMetric();
}
Expand Down Expand Up @@ -170,7 +172,7 @@ public List<EsbNotifyChannelDTO> getNotifyChannelList(String uin) {
}

@Override
public boolean sendMsg(
public void sendMsg(
String msgType,
String sender,
Set<String> receivers,
Expand All @@ -194,14 +196,21 @@ public boolean sendMsg(

if (esbResp.getResult() == null || !esbResp.getResult() || esbResp.getCode() != 0) {
status = checkRespAndGetStatus(uri, esbResp);
return false;
throw new PaasException(
ErrorType.FAILED_PRECONDITION,
ErrorCode.CMSI_FAIL_TO_SEND_MSG,
new Object[]{
esbResp.getCode().toString(),
esbResp.getMessage()
});
}
status = EsbMetricTags.VALUE_STATUS_SUCCESS;
return true;
} catch (PaasException e) {
throw e;
} catch (Exception e) {
log.error("Fail to request {}", uri, e);
status = EsbMetricTags.VALUE_STATUS_ERROR;
return false;
throw new PaasException(e, ErrorType.FAILED_PRECONDITION, ErrorCode.CMSI_API_ACCESS_ERROR, new Object[]{});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个接口调用失败似乎应该是INTERNAL_ERROR,而不是FAILED_PRECONDITION

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修改

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ErrorType不对

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修改

} finally {
HttpMetricUtil.clearHttpMetric();
recordMetrics(start, status, msgType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,5 @@ public interface IPaasClient {
/**
* ESB发通知信息接口
*/
boolean sendMsg(String msgType, String sender, Set<String> receivers, String title, String content)
throws Exception;
void sendMsg(String msgType, String sender, Set<String> receivers, String title, String content);
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public BkUserDTO getUser(String bkToken) {
return userDto.orElse(null);
} catch (ExecutionException e) {
log.warn("Error occur when get user from paas!");
throw new InternalException("Query userinfo from paas fail", e, ErrorCode.PAAS_API_DATA_ERROR);
throw new InternalException("Query userinfo from paas fail", e, ErrorCode.USER_MANAGE_API_ACCESS_ERROR);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ Response<ChannelTemplateDetailWithDefaultVO> getChannelTemplateDetail(
@RequestHeader("username")
String username,
@ApiParam("渠道Code")
@RequestParam(value = "channelCode", required = true)
@RequestParam(value = "channelCode")
String channelCode,
@ApiParam("消息类型Code")
@RequestParam(value = "messageTypeCode", required = true)
@RequestParam(value = "messageTypeCode")
String messageTypeCode
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public ServiceNotificationResourceImpl(NotifyService notifyService) {
@Override
public InternalResponse<Integer> sendNotificationsToUsers(ServiceUserNotificationDTO serviceUserNotificationDTO) {
log.info(String.format("Input:%s", JsonUtils.toJson(serviceUserNotificationDTO)));
return InternalResponse.buildSuccessResp(notifyService.sendNotificationsToUsers(serviceUserNotificationDTO));
return InternalResponse.buildSuccessResp(notifyService.asyncSendNotificationsToUsers(serviceUserNotificationDTO));
}

@Override
Expand All @@ -67,7 +67,7 @@ public InternalResponse<Integer> sendNotificationsToAdministrators(
) {
log.info(String.format("Input:%s", JsonUtils.toJson(serviceNotificationMessage)));
return InternalResponse.buildSuccessResp(
notifyService.sendNotificationsToAdministrators(serviceNotificationMessage)
notifyService.asyncSendNotificationsToAdministrators(serviceNotificationMessage)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
@Slf4j
public class WebGlobalSettingsResourceImpl implements WebGlobalSettingsResource {

private GlobalSettingsService globalSettingsService;
private final GlobalSettingsService globalSettingsService;

@Autowired
public WebGlobalSettingsResourceImpl(GlobalSettingsService globalSettingsService) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public List<NotifyEsbChannelDTO> listNotifyEsbChannel(DSLContext dslContext) {
} catch (ExecutionException e) {
String errorMsg = "Fail to load EsbChannel from cache";
logger.error(errorMsg, e);
throw new InternalException(errorMsg, e, ErrorCode.PAAS_MSG_CHANNEL_DATA_ERROR);
throw new InternalException(errorMsg, e, ErrorCode.CMSI_MSG_CHANNEL_DATA_ERROR);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ Set<String> findUserByResourceRoles(Long appId, String triggerUser, Integer reso

PageTemplateVO getPageTemplate(String username);

Integer sendNotificationsToUsers(ServiceUserNotificationDTO serviceUserNotificationDTO);
Integer asyncSendNotificationsToUsers(ServiceUserNotificationDTO serviceUserNotificationDTO);

Integer sendNotificationsToUsersByChannel(ServiceUserNotificationDTO serviceUserNotificationDTO,
List<String> channelTypeList);
Integer asyncSendNotificationsByChannel(ServiceUserNotificationDTO serviceUserNotificationDTO,
List<String> channelTypeList);

Integer sendNotificationsToAdministrators(ServiceNotificationMessage serviceNotificationMessage);
Integer asyncSendNotificationsToAdministrators(ServiceNotificationMessage serviceNotificationMessage);

Integer sendTemplateNotification(ServiceTemplateNotificationDTO templateNotificationDTO);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ public interface PaaSService {

List<EsbNotifyChannelDTO> getAllChannelList(String bkToken, String uin) throws IOException;

boolean sendMsg(
void sendMsg(
String msgType,
String sender,
Set<String> receivers,
String title,
String content
) throws Exception;
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@
import com.tencent.bk.job.manage.model.dto.notify.AvailableEsbChannelDTO;
import com.tencent.bk.job.manage.model.dto.notify.NotifyEsbChannelDTO;
import com.tencent.bk.job.manage.model.dto.notify.NotifyTemplateDTO;
import com.tencent.bk.job.manage.model.inner.ServiceNotificationMessage;
import com.tencent.bk.job.manage.model.inner.ServiceUserNotificationDTO;
import com.tencent.bk.job.manage.model.web.request.globalsetting.AccountNameRule;
import com.tencent.bk.job.manage.model.web.request.globalsetting.AccountNameRulesReq;
import com.tencent.bk.job.manage.model.web.request.globalsetting.FileUploadSettingReq;
Expand All @@ -80,6 +78,7 @@
import com.tencent.bk.job.manage.model.web.vo.notify.UserVO;
import com.tencent.bk.job.manage.service.GlobalSettingsService;
import com.tencent.bk.job.manage.service.NotifyService;
import com.tencent.bk.job.manage.service.impl.notify.NotifySendService;
import com.tencent.bk.job.manage.service.impl.notify.NotifyUserService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
Expand All @@ -94,7 +93,6 @@
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand All @@ -121,6 +119,7 @@ public class GlobalSettingsServiceImpl implements GlobalSettingsService {
private final NotifyEsbChannelDAO notifyEsbChannelDAO;
private final AvailableEsbChannelDAO availableEsbChannelDAO;
private final NotifyService notifyService;
private final NotifySendService notifySendService;
private final NotifyUserService notifyUserService;
private final GlobalSettingDAO globalSettingDAO;
private final NotifyTemplateDAO notifyTemplateDAO;
Expand All @@ -140,7 +139,8 @@ public GlobalSettingsServiceImpl(
, NotifyEsbChannelDAO notifyEsbChannelDAO
, AvailableEsbChannelDAO availableEsbChannelDAO
, NotifyService notifyService
, NotifyUserService notifyUserService,
, NotifySendService notifySendService,
NotifyUserService notifyUserService,
GlobalSettingDAO globalSettingDAO
, NotifyTemplateDAO notifyTemplateDAO,
MessageI18nService i18nService,
Expand All @@ -152,6 +152,7 @@ public GlobalSettingsServiceImpl(
this.notifyEsbChannelDAO = notifyEsbChannelDAO;
this.availableEsbChannelDAO = availableEsbChannelDAO;
this.notifyService = notifyService;
this.notifySendService = notifySendService;
this.notifyUserService = notifyUserService;
this.globalSettingDAO = globalSettingDAO;
this.notifyTemplateDAO = notifyTemplateDAO;
Expand Down Expand Up @@ -632,12 +633,15 @@ public Integer saveChannelTemplate(String username, ChannelTemplateReq req) {
public Integer sendChannelTemplate(String username, ChannelTemplatePreviewReq req) {
List<String> receiverList = StringUtil.strToList(req.getReceiverStr(), String.class,
NotifyConsts.SEPERATOR_COMMA);
return notifyService.sendNotificationsToUsersByChannel(
new ServiceUserNotificationDTO(
new HashSet<>(receiverList),
new ServiceNotificationMessage(
req.getTitle(), req.getContent())),
Collections.singletonList(req.getChannelCode()));
Set<String> receiverSet = new HashSet<>(receiverList);
notifySendService.sendUserChannelNotify(
null,
receiverSet,
req.getChannelCode(),
req.getTitle(),
req.getContent()
);
return receiverSet.size();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@ public List<EsbNotifyChannelDTO> getAllChannelList(String bkToken, String uin) {

@Override
@EsbApiTimed
public boolean sendMsg(
public void sendMsg(
String msgType,
String sender,
Set<String> receivers,
String title,
String content
) throws Exception {
) {
IPaasClient paasClient = getClientWithCurrentLang();
return paasClient.sendMsg(msgType, sender, receivers, title, content);
paasClient.sendMsg(msgType, sender, receivers, title, content);
}
}
Loading