*/
package org.onap.usecaseui.intentanalysis.Thread;
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.concurrent.*;
@Configuration
-//@EnableAsync
public class ThreadPoolConfig {
@Bean("intentTaskExecutor")
@Bean("intentReportExecutor")
public Executor getScheduledThreadPoolExecutor(){
- ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(2);
+ ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(3);
+ executor.setThreadFactory(new ThreadFactoryBuilder().setNameFormat("Report-task-%d").build());
return executor;
}
}
*/
package org.onap.usecaseui.intentanalysis.cllBusinessIntentMgt.cllBusinessModule;
-
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang.StringUtils;
import org.onap.usecaseui.intentanalysis.bean.enums.ExpectationType;
if (intentGoalBean.getIntentGoalType().equals(IntentGoalType.CREATE)) {
List<Expectation> intentExpectations = intentGoalBean.getIntent().getIntentExpectations();
List<ExpectationType> expectationTypeList = intentExpectations.stream()
- .map(Expectation::getExpectationType).distinct().collect(Collectors.toList());
+ .map(Expectation::getExpectationType)
+ .filter(expectationType -> !ExpectationType.REPORT.equals(expectationType)).distinct().collect(Collectors.toList());
if (expectationTypeList.size() > 1) {
return true;
} else {
List<ObjectType> objectTypeList = intentExpectations.stream().map(x ->
x.getExpectationObject().getObjectType()).distinct().collect(Collectors.toList());
- if (objectTypeList.size() > 1) {
- return true;
- }
+ return objectTypeList.size() > 1;
}
}
return false;
}
public List<IntentGoalBean> intentDecomposition(IntentGoalBean intentGoalBean) {
+ List<Expectation> intentExpectations = intentGoalBean.getIntent().getIntentExpectations();
+ List<Expectation> report = intentExpectations.stream()
+ .filter(expectation -> ExpectationType.REPORT.equals(expectation.getExpectationType()))
+ .collect(Collectors.toList());
//ExpectationType expectation.ExpectationObject.objtype
- Map<ExpectationType, List<Expectation>> expectationTypeListMap = intentGoalBean.getIntent().getIntentExpectations()
- .stream().collect(Collectors.groupingBy(x -> x.getExpectationType()));
+ Map<ExpectationType, List<Expectation>> expectationTypeListMap = intentExpectations.stream()
+ .filter(expectation -> !ExpectationType.REPORT.equals(expectation.getExpectationType()))
+ .collect(Collectors.groupingBy(Expectation::getExpectationType));
List<IntentGoalBean> subIntentGoalList = new ArrayList<>();
IntentGoalType intentGoalType = intentGoalBean.getIntentGoalType();
for (Map.Entry<ExpectationType, List<Expectation>> entry : expectationTypeListMap.entrySet()) {
IntentGoalBean subIntentGoalBean = new IntentGoalBean();
Intent subIntent = new Intent();
subIntent.setIntentName(objEntry.getValue().get(0).getExpectationName().replace("Expectation", "Intent"));
- subIntent.setIntentExpectations(objEntry.getValue());
+ List<Expectation> value = objEntry.getValue();
+ value.addAll(report);
+ subIntent.setIntentExpectations(value);
subIntent.setIntentGenerateType(IntentGenerateType.SYSTEMGENARATE);
//TODO intentFulfillmentInfo intentContexts
subIntentGoalBean.setIntentGoalType(intentGoalType);
}
return intentMap;
}
-
}
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.onap.usecaseui.intentanalysis.adapters.policy.PolicyService;
+import org.onap.usecaseui.intentanalysis.bean.enums.ExpectationType;
import org.onap.usecaseui.intentanalysis.bean.enums.IntentGoalType;
import org.onap.usecaseui.intentanalysis.bean.models.*;
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.IntentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.stream.Collectors;
+
@Slf4j
@Component
public class CLLAssuranceActuationModule extends ActuationModule {
@Autowired
private PolicyService policyService;
- @Autowired
- private ContextService contextService;
@Override
public void toNextIntentHandler(IntentGoalBean intentGoalBean, IntentManagementFunction IntentHandler) {
return null;
}
for (Intent deliveryIntent : deliveryIntentList) {
- List<Expectation> deliveryExpectationList = deliveryIntent.getIntentExpectations();
+ List<Expectation> deliveryExpectationList = deliveryIntent.getIntentExpectations().stream()
+ .filter(expectation -> ExpectationType.DELIVERY.equals(expectation.getExpectationType()))
+ .collect(Collectors.toList());
if (CollectionUtils.isEmpty(deliveryExpectationList)) {
log.info("expectation is empty,intentId is {}", deliveryIntent.getIntentId());
continue;
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 java.util.List;
import java.util.Map;
import java.util.UUID;
+import java.util.stream.Collectors;
@Component
@Slf4j
@Autowired
private IntentService intentService;
- @Autowired
- private ContextService contextService;
@Override
public void toNextIntentHandler(IntentGoalBean intentGoalBean, IntentManagementFunction IntentHandler) {
@Override
public void directOperation(IntentGoalBean intentGoalBean) {
Intent intent = intentGoalBean.getIntent();
+ Expectation deliveryExpectation = intent.getIntentExpectations().stream()
+ .filter(expectation -> !ExpectationType.REPORT.equals(expectation.getExpectationType()))
+ .collect(Collectors.toList()).get(0);
if (StringUtils.equalsIgnoreCase("create", intentGoalBean.getIntentGoalType().name())) {
Map<String, Object> params = new HashMap<>();
Map<String, String> accessPointOne = new HashMap<>();
- List<ExpectationTarget> targetList = intent.getIntentExpectations().get(0).getExpectationTargets();
+ List<ExpectationTarget> targetList = deliveryExpectation.getExpectationTargets();
for (ExpectationTarget target : targetList) {
String conditionName = target.getTargetConditions().get(0).getConditionName();
String conditionValue = target.getTargetConditions().get(0).getConditionValue();
params.put("instanceId", getInstanceId());
params.put("name", "cll-" + params.get("instanceId"));
params.put("protect", false);
- 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 = new FulfillmentInfo();
- Expectation intentExpectation = expectationService.getIntentExpectation(expectationId);
- if (intentExpectation != null) {
- FulfillmentInfo expectationFulfillmentInfo = intentExpectation.getExpectationFulfillmentInfo();
- if (expectationFulfillmentInfo != null) {
- fulfillmentInfo = expectationFulfillmentInfo;
- }
- }
- // 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());
+ updateFulfillment(params, deliveryExpectation.getExpectationId());
- // 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"));
- intent.getIntentExpectations().get(0).getExpectationObject().setObjectInstance((String) params.get("name"));
- expectationObjectService.updateExpectationObject(expectationObject, expectationId);
+ // fill and update the objectInstance of intent expectation(include delivery and report)
+ String objectInstance = (String) params.get("name");
+ intent.getIntentExpectations().forEach(expectation -> {
+ ExpectationObject expectationObject = expectationObjectService.getExpectationObject(expectation.getExpectationId());
+ expectationObject.setObjectInstance(objectInstance);
+ expectation.getExpectationObject().setObjectInstance(objectInstance);
+ expectationObjectService.updateExpectationObject(expectationObject, expectation.getExpectationId());
+ });
} else if (StringUtils.equalsIgnoreCase("delete", intentGoalBean.getIntentGoalType().name())) {
- String instanceId = intent.getIntentExpectations().get(0).getExpectationObject().getObjectInstance();
+ String instanceId = deliveryExpectation.getExpectationObject().getObjectInstance();
soService.deleteIntentInstance(instanceId);
} else {
- String instanceId = intent.getIntentExpectations().get(0).getExpectationObject().getObjectInstance();
+ String instanceId = deliveryExpectation.getExpectationObject().getObjectInstance();
soService.deleteIntentInstance(instanceId);
intentService.deleteIntent(intent.getIntentId());
}
this.directOperation(intentGoalBean);
}
+ private void updateFulfillment(Map<String, Object> params,String expectationId){
+ // Get the fulfillmentInfo of the first exception which need to be updated with resultHeader returned
+ FulfillmentInfo fulfillmentInfo = new FulfillmentInfo();
+ Expectation intentExpectation = expectationService.getIntentExpectation(expectationId);
+ if (intentExpectation != null) {
+ FulfillmentInfo expectationFulfillmentInfo = intentExpectation.getExpectationFulfillmentInfo();
+ if (expectationFulfillmentInfo != null) {
+ fulfillmentInfo = expectationFulfillmentInfo;
+ }
+ }
+ ResultHeader resultHeader = soService.createIntentInstance(params);
+ // 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);
+ }
+
private String getPredictValue(String name, String value) {
String text = "expectationName is cloud leased line Delivery Expectation, " +
"firstName is " + name + ",firstValue is " + value;
return randomString + String.format("%015d", hashCode);
}
+ /**
+ * update objectInstance of the previous layer’s intent
+ *
+ * @param originIntent intent of the previous layer
+ * @param intentGoalBean intent of this layer
+ */
public void updateIntentOperationInfo(Intent originIntent, IntentGoalBean intentGoalBean){
Intent subIntent = intentGoalBean.getIntent();
if (StringUtils.containsIgnoreCase(subIntent.getIntentName(),"delivery")) {
- List<Expectation> deliveryIntentExpectationList = intentGoalBean.getIntent().getIntentExpectations();
+ List<Expectation> deliveryIntentExpectationList = subIntent.getIntentExpectations().stream()
+ .filter(expectation -> ExpectationType.DELIVERY.equals(expectation.getExpectationType()))
+ .collect(Collectors.toList());
List<Expectation> originIntentExpectationList = originIntent.getIntentExpectations();
- ExpectationObject deliveryExpectationObject = deliveryIntentExpectationList.get(0).getExpectationObject();
- String objectInstance = deliveryExpectationObject.getObjectInstance();
-
+ String objectInstance = deliveryIntentExpectationList.get(0).getExpectationObject().getObjectInstance();
for (Expectation originExpectation : originIntentExpectationList) {
ExpectationObject originExpectationObject = originExpectation.getExpectationObject();
originExpectationObject.setObjectInstance(objectInstance);
}
}
- log.info("cllDeliveryActuationModule begin to update originIntent subIntentInfo");
+ log.info("cllDeliveryActuationModule end to update originIntent subIntentInfo");
}
}
IntentGoalBean originIntentGoalBean = detection(intentGoalBean);
LinkedHashMap<IntentGoalBean, IntentManagementFunction> linkedMap = investigation(originIntentGoalBean);
implementIntent(intentGoalBean.getIntent(), linkedMap);
+ generationIntentReport(intentGoalBean);
}
@Override
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
-import org.onap.usecaseui.intentanalysis.bean.enums.ExpectationType;
import org.onap.usecaseui.intentanalysis.bean.enums.IntentGoalType;
import org.onap.usecaseui.intentanalysis.bean.models.*;
import org.onap.usecaseui.intentanalysis.cllBusinessIntentMgt.CLLBusinessIntentManagementFunction;
import org.onap.usecaseui.intentanalysis.intentBaseService.IntentManagementFunction;
import org.onap.usecaseui.intentanalysis.intentBaseService.contextService.IntentContextService;
import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.DecisionModule;
-import org.onap.usecaseui.intentanalysis.service.IntentReportService;
import org.onap.usecaseui.intentanalysis.service.IntentService;
-import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
-import org.springframework.util.CollectionUtils;
-import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
-import java.util.concurrent.ScheduledThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
@Slf4j
@Autowired
public IntentService intentService;
- @Autowired
- private IntentReportService intentReportService;
-
- @Resource(name = "intentReportExecutor")
- private ScheduledThreadPoolExecutor executor;
-
@Override
public void determineUltimateGoal() {
}
log.info("FormatIntentInputMgt investigation create process start");
LinkedHashMap<IntentGoalBean, IntentManagementFunction> intentMap = new LinkedHashMap<>();
- IntentGoalBean newIntentGoalBean = removeReportExpectation(intentGoalBean);
-
- boolean needDecompostion = needDecompostion(newIntentGoalBean);
+ boolean needDecompostion = needDecompostion(intentGoalBean);
log.debug("FormatIntentInputMgt need decompose :" + needDecompostion);
if (needDecompostion) {
- intentDecomposition(newIntentGoalBean);
+ intentDecomposition(intentGoalBean);
} else {
- intentMap.put(newIntentGoalBean, exploreIntentHandlers(newIntentGoalBean));
+ intentMap.put(intentGoalBean, exploreIntentHandlers(intentGoalBean));
}
log.info("FormatIntentInputMgt investigation create process finished");
return intentMap;
}
return intentMap;
}
-
- private IntentGoalBean removeReportExpectation(IntentGoalBean intentGoalBean) {
- Intent intent = intentGoalBean.getIntent();
- List<Expectation> intentExpectations = intent.getIntentExpectations();
- List<Expectation> report = intentExpectations.stream()
- .filter(expectation -> ExpectationType.REPORT.equals(expectation.getExpectationType()))
- .collect(Collectors.toList());
- if (CollectionUtils.isEmpty(report)) {
- log.info("No expectation of type report is entered");
- return intentGoalBean;
- }
- generationIntentReport(report.get(0), intent.getIntentId());
- Intent newIntent = new Intent();
- BeanUtils.copyProperties(intent, newIntent);
- List<Expectation> notReport = intentExpectations.stream()
- .filter(expectation -> !ExpectationType.REPORT.equals(expectation.getExpectationType()))
- .collect(Collectors.toList());
- newIntent.setIntentExpectations(notReport);
- return new IntentGoalBean(newIntent, intentGoalBean.getIntentGoalType());
- }
-
- private void generationIntentReport(Expectation expectation, String intentId) {
- List<ExpectationTarget> expectationTargets = expectation.getExpectationTargets();
- if (CollectionUtils.isEmpty(expectationTargets)) {
- log.error("The expectation target is empty,expectationId is {}", expectation.getExpectationId());
- return;
- }
- ExpectationTarget expectationTarget = expectationTargets.get(0);
- List<Condition> targetConditions = expectationTarget.getTargetConditions();
- if (CollectionUtils.isEmpty(targetConditions)) {
- log.error("The target condition is empty,expectationId is {}", expectation.getExpectationId());
- return;
- }
- Condition condition = targetConditions.get(0);
- try {
- int conditionValue = Integer.parseInt(condition.getConditionValue());
- log.info("Start executing scheduled intent report generation task ");
- executor.scheduleAtFixedRate(() -> intentReportService.saveIntentReportByIntentId(intentId), 2, conditionValue, TimeUnit.SECONDS);
- } catch (Exception e) {
- log.error("The exception is {}", e.getMessage());
- }
- }
}
*/
package org.onap.usecaseui.intentanalysis.intentBaseService;
-
import lombok.Data;
+import lombok.extern.log4j.Log4j2;
+import org.onap.usecaseui.intentanalysis.bean.enums.ExpectationType;
+import org.onap.usecaseui.intentanalysis.bean.models.Condition;
+import org.onap.usecaseui.intentanalysis.bean.models.Expectation;
+import org.onap.usecaseui.intentanalysis.bean.models.ExpectationTarget;
import org.onap.usecaseui.intentanalysis.bean.models.FulfillmentInfo;
import org.onap.usecaseui.intentanalysis.bean.models.Intent;
import org.onap.usecaseui.intentanalysis.bean.models.IntentGoalBean;
import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.DecisionModule;
import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.KnowledgeModule;
import org.onap.usecaseui.intentanalysis.service.FulfillmentInfoService;
+import org.onap.usecaseui.intentanalysis.service.IntentReportService;
import org.onap.usecaseui.intentanalysis.service.ObjectInstanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
+import org.springframework.util.CollectionUtils;
+
+import javax.annotation.Resource;
+import java.util.List;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+import static org.onap.usecaseui.intentanalysis.bean.enums.IntentGoalType.CREATE;
+
+@Log4j2
@Data
@Configuration
@Component
@Autowired
private ObjectInstanceService objectInstanceService;
+ @Autowired
+ private IntentReportService intentReportService;
+
+ @Resource(name = "intentReportExecutor")
+ private ScheduledThreadPoolExecutor scheduledThreadPoolExecutor;
+
public void receiveIntentAsOwner(IntentGoalBean intentGoalBean){};
public void receiveIntentAsHandler(Intent originalIntent, IntentGoalBean intentGoalBean, IntentManagementFunction handler){};
public void createReport(String intentId, FulfillmentInfo fulfillmentInfo){};
fulfillmentInfoService.saveFulfillmentInfo(intentId, fulfillmentInfo);
objectInstanceService.saveObjectInstances(intentId, fulfillmentInfo);
}
+
+ protected void generationIntentReport(IntentGoalBean intentGoalBean) {
+ if (CREATE != intentGoalBean.getIntentGoalType()) {
+ return;
+ }
+ Intent intent = intentGoalBean.getIntent();
+ List<Expectation> intentExpectations = intent.getIntentExpectations();
+ List<Expectation> report = intentExpectations.stream()
+ .filter(expectation -> ExpectationType.REPORT.equals(expectation.getExpectationType()))
+ .collect(Collectors.toList());
+ if (CollectionUtils.isEmpty(report)) {
+ log.info("No expectation of type report is entered");
+ return;
+ }
+ List<ExpectationTarget> expectationTargets = report.get(0).getExpectationTargets();
+ if (CollectionUtils.isEmpty(expectationTargets)) {
+ log.error("The expectation target is empty,expectationId is {}", report.get(0).getExpectationId());
+ return;
+ }
+ ExpectationTarget expectationTarget = expectationTargets.get(0);
+ List<Condition> targetConditions = expectationTarget.getTargetConditions();
+ if (CollectionUtils.isEmpty(targetConditions)) {
+ log.error("The target condition is empty,expectationId is {}", report.get(0).getExpectationId());
+ return;
+ }
+ Condition condition = targetConditions.get(0);
+ try {
+ int conditionValue = Integer.parseInt(condition.getConditionValue());
+ log.info("Start executing scheduled intent report generation task ");
+ scheduledThreadPoolExecutor.scheduleAtFixedRate(() -> intentReportService.saveIntentReportByIntentId(intent.getIntentId()), 2, conditionValue, TimeUnit.SECONDS);
+ } catch (Exception e) {
+ log.error("The exception is {}", e.getMessage());
+ }
+ }
}
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockedStatic;
import org.mockito.Mockito;
import org.onap.usecaseui.intentanalysis.IntentAnalysisApplicationTests;
import org.onap.usecaseui.intentanalysis.adapters.so.SOService;
+import org.onap.usecaseui.intentanalysis.bean.enums.ExpectationType;
import org.onap.usecaseui.intentanalysis.bean.enums.IntentGoalType;
import org.onap.usecaseui.intentanalysis.bean.models.*;
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.util.HttpUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
deliveryExpectationObject.setObjectInstance("deliveryObjectInstance");
deliveryExpectation.setExpectationObject(deliveryExpectationObject);
+ deliveryExpectation.setExpectationType(ExpectationType.DELIVERY);
gbExpectationList.add(deliveryExpectation);
intentGoalBean.setIntentGoalType(IntentGoalType.CREATE);
Intent intent =new Intent();