aboutsummaryrefslogtreecommitdiffstats
path: root/intentanalysis/src/main/java
diff options
context:
space:
mode:
authorxudan16 <xudan16@huawei.com>2023-04-12 17:43:16 +0800
committerxudan16 <xudan16@huawei.com>2023-05-08 17:25:54 +0800
commitd98c1acefe136b31d9bb3af3a92c592399b377f6 (patch)
tree127d6e97709a046819572b2330bf753c3f2f2b36 /intentanalysis/src/main/java
parentce59f8d48ee369b81d67666601cb297f7688d683 (diff)
Update FulfillmentInfo with SO create intent API request response
Issue-ID: USECASEUI-795 Signed-off-by: xudan16 <xudan16@huawei.com> Change-Id: Icc521a61f035c2780c802623902b9475e226813e
Diffstat (limited to 'intentanalysis/src/main/java')
-rw-r--r--intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/so/SOService.java3
-rw-r--r--intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/so/impl/SOServiceImpl.java25
-rw-r--r--intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/cllBusinessIntentMgt/CLLBusinessIntentManagementFunction.java19
-rw-r--r--intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/clldeliveryIntentmgt/clldeliverymodule/CLLDeliveryActuationModule.java39
4 files changed, 70 insertions, 16 deletions
diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/so/SOService.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/so/SOService.java
index c95f16b..d80e0ea 100644
--- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/so/SOService.java
+++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/so/SOService.java
@@ -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);
}
diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/so/impl/SOServiceImpl.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/so/impl/SOServiceImpl.java
index 0f80853..de4ff3c 100644
--- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/so/impl/SOServiceImpl.java
+++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/so/impl/SOServiceImpl.java
@@ -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));
diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/cllBusinessIntentMgt/CLLBusinessIntentManagementFunction.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/cllBusinessIntentMgt/CLLBusinessIntentManagementFunction.java
index 6a7d7f8..084f74d 100644
--- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/cllBusinessIntentMgt/CLLBusinessIntentManagementFunction.java
+++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/cllBusinessIntentMgt/CLLBusinessIntentManagementFunction.java
@@ -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;
diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/clldeliveryIntentmgt/clldeliverymodule/CLLDeliveryActuationModule.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/clldeliveryIntentmgt/clldeliverymodule/CLLDeliveryActuationModule.java
index 1ea7f9d..b64dd9a 100644
--- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/clldeliveryIntentmgt/clldeliverymodule/CLLDeliveryActuationModule.java
+++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/clldeliveryIntentmgt/clldeliverymodule/CLLDeliveryActuationModule.java
@@ -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;
@@ -43,6 +46,12 @@ public class CLLDeliveryActuationModule extends ActuationModule {
private ExpectationObjectService expectationObjectService;
@Autowired
+ private ExpectationService expectationService;
+
+ @Autowired
+ private FulfillmentInfoService fulfillmentInfoService;
+
+ @Autowired
private IntentService intentService;
@Autowired
private ContextService contextService;
@@ -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");
}
}