summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/src/main/java/org/onap/usecaseui/server/service/nsmf/ResourceMonitorService.java28
-rw-r--r--server/src/main/java/org/onap/usecaseui/server/service/nsmf/impl/ResourceMonitorServiceConvert.java104
-rw-r--r--server/src/main/java/org/onap/usecaseui/server/service/nsmf/impl/ResourceMonitorServiceImpl.java248
-rw-r--r--server/src/main/resources/slicing.properties22
4 files changed, 402 insertions, 0 deletions
diff --git a/server/src/main/java/org/onap/usecaseui/server/service/nsmf/ResourceMonitorService.java b/server/src/main/java/org/onap/usecaseui/server/service/nsmf/ResourceMonitorService.java
new file mode 100644
index 00000000..7a2a249e
--- /dev/null
+++ b/server/src/main/java/org/onap/usecaseui/server/service/nsmf/ResourceMonitorService.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2019 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.service.nsmf;
+
+import org.onap.usecaseui.server.bean.nsmf.common.ServiceResult;
+import org.onap.usecaseui.server.bean.nsmf.monitor.ServiceList;
+
+public interface ResourceMonitorService {
+
+ ServiceResult querySlicingUsageTraffic(String queryTimestamp, ServiceList serviceList);
+
+ ServiceResult querySlicingOnlineUserNumber(String queryTimestamp, ServiceList serviceList);
+
+ ServiceResult querySlicingTotalBandwidth(String queryTimestamp, ServiceList serviceList);
+}
diff --git a/server/src/main/java/org/onap/usecaseui/server/service/nsmf/impl/ResourceMonitorServiceConvert.java b/server/src/main/java/org/onap/usecaseui/server/service/nsmf/impl/ResourceMonitorServiceConvert.java
new file mode 100644
index 00000000..98663b86
--- /dev/null
+++ b/server/src/main/java/org/onap/usecaseui/server/service/nsmf/impl/ResourceMonitorServiceConvert.java
@@ -0,0 +1,104 @@
+/*
+ * Copyright (C) 2019 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.service.nsmf.impl;
+
+import java.lang.reflect.InvocationTargetException;
+import java.text.ParseException;
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.commons.beanutils.BeanUtils;
+import org.onap.usecaseui.server.bean.nsmf.monitor.ServiceInfo;
+import org.onap.usecaseui.server.bean.nsmf.monitor.ServiceOnlineUserInfo;
+import org.onap.usecaseui.server.bean.nsmf.monitor.ServiceTotalBandwidthInfo;
+import org.onap.usecaseui.server.bean.nsmf.monitor.SlicingKpiReqInfo;
+import org.onap.usecaseui.server.bean.nsmf.monitor.TotalBandwidthInfo;
+import org.onap.usecaseui.server.bean.nsmf.monitor.TrafficReqInfo;
+import org.onap.usecaseui.server.bean.nsmf.monitor.UsageTrafficInfo;
+import org.onap.usecaseui.server.bean.nsmf.monitor.UserNumberInfo;
+import org.onap.usecaseui.server.constant.nsmf.NsmfParamConstant;
+import org.onap.usecaseui.server.service.slicingdomain.kpi.bean.KpiTotalBandwidth;
+import org.onap.usecaseui.server.service.slicingdomain.kpi.bean.KpiTotalBandwidth.TotalBandwidth;
+import org.onap.usecaseui.server.service.slicingdomain.kpi.bean.KpiTotalTraffic;
+import org.onap.usecaseui.server.service.slicingdomain.kpi.bean.KpiUserNumber;
+import org.onap.usecaseui.server.service.slicingdomain.kpi.bean.KpiUserNumber.UserNumbers;
+import org.onap.usecaseui.server.util.nsmf.NsmfCommonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ResourceMonitorServiceConvert {
+
+ private static final Logger logger = LoggerFactory.getLogger(ResourceMonitorServiceConvert.class);
+
+ TrafficReqInfo buildTrafficReqInfo(ServiceInfo serviceInfo, String queryTimestamp) {
+ TrafficReqInfo trafficReqInfo = new TrafficReqInfo();
+ trafficReqInfo.setId(serviceInfo.getServiceId());
+ trafficReqInfo.setTimeStamp(queryTimestamp);
+ return trafficReqInfo;
+ }
+
+ void convertUsageTrafficInfo(UsageTrafficInfo usageTrafficInfo, KpiTotalTraffic kpiTotalTraffic) {
+ usageTrafficInfo.setServiceId(kpiTotalTraffic.getId());
+ usageTrafficInfo.setTrafficData(String.valueOf(kpiTotalTraffic.getTotalTraffic()));
+ }
+
+ SlicingKpiReqInfo buildSlicingKpiReqInfo(ServiceInfo serviceInfo, String queryTimestamp, int kpiHours) {
+ SlicingKpiReqInfo slicingKpiReqInfo = new SlicingKpiReqInfo();
+ slicingKpiReqInfo.setId(serviceInfo.getServiceId());
+ slicingKpiReqInfo.setTimeStamp(queryTimestamp);
+ slicingKpiReqInfo.setHours(kpiHours);
+ return slicingKpiReqInfo;
+ }
+
+ void convertServiceOnlineUserInfo(ServiceOnlineUserInfo serviceOnlineUserInfo, KpiUserNumber kpiUserNumber)
+ throws InvocationTargetException, IllegalAccessException, ParseException {
+
+ List<UserNumberInfo> userNumberInfoList = new ArrayList<>();
+ serviceOnlineUserInfo.setId(kpiUserNumber.getId());
+
+ if (kpiUserNumber.getUserNumbers() != null) {
+ for (UserNumbers userNumbers : kpiUserNumber.getUserNumbers()) {
+ String newTimeStamp = NsmfCommonUtil
+ .timestamp2Time(userNumbers.getTimeStamp().replace("T", NsmfParamConstant.SPACE));
+ UserNumberInfo userNumberInfo = new UserNumberInfo();
+ userNumberInfo.setTimeStamp(newTimeStamp);
+ userNumberInfo.setUserNumber(String.valueOf(userNumbers.getUserNumber()));
+ userNumberInfoList.add(userNumberInfo);
+ }
+ }
+
+ serviceOnlineUserInfo.setUserNumberInfoList(userNumberInfoList);
+ }
+
+ void convertServiceTotalBandwidthInfo(ServiceTotalBandwidthInfo serviceTotalBandwidthInfo,
+ KpiTotalBandwidth kpiTotalBandwidth)
+ throws InvocationTargetException, IllegalAccessException, ParseException {
+
+ List<TotalBandwidthInfo> totalBandwidthInfoList = new ArrayList<>();
+ serviceTotalBandwidthInfo.setId(kpiTotalBandwidth.getId());
+ if (kpiTotalBandwidth.getTotalBandwidth() != null) {
+ for (TotalBandwidth totalBandwidth : kpiTotalBandwidth.getTotalBandwidth()) {
+ String newTimeStamp = NsmfCommonUtil
+ .timestamp2Time(totalBandwidth.getTimeStamp().replace("T", NsmfParamConstant.SPACE));
+ TotalBandwidthInfo totalBandwidthInfo = new TotalBandwidthInfo();
+ totalBandwidthInfo.setTimestamp(newTimeStamp);
+ totalBandwidthInfo.setBandwidth(String.valueOf(totalBandwidth.getBandwidth()));
+ totalBandwidthInfoList.add(totalBandwidthInfo);
+ }
+ }
+
+ serviceTotalBandwidthInfo.setTotalBandwidthInfoList(totalBandwidthInfoList);
+ }
+}
diff --git a/server/src/main/java/org/onap/usecaseui/server/service/nsmf/impl/ResourceMonitorServiceImpl.java b/server/src/main/java/org/onap/usecaseui/server/service/nsmf/impl/ResourceMonitorServiceImpl.java
new file mode 100644
index 00000000..527d493c
--- /dev/null
+++ b/server/src/main/java/org/onap/usecaseui/server/service/nsmf/impl/ResourceMonitorServiceImpl.java
@@ -0,0 +1,248 @@
+/*
+ * Copyright (C) 2019 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.service.nsmf.impl;
+
+import com.alibaba.fastjson.JSON;
+import com.google.gson.Gson;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+import okhttp3.MediaType;
+import okhttp3.RequestBody;
+import org.onap.usecaseui.server.bean.nsmf.common.ResultHeader;
+import org.onap.usecaseui.server.bean.nsmf.common.ServiceResult;
+import org.onap.usecaseui.server.bean.nsmf.monitor.ServiceInfo;
+import org.onap.usecaseui.server.bean.nsmf.monitor.ServiceList;
+import org.onap.usecaseui.server.bean.nsmf.monitor.ServiceOnlineUserInfo;
+import org.onap.usecaseui.server.bean.nsmf.monitor.ServiceOnlineUserList;
+import org.onap.usecaseui.server.bean.nsmf.monitor.ServiceTotalBandwidthInfo;
+import org.onap.usecaseui.server.bean.nsmf.monitor.ServiceTotalBandwidthList;
+import org.onap.usecaseui.server.bean.nsmf.monitor.SlicingKpiReqInfo;
+import org.onap.usecaseui.server.bean.nsmf.monitor.TrafficReqInfo;
+import org.onap.usecaseui.server.bean.nsmf.monitor.UsageTrafficInfo;
+import org.onap.usecaseui.server.bean.nsmf.monitor.UsageTrafficList;
+import org.onap.usecaseui.server.constant.nsmf.NsmfCodeConstant;
+import org.onap.usecaseui.server.constant.nsmf.NsmfParamConstant;
+import org.onap.usecaseui.server.service.nsmf.ResourceMonitorService;
+import org.onap.usecaseui.server.service.slicingdomain.kpi.KpiSliceService;
+import org.onap.usecaseui.server.service.slicingdomain.kpi.bean.KpiTotalBandwidth;
+import org.onap.usecaseui.server.service.slicingdomain.kpi.bean.KpiTotalTraffic;
+import org.onap.usecaseui.server.service.slicingdomain.kpi.bean.KpiUserNumber;
+import org.onap.usecaseui.server.util.RestfulServices;
+import org.onap.usecaseui.server.util.nsmf.NsmfCommonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.context.annotation.EnableAspectJAutoProxy;
+import org.springframework.stereotype.Service;
+import retrofit2.Response;
+
+@Service("ResourceMonitorService")
+@org.springframework.context.annotation.Configuration
+@EnableAspectJAutoProxy
+public class ResourceMonitorServiceImpl implements ResourceMonitorService {
+
+ private final static Logger logger = LoggerFactory.getLogger(ResourceMonitorServiceImpl.class);
+
+ private ResourceMonitorServiceConvert resourceMonitorServiceConvert = new ResourceMonitorServiceConvert();
+ Gson gson = new Gson();
+
+ private KpiSliceService kpiSliceService;
+ private int kpiHours;
+
+ public ResourceMonitorServiceImpl() {
+ this(RestfulServices.create(KpiSliceService.class));
+ }
+
+ public ResourceMonitorServiceImpl(KpiSliceService kpiSliceService) {
+ this.kpiSliceService = kpiSliceService;
+ initConfig();
+ }
+
+ public void initConfig() {
+ InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("slicing.properties");
+ Properties p = new Properties();
+ try {
+ p.load(inputStream);
+ String strKpiHours = p.getProperty("slicing.kpi.hours");
+ this.kpiHours = Integer.parseInt(strKpiHours);
+ } catch (IOException e1) {
+ logger.error("get configuration file arise error :{}", e1.getMessage());
+ }
+ }
+
+ @Override
+ public ServiceResult querySlicingUsageTraffic(String queryTimestamp, ServiceList serviceList) {
+ ServiceResult serviceResult = new ServiceResult();
+ ResultHeader resultHeader = new ResultHeader();
+
+ UsageTrafficList usageTrafficList = new UsageTrafficList();
+ List<UsageTrafficInfo> usageTrafficInfoList = new ArrayList<>();
+ List<ServiceInfo> serviceInfoList = serviceList.getServiceInfoList();
+ String resultMsg = "";
+
+ try {
+ // TODO
+ for (ServiceInfo serviceInfo : serviceInfoList) {
+ String newTimestamp = NsmfCommonUtil.time2Timestamp(queryTimestamp)
+ .replace(NsmfParamConstant.SPACE, "T");
+ TrafficReqInfo trafficReqInfo = resourceMonitorServiceConvert
+ .buildTrafficReqInfo(serviceInfo, newTimestamp);
+ String jsonstr = JSON.toJSONString(trafficReqInfo);
+ RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), jsonstr.toString());
+ Response<KpiTotalTraffic> response = this.kpiSliceService.listTotalTraffic(requestBody).execute();
+ if (response.isSuccessful()) {
+ KpiTotalTraffic kpiTotalTraffic = response.body();
+ logger.info("querySlicingUsageTraffic: listTotalTraffic reponse is:{}",
+ gson.toJson(kpiTotalTraffic).toString());
+ UsageTrafficInfo usageTrafficInfo = new UsageTrafficInfo();
+ resourceMonitorServiceConvert.convertUsageTrafficInfo(usageTrafficInfo, kpiTotalTraffic);
+ usageTrafficInfoList.add(usageTrafficInfo);
+ resultMsg = "5G slicing usage traffic query result.";
+ resultHeader.setResult_code(NsmfCodeConstant.SUCCESS_CODE);
+ } else {
+ logger.error(String
+ .format("querySlicingUsageTraffic: Can not get ActivateService[code={}, message={}]",
+ response.code(),
+ response.message()));
+ resultMsg = "5G slicing usage traffic query failed!";
+ resultHeader.setResult_code(NsmfCodeConstant.ERROR_CODE_UNKNOWN);
+ }
+ }
+ } catch (Exception e) {
+ resultMsg = "5G slicing usage traffic query failed. Unknown exception occurred!";
+ resultHeader.setResult_code(NsmfCodeConstant.ERROR_CODE_UNKNOWN);
+ logger.error(e.getMessage());
+ }
+ usageTrafficList.setUsageTrafficInfoList(usageTrafficInfoList);
+ logger.info(resultMsg);
+ logger.info("querySlicingUsageTraffic: 5G slicing usage traffic query has been finished.");
+ resultHeader.setResult_message(resultMsg);
+ serviceResult.setResult_header(resultHeader);
+ serviceResult.setResult_body(usageTrafficList);
+ return serviceResult;
+ }
+
+ @Override
+ public ServiceResult querySlicingOnlineUserNumber(String queryTimestamp, ServiceList serviceList) {
+ ServiceResult serviceResult = new ServiceResult();
+ ResultHeader resultHeader = new ResultHeader();
+ ServiceOnlineUserList serviceOnlineUserList = new ServiceOnlineUserList();
+ List<ServiceOnlineUserInfo> serviceOnlineUserInfoList = new ArrayList<>();
+ List<ServiceInfo> serviceInfoList = serviceList.getServiceInfoList();
+
+ String resultMsg = "";
+
+ try {
+ // TODO
+ for (ServiceInfo serviceInfo : serviceInfoList) {
+ String newTimestamp = NsmfCommonUtil.time2Timestamp(queryTimestamp)
+ .replace(NsmfParamConstant.SPACE, "T");
+ SlicingKpiReqInfo slicingKpiReqInfo = resourceMonitorServiceConvert
+ .buildSlicingKpiReqInfo(serviceInfo, newTimestamp, kpiHours);
+ String jsonstr = JSON.toJSONString(slicingKpiReqInfo);
+ RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), jsonstr.toString());
+ Response<KpiUserNumber> response = this.kpiSliceService.listUserNumber(requestBody).execute();
+
+ if (response.isSuccessful()) {
+ KpiUserNumber kpiUserNumber = response.body();
+ logger.info("querySlicingOnlineUserNumber: listUserNumber reponse is:{}",
+ gson.toJson(kpiUserNumber).toString());
+ ServiceOnlineUserInfo serviceOnlineUserInfo = new ServiceOnlineUserInfo();
+ resourceMonitorServiceConvert.convertServiceOnlineUserInfo(serviceOnlineUserInfo, kpiUserNumber);
+ serviceOnlineUserInfoList.add(serviceOnlineUserInfo);
+ resultMsg = "5G slicing online users query result.";
+ resultHeader.setResult_code(NsmfCodeConstant.SUCCESS_CODE);
+ } else {
+ logger.error(String
+ .format("querySlicingOnlineUserNumber: Can not get KpiUserNumber[code={}, message={}]",
+ response.code(),
+ response.message()));
+ resultMsg = "5G slicing online users query failed!";
+ resultHeader.setResult_code(NsmfCodeConstant.ERROR_CODE_UNKNOWN);
+ }
+ }
+ } catch (Exception e) {
+ resultMsg = "5G slicing online users query failed. Unknown exception occurred!";
+ resultHeader.setResult_code(NsmfCodeConstant.ERROR_CODE_UNKNOWN);
+ logger.error(e.getMessage());
+ }
+
+ logger.info(resultMsg);
+ logger.info("querySlicingOnlineUserNumber: 5G slicing online users query has been finished.");
+ serviceOnlineUserList.setServiceOnlineUserInfoList(serviceOnlineUserInfoList);
+ resultHeader.setResult_message(resultMsg);
+ serviceResult.setResult_header(resultHeader);
+ serviceResult.setResult_body(serviceOnlineUserList);
+ return serviceResult;
+ }
+
+ @Override
+ public ServiceResult querySlicingTotalBandwidth(String queryTimestamp, ServiceList serviceList) {
+ ServiceResult serviceResult = new ServiceResult();
+ ResultHeader resultHeader = new ResultHeader();
+ ServiceTotalBandwidthList serviceTotalBandwidthList = new ServiceTotalBandwidthList();
+
+ List<ServiceTotalBandwidthInfo> serviceTotalBandwidthInfoList = new ArrayList<>();
+ List<ServiceInfo> serviceInfoList = serviceList.getServiceInfoList();
+
+ String resultMsg = "";
+
+ try {
+ for (ServiceInfo serviceInfo : serviceInfoList) {
+ String newTimestamp = NsmfCommonUtil.time2Timestamp(queryTimestamp)
+ .replace(NsmfParamConstant.SPACE, "T");
+ SlicingKpiReqInfo slicingKpiReqInfo = resourceMonitorServiceConvert
+ .buildSlicingKpiReqInfo(serviceInfo, newTimestamp, kpiHours);
+ String jsonstr = JSON.toJSONString(slicingKpiReqInfo);
+ RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), jsonstr.toString());
+ Response<KpiTotalBandwidth> response = this.kpiSliceService.listTotalBandwidth(requestBody).execute();
+
+ if (response.isSuccessful()) {
+ KpiTotalBandwidth kpiTotalBandwidth = response.body();
+ logger.info("querySlicingTotalBandwidth: listTotalBandwidth reponse is:{}",
+ gson.toJson(kpiTotalBandwidth).toString());
+ ServiceTotalBandwidthInfo serviceTotalBandwidthInfo = new ServiceTotalBandwidthInfo();
+ resourceMonitorServiceConvert
+ .convertServiceTotalBandwidthInfo(serviceTotalBandwidthInfo, kpiTotalBandwidth);
+ serviceTotalBandwidthInfoList.add(serviceTotalBandwidthInfo);
+ resultMsg = "5G slicing total bandwidth query result.";
+ resultHeader.setResult_code(NsmfCodeConstant.SUCCESS_CODE);
+ } else {
+ logger.error(String
+ .format("querySlicingTotalBandwidth: Can not get KpiUserNumber[code={}, message={}]",
+ response.code(),
+ response.message()));
+ resultMsg = "5G slicing total bandwidth query failed!";
+ resultHeader.setResult_code(NsmfCodeConstant.ERROR_CODE_UNKNOWN);
+ }
+ }
+ } catch (Exception e) {
+ resultMsg = "5G slicing total bandwidth query failed. Unknown exception occurred!";
+ resultHeader.setResult_code(NsmfCodeConstant.ERROR_CODE_UNKNOWN);
+ logger.error(e.getMessage());
+ }
+
+ logger.info(resultMsg);
+ logger.info("querySlicingTotalBandwidth: 5G slicing total bandwidth query has been finished.");
+ serviceTotalBandwidthList.setServiceTotalBandwidthInfoList(serviceTotalBandwidthInfoList);
+ resultHeader.setResult_message(resultMsg);
+ serviceResult.setResult_header(resultHeader);
+ serviceResult.setResult_body(serviceTotalBandwidthList);
+ return serviceResult;
+ }
+}
diff --git a/server/src/main/resources/slicing.properties b/server/src/main/resources/slicing.properties
new file mode 100644
index 00000000..e9363c27
--- /dev/null
+++ b/server/src/main/resources/slicing.properties
@@ -0,0 +1,22 @@
+##
+## Copyright (C) 2019 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.
+##/
+
+slicing.kpi.hours=4
+slicing.globalSubscriberId=5GCustomer
+slicing.serviceType=5G
+slicing.serviceInvariantUuid=e75698d9-925a-4cdd-a6c0-edacbe6a0b51
+slicing.serviceUuid=8ee5926d-720b-4bb2-86f9-d20e921c143b
+