|
|
@@ -75,64 +75,65 @@ public class BeringServiceImpl extends ServiceImpl<HostInfoDao, HostInfo> imple
|
|
|
|
|
|
//1.先判断请求参数是否合法
|
|
|
if(tokenVo == null){
|
|
|
- logger.error("主机获取令牌失败:参数不能为空!");
|
|
|
+ logger.error("主机获取令牌失败:传入参数为空!");
|
|
|
throw new ServerException("主机获取令牌失败:参数不能为空!");
|
|
|
}
|
|
|
-
|
|
|
+ logger.info("主机获取令牌start:{}",JSON.toJSONString(tokenVo));
|
|
|
if(StringUtils.isEmpty(tokenVo.getClient_id())){
|
|
|
- logger.error("主机获取令牌失败:主机ID不能为空!");
|
|
|
+ logger.error("主机获取令牌失败:传入client_id为空!");
|
|
|
throw new ServerException("主机获取令牌失败:主机ID不能为空!");
|
|
|
}
|
|
|
|
|
|
MachineInfo machineInfo = tokenVo.getMachineInfo();
|
|
|
if(machineInfo == null){
|
|
|
- logger.error("主机获取令牌失败:计算机信息不能为空!");
|
|
|
+ logger.error("主机获取令牌失败:传入machineInfo为空!");
|
|
|
throw new ServerException("主机获取令牌失败:计算机信息不能为空!");
|
|
|
}
|
|
|
|
|
|
if(StringUtils.isEmpty(tokenVo.getGrant_type())){
|
|
|
- logger.error("主机获取令牌失败:认证类型不能为空!");
|
|
|
+ logger.error("主机获取令牌失败:传入grant_type为空!");
|
|
|
throw new ServerException("主机获取令牌失败:认证类型不能为空!");
|
|
|
}
|
|
|
if(!tokenVo.getGrant_type().equals("client_credentials")){
|
|
|
- logger.error("主机获取令牌失败:请求参数认证类型错误!");
|
|
|
+ logger.error("主机获取令牌失败:传入grant_type类型错误(值应为client_credentials)!");
|
|
|
throw new ServerException("主机获取令牌失败:请求参数认证类型错误!");
|
|
|
}
|
|
|
|
|
|
//验证秘钥是否合法
|
|
|
List<String> macs = machineInfo.getMacs();
|
|
|
if (null == macs || macs.size() <= 0){
|
|
|
- logger.error("主机获取令牌失败:计算机macs信息不能为空!");
|
|
|
+ logger.error("主机获取令牌失败:传入machineInfo内macs数组为空!");
|
|
|
throw new ServerException("主机获取令牌失败:计算机macs信息不能为空!");
|
|
|
}
|
|
|
|
|
|
Collections.sort(macs);
|
|
|
- String macss = StringUtils.join(macs.toArray(), "");
|
|
|
-
|
|
|
- String str = macss + "zmoon";
|
|
|
+ String macsStr = StringUtils.join(macs.toArray(), "");
|
|
|
+ String str = macsStr + "zmoon";
|
|
|
|
|
|
//md5加密--->按照生成规则生成后的秘钥
|
|
|
String code = DigestUtils.md5DigestAsHex(str.getBytes());
|
|
|
- if(!code.equals(tokenVo.getClient_secret())){
|
|
|
- logger.error("主机获取令牌失败:主机秘钥认证失败!");
|
|
|
+ String clientSecret = tokenVo.getClient_secret();
|
|
|
+ if(!code.equals(clientSecret)){
|
|
|
+ logger.error("主机获取令牌失败:client_secret={}与machineInfo内macs数组解析算法不一致!",clientSecret);
|
|
|
throw new ServerException("主机获取令牌失败:主机秘钥认证失败!");
|
|
|
}
|
|
|
|
|
|
//2.验证该秘钥是否在数据库中已经存在
|
|
|
TokenCache tokenCache = null;
|
|
|
- String result = redisTemplateUtil.get(RedisPrefix.CACHE_TOKENS + ":" + tokenVo.getClient_secret());
|
|
|
+ String result = redisTemplateUtil.get(RedisPrefix.CACHE_TOKENS + ":" + clientSecret);
|
|
|
if (StringUtils.isNotBlank(result)){
|
|
|
tokenCache = JSON.parseObject(result, TokenCache.class);
|
|
|
}
|
|
|
|
|
|
|
|
|
- HostInfo hostInfo = baseMapper.selectById(tokenVo.getClient_secret());
|
|
|
+ HostInfo hostInfo = baseMapper.selectById(clientSecret);
|
|
|
//秘钥验证成功且数据库无该秘钥,判断为数据库丢失数据,需要重新注册
|
|
|
if (hostInfo == null){
|
|
|
+ logger.info("主机获取令牌:表hostInfo中不存在id={}主机(数据库注册数据丢失)",clientSecret);
|
|
|
//判断是否允许重新注册
|
|
|
SysConf sysConf = sysConfDao.getByCode("register_again");
|
|
|
if ("1".equals(sysConf.getValue())){
|
|
|
- logger.info("数据库注册数据丢失,程序允许主机重新注册!\n"+ JSON.toJSONString(machineInfo));
|
|
|
+ logger.info("主机获取令牌:程序允许主机重新注册,开始注册\n{}",clientSecret,JSON.toJSONString(machineInfo));
|
|
|
hostInfo = new HostInfo();
|
|
|
hostInfo.setId(code);
|
|
|
hostInfo.setHostName(machineInfo.getMachineName());
|
|
|
@@ -156,7 +157,7 @@ public class BeringServiceImpl extends ServiceImpl<HostInfoDao, HostInfo> imple
|
|
|
tc.setClientSecret(hostInfo.getId());
|
|
|
redisTemplateUtil.set(RedisPrefix.CACHE_TOKENS + ":" +hostInfo.getId(),tc,2 * 60 * 60);
|
|
|
}else {
|
|
|
- logger.error("数据库注册数据丢失,程序不允许主机重新注册!\n"+ JSON.toJSONString(machineInfo));
|
|
|
+ logger.info("主机获取令牌:程序不允许主机重新注册,放弃注册\n{}",JSON.toJSONString(machineInfo));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -188,9 +189,10 @@ public class BeringServiceImpl extends ServiceImpl<HostInfoDao, HostInfo> imple
|
|
|
hostInfo.setExpiresIn(7200);
|
|
|
hostInfo.setAccessToken(newMd5);
|
|
|
hostInfo.setHostName(tokenVo.getMachineInfo().getMachineName());
|
|
|
- logger.info("token不为空,时效超时,请求里面的ip 为:"+tokenVo.getMachineInfo().getIpAddresses().toString());
|
|
|
hostInfo.setHostIp(tokenVo.getMachineInfo().getIpAddresses().toString());
|
|
|
baseMapper.updateById(hostInfo);
|
|
|
+
|
|
|
+ logger.info("主机获取令牌:主机ip={},缓存token时效已过,删除缓存并重新设置",tokenVo.getMachineInfo().getIpAddresses().toString());
|
|
|
}
|
|
|
}else{
|
|
|
//生成新的令牌 更新数据库与缓存
|
|
|
@@ -201,7 +203,6 @@ public class BeringServiceImpl extends ServiceImpl<HostInfoDao, HostInfo> imple
|
|
|
hostInfo.setScope("* identity");
|
|
|
hostInfo.setTokenType("Bearer");
|
|
|
hostInfo.setTokenCreateTime(System.currentTimeMillis());
|
|
|
- logger.info("token为空,请求里面的ip 为:"+tokenVo.getMachineInfo().getIpAddresses().toString());
|
|
|
hostInfo.setHostName(tokenVo.getMachineInfo().getMachineName());
|
|
|
hostInfo.setHostIp(tokenVo.getMachineInfo().getIpAddresses().toString());
|
|
|
baseMapper.updateById(hostInfo);
|
|
|
@@ -215,7 +216,11 @@ public class BeringServiceImpl extends ServiceImpl<HostInfoDao, HostInfo> imple
|
|
|
|
|
|
redisTemplateUtil.set(RedisPrefix.CACHE_TOKENS + ":" + tokenVo.getClient_id(),tc,2 * 60 * 60);
|
|
|
redisTemplateUtil.set(RedisPrefix.CACHE_TOKEN_TIMES + ":" + md5Token,tc,2 * 60 * 60);
|
|
|
+
|
|
|
+ logger.info("主机获取令牌:主机ip={},缓存token为空,开始设置缓存",tokenVo.getMachineInfo().getIpAddresses().toString());
|
|
|
}
|
|
|
+
|
|
|
+ logger.info("主机获取令牌:client_secret={}获取成功",clientSecret);
|
|
|
return hostInfo;
|
|
|
}
|
|
|
|
|
|
@@ -223,33 +228,33 @@ public class BeringServiceImpl extends ServiceImpl<HostInfoDao, HostInfo> imple
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public HeartResponse heartBeat(String authorization, HeartBeat heartBeat) throws Exception {
|
|
|
|
|
|
- logger.info("心跳携带令牌:{}", authorization);
|
|
|
+ logger.info("主机节点心跳:Authorization={}", authorization);
|
|
|
HeartResponse response = new HeartResponse();
|
|
|
//参数严重
|
|
|
String time = heartBeat.getTime();
|
|
|
if(StringUtils.isBlank(time)){
|
|
|
- logger.error("白令海节点计算机的UTC时间不能为空!");
|
|
|
+ logger.error("主机节点心跳:传入time为空");
|
|
|
throw new RuntimeException("白令海节点计算机的UTC时间不能为空!");
|
|
|
}
|
|
|
|
|
|
String version = heartBeat.getVersion();
|
|
|
if(StringUtils.isBlank(version)){
|
|
|
- logger.error("白令海自身版本号不能为空!");
|
|
|
+ logger.error("主机节点心跳:传入version为空");
|
|
|
throw new RuntimeException("白令海自身版本号不能为空!");
|
|
|
}
|
|
|
|
|
|
Boolean allowPrerelsease = heartBeat.getAllowPrerelease();
|
|
|
if(allowPrerelsease == null){
|
|
|
- logger.error("白令海允许升级到预发布版本不能为空!");
|
|
|
+ logger.error("主机节点心跳:传入allowPrerelease为空");
|
|
|
throw new RuntimeException("白令海允许升级到预发布版本不能为空!");
|
|
|
|
|
|
}
|
|
|
|
|
|
-// String description = heartBeat.getDescription();
|
|
|
-// if(StringUtils.isBlank(description)){
|
|
|
-// logger.error("白令海节点描述不能为空!");
|
|
|
-// throw new RuntimeException("白令海节点描述不能为空!");
|
|
|
-// }
|
|
|
+ String description = heartBeat.getDescription();
|
|
|
+ if(description == null){
|
|
|
+ logger.error("主机节点心跳:传入description为null");
|
|
|
+ throw new RuntimeException("白令海节点描述不能为空!");
|
|
|
+ }
|
|
|
|
|
|
//根据token获取主机信息
|
|
|
TokenCache tokenCache = null;
|
|
|
@@ -259,7 +264,7 @@ public class BeringServiceImpl extends ServiceImpl<HostInfoDao, HostInfo> imple
|
|
|
}
|
|
|
|
|
|
if(tokenCache == null){
|
|
|
- logger.error(authorization + "令牌不合法!");
|
|
|
+ logger.error("主机节点心跳:Authorization={}匹配缓存失败!",authorization);
|
|
|
throw new RuntimeException(authorization + "令牌不合法!");
|
|
|
}
|
|
|
|
|
|
@@ -268,49 +273,44 @@ public class BeringServiceImpl extends ServiceImpl<HostInfoDao, HostInfo> imple
|
|
|
|
|
|
HostInfo hostInfo = hostInfoDao.selectById(clientId);
|
|
|
if (null == hostInfo){
|
|
|
- logger.error("主机{}在数据库不存在", clientId);
|
|
|
+ logger.error("主机节点心跳:主机id={}在表hostInfo中不存在", clientId);
|
|
|
+ throw new RuntimeException(authorization + "令牌不合法!");
|
|
|
}
|
|
|
- logger.info("主机{},心跳获取参数:{}", hostInfo.getId(), JSON.toJSONString(heartBeat));
|
|
|
+ logger.info("主机节点心跳:主机id={},传入参数:{}", clientId, JSON.toJSONString(heartBeat));
|
|
|
//查询hostZipInfo信息是否存在,如果不存在,按照默认新建
|
|
|
+ String hostId = hostInfo.getId();
|
|
|
QueryWrapper<HostZipInfo> qw = new QueryWrapper<>();
|
|
|
- qw.eq("host_id",hostInfo.getId());
|
|
|
-
|
|
|
+ qw.eq("host_id",hostId);
|
|
|
HostZipInfo hostZipInfo = hostZipInfoDao.selectOne(qw);
|
|
|
- if(hostZipInfo == null){
|
|
|
- String orgId = upgradeBatchInfoDao.getOrgId(hostInfo.getId());
|
|
|
+ String orgId = upgradeBatchInfoDao.getOrgId(hostId);
|
|
|
|
|
|
- if(StringUtils.isNotEmpty(orgId) || "YCAF".equals(hostInfo.getHostName())){
|
|
|
+ if(hostZipInfo == null){
|
|
|
+ if(StringUtils.isNotEmpty(orgId)){
|
|
|
OrgVo org = orgVoDao.getByOrgId(orgId);
|
|
|
- if(org == null && !"YCAF".equals(hostInfo.getHostName())){
|
|
|
+ if(org == null){
|
|
|
+ logger.error("主机节点心跳:主机id={}的机构orgId={}在表sysOrg中不存在(hostZipInfo无记录)",clientId,orgId);
|
|
|
throw new RuntimeException("心跳异常:组织机构不存在,该机器组织机构id"+orgId);
|
|
|
}
|
|
|
hostZipInfo = new HostZipInfo();
|
|
|
hostZipInfo.setStatus(1);
|
|
|
hostZipInfo.setZipVersion(defaultVersion);
|
|
|
hostZipInfo.setTargetVersion(defaultVersion);
|
|
|
- hostZipInfo.setHostId(hostInfo.getId());
|
|
|
-
|
|
|
+ hostZipInfo.setHostId(hostId);
|
|
|
hostZipInfo.setHostIp(hostInfo.getHostIp());
|
|
|
- if (org != null){
|
|
|
- hostZipInfo.setOrgId(org.getOrgId()+"");
|
|
|
- hostZipInfo.setOrgName(org.getOrgName());
|
|
|
- }else {
|
|
|
- hostZipInfo.setOrgId(null);
|
|
|
- hostZipInfo.setOrgName(null);
|
|
|
- }
|
|
|
+ hostZipInfo.setOrgId(orgId);
|
|
|
+ hostZipInfo.setOrgName(org.getOrgName());
|
|
|
hostZipInfo.setHostName(hostInfo.getHostName());
|
|
|
|
|
|
-
|
|
|
hostZipInfoDao.insert(hostZipInfo);
|
|
|
}
|
|
|
}else{
|
|
|
hostZipInfo.setHostName(hostInfo.getHostName());
|
|
|
hostZipInfo.setHostIp(hostInfo.getHostIp());
|
|
|
- hostZipInfo.setHostId(hostInfo.getId());
|
|
|
- String orgId = upgradeBatchInfoDao.getOrgId(hostInfo.getId());
|
|
|
+ hostZipInfo.setHostId(hostId);
|
|
|
if(StringUtils.isNotEmpty(orgId)){
|
|
|
OrgVo org = orgVoDao.getByOrgId(orgId);
|
|
|
if(org == null){
|
|
|
+ logger.error("主机节点心跳:主机id={}的机构orgId={}在表sysOrg中不存在(hostZipInfo有记录)",clientId,orgId);
|
|
|
throw new RuntimeException("心跳异常:组织机构不存在,该机器组织机构id"+orgId);
|
|
|
}
|
|
|
hostZipInfo.setOrgId(orgId);
|
|
|
@@ -320,23 +320,19 @@ public class BeringServiceImpl extends ServiceImpl<HostInfoDao, HostInfo> imple
|
|
|
}
|
|
|
|
|
|
//获取到心跳信息,获取缓存中是否有心跳信息。
|
|
|
- HeartTimeVo heartTimeVo = null;
|
|
|
+ HeartTimeVo heartTimeVo;
|
|
|
+ long now = System.currentTimeMillis();
|
|
|
String heartResult = redisTemplateUtil.get(RedisPrefix.CACHE_HEARTS + ":" + clientId);
|
|
|
- if (org.apache.commons.lang3.StringUtils.isNotBlank(heartResult)){
|
|
|
- heartTimeVo = JSON.parseObject(heartResult, HeartTimeVo.class);
|
|
|
- }
|
|
|
- if(heartTimeVo == null){
|
|
|
+ if(StringUtils.isBlank(heartResult)){
|
|
|
//缓存中不存在该token信息,缓存中添加心跳信息
|
|
|
heartTimeVo = new HeartTimeVo();
|
|
|
-
|
|
|
heartTimeVo.setClientId(tokenCache.getClientId());
|
|
|
- heartTimeVo.setHeartTime(System.currentTimeMillis());
|
|
|
- logger.info("第一次心跳向心跳缓存中添加信息:key:{},value:{}",clientId,JSON.toJSONString(heartTimeVo));
|
|
|
- //缓存中添加
|
|
|
+ heartTimeVo.setHeartTime(now);
|
|
|
redisTemplateUtil.set(RedisPrefix.CACHE_HEARTS + ":" + clientId,heartTimeVo,2 * 60 * 60);
|
|
|
+ logger.info("主机节点心跳:新增心跳缓存,key={},value={}",clientId,JSON.toJSONString(heartTimeVo));
|
|
|
}else{
|
|
|
+ heartTimeVo = JSON.parseObject(heartResult, HeartTimeVo.class);
|
|
|
//存在该心跳,1.更新心态缓存
|
|
|
- long now = System.currentTimeMillis();
|
|
|
heartTimeVo.setHeartTime(now);
|
|
|
if(hostInfo.getHostStatus() == 2){
|
|
|
//如果是离线状态,改为在线状态
|
|
|
@@ -345,19 +341,20 @@ public class BeringServiceImpl extends ServiceImpl<HostInfoDao, HostInfo> imple
|
|
|
heartTimeVo.setHostStatus(1);
|
|
|
}
|
|
|
redisTemplateUtil.set(RedisPrefix.CACHE_HEARTS + ":" + clientId,heartTimeVo,2 * 60 * 60);
|
|
|
+ logger.info("主机节点心跳:更新心跳缓存,key={},value={}",clientId,JSON.toJSONString(heartTimeVo));
|
|
|
}
|
|
|
|
|
|
//调用是否生成任务清单判断,线程池开启线程
|
|
|
frontTaskService.validateAppInfoList(clientId,heartBeat.getVersion());
|
|
|
- //获取缓存中数据,告知白代理需要来弄一波任务清单推送了哦
|
|
|
List<FrontTask> hasTask = null;
|
|
|
String frontTaskResult = redisTemplateUtil.get(RedisPrefix.CACHE_FRONT_TASKS + ":" + clientId);
|
|
|
if (StringUtils.isNotBlank(frontTaskResult)){
|
|
|
hasTask = JSON.parseArray(frontTaskResult,FrontTask.class);
|
|
|
}
|
|
|
response.setHasTask(false);
|
|
|
+ //设置true,返回给白令海通知其调用中心获取应用清单接口
|
|
|
if(hasTask != null && hasTask.size() > 0 ){
|
|
|
- logger.info("判断{}需要推送任务清单:{}",clientId,JSON.toJSONString(hasTask));
|
|
|
+ logger.info("主机节点心跳:主机id={}推送任务清单:{}",clientId,JSON.toJSONString(hasTask));
|
|
|
response.setHasTask(true);
|
|
|
}
|
|
|
response.setName("部署中心");
|
|
|
@@ -372,10 +369,10 @@ public class BeringServiceImpl extends ServiceImpl<HostInfoDao, HostInfo> imple
|
|
|
|
|
|
List<AppRunningInfo> appRunningInfos = heartBeat.getApps();
|
|
|
if (null != appRunningInfos && appRunningInfos.size() > 0){
|
|
|
- asyncService.asyncSaveOrUpdateBatch(appRunningInfos,hostInfo.getId());
|
|
|
+ asyncService.asyncSaveOrUpdateBatch(appRunningInfos,hostId);
|
|
|
}
|
|
|
|
|
|
- logger.info("心跳返回结果:{}",JSON.toJSONString(response));
|
|
|
+ logger.info("主机节点心跳:主机id={}执行成功,响应数据={}",clientId,JSON.toJSONString(response));
|
|
|
return response;
|
|
|
}
|
|
|
|