2 * Copyright (C) 2022 CMCC, Inc. and others. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.onap.usecaseui.intentanalysis.cllassuranceIntentmgt.cllassurancemodule;
18 import lombok.extern.slf4j.Slf4j;
19 import org.apache.commons.lang.StringUtils;
20 import org.onap.usecaseui.intentanalysis.adapters.policy.PolicyService;
21 import org.onap.usecaseui.intentanalysis.bean.enums.ExpectationType;
22 import org.onap.usecaseui.intentanalysis.bean.enums.IntentGoalType;
23 import org.onap.usecaseui.intentanalysis.bean.models.*;
24 import org.onap.usecaseui.intentanalysis.intentBaseService.IntentManagementFunction;
25 import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.ActuationModule;
26 import org.onap.usecaseui.intentanalysis.service.IntentService;
27 import org.springframework.beans.factory.annotation.Autowired;
28 import org.springframework.stereotype.Component;
29 import org.springframework.util.CollectionUtils;
31 import java.util.List;
32 import java.util.stream.Collectors;
36 public class CLLAssuranceActuationModule extends ActuationModule {
38 private IntentService intentService;
41 private PolicyService policyService;
44 public void toNextIntentHandler(IntentGoalBean intentGoalBean, IntentManagementFunction IntentHandler) {
49 public void directOperation(IntentGoalBean intentGoalBean) {
50 Intent intent = intentGoalBean.getIntent();
51 List<String> cllIds = getCLLId(intent);
52 cllIds.forEach(cllId -> {
53 String bandwidth = getBandwidth(cllId);
54 IntentGoalType intentGoalType = intentGoalBean.getIntentGoalType();
55 if (StringUtils.equalsIgnoreCase("create", intentGoalType.name())) {
56 policyService.updateIntentConfigPolicy(cllId, bandwidth, "true");
57 } else if (StringUtils.equalsIgnoreCase("update", intentGoalType.name())) {
58 policyService.updateIntentConfigPolicy(cllId, bandwidth, "false");
59 } else if (StringUtils.equalsIgnoreCase("delete", intentGoalType.name())) {
60 policyService.updateIntentConfigPolicy(cllId, bandwidth, "false");
66 public void interactWithIntentHandle() {
71 public void fulfillIntent(IntentGoalBean intentGoalBean, IntentManagementFunction intentHandler) {
72 directOperation(intentGoalBean);
76 public void updateIntentOperationInfo(Intent originIntent, IntentGoalBean intentGoalBean){
79 private String getBandwidth(String cllId) {
80 List<Intent> deliveryIntentList = intentService.getIntentByName("CLL Delivery Intent");
81 if (CollectionUtils.isEmpty(deliveryIntentList)) {
82 log.info("get CLL Delivery Intent from the database is empty");
85 for (Intent deliveryIntent : deliveryIntentList) {
86 List<Expectation> deliveryExpectationList = deliveryIntent.getIntentExpectations().stream()
87 .filter(expectation -> ExpectationType.DELIVERY.equals(expectation.getExpectationType()))
88 .collect(Collectors.toList());
89 if (CollectionUtils.isEmpty(deliveryExpectationList)) {
90 log.info("expectation is empty,intentId is {}", deliveryIntent.getIntentId());
93 for (Expectation deliveryExpectation : deliveryExpectationList) {
94 ExpectationObject expectationObject = deliveryExpectation.getExpectationObject();
95 if (expectationObject == null) {
96 log.info("expectationObject is empty,expectationId is {}", deliveryExpectation.getExpectationId());
99 List<String> objectInstances = expectationObject.getObjectInstance();
101 for (String objectInstance : objectInstances) {
102 if (StringUtils.equalsIgnoreCase(cllId, objectInstance)) {
103 object = objectInstance;
107 if (StringUtils.isEmpty(object)) {
108 log.info("no objectInstance is equal cllId {}", cllId);
111 List<ExpectationTarget> deliveryTargetList = deliveryExpectation.getExpectationTargets();
112 List<ExpectationTarget> bandwidth = deliveryTargetList.stream()
113 .filter(target -> StringUtils.equalsIgnoreCase("bandwidth", target.getTargetName()))
114 .collect(Collectors.toList());
115 if (CollectionUtils.isEmpty(bandwidth)) {
116 log.info("bandwidth target is empty,expectation is {}", deliveryExpectation.getExpectationId());
119 List<Condition> deliveryConditionList = bandwidth.get(0).getTargetConditions();
120 List<Condition> collect = deliveryConditionList.stream()
121 .filter(condition -> StringUtils.equalsIgnoreCase("condition of the cll service bandwidth", condition.getConditionName()))
122 .collect(Collectors.toList());
123 if (CollectionUtils.isEmpty(collect)) {
124 log.info("condition of the cll service bandwidth is empty,targetId is {}", bandwidth.get(0).getTargetId());
127 return collect.get(0).getConditionValue();
133 private List<String> getCLLId(Intent intent) {
134 List<Expectation> expectationList = intent.getIntentExpectations();
135 for (Expectation expectation : expectationList) {
136 if (StringUtils.equalsIgnoreCase("assurance", expectation.getExpectationType().name())) {
137 return expectation.getExpectationObject().getObjectInstance();