1:添加nms上报服务器信息的接口

2:修改读取app*-rule.properties的方法
This commit is contained in:
RenKaiGe-Office
2018-08-21 16:36:52 +08:00
parent bbf0d42c68
commit 31f2fd11ea
9 changed files with 459 additions and 59 deletions

View File

@@ -0,0 +1,55 @@
package com.nis.domain.restful;
import java.io.Serializable;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.wordnik.swagger.annotations.ApiModel;
import com.wordnik.swagger.annotations.ApiModelProperty;
/**
*
* <p>Title: AbnormalMachine</p>
* <p>Description: nms上报的异常机器ip信息</p>
* <p>Company: IIE</p>
* @author rkg
* @date 2018年8月17日
*
*/
@ApiModel(value = "AbnormalMachine对象", description = "nms上报的异常机器ip信息类")
public class AbnormalMachine implements Serializable {
private static final long serialVersionUID = 1L;
// 与TrafficNmsServerStatistic中id是主外键关系,TrafficNmsServerStatistic中id是主键
@JsonIgnore
private Integer nmsServerId;
// 主机名称
@ApiModelProperty(value = "hostName", notes = "主机名称")
private String hostName;
private String ip;
public String getHostName() {
return hostName;
}
public void setHostName(String hostName) {
this.hostName = hostName;
}
public String getIp() {
return ip;
}
public void setIp(String ip) {
this.ip = ip;
}
public Integer getNmsServerId() {
return nmsServerId;
}
public void setNmsServerId(Integer nmsServerId) {
this.nmsServerId = nmsServerId;
}
}

View File

@@ -0,0 +1,96 @@
package com.nis.domain.restful;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.wordnik.swagger.annotations.ApiModel;
import com.wordnik.swagger.annotations.ApiModelProperty;
/**
*
* <p>Title: TrafficNmsServerStatistic</p>
* <p>Description: 记录nms服务器信息,全网机器总量,正常在线机器总数,异常机器列表</p>
* <p>Company: IIE</p>
* @author rkg
* @date 2018年8月17日
*
*/
@ApiModel(value = "TrafficNmsServerStatistic对象", description = "nms上报的服务器相关信息对象类")
public class TrafficNmsServerStatistic implements Serializable {
private static final long serialVersionUID = 1L;
@JsonIgnore
private Integer id;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "commitTime", notes = "上报时间")
private Date commitTime;// 提交时间
@ApiModelProperty(value = "area", notes = "区域")
private String area;// 区域信息
@ApiModelProperty(value = "total", notes = "主机总数量")
private Integer total;// 机器总数量
@ApiModelProperty(value = "normal", notes = "正常主机数量")
private Integer normal;// 正常数量
@ApiModelProperty(value = "abnormal", notes = "异常主机数量")
private Integer abnormal;//
@ApiModelProperty(value = "abnormalMachineList", notes = "异常主机列表")
private List<AbnormalMachine> abnormalMachineList;
public Date getCommitTime() {
return commitTime;
}
public void setCommitTime(Date commitTime) {
this.commitTime = commitTime;
}
public String getArea() {
return area;
}
public void setArea(String area) {
this.area = area;
}
public Integer getTotal() {
return total;
}
public void setTotal(Integer total) {
this.total = total;
}
public Integer getNormal() {
return normal;
}
public void setNormal(Integer normal) {
this.normal = normal;
}
public Integer getAbnormal() {
return abnormal;
}
public void setAbnormal(Integer abnormal) {
this.abnormal = abnormal;
}
public List<AbnormalMachine> getAbnormalMachineList() {
return abnormalMachineList;
}
public void setAbnormalMachineList(List<AbnormalMachine> abnormalMachineList) {
this.abnormalMachineList = abnormalMachineList;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
}

View File

