OCT
REM: 1. 增加项目Git版本信息获取功能 2. 增加规范化IP端口接口 3. 增加获取能力节点信息接口 4. 增加获取平台版本信息接口 5. 增加获取设备版本信息接口
This commit is contained in:
parent
d899cb5da3
commit
3ec6da278d
|
@ -102,4 +102,15 @@ public class Helper {
|
|||
.collect(Collectors.joining(".")) + mask;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ip port normalize string.
|
||||
*
|
||||
* @param ipPort the ip port
|
||||
* @param type the type
|
||||
* @return the string
|
||||
*/
|
||||
public static String ipPortNormalize(String ipPort, HttpType type) {
|
||||
return ipPort.length() == 0 ? (type == HttpType.HTTP ? "80" : "443") : ipPort;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
package com.dispose.common;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* The type Version configure.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Component
|
||||
@Slf4j
|
||||
@PropertySource("classpath:git.properties")
|
||||
public class ProjectGitVersionInfo {
|
||||
/**
|
||||
* The Commit id.
|
||||
*/
|
||||
@Value("${git.commit.id}")
|
||||
private String commitId;
|
||||
/**
|
||||
* The Commit describe.
|
||||
*/
|
||||
@Value("${git.commit.id.describe}")
|
||||
private String commitDescribe;
|
||||
/**
|
||||
* The Commit time.
|
||||
*/
|
||||
@Value("${git.commit.time}")
|
||||
private String commitTime;
|
||||
/**
|
||||
* The Tag name.
|
||||
*/
|
||||
@Value("${git.closest.tag.name}")
|
||||
private String tagName;
|
||||
/**
|
||||
* The Build time.
|
||||
*/
|
||||
@Value("${git.build.time}")
|
||||
private String buildTime;
|
||||
|
||||
/**
|
||||
* The Git branch.
|
||||
*/
|
||||
@Value("${git.branch}")
|
||||
private String gitBranch;
|
||||
}
|
|
@ -6,6 +6,7 @@ import com.dispose.common.DisposeConfigValue;
|
|||
import com.dispose.common.DisposeDeviceType;
|
||||
import com.dispose.common.DisposeObjectType;
|
||||
import com.dispose.common.ErrorCode;
|
||||
import com.dispose.common.Helper;
|
||||
import com.dispose.common.HttpType;
|
||||
import com.dispose.common.IpAddrType;
|
||||
import com.dispose.common.PrivacyHelper;
|
||||
|
@ -143,9 +144,7 @@ public class DisposeDeviceManagerController {
|
|||
DisposeDevice dev = v.getSecondParam();
|
||||
AddDeviceRet rsp = AddDeviceRet.builder()
|
||||
.ipAddr(dev.getIpAddr())
|
||||
.ipPort(dev.getIpPort().length() == 0 ?
|
||||
(dev.getUrlType() == HttpType.HTTP ?
|
||||
"80" : "443") : dev.getIpPort())
|
||||
.ipPort(Helper.ipPortNormalize(dev.getIpPort(), dev.getUrlType()))
|
||||
.build();
|
||||
|
||||
rsp.setStatus(v.getFirstParam().getCode());
|
||||
|
@ -272,8 +271,7 @@ public class DisposeDeviceManagerController {
|
|||
devInfo.setId(v.getId().toString());
|
||||
devInfo.setIpAddr(DisposeConfigValue.USED_PRIVACY_PROTECT ?
|
||||
PrivacyHelper.ipAddressPrivacy(v.getIpAddr()) : v.getIpAddr());
|
||||
devInfo.setIpPort(v.getIpPort().length() == 0 ?
|
||||
(v.getUrlType() == HttpType.HTTP ? "80" : "443") : v.getIpPort());
|
||||
devInfo.setIpPort(Helper.ipPortNormalize(v.getIpPort(), v.getUrlType()));
|
||||
devInfo.setDeviceType(v.getDeviceType().getValue());
|
||||
devInfo.setAreaCode(v.getAreaCode());
|
||||
devInfo.setDeviceName(v.getDeviceName());
|
||||
|
|
|
@ -2,13 +2,21 @@ package com.dispose.controller;
|
|||
|
||||
import com.dispose.common.DisposeCapacityType;
|
||||
import com.dispose.common.ErrorCode;
|
||||
import com.dispose.common.Helper;
|
||||
import com.dispose.common.ProjectGitVersionInfo;
|
||||
import com.dispose.pojo.dto.protocol.base.IdArraysReq;
|
||||
import com.dispose.pojo.dto.protocol.base.ProtocolReqDTO;
|
||||
import com.dispose.pojo.dto.protocol.base.ProtocolRespDTO;
|
||||
import com.dispose.pojo.dto.protocol.device.info.AreaInfoDetail;
|
||||
import com.dispose.pojo.dto.protocol.device.info.DeviceVersionDetail;
|
||||
import com.dispose.pojo.dto.protocol.device.info.GetAreaInfoRsp;
|
||||
import com.dispose.pojo.dto.protocol.device.info.GetDeviceVerInfoRsp;
|
||||
import com.dispose.pojo.dto.protocol.device.info.GetPlatformVerInfoRsp;
|
||||
import com.dispose.pojo.entity.DisposeDevice;
|
||||
import com.dispose.service.AreaCodeManagerService;
|
||||
import com.dispose.service.DisposeAbilityRouterService;
|
||||
import com.dispose.service.DisposeDeviceManagerService;
|
||||
import com.dispose.validation.group.ValidGroups;
|
||||
import com.security.annotation.Decryption;
|
||||
import com.security.annotation.Encryption;
|
||||
import io.swagger.annotations.Api;
|
||||
|
@ -18,6 +26,8 @@ import org.springframework.stereotype.Component;
|
|||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
|
@ -26,6 +36,8 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* The type Dispose info controller.
|
||||
|
@ -48,24 +60,33 @@ public class DisposeInfoController {
|
|||
@Resource
|
||||
private DisposeDeviceManagerService disposeDeviceManagerService;
|
||||
|
||||
/**
|
||||
* The Area code manager service.
|
||||
*/
|
||||
@Resource
|
||||
private AreaCodeManagerService areaCodeManagerService;
|
||||
|
||||
/**
|
||||
* The Project git version info.
|
||||
*/
|
||||
@Resource
|
||||
private ProjectGitVersionInfo projectGitVersionInfo;
|
||||
|
||||
/**
|
||||
* The Dispose ability router service.
|
||||
*/
|
||||
@Resource
|
||||
private DisposeAbilityRouterService disposeAbilityRouterService;
|
||||
|
||||
@Resource
|
||||
private AreaCodeManagerService areaCodeManagerService;
|
||||
|
||||
/**
|
||||
* Gets all dispose device.
|
||||
* Gets all dispose device area info.
|
||||
*
|
||||
* @return the all dispose device
|
||||
* @return the all dispose device area info
|
||||
*/
|
||||
@GetMapping("areaInfo")
|
||||
@ResponseBody
|
||||
@ApiOperation("获取处置能力节点")
|
||||
public ProtocolRespDTO<?> getAllDisposeDevice() {
|
||||
public ProtocolRespDTO<GetAreaInfoRsp> getAllDisposeDeviceAreaInfo() {
|
||||
|
||||
GetAreaInfoRsp rspInfo = GetAreaInfoRsp.builder()
|
||||
.items(new ArrayList<>())
|
||||
|
@ -85,6 +106,78 @@ public class DisposeInfoController {
|
|||
rspInfo.getItems().add(info);
|
||||
}
|
||||
|
||||
rspInfo.setStatus(ErrorCode.ERR_OK.getCode());
|
||||
rspInfo.setMessage(new String[]{ErrorCode.ERR_OK.getMsg()});
|
||||
|
||||
return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets version info.
|
||||
*
|
||||
* @return the version info
|
||||
*/
|
||||
@GetMapping("platformVersion")
|
||||
@ResponseBody
|
||||
@ApiOperation("获取平台版本信息")
|
||||
public ProtocolRespDTO<GetPlatformVerInfoRsp> getPlatformVersionInfo() {
|
||||
GetPlatformVerInfoRsp rspInfo = GetPlatformVerInfoRsp.builder()
|
||||
.platformVersion(projectGitVersionInfo)
|
||||
.build();
|
||||
rspInfo.setStatus(ErrorCode.ERR_OK.getCode());
|
||||
rspInfo.setMessage(new String[]{ErrorCode.ERR_OK.getMsg()});
|
||||
return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspInfo);
|
||||
}
|
||||
|
||||
@PostMapping("deviceVersion")
|
||||
@ResponseBody
|
||||
@ApiOperation("获取设备版本信息")
|
||||
public ProtocolRespDTO<GetDeviceVerInfoRsp> getDeviceVersionInfo(
|
||||
@Validated(ValidGroups.GetDevVerReqValid.class)
|
||||
@RequestBody ProtocolReqDTO<IdArraysReq> mr
|
||||
) {
|
||||
GetDeviceVerInfoRsp rspInfo = GetDeviceVerInfoRsp.builder()
|
||||
.deviceVersion(new ArrayList<>())
|
||||
.build();
|
||||
List<Long> reqIds = Arrays.stream(mr.getMsgContent().getId()).map(Long::parseLong).collect(Collectors.toList());
|
||||
|
||||
Map<Long, DisposeDevice> devMap = disposeDeviceManagerService.getAllDisposeDevice()
|
||||
.stream()
|
||||
.collect(Collectors.toMap(DisposeDevice::getId,
|
||||
Function.identity()));
|
||||
|
||||
|
||||
List<Long> allDevId = new ArrayList<>(devMap.keySet());
|
||||
|
||||
if (reqIds.size() == 0) {
|
||||
reqIds = allDevId;
|
||||
}
|
||||
|
||||
reqIds.stream().collect(Collectors.groupingBy(allDevId::contains))
|
||||
.forEach((k, v) -> v.forEach(m -> {
|
||||
DeviceVersionDetail dv = DeviceVersionDetail.builder().build();
|
||||
dv.setId(String.valueOf(m));
|
||||
|
||||
if (k) {
|
||||
DisposeDevice d = devMap.get(m);
|
||||
|
||||
dv.setIpAddr(d.getIpAddr());
|
||||
dv.setIpPort(Helper.ipPortNormalize(d.getIpPort(), d.getUrlType()));
|
||||
dv.setVersion(disposeAbilityRouterService.getAbilityDevice(d.getId())
|
||||
.getFirewareInfo()
|
||||
.getVersion());
|
||||
|
||||
dv.setStatus(ErrorCode.ERR_OK.getCode());
|
||||
dv.setMessage(new String[]{ErrorCode.ERR_OK.getMsg()});
|
||||
} else {
|
||||
dv.setStatus(ErrorCode.ERR_NOSUCHDEVICE.getCode());
|
||||
dv.setMessage(new String[]{ErrorCode.ERR_NOSUCHDEVICE.getMsg()});
|
||||
}
|
||||
|
||||
rspInfo.getDeviceVersion().add(dv);
|
||||
}));
|
||||
|
||||
return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspInfo);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -25,7 +25,8 @@ public class IdArraysReq {
|
|||
/**
|
||||
* The Id.
|
||||
*/
|
||||
@NotNull(message = "id 字段不能为空", groups = ValidGroups.IdArrayValid.class)
|
||||
@NotNull(message = "id 字段不能为空",
|
||||
groups = {ValidGroups.IdArrayValid.class, ValidGroups.GetDevVerReqValid.class})
|
||||
@Size(min = 1, message = "id 字段必须指定明确id编号", groups = ValidGroups.ExplicitIdArrayValid.class)
|
||||
private String[] id;
|
||||
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
package com.dispose.pojo.dto.protocol.device.info;
|
||||
|
||||
import com.dispose.pojo.dto.protocol.base.BaseIdResp;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* The type Device version detail.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@JsonPropertyOrder({"ipAddr", "ipPort", "version", "status", "message"})
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class DeviceVersionDetail extends BaseIdResp {
|
||||
/**
|
||||
* The Ip addr.
|
||||
*/
|
||||
private String ipAddr;
|
||||
/**
|
||||
* The Ip port.
|
||||
*/
|
||||
private String ipPort;
|
||||
/**
|
||||
* The Version.
|
||||
*/
|
||||
private String version;
|
||||
}
|
|
@ -20,7 +20,7 @@ import java.util.List;
|
|||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@JsonPropertyOrder({"taskId", "disposeIp", "expireTime", "status", "message"})
|
||||
@JsonPropertyOrder({"items", "status", "message"})
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class GetAreaInfoRsp extends BaseRespStatus {
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
package com.dispose.pojo.dto.protocol.device.info;
|
||||
|
||||
public class GetDevVerReq {
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.dispose.pojo.dto.protocol.device.info;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The type Get device ver info rsp.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@JsonPropertyOrder({"deviceVersion", "status", "message"})
|
||||
public class GetDeviceVerInfoRsp {
|
||||
/**
|
||||
* The Device version.
|
||||
*/
|
||||
private List<DeviceVersionDetail> deviceVersion;
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package com.dispose.pojo.dto.protocol.device.info;
|
||||
|
||||
import com.dispose.common.ProjectGitVersionInfo;
|
||||
import com.dispose.pojo.dto.protocol.base.BaseRespStatus;
|
||||
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* The type Get version info rsp.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@JsonPropertyOrder({"platformVersion", "status", "message"})
|
||||
public class GetPlatformVerInfoRsp extends BaseRespStatus {
|
||||
/**
|
||||
* The Platform version.
|
||||
*/
|
||||
private ProjectGitVersionInfo platformVersion;
|
||||
}
|
|
@ -43,11 +43,6 @@ public class AreaCodeManagerServiceImpl implements AreaCodeManagerService {
|
|||
@Override
|
||||
public Map<Integer, List<DisposeDevice>> getAreaCodeGroup() {
|
||||
List<DisposeDevice> disposeDevices = disposeDeviceManagerService.getAllDisposeDevice();
|
||||
|
||||
if (disposeDevices == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return disposeDevices.stream().collect(Collectors.groupingBy(DisposeDevice::getAreaCode));
|
||||
}
|
||||
|
||||
|
@ -60,11 +55,6 @@ public class AreaCodeManagerServiceImpl implements AreaCodeManagerService {
|
|||
@Override
|
||||
public int getAreaCodeGroupReserveNetflow(Integer areaCode) {
|
||||
List<DisposeDevice> disposeDevices = disposeDeviceManagerService.getAllDisposeDevice();
|
||||
|
||||
if (disposeDevices == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return disposeDevices.stream()
|
||||
.filter(v -> v.getAreaCode().equals(areaCode))
|
||||
.mapToInt(v -> v.getDevCapacity().stream()
|
||||
|
@ -82,11 +72,6 @@ public class AreaCodeManagerServiceImpl implements AreaCodeManagerService {
|
|||
@Override
|
||||
public int getAreaCodeOnlineDeviceNum(Integer areaCode) {
|
||||
List<DisposeDevice> disposeDevices = disposeDeviceManagerService.getAllDisposeDevice();
|
||||
|
||||
if (disposeDevices == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (int) disposeDevices.stream()
|
||||
.filter(v -> v.getAreaCode().equals(areaCode))
|
||||
.filter(k -> disposeAbilityRouterService.getAbilityDevice(k.getId())
|
||||
|
@ -104,11 +89,6 @@ public class AreaCodeManagerServiceImpl implements AreaCodeManagerService {
|
|||
@Override
|
||||
public DisposeCapacityType[] getAreaCodeSupportCapacity(Integer areaCode) {
|
||||
List<DisposeDevice> disposeDevices = disposeDeviceManagerService.getAllDisposeDevice();
|
||||
|
||||
if (disposeDevices == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return disposeDevices.stream()
|
||||
.filter(v -> v.getAreaCode().equals(areaCode))
|
||||
.flatMap(k -> k.getDevCapacity().stream()
|
||||
|
|
|
@ -120,6 +120,12 @@ public class DisposeDeviceManagerServiceImpl implements DisposeDeviceManagerServ
|
|||
*/
|
||||
@Override
|
||||
public List<DisposeDevice> getAllDisposeDevice() {
|
||||
return disposeDeviceManager.getAllNormalDisposeDevices();
|
||||
List<DisposeDevice> disposeDevices = disposeDeviceManager.getAllNormalDisposeDevices();
|
||||
|
||||
if(disposeDevices == null) {
|
||||
return new ArrayList<>();
|
||||
} else {
|
||||
return disposeDevices;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,13 +63,18 @@ public interface ValidGroups {
|
|||
}
|
||||
|
||||
/**
|
||||
* The interface Task start req valid.
|
||||
* The interface Task start req common valid.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
interface TaskStartReqCommonValid extends ProtocolCommonValid {
|
||||
}
|
||||
|
||||
/**
|
||||
* The interface Task start req valid.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
interface TaskStartReqValid extends TaskStartReqCommonValid {
|
||||
}
|
||||
|
||||
|
@ -88,4 +93,12 @@ public interface ValidGroups {
|
|||
*/
|
||||
interface TaskStopReqValid extends ProtocolCommonValid {
|
||||
}
|
||||
|
||||
/**
|
||||
* The interface Get dev ver req valid.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
interface GetDevVerReqValid extends ProtocolCommonValid {
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue