Update FulfillmentInfo with SO create intent API request response 79/134079/6
authorxudan16 <xudan16@huawei.com>
Wed, 12 Apr 2023 09:43:16 +0000 (17:43 +0800)
committerxudan16 <xudan16@huawei.com>
Mon, 8 May 2023 09:25:54 +0000 (17:25 +0800)
Issue-ID: USECASEUI-795
Signed-off-by: xudan16 <xudan16@huawei.com>
Change-Id: Icc521a61f035c2780c802623902b9475e226813e

.gitignore
intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/so/SOService.java
intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/so/impl/SOServiceImpl.java
intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/cllBusinessIntentMgt/CLLBusinessIntentManagementFunction.java
intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/clldeliveryIntentmgt/clldeliverymodule/CLLDeliveryActuationModule.java
intentanalysis/src/main/resources/intent-analysis-init.sql
intentanalysis/src/main/resources/mybatis/sql/IntentEventRecordMapper.xml
intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/util/DmaapUtilTest.java

index 7915757..84e9076 100644 (file)
@@ -1,8 +1,9 @@
 target/
+intentanalysis/log/
 
 # IntelliJ files
 .idea/
 *.iml
 
 # Generated by Springboot Init Tool
-.mvn/
\ No newline at end of file
+.mvn/
index c95f16b..d80e0ea 100644 (file)
@@ -16,6 +16,7 @@
 package org.onap.usecaseui.intentanalysis.adapters.so;
 
 import org.onap.usecaseui.intentanalysis.bean.models.CCVPNInstance;
+import org.onap.usecaseui.intentanalysis.bean.models.ResultHeader;
 import org.springframework.stereotype.Service;
 
 import java.util.Map;
@@ -26,5 +27,5 @@ public interface SOService {
 
     int deleteIntentInstance(String instanceId);
 
-    int createIntentInstance(Map<String, Object> params);
+    ResultHeader createIntentInstance(Map<String, Object> params);
 }
index 0f80853..de4ff3c 100644 (file)
@@ -24,6 +24,7 @@ import org.onap.usecaseui.intentanalysis.adapters.so.SOService;
 import org.onap.usecaseui.intentanalysis.adapters.so.apicall.SOAPICall;
 import org.onap.usecaseui.intentanalysis.adapters.so.apicall.SOAuthConfig;
 import org.onap.usecaseui.intentanalysis.bean.models.CCVPNInstance;
+import org.onap.usecaseui.intentanalysis.bean.models.ResultHeader;
 import org.onap.usecaseui.intentanalysis.util.RestfulServices;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -76,7 +77,7 @@ public class SOServiceImpl implements SOService {
     }
 
     @Override
