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.ExpectationObjectService;
25 import org.onap.usecaseui.intentanalysis.service.IntentService;
26 import org.springframework.beans.factory.annotation.Autowired;
27 import org.springframework.stereotype.Component;
29 import java.util.HashMap;
30 import java.util.List;
32 import java.util.UUID;
36 public class CLLDeliveryActuationModule extends ActuationModule {
39 private SOService soService;
42 private ExpectationObjectService expectationObjectService;
45 private IntentService intentService;
48 public void toNextIntentHandler(IntentGoalBean intentGoalBean, IntentManagementFunction IntentHandler) {
53 public void directOperation(IntentGoalBean intentGoalBean) {
54 Intent intent = intentGoalBean.getIntent();
55 if (StringUtils.equalsIgnoreCase("create", intentGoalBean.getIntentGoalType().name())) {
56 Map<String, Object> params = new HashMap<>();
57 Map<String, String> accessPointOne = new HashMap<>();
58 List<ExpectationTarget> targetList = intent.getIntentExpectations().get(0).getExpectationTargets();
59 for (ExpectationTarget target : targetList) {
60 String conditionName = target.getTargetConditions().get(0).getConditionName();
61 String conditionValue = target.getTargetConditions().get(0).getConditionValue();
62 if (StringUtils.containsIgnoreCase(conditionName, "source")) {
63 accessPointOne.put("name", conditionValue);
64 } else if (StringUtils.containsIgnoreCase(conditionName, "destination")) {
65 params.put("cloudPointName", conditionValue);
66 } else if (StringUtils.containsIgnoreCase(conditionName, "bandwidth")) {
67 accessPointOne.put("bandwidth", conditionValue);
70 params.put("accessPointOne", accessPointOne);
71 params.put("instanceId", getInstanceId());
72 params.put("name", "cll-" + params.get("instanceId"));
73 params.put("protect", false);
74 soService.createIntentInstance(params);
75 String expectationId = intent.getIntentExpectations().get(0).getExpectationId();
76 ExpectationObject expectationObject = expectationObjectService.getExpectationObject(expectationId);
77 expectationObject.setObjectInstance((String) params.get("name"));
78 expectationObjectService.updateExpectationObject(expectationObject, expectationId);
80 String instanceId = intent.getIntentExpectations().get(0).getExpectationObject().getObjectInstance();
81 soService.deleteIntentInstance(instanceId);
82 intentService.deleteIntent(intent.getIntentId());
87 public void interactWithIntentHandle() {
92 public void fulfillIntent(IntentGoalBean intentGoalBean, IntentManagementFunction intentHandler) {
93 this.directOperation(intentGoalBean);
96 public String getInstanceId() {
97 int random = (int) (Math.random() * 9 + 1);
99 String randomString = String.valueOf(random);
100 int hashCode = UUID.randomUUID().toString().hashCode();
102 hashCode = -hashCode;
104 return randomString + String.format("%015d", hashCode);
107 public void updateIntentOperationInfo(Intent originIntent, IntentGoalBean intentGoalBean){
108 Intent subIntent = intentGoalBean.getIntent();
109 if (StringUtils.containsIgnoreCase(subIntent.getIntentName(),"delivery")) {
110 List<Expectation> deliveryIntentExpectationList = intentGoalBean.getIntent().getIntentExpectations();
111 List<Expectation> originIntentExpectationList = originIntent.getIntentExpectations();
112 ExpectationObject deliveryExpectationObject = deliveryIntentExpectationList.get(0).getExpectationObject();
113 String objectInstance = deliveryExpectationObject.getObjectInstance();
115 for (Expectation originExpectation : originIntentExpectationList) {
116 ExpectationObject originExpectationObject = originExpectation.getExpectationObject();
117 originExpectationObject.setObjectInstance(objectInstance);
118 expectationObjectService.updateExpectationObject(originExpectationObject,originExpectation.getExpectationId());