package org.onap.usecaseui.server;
import org.onap.usecaseui.server.util.DmaapSubscriber;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
@SpringBootApplication
@ComponentScan(basePackages = "org.onap.usecaseui.server")
public class UsecaseuiServerApplication {
+
+ public static DmaapSubscriber dmaapSubscriber;
+ @Autowired
+ public void setDatastore(DmaapSubscriber dmaapSubscriber) {
+ UsecaseuiServerApplication.dmaapSubscriber = dmaapSubscriber;
+ }
+
@Bean
public RestTemplate getRestTemplate(){
return new RestTemplate();
public static void main(String[] args) {
SpringApplication.run(UsecaseuiServerApplication.class, args);
- DmaapSubscriber dmaapSubscriber = new DmaapSubscriber();
dmaapSubscriber.run();
}
}
-/*
+/**
* Copyright (C) 2017 CMCC, Inc. and others. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
@Entity
@Table(name="alarms_commoneventheader")
public class AlarmsHeader implements Serializable{
-
+
+ @Id
+ @Column(name = "id")
+ private String id;
+
@Column(name = "version")
private String version;
- @Id
@Column(name = "eventName")
private String eventName;
@Column(name = "lastEpochMicroSec")
private String lastEpochMicroSec;
+
+ @Column(name = "startEpochMicrosecCleared")
+ private String startEpochMicrosecCleared;
+
+ @Column(name = "lastEpochMicroSecCleared")
+ private String lastEpochMicroSecCleared;
+
@Column(name = "sequence")
private String sequence;
@Column(name = "updateTime")
private Date updateTime;
+
+
public AlarmsHeader() {
}
- public AlarmsHeader(String version, String eventName, String domain, String eventId, String eventType, String nfcNamingCode, String nfNamingCode, String sourceId, String sourceName, String reportingEntityId, String reportingEntityName, String priority, String startEpochMicrosec, String lastEpochMicroSec, String sequence, String faultFieldsVersion, String eventServrity, String eventSourceType, String eventCategory, String alarmCondition, String specificProblem, String vfStatus, String alarmInterfaceA, String status, Date createTime, Date updateTime) {
+ public AlarmsHeader(String version, String eventName, String domain, String eventId, String eventType, String nfcNamingCode, String nfNamingCode, String sourceId, String sourceName, String reportingEntityId, String reportingEntityName, String priority, String startEpochMicrosec, String lastEpochMicroSec, String startEpochMicrosecCleared, String lastEpochMicroSecCleared, String sequence, String faultFieldsVersion, String eventServrity, String eventSourceType, String eventCategory, String alarmCondition, String specificProblem, String vfStatus, String alarmInterfaceA, String status, Date createTime, Date updateTime) {
this.version = version;
this.eventName = eventName;
this.domain = domain;
this.priority = priority;
this.startEpochMicrosec = startEpochMicrosec;
this.lastEpochMicroSec = lastEpochMicroSec;
+ this.startEpochMicrosecCleared = startEpochMicrosecCleared;
+ this.lastEpochMicroSecCleared = lastEpochMicroSecCleared;
this.sequence = sequence;
this.faultFieldsVersion = faultFieldsVersion;
this.eventServrity = eventServrity;
this.startEpochMicrosec = startEpochMicrosec;
}
+ public String getStartEpochMicrosecCleared() {
+ return startEpochMicrosecCleared;
+ }
+
+ public void setStartEpochMicrosecCleared(String startEpochMicrosecCleared) {
+ this.startEpochMicrosecCleared = startEpochMicrosecCleared;
+ }
+
+ public String getLastEpochMicroSecCleared() {
+ return lastEpochMicroSecCleared;
+ }
+
+ public void setLastEpochMicroSecCleared(String lastEpochMicroSecCleared) {
+ this.lastEpochMicroSecCleared = lastEpochMicroSecCleared;
+ }
+
public String getLastEpochMicroSec() {
return lastEpochMicroSec;
}
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
-
-
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
}
@Column(name = "value")
private String value;
- @Column(name = "eventId")
- private String eventId;
+ @Column(name = "sourceId")
+ private String sourceId;
@Column(name = "createTime")
private Date createTime;
@Column(name = "updateTime")
private Date updateTime;
-
+
+ @Column(name = "headerId")
+ private String headerId;
+
@Override
public String toString() {
return "AlarmsInformation{" +
"id=" + id +
", name='" + name + '\'' +
", value='" + value + '\'' +
- ", eventId='" + eventId + '\'' +
+ ", sourceId='" + sourceId + '\'' +
", createTime=" + createTime +
", updateTime=" + updateTime +
+ ", headerId=" + headerId +
'}';
}
public AlarmsInformation() {
}
- public AlarmsInformation(String eventId) {
- this.eventId = eventId;
+ public AlarmsInformation(String sourceId) {
+ this.sourceId = sourceId;
}
- public AlarmsInformation(String name, String value, String eventId, Date createTime, Date updateTime) {
+ public AlarmsInformation(String name, String value, String sourceId, Date createTime, Date updateTime,String headerId) {
this.name = name;
this.value = value;
- this.eventId = eventId;
+ this.sourceId = sourceId;
this.createTime = createTime;
this.updateTime = updateTime;
+ this.headerId = headerId;
}
public String getName() {
this.value = value;
}
- public String getEventId() {
- return eventId;
+ public String getSourceId() {
+ return sourceId;
}
- public void setEventId(String eventId) {
- this.eventId = eventId;
+ public void setSourceId(String sourceId) {
+ this.sourceId = sourceId;
}
public Date getCreateTime() {
public void setId(int id) {
this.id = id;
}
-
+
+ public String getHeaderId() {
+ return headerId;
+ }
+
+ public void setHeaderId(String headerId) {
+ this.headerId = headerId;
+ }
}
-/*\r
+/**\r
* Copyright (C) 2017 CMCC, Inc. and others. All rights reserved.\r
*\r
* Licensed under the Apache License, Version 2.0 (the "License");\r
@Entity\r
@Table(name="performance_commoneventheader")\r
public class PerformanceHeader implements Serializable {\r
- \r
+\r
+ @Id\r
+ @Column(name = "id")\r
+ private String id;\r
+\r
@Column(name = "version")\r
private String version;\r
\r
- @Id\r
@Column(name = "eventName")\r
private String eventName;\r
\r
\r
@Column(name = "updateTime")\r
private Date updateTime;\r
-\r
+ \r
public PerformanceHeader() {\r
}\r
\r
this.updateTime = updateTime;\r
}\r
\r
- \r
- \r
+ public String getId() {\r
+ return id;\r
+ }\r
+\r
+ public void setId(String id) {\r
+ this.id = id;\r
+ }\r
\r
}\r
@Column(name = "value")\r
private String value;\r
\r
- @Column(name = "eventId")\r
- private String eventId;\r
+ @Column(name = "sourceId")\r
+ private String sourceId;\r
\r
@Column(name = "createTime")\r
private Date createTime;\r
\r
@Column(name = "updateTime")\r
private Date updateTime;\r
-\r
+ \r
+ @Column(name="headerId")\r
+ private String headerId;\r
+ \r
public PerformanceInformation() {\r
}\r
\r
- public PerformanceInformation(String eventId) {\r
- this.eventId = eventId;\r
+ public PerformanceInformation(String sourceId) {\r
+ this.sourceId = sourceId;\r
}\r
\r
- public PerformanceInformation(String name, String value, String eventId, Date createTime, Date updateTime) {\r
+ public PerformanceInformation(String name, String value, String sourceId, Date createTime, Date updateTime,String headerId) {\r
this.name = name;\r
this.value = value;\r
- this.eventId = eventId;\r
+ this.sourceId = sourceId;\r
this.createTime = createTime;\r
this.updateTime = updateTime;\r
+ this.headerId = headerId;\r
}\r
\r
public String getName() {\r
this.value = value;\r
}\r
\r
- public String getEventId() {\r
- return eventId;\r
+ public String getSourceId() {\r
+ return sourceId;\r
}\r
\r
- public void setEventId(String eventId) {\r
- this.eventId = eventId;\r
+ public void setSourceId(String sourceId) {\r
+ this.sourceId = sourceId;\r
}\r
\r
public Date getCreateTime() {\r
public void setId(int id) {\r
this.id = id;\r
}\r
- \r
+\r
+ public String getHeaderId() {\r
+ return headerId;\r
+ }\r
+\r
+ public void setHeaderId(String headerId) {\r
+ this.headerId = headerId;\r
+ }\r
\r
}\r
import org.onap.usecaseui.server.util.DateUtils;\r
import org.onap.usecaseui.server.util.Page;\r
import org.onap.usecaseui.server.util.ResponseUtil;\r
+import org.onap.usecaseui.server.util.UuiCommonUtil;\r
import org.slf4j.Logger;\r
import org.slf4j.LoggerFactory;\r
import org.springframework.context.annotation.EnableAspectJAutoProxy;\r
AlarmBo abo = new AlarmBo();\r
abo.setAlarmsHeader(a);\r
AlarmsInformation information = new AlarmsInformation();\r
- information.setEventId(a.getSourceId());\r
+ information.setSourceId(a.getSourceId());\r
List<AlarmsInformation> informationList = alarmsInformationService.queryAlarmsInformation(information,1,100).getList();\r
informationList.forEach( il -> {\r
if (il.getValue().equals("")){\r
return "";\r
}\r
}\r
+ \r
+ @RequestMapping(value = "/alarm/statusCount", method = RequestMethod.GET, produces = "application/json")\r
+ public String getStatusCount() throws JsonProcessingException {\r
+ List<String> statusCount = new ArrayList<>();\r
+\r
+ statusCount.add(alarmsHeaderService.queryStatusCount("0"));\r
+ statusCount.add(alarmsHeaderService.queryStatusCount("active"));\r
+ statusCount.add(alarmsHeaderService.queryStatusCount("close"));\r
+ return omAlarm.writeValueAsString(statusCount);\r
+ }\r
+ \r
+ @RequestMapping("/alarm/getAlarmsHeaderDetail/{id}")\r
+ public String getAlarmsHeaderDetail(@PathVariable String id) throws JsonProcessingException {\r
+ AlarmsHeader alarmsHeader= alarmsHeaderService.getAlarmsHeaderById(id);\r
+ List<AlarmsInformation> list =new ArrayList<>();\r
+ if(UuiCommonUtil.isNotNullOrEmpty(alarmsHeader)){\r
+ String headerId = alarmsHeader.getId();\r
+ list = alarmsInformationService.getAllAlarmsInformationByHeaderId(headerId);\r
+ }\r
\r
+ Map map = new HashMap();\r
+ map.put("alarmsHeader",alarmsHeader);\r
+ map.put("list",list);\r
+\r
+ String string =omAlarm.writeValueAsString(map);\r
+ return string;\r
+ }\r
}\r
package org.onap.usecaseui.server.controller;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletResponse;
+
import org.onap.usecaseui.server.bean.PerformanceHeader;
import org.onap.usecaseui.server.bean.PerformanceInformation;
import org.onap.usecaseui.server.bo.PerformanceBo;
import org.onap.usecaseui.server.service.PerformanceInformationService;
import org.onap.usecaseui.server.util.DateUtils;
import org.onap.usecaseui.server.util.Page;
-import org.onap.usecaseui.server.util.ResponseUtil;
+import org.onap.usecaseui.server.util.UuiCommonUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.RestController;
-import javax.annotation.Resource;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.*;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
@RestController
performanceHeaders.forEach( per ->{
PerformanceBo pbo = new PerformanceBo();
PerformanceInformation pe = new PerformanceInformation();
- pe.setEventId(per.getSourceId());
+ pe.setSourceId(per.getSourceId());
List<PerformanceInformation> performanceInformations = performanceInformationService.queryPerformanceInformation(pe,1,100).getList();
pbo.setPerformanceHeader(per);
performanceInformations.forEach( pi ->{
@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(required = false) String nameChild) {
- List<Integer> diagramSource = new ArrayList<>();
+ List<String> diagramSource = new ArrayList<>();
try {
logger.info(sourceId+":"+startTime+":"+endTime+":"+nameParent+":"+nameChild);
if (performanceHeaderService.queryPerformanceHeader(new PerformanceHeader(sourceId),1,10).getList() != null){
}
performanceInformationService.queryDateBetween(sourceId,nameParent,startTime,endTime)
.forEach( per -> {
- diagramSource.add(Integer.parseInt(per.getValue()));
+ diagramSource.add(per.getValue());
});
}
} catch (Exception e) {
return "";
}
}
+
+ @RequestMapping("/performance/getPerformanceHeaderDetail/{id}")
+ public String getPerformanceHeaderDetail(@PathVariable String id) throws JsonProcessingException {
+ PerformanceHeader performanceHeader= performanceHeaderService.getPerformanceHeaderById(id);
+ List<PerformanceInformation> list =new ArrayList<>();
+ if(UuiCommonUtil.isNotNullOrEmpty(performanceHeader)){
+ String headerId = performanceHeader.getId();
+ list = performanceInformationService.getAllPerformanceInformationByHeaderId(headerId);
+ }
+
+ Map map = new HashMap();
+ map.put("performanceHeader",performanceHeader);
+ map.put("list",list);
+
+ String string =omPerformance.writeValueAsString(map);
+ return string;
+ }
}
package org.onap.usecaseui.server.service;
+import java.sql.Timestamp;
import java.util.List;
import org.onap.usecaseui.server.bean.AlarmsHeader;
Page<AlarmsHeader> queryAlarmsHeader(AlarmsHeader alarmsHeader, int currentPage, int pageSize);
List<AlarmsHeader> queryId(String[] id);
+
+ public String updateAlarmsHeader2018(String status, Timestamp date, String startEpochMicrosecCleared, String lastEpochMicroSecCleared, String eventName, String reportingEntityName, String specificProblem);
+
+ /**
+ *
+ * queryStatusCount
+ *
+ * @Auther YYY
+ * @Date 2018/5/17 15:59:23
+ * @Title: queryStatusCount
+ * @Description:
+ * @param status
+ * @return
+ */
+ String queryStatusCount(String status);
+
+ /**
+ *
+ * getAlarmsHeaderById
+ *
+ * @Auther YYY
+ * @Date 2018/5/17 16:05:59
+ * @Title: getAlarmsHeaderById
+ * @Description:
+ * @param id
+ * @return
+ */
+ AlarmsHeader getAlarmsHeaderById(String id);
}
List<AlarmsInformation> queryId(String[] id);
List<Map<String,String>> queryDateBetween(String sourceId, String startTime, String endTime);
+
+ /**
+ *
+ * getAllAlarmsInformationByHeaderId
+ *
+ * @Auther YYY
+ * @Date 2018/5/17 16:10:26
+ * @Title: getAllAlarmsInformationByHeaderId
+ * @Description:
+ * @param id
+ * @return
+ */
+ List<AlarmsInformation> getAllAlarmsInformationByHeaderId(String id);
}
import java.util.List;
-import org.onap.usecaseui.server.bean.AlarmsHeader;
import org.onap.usecaseui.server.bean.PerformanceHeader;
import org.onap.usecaseui.server.util.Page;
List<PerformanceHeader> queryId(String[] id);
List<String> queryAllSourceId();
+
+ PerformanceHeader getPerformanceHeaderById(String id);
}
import java.util.Date;
import java.util.List;
-import org.onap.usecaseui.server.bean.AlarmsInformation;
import org.onap.usecaseui.server.bean.PerformanceInformation;
import org.onap.usecaseui.server.util.Page;
int queryDataBetweenSum(String eventId, String name, Date startDate, Date endDate);
List<PerformanceInformation> queryDateBetween(String resourceId, String name, String startTime, String endTime);
-
+
+ List<PerformanceInformation> getAllPerformanceInformationByHeaderId(String headerId);
}
package org.onap.usecaseui.server.service.impl;\r
\r
\r
+import java.sql.Timestamp;\r
import java.text.SimpleDateFormat;\r
import java.util.ArrayList;\r
import java.util.Date;\r
return null;\r
}\r
}\r
+ \r
+ @Override\r
+ public String updateAlarmsHeader2018(String status, Timestamp date, String startEpochMicrosecCleared, String lastEpochMicroSecCleared, String eventName, String reportingEntityName, String specificProblem) {\r
+\r
+ try(Session session = getSession()){\r
+ //try(Session session = sessionFactory.getCurrentSession();){\r
+ session.beginTransaction();\r
+\r
+ //Query q=session.createQuery("update AlarmsHeader set status='"+status+"', updateTime='"+date+"' , startEpochMicrosecCleared='"+startEpochMicrosecCleared+"' ,lastEpochMicroSecCleared='"+lastEpochMicroSecCleared+"' where eventName='"+eventName+"' and reportingEntityName='"+reportingEntityName+"' and specificProblem ='"+specificProblem+"'");\r
+ Query q=session.createQuery("update AlarmsHeader set status=:status, updateTime=:date, startEpochMicrosecCleared=:startEpochMicrosecCleared ,lastEpochMicroSecCleared=:lastEpochMicroSecCleared where eventName=:eventName and reportingEntityName=:reportingEntityName and specificProblem =:specificProblem");\r
+\r
+ q.setString("status",status);\r
+ q.setDate("date",date);\r
+\r
+ q.setString("startEpochMicrosecCleared",startEpochMicrosecCleared);\r
+ q.setString("lastEpochMicroSecCleared",lastEpochMicroSecCleared);\r
+ q.setString("eventName",eventName);\r
+ q.setString("reportingEntityName",reportingEntityName);\r
+ q.setString("specificProblem",specificProblem);\r
+\r
+\r
+ q.executeUpdate();\r
+ session.getTransaction().commit();\r
+ session.flush();\r
+ return "1";\r
+ } catch (Exception e) {\r
+ logger.error("exception occurred while performing AlarmsInformationServiceImpl updateAlarmsInformation. Details:" + e.getMessage());\r
+ return "0";\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public String queryStatusCount(String status) {\r
+ try(Session session = sessionFactory.openSession()){\r
+ String hql = "select count(status) from AlarmsHeader a";\r
+ if (!status.equals("0"))\r
+ hql+=" where a.status = :status";\r
+ Query query = session.createQuery(hql);\r
+ if (!status.equals("0"))\r
+ query.setString("status",status);\r
+ return query.uniqueResult().toString();\r
+ } catch (Exception e) {\r
+ logger.error("exception occurred while performing AlarmsHeaderServiceImpl queryStatusCount. Details:" + e.getMessage());\r
+ return null;\r
+ }\r
+ }\r
+ \r
+ @Override\r
+ public AlarmsHeader getAlarmsHeaderById(String id) {\r
+ try(Session session = sessionFactory.openSession()) {\r
+\r
+ String string = "from AlarmsHeader a where 1=1 and a.id=:id";\r
+ Query q = session.createQuery(string);\r
+ q.setString("id",id);\r
+ AlarmsHeader alarmsHeader =(AlarmsHeader)q.uniqueResult();\r
+ session.flush();\r
+ return alarmsHeader;\r
+\r
+ }catch (Exception e){\r
+ logger.error("exception occurred while performing AlarmsHeaderServiceImpl getAlarmsHeaderDetail."+e.getMessage());\r
+ return null;\r
+ }\r
+ }\r
}\r
String ver=alarmsInformation.getValue();\r
hql.append(" and a.value like '%"+ver+"%'");\r
}\r
- if(null!=alarmsInformation.getEventId()) {\r
- String ver=alarmsInformation.getEventId();\r
- hql.append(" and a.eventId = '"+ver+"'");\r
+ if(null!=alarmsInformation.getSourceId()) {\r
+ String ver=alarmsInformation.getSourceId();\r
+ hql.append(" and a.sourceId = '"+ver+"'");\r
}\r
if(null!=alarmsInformation.getCreateTime()) {\r
Date ver =alarmsInformation.getCreateTime();\r
String ver=alarmsInformation.getValue();\r
hql.append(" and a.value like '%"+ver+"%'");\r
}\r
- if(null!=alarmsInformation.getEventId()) {\r
- String ver=alarmsInformation.getEventId();\r
- hql.append(" and a.eventId = '"+ver+"'");\r
+ if(null!=alarmsInformation.getSourceId()) {\r
+ String ver=alarmsInformation.getSourceId();\r
+ hql.append(" and a.sourceId = '"+ver+"'");\r
}\r
if(null!=alarmsInformation.getCreateTime()) {\r
Date ver =alarmsInformation.getCreateTime();\r
}\r
List<AlarmsInformation> list = new ArrayList<AlarmsInformation>();\r
Session session = getSession();\r
- Query query = session.createQuery("from AlarmsInformation a where a.eventId IN (:alist)");\r
+ Query query = session.createQuery("from AlarmsInformation a where a.sourceId IN (:alist)");\r
list = query.setParameterList("alist", id).list();\r
session.close();\r
return list;\r
List<Map<String,String>> mapList = new ArrayList<>();\r
String hql = "select a.createTime,count(*) from AlarmsInformation a where 1=1 ";\r
if (sourceId != null && !"".equals(sourceId)){\r
- hql += " and a.eventId = :sourceId";\r
+ hql += " and a.sourceId = :sourceId";\r
}\r
if (startTime != null && !"".equals(startTime) && endTime != null && !"".equals(endTime)){\r
hql += " and a.createTime between :startTime and :endTime ";\r
return null;\r
}\r
}\r
+\r
+ @Override\r
+ public List<AlarmsInformation> getAllAlarmsInformationByHeaderId(String headerId) {\r
+ try (Session session = getSession()){\r
+ String string = "from AlarmsInformation a where 1=1 and a.headerId=:headerId";\r
+ Query query = session.createQuery(string);\r
+ query.setString("headerId",headerId);\r
+ List<AlarmsInformation> list = query.list();\r
+ session.flush();\r
+ return list;\r
+ }catch (Exception e){\r
+ logger.error("exception occurred while performing PerformanceInformationServiceImpl queryDateBetween. LIST:" + e.getMessage());\r
+\r
+ return null;\r
+ }\r
+ }\r
}\r
\r
\r
import java.util.ArrayList;\r
-import java.util.Date;\r
import java.util.List;\r
\r
import javax.transaction.Transactional;\r
return null;\r
}\r
}\r
+ \r
+ @Override\r
+ public PerformanceHeader getPerformanceHeaderById(String id) {\r
+ try(Session session = sessionFactory.openSession()) {\r
+\r
+ String string = "from PerformanceHeader a where 1=1 and a.id=:id";\r
+ Query q = session.createQuery(string);\r
+ q.setString("id",id);\r
+ PerformanceHeader performanceHeader =(PerformanceHeader)q.uniqueResult();\r
+ session.flush();\r
+ return performanceHeader;\r
+\r
+ }catch (Exception e){\r
+ logger.error("exception occurred while performing PerformanceHeaderServiceImpl getPerformanceHeaderById."+e.getMessage());\r
+ return null;\r
+ }\r
+ }\r
}\r
package org.onap.usecaseui.server.service.impl;\r
\r
\r
-import java.text.SimpleDateFormat;\r
import java.util.ArrayList;\r
import java.util.Date;\r
import java.util.List;\r
\r
-import javax.persistence.Id;\r
import javax.transaction.Transactional;\r
\r
-import org.hibernate.*;\r
+import org.hibernate.Query;\r
+import org.hibernate.Session;\r
+import org.hibernate.SessionFactory;\r
+import org.hibernate.Transaction;\r
import org.onap.usecaseui.server.bean.PerformanceInformation;\r
import org.onap.usecaseui.server.service.PerformanceInformationService;\r
-import org.onap.usecaseui.server.util.DateUtils;\r
import org.onap.usecaseui.server.util.Page;\r
import org.slf4j.Logger;\r
import org.slf4j.LoggerFactory;\r
String ver=performanceInformation.getValue();\r
hql.append(" and a.value like '%"+ver+"%'");\r
}\r
- if(null!=performanceInformation.getEventId()) {\r
- String ver=performanceInformation.getEventId();\r
- hql.append(" and a.eventId = '"+ver+"'");\r
+ if(null!=performanceInformation.getSourceId()) {\r
+ String ver=performanceInformation.getSourceId();\r
+ hql.append(" and a.sourceId = '"+ver+"'");\r
}\r
if(null!=performanceInformation.getCreateTime()) {\r
Date ver =performanceInformation.getCreateTime();\r
String ver=performanceInformation.getValue();\r
hql.append(" and a.value like '%"+ver+"%'");\r
}\r
- if(null!=performanceInformation.getEventId()) {\r
- String ver=performanceInformation.getEventId();\r
- hql.append(" and a.eventId = '"+ver+"'");\r
+ if(null!=performanceInformation.getSourceId()) {\r
+ String ver=performanceInformation.getSourceId();\r
+ hql.append(" and a.sourceId = '"+ver+"'");\r
}\r
if(null!=performanceInformation.getCreateTime()) {\r
Date ver =performanceInformation.getCreateTime();\r
logger.error("PerformanceInformationServiceImpl queryId is null!");\r
}\r
List<PerformanceInformation> list = new ArrayList<>();\r
- Query query = session.createQuery("from PerformanceInformation a where a.eventId IN (:alist)");\r
+ Query query = session.createQuery("from PerformanceInformation a where a.sourceId IN (:alist)");\r
list = query.setParameterList("alist", id).list();\r
return list;\r
} catch (Exception e) {\r
\r
@SuppressWarnings("unchecked")\r
@Override\r
- public List<PerformanceInformation> queryDateBetween(String eventId, Date startDate, Date endDate) {\r
+ public List<PerformanceInformation> queryDateBetween(String sourceId, Date startDate, Date endDate) {\r
try(Session session = getSession()) {\r
List<PerformanceInformation> list = new ArrayList<>();\r
- Query query = session.createQuery("from PerformanceInformation a where a.eventId = :eventId and a.createTime BETWEEN :startDate and :endDate");\r
- list = query.setParameter("eventId",eventId).setParameter("startDate", startDate).setParameter("endDate",endDate).list();\r
+ Query query = session.createQuery("from PerformanceInformation a where a.sourceId = :sourceId and a.createTime BETWEEN :startDate and :endDate");\r
+ list = query.setParameter("sourceId",sourceId).setParameter("startDate", startDate).setParameter("endDate",endDate).list();\r
logger.info("PerformanceInformationServiceImpl queryDateBetween: list={}", list);\r
return list;\r
} catch (Exception e) {\r
\r
@SuppressWarnings("unchecked")\r
@Override\r
- public int queryDataBetweenSum(String eventId, String name, Date startDate, Date endDate){\r
+ public int queryDataBetweenSum(String sourceId, String name, Date startDate, Date endDate){\r
try(Session session = getSession()) {\r
int sum = 0;\r
- Query query = session.createQuery("select sum(a.value) from PerformanceInformation a where a.eventId = :eventId and a.name = :name and a.createTime BETWEEN :startDate and :endDate");\r
- sum = Integer.parseInt(query.setParameter("eventId",eventId).setParameter("name",name).setParameter("startDate", startDate).setParameter("endDate",endDate).uniqueResult().toString());\r
+ Query query = session.createQuery("select sum(a.value) from PerformanceInformation a where a.sourceId = :sourceId and a.name = :name and a.createTime BETWEEN :startDate and :endDate");\r
+ sum = Integer.parseInt(query.setParameter("sourceId",sourceId).setParameter("name",name).setParameter("startDate", startDate).setParameter("endDate",endDate).uniqueResult().toString());\r
logger.info("PerformanceInformationServiceImpl queryDataBetweenSum: sum={}", sum);\r
return sum;\r
} catch (Exception e) {\r
try(Session session = getSession()) {\r
String hql = "from PerformanceInformation a where 1=1 ";\r
if (resourceId != null && !"".equals(resourceId)){\r
- hql += " and a.eventId = :resourceId";\r
+ hql += " and a.sourceId = :resourceId";\r
}\r
if (name != null && !"".equals(name)){\r
hql += " and a.name = :name ";\r
return null;\r
}\r
}\r
+ \r
+ @Override\r
+ public List<PerformanceInformation> getAllPerformanceInformationByHeaderId(String headerId) {\r
+ try (Session session = getSession()){\r
+ String string = "from PerformanceInformation a where 1=1 and a.headerId=:headerId";\r
+ Query query = session.createQuery(string);\r
+ query.setString("headerId",headerId);\r
+ List<PerformanceInformation> list = query.list();\r
+ session.flush();\r
+ return list;\r
+ }catch (Exception e){\r
+ logger.error("exception occurred while performing PerformanceInformationServiceImpl queryDateBetween. LIST:" + e.getMessage());\r
+\r
+ return null;\r
+ }\r
+ }\r
}\r
*/
package org.onap.usecaseui.server.util;
-import com.fasterxml.jackson.databind.ObjectMapper;
+import java.io.IOException;
+import java.io.InputStream;
+import java.sql.Timestamp;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import javax.annotation.Resource;
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Response;
+
import org.glassfish.jersey.client.ClientConfig;
import org.onap.usecaseui.server.bean.AlarmsHeader;
import org.onap.usecaseui.server.bean.AlarmsInformation;
import org.onap.usecaseui.server.service.PerformanceInformationService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.context.annotation.EnableAspectJAutoProxy;
+import org.springframework.stereotype.Component;
-import javax.annotation.Resource;
-import javax.ws.rs.client.Client;
-import javax.ws.rs.client.ClientBuilder;
-import javax.ws.rs.client.WebTarget;
-import javax.ws.rs.core.Response;
-import java.io.*;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.*;
+import com.fasterxml.jackson.databind.ObjectMapper;
-@org.springframework.context.annotation.Configuration
-@EnableAspectJAutoProxy
+@Component
public class DmaapSubscriber implements Runnable {
private Logger logger = LoggerFactory.getLogger(DmaapSubscriber.class);
@Resource(name = "PerformanceInformationService")
private PerformanceInformationService performanceInformationService;
- public void subscribe(String topic) {
- String response;
+ public void subscribe(String topic) {
try {
- response = getDMaaPData(topic);
- logger.info(response);
- if (response == null && "".equals(response)) {
- logger.info("response is null");
+ List<String> respList = getDMaaPData(topic);
+ if (respList.size() <= 0 || respList == null) {
+ logger.info("response content is :"+respList);
return;
- } else {
- ObjectMapper objMapper = new ObjectMapper();
- objMapper.setDateFormat(new SimpleDateFormat(Constant.DATE_FORMAT));
- if (response.contains("}}\""))
- response = response.replaceAll("}}\"","}}");
- if (response.contains("\"{\"VESversion\""))
- response = response.replaceAll("\"\\{\"VESversion\"","{\"VESversion\"");
- if (response.contains("]\""))
- response = response.replaceAll("]\"","]");
- if (response.contains("\"["))
- response = response.replaceAll("\"\\[","[");
- if (response.contains("Remark:\""))
- response = response.replaceAll("Remark:\"",":");
- if (response.contains("\";"))
- response = response.replaceAll("\";",";");
-
- if (response.indexOf("[") == 0) {
- List<Object> eventList = objMapper.readValue(response, List.class);
-
- eventList.forEach(el -> {
- Map<String, Object> eventMaps = (Map<String, Object>) ((Map<String, Object>) el).get("event");
- if (eventMaps.containsKey("measurementsForVfScalingFields")) {
- performanceProcess(eventMaps);
- } else if (eventMaps.containsKey("faultFields")) {
- alarmProcess(eventMaps);
- }
- });
- } else if (response.indexOf("{") == 0) {
- Map<String, Object> eventMaps = (Map<String, Object>) objMapper.readValue(response, Map.class).get("event");
-
+ }
+ ObjectMapper objMapper = new ObjectMapper();
+ objMapper.setDateFormat(new SimpleDateFormat(Constant.DATE_FORMAT));
+ respList.forEach(rl -> {
+ try {
+ Map<String, Object> eventMaps = (Map<String, Object>) objMapper.readValue(rl, Map.class).get("event");
if (eventMaps.containsKey("measurementsForVfScalingFields")) {
performanceProcess(eventMaps);
} else if (eventMaps.containsKey("faultFields")) {
alarmProcess(eventMaps);
}
- } else {
- logger.error("unknown json type!");
+ } catch (IOException e) {
+ e.printStackTrace();
+ logger.error(rl);
+ logger.error("exception occurred while performing DmaapSubcriber performanceProcess or alarmProcess. Details:"+ e.getMessage());
+
}
- }
+ });
+
} catch (Exception e) {
+ e.printStackTrace();
logger.error("getDMaaP Information failed :" + e.getMessage());
}
}
- private String getDMaaPData(String topic) {
+ private List<String> getDMaaPData(String topic) {
Client client = ClientBuilder.newClient(new ClientConfig());
WebTarget webTarget = client.target(url + "/" + topic + "/" + consumerGroup + "/" + consumer);
Response response = webTarget.queryParam("timeout", timeout).request().get();
- return response.readEntity(String.class);
+ return response.readEntity(List.class);
}
private void initConfig() {
private void alarmProcess(Map<String, Object> eventMap) {
AlarmsHeader alarm_header = new AlarmsHeader();
+ alarm_header.setId(UuiCommonUtil.getUUID());
List<AlarmsInformation> alarm_informations = new ArrayList<>();
eventMap.forEach((ek1, ev1) -> {
if (ek1.equals("commonEventHeader")) {
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.stringToDate(i.get("value").toString()));
- } catch (ParseException e) {
- e.printStackTrace();
- }
- if (i.get("value").toString().contains(";")) {
- alarm_informations.add(new AlarmsInformation(i.get("name").toString(), "", alarm_header.getSourceId(), null, null));
- char[] valStr = i.get("value").toString().toCharArray();
- String name = "";
- String value = "";
- boolean nameFlag = true;
- boolean valueFlag = false;
- for (int j = 0; j < valStr.length; j++) {
- if (valStr[j] == ':') {
- nameFlag = false;
- valueFlag = true;
- continue;
- }
- if (valStr[j] == ';') {
- nameFlag = true;
- valueFlag = false;
- alarm_informations.add(new AlarmsInformation(name, value, i.get("name").toString(), null, null));
- continue;
- }
- if (nameFlag)
- name += valStr[j];
- if (valueFlag)
- value += valStr[j];
- }
- } else {
- alarm_informations.add(new AlarmsInformation(i.get("name").toString(), i.get("value").toString(), alarm_header.getSourceId(), null, null));
- }
+ alarm_informations.add(new AlarmsInformation(i.get("name").toString(), i.get("value").toString(), alarm_header.getSourceId(), new Date(), null,alarm_header.getId()));
});
} catch (Exception e) {
e.printStackTrace();
}
}
});
- alarm_informations.forEach(ai -> {
- ai.setCreateTime(alarm_header.getCreateTime());
- ai.setUpdateTime(new Date());
- });
- if (alarm_header.getEventName().contains("Cleared")) {
- alarm_header.setStatus("3");
- alarmsHeaderService.saveAlarmsHeader(alarm_header);
- alarm_informations.forEach(information ->
- alarmsInformationService.saveAlarmsInformation(information));
- 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());
- alarmsHeaderService.updateAlarmsHeader(alarms);
- });
- } else {
- alarm_header.setUpdateTime(new Date());
- alarm_header.setStatus("1");
- alarmsHeaderService.saveAlarmsHeader(alarm_header);
- alarm_informations.forEach(information ->
- alarmsInformationService.saveAlarmsInformation(information));
- }
}
});
+ if (alarm_header.getEventName() != null){
+ alarm_informations.forEach(ai -> {
+ ai.setCreateTime(alarm_header.getCreateTime());
+ ai.setUpdateTime(new Date());
+ });
+ Long l = System.currentTimeMillis();
+
+ Timestamp date_get = new Timestamp(l);
+ if (alarm_header.getEventName().contains("Cleared")) {
+ alarm_header.setStatus("close");
+ alarmsHeaderService.updateAlarmsHeader2018("close", date_get, alarm_header.getStartEpochMicrosec(), alarm_header.getLastEpochMicroSec(), alarm_header.getEventName().replace("Cleared", ""), alarm_header.getReportingEntityName(), alarm_header.getSpecificProblem());
+ alarm_informations.forEach(information ->
+ alarmsInformationService.saveAlarmsInformation(information));
+
+ } else {
+ alarm_header.setCreateTime(new Date());
+ alarm_header.setStatus("active");
+ alarmsHeaderService.saveAlarmsHeader(alarm_header);
+ if(alarm_informations.size() > 0) {
+ alarm_informations.forEach(information ->
+ alarmsInformationService.saveAlarmsInformation(information));
+ }
+ }
+ }
}
private void performanceProcess(Map<String, Object> maps) {
PerformanceHeader performance_header = new PerformanceHeader();
+ performance_header.setId(UuiCommonUtil.getUUID());
List<PerformanceInformation> performance_informations = new ArrayList<>();
- maps.forEach((k, v) -> {
- if (k.equals("event")) {
- Map<String, Object> eventMap = (Map<String, Object>) v;
- eventMap.forEach((ek1, ev1) -> {
+ maps.forEach((ek1, ev1) -> {
if (ek1.equals("commonEventHeader")) {
((Map<String, Object>) ev1).forEach((k2, v2) -> {
if (k2.equals("version"))
try {
List<Map<String, Object>> m = (List<Map<String, Object>>) v3;
m.forEach(i -> {
- if (i.get("name").toString().equals("eventTime"))
- try {
- performance_header.setCreateTime(DateUtils.stringToDate(i.get("value").toString()));
- performance_header.setUpdateTime(DateUtils.stringToDate(i.get("value").toString()));
- } catch (ParseException e) {
- e.printStackTrace();
- }
- if (i.get("value").toString().contains(";")) {
- performance_informations.add(new PerformanceInformation(i.get("name").toString(), "", performance_header.getSourceId(), null, null));
+ 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")){
- char[] valStr = i.get("value").toString().replace("=", ":").toCharArray();
- String name = "";
- String value = "";
- boolean nameFlag = true;
- boolean valueFlag = false;
- for (int j = 0; j < valStr.length; j++) {
- if (valStr[j] == ':') {
- nameFlag = false;
- valueFlag = true;
- continue;
- }
- if (valStr[j] == ';') {
- nameFlag = true;
- valueFlag = false;
- performance_informations.add(new PerformanceInformation(name, value, i.get("name").toString(), null, null));
- continue;
- }
- if (nameFlag)
- name += valStr[j];
- if (valueFlag)
- value += valStr[j];
+ try {
+ String type = performance_header.getEventType();
+ performance_informations.add(new PerformanceInformation(fields.get("name"), fields.get("value"), performance_header.getSourceId(), null, DateUtils.now(),performance_header.getId()));
+ 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(), performance_header.getId()));
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ }
+ } );
}
- } else {
- performance_informations.add(new PerformanceInformation(i.get("name").toString(), i.get("value").toString(), performance_header.getSourceId(), null, null));
- }
+ });
});
-
} catch (Exception e) {
e.printStackTrace();
logger.error("convert performanceAdditionalInformation error:" + e.getMessage());
performanceHeaderService.savePerformanceHeader(performance_header);
performance_informations.forEach(ai -> {
ai.setCreateTime(performance_header.getCreateTime());
- ai.setUpdateTime(new Date());
performanceInformationService.savePerformanceInformation(ai);
});
}
});
- }
- });
}
}
\ No newline at end of file
public void testGetAlarmsHeader() throws Exception {
AlarmsHeader ah = new AlarmsHeader("version", "eventName", "domain", "eventId", "eventType", "nfcNamingCode",
"nfNamingCode", "sourceId", "sourceName", "reportingEntityId", "reportingEntityName",
- "priority", "startEpochMicrosec", "lastEpochMicroSec", "sequence", "faultFieldsVersion",
+ "priority", "startEpochMicrosec", "lastEpochMicroSec","startEpochMicrosecCleared", "lastEpochMicroSecCleared", "sequence", "faultFieldsVersion",
"eventServrity", "eventSourceType", "eventCategory", "alarmCondition", "specificProblem",
"vfStatus", "alarmInterfaceA", "status", DateUtils.now(), DateUtils.now());
ah.getVersion();
@Test
public void testGetAlarmsInformation() throws Exception {
- AlarmsInformation ai = new AlarmsInformation("name", "value", "eventId", DateUtils.now(), DateUtils.now());
+ AlarmsInformation ai = new AlarmsInformation("name", "value", "eventId", DateUtils.now(), DateUtils.now(),"headerId");
ai.getName();
ai.getValue();
- ai.getEventId();
+ ai.getSourceId();
ai.getCreateTime();
ai.getUpdateTime();
ai.getId();
AlarmsInformation ai = new AlarmsInformation("eventId");
ai.setName("");
ai.setValue("");
- ai.setEventId("");
+ ai.setSourceId("");
ai.setCreateTime(DateUtils.now());
ai.setUpdateTime(DateUtils.now());
ai.setId(1);
@Test
public void testGetPerformanceInformation() throws Exception {
- PerformanceInformation pi = new PerformanceInformation("name", "value", "eventId", DateUtils.now(), DateUtils.now());
+ PerformanceInformation pi = new PerformanceInformation("name", "value", "eventId", DateUtils.now(), DateUtils.now(),"headerId");
pi.getName();
pi.getValue();
- pi.getEventId();
+ pi.getSourceId();
pi.getCreateTime();
pi.getUpdateTime();
pi.getId();
PerformanceInformation pi = new PerformanceInformation("eventId");
pi.setName("");
pi.setValue("");
- pi.setEventId("");
+ pi.setSourceId("");
pi.setCreateTime(DateUtils.now());
pi.setUpdateTime(DateUtils.now());
pi.setId(1);
AlarmsInformation ai = new AlarmsInformation();
ai.setName("");
ai.setValue("");
- ai.setEventId("");
+ ai.setSourceId("");
ai.setCreateTime(DateUtils.now());
ai.setUpdateTime(DateUtils.now());
alarmsInformationServiceImpl.getAllCount(ai, 1, 1);
AlarmsInformation ai = new AlarmsInformation();
ai.setName("");
ai.setValue("");
- ai.setEventId("");
+ ai.setSourceId("");
ai.setCreateTime(DateUtils.now());
ai.setUpdateTime(DateUtils.now());
alarmsInformationServiceImpl.queryAlarmsInformation(ai, 1, 1);
PerformanceInformation pi = new PerformanceInformation();
pi.setName("");
pi.setValue("");
- pi.setEventId("");
+ pi.setSourceId("");
pi.setCreateTime(DateUtils.now());
pi.setUpdateTime(DateUtils.now());
performanceInformationServiceImpl.getAllCount(pi, 1, 1);
PerformanceInformation pi = new PerformanceInformation();
pi.setName("");
pi.setValue("");
- pi.setEventId("");
+ pi.setSourceId("");
pi.setCreateTime(DateUtils.now());
pi.setUpdateTime(DateUtils.now());
performanceInformationServiceImpl.queryPerformanceInformation(pi, 1, 1);