From d98c1acefe136b31d9bb3af3a92c592399b377f6 Mon Sep 17 00:00:00 2001 From: xudan16 Date: Wed, 12 Apr 2023 17:43:16 +0800 Subject: Update FulfillmentInfo with SO create intent API request response Issue-ID: USECASEUI-795 Signed-off-by: xudan16 Change-Id: Icc521a61f035c2780c802623902b9475e226813e --- .../intentanalysis/adapters/so/SOService.java | 3 +- .../adapters/so/impl/SOServiceImpl.java | 25 +++++++++++--- .../CLLBusinessIntentManagementFunction.java | 19 +++++++---- .../CLLDeliveryActuationModule.java | 39 ++++++++++++++++++++-- .../src/main/resources/intent-analysis-init.sql | 12 +++---- .../mybatis/sql/IntentEventRecordMapper.xml | 17 +++++----- 6 files changed, 84 insertions(+), 31 deletions(-) (limited to 'intentanalysis/src/main') 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 params); + ResultHeader createIntentInstance(Map 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 params) { + public ResultHeader createIntentInstance(Map params) { + ResultHeader resultHeader = new ResultHeader(); try { okhttp3.RequestBody requestBody = okhttp3.RequestBody.create(okhttp3.MediaType.parse("application/json"), JSON.toJSONString(params)); Response 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 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; @@ -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 deliveryIntentExpectationList = intentGoalBean.getIntent().getIntentExpectations(); List 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"); } } diff --git a/intentanalysis/src/main/resources/intent-analysis-init.sql b/intentanalysis/src/main/resources/intent-analysis-init.sql index 4a349e7..ee7f8af 100644 --- a/intentanalysis/src/main/resources/intent-analysis-init.sql +++ b/intentanalysis/src/main/resources/intent-analysis-init.sql @@ -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 + ); diff --git a/intentanalysis/src/main/resources/mybatis/sql/IntentEventRecordMapper.xml b/intentanalysis/src/main/resources/mybatis/sql/IntentEventRecordMapper.xml index bd86b9e..d10562d 100644 --- a/intentanalysis/src/main/resources/mybatis/sql/IntentEventRecordMapper.xml +++ b/intentanalysis/src/main/resources/mybatis/sql/IntentEventRecordMapper.xml @@ -5,20 +5,19 @@ - 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}) - - + 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 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}; -- cgit