-    public int  createCCVPNInstance(CCVPNInstance ccvpnInstance) {
+    public int createCCVPNInstance(CCVPNInstance ccvpnInstance) {
         try{
             if (null == ccvpnInstance){
                 logger.error("CCVPN instance is null!");
@@ -119,17 +120,31 @@ public class SOServiceImpl implements SOService {
 
 
     @Override
-    public int createIntentInstance(Map<String, Object> params) {
+    public ResultHeader createIntentInstance(Map<String, Object> params) {
+        ResultHeader resultHeader = new ResultHeader();
         try {
             okhttp3.RequestBody requestBody = okhttp3.RequestBody.create(okhttp3.MediaType.parse("application/json"), JSON.toJSONString(params));
             Response<JSONObject> response = getSoApiCall().createIntentInstance(requestBody).execute();
-            return 1;
+            if (response.isSuccessful()) {
+                String msg = "Successfully sent intent creation request, code: " + response.code() + ", msg: " + response.message();
+                logger.debug(msg);
+                resultHeader.setResult_code(1);
+                resultHeader.setResult_message(msg);
+            } else {
+                String msg = "Failed to send intent creation request, code: " + response.code() + ", msg: " + response.message();
+                logger.error(msg);
+                resultHeader.setResult_code(0);
+                resultHeader.setResult_message(msg);
+            }
         } catch (IOException e) {
-            logger.error("Details:" + e.getMessage());
-            return 0;
+            logger.error("Failed to send intent creation request. Details: " + e.getMessage());
+            resultHeader.setResult_code(0);
+            resultHeader.setResult_message(e.getMessage());
         }
+        return resultHeader;
     }
 
+
     public String createIntentInstanceToSO(CCVPNInstance ccvpnInstance) throws IOException {
         Map<String, Object> params = paramsSetUp(ccvpnInstance);
         params.put("additionalProperties",additionalPropertiesSetUp(ccvpnInstance));
index 6a7d7f8..084f74d 100644 (file)
@@ -167,16 +167,21 @@ public class CLLBusinessIntentManagementFunction extends IntentManagementFunctio
                     boolean isPublish = false;
                     int count = 1;
                     while (!isPublish) {
-                        Thread.sleep(1000);
-                        IntentEventRecord record = intentEventRecordService.getIntentEventRecordByIntentId(newIdIntent.getIntentId(), "create");
-                        count++;
-                        // it will take one hour to wait operation end
-                        if (count == 3600) {
-                            throw new CommonException("Operation took too long, failed", 500);
+                        // Set the timeout to be 60min
+                        if (count >= 3600) {
+                            throw new CommonException("Timed out for implementing intent", 500);
                         }
-                        if (null != record) {
+                        log.debug("Try to get record of intent CREATE event from DB.");
+                        IntentEventRecord record = intentEventRecordService.getIntentEventRecordByIntentId(
+                                                        newIdIntent.getIntentId(), intentGoalType.toString());
+                        if (record != null) {
                             isPublish = true;
+                            log.debug("Successfully got Intent Event Record from DB.");
+                        } else {
+                            log.debug("Index " + count + ": None Intent Event Record been got. Will try again.");
                         }
+                        count++;
+                        Thread.sleep(1000);
                     }
                 }
                 // return isAcceptCreate;
index 1ea7f9d..b64dd9a 100644 (file)
@@ -19,10 +19,13 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang.StringUtils;
 import org.onap.usecaseui.intentanalysis.adapters.so.SOService;
 import org.onap.usecaseui.intentanalysis.bean.models.*;
+import org.onap.usecaseui.intentanalysis.bean.enums.*;
 import org.onap.usecaseui.intentanalysis.intentBaseService.IntentManagementFunction;
 import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.ActuationModule;
 import org.onap.usecaseui.intentanalysis.service.ContextService;
 import org.onap.usecaseui.intentanalysis.service.ExpectationObjectService;
+import org.onap.usecaseui.intentanalysis.service.ExpectationService;
+import org.onap.usecaseui.intentanalysis.service.FulfillmentInfoService;
 import org.onap.usecaseui.intentanalysis.service.IntentService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
@@ -42,6 +45,12 @@ public class CLLDeliveryActuationModule extends ActuationModule {
     @Autowired
     private ExpectationObjectService expectationObjectService;
 
+    @Autowired
+    private ExpectationService expectationService;
+
+    @Autowired
+    private FulfillmentInfoService fulfillmentInfoService;
+
     @Autowired
     private IntentService intentService;
     @Autowired
@@ -74,8 +83,32 @@ public class CLLDeliveryActuationModule extends ActuationModule {
             params.put("instanceId", getInstanceId());
             params.put("name", "cll-" + params.get("instanceId"));
             params.put("protect", false);
-            soService.createIntentInstance(params);
+            ResultHeader resultHeader = soService.createIntentInstance(params);
+
+            // Get the expectationId of the first exception from intent which should be CLL_VPN DELIVERY
             String expectationId = intent.getIntentExpectations().get(0).getExpectationId();
+
+            // Get the fulfillmentInfo of the first exception which need to be updated with resultHeader returned
+            FulfillmentInfo fulfillmentInfo = expectationService.getIntentExpectation(expectationId).getExpectationFulfillmentInfo();
+
+            if (fulfillmentInfo == null) {
+                fulfillmentInfo = new FulfillmentInfo();
+            }
+
+            // Update fulfillmentInfo and write back to DB
+            // Originally set to be NOT_FULFILLED, and will change after requesting the SO operation status
+            fulfillmentInfo.setFulfillmentStatus(FulfillmentStatus.NOT_FULFILLED);
+            fulfillmentInfo.setNotFulfilledReason(resultHeader.getResult_message());
+
+            // If SO request accepted, means intent acknowledged, otherwise, means failed
+            if (resultHeader.getResult_code() == 1) {
+                fulfillmentInfo.setNotFulfilledState(NotFulfilledState.ACKNOWLEDGED);
+            } else {
+                fulfillmentInfo.setNotFulfilledState(NotFulfilledState.FULFILMENTFAILED);
+            }
+
+            fulfillmentInfoService.updateFulfillmentInfo(fulfillmentInfo, expectationId);
+
             ExpectationObject expectationObject = expectationObjectService.getExpectationObject(expectationId);
             expectationObject.setObjectInstance((String) params.get("name"));
             expectationObjectService.updateExpectationObject(expectationObject, expectationId);
@@ -109,7 +142,7 @@ public class CLLDeliveryActuationModule extends ActuationModule {
 
     public void updateIntentOperationInfo(Intent originIntent, IntentGoalBean intentGoalBean){
         Intent subIntent = intentGoalBean.getIntent();
-          if (StringUtils.containsIgnoreCase(subIntent.getIntentName(),"delivery")) {
+        if (StringUtils.containsIgnoreCase(subIntent.getIntentName(),"delivery")) {
             List<Expectation> deliveryIntentExpectationList = intentGoalBean.getIntent().getIntentExpectations();
             List<Expectation> originIntentExpectationList = originIntent.getIntentExpectations();
             ExpectationObject deliveryExpectationObject = deliveryIntentExpectationList.get(0).getExpectationObject();
@@ -120,6 +153,6 @@ public class CLLDeliveryActuationModule extends ActuationModule {
                 originExpectationObject.setObjectInstance(objectInstance);
             }
         }
-       log.info("cllDeliveryActuationModule begin to update originIntent subIntentInfo");
+        log.info("cllDeliveryActuationModule begin to update originIntent subIntentInfo");
     }
 }
index 4a349e7..ee7f8af 100644 (file)
@@ -72,11 +72,11 @@ create table if not exists intent_management_function_reg_info(
     intent_function_type varchar(255)
     );
 
-create table if not exists intent_Event_Record(
+create table if not exists intent_event_record(
     id varchar(255) DEFAULT uuid_generate_v4 (),
-    intentId varchar(255),
-    intentName varchar(255),
-    intentStatus varchar (225),
-    operateType varchar (225),
+    intent_id varchar(255),
+    intent_name varchar(255),
+    intent_status varchar (225),
+    operate_type varchar (225),
     parent_id varchar(255)
-    );
\ No newline at end of file
+    );
index bd86b9e..d10562d 100644 (file)
@@ -5,20 +5,19 @@
 <mapper namespace="org.onap.usecaseui.intentanalysis.mapper.IntentEventRecordMapper">
 
     <insert id="insertIntentRecord">
-        insert into intent_Event_Record(intentId, intentName, intentStatus, operateType,parent_id)
+        insert into intent_event_record(intent_id, intent_name, intent_status, operate_type, parent_id)
         values(#{intentEventRecord.intentId}, #{intentEventRecord.intentName},
-               #{intentEventRecord.intentStatus},#{intentEventRecord.operateType},
+               #{intentEventRecord.intentStatus}, #{intentEventRecord.operateType},
                #{parentId})
     </insert>
 
-
-    <select id="getIntentEventRecordByIntentId"  resultType="org.onap.usecaseui.intentanalysis.bean.models.IntentEventRecord">
-       select id,intentId,intentName,intentStatus,operateType,parent_id parentId
-       from intent_Event_Record where intentId = #{intentId};
+    <select id="getIntentEventRecordByIntentId" flushCache="true" resultType="org.onap.usecaseui.intentanalysis.bean.models.IntentEventRecord">
+        select id id, intent_id intentId, intent_name intentName, intent_status intentStatus, operate_type operateType
+        from intent_event_record where intent_id = #{intentId} and operate_type=#{operateType};
     </select>
 
-    <select id="getIntentEventRecordByPid"  resultType="org.onap.usecaseui.intentanalysis.bean.models.IntentEventRecord">
-        select id,intentId,intentName,intentStatus,operateType,parent_id
-        from intent_Event_Record where parent_id = #{parentId} and operateType=#{operateType};
+    <select id="getIntentEventRecordByPid" flushCache="true" resultType="org.onap.usecaseui.intentanalysis.bean.models.IntentEventRecord">
+        select id id, intent_id intentId, intent_name intentName, intent_status intentStatus, operate_type operateType
+        from intent_event_record where parent_id = #{parentId} and operate_type=#{operateType};
     </select>
 </mapper>
index be2a020..c7023b6 100644 (file)
@@ -1,3 +1,17 @@
+/*
+ * Copyright 2023 Huawei Technologies Co., Ltd.
+ *
+ * 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.intentanalysis.util;
 
 import java.io.IOException;