Skip to content

Commit

Permalink
Merge pull request TencentBlueKing#1720 from jsonwan/3.6.x
Browse files Browse the repository at this point in the history
Merge: 3.5.x上面的改动cherry-pick到3.6.x
  • Loading branch information
jsonwan authored Feb 3, 2023
2 parents c230738 + 3b0a481 commit abbe8cc
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@

package com.tencent.bk.job.common.cc.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.tencent.bk.job.common.util.ip.IpUtils;
import lombok.Data;

import java.util.List;
Expand All @@ -44,9 +46,15 @@ public class CcGroupHostPropDTO {
@JsonProperty("bk_host_name")
private String name;

// 可能为多IP
@JsonProperty("bk_host_innerip")
private String ip;
private String innerIp;

@JsonProperty("bk_cloud_id")
private List<CcCloudIdDTO> cloudIdList;

@JsonIgnore
public String getFirstIp() {
return IpUtils.getFirstIpFromMultiIp(innerIp, ",");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@

package com.tencent.bk.job.common.cc.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.tencent.bk.job.common.util.ip.IpUtils;
import lombok.Getter;
import lombok.Setter;

Expand All @@ -37,11 +39,16 @@ public class CcHostInfoDTO {
@JsonProperty("bk_host_id")
private Long hostId;
@JsonProperty("bk_host_innerip")
private String ip;
private String innerIp;
@JsonProperty("bk_host_name")
private String hostName;
@JsonProperty("bk_os_name")
private String os;
@JsonProperty("bk_cloud_id")
private Long cloudId;

@JsonIgnore
public String getFirstIp() {
return IpUtils.getFirstIpFromMultiIp(innerIp, ",");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ private ApplicationHostDTO convertHost(long bizId, CcHostInfoDTO hostInfo) {
ApplicationHostDTO ipInfo = new ApplicationHostDTO();
ipInfo.setHostId(hostInfo.getHostId());
// 部分从cmdb同步过来的资源没有ip,需要过滤掉
if (StringUtils.isBlank(hostInfo.getIp())) {
if (StringUtils.isBlank(hostInfo.getInnerIp())) {
return null;
}

Expand All @@ -709,10 +709,12 @@ private ApplicationHostDTO convertHost(long bizId, CcHostInfoDTO hostInfo) {
return null;
}

ipInfo.setDisplayIp(hostInfo.getInnerIp());

if (queryAgentStatusClient != null) {
ipInfo.setIp(queryAgentStatusClient.getHostIpByAgentStatus(hostInfo.getIp(), hostInfo.getCloudId()));
ipInfo.setIp(queryAgentStatusClient.getHostIpByAgentStatus(hostInfo.getInnerIp(), hostInfo.getCloudId()));
} else {
ipInfo.setIp(hostInfo.getIp());
ipInfo.setIp(hostInfo.getFirstIp());
}
ipInfo.setBizId(bizId);
ipInfo.setIpDesc(hostInfo.getHostName());
Expand Down Expand Up @@ -832,13 +834,13 @@ private List<CcGroupHostPropDTO> convertToCcGroupHostPropList(List<CcHostInfoDTO
log.warn(
"host(id={},ip={}) does not have cloud area, ignore",
ccHostInfo.getHostId(),
ccHostInfo.getIp()
ccHostInfo.getInnerIp()
);
} else if (StringUtils.isBlank(ccHostInfo.getIp())) {
} else if (StringUtils.isBlank(ccHostInfo.getInnerIp())) {
log.warn(
"host(id={},ip={}) ip invalid, ignore",
ccHostInfo.getHostId(),
ccHostInfo.getIp()
ccHostInfo.getInnerIp()
);
} else {
ccGroupHostList.add(convertToCcHost(ccHostInfo));
Expand Down Expand Up @@ -892,7 +894,7 @@ private CcGroupHostPropDTO convertToCcHost(CcHostInfoDTO ccHostInfo) {
CcGroupHostPropDTO ccGroupHostPropDTO = new CcGroupHostPropDTO();
ccGroupHostPropDTO.setId(ccHostInfo.getHostId());
ccGroupHostPropDTO.setName(ccHostInfo.getHostName());
ccGroupHostPropDTO.setIp(ccHostInfo.getIp());
ccGroupHostPropDTO.setInnerIp(ccHostInfo.getInnerIp());
CcCloudIdDTO ccCloudIdDTO = new CcCloudIdDTO();
// 仅使用CloudId其余属性未用到,暂不设置
ccCloudIdDTO.setInstanceId(ccHostInfo.getCloudId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,4 +248,21 @@ public static String getFirstMachineIP() {
}
return ip;
}

/**
* 从含有多个IP的字符串中获取首个IP,若multiIp不含有任何IP则直接返回multiIp本身
*
* @param multiIp 多IP字符串
* @param separator 分隔符
* @return 首个IP
*/
public static String getFirstIpFromMultiIp(String multiIp, String separator) {
if (StringUtils.isBlank(multiIp)) {
return multiIp;
}
if (multiIp.contains(separator)) {
return multiIp.split(separator)[0];
}
return multiIp;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,13 @@ void testLongStr2Ip() {
String ip = IpUtils.revertIpFromLongStr(ipLongStr);
assertThat(ip).isEqualTo("127.0.0.1");
}

@Test
void testGetFirstIpFromMultiIp() {
assertThat(IpUtils.getFirstIpFromMultiIp(null, ",")).isNull();
assertThat(IpUtils.getFirstIpFromMultiIp("", ",")).isEqualTo("");
assertThat(IpUtils.getFirstIpFromMultiIp("192.168.1.1", ",")).isEqualTo("192.168.1.1");
assertThat(IpUtils.getFirstIpFromMultiIp("192.168.1.1,", ",")).isEqualTo("192.168.1.1");
assertThat(IpUtils.getFirstIpFromMultiIp("192.168.1.1,192.168.1.2", ",")).isEqualTo("192.168.1.1");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -211,16 +211,16 @@ public List<HostDTO> getIpByDynamicGroupId(long appId, String groupId) {
List<CcCloudIdDTO> hostCloudIdList = hostProp.getCloudIdList();
if (hostCloudIdList == null || hostCloudIdList.isEmpty()) {
log.warn("Get ip by dynamic group id, cmdb return illegal host, skip it!appId={}, groupId={}, " +
"hostIp={}", appId, groupId, hostProp.getIp());
"hostIp={}", appId, groupId, hostProp.getInnerIp());
continue;
}
CcCloudIdDTO hostCloudId = hostCloudIdList.get(0);
if (hostCloudId == null) {
log.warn("Get ip by dynamic group id, cmdb return illegal host, skip it!appId={}, groupId={}, " +
"hostIp={}", appId, groupId, hostProp.getIp());
"hostIp={}", appId, groupId, hostProp.getInnerIp());
continue;
}
HostDTO ip = new HostDTO(hostCloudId.getInstanceId(), hostProp.getIp());
HostDTO ip = new HostDTO(hostCloudId.getInstanceId(), hostProp.getFirstIp());
ips.add(ip);
}
log.info("Get hosts by groupId, appId={}, groupId={}, hosts={}", appId, groupId, ips);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ public class JobManageConfig {
@Value("${job.web.url:}")
private String jobWebUrl;

@Value("${bk.helper.url:}")
private String bkHelperUrl;

@Value("${bk.doc.root:}")
private String bkDocRoot;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ public List<DynamicGroupWithHost> getBizDynamicGroupHostList(String username,
List<String> cloudIpList = new ArrayList<>();
for (CcGroupHostPropDTO groupHost : ccGroupHostProps) {
if (CollectionUtils.isNotEmpty(groupHost.getCloudIdList())) {
cloudIpList.add(groupHost.getCloudIdList().get(0).getInstanceId() + ":" + groupHost.getIp());
cloudIpList.add(groupHost.getCloudIdList().get(0).getInstanceId() + ":" + groupHost.getFirstIp());
} else {
log.warn("Wrong host info! No cloud area!|{}", groupHost);
}
Expand Down
9 changes: 9 additions & 0 deletions support-files/kubernetes/charts/bk-job/VALUES_LOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@ fileWorkerConfig:
port: 19810
```

## 0.2.2-rc.7
1.增加文档中心与问题反馈URL配置项
```shell script
# 文档中心 url
bkDocsCenterUrl: "https://bk.tencent.com/docs"
# 问题反馈 url
bkFeedBackUrl: "https://bk.tencent.com/s-mart/community"
```

## 0.2.2-rc.1
1.增加权限中心系统ID配置:
```shell script
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,9 @@ data:
max-request-size: 5GB
bk:
doc:
root:
root: {{ .Values.bkDocsCenterUrl }}
feedback:
root:
helper:
url:
root: {{ .Values.bkFeedBackUrl }}
job:
manage:
sync:
Expand Down
4 changes: 4 additions & 0 deletions support-files/kubernetes/charts/bk-job/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,10 @@ bkIamApiUrl: "http://bkiam-api.example.com"
bkRepoUrl: "http://bkrepo.example.com"
# 节点管理 url
bkNodemanUrl: "http://nodeman.example.com"
# 文档中心 url
bkDocsCenterUrl: "https://bk.tencent.com/docs"
# 问题反馈 url
bkFeedBackUrl: "https://bk.tencent.com/s-mart/community"

## 蓝鲸GSE参数配置
gse:
Expand Down
3 changes: 0 additions & 3 deletions support-files/templates/#etc#job#job-manage#job-manage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ bk:
feedback:
# 首页右上角问题反馈链接
root:
helper:
# 首页底部联系BK助手的跳转URL(可为企业微信URL)
url: wxwork://message?uin=8444252571319680
job:
manage:
sync:
Expand Down

0 comments on commit abbe8cc

Please sign in to comment.