summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorshentao <shentao@chinamobile.com>2018-01-29 16:20:28 +0800
committershentao <shentao@chinamobile.com>2018-01-29 16:20:36 +0800
commit7acb391d04f2efdac6e6306c208ae1586c23ffd9 (patch)
tree15f7309dd86c0bd11092ee98a3ccc459e2c1bb0e
parente6a9f95aec91bb0ef3ef91006c30a1d7daf87d8a (diff)
Fix monitor bug about alarm record update
Change-Id: Ieb08e334aa50747b61baa63bf78b277546ace029 Issue-ID: USECASEUI-101 Signed-off-by: shentao <shentao@chinamobile.com>
-rw-r--r--server/pom.xml6
-rwxr-xr-xserver/src/main/java/org/onap/usecaseui/server/controller/AlarmController.java269
-rwxr-xr-xserver/src/main/java/org/onap/usecaseui/server/controller/PerformanceController.java78
-rw-r--r--server/src/main/java/org/onap/usecaseui/server/service/AlarmsHeaderService.java6
-rwxr-xr-xserver/src/main/java/org/onap/usecaseui/server/service/impl/AlarmsHeaderServiceImpl.java39
-rwxr-xr-xserver/src/main/java/org/onap/usecaseui/server/util/DateUtils.java51
-rw-r--r--server/src/main/java/org/onap/usecaseui/server/util/DmaapSubscriber.java82
-rw-r--r--standalone/src/main/assembly/resources/topologyD_data.json21
8 files changed, 389 insertions, 163 deletions
diff --git a/server/pom.xml b/server/pom.xml
index 9c68cffd..1c8ba798 100644
--- a/server/pom.xml
+++ b/server/pom.xml
@@ -189,6 +189,12 @@
<version>2.3.0</version>
</dependency>
+ <!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
+ <dependency>
+ <groupId>com.alibaba</groupId>
+ <artifactId>fastjson</artifactId>
+ <version>1.2.23</version>
+ </dependency>
<dependency>
<groupId>org.openecomp.sdc.jtosca</groupId>
<artifactId>jtosca</artifactId>
diff --git a/server/src/main/java/org/onap/usecaseui/server/controller/AlarmController.java b/server/src/main/java/org/onap/usecaseui/server/controller/AlarmController.java
index 502bd7b2..31cf2156 100755
--- a/server/src/main/java/org/onap/usecaseui/server/controller/AlarmController.java
+++ b/server/src/main/java/org/onap/usecaseui/server/controller/AlarmController.java
@@ -18,6 +18,9 @@ package org.onap.usecaseui.server.controller;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.onap.usecaseui.server.bean.AlarmsHeader;
@@ -36,23 +39,21 @@ import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
+import java.io.*;
+import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
+import java.time.format.DateTimeFormatter;
import java.util.*;
@RestController
@org.springframework.context.annotation.Configuration
@EnableAspectJAutoProxy
-public class AlarmController
-{
+public class AlarmController {
private final Logger logger = LoggerFactory.getLogger(AlarmController.class);
@@ -69,76 +70,71 @@ public class AlarmController
@RequestMapping(value = {"/alarm/{currentPage}/{pageSize}",
"/alarm/{currentPage}/{pageSize}/{sourceId}/{sourceName}/{priority}/{startTime}/{endTime}/{vfStatus}"},
- method = RequestMethod.GET , produces = "application/json")
- public String getAlarmData(@PathVariable(required = false) String sourceId,@PathVariable(required = false) String sourceName,
- @PathVariable(required = false) String priority,@PathVariable(required = false) String startTime,
- @PathVariable(required = false) String endTime,@PathVariable(required = false) String vfStatus,
+ method = RequestMethod.GET, produces = "application/json")
+ public String getAlarmData(@PathVariable(required = false) String sourceId, @PathVariable(required = false) String sourceName,
+ @PathVariable(required = false) String priority, @PathVariable(required = false) String startTime,
+ @PathVariable(required = false) String endTime, @PathVariable(required = false) String vfStatus,
@PathVariable int currentPage, @PathVariable int pageSize) throws JsonProcessingException {
logger.info("transfer getAlarmData Apis, " +
- "Parameter all follows : [currentPage : {} , pageSize : {} , sourceId : {} , " +
- "sourceName : {} , priority : {} , startTime :{} , endTime : {} , vfStatus : {}]"
- ,currentPage,pageSize,sourceId,sourceName,priority,startTime,endTime,vfStatus);
+ "Parameter all follows : [currentPage : {} , pageSize : {} , sourceId : {} , " +
+ "sourceName : {} , priority : {} , startTime :{} , endTime : {} , vfStatus : {}]"
+ , currentPage, pageSize, sourceId, sourceName, priority, startTime, endTime, vfStatus);
List<AlarmsHeader> alarmsHeaders = null;
List<AlarmBo> list = new ArrayList<>();
Page pa = null;
if (null != sourceId || null != sourceName || null != priority || null != startTime || null != endTime
- || null != vfStatus ){
+ || null != vfStatus) {
AlarmsHeader alarm = new AlarmsHeader();
- alarm.setSourceId(!"null".equals(sourceId)?sourceId:null);
- alarm.setSourceName(!"null".equals(sourceName)?sourceName:null);
- alarm.setStatus(!"null".equals(vfStatus)?vfStatus:null);
+ alarm.setSourceId(!"null".equals(sourceId) ? sourceId : null);
+ alarm.setSourceName(!"null".equals(sourceName) ? sourceName : null);
+ alarm.setStatus(!"null".equals(vfStatus) ? vfStatus : null);
try {
- alarm.setCreateTime(!"null".equals(startTime)?new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(startTime):null);
- alarm.setUpdateTime(!"null".equals(endTime)?new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(endTime):null);
+ alarm.setCreateTime(!"null".equals(startTime) ? new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(startTime) : null);
+ alarm.setUpdateTime(!"null".equals(endTime) ? new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(endTime) : null);
} catch (ParseException e) {
- logger.error("Parse date error :"+e.getMessage());
+ logger.error("Parse date error :" + e.getMessage());
}
- pa = alarmsHeaderService.queryAlarmsHeader(alarm,currentPage,pageSize);
+ pa = alarmsHeaderService.queryAlarmsHeader(alarm, currentPage, pageSize);
alarmsHeaders = pa.getList();
if (null != alarmsHeaders && alarmsHeaders.size() > 0) {
- alarmsHeaders.forEach(a ->{
+ alarmsHeaders.forEach(a -> {
logger.info(a.toString());
AlarmBo abo = new AlarmBo();
- if (!a.getStatus().equals("3")){
+ if (!a.getStatus().equals("3")) {
abo.setAlarmsHeader(a);
AlarmsInformation information = new AlarmsInformation();
information.setEventId(a.getSourceId());
- List<AlarmsInformation> informationList = alarmsInformationService.queryAlarmsInformation(information,1,100).getList();
+ List<AlarmsInformation> informationList = alarmsInformationService.queryAlarmsInformation(information, 1, 100).getList();
abo.setAlarmsInformation(informationList);
list.add(abo);
}
});
}
- }else {
+ } else {
pa = alarmsHeaderService.queryAlarmsHeader(null, currentPage, pageSize);
alarmsHeaders = pa.getList();
if (null != alarmsHeaders && alarmsHeaders.size() > 0) {
alarmsHeaders.forEach(a -> {
AlarmBo abo = new AlarmBo();
- if (!a.getStatus().equals("3")){
+ if (!a.getStatus().equals("3")) {
abo.setAlarmsHeader(a);
- abo.setAlarmsInformation(alarmsInformationService.queryAlarmsInformation(new AlarmsInformation(a.getEventId()),currentPage,pageSize).getList());
+ abo.setAlarmsInformation(alarmsInformationService.queryAlarmsInformation(new AlarmsInformation(a.getEventId()), currentPage, pageSize).getList());
list.add(abo);
}
});
}
}
- try {
- Map<String,Object> map = new HashMap<>();
- map.put("alarms",list);
- map.put("totalRecords",pa.getTotalRecords());
- omAlarm.setDateFormat(new SimpleDateFormat(Constant.DATE_FORMAT));
- return omAlarm.writeValueAsString(map);
- } catch (JsonProcessingException e) {
- logger.debug("JsonProcessingException :"+e.getMessage());
- return omAlarm.writeValueAsString("failed");
- }
+ Map<String, Object> map = new HashMap<>();
+ map.put("alarms", list);
+ map.put("totalRecords", pa.getTotalRecords());
+ omAlarm.setDateFormat(new SimpleDateFormat(Constant.DATE_FORMAT));
+ return omAlarm.writeValueAsString(map);
}
- @RequestMapping(value = "/alarm/statusCount",method = RequestMethod.GET , produces = "application/json")
- public String getStatusCount(){
+ @RequestMapping(value = "/alarm/statusCount", method = RequestMethod.GET, produces = "application/json")
+ public String getStatusCount() {
List<String> statusCount = new ArrayList<>();
try {
statusCount.add(alarmsHeaderService.queryStatusCount("0"));
@@ -152,41 +148,160 @@ public class AlarmController
return null;
}
- @RequestMapping(value = {"/alarm/sourceId"},method = RequestMethod.GET)
- public String getSourceId(){
+ @RequestMapping(value = {"/topology/{serviceName}"}, method = RequestMethod.GET)
+ public String getTopologyData(@PathVariable String serviceName) {
+ Map<String,Object> topologyMap = new HashMap<>();
+ try {
+ topologyMap.put("name",serviceName);
+
+ List<Map<String,Object>> networkServices = (List<Map<String, Object>>) getAllVNFS().get("networkServices");
+ List<Map<String,Object>> VNFS = (List<Map<String, Object>>) getAllVNFS().get("VNFS");
+
+ List<Map<String,Object>> children = new ArrayList<>();
+ networkServices.forEach( i -> {
+ Map<String,Object> childrenMap = new HashMap<>();
+ i.forEach( (k,v) -> {
+ if (k.equals("parentService"))
+ if (v.equals(serviceName)){
+ childrenMap.put("name",i.get("nsName"));
+ List<Map<String,Object>> childrenList = new ArrayList<>();
+ VNFS.forEach( j -> {
+ Map<String,Object> childrenJMap = new HashMap<>();
+ j.forEach( (k1,v2) -> {
+ if (k1.equals("parentNS"))
+ if (v2.equals(i.get("nsName"))) {
+ childrenJMap.put("name",j.get("vnfName"));
+ childrenJMap.put("isAlarm",j.get("isAlarm"));
+ }
+ });
+ if (childrenJMap.size() > 0)
+ childrenList.add(childrenJMap);
+ });
+ if (childrenList.size() > 0) {
+ childrenMap.put("children",childrenList);
+ }
+ }
+ });
+ if (childrenMap.size() > 0) {
+ children.add(childrenMap);
+ }
+ });
+ if (children.size() > 0) {
+ topologyMap.put("children",children);
+ }
+ return omAlarm.writeValueAsString(topologyMap);
+ } catch (IOException e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ @RequestMapping(value = {"/topology/services"}, method = RequestMethod.GET)
+ public String getTopologyServices() {
+ try {
+ List<Map<String,Object>> services = (List<Map<String, Object>>) getAllVNFS().get("services");
+ services.forEach( i -> {
+ i.forEach( (k,v) -> {
+ if (k.equals("ServiceName")) {
+ AlarmsHeader alarmsHeader = new AlarmsHeader();
+ alarmsHeader.setSourceId(v.toString());
+ List<AlarmsHeader> alarmsHeaderList = alarmsHeaderService.queryAlarmsHeader(alarmsHeader,1,10).getList();
+ alarmsHeaderList.forEach(alarmsHeader1 -> {
+ if (alarmsHeader1.getStatus().equals("1")) {
+ i.replace("isAlarm","true");
+ }
+ });
+ }
+ });
+ });
+ return omAlarm.writeValueAsString(services);
+ } catch (Exception e) {
+ logger.error(e.getMessage());
+ return null;
+ }
+ }
+
+ private Map<String,Object> getTopologyData() throws IOException {
+ String data = "";
+ try {
+ BufferedReader br = new BufferedReader(new FileReader("/home/uui/resources/topologyD_data.json"));
+ String tmpStr = "";
+ while ((tmpStr=br.readLine()) != null) {
+ data += tmpStr;
+ }
+ br.close();
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ Map<String,Object> map = omAlarm.readValue(data, Map.class);
+ return map;
+ }
+
+ public Map<String,Object> getAllVNFS() throws IOException {
+ String data="";
+ try {
+ String str=null;
+ BufferedReader br = new BufferedReader(new FileReader("/home/uui/resources/topologyD_data.json"));
+ while ((str=br.readLine())!=null) {
+ data += str;
+ }
+ br.close();
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ JSONObject jsonObject = (JSONObject) JSON.parseObject(data);
+ JSONArray jsonArray = jsonObject.getJSONArray("VNFS");
+
+ for (int a=0;a<jsonArray.size();a++) {
+ JSONObject jsonObject1 = jsonArray.getJSONObject(a);
+ String vnfName = jsonObject1.getString("vnfName");
+ Boolean name = alarmsHeaderService.getStatusBySourceName(vnfName);
+ jsonObject1.put("isAlarm",name);
+ System.out.print("vnfName===="+vnfName+"name====="+name);
+ }
+
+ String jsonS = jsonObject.toJSONString();
+ System.out.print("toJSONString===="+jsonS);
+
+ Map<String,Object> map = omAlarm.readValue(jsonS, Map.class);
+ return map;
+ }
+
+
+ @RequestMapping(value = {"/alarm/sourceId"}, method = RequestMethod.GET)
+ public String getSourceId() throws JsonProcessingException {
List<String> sourceIds = new ArrayList<>();
- alarmsHeaderService.queryAlarmsHeader(new AlarmsHeader(),1,Integer.MAX_VALUE).getList().forEach( al ->{
+ alarmsHeaderService.queryAlarmsHeader(new AlarmsHeader(), 1, Integer.MAX_VALUE).getList().forEach(al -> {
if (!al.getStatus().equals("3") &&
!sourceIds.contains(al.getSourceId()))
sourceIds.add(al.getSourceId());
- } );
- try {
- return omAlarm.writeValueAsString(sourceIds);
- } catch (JsonProcessingException e) {
- e.printStackTrace();
- return "";
- }
+ });
+ return omAlarm.writeValueAsString(sourceIds);
}
- @RequestMapping(value = {"/alarm/diagram"},method = RequestMethod.POST)
- public String genDiagram(@RequestParam String sourceId,@RequestParam String startTime,@RequestParam String endTime,@RequestParam String showMode){
+ @RequestMapping(value = {"/alarm/diagram"}, method = RequestMethod.POST)
+ public String genDiagram(@RequestParam String sourceId, @RequestParam String startTime, @RequestParam String endTime, @RequestParam String showMode) {
try {
- return omAlarm.writeValueAsString(diagramDate(sourceId,startTime,endTime,showMode));
+ return omAlarm.writeValueAsString(diagramDate(sourceId, startTime, endTime, showMode));
} catch (JsonProcessingException e) {
e.printStackTrace();
return "";
}
}
- private List<List<Long>> dateProcess(String sourceId,long startTimeL,long endTimeL,long timeIteraPlusVal,long keyVal,long keyValIteraVal,String keyUnit) throws ParseException {
+ private List<List<Long>> dateProcess(String sourceId, long startTimeL, long endTimeL, long timeIteraPlusVal, long keyVal, long keyValIteraVal, String keyUnit) throws ParseException {
List<List<Long>> dataList = new ArrayList<>();
long tmpEndTimeL = startTimeL + timeIteraPlusVal;
- while (endTimeL >= tmpEndTimeL){
- List<Map<String,String>> maps = alarmsInformationService.queryDateBetween(sourceId,sdf.format(new Date(startTimeL)),sdf.format(new Date(tmpEndTimeL)));
- maps.forEach( map -> {
+ while (endTimeL >= tmpEndTimeL) {
+ List<Map<String, String>> maps = alarmsInformationService.queryDateBetween(sourceId, sdf.format(new Date(startTimeL)), sdf.format(new Date(tmpEndTimeL)));
+ maps.forEach(map -> {
try {
List<Long> longList = new ArrayList<>();
- if (map.get("Time") != null && !"".equals(map.get("Time")) && !"NULL".equals(map.get("Time")) ){
+ if (map.get("Time") != null && !"".equals(map.get("Time")) && !"NULL".equals(map.get("Time"))) {
longList.add(sdf.parse(map.get("Time")).getTime());
if (map.get("Count") != null && !"".equals(map.get("Count")))
longList.add(Long.parseLong(map.get("Count")));
@@ -199,7 +314,7 @@ public class AlarmController
e.printStackTrace();
}
- } );
+ });
startTimeL += timeIteraPlusVal;
tmpEndTimeL += timeIteraPlusVal;
keyVal += keyValIteraVal;
@@ -207,40 +322,40 @@ public class AlarmController
return dataList;
}
- private List<List<Long>> diagramDate(String sourceId,String startTime,String endTime,String format){
+ private List<List<Long>> diagramDate(String sourceId, String startTime, String endTime, String format) {
try {
long startTimel = sdf.parse(startTime).getTime();
long endTimel = sdf.parse(endTime).getTime();
- if (format != null && !format.equals("auto")){
- switch (format){
+ if (format != null && !format.equals("auto")) {
+ switch (format) {
case "minute":
- return dateProcess(sourceId,startTimel,endTimel,900000,15,15,"minute");
+ return dateProcess(sourceId, startTimel, endTimel, 900000, 15, 15, "minute");
case "hour":
- return dateProcess(sourceId,startTimel,endTimel,3600000,1,1,"hour");
+ return dateProcess(sourceId, startTimel, endTimel, 3600000, 1, 1, "hour");
case "day":
- return dateProcess(sourceId,startTimel,endTimel,86400000,1,1,"day");
+ return dateProcess(sourceId, startTimel, endTimel, 86400000, 1, 1, "day");
case "month":
- return dateProcess(sourceId,startTimel,endTimel,2592000000L,1,1,"month");
+ return dateProcess(sourceId, startTimel, endTimel, 2592000000L, 1, 1, "month");
case "year":
- return dateProcess(sourceId,startTimel,endTimel,31536000000L,1,1,"year");
+ return dateProcess(sourceId, startTimel, endTimel, 31536000000L, 1, 1, "year");
}
- }else if (format != null && format.equals("auto")){
+ } else if (format != null && format.equals("auto")) {
long minutes = (endTimel - startTimel) / (1000 * 60);
long hours = minutes / 60;
- if (hours > 12){
+ if (hours > 12) {
long days = hours / 24;
- if (days > 3){
+ if (days > 3) {
long months = days / 31;
- if (months > 2){
- return dateProcess(sourceId,startTimel,endTimel,86400000,1,1,"day");
- }else {
- return dateProcess(sourceId,startTimel,endTimel,2592000000L,1,1,"month");
+ if (months > 2) {
+ return dateProcess(sourceId, startTimel, endTimel, 86400000, 1, 1, "day");
+ } else {
+ return dateProcess(sourceId, startTimel, endTimel, 2592000000L, 1, 1, "month");
}
- }else {
- return dateProcess(sourceId,startTimel,endTimel,3600000,1,1,"hour");
+ } else {
+ return dateProcess(sourceId, startTimel, endTimel, 3600000, 1, 1, "hour");
}
- }else {
- return dateProcess(sourceId,startTimel,endTimel,900000,15,15,"minute");
+ } else {
+ return dateProcess(sourceId, startTimel, endTimel, 900000, 15, 15, "minute");
}
}
} catch (ParseException e) {
diff --git a/server/src/main/java/org/onap/usecaseui/server/controller/PerformanceController.java b/server/src/main/java/org/onap/usecaseui/server/controller/PerformanceController.java
index f534264b..eeddf6c2 100755
--- a/server/src/main/java/org/onap/usecaseui/server/controller/PerformanceController.java
+++ b/server/src/main/java/org/onap/usecaseui/server/controller/PerformanceController.java
@@ -120,16 +120,11 @@ public class PerformanceController {
list.add(pbo);
});
}
- try {
- Map<String, Object> map = new HashMap<>();
- map.put("performances", list);
- map.put("totalRecords", pa.getTotalRecords());
- omPerformance.setDateFormat(new SimpleDateFormat(Constant.DATE_FORMAT));
- return omPerformance.writeValueAsString(map);
- } catch (JsonProcessingException e) {
- logger.error("JsonProcessingException" + e.getMessage());
- return omPerformance.writeValueAsString("failed");
- }
+ Map<String, Object> map = new HashMap<>();
+ map.put("performances", list);
+ map.put("totalRecords", pa.getTotalRecords());
+ omPerformance.setDateFormat(new SimpleDateFormat(Constant.DATE_FORMAT));
+ return omPerformance.writeValueAsString(map);
}
/*@RequestMapping(value = {"/performance/genCsv/{eventId}"}, method = RequestMethod.GET, produces = "application/json")
@@ -198,10 +193,7 @@ public class PerformanceController {
@RequestMapping(value = {"/performance/diagram"}, method = RequestMethod.POST, produces = "application/json")
public String generateDiagram(@RequestParam String sourceId, @RequestParam String startTime, @RequestParam String endTime, @RequestParam String nameParent, @RequestParam String format) {
try {
- return omPerformance.writeValueAsString(diagramDate(sourceId,nameParent,startTime,endTime,format));
- } catch (JsonProcessingException e) {
- logger.error("JsonProcessingException:" + e.getMessage());
- return null;
+ return omPerformance.writeValueAsString(diagramDate(sourceId, nameParent, startTime, endTime, format));
} catch (Exception e) {
logger.error(e.getMessage());
e.printStackTrace();
@@ -213,14 +205,14 @@ public class PerformanceController {
public String getSourceIds() {
List<String> sourceIds = new ArrayList<>();
try {
- performanceHeaderService.queryAllSourceId().forEach( ph -> {
+ performanceHeaderService.queryAllSourceId().forEach(ph -> {
if (!sourceIds.contains(ph))
sourceIds.add(ph);
- } );
+ });
return omPerformance.writeValueAsString(sourceIds);
- } catch (JsonProcessingException e) {
+ } catch (Exception e) {
logger.error(e.getMessage());
- return "";
+ return null;
}
}
@@ -235,21 +227,21 @@ public class PerformanceController {
});
return omPerformance.writeValueAsString(names);
- } catch (JsonProcessingException e) {
+ } catch (Exception e) {
logger.error(e.getMessage());
return "";
}
}
- private List<List<Long>> dateProcess(String sourceId,String name,long startTimeL,long endTimeL,long timeIteraPlusVal,long keyVal,long keyValIteraVal,String keyUnit) throws ParseException {
+ private List<List<Long>> dateProcess(String sourceId, String name, long startTimeL, long endTimeL, long timeIteraPlusVal, long keyVal, long keyValIteraVal, String keyUnit) throws ParseException {
List<List<Long>> dataList = new ArrayList<>();
long tmpEndTimeL = startTimeL + timeIteraPlusVal;
- while (endTimeL >= tmpEndTimeL){
- List<Map<String,String>> maps = performanceInformationService.queryMaxValueByBetweenDate(sourceId,name,sdf.format(new Date(startTimeL)),sdf.format(new Date(tmpEndTimeL)));
- maps.forEach( map -> {
+ while (endTimeL >= tmpEndTimeL) {
+ List<Map<String, String>> maps = performanceInformationService.queryMaxValueByBetweenDate(sourceId, name, sdf.format(new Date(startTimeL)), sdf.format(new Date(tmpEndTimeL)));
+ maps.forEach(map -> {
try {
List<Long> longList = new ArrayList<>();
- if (map.get("Time") != null && !"".equals(map.get("Time")) && !"NULL".equals(map.get("Time")) ){
+ if (map.get("Time") != null && !"".equals(map.get("Time")) && !"NULL".equals(map.get("Time"))) {
longList.add(sdf.parse(map.get("Time")).getTime());
if (map.get("Max") != null && !"".equals(map.get("Max")))
longList.add(Long.parseLong(map.get("Max")));
@@ -269,40 +261,40 @@ public class PerformanceController {
return dataList;
}
- private List<List<Long>> diagramDate(String sourceId,String name,String startTime,String endTime,String format){
+ private List<List<Long>> diagramDate(String sourceId, String name, String startTime, String endTime, String format) {
try {
long startTimel = sdf.parse(startTime).getTime();
long endTimel = sdf.parse(endTime).getTime();
- if (format != null && !format.equals("auto")){
- switch (format){
+ if (format != null && !format.equals("auto")) {
+ switch (format) {
case "minute":
- return dateProcess(sourceId,name,startTimel,endTimel,900000,15,15,"minute");
+ return dateProcess(sourceId, name, startTimel, endTimel, 900000, 15, 15, "minute");
case "hour":
- return dateProcess(sourceId,name,startTimel,endTimel,3600000,1,1,"hour");
+ return dateProcess(sourceId, name, startTimel, endTimel, 3600000, 1, 1, "hour");
case "day":
- return dateProcess(sourceId,name,startTimel,endTimel,86400000,1,1,"day");
+ return dateProcess(sourceId, name, startTimel, endTimel, 86400000, 1, 1, "day");
case "month":
- return dateProcess(sourceId,name,startTimel,endTimel,2592000000L,1,1,"month");
+ return dateProcess(sourceId, name, startTimel, endTimel, 2592000000L, 1, 1, "month");
case "year":
- return dateProcess(sourceId,name,startTimel,endTimel,31536000000L,1,1,"year");
+ return dateProcess(sourceId, name, startTimel, endTimel, 31536000000L, 1, 1, "year");
}
- }else if (format != null && format.equals("auto")){
+ } else if (format != null && format.equals("auto")) {
long minutes = (endTimel - startTimel) / (1000 * 60);
long hours = minutes / 60;
- if (hours > 12){
+ if (hours > 12) {
long days = hours / 24;
- if (days > 3){
+ if (days > 3) {
long months = days / 31;
- if (months > 2){
- return dateProcess(sourceId,name,startTimel,endTimel,86400000,1,1,"day");
- }else {
- return dateProcess(sourceId,name,startTimel,endTimel,2592000000L,1,1,"month");
+ if (months > 2) {
+ return dateProcess(sourceId, name, startTimel, endTimel, 86400000, 1, 1, "day");
+ } else {
+ return dateProcess(sourceId, name, startTimel, endTimel, 2592000000L, 1, 1, "month");
}
- }else {
- return dateProcess(sourceId,name,startTimel,endTimel,3600000,1,1,"hour");
+ } else {
+ return dateProcess(sourceId, name, startTimel, endTimel, 3600000, 1, 1, "hour");
}
- }else {
- return dateProcess(sourceId,name,startTimel,endTimel,900000,15,15,"minute");
+ } else {
+ return dateProcess(sourceId, name, startTimel, endTimel, 900000, 15, 15, "minute");
}
}
} catch (ParseException e) {
diff --git a/server/src/main/java/org/onap/usecaseui/server/service/AlarmsHeaderService.java b/server/src/main/java/org/onap/usecaseui/server/service/AlarmsHeaderService.java
index b487f2b4..8d488d1f 100644
--- a/server/src/main/java/org/onap/usecaseui/server/service/AlarmsHeaderService.java
+++ b/server/src/main/java/org/onap/usecaseui/server/service/AlarmsHeaderService.java
@@ -16,6 +16,7 @@
package org.onap.usecaseui.server.service;
+import java.util.Date;
import java.util.List;
import org.onap.usecaseui.server.bean.AlarmsHeader;
@@ -26,7 +27,10 @@ public interface AlarmsHeaderService {
String saveAlarmsHeader(AlarmsHeader alarmsHeader);
String updateAlarmsHeader(AlarmsHeader alarmsHeader);
-
+
+ public String updateAlarmsHeader2018(String status, String date, String eventNameCleared,String eventName, String reportingEntityName,String specificProblem);
+
+ public Boolean getStatusBySourceName(String sourceName);
int getAllCount(AlarmsHeader alarmsHeader, int currentPage, int pageSize);
Page<AlarmsHeader> queryAlarmsHeader(AlarmsHeader alarmsHeader, int currentPage, int pageSize);
diff --git a/server/src/main/java/org/onap/usecaseui/server/service/impl/AlarmsHeaderServiceImpl.java b/server/src/main/java/org/onap/usecaseui/server/service/impl/AlarmsHeaderServiceImpl.java
index 17886074..43413d07 100755
--- a/server/src/main/java/org/onap/usecaseui/server/service/impl/AlarmsHeaderServiceImpl.java
+++ b/server/src/main/java/org/onap/usecaseui/server/service/impl/AlarmsHeaderServiceImpl.java
@@ -67,7 +67,44 @@ public class AlarmsHeaderServiceImpl implements AlarmsHeaderService {
}
}
-
+
+ @Override
+ public String updateAlarmsHeader2018(String status, String date,String eventNameCleared,String eventName, String reportingEntityName,String specificProblem) {
+
+ try(Session session = sessionFactory.getCurrentSession();){
+ logger.info("AlarmsInformationServiceImpl updateAlarmsInformation: alarmsInformation={}");
+ session.beginTransaction();
+ Query q=session.createQuery("update AlarmsHeader set status='"+status+"', eventName='"+eventNameCleared+"',updateTime='"+date+"' where eventName='"+eventName+"' and reportingEntityName='"+reportingEntityName+"' and specificProblem ='"+specificProblem+"' ");
+ q.executeUpdate();
+ session.getTransaction().commit();
+ session.flush();
+ return "1";
+ } catch (Exception e) {
+ logger.error("exception occurred while performing AlarmsInformationServiceImpl updateAlarmsInformation. Details:" + e.getMessage());
+ return "0";
+ }
+ }
+
+ @Override
+ public Boolean getStatusBySourceName(String sourceName) {
+ try(Session session = sessionFactory.openSession()){
+ logger.info("AlarmsInformationServiceImpl updateAlarmsInformation: alarmsInformation={}");
+ Query q=session.createQuery("select status from AlarmsHeader where sourceName='"+sourceName+"'");
+ String s=(String)q.uniqueResult();
+ Boolean status=false;
+ if(s!=null && "active".equals(s)){
+ status = true;
+ }else{
+ status = false;
+ }
+ session.flush();
+ return status;
+ } catch (Exception e) {
+ logger.error("exception occurred while performing AlarmsInformationServiceImpl updateAlarmsInformation. Details:" + e.getMessage());
+ return false;
+ }
+ }
+
@Override
public String updateAlarmsHeader(AlarmsHeader alarmsHeader) {
diff --git a/server/src/main/java/org/onap/usecaseui/server/util/DateUtils.java b/server/src/main/java/org/onap/usecaseui/server/util/DateUtils.java
index f4ac5263..a1d0e75d 100755
--- a/server/src/main/java/org/onap/usecaseui/server/util/DateUtils.java
+++ b/server/src/main/java/org/onap/usecaseui/server/util/DateUtils.java
@@ -25,6 +25,7 @@ import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;
+import java.util.TimeZone;
public class DateUtils {
@@ -91,4 +92,54 @@ public class DateUtils {
return new SimpleDateFormat(Constant.DATE_FORMAT).parse(dateToString(new Date()));
}
+ public String getYearMonthDayHourMinuteSecond(long timeMillis) {
+ Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT+8"));
+ calendar.setTimeInMillis(timeMillis);
+ int year=calendar.get(Calendar.YEAR);
+
+ int month=calendar.get(Calendar.MONTH) + 1;
+ String mToMonth=null;
+ if (String.valueOf(month).length()==1) {
+ mToMonth="0"+month;
+ } else {
+ mToMonth=String.valueOf(month);
+ }
+
+ int day=calendar.get(Calendar.DAY_OF_MONTH);
+ String dToDay=null;
+ if (String.valueOf(day).length()==1) {
+ dToDay="0"+day;
+ } else {
+ dToDay=String.valueOf(day);
+ }
+
+ int hour=calendar.get(Calendar.HOUR_OF_DAY);
+ String hToHour=null;
+ if (String.valueOf(hour).length()==1) {
+ hToHour="0"+hour;
+ } else {
+ hToHour=String.valueOf(hour);
+ }
+
+ int minute=calendar.get(Calendar.MINUTE);
+ String mToMinute=null;
+ if (String.valueOf(minute).length()==1) {
+ mToMinute="0"+minute;
+ } else {
+ mToMinute=String.valueOf(minute);
+ }
+
+ int second=calendar.get(Calendar.SECOND);
+ String sToSecond=null;
+ if (String.valueOf(second).length()==1) {
+ sToSecond="0"+second;
+ } else {
+ sToSecond=String.valueOf(second);
+ }
+ return year+ "-" +mToMonth+ "-" +dToDay+ " "+hToHour+ ":" +mToMinute+ ":" +sToSecond;
+ }
+
+ public static void main(String[] args) {
+ System.out.println(new DateUtils().getYearMonthDayHourMinuteSecond(System.currentTimeMillis()));
+ }
}
diff --git a/server/src/main/java/org/onap/usecaseui/server/util/DmaapSubscriber.java b/server/src/main/java/org/onap/usecaseui/server/util/DmaapSubscriber.java
index 7ae9e414..0632ed30 100644
--- a/server/src/main/java/org/onap/usecaseui/server/util/DmaapSubscriber.java
+++ b/server/src/main/java/org/onap/usecaseui/server/util/DmaapSubscriber.java
@@ -39,6 +39,8 @@ import java.io.IOException;
import java.io.InputStream;
import java.text.ParseException;
import java.text.SimpleDateFormat;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
import java.util.*;
@Component
@@ -202,16 +204,7 @@ public class DmaapSubscriber implements Runnable {
try {
List<Map<String, Object>> m = (List<Map<String, Object>>) v3;
m.forEach(i -> {
- if (i.get("name").toString().equals("eventTime"))
- try {
- alarm_header.setCreateTime(DateUtils.stringToDate(i.get("value").toString()));
- alarm_header.setUpdateTime(DateUtils.now());
- } catch (ParseException e) {
- e.printStackTrace();
- }
- else {
- alarm_informations.add(new AlarmsInformation(i.get("name").toString(), i.get("value").toString(), alarm_header.getSourceId(), null, new Date()));
- }
+ alarm_informations.add(new AlarmsInformation(i.get("name").toString(), i.get("value").toString(), alarm_header.getSourceId(), new Date(), null));
});
} catch (Exception e) {
e.printStackTrace();
@@ -222,38 +215,45 @@ public class DmaapSubscriber implements Runnable {
}
});
- if (alarm_header.getEventName() != null && alarm_informations.size() > 0){
+ if (alarm_header.getEventName() != null){
alarm_informations.forEach(ai -> {
ai.setCreateTime(alarm_header.getCreateTime());
ai.setUpdateTime(new Date());
});
+
+ Long startEpochMicrosec_s = Long.parseLong(alarm_header.getStartEpochMicrosec());
+ String date_get = new DateUtils().getYearMonthDayHourMinuteSecond(startEpochMicrosec_s);
+
if (alarm_header.getEventName().contains("Cleared")) {
- alarm_header.setStatus("3");
+ alarm_header.setStatus("close");
logger.info("alarmCleared data header insert is starting......");
- alarmsHeaderService.saveAlarmsHeader(alarm_header);
+ alarmsHeaderService.updateAlarmsHeader2018("close",date_get,alarm_header.getEventName(),alarm_header.getEventName().replace("Cleared",""),alarm_header.getReportingEntityName(),alarm_header.getSpecificProblem());
logger.info("alarmCleared data header insert has finished.");
logger.info("alarmCleared data detail insert is starting......");
alarm_informations.forEach(information ->
- alarmsInformationService.saveAlarmsInformation(information));
+ alarmsInformationService.saveAlarmsInformation(information));
+
logger.info("alarmCleared data detail insert has finished. " + alarm_informations.size() + " records have been inserted.");
AlarmsHeader header1 = new AlarmsHeader();
header1.setEventName(alarm_header.getEventName().substring(0, alarm_header.getEventName().indexOf("Cleared")));
List<AlarmsHeader> alarmsHeaders = alarmsHeaderService.queryAlarmsHeader(header1, 1, 10).getList();
alarmsHeaders.forEach(alarms -> {
alarms.setStatus("2");
- alarms.setUpdateTime(new Date());
+ alarms.setUpdateTime(alarm_header.getCreateTime());
alarmsHeaderService.updateAlarmsHeader(alarms);
});
} else {
- alarm_header.setUpdateTime(new Date());
- alarm_header.setStatus("1");
+ alarm_header.setCreateTime(new Date());
+ alarm_header.setStatus("active");
logger.info("alarm data header insert is starting......");
alarmsHeaderService.saveAlarmsHeader(alarm_header);
logger.info("alarm data header insert has finished.");
logger.info("alarm data detail insert is starting......");
- alarm_informations.forEach(information ->
- alarmsInformationService.saveAlarmsInformation(information));
- logger.info("alarm data detail insert has finished. " + alarm_informations.size() + " records have been inserted.");
+ if(alarm_informations.size() > 0) {
+ alarm_informations.forEach(information ->
+ alarmsInformationService.saveAlarmsInformation(information));
+ logger.info("alarm data detail insert has finished. " + alarm_informations.size() + " records have been inserted.");
+ }
}
}
}
@@ -305,29 +305,29 @@ public class DmaapSubscriber implements Runnable {
try {
List<Map<String, Object>> m = (List<Map<String, Object>>) v3;
m.forEach(i -> {
- if (i.containsKey("arrayOfFields")){
- List<Map<String,String>> arrayOfFields = (List<Map<String, String>>) i.get("arrayOfFields");
- arrayOfFields.forEach( fields -> {
- if (fields.get("name").equals("StartTime")){
- try {
- performance_informations.add(new PerformanceInformation(fields.get("name"),fields.get("value"),performance_header.getSourceId(),null,DateUtils.now()));
- performance_header.setCreateTime(DateUtils.stringToDate(fields.get("value").replaceAll(Constant.RegEX_DATE_FORMAT," ")));
- performance_header.setUpdateTime(DateUtils.now());
- } catch (ParseException e) {
- e.printStackTrace();
- }
- }else{
- try {
- performance_informations.add(new PerformanceInformation(fields.get("name"),fields.get("value"),performance_header.getSourceId(),null,DateUtils.now()));
- } catch (ParseException e) {
- e.printStackTrace();
+ i.forEach( (k,v) -> {
+ if (k.equals("arrayOfFields")){
+ List<Map<String,String>> arrayOfFields = (List<Map<String, String>>) v;
+ arrayOfFields.forEach( fields -> {
+ if (fields.get("name").equals("StartTime")){
+ try {
+ performance_informations.add(new PerformanceInformation(fields.get("name"),fields.get("value"),performance_header.getSourceId(),null,DateUtils.now()));
+ performance_header.setCreateTime(DateUtils.stringToDate(fields.get("value").replaceAll(Constant.RegEX_DATE_FORMAT," ")));
+ performance_header.setUpdateTime(DateUtils.now());
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ }else{
+ try {
+ performance_informations.add(new PerformanceInformation(fields.get("name"),fields.get("value"),performance_header.getSourceId(),null,DateUtils.now()));
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
}
- }
- } );
- }
-
+ } );
+ }
+ });
});
-
} catch (Exception e) {
e.printStackTrace();
logger.error("convert performanceAdditionalInformation error:" + e.getMessage());
diff --git a/standalone/src/main/assembly/resources/topologyD_data.json b/standalone/src/main/assembly/resources/topologyD_data.json
new file mode 100644
index 00000000..b945ae3a
--- /dev/null
+++ b/standalone/src/main/assembly/resources/topologyD_data.json
@@ -0,0 +1,21 @@
+{
+ "services":[
+ {"ServiceName":"VoLTE"},
+ {"ServiceName":"VoLTE_1"}
+ ],
+ "networkServices":[
+ {"nsName":"ns1","parentService":"VoLTE"},
+ {"nsName":"ns2","parentService":"VoLTE"},
+ {"nsName":"ns3","parentService":"VoLTE"}
+ ],
+ "VNFS":[
+ {"vnfName":"vnf_a_1","parentNS":"ns1"},
+ {"vnfName":"vnf_a_2","parentNS":"ns1"},
+ {"vnfName":"vnf_a_3","parentNS":"ns1"},
+ {"vnfName":"vnf_b_1","parentNS":"ns2"},
+ {"vnfName":"vnf_b_2","parentNS":"ns2"},
+ {"vnfName":"vnf_b_3","parentNS":"ns2"},
+ {"vnfName":"vnf_c_1","parentNS":"ns3"},
+ {"vnfName":"vnf_c_1","parentNS":"ns3"}
+ ]
+} \ No newline at end of file