@@ -0,0 +1,82 @@
package com.nis.domain.restful;
import java.util.Date;
import java.util.List;
import com.wordnik.swagger.annotations.ApiModel;
import com.wordnik.swagger.annotations.ApiModelProperty;
/**
*
* <p>Title: NmsServerInfoVo</p>
* <p>Description: 记录nms服务器信息,全网机器总量,正常在线机器总数,异常机器列表</p>
* <p>Company: IIE</p>
* @author rkg
* @date 2018年8月17日
*
*/
@ApiModel(value = "NmsServerInfoVo对象", description = "nms上报的服务器相关信息对象类")
public class TrafficServerInfo {
@ApiModelProperty(value = "commitTime", notes = "上报时间")
private Date commitTime;// 提交时间
@ApiModelProperty(value = "area", notes = "区域")
private String area;// 区域信息
@ApiModelProperty(value = "total", notes = "主机总数量")
private Integer total;// 机器总数量
@ApiModelProperty(value = "normal", notes = "正常主机数量")
private Integer normal;// 正常数量
@ApiModelProperty(value = "abnormal", notes = "异常主机数量")
private Integer abnormal;//
@ApiModelProperty(value = "abnormalMachineList", notes = "异常主机列表")
private List<AbnormalMachine> abnormalMachineList;
public Date getCommitTime() {
return commitTime;
}
public void setCommitTime(Date commitTime) {
this.commitTime = commitTime;
}
public String getArea() {
return area;
}
public void setArea(String area) {
this.area = area;
}
public Integer getTotal() {
return total;
}
public void setTotal(Integer total) {
this.total = total;
}
public Integer getNormal() {
return normal;
}
public void setNormal(Integer normal) {
this.normal = normal;
}
public Integer getAbnormal() {
return abnormal;
}
public void setAbnormal(Integer abnormal) {
this.abnormal = abnormal;
}
public List<AbnormalMachine> getAbnormalMachineList() {
return abnormalMachineList;
}
public void setAbnormalMachineList(List<AbnormalMachine> abnormalMachineList) {
this.abnormalMachineList = abnormalMachineList;
}
}

View File

