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.clldeliveryIntentmgt.clldeliverymodule;
18 import lombok.extern.slf4j.Slf4j;
19 import org.apache.commons.lang.StringUtils;
20 import org.onap.usecaseui.intentanalysis.adapters.so.SOService;
21 import org.onap.usecaseui.intentanalysis.bean.models.*;
22 import org.onap.usecaseui.intentanalysis.bean.enums.*;
23 import org.onap.usecaseui.intentanalysis.intentBaseService.IntentManagementFunction;
24 import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.ActuationModule;
25 import org.onap.usecaseui.intentanalysis.service.ContextService;
26 import org.onap.usecaseui.intentanalysis.service.ExpectationObjectService;
27 import org.onap.usecaseui.intentanalysis.service.ExpectationService;
28 import org.onap.usecaseui.intentanalysis.service.FulfillmentInfoService;
29 import org.onap.usecaseui.intentanalysis.service.IntentService;
30 import org.springframework.beans.factory.annotation.Autowired;
31 import org.springframework.stereotype.Component;
33 import java.util.HashMap;
34 import java.util.List;
36 import java.util.UUID;
40 public class CLLDeliveryActuationModule extends ActuationModule {
43 private SOService soService;
46 private ExpectationObjectService expectationObjectService;
49 private ExpectationService expectationService;
52 private FulfillmentInfoService fulfillmentInfoService;
55 private IntentService intentService;
57 private ContextService contextService;
60 public void toNextIntentHandler(IntentGoalBean intentGoalBean, IntentManagementFunction IntentHandler) {
65 public void directOperation(IntentGoalBean intentGoalBean) {
66 Intent intent = intentGoalBean.getIntent();
67 if (StringUtils.equalsIgnoreCase("create", intentGoalBean.getIntentGoalType().name())) {
68 Map<String, Object> params = new HashMap<>();
69 Map<String, String> accessPointOne = new HashMap<>();
70 List<ExpectationTarget> targetList = intent.getIntentExpectations().get(0).getExpectationTargets();
71 for (ExpectationTarget target : targetList) {
72 String conditionName = target.getTargetConditions().get(0).getConditionName();
73 String conditionValue = target.getTargetConditions().get(0).getConditionValue();
74 if (StringUtils.containsIgnoreCase(conditionName, "source")) {
75 accessPointOne.put("name", conditionValue);
76 } else if (StringUtils.containsIgnoreCase(conditionName, "destination")) {
77 params.put("cloudPointName", conditionValue);
78 } else if (StringUtils.containsIgnoreCase(conditionName, "bandwidth")) {
79 accessPointOne.put("bandwidth", conditionValue);
82 params.put("accessPointOne", accessPointOne);
83 params.put("instanceId", getInstanceId());
84 params.put("name", "cll-" + params.get("instanceId"));
85 params.put("protect", false);
86 ResultHeader resultHeader = soService.createIntentInstance(params);
88 // Get the expectationId of the first exception from intent which should be CLL_VPN DELIVERY
89 String expectationId = intent.getIntentExpectations().get(0).getExpectationId();
91 // Get the fulfillmentInfo of the first exception which need to be updated with resultHeader returned
92 FulfillmentInfo fulfillmentInfo = expectationService.getIntentExpectation(expectationId).getExpectationFulfillmentInfo();
94 if (fulfillmentInfo == null) {
95 fulfillmentInfo = new FulfillmentInfo();
98 // Update fulfillmentInfo and write back to DB
99 // Originally set to be NOT_FULFILLED, and will change after requesting the SO operation status
100 fulfillmentInfo.setFulfillmentStatus(FulfillmentStatus.NOT_FULFILLED);
101 fulfillmentInfo.setNotFulfilledReason(resultHeader.getResult_message());
103 // If SO request accepted, means intent acknowledged, otherwise, means failed
104 if (resultHeader.getResult_code() == 1) {
105 fulfillmentInfo.setNotFulfilledState(NotFulfilledState.ACKNOWLEDGED);
107 fulfillmentInfo.setNotFulfilledState(NotFulfilledState.FULFILMENTFAILED);
110 fulfillmentInfoService.updateFulfillmentInfo(fulfillmentInfo, expectationId);
112 ExpectationObject expectationObject = expectationObjectService.getExpectationObject(expectationId);
113 expectationObject.setObjectInstance((String) params.get("name"));
114 expectationObjectService.updateExpectationObject(expectationObject, expectationId);
115 } else if (StringUtils.equalsIgnoreCase("delete", intentGoalBean.getIntentGoalType().name())) {
116 String instanceId = intent.getIntentExpectations().get(0).getExpectationObject().getObjectInstance();
117 soService.deleteIntentInstance(instanceId);
119 String instanceId = intent.getIntentExpectations().get(0).getExpectationObject().getObjectInstance();
120 soService.deleteIntentInstance(instanceId);
121 intentService.deleteIntent(intent.getIntentId());
126 public void interactWithIntentHandle() {
131 public void fulfillIntent(IntentGoalBean intentGoalBean, IntentManagementFunction intentHandler) {
132 this.directOperation(intentGoalBean);
135 public String getInstanceId() {
136 int random = (int) (Math.random() * 9 + 1);
138 String randomString = String.valueOf(random);
139 int hashCode = UUID.randomUUID().toString().hashCode();
141 hashCode = -hashCode;
143 return randomString + String.format("%015d", hashCode);
146 public void updateIntentOperationInfo(Intent originIntent, IntentGoalBean intentGoalBean){
147 Intent subIntent = intentGoalBean.getIntent();
148 if (StringUtils.containsIgnoreCase(subIntent.getIntentName(),"delivery")) {
149 List<Expectation> deliveryIntentExpectationList = intentGoalBean.getIntent().getIntentExpectations();
150 List<Expectation> originIntentExpectationList = originIntent.getIntentExpectations();
151 ExpectationObject deliveryExpectationObject = deliveryIntentExpectationList.get(0).getExpectationObject();
152 String objectInstance = deliveryExpectationObject.getObjectInstance();
154 for (Expectation originExpectation : originIntentExpectationList) {
155 ExpectationObject originExpectationObject = originExpectation.getExpectationObject();
156 originExpectationObject.setObjectInstance(objectInstance);
159 log.info("cllDeliveryActuationModule begin to update originIntent subIntentInfo");