summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzhaoyehua <zhaoyh6@asiainfo.com>2021-10-25 14:56:56 +0800
committer’zhaoyh6‘ <zhaoyh6@asiainfo.com>2021-10-25 14:59:26 +0800
commit8a082cb9ef0b96a06760ee10233c629d12fab9cd (patch)
treef773bce211e22b47d64a2f6ac6bf98effb6ea89c
parentdcbfd5f2e9f4a16d90c4e49aeed2c5278dbf8f47 (diff)
fix:The query mode and operation mode are optimized
Issue-ID: USECASEUI-605 Signed-off-by: ’zhaoyh6‘ <zhaoyh6@asiainfo.com> Change-Id: Ib4c81d42897e420b68c65686ed3efe5d985b3d62 Signed-off-by: ’zhaoyh6‘ <zhaoyh6@asiainfo.com>
-rw-r--r--server/src/main/java/org/onap/usecaseui/server/bean/intent/InstancePerformance.java14
-rw-r--r--server/src/main/java/org/onap/usecaseui/server/conf/intent/IntentScheduleTask.java7
-rw-r--r--server/src/main/java/org/onap/usecaseui/server/controller/IntentController.java97
-rw-r--r--server/src/main/java/org/onap/usecaseui/server/service/intent/IntentApiService.java11
-rw-r--r--server/src/main/java/org/onap/usecaseui/server/service/intent/IntentInstanceService.java11
-rw-r--r--server/src/main/java/org/onap/usecaseui/server/service/intent/impl/IntentInstanceServiceImpl.java287
-rw-r--r--server/src/main/java/org/onap/usecaseui/server/service/intent/impl/IntentServiceImpl.java2
-rw-r--r--server/src/test/java/org/onap/usecaseui/server/controller/IntentControllerTest.java2
-rw-r--r--standalone/src/main/assembly/resources/dbscripts/postgres/uui_create_table.sql11
9 files changed, 345 insertions, 97 deletions
diff --git a/server/src/main/java/org/onap/usecaseui/server/bean/intent/InstancePerformance.java b/server/src/main/java/org/onap/usecaseui/server/bean/intent/InstancePerformance.java
index 677f86fa..25ddb6f0 100644
--- a/server/src/main/java/org/onap/usecaseui/server/bean/intent/InstancePerformance.java
+++ b/server/src/main/java/org/onap/usecaseui/server/bean/intent/InstancePerformance.java
@@ -35,14 +35,14 @@ public class InstancePerformance implements Serializable {
private String resourceInstanceId;
@Column(name = "bandwidth")
- private String bandwidth;
+ private int bandwidth;
- @Temporal(TemporalType.DATE)
+ @Temporal(TemporalType.TIMESTAMP)
@Column(name = "date")
private Date date;
@Column(name = "max_bandwidth")
- private String maxBandwidth;
+ private int maxBandwidth;
public InstancePerformance() {
@@ -73,11 +73,11 @@ public class InstancePerformance implements Serializable {
this.resourceInstanceId = resourceInstanceId;
}
- public String getBandwidth() {
+ public int getBandwidth() {
return bandwidth;
}
- public void setBandwidth(String bandwidth) {
+ public void setBandwidth(int bandwidth) {
this.bandwidth = bandwidth;
}
@@ -89,11 +89,11 @@ public class InstancePerformance implements Serializable {
this.date = date;
}
- public String getMaxBandwidth() {
+ public int getMaxBandwidth() {
return maxBandwidth;
}
- public void setMaxBandwidth(String maxBandwidth) {
+ public void setMaxBandwidth(int maxBandwidth) {
this.maxBandwidth = maxBandwidth;
}
} \ No newline at end of file
diff --git a/server/src/main/java/org/onap/usecaseui/server/conf/intent/IntentScheduleTask.java b/server/src/main/java/org/onap/usecaseui/server/conf/intent/IntentScheduleTask.java
index f35edf41..4f168801 100644
--- a/server/src/main/java/org/onap/usecaseui/server/conf/intent/IntentScheduleTask.java
+++ b/server/src/main/java/org/onap/usecaseui/server/conf/intent/IntentScheduleTask.java
@@ -18,6 +18,7 @@ package org.onap.usecaseui.server.conf.intent;
import org.onap.usecaseui.server.service.intent.IntentInstanceService;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
import javax.annotation.Resource;
import java.io.IOException;
@@ -30,11 +31,11 @@ public class IntentScheduleTask {
@Resource(name = "IntentInstanceService")
private IntentInstanceService intentInstanceService;
-// @Scheduled(cron = "0/20 * * * * ?")
+ @Scheduled(cron = "0/20 * * * * ?")
public void getIntentInstanceCompleteness() {
- intentInstanceService.getIntentInstanceProgress();
+ intentInstanceService.getIntentInstanceCreateStatus();
}
-// @Scheduled(cron = "0/20 * * * * ?")
+ @Scheduled(cron = "0/20 * * * * ?")
public void getIntentInstanceBandwidth() throws IOException {
intentInstanceService.getIntentInstanceBandwidth();
}
diff --git a/server/src/main/java/org/onap/usecaseui/server/controller/IntentController.java b/server/src/main/java/org/onap/usecaseui/server/controller/IntentController.java
index 4a324a63..4dbed7bd 100644
--- a/server/src/main/java/org/onap/usecaseui/server/controller/IntentController.java
+++ b/server/src/main/java/org/onap/usecaseui/server/controller/IntentController.java
@@ -21,6 +21,7 @@ import java.text.ParseException;
import java.util.*;
import javax.annotation.Resource;
+import com.alibaba.fastjson.JSONArray;
import org.apache.commons.collections.MapUtils;
import org.onap.usecaseui.server.bean.HttpResponseResult;
import org.onap.usecaseui.server.bean.intent.IntentInstance;
@@ -51,7 +52,13 @@ import com.fasterxml.jackson.databind.ObjectMapper;
public class IntentController {
private final Logger logger = LoggerFactory.getLogger(IntentController.class);
private final static String UPLOADPATH = "/home/uui/upload/";
- private final static String NLPLOADPATH = "/home/run/bert-master/upload/";
+ private final static String NLPLOADPATH = "/home/uuihome/uui/bert-master/upload/";
+ private final static String[] QUESTIONS_CCVPN = {"bandwidth", "access point", "cloud point"};
+ private final static String[] QUESTIONS_5GS = {"Communication Service Name", "Max Number of UEs", "Data Rate Downlink", "Latency", "Data Rate Uplink", "Resource Sharing Level", "Mobility", "Area"};
+
+ private final static String MODEL_TYPE_CCVPN = "ccvpn";
+ private final static String MODEL_TYPE_5GS = "5gs";
+
@Resource(name = "IntentService")
private IntentService intentService;
@@ -232,11 +239,12 @@ public class IntentController {
if (modelType == null || !modelType.equals(activeModelType)) {
throw new RuntimeException("The active model file does not support parsing the current text");
}
+ String[] questions = getQuestions(modelType);
String url = "http://uui-nlp:33011/api/online/predict";
HashMap<String, String> headers = new HashMap<>();
String bodyStr = "{\"title\": \"predict\", \"text\": \"" + text
- + "\"}";
+ + "\", \"questions\":" + new JSONArray(Arrays.asList(questions)).toJSONString() + "}";
logger.info("request body: " + bodyStr);
HttpResponseResult result = HttpUtil.sendPostRequestByJson(url, headers, bodyStr);
@@ -249,12 +257,32 @@ public class IntentController {
JSONObject map2 = new JSONObject();
- for (Map.Entry<String, Object> entry:map.entrySet()) {
- logger.debug(entry.getKey()+","+entry.getValue());
- String key = tranlateFieldName(entry.getKey());
- String valueStr = (String) entry.getValue();
- String value = intentService.calcFieldValue(key, valueStr);
- map2.put(key, value);
+ if (MODEL_TYPE_CCVPN.equals(modelType)) {
+
+ String bandWidth = map.getString("bandwidth");
+ String accessPoint = map.getString("access point");
+ String cloudPoint = map.getString("cloud point");
+ String instanceId = getUUID();
+ String accessPointAlias = intentInstanceService.formatAccessPoint(accessPoint);
+ String bandwidthAlias = intentInstanceService.formatBandwidth(bandWidth);
+ String cloudPointAlias = intentInstanceService.formatCloudPoint(cloudPoint);
+
+ Map<String, Object> accessPointOne = new HashMap<>();
+ accessPointOne.put("name", accessPointAlias);
+ accessPointOne.put("bandwidth", bandwidthAlias);
+ map2.put("name", "");
+ map2.put("instanceId", instanceId);
+ map2.put("accessPointOne", accessPointOne);
+ map2.put("cloudPointName", cloudPointAlias);
+ }
+ else {
+ for (Map.Entry<String, Object> entry:map.entrySet()) {
+ logger.debug(entry.getKey()+","+entry.getValue());
+ String key = tranlateFieldName(entry.getKey());
+ String valueStr = (String) entry.getValue();
+ String value = intentService.calcFieldValue(key, valueStr);
+ map2.put(key, value);
+ }
}
logger.info("translate result: " + map2.toJSONString());
@@ -262,6 +290,13 @@ public class IntentController {
return map2.toJSONString();
}
+ private String[] getQuestions(String modelType) {
+ if (MODEL_TYPE_CCVPN.equals(modelType)) {
+ return QUESTIONS_CCVPN;
+ } else {
+ return QUESTIONS_5GS;
+ }
+ }
private static String tranlateFieldName(String key){
@@ -270,14 +305,14 @@ public class IntentController {
return ret;
HashMap<String, String> map = new HashMap<>();
- map.put("Communication service","name");
- map.put("Maximum user devices","maxNumberofUEs");
- map.put("Downlink data rate","expDataRateDL");
- map.put("Time delay","latency");
- map.put("Uplink data rate","expDataRateUL");
- map.put("Resource","resourceSharingLevel");
+ map.put("Communication Service Name","name");
+ map.put("Max Number of UEs","maxNumberofUEs");
+ map.put("Data Rate Downlink","expDataRateDL");
+ map.put("Latency","latency");
+ map.put("Data Rate Uplink","expDataRateUL");
+ map.put("Resource Sharing Level","resourceSharingLevel");
map.put("Mobility","uEMobilityLevel");
- map.put("Region","coverageArea");
+ map.put("Area","coverageArea");
ret = map.get(key.trim());
return ret;
@@ -288,16 +323,22 @@ public class IntentController {
@GetMapping(value = {"/getInstanceId"},
produces = "application/json")
public JSONObject getInstanceId() {
+ String instanceId = getUUID();
+ JSONObject result = new JSONObject();
+ result.put("instanceId", instanceId);
+ return result;
+ }
+
+ private String getUUID() {
int first = new Random(10).nextInt(8) + 1;
int hashCodeV = UUID.randomUUID().toString().hashCode();
- if (hashCodeV < 0) {//有可能是负数
+ if (hashCodeV < 0) {
hashCodeV = -hashCodeV;
}
String instanceId = first + String.format("%015d", hashCodeV);
- JSONObject result = new JSONObject();
- result.put("instanceId", instanceId);
- return result;
+ return instanceId;
}
+
@IntentResponseBody
@ResponseBody
@PostMapping (value = {"/getInstanceList"},consumes = MediaType.APPLICATION_JSON_VALUE,
@@ -328,6 +369,7 @@ public class IntentController {
intentInstance.setCloudPointName(cloudPointName);
intentInstance.setAccessPointOneName(accessPointOneName);
intentInstance.setAccessPointOneBandWidth(accessPointOneBandWidth);
+ intentInstance.setStatus("0");
int flag = intentInstanceService.createIntentInstance(intentInstance);
@@ -355,11 +397,8 @@ public class IntentController {
}
@IntentResponseBody
- @ResponseBody
- @PostMapping(value = {"/deleteIntentInstance"}, consumes = MediaType.APPLICATION_JSON_VALUE,
- produces = "application/json; charset=utf-8")
- public Object deleteIntentInstance(@RequestBody Object body) {
- String instanceId= (String) ((Map)body).get("instanceId");
+ @DeleteMapping(value = {"/deleteIntentInstance"}, produces = "application/json; charset=utf-8")
+ public Object deleteIntentInstance(@RequestParam String instanceId) {
intentInstanceService.deleteIntentInstance(instanceId);
return "ok";
}
@@ -397,4 +436,14 @@ public class IntentController {
public Object queryAccessNodeInfo() throws IOException{
return intentInstanceService.queryAccessNodeInfo();
}
+
+
+ @IntentResponseBody
+ @ResponseBody
+ @PostMapping(value = {"/getInstanceStatus"}, consumes = MediaType.APPLICATION_JSON_VALUE,
+ produces = "application/json; charset=utf-8")
+ public Object getInstanceStatus(@RequestBody Object body) {
+ JSONArray ids= new JSONObject((Map)body).getJSONArray("ids");
+ return intentInstanceService.getInstanceStatus(ids);
+ }
}
diff --git a/server/src/main/java/org/onap/usecaseui/server/service/intent/IntentApiService.java b/server/src/main/java/org/onap/usecaseui/server/service/intent/IntentApiService.java
index 2c636479..62f2381a 100644
--- a/server/src/main/java/org/onap/usecaseui/server/service/intent/IntentApiService.java
+++ b/server/src/main/java/org/onap/usecaseui/server/service/intent/IntentApiService.java
@@ -58,10 +58,19 @@ public interface IntentApiService {
Call<JSONObject> getInstanceBandwidth(@Path("resource-service-id") String resourceServiceId);
@Headers({
+ "X-TransactionId: 9999",
+ "X-FromAppId: MSO",
+ "Authorization: Basic QUFJOkFBSQ==",
+ "Accept: application/json"
+ })
+ @GET("/aai/v24/business/customers/customer/IBNCustomer/service-subscriptions/service-subscription/IBN/service-instances/service-instance/{resource-service-id}")
+ Call<JSONObject> getInstanceInfo(@Path("resource-service-id") String resourceServiceId);
+
+ @Headers({
"Authorization: Basic SW5mcmFQb3J0YWxDbGllbnQ6cGFzc3dvcmQxJA==",
"Accept: application/json"
})
- @DELETE("/so/infra/serviceIntent/v1/delete")
+ @HTTP(method="DELETE", path="/so/infra/serviceIntent/v1/delete", hasBody = true)
Call<JSONObject> deleteIntentInstance(@Body RequestBody body);
@Headers({
diff --git a/server/src/main/java/org/onap/usecaseui/server/service/intent/IntentInstanceService.java b/server/src/main/java/org/onap/usecaseui/server/service/intent/IntentInstanceService.java
index dfc86830..ddbcb6e4 100644
--- a/server/src/main/java/org/onap/usecaseui/server/service/intent/IntentInstanceService.java
+++ b/server/src/main/java/org/onap/usecaseui/server/service/intent/IntentInstanceService.java
@@ -15,6 +15,8 @@
*/
package org.onap.usecaseui.server.service.intent;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
import org.onap.usecaseui.server.bean.intent.IntentInstance;
import org.onap.usecaseui.server.util.Page;
@@ -26,6 +28,7 @@ public interface IntentInstanceService {
Page<IntentInstance> queryIntentInstance(IntentInstance intentInstance, int currentPage, int pageSize);
int createIntentInstance(IntentInstance intentInstance);
void getIntentInstanceProgress();
+ void getIntentInstanceCreateStatus();
List<IntentInstance> getFinishedInstanceInfo();
void getIntentInstanceBandwidth() throws IOException;
@@ -38,4 +41,12 @@ public interface IntentInstanceService {
Map<String, Object> queryInstancePerformanceData(String instanceId);
Object queryAccessNodeInfo() throws IOException;
+
+ JSONObject getInstanceStatus(JSONArray ids);
+
+ String formatBandwidth(String strValue);
+
+ String formatCloudPoint(String cloudPoint);
+
+ String formatAccessPoint(String accessPoint);
}
diff --git a/server/src/main/java/org/onap/usecaseui/server/service/intent/impl/IntentInstanceServiceImpl.java b/server/src/main/java/org/onap/usecaseui/server/service/intent/impl/IntentInstanceServiceImpl.java
index fe8ee64f..6b1e96c9 100644
--- a/server/src/main/java/org/onap/usecaseui/server/service/intent/impl/IntentInstanceServiceImpl.java
+++ b/server/src/main/java/org/onap/usecaseui/server/service/intent/impl/IntentInstanceServiceImpl.java
@@ -42,6 +42,8 @@ import javax.transaction.Transactional;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
@Service("IntentInstanceService")
@Transactional
@@ -58,6 +60,12 @@ public class IntentInstanceServiceImpl implements IntentInstanceService {
private SOService soService;
+ private final static int MAX_BANDWIDTH = 6000;
+ private final static int MIN_BANDWIDTH = 100;
+
+ private final static List<String> GB_COMPANY = Arrays.asList(new String[] {"gbps", "gb"});
+ private final static List<String> MB_COMPANY = Arrays.asList(new String[] {"mbps", "mb"});
+
public IntentInstanceServiceImpl() {
this(RestfulServices.create(IntentApiService.class),RestfulServices.create(SOService.class));
}
@@ -106,6 +114,8 @@ public class IntentInstanceServiceImpl implements IntentInstanceService {
} catch (Exception e) {
logger.error("exception occurred while performing AlarmsHeaderServiceImpl queryAlarmsHeader. Details:" + e.getMessage());
return null;
+ } finally {
+ session.close();
}
}
@@ -134,11 +144,15 @@ public class IntentInstanceServiceImpl implements IntentInstanceService {
} catch (Exception e) {
logger.error("exception occurred while performing IntentInstanceServiceImpl getAllCount. Details:" + e.getMessage());
return -1;
+ } finally {
+ session.close();
}
}
@Override
public int createIntentInstance(IntentInstance intentInstance) {
+ Session session = getSession();
+ Transaction tx = null;
try{
if (null == intentInstance){
@@ -146,17 +160,25 @@ public class IntentInstanceServiceImpl implements IntentInstanceService {
return 0;
}
String jobId = createIntentInstanceToSO(intentInstance);
+ if (null == jobId){
+ logger.error("create Instance error:jobId is null");
+ return 0;
+ }
intentInstance.setJobId(jobId);
intentInstance.setResourceInstanceId("cll-"+intentInstance.getInstanceId());
- Session session = getSession();
- Transaction tx = session.beginTransaction();
+
+ tx = session.beginTransaction();
session.save(intentInstance);
tx.commit();
-// session.flush();
return 1;
} catch (Exception e) {
+ if (tx != null) {
+ tx.rollback();
+ }
logger.error("Details:" + e.getMessage());
return 0;
+ } finally {
+ session.close();
}
}
@@ -207,7 +229,24 @@ public class IntentInstanceServiceImpl implements IntentInstanceService {
if (progress >=100) {
instance.setStatus("1");
}
- instance.setProgress(progress);
+ }
+ catch (Exception e) {
+ logger.info("get progress exception:"+e);
+ }
+ }
+ saveProgress(instanceList);
+
+ }
+ @Override
+ public void getIntentInstanceCreateStatus() {
+ List<IntentInstance> instanceList = getInstanceByFinishedFlag("0");
+ for (IntentInstance instance: instanceList) {
+ try {
+
+ int flag = getCreateStatusByJobId(instance);
+ if (flag > 0) {
+ instance.setStatus(flag + "");
+ }
}
catch (Exception e) {
logger.info("get progress exception:"+e);
@@ -218,14 +257,16 @@ public class IntentInstanceServiceImpl implements IntentInstanceService {
}
private void saveProgress(List<IntentInstance> instanceList) {
- Transaction tx = null;
if(instanceList == null || instanceList.isEmpty()) {
return;
}
- try(Session session = getSession()) {
+ Session session = getSession();
+ Transaction tx = null;
+ try {
tx = session.beginTransaction();
for (IntentInstance instance : instanceList) {
- session.save(instance);
+ session.update(instance);
+ session.flush();
}
tx.commit();
logger.info("update progress ok");
@@ -236,12 +277,35 @@ public class IntentInstanceServiceImpl implements IntentInstanceService {
}
logger.error("update progress exception:"+e);
+ } finally {
+ session.close();
}
}
private int getProgressByJobId(IntentInstance instance) throws IOException {
Response<OperationProgressInformation> response = soService.queryOperationProgress(instance.getResourceInstanceId(), instance.getJobId()).execute();
- return response.body().getOperationStatus().getProgress();
+ logger.debug(response.toString());
+ if (response.isSuccessful()) {
+ return response.body().getOperationStatus().getProgress();
+ }
+ return -1;
+ }
+
+ private int getCreateStatusByJobId(IntentInstance instance) throws IOException {
+ if (instance == null || instance.getResourceInstanceId() == null) {
+ return -1;
+ }
+ Response<JSONObject> response = intentApiService.getInstanceInfo(instance.getResourceInstanceId()).execute();
+ logger.debug(response.toString());
+ if (response.isSuccessful()) {
+ String status = response.body().getString("orchestration-status");
+ if ("created".equals(status)) {
+ return 1;
+ }
+ return 0;
+ }
+ logger.error("getIntentInstance Create Statue Error:" + response.toString());
+ return -1;
}
private List<IntentInstance> getInstanceByFinishedFlag(String flag) {
@@ -256,6 +320,8 @@ public class IntentInstanceServiceImpl implements IntentInstanceService {
} catch (Exception e) {
logger.error("exception occurred while performing IntentInstanceServiceImpl getNotFinishedJobId. Details:" + e.getMessage());
return null;
+ } finally {
+ session.close();
}
}
@@ -273,6 +339,8 @@ public class IntentInstanceServiceImpl implements IntentInstanceService {
} catch (Exception e) {
logger.error("exception occurred while performing IntentInstanceServiceImpl getNotFinishedJobId. Details:" + e.getMessage());
return null;
+ } finally {
+ session.close();
}
}
@@ -282,6 +350,10 @@ public class IntentInstanceServiceImpl implements IntentInstanceService {
for (IntentInstance instance : instanceList) {
String serviceInstanceId = instance.getResourceInstanceId();
Response<JSONObject> response = intentApiService.getInstanceNetworkInfo(serviceInstanceId).execute();
+ if (!response.isSuccessful()) {
+ logger.error("get Intent-Instance Bandwidth error:" + response.toString());
+ continue;
+ }
JSONObject responseBody = response.body();
JSONObject allottedResource = responseBody.getJSONObject("allotted-resources").getJSONArray("allotted-resource").getJSONObject(0);
JSONArray relationshipList = allottedResource.getJSONObject("relationship-list").getJSONArray("relationship");
@@ -302,25 +374,42 @@ public class IntentInstanceServiceImpl implements IntentInstanceService {
logger.error("get network Policy Id exception. serviceInstanceId:" + instance.getResourceInstanceId());
continue;
}
- JSONObject networkPolicyInfo = intentApiService.getInstanceNetworkPolicyInfo(networkPolicyId).execute().body();
- String maxBandwidth = networkPolicyInfo.getString("max-bandwidth");
+
+ Response<JSONObject> networkPolicyInfoResponse = intentApiService.getInstanceNetworkPolicyInfo(networkPolicyId).execute();
+ if (!networkPolicyInfoResponse.isSuccessful()) {
+ logger.error("get Intent-Instance networkPolicyInfo error:" + networkPolicyInfoResponse.toString());
+ continue;
+ }
+ JSONObject networkPolicyInfo = networkPolicyInfoResponse.body();
+ int maxBandwidth = networkPolicyInfo.getIntValue("max-bandwidth");
InstancePerformance instancePerformance = new InstancePerformance();
instancePerformance.setMaxBandwidth(maxBandwidth);
instancePerformance.setResourceInstanceId(instance.getResourceInstanceId());
instancePerformance.setJobId(instance.getJobId());
instancePerformance.setDate(new Date());
- JSONObject metadatum = intentApiService.getInstanceBandwidth(serviceInstanceId).execute().body();
- String metaval = metadatum.getJSONArray("metadatum").getJSONObject(0).getString("metaval");
+ Response<JSONObject> metadatumResponse = intentApiService.getInstanceBandwidth(serviceInstanceId).execute();
+ if (!metadatumResponse.isSuccessful()) {
+ logger.error("get Intent-Instance metadatum error:" + metadatumResponse.toString());
+ continue;
+ }
+ JSONObject metadatum = metadatumResponse.body();
+ int metaval = metadatum.getJSONArray("metadatum").getJSONObject(0).getIntValue("metaval");
instancePerformance.setBandwidth(metaval);
+ Session session = getSession();
+ Transaction tx = null;
try{
- Session session = getSession();
- Transaction tx = session.beginTransaction();
+ tx = session.beginTransaction();
session.save(instancePerformance);
tx.commit();
} catch (Exception e) {
+ if(tx!=null){
+ tx.rollback();
+ }
logger.error("Details:" + e.getMessage());
+ } finally {
+ session.close();
}
@@ -330,8 +419,8 @@ public class IntentInstanceServiceImpl implements IntentInstanceService {
@Override
public void deleteIntentInstance(String instanceId) {
IntentInstance result = null;
-
- try(Session session = getSession()) {
+ Session session = getSession();
+ try {
result = (IntentInstance)session.createQuery("from IntentInstance where deleteState = 0 and instanceId = :instanceId")
.setParameter("instanceId", instanceId).uniqueResult();
@@ -340,11 +429,13 @@ public class IntentInstanceServiceImpl implements IntentInstanceService {
} catch (Exception e) {
logger.error("getodel occur exception:"+e);
+ } finally {
+ session.close();
}
try {
String serviceInstanceId = result.getResourceInstanceId();
deleteInstanceToSO(serviceInstanceId);
- deleteInstance(serviceInstanceId);
+ deleteInstance(result);
}catch (Exception e) {
logger.error("delete instance to SO error :" + e);
}
@@ -363,20 +454,16 @@ public class IntentInstanceServiceImpl implements IntentInstanceService {
okhttp3.RequestBody requestBody = okhttp3.RequestBody.create(okhttp3.MediaType.parse("application/json"), JSON.toJSONString(params));
intentApiService.deleteIntentInstance(requestBody).execute();
}
- private String deleteInstance(String serviceInstanceId) {
+ private String deleteInstance(IntentInstance instance) {
Transaction tx = null;
String result="0";
- if(serviceInstanceId==null || serviceInstanceId.trim().equals(""))
- return result;
-
- try(Session session = getSession()) {
+ Session session = getSession();
+ try {
tx = session.beginTransaction();
- IntentInstance instance = new IntentInstance();
- instance.setInstanceId(serviceInstanceId);
session.delete(instance);
tx.commit();
- logger.info("delete instance OK, id=" + serviceInstanceId);
+ logger.info("delete instance OK, id=" + instance.getInstanceId());
result="1";
} catch (Exception e) {
@@ -385,6 +472,8 @@ public class IntentInstanceServiceImpl implements IntentInstanceService {
}
logger.error("delete instance occur exception:"+e);
+ } finally {
+ session.close();
}
return result;
}
@@ -392,75 +481,79 @@ public class IntentInstanceServiceImpl implements IntentInstanceService {
@Override
public void activeIntentInstance(String instanceId) {
IntentInstance instance = null;
-
- try(Session session = getSession()) {
+ Session session = getSession();
+ Transaction tx = null;
+ try {
instance = (IntentInstance)session.createQuery("from IntentInstance where deleteState = 0 and instanceId = :instanceId and status = :status")
.setParameter("instanceId", instanceId).setParameter("status", "3").uniqueResult();
logger.info("get instance OK, id=" + instanceId);
- } catch (Exception e) {
- logger.error("getodel occur exception:"+e);
+ if (null == instance) {
+ logger.error("intentInstance is null!");
+ return;
+ }
- }
- if (null == instance) {
- logger.error("intentInstance is null!");
- return;
- }
- try {
String jobId = createIntentInstanceToSO(instance);
instance.setStatus("0");
instance.setJobId(jobId);
- Session session = getSession();
- Transaction tx = session.beginTransaction();
+ tx = session.beginTransaction();
session.save(instance);
tx.commit();
}catch (Exception e) {
+ if(tx!=null){
+ tx.rollback();
+ }
logger.error("active instance to SO error :" + e);
+ } finally {
+ session.close();
}
}
public void invalidIntentInstance(String instanceId) {
IntentInstance instance = null;
-
- try(Session session = getSession()) {
+ Session session = getSession();
+ Transaction tx = null;
+ try {
instance = (IntentInstance)session.createQuery("from IntentInstance where deleteState = 0 and instanceId = :instanceId")
.setParameter("instanceId", instanceId).uniqueResult();
logger.info("get instance OK, id=" + instanceId);
- } catch (Exception e) {
- logger.error("get instance occur exception:"+e);
-
- }
- if (null == instance) {
- logger.error("intentInstance is null!");
- return;
- }
- try {
+ if (null == instance) {
+ logger.error("intentInstance is null!");
+ return;
+ }
deleteInstanceToSO(instance.getInstanceId());
instance.setStatus("3");
- Session session = getSession();
- Transaction tx = session.beginTransaction();
+ tx = session.beginTransaction();
session.save(instance);
+ session.flush();
tx.commit();
}catch (Exception e) {
+ if(tx!=null){
+ tx.rollback();
+ }
logger.error("invalid instance to SO error :" + e);
+ } finally {
+ session.close();
}
}
@Override
public Map<String, Object> queryInstancePerformanceData(String instanceId) {
- try(Session session = getSession()) {
+ Session session = getSession();
+ try {
String hql = "from IntentInstance i, InstancePerformance p where i.resourceInstanceId = p.resourceInstanceId and i.instanceId = :instanceId and i.deleteState = 0 order by p.date";
Query query = session.createQuery(hql).setParameter("instanceId", instanceId);
List<Object[]> queryResult= query.list();
List<String> date = new ArrayList<>();
- List<String> bandwidth = new ArrayList<>();
- List<String> maxBandwidth = new ArrayList<>();
- SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd");
- for (Object[] o : queryResult) {
+ List<Integer> bandwidth = new ArrayList<>();
+ List<Integer> maxBandwidth = new ArrayList<>();
+ SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ for (int i = queryResult.size() > 50? queryResult.size() - 50 : 0; i < queryResult.size(); i++) {
+ Object[] o = queryResult.get(i);
InstancePerformance performance = (InstancePerformance) o[1];
date.add(ft.format(performance.getDate()));
bandwidth.add(performance.getBandwidth());
@@ -484,6 +577,8 @@ public class IntentInstanceServiceImpl implements IntentInstanceService {
}catch (Exception e) {
logger.error("invalid instance to SO error :" + e);
throw e;
+ } finally {
+ session.close();
}
}
@@ -493,6 +588,10 @@ public class IntentInstanceServiceImpl implements IntentInstanceService {
List<String> accessNodeList = new ArrayList<>();
List<String> cloudAccessNodeList = new ArrayList<>();
Response<JSONObject> response = intentApiService.queryNetworkRoute().execute();
+ if (!response.isSuccessful()) {
+ logger.error(response.toString());
+ throw new RuntimeException("Query Access Node Info Error");
+ }
JSONObject body = response.body();
JSONArray data = body.getJSONArray("network-route");
for (int i = 0; i<data.size(); i++) {
@@ -508,4 +607,82 @@ public class IntentInstanceServiceImpl implements IntentInstanceService {
result.put("cloudAccessNodeList",cloudAccessNodeList);
return result;
}
+
+ @Override
+ public JSONObject getInstanceStatus(JSONArray ids) {
+ Session session = getSession();
+ try {
+ JSONObject result = new JSONObject();
+ JSONArray instanceInfos = new JSONArray();
+ String hql = "from IntentInstance i where i.instanceId in (:ids)";
+ Query query = session.createQuery(hql).setParameter("ids", ids);
+ List<IntentInstance> queryResult= query.list();
+ if (queryResult != null && queryResult.size() > 0) {
+ for (IntentInstance instance : queryResult) {
+ JSONObject instanceInfo = new JSONObject();
+ instanceInfo.put("id", instance.getInstanceId());
+ instanceInfo.put("status", instance.getStatus());
+ instanceInfos.add(instanceInfo);
+ }
+ }
+ result.put("IntentInstances",instanceInfos);
+ return result;
+
+ } catch (Exception e) {
+ logger.error("get Instance status error : " + e.getMessage());
+ throw e;
+ } finally {
+ session.close();
+ }
+ }
+
+
+ public String formatBandwidth(String strValue) {
+ String ret;
+ Pattern pattern = Pattern.compile("(\\d+)([\\w ]*)");
+ Matcher matcher = pattern.matcher(strValue);
+
+
+ int dataRate = 100;
+ if (matcher.matches()) {
+ dataRate = Integer.parseInt(matcher.group(1));
+ String company = matcher.group(2).trim().toLowerCase();
+ if (GB_COMPANY.contains(company)) {
+ dataRate = dataRate * 1000;
+ }
+ else if (!MB_COMPANY.contains(company)) {
+ dataRate = 100;
+ }
+ dataRate = dataRate < MIN_BANDWIDTH ? MIN_BANDWIDTH : (dataRate > MAX_BANDWIDTH ? MAX_BANDWIDTH : dataRate);
+ }
+ ret = dataRate + "";
+ return ret;
+ }
+
+
+ public String formatCloudPoint(String cloudPoint) {
+ String cloudPointAlias = "";
+ switch (cloudPoint) {
+ case "Cloud one" :
+ cloudPointAlias = "tranportEp_dst_ID_212_1";
+ break;
+ }
+ return cloudPointAlias;
+ }
+
+ public String formatAccessPoint(String accessPoint) {
+ String accessPointAlias = "";
+ switch (accessPoint) {
+ case "Access one" :
+ accessPointAlias = "tranportEp_src_ID_111_1";
+ break;
+ case "Access two" :
+ accessPointAlias = "tranportEp_src_ID_111_2";
+ break;
+ case "Access three" :
+ accessPointAlias = "tranportEp_src_ID_113_1";
+ break;
+ }
+ return accessPointAlias;
+ }
}
diff --git a/server/src/main/java/org/onap/usecaseui/server/service/intent/impl/IntentServiceImpl.java b/server/src/main/java/org/onap/usecaseui/server/service/intent/impl/IntentServiceImpl.java
index c2994db5..137b77a3 100644
--- a/server/src/main/java/org/onap/usecaseui/server/service/intent/impl/IntentServiceImpl.java
+++ b/server/src/main/java/org/onap/usecaseui/server/service/intent/impl/IntentServiceImpl.java
@@ -383,7 +383,7 @@ public class IntentServiceImpl implements IntentService {
private String formatValueForResourcesSharingLevel(String strValue) {
String ret;
- ret = "no-shared";
+ ret = "non-shared";
if("shared".equalsIgnoreCase(strValue)){
ret = "shared";
}
diff --git a/server/src/test/java/org/onap/usecaseui/server/controller/IntentControllerTest.java b/server/src/test/java/org/onap/usecaseui/server/controller/IntentControllerTest.java
index 7727420a..4093d56d 100644
--- a/server/src/test/java/org/onap/usecaseui/server/controller/IntentControllerTest.java
+++ b/server/src/test/java/org/onap/usecaseui/server/controller/IntentControllerTest.java
@@ -172,7 +172,7 @@ public class IntentControllerTest {
Map<String, Object> body = new HashMap<>();
body.put("instanceId", "instanceId");
Mockito.doNothing().when(intentInstanceService).deleteIntentInstance(anyString());
- assertEquals(intentController.deleteIntentInstance(body), "ok");
+ assertEquals(intentController.deleteIntentInstance("instanceId"), "ok");
}
@Test
public void activeIntentInstance() {
diff --git a/standalone/src/main/assembly/resources/dbscripts/postgres/uui_create_table.sql b/standalone/src/main/assembly/resources/dbscripts/postgres/uui_create_table.sql
index 1a29c372..e6a4c1ed 100644
--- a/standalone/src/main/assembly/resources/dbscripts/postgres/uui_create_table.sql
+++ b/standalone/src/main/assembly/resources/dbscripts/postgres/uui_create_table.sql
@@ -153,13 +153,14 @@ CREATE TABLE sort_master (
DROP TABLE IF EXISTS instance_performance;
CREATE TABLE instance_performance
(
- id integer not null,
+ id serial not null
+ constraint instance_performance_pk
+ primary key,
job_id varchar(36),
resource_instance_id varchar(36),
bandwidth numeric,
- date date,
- max_bandwidth numeric,
- CONSTRAINT instance_performance_pk PRIMARY KEY (id)
+ date timestamp,
+ max_bandwidth numeric
);
-- ----------------------------
@@ -174,7 +175,7 @@ CREATE TABLE intent_instance
instance_id varchar(16),
job_id varchar(36),
progress integer,
- status char,
+ status char default 0,
resource_instance_id varchar(36),
name varchar(255),
cloud_point_name varchar(255),