@@ -147,17 +147,21 @@ public class ServiceAndRDBIndexReal {
}
public static void main(String[] args) {
getUnMaatTable();
// getUnMaatTable();
getMaatTable();
}
public static void getUnMaatTable() {
Map<Integer, String> typeTable = new HashMap<Integer, String>();
Map<String, String> map = new HashMap<String, String>();
String unMaatService = Configurations.getStringProperty("unMaatService", "");
if (unMaatService != null && !unMaatService.trim().equals("")) {
String[] split = unMaatService.split(";");
for (String str : split) {
String[] serviceAction = str.split(":");
String action = serviceAction[1];
map.put(serviceAction[0], action);
String serviceType = Configurations.getStringProperty(serviceAction[0], "");
if (serviceType != null && !serviceType.trim().equals("")) {
String[] typeArrs = serviceType.split(";");
@@ -170,7 +174,7 @@ public class ServiceAndRDBIndexReal {
} else {
System.out.println();
}
map.put(serviceAction[0], action);
unMaatSercieNameMap.put(Integer.parseInt(serviceAction[0]), tableName.toUpperCase());
}
}
@@ -178,48 +182,35 @@ public class ServiceAndRDBIndexReal {
}
}
for (Integer service : typeTable.keySet()) {
List<MaatXmlExpr> expressionList = ReadMaatXmlUtil.getMaatConfigByService(service).getExpressionList();
for (MaatXmlExpr maatXmlExpr : expressionList) {
if (maatXmlExpr.getValueExpression() != null) {
String[] valSplit = maatXmlExpr.getValueExpression().split(";");
int a = 1;
for (int i = 0; i < valSplit.length; i++) {
if (valSplit[i].toLowerCase().contains("is_valid")) {// xml中是字符串的\t这里判断的时候需要转义为\\t,但是添加的时候需要添加\t不是\\t
System.out.println(service + "--" + typeTable.get(service) + "---" + a);
} else if (valSplit[i].toLowerCase().contains("[")) {
a++;
}
}
}
}
System.out.println(
"0x" + Integer.toHexString(service) + "--servie=" + service + "--table=" + typeTable.get(service)
+ "---redisDB=" + serviceDBIndexmap.get(service) + "--action=" + map.get(service.toString())
+ "--HexAction=0x" + Integer.toHexString(Integer.parseInt(map.get(service.toString()))));
}
}
public static void getMaatTable() {
Map<Integer, Set<String>> typeMap = new HashMap<Integer, Set<String>>();
String service = Configurations.getStringProperty("service", "");
if (service != null && !service.trim().equals("")) {
String[] split = service.split(";");
String serviceStr = Configurations.getStringProperty("service", "");
if (serviceStr != null && !serviceStr.trim().equals("")) {
String[] split = serviceStr.split(";");
for (String str : split) {
String[] serviceAction = str.split(":");
serviceActionMap.put(Integer.valueOf(serviceAction[0]), Integer.valueOf(serviceAction[1]));
Integer ser = Integer.parseInt(serviceAction[0]);
String type = Configurations.getStringProperty(serviceAction[0], "");
if (type != null && !type.trim().equals("")) {
String[] typeArrs = type.split(";");
for (String typeStr : typeArrs) {
String[] typeArr = typeStr.split(":");
int tableType = Integer.parseInt(typeArr[0]);
String tableNameArr[] = typeArr[1].split(",");
for (String tableName : tableNameArr) {
if (typeMap.containsKey(tableType)) {
typeMap.get(tableType).add(tableName.toUpperCase());
if (typeMap.containsKey(ser)) {
typeMap.get(ser).add(tableName.toUpperCase());
} else {
Set<String> list = new HashSet<String>();
list.add(tableName.toUpperCase());
typeMap.put(tableType, list);
typeMap.put(ser, list);
}
}
}
@@ -227,8 +218,16 @@ public class ServiceAndRDBIndexReal {
}
}
for (Integer type : typeMap.keySet()) {
System.out.println(type + "----" + typeMap.get(type));
if (serviceStr != null && !serviceStr.trim().equals("")) {
String[] split = serviceStr.split(";");
for (String str : split) {
String[] serviceAction = str.split(":");
Integer ser = Integer.parseInt(serviceAction[0]);
String action = serviceAction[1];
System.out.println("0x" + Integer.toHexString(ser) + "--servie=" + ser + "--table="
+ typeMap.get(ser) + "---redisDB=" + serviceDBIndexmap.get(ser) + "--action=" + action
+ "--HexAction=0x" + Integer.toHexString(Integer.parseInt(action)));
}
}
}
@@ -280,7 +279,7 @@ public class ServiceAndRDBIndexReal {
throw new ServiceRuntimeException("无法从applicationConfig-rule.properties配置文件中,找到回调类配置service为"
+ service + ",配置类型:" + type + "对应的真实表名", RestBusinessCode.NotFoundTableName.getValue());
}
}
}
@@ -350,7 +349,5 @@ public class ServiceAndRDBIndexReal {
public static void setUnMaatSercieNameMap(Map<Integer, String> unMaatSercieNameMap) {
ServiceAndRDBIndexReal.unMaatSercieNameMap = unMaatSercieNameMap;
}
}

View File

@@ -0,0 +1,67 @@
package com.nis.web.controller.restful;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.nis.domain.restful.TrafficNmsServerStatistic;
import com.nis.restful.RestBusinessCode;
import com.nis.restful.RestConstants;
import com.nis.restful.RestServiceException;
import com.nis.util.Constants;
import com.nis.web.controller.BaseRestController;
import com.nis.web.service.AuditLogThread;
import com.nis.web.service.ServicesRequestLogService;
import com.nis.web.service.restful.TrafficNmsServerStatisticService;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;
@RestController
@RequestMapping("${servicePath}")
@Api(value = "NmsInfoController", description = "接收nms提交的系统状态等数据,将数据入库供服务推送给大屏")
public class NmsInfoController extends BaseRestController {
@Autowired
protected ServicesRequestLogService servicesRequestLogService;
@Autowired
TrafficNmsServerStatisticService trafficNmsServerStatisticService;
@RequestMapping(value = "/nms/v1/saveServerStatus", method = RequestMethod.POST)
@ApiOperation(value = "存储NMS系统上报的服务器状态接口", httpMethod = "POST", response = Map.class, notes = "接收NMS系统上报的服务器状态信息")
@ApiParam(value = "存储NMS系统上报的服务器状态接口", name = "saveServerStatus", required = true)
public Map<String, Object> saveServerStatus(@RequestBody TrafficNmsServerStatistic trafficNmsServerStatistic,
HttpServletRequest request, HttpServletResponse response) {
long start = System.currentTimeMillis();
AuditLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_POST, request,
trafficNmsServerStatistic);
Map<String, Object> map = new HashMap<String, Object>();
map.put(RestConstants.REST_SERVICE_HTTP_STATUS, HttpStatus.OK);
try {
TrafficNmsServerStatistic saveNmsServer = trafficNmsServerStatisticService
.saveNmsServer(trafficNmsServerStatistic);
try {
trafficNmsServerStatisticService.saveAbnormalMachine(saveNmsServer.getId(),
saveNmsServer.getAbnormalMachineList());
} catch (Exception e) {
trafficNmsServerStatisticService.delNmsServer(saveNmsServer);
throw e;
}
} catch (Exception e) {
throw new RestServiceException(thread, System.currentTimeMillis() - start, "上报服务器状态信息异常:" + e.getMessage(),
RestBusinessCode.unknow_error.getValue());
}
return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response, "上报服务器状态信息成功",
Constants.IS_DEBUG ? trafficNmsServerStatistic : null);
}
}

View File

@@ -0,0 +1,14 @@
package com.nis.web.dao;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.nis.domain.restful.AbnormalMachine;
import com.nis.domain.restful.TrafficNmsServerStatistic;
@MyBatisDao
public interface TrafficNmsServerStatisticDao extends CrudDao<TrafficNmsServerStatistic> {
public void insertAbnormalMachine(@Param("nmsServerId") Integer nmsServerId,@Param("list") List<AbnormalMachine> abnormalMachineList);
}

View File

@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.nis.web.dao.TrafficNmsServerStatisticDao">
<insert id="insert" parameterType="trafficNmsServerStatistic"
useGeneratedKeys="true" keyProperty="id">
INSERT INTO
traffic_nmsserver_statistic(
commit_time ,
area ,
total ,
normal ,
abnormal
) VALUES (
#{commitTime},
#{area},
#{total},
#{normal},
#{abnormal}
)
</insert>
<insert id="delete" parameterType="trafficNmsServerStatistic"
useGeneratedKeys="true" keyProperty="id">
delete from
traffic_nmsserver_statistic
where id=#{id}
</insert>
<insert id="insertAbnormalMachine" parameterType="trafficNmsServerStatistic">
INSERT INTO traffic_abnormal_machine(
nmsserver_id ,
hostName ,
ip
)
VALUES
<foreach collection="list" item="item" separator=",">
(
#{nmsServerId},
#{item.hostName},
#{item.ip}
)
</foreach>
</insert>
</mapper>

View File

@@ -0,0 +1,29 @@
package com.nis.web.service.restful;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.nis.domain.restful.AbnormalMachine;
import com.nis.domain.restful.TrafficNmsServerStatistic;
import com.nis.web.dao.TrafficNmsServerStatisticDao;
@Service
public class TrafficNmsServerStatisticService {
@Autowired
TrafficNmsServerStatisticDao trafficNmsServerStatisticDao;
public TrafficNmsServerStatistic saveNmsServer(TrafficNmsServerStatistic trafficNmsServerStatistic) {
trafficNmsServerStatisticDao.insert(trafficNmsServerStatistic);
return trafficNmsServerStatistic;
}
public void saveAbnormalMachine(Integer id, List<AbnormalMachine> abnormalMachineList) {
trafficNmsServerStatisticDao.insertAbnormalMachine(id, abnormalMachineList);
}
public void delNmsServer(TrafficNmsServerStatistic trafficNmsServerStatistic) {
trafficNmsServerStatisticDao.delete(trafficNmsServerStatistic);
}
}

View File

@@ -79,36 +79,46 @@
<!-- 缓存prepared statements的大小默认值0 -->
<property name="statementsCacheSize" value="${bonecp.hive.statementsCacheSize}" />
</bean>
<bean id="HiveDataSourceByDruid" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
<bean id="HiveDataSourceByDruid" class="com.alibaba.druid.pool.DruidDataSource"
init-method="init" destroy-method="close">
<property name="driverClassName" value="${jdbc.hive.driver}" />
<property name="url" value="${jdbc.hive.url}" />
<property name="username" value="${jdbc.hive.username}"/>
<property name="password" value="${jdbc.hive.password}"/>
<property name="initialSize" value="${druid.hive.initialSize}" /><!-- 配置初始化连接池数量-->
<property name="minIdle" value="${druid.hive.minIdle}" /><!-- 配置最小连接池数量-->
<property name="maxActive" value="${druid.hive.maxActive}" /><!-- 配置最连接池数量-->
<property name="maxWait" value="${druid.hive.maxWait}" /><!-- 配置获取连接等待超时的时间 单位毫秒-->
<property name="useUnfairLock" value="${druid.hive.useUnfairLock}"/><!--使用非公平锁-->
<property name="timeBetweenEvictionRunsMillis" value="${druid.hive.timeBetweenEvictionRunsMillis}" /><!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
<property name="minEvictableIdleTimeMillis" value="${druid.hive.minEvictableIdleTimeMillis}" /><!-- 配置一个连接在池中最小生存的时间单位毫秒 -->
<property name="validationQuery" value="${druid.hive.validationQuery}" /><!--用来检测连接是否有效的sql要求是一个查询语句。 -->
<property name="testWhileIdle" value="${druid.hive.testWhileIdle}" /><!--申请连接的时候检测如果空闲时间大于timeBetweenEvictionRunsMillis执行validationQuery检测连接是否有效。-->
<property name="testOnBorrow" value="${druid.hive.testOnBorrow}" /><!--申请连接时执行validationQuery检测连接是否有效-->
<property name="testOnReturn" value="${druid.hive.testOnReturn}" /><!--归还连接时执行validationQuery检测连接是否有效-->
<property name="poolPreparedStatements" value="${druid.hive.poolPreparedStatements}" /><!-- 打开PSCache并且指定每个连接上PSCache的大小 -->
<property name="maxOpenPreparedStatements" value="${druid.hive.maxOpenPreparedStatements}" /><!--要启用PSCache必须配置大于0当大于0时poolPreparedStatements自动触发修改为true。在Druid中不会存在Oracle下PSCache占用内存过多的问题可以把这个数值配置大一些比如说100 -->
<property name="filters" value="${druid.hive.filters}" /><!-- 配置监控统计拦截的filters去掉后监控界面sql无法统计 -->
</bean>
<property name="username" value="${jdbc.hive.username}" />
<property name="password" value="${jdbc.hive.password}" />
<!-- 配置初始化连接池数量 -->
<property name="initialSize" value="${druid.hive.initialSize}" />
<!-- 配置最连接池数量 -->
<property name="minIdle" value="${druid.hive.minIdle}" />
<!-- 配置最大连接池数量 -->
<property name="maxActive" value="${druid.hive.maxActive}" />
<!-- 配置获取连接等待超时的时间 单位毫秒 -->
<property name="maxWait" value="${druid.hive.maxWait}" />
<!--使用非公平锁 -->
<property name="useUnfairLock" value="${druid.hive.useUnfairLock}" />
<!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
<property name="timeBetweenEvictionRunsMillis" value="${druid.hive.timeBetweenEvictionRunsMillis}" />
<!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
<property name="minEvictableIdleTimeMillis" value="${druid.hive.minEvictableIdleTimeMillis}" />
<!--用来检测连接是否有效的sql要求是一个查询语句。 -->
<property name="validationQuery" value="${druid.hive.validationQuery}" />
<!--申请连接的时候检测如果空闲时间大于timeBetweenEvictionRunsMillis执行validationQuery检测连接是否有效。 -->
<property name="testWhileIdle" value="${druid.hive.testWhileIdle}" />
<!--申请连接时执行validationQuery检测连接是否有效 -->
<property name="testOnBorrow" value="${druid.hive.testOnBorrow}" />
<!--归还连接时执行validationQuery检测连接是否有效 -->
<property name="testOnReturn" value="${druid.hive.testOnReturn}" />
<!-- 打开PSCache并且指定每个连接上PSCache的大小 -->
<property name="poolPreparedStatements" value="${druid.hive.poolPreparedStatements}" />
<!--要启用PSCache必须配置大于0当大于0时poolPreparedStatements自动触发修改为true。在Druid中不会存在Oracle下PSCache占用内存过多的问题可以把这个数值配置大一些比如说100 -->
<property name="maxOpenPreparedStatements" value="${druid.hive.maxOpenPreparedStatements}" />
<!-- 配置监控统计拦截的filters去掉后监控界面sql无法统计 -->
<property name="filters" value="${druid.hive.filters}" />
</bean>
<bean id="dynamicDataSource" class="com.nis.datasource.DynamicDataSource">
<property name="targetDataSources">