target/
+intentanalysis/log/
# IntelliJ files
.idea/
*.iml
# Generated by Springboot Init Tool
-.mvn/
\ No newline at end of file
+.mvn/
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;
int deleteIntentInstance(String instanceId);
- int createIntentInstance(Map<String, Object> params);
+ ResultHeader createIntentInstance(Map<String, Object> params);
}
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;
}
@Override
- public int createCCVPNInstance(CCVPNInstance ccvpnInstance) {
+ public int createCCVPNInstance(CCVPNInstance ccvpnInstance) {
try{
if (null == ccvpnInstance){
logger.error("CCVPN instance is null!");
@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));
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;
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;
@Autowired
private ExpectationObjectService expectationObjectService;
+ @Autowired
+ private ExpectationService expectationService;
+
+ @Autowired
+ private FulfillmentInfoService fulfillmentInfoService;
+
@Autowired
private IntentService intentService;
@Autowired
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);
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();
originExpectationObject.setObjectInstance(objectInstance);
}
}
- log.info("cllDeliveryActuationModule begin to update originIntent subIntentInfo");
+ log.info("cllDeliveryActuationModule begin to update originIntent subIntentInfo");
}
}
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
+ );
<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>
+/*
+ * 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;