2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (c) 2022 Deutsche telekom
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
22 package org.onap.so.bpmn.moi.tasks;
24 import com.fasterxml.jackson.databind.ObjectMapper;
25 import org.camunda.bpm.engine.delegate.DelegateExecution;
26 import org.onap.so.bpmn.common.BuildingBlockExecution;
27 import org.onap.so.bpmn.common.DelegateExecutionImpl;
28 import org.onap.so.bpmn.common.InjectExecution;
29 import org.onap.so.bpmn.common.scripts.ExceptionUtil;
30 import org.onap.so.bpmn.common.scripts.OofUtils;
31 import org.onap.so.bpmn.core.json.JsonUtils;
32 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
33 import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
34 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance;
35 import org.onap.so.db.catalog.beans.Service;
36 import org.onap.so.db.catalog.client.CatalogDbClient;
37 import org.onap.so.moi.Attributes;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
40 import org.springframework.beans.factory.annotation.Autowired;
41 import org.springframework.stereotype.Component;
42 import java.util.HashMap;
43 import java.util.List;
47 public class EnrichGBBTask {
49 private static final String EXECUTE_BB_VAR_NAME = "buildingBlock";
50 private static final String GBB_INPUT_VAR_NAME = "gBBInput";
52 ExceptionUtil exceptionUtil = new ExceptionUtil();
53 JsonUtils jsonUtil = new JsonUtils();
56 CatalogDbClient catalogDbClient;
58 InjectExecution injectExecution = new InjectExecution();
61 private static final Logger LOGGER = LoggerFactory.getLogger(EnrichGBBTask.class);
62 private static final ObjectMapper mapper = new ObjectMapper();
63 OofUtils oofUtils = new OofUtils(null);
65 public void prepareOofRequest(DelegateExecution execution) throws Exception {
67 String msoReqId = (String) execution.getVariable("mso-request-id");
70 BuildingBlockExecution gBuildingBlockExecution =
71 (BuildingBlockExecution) execution.getVariable("gBuildingBlockExecution");
73 DelegateExecutionImpl gbbEx = injectExecution.execute(execution,
74 (DelegateExecutionImpl) execution.getVariable("gBuildingBlockExecution"));
77 GeneralBuildingBlock generalBuildingBlock = (GeneralBuildingBlock) execution.getVariable("gBBInput");
79 List<Map<String, Object>> mapUserParams =
80 generalBuildingBlock.getRequestContext().getRequestParameters().getUserParams();
82 Attributes attributes = null;
84 for (Map<String, Object> userParamData : mapUserParams) {
85 if (userParamData.get("nssi") != null) {
86 Map<String, Object> mapParam = (Map<String, Object>) userParamData.get("nssi");
87 LOGGER.info(">>> mapParam: {}", mapParam);
88 attributes = mapper.convertValue(mapParam, Attributes.class);
91 // Attributes attributes = new ObjectMapper().convertValue(attrMap, Attributes.class);
92 Integer latency = attributes.getSliceProfileList().get(0).getRANSliceSubnetProfile().getLatency();
93 Integer areaTrafficCapDL =
94 attributes.getSliceProfileList().get(0).getRANSliceSubnetProfile().getAreaTrafficCapDL();
97 String requestId = generalBuildingBlock.getRequestContext().getMsoRequestId();
100 String apiPath = "/api/oof/v1/selection/nsst";
101 LOGGER.debug("API path for NSST Selection: " + apiPath);
102 execution.setVariable("NSST_apiPath", apiPath);
104 // Setting correlator as requestId
105 execution.setVariable("NSST_correlator", requestId);
107 // Setting messageType for all Core slice as an
108 String messageType = "an";
109 execution.setVariable("NSST_messageType", messageType);
111 String timeout = "PT30M";
112 execution.setVariable("NSST_timeout", timeout);
114 Map<String, Object> profileInfo = new HashMap<>();
115 profileInfo.put("latency", latency);
116 profileInfo.put("areaTrafficCapDL", areaTrafficCapDL);
118 String oofRequest = oofUtils.buildSelectNSTRequest(requestId, messageType, profileInfo);
119 LOGGER.debug("**** OOfRequest for NSST Selection: " + oofRequest);
120 execution.setVariable("NSST_oofRequest", oofRequest);
124 public void processOOFAsyncResponse(DelegateExecution execution) {
125 GeneralBuildingBlock generalBuildingBlock = (GeneralBuildingBlock) execution.getVariable("gBBInput");
127 LOGGER.debug(">>>> generalBuildingBlock Initial: {}", generalBuildingBlock);
129 LOGGER.debug(" **** Enter EnrichGBB ::: processOOFAsyncResponse ****");
130 String OOFResponse = (String) execution.getVariable("NSST_asyncCallbackResponse");
131 String requestStatus = jsonUtil.getJsonValue(OOFResponse, "requestStatus");
132 LOGGER.debug("NSST OOFResponse is: " + OOFResponse);
133 execution.setVariable("OOFResponse", OOFResponse);
134 String solutions = "";
135 if (requestStatus.equals("completed")) {
136 List solutionsList = jsonUtil.StringArrayToList(jsonUtil.getJsonValue(OOFResponse, "solutions"));
137 if (solutionsList != null && !solutionsList.isEmpty()) {
138 solutions = (String) solutionsList.get(0);
141 String statusMessage = jsonUtil.getJsonValue(OOFResponse, "statusMessage");
142 LOGGER.error("received failed status from oof " + statusMessage);
143 LOGGER.debug("received failed status from oof " + statusMessage);
146 LOGGER.debug(">>>>>> solutions: {}", solutions);
148 String nsstId = jsonUtil.getJsonValue(solutions, "UUID");
149 LOGGER.info(">>> nsstId:{} ", nsstId);
151 Service service = catalogDbClient.getServiceByModelUUID(nsstId);
153 LOGGER.info("Service from CatalogDB: {}", service);
155 LOGGER.debug(">>> Map Incoming Values to GBB");
157 ServiceInstance serviceInstance = generalBuildingBlock.getServiceInstance();
159 ModelInfoServiceInstance modelInfoServiceInstanceFromGBB = serviceInstance.getModelInfoServiceInstance();
161 if (modelInfoServiceInstanceFromGBB == null) {
162 String modelInvariantId = service.getModelInvariantUUID();
163 String modelVersion = service.getModelVersion();
164 String serviceType = service.getServiceType();
165 String serviceRole = service.getServiceRole();
166 String controllerActor = service.getControllerActor();
167 String blueprintName = service.getBlueprintName();
168 String blueprintVersion = service.getBlueprintVersion();
170 ModelInfoServiceInstance modelInfoServiceInstance = new ModelInfoServiceInstance();
171 modelInfoServiceInstance.setModelUuid("ad2233a2-6e3f-42cf-8c60-04e614031383");
172 modelInfoServiceInstance.setModelInvariantUuid("38730fb9-bfbb-4a78-88f8-b4f6823197b6");
173 modelInfoServiceInstance.setModelVersion("1.0");
174 modelInfoServiceInstance.setServiceRole("AN");
175 modelInfoServiceInstance.setServiceType("eMBB");
176 modelInfoServiceInstance.setBlueprintVersion("1.0.0");
177 modelInfoServiceInstance.setControllerActor("CDS");
178 modelInfoServiceInstance.setBlueprintName("Hello_World_CBA");
179 modelInfoServiceInstance.setServiceType(serviceType);
180 modelInfoServiceInstance.setServiceRole(serviceRole);
181 modelInfoServiceInstance.setControllerActor(controllerActor);
182 modelInfoServiceInstance.setBlueprintName(blueprintName);
183 modelInfoServiceInstance.setBlueprintVersion(blueprintVersion);
184 modelInfoServiceInstance.setModelInvariantUuid(modelInvariantId);
185 modelInfoServiceInstance.setModelUuid(nsstId);
186 modelInfoServiceInstance.setModelVersion(modelVersion);
188 serviceInstance.setModelInfoServiceInstance(modelInfoServiceInstance);
190 serviceInstance.setModelInfoServiceInstance(modelInfoServiceInstance);
195 LOGGER.info(">>> ServiceInstance: {}", serviceInstance);
197 generalBuildingBlock.setServiceInstance(serviceInstance);
199 LOGGER.debug("generalBuildingBlock: {}", generalBuildingBlock);
201 execution.setVariable(GBB_INPUT_VAR_NAME, generalBuildingBlock);
202 BuildingBlockExecution gBuildingBlockExecution1 = new DelegateExecutionImpl(execution);
203 execution.setVariable("gBuildingBlockExecution", gBuildingBlockExecution1);
205 // execution.setVariable("gBuildingBlockExecution", gBBExecution);
206 LOGGER.debug(" **** Exit EnrichBB ::: processOOFAsyncResponse ****");