aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorshentao <shentao@chinamobile.com>2017-11-03 20:49:26 +0800
committershentao <shentao@chinamobile.com>2017-11-03 20:49:34 +0800
commitaa1764cf15ff7548d67b6cebdea345b3adc5c899 (patch)
tree2e93b93432223d3a9f6aad1c15c5a95cf51c176f
parentf59c8533f47fbf34477b1594ef48b173b3a88741 (diff)
Fix bug about getting monitor data from dmaap
Change-Id: Id68eb80f3e098b44e1dfc95b21f02f4e5ce2ec21 Issue-Id: USECASEUI-50 Signed-off-by: shentao <shentao@chinamobile.com>
-rw-r--r--resources/dbscripts/mysql/usecase-ui-createobj.sql14
-rw-r--r--server/src/main/java/org/onap/usecaseui/server/UsecaseuiServerApplication.java5
-rw-r--r--server/src/main/java/org/onap/usecaseui/server/bean/AlarmsHeader.java3
-rwxr-xr-xserver/src/main/java/org/onap/usecaseui/server/bean/PerformanceHeader.java3
-rwxr-xr-xserver/src/main/java/org/onap/usecaseui/server/controller/AlarmController.java93
-rwxr-xr-xserver/src/main/java/org/onap/usecaseui/server/controller/PerformanceController.java82
-rwxr-xr-xserver/src/main/java/org/onap/usecaseui/server/service/impl/AlarmsHeaderServiceImpl.java22
-rwxr-xr-xserver/src/main/java/org/onap/usecaseui/server/service/impl/AlarmsInformationServiceImpl.java16
-rwxr-xr-xserver/src/main/java/org/onap/usecaseui/server/service/impl/PerformanceHeaderServiceImpl.java22
-rwxr-xr-xserver/src/main/java/org/onap/usecaseui/server/service/impl/PerformanceInformationServiceImpl.java31
-rwxr-xr-xserver/src/main/java/org/onap/usecaseui/server/util/DateUtils.java2
-rw-r--r--server/src/main/java/org/onap/usecaseui/server/util/DmaapSubscriber.java292
-rw-r--r--server/src/main/java/org/onap/usecaseui/server/util/ResponseUtil.java55
-rw-r--r--server/src/main/resources/dmaap.properties20
-rwxr-xr-xserver/src/test/java/org/onap/usecaseui/server/controller/AlarmControllerTest.java7
-rwxr-xr-xserver/src/test/java/org/onap/usecaseui/server/controller/PerformanceControllerTest.java2
16 files changed, 453 insertions, 216 deletions
diff --git a/resources/dbscripts/mysql/usecase-ui-createobj.sql b/resources/dbscripts/mysql/usecase-ui-createobj.sql
index 7a55c72b..7f839578 100644
--- a/resources/dbscripts/mysql/usecase-ui-createobj.sql
+++ b/resources/dbscripts/mysql/usecase-ui-createobj.sql
@@ -27,7 +27,8 @@ CREATE TABLE `alarms_additionalinformation` (
`eventId` varchar(30) NOT NULL,
`createTime` datetime NOT NULL,
`updateTime` datetime NOT NULL,
- PRIMARY KEY (`name`,`eventId`)
+ `id` int(10) NOT NULL,
+ PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
@@ -61,7 +62,7 @@ CREATE TABLE `alarms_commoneventheader` (
`status` varchar(11) NOT NULL,
`createTime` datetime NOT NULL,
`updateTime` datetime NOT NULL,
- PRIMARY KEY (`eventId`)
+ PRIMARY KEY (`eventName`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
@@ -74,7 +75,8 @@ CREATE TABLE `performance_additionalinformation` (
`eventId` varchar(30) NOT NULL,
`createTime` datetime NOT NULL,
`updateTime` datetime NOT NULL,
- PRIMARY KEY (`name`,`eventId`)
+ `id` int(10) NOT NULL,
+ PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
@@ -101,11 +103,9 @@ CREATE TABLE `performance_commoneventheader` (
`measurementInterval` varchar(10) NOT NULL,
`createTime` datetime NOT NULL,
`updateTime` datetime NOT NULL,
- PRIMARY KEY (`eventId`)
+ PRIMARY KEY (`eventName`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Init Records
--- ----------------------------
-INSERT INTO `alarms_additionalinformation` VALUES ('name', 'value', 'eventId', '2017-09-19 11:12:34', '2017-09-19 11:12:34');
-INSERT INTO `alarms_commoneventheader` VALUES ('1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '2017-09-04 15:25:11', '2017-09-11 15:25:19');
+-- ---------------------------- \ No newline at end of file
diff --git a/server/src/main/java/org/onap/usecaseui/server/UsecaseuiServerApplication.java b/server/src/main/java/org/onap/usecaseui/server/UsecaseuiServerApplication.java
index c12bb24e..a99a6c5c 100644
--- a/server/src/main/java/org/onap/usecaseui/server/UsecaseuiServerApplication.java
+++ b/server/src/main/java/org/onap/usecaseui/server/UsecaseuiServerApplication.java
@@ -15,6 +15,7 @@
*/
package org.onap.usecaseui.server;
+import org.onap.usecaseui.server.util.DmaapSubscriber;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
@@ -29,9 +30,11 @@ public class UsecaseuiServerApplication {
public RestTemplate getRestTemplate(){
return new RestTemplate();
}
-
+
public static void main(String[] args) {
SpringApplication.run(UsecaseuiServerApplication.class, args);
+ DmaapSubscriber dmaapSubscriber = new DmaapSubscriber();
+ dmaapSubscriber.run();
}
}
diff --git a/server/src/main/java/org/onap/usecaseui/server/bean/AlarmsHeader.java b/server/src/main/java/org/onap/usecaseui/server/bean/AlarmsHeader.java
index d9745686..fd896c52 100644
--- a/server/src/main/java/org/onap/usecaseui/server/bean/AlarmsHeader.java
+++ b/server/src/main/java/org/onap/usecaseui/server/bean/AlarmsHeader.java
@@ -31,13 +31,14 @@ public class AlarmsHeader implements Serializable{
@Column(name = "version")
private String version;
+ @Id
@Column(name = "eventName")
private String eventName;
@Column(name = "domain")
private String domain;
- @Id
+
@Column(name = "eventId")
private String eventId;
diff --git a/server/src/main/java/org/onap/usecaseui/server/bean/PerformanceHeader.java b/server/src/main/java/org/onap/usecaseui/server/bean/PerformanceHeader.java
index a5afae8d..c42fcf8e 100755
--- a/server/src/main/java/org/onap/usecaseui/server/bean/PerformanceHeader.java
+++ b/server/src/main/java/org/onap/usecaseui/server/bean/PerformanceHeader.java
@@ -31,13 +31,14 @@ public class PerformanceHeader implements Serializable {
@Column(name = "version")
private String version;
+ @Id
@Column(name = "eventName")
private String eventName;
@Column(name = "domain")
private String domain;
- @Id
+
@Column(name = "eventId")
private String eventId;
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 170d67da..7b3bd7d4 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
@@ -29,6 +29,7 @@ import org.onap.usecaseui.server.service.AlarmsInformationService;
import org.onap.usecaseui.server.util.CSVUtils;
import org.onap.usecaseui.server.util.DateUtils;
import org.onap.usecaseui.server.util.Page;
+import org.onap.usecaseui.server.util.ResponseUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
@@ -70,25 +71,12 @@ public class AlarmController
private ObjectMapper omAlarm = new ObjectMapper();
- private List<String> last_eventId = new ArrayList<>();
-
- private List<String> last_status = new ArrayList<>();
-
- private List<String> last_vfStatus = new ArrayList<>();
@RequestMapping(value = {"/usecase-ui"}, method = RequestMethod.GET)
public ModelAndView index(){
return new ModelAndView("index");
}
- @RequestMapping(value = {"/alarm/{eventId}/{eventName}/{name}/{value}/{createTime}/{status}/{vfStatus}"})
- public String getAlarmDateTotal(@PathVariable String eventId,@PathVariable String eventName,
- @PathVariable String name,@PathVariable String value,
- @PathVariable String createTime,@PathVariable String status,
- @PathVariable String vfStatus) throws ParseException {
-
- return "";
- }
@RequestMapping(value = {"/alarm/{currentPage}/{pageSize}",
"/alarm/{currentPage}/{pageSize}/{eventId}/{eventName}/{name}/{value}/{createTime}/{status}/{vfStatus}"},
@@ -98,6 +86,10 @@ public class AlarmController
@PathVariable(required = false) String createTime,@PathVariable(required = false) String status,
@PathVariable(required = false) String vfStatus,
@PathVariable int currentPage, @PathVariable int pageSize) throws JsonProcessingException {
+ logger.info("transfer getAlarmData Apis, " +
+ "Parameter all follows : [currentPage : {} , pageSize : {} , eventId : {} , " +
+ "eventName : {} , name : {} , value :{} , createTime : {} , status : {} , vfStatus : {}]"
+ ,currentPage,pageSize,eventId,eventName,name,value,createTime,status,vfStatus);
List<AlarmsHeader> alarmsHeaders = null;
List<AlarmBo> list = new ArrayList<>();
Page pa = null;
@@ -153,6 +145,8 @@ public class AlarmController
@RequestMapping(value = { "/alarm/genCsv/{eventId}" } , method = RequestMethod.GET , produces = "application/json")
public String generateCsvFile(HttpServletResponse response, @PathVariable String[] eventId) throws JsonProcessingException {
+ logger.info("transfer generateCsvFile Apis, " +
+ "Parameter all follows : [eventId : {}]",eventId);
String csvFile = "csvFiles/vnf_alarm_"+new SimpleDateFormat("yy-MM-ddHH:mm:ss").format(new Date())+".csv";
List<AlarmsHeader> alarmsHeaders = alarmsHeaderService.queryId(eventId);
List<String[]> csvData = new ArrayList<>();
@@ -183,76 +177,11 @@ public class AlarmController
}catch (Exception e){
logger.error(e.getMessage());
}
- if (null != response){
- response.setCharacterEncoding("utf-8");
- response.setContentType("application/csv");
- response.setHeader("Content-Disposition","attachment;filename="+csvFile);
- try(InputStream is = new FileInputStream(csvFile);
- OutputStream os = response.getOutputStream()){
- byte[] b = new byte[2048];
- int length;
- while ((length = is.read(b)) > 0) {
- os.write(b, 0, length);
- }
- return omAlarm.writeValueAsString("success");
- }catch (IOException e){
- logger.error("download csv File error :"+e.getMessage());
- return omAlarm.writeValueAsString("failed");
- }
- }else
- return omAlarm.writeValueAsString("csvFile generate success,response is null,don't download to local");
- }
-
-
- @RequestMapping(value = { "/alarm/{eventId}/{status}/{type}" } , method = RequestMethod.PUT )
- public String updateStatus(HttpServletResponse response,@PathVariable String[] eventId,@PathVariable String[] status,@PathVariable String type) throws JsonProcessingException {
- List<AlarmsHeader> alarmsHeaders = alarmsHeaderService.queryId(eventId);
- last_eventId.clear();
- last_vfStatus.clear();
- last_status.clear();
- for (AlarmsHeader ala: alarmsHeaders) {
- last_eventId.add(ala.getEventId());
- last_status.add(ala.getStatus());
- last_vfStatus.add(ala.getVfStatus());
- if ("vf".equals(type))
- ala.setVfStatus(status[0]);
- else if ("many".equals(type)){
- ala.setStatus(status[0]);
- ala.setVfStatus(status[1]);
- }else {
- ala.setStatus(status[0]);
- }
- if ("0".equals(alarmsHeaderService.updateAlarmsHeader(ala))) {
- if (null != response)
- response.setStatus(400);
- return omAlarm.writeValueAsString("failed");
- }
- }
- return omAlarm.writeValueAsString("success");
- }
-
- @RequestMapping(value = {"/alarm/revoke"} , method = RequestMethod.GET)
- public String revoke() throws JsonProcessingException {
- String result ;
- if (last_eventId.size() > 0 && last_vfStatus.size() > 0 && last_status.size() > 0){
- String[] eids = new String[last_eventId.size()];
- last_eventId.toArray(eids);
- List<AlarmsHeader> alarmsHeaders = alarmsHeaderService.queryId(eids);
- for (int i = 0;i<alarmsHeaders.size();i++){
- AlarmsHeader ala = alarmsHeaders.get(i);
- ala.setStatus(last_status.get(i));
- ala.setVfStatus(last_vfStatus.get(i));
- alarmsHeaderService.updateAlarmsHeader(ala);
- }
- last_eventId.clear();
- last_status.clear();
- last_vfStatus.clear();
- result = "revoke success";
- } else {
- result = "nothing can revoke";
+ if (ResponseUtil.responseDownload(csvFile,response)){
+ return omAlarm.writeValueAsString("success");
+ }else{
+ return omAlarm.writeValueAsString("failed");
}
- return omAlarm.writeValueAsString(result);
}
-
}
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 2634d259..19a69b93 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
@@ -27,6 +27,7 @@ import org.onap.usecaseui.server.service.PerformanceInformationService;
import org.onap.usecaseui.server.util.CSVUtils;
import org.onap.usecaseui.server.util.DateUtils;
import org.onap.usecaseui.server.util.Page;
+import org.onap.usecaseui.server.util.ResponseUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;
@@ -71,6 +72,10 @@ public class PerformanceController {
@PathVariable int pageSize,@PathVariable(required = false) String eventId,
@PathVariable(required = false) String eventName,@PathVariable(required = false) String name,
@PathVariable(required = false) String value,@PathVariable(required = false) String createTime) throws JsonProcessingException {
+ logger.info("transfer getAlarmData Apis, " +
+ "Parameter all follows : [currentPage : {} , pageSize : {} , eventId : {} , " +
+ "eventName : {} , name : {} , value :{} , createTime : {} ]"
+ ,currentPage,pageSize,eventId,eventName,name,value,createTime);
List<Object> list = new ArrayList<>();
Page pa = null;
if (null != eventId || null != eventName || null != name || null != value || null != createTime){
@@ -149,61 +154,39 @@ public class PerformanceController {
});
});
CSVUtils.writeCsv(PerformanceCSVHeaders,csvData,csvFile);
- if (null != response){
- response.setCharacterEncoding("utf-8");
- response.setContentType("application/csv");
- response.setHeader("Content-Disposition","attachment;filename="+csvFile);
- try(InputStream is = new FileInputStream(csvFile);
- OutputStream os = response.getOutputStream()){
- byte[] b = new byte[2048];
- int length;
- while ((length = is.read(b)) > 0) {
- os.write(b, 0, length);
- }
- return omPerformance.writeValueAsString("success");
- }catch (IOException e){
- logger.error("download csv File error :"+e.getMessage());
- return omPerformance.writeValueAsString("failed");
- }
- }else
- return omPerformance.writeValueAsString("csvFile generate success,but response is null,don't download to local");
-
+ if (ResponseUtil.responseDownload(csvFile,response)){
+ return omPerformance.writeValueAsString("success");
+ }else{
+ return omPerformance.writeValueAsString("failed");
+ }
}
- @RequestMapping(value = {"/performance/genDiaCsv"}, method = RequestMethod.POST, produces = "application/json")
- public String generateDiaCsvFile(HttpServletResponse response,@RequestBody Map<String,String> p) throws JsonProcessingException {
- String csvFileName = "csvFiles/"+p.get("name")+"_"+new SimpleDateFormat("yy-MM-ddHH:mm:ss").format(new Date())+".csv";
+ @RequestMapping(value = {"/performance/genDiaCsv/{dataJson}"}, method = RequestMethod.GET, produces = "application/json")
+ public String generateDiaCsvFile(HttpServletResponse response,@PathVariable String dataJson) throws IOException {
+ List<Map<String,Object>> dataList = omPerformance.readValue(dataJson,List.class);
+ String csvFileName = "csvFiles/"+dataList.get(0).get("name")+"_"+new SimpleDateFormat("yy-MM-ddHH:mm:ss").format(new Date())+".csv";
try{
- String[] headers = new String[]{"eventId","name","value","createTime","updateTime"};
+ String[] headers = new String[]{"eventId","name","dateUnit","value"};
List<String[]> csvDatas = new ArrayList<>();
- if (null != p){
- StringBuffer fileData = new StringBuffer();
- p.forEach((k,v)->{
- fileData.append(v+",");
+ if (null != dataList){
+ dataList.forEach((l)->{
+ StringBuffer fileData = new StringBuffer();
+ l.forEach((k,v)->{
+ logger.info(v.toString());
+ fileData.append(v.toString()+",");
+ });
+ csvDatas.add(fileData.toString().split(","));
});
- csvDatas.add(fileData.toString().split(","));
}
CSVUtils.writeCsv(headers,csvDatas,csvFileName);
}catch (Exception pe){
logger.error(pe.getMessage());
}
- if (null != response){
- response.setContentType("application/csv");
- response.setHeader("Content-Disposition","attachment;filename="+csvFileName+"");
- try(InputStream is = new FileInputStream(csvFileName);
- OutputStream os = response.getOutputStream()){
- byte[] b = new byte[2048];
- int length;
- while ((length = is.read(b)) > 0) {
- os.write(b, 0, length);
- }
- return omPerformance.writeValueAsString("success");
- }catch (IOException e){
- logger.error("download csv File error :"+e.getMessage());
- return omPerformance.writeValueAsString("failed");
- }
- }else
- return omPerformance.writeValueAsString("csvFile generate success,but response is null,don't download to local");
+ if (ResponseUtil.responseDownload(csvFileName,response)){
+ return omPerformance.writeValueAsString("success");
+ }else{
+ return omPerformance.writeValueAsString("failed");
+ }
}
@ResponseBody
@@ -214,11 +197,13 @@ public class PerformanceController {
switch (unit){
case "hour":
for(int i = 0 ; i < 4 ; i++){
- Date startDateHour = DateUtils.stringToDate(DateUtils.initDate(new Date(),1,1,-1,-1,0,0));
- Date endDateHour = DateUtils.stringToDate(DateUtils.initDate(new Date(),1,1,-1,-1,0,0));
+ Date startDateHour = DateUtils.stringToDate(DateUtils.initDate(new Date(),1,1,1,-1,0,0));
+ Date endDateHour = DateUtils.stringToDate(DateUtils.initDate(new Date(),1,1,1,-1,0,0));
endDateHour = DateUtils.stringToDate(DateUtils.addDate(endDateHour,"minute",15));
List<Integer> values = new ArrayList<>();
for (int j = 0 ; j < 4 ; j++){
+ logger.info(DateUtils.dateToString(startDateHour));
+ logger.info(DateUtils.dateToString(endDateHour));
values.add(performanceInformationService.queryDataBetweenSum(eventId,names[i],startDateHour,endDateHour));
startDateHour = DateUtils.stringToDate(DateUtils.addDate(startDateHour,"minute",15));
endDateHour = DateUtils.stringToDate(DateUtils.addDate(endDateHour,"minute",15));
@@ -261,9 +246,6 @@ public class PerformanceController {
endDateYear = DateUtils.stringToDate(DateUtils.addDate(endDateYear,"month",1));
List<Integer> values = new ArrayList<>();
for (int j = 0 ; j < 12 ; j++){
- logger.info(names[i]);
- logger.info(DateUtils.dateToString(startDateYear));
- logger.info(DateUtils.dateToString(endDateYear));
values.add(performanceInformationService.queryDataBetweenSum(eventId,names[i],startDateYear,endDateYear));
startDateYear = DateUtils.stringToDate(DateUtils.addDate(startDateYear,"month",1));
endDateYear = DateUtils.stringToDate(DateUtils.addDate(endDateYear,"month",1));
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 f918b22b..91c090af 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
@@ -49,17 +49,15 @@ public class AlarmsHeaderServiceImpl implements AlarmsHeaderService {
public String saveAlarmsHeader(AlarmsHeader alarmsHeader) {
- try{
+ try(Session session = sessionFactory.openSession();){
if (null == alarmsHeader) {
logger.error("AlarmsHeaderServiceImpl saveAlarmsHeader alarmsHeader is null!");
}
logger.info("AlarmsHeaderServiceImpl saveAlarmsHeader: alarmsHeader={}", alarmsHeader);
- Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
session.save(alarmsHeader);
tx.commit();
session.flush();
- session.close();
return "1";
} catch (Exception e) {
logger.error("exception occurred while performing AlarmsHeaderServiceImpl saveAlarmsHeader. Details:" + e.getMessage());
@@ -71,17 +69,15 @@ public class AlarmsHeaderServiceImpl implements AlarmsHeaderService {
@Override
public String updateAlarmsHeader(AlarmsHeader alarmsHeader) {
- try{
+ try(Session session = sessionFactory.openSession();){
if (null == alarmsHeader){
logger.error("AlarmsHeaderServiceImpl updateAlarmsHeader alarmsHeader is null!");
}
logger.info("AlarmsHeaderServiceImpl updateAlarmsHeader: alarmsHeader={}", alarmsHeader);
- Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
session.update(alarmsHeader);
tx.commit();
session.flush();
- session.close();
return "1";
} catch (Exception e) {
logger.error("exception occurred while performing AlarmsHeaderServiceImpl updateAlarmsHeader. Details:" + e.getMessage());
@@ -90,7 +86,7 @@ public class AlarmsHeaderServiceImpl implements AlarmsHeaderService {
}
public int getAllCount(AlarmsHeader alarmsHeader,int currentPage,int pageSize) {
- try{
+ try(Session session = sessionFactory.openSession();){
StringBuffer count=new StringBuffer("select count(*) from AlarmsHeader a where 1=1");
if (null == alarmsHeader) {
//logger.error("AlarmsHeaderServiceImpl getAllCount alarmsHeader is null!");
@@ -200,10 +196,8 @@ public class AlarmsHeaderServiceImpl implements AlarmsHeaderService {
count.append(" and a.updateTime like '%"+ver+"%'");
}
}
- Session session = sessionFactory.openSession();
long q=(long)session.createQuery(count.toString()).uniqueResult();
session.flush();
- session.close();
return (int)q;
} catch (Exception e) {
logger.error("exception occurred while performing AlarmsHeaderServiceImpl getAllCount. Details:" + e.getMessage());
@@ -218,7 +212,7 @@ public class AlarmsHeaderServiceImpl implements AlarmsHeaderService {
int allRow =this.getAllCount(alarmsHeader,currentPage,pageSize);
int offset = page.countOffset(currentPage, pageSize);
- try{
+ try(Session session = sessionFactory.openSession();){
StringBuffer hql =new StringBuffer("from AlarmsHeader a where 1=1");
if (null == alarmsHeader) {
//logger.error("AlarmsHeaderServiceImpl queryAlarmsHeader alarmsHeader is null!");
@@ -329,7 +323,6 @@ public class AlarmsHeaderServiceImpl implements AlarmsHeaderService {
}
}
logger.info("AlarmsHeaderServiceImpl queryAlarmsHeader: alarmsHeader={}", alarmsHeader);
- Session session = sessionFactory.openSession();
Query query = session.createQuery(hql.toString());
query.setFirstResult(offset);
query.setMaxResults(pageSize);
@@ -339,7 +332,6 @@ public class AlarmsHeaderServiceImpl implements AlarmsHeaderService {
page.setTotalRecords(allRow);
page.setList(list);
session.flush();
- session.close();
return page;
} catch (Exception e) {
logger.error("exception occurred while performing AlarmsHeaderServiceImpl queryAlarmsHeader. Details:" + e.getMessage());
@@ -351,15 +343,13 @@ public class AlarmsHeaderServiceImpl implements AlarmsHeaderService {
@SuppressWarnings("unchecked")
@Override
public List<AlarmsHeader> queryId(String[] id) {
- try {
+ try(Session session = sessionFactory.openSession();){
if(id.length==0) {
logger.error("AlarmsHeaderServiceImpl queryId is null!");
}
List<AlarmsHeader> list = new ArrayList<AlarmsHeader>();
- Session session = sessionFactory.openSession();
- Query query = session.createQuery("from AlarmsHeader a where a.eventId IN (:alist)");
+ Query query = session.createQuery("from AlarmsHeader a where a.eventName IN (:alist)");
list = query.setParameterList("alist", id).list();
- session.close();
return list;
} catch (Exception e) {
logger.error("exception occurred while performing AlarmsHeaderServiceImpl queryId. Details:" + e.getMessage());
diff --git a/server/src/main/java/org/onap/usecaseui/server/service/impl/AlarmsInformationServiceImpl.java b/server/src/main/java/org/onap/usecaseui/server/service/impl/AlarmsInformationServiceImpl.java
index dfd92d32..6da264fa 100755
--- a/server/src/main/java/org/onap/usecaseui/server/service/impl/AlarmsInformationServiceImpl.java
+++ b/server/src/main/java/org/onap/usecaseui/server/service/impl/AlarmsInformationServiceImpl.java
@@ -48,17 +48,15 @@ public class AlarmsInformationServiceImpl implements AlarmsInformationService {
@Override
public String saveAlarmsInformation(AlarmsInformation alarmsInformation) {
- try{
+ try(Session session = sessionFactory.openSession();){
if (null == alarmsInformation) {
logger.error("alarmsInformation saveAlarmsInformation alarmsInformation is null!");
}
logger.info("AlarmsInformationServiceImpl saveAlarmsInformation: alarmsInformation={}", alarmsInformation);
- Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
session.save(alarmsInformation);
tx.commit();
session.flush();
- session.close();
return "1";
} catch (Exception e) {
logger.error("exception occurred while performing AlarmsInformationServiceImpl saveAlarmsInformation. Details:" + e.getMessage());
@@ -69,17 +67,15 @@ public class AlarmsInformationServiceImpl implements AlarmsInformationService {
@Override
public String updateAlarmsInformation(AlarmsInformation alarmsInformation) {
- try{
+ try(Session session = sessionFactory.openSession();){
if (null == alarmsInformation) {
logger.error("alarmsInformation updateAlarmsInformation alarmsInformation is null!");
}
logger.info("AlarmsInformationServiceImpl updateAlarmsInformation: alarmsInformation={}", alarmsInformation);
- Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
session.update(alarmsInformation);
tx.commit();
session.flush();
- session.close();
return "1";
} catch (Exception e) {
logger.error("exception occurred while performing AlarmsInformationServiceImpl updateAlarmsInformation. Details:" + e.getMessage());
@@ -89,7 +85,7 @@ public class AlarmsInformationServiceImpl implements AlarmsInformationService {
public int getAllCount(AlarmsInformation alarmsInformation, int currentPage, int pageSize) {
- try{
+ try(Session session = sessionFactory.openSession();){
StringBuffer hql = new StringBuffer("select count(*) from AlarmsInformation a where 1=1");
if (null == alarmsInformation) {
//logger.error("AlarmsInformationServiceImpl getAllCount alarmsInformation is null!");
@@ -115,10 +111,8 @@ public class AlarmsInformationServiceImpl implements AlarmsInformationService {
hql.append(" and a.updateTime like '%"+ver+"%'");
}
}
- Session session = sessionFactory.openSession();
long q=(long)session.createQuery(hql.toString()).uniqueResult();
session.flush();
- session.close();
return (int)q;
} catch (Exception e) {
logger.error("exception occurred while performing AlarmsInformationServiceImpl getAllCount. Details:" + e.getMessage());
@@ -134,7 +128,7 @@ public class AlarmsInformationServiceImpl implements AlarmsInformationService {
int allRow =this.getAllCount(alarmsInformation,currentPage,pageSize);
int offset = page.countOffset(currentPage, pageSize);
- try{
+ try(Session session = sessionFactory.openSession();){
StringBuffer hql =new StringBuffer("from AlarmsInformation a where 1=1");
if (null == alarmsInformation) {
//logger.error("AlarmsInformationServiceImpl queryAlarmsInformation alarmsInformation is null!");
@@ -161,7 +155,6 @@ public class AlarmsInformationServiceImpl implements AlarmsInformationService {
}
}
logger.info("AlarmsInformationServiceImpl queryAlarmsInformation: alarmsInformation={}", alarmsInformation);
- Session session = sessionFactory.openSession();
Query query = session.createQuery(hql.toString());
query.setFirstResult(offset);
query.setMaxResults(pageSize);
@@ -171,7 +164,6 @@ public class AlarmsInformationServiceImpl implements AlarmsInformationService {
page.setTotalRecords(allRow);
page.setList(list);
session.flush();
- session.close();
return page;
} catch (Exception e) {
logger.error("exception occurred while performing AlarmsInformationServiceImpl queryAlarmsInformation. Details:" + e.getMessage());
diff --git a/server/src/main/java/org/onap/usecaseui/server/service/impl/PerformanceHeaderServiceImpl.java b/server/src/main/java/org/onap/usecaseui/server/service/impl/PerformanceHeaderServiceImpl.java
index 1dd783e0..3a4ddf54 100755
--- a/server/src/main/java/org/onap/usecaseui/server/service/impl/PerformanceHeaderServiceImpl.java
+++ b/server/src/main/java/org/onap/usecaseui/server/service/impl/PerformanceHeaderServiceImpl.java
@@ -50,17 +50,15 @@ public class PerformanceHeaderServiceImpl implements PerformanceHeaderService {
@Override
public String savePerformanceHeader(PerformanceHeader performanceHeder) {
- try{
+ try(Session session = sessionFactory.openSession();){
if (null == performanceHeder){
logger.error("PerformanceHeaderServiceImpl savePerformanceHeader performanceHeder is null!");
}
logger.info("PerformanceHeaderServiceImpl savePerformanceHeader: performanceHeder={}", performanceHeder);
- Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
session.save(performanceHeder);
tx.commit();
session.flush();
- session.close();
return "1";
} catch (Exception e) {
logger.error("exception occurred while performing PerformanceHeaderServiceImpl savePerformanceHeader. Details:" + e.getMessage());
@@ -72,17 +70,15 @@ public class PerformanceHeaderServiceImpl implements PerformanceHeaderService {
@Override
public String updatePerformanceHeader(PerformanceHeader performanceHeder) {
- try{
+ try(Session session = sessionFactory.openSession();){
if (null == performanceHeder){
logger.error("PerformanceHeaderServiceImpl updatePerformanceHeader performanceHeder is null!");
}
logger.info("PerformanceHeaderServiceImpl updatePerformanceHeader: performanceHeder={}", performanceHeder);
- Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
session.update(performanceHeder);
tx.commit();
session.flush();
- session.close();
return "1";
} catch (Exception e) {
logger.error("exception occurred while performing PerformanceHeaderServiceImpl updatePerformanceHeader. Details:" + e.getMessage());
@@ -92,7 +88,7 @@ public class PerformanceHeaderServiceImpl implements PerformanceHeaderService {
public int getAllCount(PerformanceHeader performanceHeder, int currentPage, int pageSize) {
- try{
+ try(Session session = sessionFactory.openSession();){
StringBuffer hql = new StringBuffer("select count(*) from PerformanceHeader a where 1=1");
if (null == performanceHeder) {
//logger.error("PerformanceHeaderServiceImpl getAllCount performanceHeder is null!");
@@ -174,10 +170,8 @@ public class PerformanceHeaderServiceImpl implements PerformanceHeaderService {
hql.append(" and a.updateTime like '%"+ver+"%'");
}
}
- Session session = sessionFactory.openSession();
long q=(long)session.createQuery(hql.toString()).uniqueResult();
session.flush();
- session.close();
return (int)q;
} catch (Exception e) {
logger.error("exception occurred while performing PerformanceHeaderServiceImpl getAllCount. Details:" + e.getMessage());
@@ -193,7 +187,7 @@ public class PerformanceHeaderServiceImpl implements PerformanceHeaderService {
int allRow =this.getAllCount(performanceHeder,currentPage,pageSize);
int offset = page.countOffset(currentPage, pageSize);
- try{
+ try(Session session = sessionFactory.openSession();){
StringBuffer hql =new StringBuffer("from PerformanceHeader a where 1=1");
if (null == performanceHeder) {
//logger.error("PerformanceHeaderServiceImpl queryPerformanceHeader performanceHeder is null!");
@@ -276,7 +270,6 @@ public class PerformanceHeaderServiceImpl implements PerformanceHeaderService {
}
}
logger.info("PerformanceHeaderServiceImpl queryPerformanceHeader: performanceHeder={}", performanceHeder);
- Session session = sessionFactory.openSession();
Query query = session.createQuery(hql.toString());
query.setFirstResult(offset);
query.setMaxResults(pageSize);
@@ -286,7 +279,6 @@ public class PerformanceHeaderServiceImpl implements PerformanceHeaderService {
page.setTotalRecords(allRow);
page.setList(list);
session.flush();
- session.close();
return page;
} catch (Exception e) {
logger.error("exception occurred while performing PerformanceHeaderServiceImpl queryPerformanceHeader. Details:" + e.getMessage());
@@ -298,15 +290,13 @@ public class PerformanceHeaderServiceImpl implements PerformanceHeaderService {
@SuppressWarnings("unchecked")
@Override
public List<PerformanceHeader> queryId(String[] id) {
- try {
+ try(Session session = sessionFactory.openSession();) {
if(id.length==0) {
logger.error("PerformanceHeaderServiceImpl queryId is null!");
}
List<PerformanceHeader> list = new ArrayList<PerformanceHeader>();
- Session session = sessionFactory.openSession();
- Query query = session.createQuery("from PerformanceHeader a where a.eventId IN (:alist)");
+ Query query = session.createQuery("from PerformanceHeader a where a.eventName IN (:alist)");
list = query.setParameterList("alist", id).list();
- session.close();
return list;
} catch (Exception e) {
logger.error("exception occurred while performing PerformanceHeaderServiceImpl queryId. Details:" + e.getMessage());
diff --git a/server/src/main/java/org/onap/usecaseui/server/service/impl/PerformanceInformationServiceImpl.java b/server/src/main/java/org/onap/usecaseui/server/service/impl/PerformanceInformationServiceImpl.java
index a1a9a0dd..0b4371ea 100755
--- a/server/src/main/java/org/onap/usecaseui/server/service/impl/PerformanceInformationServiceImpl.java
+++ b/server/src/main/java/org/onap/usecaseui/server/service/impl/PerformanceInformationServiceImpl.java
@@ -47,17 +47,15 @@ public class PerformanceInformationServiceImpl implements PerformanceInformation
@Override
public String savePerformanceInformation(PerformanceInformation performanceInformation) {
- try {
+ try(Session session = sessionFactory.openSession();) {
if (null == performanceInformation) {
logger.error("performanceInformation savePerformanceInformation performanceInformation is null!");
}
logger.info("PerformanceInformationServiceImpl savePerformanceInformation: performanceInformation={}", performanceInformation);
- Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
session.save(performanceInformation);
tx.commit();
session.flush();
- session.close();
return "1";
} catch (Exception e) {
logger.error("exception occurred while performing PerformanceInformationServiceImpl savePerformanceInformation. Details:" + e.getMessage());
@@ -69,17 +67,15 @@ public class PerformanceInformationServiceImpl implements PerformanceInformation
@Override
public String updatePerformanceInformation(PerformanceInformation performanceInformation) {
- try {
+ try(Session session = sessionFactory.openSession();) {
if (null == performanceInformation) {
logger.error("performanceInformation updatePerformanceInformation performanceInformation is null!");
}
logger.info("PerformanceInformationServiceImpl updatePerformanceInformation: performanceInformation={}", performanceInformation);
- Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
session.update(performanceInformation);
tx.commit();
session.flush();
- session.close();
return "1";
} catch (Exception e) {
logger.error("exception occurred while performing PerformanceInformationServiceImpl updatePerformanceInformation. Details:" + e.getMessage());
@@ -89,7 +85,7 @@ public class PerformanceInformationServiceImpl implements PerformanceInformation
public int getAllCount(PerformanceInformation performanceInformation, int currentPage, int pageSize) {
- try{
+ try(Session session = sessionFactory.openSession();){
StringBuffer hql = new StringBuffer("select count(*) from PerformanceInformation a where 1=1");
if (null == performanceInformation) {
//logger.error("AlarmsInformationServiceImpl getAllCount performanceInformation is null!");
@@ -115,10 +111,8 @@ public class PerformanceInformationServiceImpl implements PerformanceInformation
hql.append(" and a.updateTime like '%"+ver+"%'");
}
}
- Session session = sessionFactory.openSession();
long q=(long)session.createQuery(hql.toString()).uniqueResult();
session.flush();
- session.close();
return (int)q;
} catch (Exception e) {
logger.error("exception occurred while performing PerformanceInformationServiceImpl getAllCount. Details:" + e.getMessage());
@@ -134,7 +128,7 @@ public class PerformanceInformationServiceImpl implements PerformanceInformation
int allRow =this.getAllCount(performanceInformation,currentPage,pageSize);
int offset = page.countOffset(currentPage, pageSize);
- try{
+ try(Session session = sessionFactory.openSession();){
StringBuffer hql =new StringBuffer("from PerformanceInformation a where 1=1 ");
if (null == performanceInformation) {
//logger.error("AlarmsInformationServiceImpl queryPerformanceInformation performanceInformation is null!");
@@ -161,7 +155,6 @@ public class PerformanceInformationServiceImpl implements PerformanceInformation
}
}
logger.info("PerformanceInformationServiceImpl queryPerformanceInformation: performanceInformation={}", performanceInformation);
- Session session = sessionFactory.openSession();
Query query = session.createQuery(hql.toString());
query.setFirstResult(offset);
query.setMaxResults(pageSize);
@@ -172,7 +165,6 @@ public class PerformanceInformationServiceImpl implements PerformanceInformation
page.setTotalRecords(allRow);
page.setList(list);
session.flush();
- session.close();
return page;
} catch (Exception e) {
logger.error("exception occurred while performing PerformanceInformationServiceImpl queryPerformanceInformation. Details:" + e.getMessage());
@@ -184,17 +176,16 @@ public class PerformanceInformationServiceImpl implements PerformanceInformation
@SuppressWarnings("unchecked")
@Override
public List<PerformanceInformation> queryId(String[] id) {
- try {
+ try(Session session = sessionFactory.openSession();) {
if(id.length==0) {
- logger.error("PerformanceInformationServiceImpl queryId is null!");
+ //logger.error("PerformanceInformationServiceImpl queryId is null!");
}
List<PerformanceInformation> list = new ArrayList<>();
- Session session = sessionFactory.openSession();
Query query = session.createQuery("from PerformanceInformation a where a.eventId IN (:alist)");
list = query.setParameterList("alist", id).list();
- session.close();
return list;
} catch (Exception e) {
+ e.printStackTrace();
logger.error("exception occurred while performing PerformanceInformationServiceImpl queryId. Details:" + e.getMessage());
return null;
}
@@ -204,15 +195,13 @@ public class PerformanceInformationServiceImpl implements PerformanceInformation
@SuppressWarnings("unchecked")
@Override
public List<PerformanceInformation> queryDateBetween(String eventId,Date startDate, Date endDate) {
- try {
+ try(Session session = sessionFactory.openSession();) {
List<PerformanceInformation> list = new ArrayList<>();
- Session session = sessionFactory.openSession();
Query query = session.createQuery("from PerformanceInformation a where a.eventId = :eventId and a.createTime BETWEEN :startDate and :endDate");
list = query.setParameter("eventId",eventId).setParameter("startDate", startDate).setParameter("endDate",endDate).list();
- session.close();
return list;
} catch (Exception e) {
- logger.error("exception occurred while performing PerformanceInformationServiceImpl queryId. Details:" + e.getMessage());
+ logger.error("exception occurred while performing PerformanceInformationServiceImpl queryDateBetween. Details:" + e.getMessage());
return null;
}
}
@@ -228,7 +217,7 @@ public class PerformanceInformationServiceImpl implements PerformanceInformation
sum = Integer.parseInt(query.setParameter("eventId",eventId).setParameter("name",name).setParameter("startDate", startDate).setParameter("endDate",endDate).uniqueResult().toString());
return sum;
} catch (Exception e) {
- logger.error("exception occurred while performing PerformanceInformationServiceImpl queryId. Details:" + e.getMessage());
+ logger.error("exception occurred while performing PerformanceInformationServiceImpl queryDataBetweenSum. Details:" + e.getMessage());
return 0;
}
}
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 3184dc01..0d294d1a 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
@@ -49,7 +49,7 @@ public class DateUtils {
if(day == 0)
ldt = ldt.withDayOfMonth(1);
} else
- ldt = ldt.withDayOfMonth(ldt.getDayOfMonth()-1);
+ ldt = ldt.withDayOfMonth(ldt.getDayOfMonth()-1<1?ldt.getDayOfMonth():ldt.getDayOfMonth()+-1);
if(hour >= 0){
if(hour == 0)
ldt = ldt.withHour(0);
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
new file mode 100644
index 00000000..6d6116ae
--- /dev/null
+++ b/server/src/main/java/org/onap/usecaseui/server/util/DmaapSubscriber.java
@@ -0,0 +1,292 @@
+/*
+ * Copyright (C) 2017 CMCC, Inc. and others. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onap.usecaseui.server.util;
+
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import lombok.Getter;
+import lombok.Setter;
+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.bean.PerformanceHeader;
+import org.onap.usecaseui.server.bean.PerformanceInformation;
+import org.onap.usecaseui.server.service.AlarmsHeaderService;
+import org.onap.usecaseui.server.service.AlarmsInformationService;
+import org.onap.usecaseui.server.service.PerformanceHeaderService;
+import org.onap.usecaseui.server.service.PerformanceInformationService;
+import org.onap.usecaseui.server.service.impl.AlarmsHeaderServiceImpl;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.EnableAspectJAutoProxy;
+import org.springframework.stereotype.Controller;
+
+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.util.*;
+
+@org.springframework.context.annotation.Configuration
+@EnableAspectJAutoProxy
+public class DmaapSubscriber implements Runnable {
+
+ private Logger logger = LoggerFactory.getLogger(DmaapSubscriber.class);
+
+ private String url;
+ private String topic;
+ private String consumerGroup;
+ private String consumer;
+ private int timeout ;
+
+ private boolean isActive = true;
+
+ @Resource(name = "AlarmsHeaderService")
+ private AlarmsHeaderService alarmsHeaderService;
+
+ @Resource(name = "AlarmsInformationService")
+ private AlarmsInformationService alarmsInformationService;
+
+ @Resource(name = "PerformanceHeaderService")
+ private PerformanceHeaderService performanceHeaderService;
+
+ @Resource(name = "PerformanceInformationService")
+ private PerformanceInformationService performanceInformationService;
+
+ private void subscribe(){
+ String response = "";
+ try{
+ response = getDMaaPData();
+ logger.info(response);
+ try{
+ ObjectMapper objMapper = new ObjectMapper();
+ Map<String,Map<String,Map<String,Object>>> maps = objMapper.readValue(response,Map.class);
+ AlarmsHeader alarm_header = new AlarmsHeader();
+ List<AlarmsInformation> alarm_informations = new ArrayList<>();
+ PerformanceHeader performance_header = new PerformanceHeader();
+ List<PerformanceInformation> performance_infomations = new ArrayList<>();
+ maps.forEach( (k,v) -> {
+ maps.get(k).forEach( (k1,v1) ->{
+ if (maps.get(k).get(k1).containsValue("fault") || maps.get(k).containsKey("faultFields")){
+ if (k1.equals("commonEventHeader")){
+ maps.get(k).get(k1).forEach( (k2,v2 ) ->{
+ if (k2.equals("version"))
+ alarm_header.setVersion(v2.toString());
+ if (k2.equals("eventName"))
+ alarm_header.setEventName(v2.toString());
+ if (k2.equals("domain"))
+ alarm_header.setDomain(v2.toString());
+ if (k2.equals("eventId"))
+ alarm_header.setEventId(v2.toString());
+ if (k2.equals("eventType"))
+ alarm_header.setEventType(v2.toString());
+ if (k2.equals("nfcNamingCode"))
+ alarm_header.setNfcNamingCode(v2.toString());
+ if (k2.equals("nfNamingCode"))
+ alarm_header.setNfNamingCode(v2.toString());
+ if (k2.equals("sourceId"))
+ alarm_header.setSourceId(v2.toString());
+ if (k2.equals("sourceName"))
+ alarm_header.setSourceName(v2.toString());
+ if (k2.equals("reportingEntityId"))
+ alarm_header.setReportingEntityId(v2.toString());
+ if (k2.equals("reportingEntityName"))
+ alarm_header.setReportingEntityName(v2.toString());
+ if (k2.equals("priority"))
+ alarm_header.setPriority(v2.toString());
+ if (k2.equals("startEpochMicrosec"))
+ alarm_header.setStartEpochMicrosec(v2.toString());
+ if (k2.equals("lastEpochMicrosec"))
+ alarm_header.setLastEpochMicroSec(v2.toString());
+ if (k2.equals("sequence"))
+ alarm_header.setSequence(v2.toString());
+ } );
+ }
+ else if (k1.equals("faultFields")) {
+ maps.get(k).get(k1).forEach((k3, v3) -> {
+ if (k3.equals("faultFieldsVersion"))
+ alarm_header.setFaultFieldsVersion(v3.toString());
+ if (k3.equals("eventSeverity"))
+ alarm_header.setEventServrity(v3.toString());
+ if (k3.equals("eventSourceType"))
+ alarm_header.setEventSourceType(v3.toString());
+ if (k3.equals("eventCategory"))
+ alarm_header.setEventCategory(v3.toString());
+ if (k3.equals("alarmCondition"))
+ alarm_header.setAlarmCondition(v3.toString());
+ if (k3.equals("specificProblem"))
+ alarm_header.setSpecificProblem(v3.toString());
+ if (k3.equals("vfStatus"))
+ alarm_header.setVfStatus(v3.toString());
+ if (k3.equals("alarmInterfaceA"))
+ alarm_header.setAlarmInterfaceA(v3.toString());
+ if (k3.equals("alarmAdditionalInformation")) {
+ try {
+ List<Map<String,Object>> m = (List<Map<String, Object>>) v3;
+ m.forEach( i -> {
+ i.forEach( (k4,v4) -> {
+ alarm_informations.add(new AlarmsInformation(k4,v4.toString(),alarm_header.getEventName(),new Date(),new Date()));
+ });
+ } );
+ alarm_header.setCreateTime(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");
+ alarmsHeaderService.updateAlarmsHeader(alarms);
+ } );
+ }else{
+ alarm_header.setStatus("1");
+ logger.info(alarm_header.toString() +"");
+ alarmsHeaderService.saveAlarmsHeader(alarm_header);
+ alarm_informations.forEach( information ->
+ alarmsInformationService.saveAlarmsInformation(information));
+ }
+ } catch (Exception e) {
+ logger.error("convert alarmAdditionalInformation error:"+e.getMessage());
+ }
+ }
+ });
+
+ }
+ }else if(maps.get(k).get(k1).containsValue("measurementsForVfScaling") || maps.get(k).containsKey("measurementsForVfScalingFields")){
+ if (k1.equals("commonEventHeader"))
+ maps.get(k).get(k1).forEach( (k2,v2) ->{
+ if (k2.equals("version"))
+ performance_header.setVersion(v2.toString());
+ if (k2.equals("eventName"))
+ performance_header.setEventName(v2.toString());
+ if (k2.equals("domain"))
+ performance_header.setDomain(v2.toString());
+ if (k2.equals("eventId"))
+ performance_header.setEventId(v2.toString());
+ if (k2.equals("eventType"))
+ performance_header.setEventType(v2.toString());
+ if (k2.equals("nfcNamingCode"))
+ performance_header.setNfcNamingCode(v2.toString());
+ if (k2.equals("nfNamingCode"))
+ performance_header.setNfNamingCode(v2.toString());
+ if (k2.equals("sourceId"))
+ performance_header.setSourceId(v2.toString());
+ if (k2.equals("sourceName"))
+ performance_header.setSourceName(v2.toString());
+ if (k2.equals("reportingEntityId"))
+ performance_header.setReportingEntityId(v2.toString());
+ if (k2.equals("reportingEntityName"))
+ performance_header.setReportingEntityName(v2.toString());
+ if (k2.equals("priority"))
+ performance_header.setPriority(v2.toString());
+ if (k2.equals("startEpochMicrosec"))
+ performance_header.setStartEpochMicrosec(v2.toString());
+ if (k2.equals("lastEpochMicrosec"))
+ performance_header.setLastEpochMicroSec(v2.toString());
+ if (k2.equals("sequence"))
+ performance_header.setSequence(v2.toString());
+ } );
+ else if(k1.equals("measurementsForVfScalingFields")) {
+ maps.get(k).get(k1).forEach((k3, v3) -> {
+ if (k3.equals("measurementsForVfScalingVersion"))
+ performance_header.setMeasurementsForVfScalingVersion(v3.toString());
+ if (k3.equals("measurementInterval"))
+ performance_header.setMeasurementInterval(v3.toString());
+ if (k3.equals("additionalMeasurements")){
+ try {
+ List<Map<String,Object>> m = (List<Map<String, Object>>) v3;
+ m.forEach( i -> {
+ i.forEach( (k4,v4) -> {
+ performance_infomations.add(new PerformanceInformation(k4,v4.toString(),performance_header.getEventName(),new Date(),new Date()));
+ });
+ } );
+ } catch (Exception e) {
+ logger.error("convert additionalMeasurements error:"+e.getMessage());
+ }
+
+ }
+ });
+ performance_header.setCreateTime(new Date());
+ performance_header.setUpdateTime(new Date());
+ performanceHeaderService.savePerformanceHeader(performance_header);
+ performance_infomations.forEach( information ->
+ performanceInformationService.savePerformanceInformation(information));
+ }
+ }
+
+ });
+ });
+ }catch (Exception e){
+ e.printStackTrace();
+ logger.error("dispose of Data failed:"+e.getMessage());
+ }
+ }catch (Exception e){
+ logger.error("getDMaaP Information failed :"+e.getMessage());
+ }
+ }
+
+ private String getDMaaPData(){
+ 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);
+ }
+
+ private void initConfig(){
+ InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("dmaap.properties");
+ Properties p = new Properties();
+ try {
+ p.load(inputStream);
+ this.url = p.getProperty("dmaap.url");
+ this.topic = p.getProperty("dmaap.topic");
+ this.consumerGroup = p.getProperty("dmaap.consumerGroup");
+ this.consumer = p.getProperty("dmaap.consumer");
+ this.timeout = Integer.parseInt(p.getProperty("dmaap.timeout"));
+ } catch (IOException e1) {
+ logger.error("get configuration file arise error :"+e1.getMessage());
+ }
+
+ }
+
+ public void run() {
+ try{
+ initConfig();
+ while(isActive){
+ subscribe();
+ }
+ }catch (Exception e){
+ try {
+ Thread.sleep(10000);
+ } catch (InterruptedException e1) {
+ e1.printStackTrace();
+ }
+ logger.error("subscribe raise error :"+e.getCause());
+ }
+ }
+
+ public void stopTask(){
+ if (isActive)
+ isActive = false;
+ }
+
+}
diff --git a/server/src/main/java/org/onap/usecaseui/server/util/ResponseUtil.java b/server/src/main/java/org/onap/usecaseui/server/util/ResponseUtil.java
new file mode 100644
index 00000000..8e2f39cb
--- /dev/null
+++ b/server/src/main/java/org/onap/usecaseui/server/util/ResponseUtil.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2017 CMCC, Inc. and others. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onap.usecaseui.server.util;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.http.HttpServletResponse;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+public class ResponseUtil {
+
+ private static Logger logger = LoggerFactory.getLogger(ResponseUtil.class);
+
+ public static boolean responseDownload(String filePath, HttpServletResponse response){
+ if (null != response){
+ response.setCharacterEncoding("utf-8");
+ response.setContentType("application/csv");
+ response.setHeader("Content-Disposition","attachment;filename="+filePath);
+ try(InputStream is = new FileInputStream(filePath);
+ OutputStream os = response.getOutputStream()){
+ byte[] b = new byte[2048];
+ int length;
+ while ((length = is.read(b)) > 0) {
+ os.write(b, 0, length);
+ }
+ return true;
+ }catch (IOException e){
+ logger.error("download csv File error :"+e.getMessage());
+ return false;
+ }
+ }else{
+ logger.error("csvFile generate success,but response is null,don't download to local");
+ return false;
+ }
+
+ }
+
+}
diff --git a/server/src/main/resources/dmaap.properties b/server/src/main/resources/dmaap.properties
new file mode 100644
index 00000000..62ea4550
--- /dev/null
+++ b/server/src/main/resources/dmaap.properties
@@ -0,0 +1,20 @@
+##
+## Copyright (C) 2017 CMCC, Inc. and others. All rights reserved.
+##
+## Licensed under the Apache License, Version 2.0 (the "License");
+## you may not use this file except in compliance with the License.
+## You may obtain a copy of the License at
+##
+## http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+##
+dmaap.url = http://
+dmaap.topic = unauthenticated.SEC_FAULT_OUTPUT
+dmaap.consumerGroup = uuiGroup
+dmaap.conusmer = uuiUser
+dmaap.timeout = 10000 \ No newline at end of file
diff --git a/server/src/test/java/org/onap/usecaseui/server/controller/AlarmControllerTest.java b/server/src/test/java/org/onap/usecaseui/server/controller/AlarmControllerTest.java
index a674cf2e..2fbfaadd 100755
--- a/server/src/test/java/org/onap/usecaseui/server/controller/AlarmControllerTest.java
+++ b/server/src/test/java/org/onap/usecaseui/server/controller/AlarmControllerTest.java
@@ -56,12 +56,5 @@ public class AlarmControllerTest {
System.out.println(alarmController.generateCsvFile(null,new String[]{"110"}));
}
- @Test
- public void update() throws JsonProcessingException {
- System.out.println(alarmController.updateStatus(null,new String[]{"110"},new String[]{"1"},"s"));
- System.out.println(alarmController.updateStatus(null,new String[]{"110","1101"},new String[]{"1","1"},"many"));
- System.out.println(alarmController.updateStatus(null,new String[]{"110"},new String[]{"1"},"vf"));
-
- }
}
diff --git a/server/src/test/java/org/onap/usecaseui/server/controller/PerformanceControllerTest.java b/server/src/test/java/org/onap/usecaseui/server/controller/PerformanceControllerTest.java
index 4b90e86e..65ef8708 100755
--- a/server/src/test/java/org/onap/usecaseui/server/controller/PerformanceControllerTest.java
+++ b/server/src/test/java/org/onap/usecaseui/server/controller/PerformanceControllerTest.java
@@ -71,7 +71,7 @@ public class PerformanceControllerTest {
p.put("value","110");
p.put("createTime","110");
p.put("updateTime","110");
- System.out.println(performanceController.generateDiaCsvFile(null,p));
+ //System.out.println(performanceController.generateDiaCsvFile(null,p));
}
@Test