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.intentBaseService.IntentManagementFunction;
23 import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.ActuationModule;
24 import org.onap.usecaseui.intentanalysis.service.ContextService;
25 import org.onap.usecaseui.intentanalysis.service.ExpectationObjectService;
26 import org.onap.usecaseui.intentanalysis.service.IntentService;
27 import org.springframework.beans.factory.annotation.Autowired;
28 import org.springframework.stereotype.Component;
30 import java.util.HashMap;
31 import java.util.List;
33 import java.util.UUID;
37 public class CLLDeliveryActuationModule extends ActuationModule {
40 private SOService soService;
43 private ExpectationObjectService expectationObjectService;
46 private IntentService intentService;
48 private ContextService contextService;
51 public void toNextIntentHandler(IntentGoalBean intentGoalBean, IntentManagementFunction IntentHandler) {
56 public void directOperation(IntentGoalBean intentGoalBean) {
57 Intent intent = intentGoalBean.getIntent();
58 if (StringUtils.equalsIgnoreCase("create", intentGoalBean.getIntentGoalType().name())) {
59 Map<String, Object> params = new HashMap<>();
60 Map<String, String> accessPointOne = new HashMap<>();
61 List<ExpectationTarget> targetList = intent.getIntentExpectations().get(0).getExpectationTargets();
62 for (ExpectationTarget target : targetList) {
63 String conditionName = target.getTargetConditions().get(0).getConditionName();
64 String conditionValue = target.getTargetConditions().get(0).getConditionValue();
65 if (StringUtils.containsIgnoreCase(conditionName, "source")) {
66 accessPointOne.put("name", conditionValue);
67 } else if (StringUtils.containsIgnoreCase(conditionName, "destination")) {
68 params.put("cloudPointName", conditionValue);
69 } else if (StringUtils.containsIgnoreCase(conditionName, "bandwidth")) {
70 accessPointOne.put("bandwidth", conditionValue);
73 params.put("accessPointOne", accessPointOne);
74 params.put("instanceId", getInstanceId());
75 params.put("name", "cll-" + params.get("instanceId"));
76 params.put("protect", false);
77 soService.createIntentInstance(params);
78 String expectationId = intent.getIntentExpectations().get(0).getExpectationId();
79 ExpectationObject expectationObject = expectationObjectService.getExpectationObject(expectationId);
80 expectationObject.setObjectInstance((String) params.get("name"));
81 expectationObjectService.updateExpectationObject(expectationObject, expectationId);
83 String instanceId = intent.getIntentExpectations().get(0).getExpectationObject().getObjectInstance();
84 soService.deleteIntentInstance(instanceId);
85 intentService.deleteIntent(intent.getIntentId());
90 public void interactWithIntentHandle() {
95 public void fulfillIntent(IntentGoalBean intentGoalBean, IntentManagementFunction intentHandler) {
96 this.directOperation(intentGoalBean);
99 public String getInstanceId() {
100 int random = (int) (Math.random() * 9 + 1);
102 String randomString = String.valueOf(random);
103 int hashCode = UUID.randomUUID().toString().hashCode();
105 hashCode = -hashCode;
107 return randomString + String.format("%015d", hashCode);
110 public void updateIntentOperationInfo(Intent originIntent, IntentGoalBean intentGoalBean){
111 Intent subIntent = intentGoalBean.getIntent();
112 if (StringUtils.containsIgnoreCase(subIntent.getIntentName(),"delivery")) {
113 List<Expectation> deliveryIntentExpectationList = intentGoalBean.getIntent().getIntentExpectations();
114 List<Expectation> originIntentExpectationList = originIntent.getIntentExpectations();
115 ExpectationObject deliveryExpectationObject = deliveryIntentExpectationList.get(0).getExpectationObject();
116 String objectInstance = deliveryExpectationObject.getObjectInstance();
118 for (Expectation originExpectation : originIntentExpectationList) {
119 ExpectationObject originExpectationObject = originExpectation.getExpectationObject();
120 originExpectationObject.setObjectInstance(objectInstance);
123 log.info("cllDeliveryActuationModule begin to update originIntent subIntentInfo");