diff --git a/src/main/java/com/nis/domain/restful/AbnormalMachine.java b/src/main/java/com/nis/domain/restful/AbnormalMachine.java new file mode 100644 index 0000000..cb170b6 --- /dev/null +++ b/src/main/java/com/nis/domain/restful/AbnormalMachine.java @@ -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; + +/** + * + *

Title: AbnormalMachine

+ *

Description: nms上报的异常机器ip信息

+ *

Company: IIE

+ * @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; + } + +} diff --git a/src/main/java/com/nis/domain/restful/TrafficNmsServerStatistic.java b/src/main/java/com/nis/domain/restful/TrafficNmsServerStatistic.java new file mode 100644 index 0000000..77832b0 --- /dev/null +++ b/src/main/java/com/nis/domain/restful/TrafficNmsServerStatistic.java @@ -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; + +/** + * + *

Title: TrafficNmsServerStatistic

+ *

Description: 记录nms服务器信息,全网机器总量,正常在线机器总数,异常机器列表

+ *

Company: IIE

+ * @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 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 getAbnormalMachineList() { + return abnormalMachineList; + } + + public void setAbnormalMachineList(List abnormalMachineList) { + this.abnormalMachineList = abnormalMachineList; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + +} diff --git a/src/main/java/com/nis/domain/restful/TrafficServerInfo.java b/src/main/java/com/nis/domain/restful/TrafficServerInfo.java new file mode 100644 index 0000000..a4a4b24 --- /dev/null +++ b/src/main/java/com/nis/domain/restful/TrafficServerInfo.java @@ -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; + +/** + * + *

Title: NmsServerInfoVo

+ *

Description: 记录nms服务器信息,全网机器总量,正常在线机器总数,异常机器列表

+ *

Company: IIE

+ * @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 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 getAbnormalMachineList() { + return abnormalMachineList; + } + + public void setAbnormalMachineList(List abnormalMachineList) { + this.abnormalMachineList = abnormalMachineList; + } + +} diff --git a/src/main/java/com/nis/util/ServiceAndRDBIndexReal.java b/src/main/java/com/nis/util/ServiceAndRDBIndexReal.java index 4fe4233..581c6bc 100644 --- a/src/main/java/com/nis/util/ServiceAndRDBIndexReal.java +++ b/src/main/java/com/nis/util/ServiceAndRDBIndexReal.java @@ -147,17 +147,21 @@ public class ServiceAndRDBIndexReal { } public static void main(String[] args) { - getUnMaatTable(); + // getUnMaatTable(); + getMaatTable(); } public static void getUnMaatTable() { Map typeTable = new HashMap(); + Map map = new HashMap(); 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 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> typeMap = new HashMap>(); - 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 list = new HashSet(); 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 unMaatSercieNameMap) { ServiceAndRDBIndexReal.unMaatSercieNameMap = unMaatSercieNameMap; } - - - + } diff --git a/src/main/java/com/nis/web/controller/restful/NmsInfoController.java b/src/main/java/com/nis/web/controller/restful/NmsInfoController.java new file mode 100644 index 0000000..f2bca8f --- /dev/null +++ b/src/main/java/com/nis/web/controller/restful/NmsInfoController.java @@ -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 saveServerStatus(@RequestBody TrafficNmsServerStatistic trafficNmsServerStatistic, + HttpServletRequest request, HttpServletResponse response) { + long start = System.currentTimeMillis(); + AuditLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_POST, request, + trafficNmsServerStatistic); + + Map map = new HashMap(); + 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); + } + +} diff --git a/src/main/java/com/nis/web/dao/TrafficNmsServerStatisticDao.java b/src/main/java/com/nis/web/dao/TrafficNmsServerStatisticDao.java new file mode 100644 index 0000000..d2b2125 --- /dev/null +++ b/src/main/java/com/nis/web/dao/TrafficNmsServerStatisticDao.java @@ -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 { + + public void insertAbnormalMachine(@Param("nmsServerId") Integer nmsServerId,@Param("list") List abnormalMachineList); +} \ No newline at end of file diff --git a/src/main/java/com/nis/web/dao/TrafficNmsServerStatisticDao.xml b/src/main/java/com/nis/web/dao/TrafficNmsServerStatisticDao.xml new file mode 100644 index 0000000..f15c840 --- /dev/null +++ b/src/main/java/com/nis/web/dao/TrafficNmsServerStatisticDao.xml @@ -0,0 +1,50 @@ + + + + + + + + INSERT INTO + traffic_nmsserver_statistic( + commit_time , + area , + total , + normal , + abnormal + ) VALUES ( + #{commitTime}, + #{area}, + #{total}, + #{normal}, + #{abnormal} + ) + + + + delete from + traffic_nmsserver_statistic + where id=#{id} + + + + + INSERT INTO traffic_abnormal_machine( + nmsserver_id , + hostName , + ip + ) + VALUES + + ( + #{nmsServerId}, + #{item.hostName}, + #{item.ip} + ) + + + + + \ No newline at end of file diff --git a/src/main/java/com/nis/web/service/restful/TrafficNmsServerStatisticService.java b/src/main/java/com/nis/web/service/restful/TrafficNmsServerStatisticService.java new file mode 100644 index 0000000..4fe2b2c --- /dev/null +++ b/src/main/java/com/nis/web/service/restful/TrafficNmsServerStatisticService.java @@ -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 abnormalMachineList) { + trafficNmsServerStatisticDao.insertAbnormalMachine(id, abnormalMachineList); + } + + public void delNmsServer(TrafficNmsServerStatistic trafficNmsServerStatistic) { + trafficNmsServerStatisticDao.delete(trafficNmsServerStatistic); + } +} diff --git a/src/main/resources/applicationContext-mybatis.xml b/src/main/resources/applicationContext-mybatis.xml index 3320b57..89a106c 100644 --- a/src/main/resources/applicationContext-mybatis.xml +++ b/src/main/resources/applicationContext-mybatis.xml @@ -79,36 +79,46 @@ - - - - - + + + + + - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +