summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
author’zhaoyh6‘ <zhaoyh6@asiainfo.com>2022-03-23 09:41:45 +0800
committer’zhaoyh6‘ <zhaoyh6@asiainfo.com>2022-03-23 09:42:40 +0800
commit346b023cda770a75b85828a2a4ccb51ceb81b3e6 (patch)
tree2af125e32e48bef16404d4b84a102045ae836746
parentb2f757044deb48143b6bac2a6340d2dc4bd107a9 (diff)
feat:Add instance modification function4.0.6
Issue-ID: REQ-1075 Signed-off-by: ’zhaoyh6‘ <zhaoyh6@asiainfo.com> Change-Id: I60151668dd67a2325b34f0c2a57df14993be84ad
-rw-r--r--server/src/main/java/org/onap/usecaseui/server/controller/IntentController.java23
-rw-r--r--server/src/main/java/org/onap/usecaseui/server/service/intent/IntentInstanceService.java2
-rw-r--r--server/src/main/java/org/onap/usecaseui/server/service/intent/impl/IntentInstanceServiceImpl.java33
-rw-r--r--server/src/test/java/org/onap/usecaseui/server/service/intent/impl/IntentInstanceServiceImplTest.java25
4 files changed, 82 insertions, 1 deletions
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 f63f9d99..b8d63f44 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
@@ -450,6 +450,29 @@ public class IntentController {
}
@IntentResponseBody
+ @ResponseBody
+ @PostMapping(value = {"/updateCCVPNInstance"}, consumes = MediaType.APPLICATION_JSON_VALUE,
+ produces = "application/json; charset=utf-8")
+ public Object updateCCVPNInstance(@RequestBody Object body) throws IOException {
+ String intentInstanceId = MapUtils.getString((Map)body,"instanceId");
+ int accessPointOneBandWidth = MapUtils.getIntValue((Map)body,"bandwidth");
+
+ CCVPNInstance instance = new CCVPNInstance();
+ instance.setInstanceId(intentInstanceId);
+ instance.setAccessPointOneBandWidth(accessPointOneBandWidth);
+
+ int flag = intentInstanceService.updateCCVPNInstance(instance);
+
+ if(flag == 1) {
+ return "OK";
+ }
+ else {
+ throw new RuntimeException("create Instance error");
+ }
+ }
+
+
+ @IntentResponseBody
@GetMapping(value = {"/getFinishedInstanceInfo"},
produces = "application/json")
public Object getFinishedInstanceInfo() {
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 cb922e7b..d0595ce6 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
@@ -63,4 +63,6 @@ public interface IntentInstanceService {
Page<IntentInstance> getIntentInstanceList(int currentPage, int pageSize);
ServiceResult createSlicingServiceWithIntent(Object slicingOrderBody);
+
+ int updateCCVPNInstance(CCVPNInstance instance);
}
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 c54e591c..b62f3aa9 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
@@ -856,6 +856,37 @@ public class IntentInstanceServiceImpl implements IntentInstanceService {
return serviceResult;
}
+ @Override
+ public int updateCCVPNInstance(CCVPNInstance instance) {
+ Session session = getSession();
+ Transaction tx = null;
+ try{
+ if (null == instance){
+ logger.error("instance is null!");
+ return 0;
+ }
+ instance.setResourceInstanceId("cll-"+instance.getInstanceId());
+
+ CCVPNInstance ccvpnInstance = (CCVPNInstance)session.createQuery("from CCVPNInstance where instanceId = :instanceId")
+ .setParameter("instanceId", instance.getInstanceId()).uniqueResult();
+ ccvpnInstance.setAccessPointOneBandWidth(instance.getAccessPointOneBandWidth());
+ saveIntentInstanceToAAI(IntentConstant.INTENT_INSTANCE_ID_PREFIX + "-" + ccvpnInstance.getInstanceId(), ccvpnInstance);
+
+ tx = session.beginTransaction();
+ session.update(ccvpnInstance);
+ tx.commit();
+ return 1;
+ } catch (Exception e) {
+ if (tx != null) {
+ tx.rollback();
+ }
+ logger.error("Details:" + e.getMessage());
+ return 0;
+ } finally {
+ session.close();
+ }
+ }
+
public int getIntentInstanceAllCount() {
Session session = getSession();
try{
@@ -917,7 +948,7 @@ public class IntentInstanceServiceImpl implements IntentInstanceService {
params.put("service-instance-id", serviceInstanceId);
params.put("service-instance-name", instance.getName());
params.put("service-type", IntentConstant.MODEL_TYPE_CCVPN);
- params.put("environment-context", environmentContext);
+ params.put("environment-context", environmentContext.toJSONString());
params.put("service-instance-location-id", instance.getResourceInstanceId());
params.put("bandwidth-total", instance.getAccessPointOneBandWidth());
params.put("data-owner", IntentConstant.INTENT_INSTANCE_DATA_OWNER);
diff --git a/server/src/test/java/org/onap/usecaseui/server/service/intent/impl/IntentInstanceServiceImplTest.java b/server/src/test/java/org/onap/usecaseui/server/service/intent/impl/IntentInstanceServiceImplTest.java
index 90353d4b..7fb9eb5e 100644
--- a/server/src/test/java/org/onap/usecaseui/server/service/intent/impl/IntentInstanceServiceImplTest.java
+++ b/server/src/test/java/org/onap/usecaseui/server/service/intent/impl/IntentInstanceServiceImplTest.java
@@ -987,4 +987,29 @@ public class IntentInstanceServiceImplTest {
when(session.createQuery("select count(*) from IntentInstance")).thenThrow(new RuntimeException());
assertEquals(intentInstanceService.getIntentInstanceAllCount(),-1);
}
+
+ @Test
+ public void updateCCVPNInstanceTest() throws IOException {
+ CCVPNInstance instance = new CCVPNInstance();
+ instance.setInstanceId("1");
+ instance.setAccessPointOneBandWidth(1);
+
+ CCVPNInstance ccvpnInstance = new CCVPNInstance();
+ ccvpnInstance.setInstanceId(instance.getInstanceId());
+
+ Query query = mock(Query.class);
+ when(session.createQuery("from CCVPNInstance where instanceId = :instanceId")).thenReturn(query);
+ when(query.setParameter(anyString(), anyString())).thenReturn(query);
+ when(query.uniqueResult()).thenReturn(ccvpnInstance);
+
+ IntentInstanceServiceImpl spy = PowerMockito.spy(intentInstanceService);
+ doNothing().when(spy).saveIntentInstanceToAAI(anyString(),any(CCVPNInstance.class));
+
+ Transaction tx = Mockito.mock(Transaction.class);
+ Mockito.when(session.beginTransaction()).thenReturn(tx);
+ doNothing().when(session).update(ccvpnInstance);
+ Mockito.doNothing().when(tx).commit();
+
+ assertEquals(spy.updateCCVPNInstance(instance), 1);
+ }
} \ No newline at end of file