2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved.
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=========================================================
21 package org.onap.so.bpmn.infrastructure.scripts
24 import org.camunda.bpm.engine.delegate.DelegateExecution
25 import org.onap.so.bpmn.common.scripts.ExceptionUtil
26 import org.onap.so.bpmn.common.scripts.MsoUtils
27 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
28 import org.onap.so.bpmn.core.RollbackData
29 import org.onap.so.bpmn.core.UrnPropertiesReader
30 import org.onap.so.bpmn.core.WorkflowException
31 import org.onap.so.bpmn.core.json.JsonUtils
32 import org.slf4j.Logger
33 import org.slf4j.LoggerFactory
35 import static org.apache.commons.lang3.StringUtils.isBlank
38 private static final Logger logger = LoggerFactory.getLogger(TnNssmfUtils.class);
41 ExceptionUtil exceptionUtil = new ExceptionUtil()
42 JsonUtils jsonUtil = new JsonUtils()
43 MsoUtils msoUtils = new MsoUtils()
44 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils()
50 void setSdncCallbackUrl(DelegateExecution execution, boolean exceptionOnErr) {
51 setSdncCallbackUrl(execution, "sdncCallbackUrl", exceptionOnErr)
54 void setSdncCallbackUrl(DelegateExecution execution, String variableName, boolean exceptionOnErr) {
55 String sdncCallbackUrl = UrnPropertiesReader.getVariable('mso.workflow.sdncadapter.callback', execution)
57 if (isBlank(sdncCallbackUrl) && exceptionOnErr) {
58 String msg = "mso.workflow.sdncadapter.callback is null"
60 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
62 execution.setVariable(variableName, sdncCallbackUrl)
66 String buildSDNCRequest(DelegateExecution execution, String svcInstId, String action) {
68 String uuid = execution.getVariable('testReqId') // for junits
70 uuid = execution.getVariable("msoRequestId") + "-" + System.currentTimeMillis()
73 def callbackURL = execution.getVariable("sdncCallbackUrl")
74 def requestId = execution.getVariable("msoRequestId")
75 def serviceId = execution.getVariable("sliceServiceInstanceId")
76 def vnfType = execution.getVariable("serviceType")
77 def vnfName = execution.getVariable("sliceServiceInstanceName")
78 def tenantId = execution.getVariable("sliceServiceInstanceId")
79 def source = execution.getVariable("sliceServiceInstanceId")
80 def vnfId = execution.getVariable("sliceServiceInstanceId")
81 def cloudSiteId = execution.getVariable("sliceServiceInstanceId")
82 def serviceModelInfo = execution.getVariable("serviceModelInfo")
83 def vnfModelInfo = execution.getVariable("serviceModelInfo")
84 def globalSubscriberId = execution.getVariable("globalSubscriberId")
86 String vnfNameString = """<vnf-name>${MsoUtils.xmlEscape(vnfName)}</vnf-name>"""
87 String serviceEcompModelInformation = sdncAdapterUtils.modelInfoToEcompModelInformation(serviceModelInfo)
88 String vnfEcompModelInformation = sdncAdapterUtils.modelInfoToEcompModelInformation(vnfModelInfo)
90 String sdncVNFParamsXml = ""
92 if (execution.getVariable("vnfParamsExistFlag") == true) {
93 sdncVNFParamsXml = buildSDNCParamsXml(execution)
99 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
100 xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
101 xmlns:sdncadapter="http://org.onap/workflow/sdnc/adapter/schema/v1">
102 <sdncadapter:RequestHeader>
103 <sdncadapter:RequestId>${MsoUtils.xmlEscape(uuid)}</sdncadapter:RequestId>
104 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(svcInstId)}</sdncadapter:SvcInstanceId>
105 <sdncadapter:SvcAction>${MsoUtils.xmlEscape(action)}</sdncadapter:SvcAction>
106 <sdncadapter:SvcOperation>vnf-topology-operation</sdncadapter:SvcOperation>
107 <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackURL)}</sdncadapter:CallbackUrl>
108 <sdncadapter:MsoAction>generic-resource</sdncadapter:MsoAction>
109 </sdncadapter:RequestHeader>
110 <sdncadapterworkflow:SDNCRequestData>
111 <request-information>
112 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
113 <request-action>AllocateTnNssi</request-action>
114 <source>${MsoUtils.xmlEscape(source)}</source>
118 </request-information>
119 <service-information>
120 <service-id>${MsoUtils.xmlEscape(serviceId)}</service-id>
121 <subscription-service-type>${MsoUtils.xmlEscape(serviceId)}</subscription-service-type>
122 ${serviceEcompModelInformation}
123 <service-instance-id>${MsoUtils.xmlEscape(svcInstId)}</service-instance-id>
124 <global-customer-id>${MsoUtils.xmlEscape(globalSubscriberId)}</global-customer-id>
125 </service-information>
127 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
128 <vnf-type>${MsoUtils.xmlEscape(vnfType)}</vnf-type>
129 ${vnfEcompModelInformation}
133 <tenant>${MsoUtils.xmlEscape(tenantId)}</tenant>
134 <aic-cloud-region>${MsoUtils.xmlEscape(cloudSiteId)}</aic-cloud-region>
137 </sdncadapterworkflow:SDNCRequestData>
138 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
140 logger.debug("sdncRequest: " + sdncRequest)
144 String buildSDNCParamsXml(DelegateExecution execution) {
146 StringBuilder sb = new StringBuilder()
147 Map<String, String> paramsMap = execution.getVariable("TNNSSMF_vnfParamsMap")
149 for (Map.Entry<String, String> entry : paramsMap.entrySet()) {
151 String key = entry.getKey();
152 String value = entry.getValue()
153 paramsXml = """<${key}>$value</$key>"""
154 params = sb.append(paramsXml)
159 void validateSDNCResponse(DelegateExecution execution, String response, String method) {
160 validateSDNCResponse(execution, response, method, true)
163 void validateSDNCResponse(DelegateExecution execution, String response, String method, boolean exceptionOnErr) {
164 logger.debug("STARTED ValidateSDNCResponse Process")
168 String prefix = execution.setVariable("prefix")
169 if (isBlank(prefix)) {
170 if (exceptionOnErr) {
171 msg = "validateSDNCResponse: prefix is null"
173 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
178 WorkflowException workflowException = execution.getVariable("WorkflowException")
179 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
181 logger.debug("workflowException: " + workflowException)
183 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
185 String sdncResponse = response
186 if (execution.getVariable(prefix + 'sdncResponseSuccess') == true) {
187 logger.debug("Received a Good Response from SDNC Adapter for " + method + " SDNC Call. Response is: \n" + sdncResponse)
188 RollbackData rollbackData = execution.getVariable("rollbackData")
190 if (method.equals("allocate")) {
191 rollbackData.put("VNFMODULE", "rollbackSDNCRequestAllocate", "true")
192 } else if (method.equals("deallocate")) {
193 rollbackData.put("VNFMODULE", "rollbackSDNCRequestDeallocate", "true")
194 } else if (method.equals("activate")) {
195 rollbackData.put("VNFMODULE", "rollbackSDNCRequestActivate", "true")
196 } else if (method.equals("deactivate")) {
197 rollbackData.put("VNFMODULE", "rollbackSDNCRequestDeactivate", "true")
198 } else if (method.equals("modify")) {
199 rollbackData.put("VNFMODULE", "rollbackSDNCRequestModify", "true")
201 execution.setVariable("rollbackData", rollbackData)
203 if (exceptionOnErr) {
204 msg = "validateSDNCResponse: bad Response from SDNC Adapter for " + method + " SDNC Call."
206 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
210 logger.debug("COMPLETED ValidateSDNCResponse Process")
213 String getExecutionInputParams(DelegateExecution execution) {
214 String res = "msoRequestId=" + execution.getVariable("msoRequestId") +
215 ", modelInvariantUuid=" + execution.getVariable("modelInvariantUuid") +
216 ", modelUuid=" + execution.getVariable("modelUuid") +
217 ", serviceInstanceID=" + execution.getVariable("serviceInstanceID") +
218 ", operationType=" + execution.getVariable("operationType") +
219 ", globalSubscriberId=" + execution.getVariable("globalSubscriberId") +
220 ", dummyServiceId=" + execution.getVariable("dummyServiceId") +
221 ", nsiId=" + execution.getVariable("nsiId") +
222 ", networkType=" + execution.getVariable("networkType") +
223 ", subscriptionServiceType=" + execution.getVariable("subscriptionServiceType") +
224 ", jobId=" + execution.getVariable("jobId") +
225 ", sliceParams=" + execution.getVariable("sliceParams") +
226 ", servicename=" + execution.getVariable("servicename")
231 String getFirstSnssaiFromSliceProfile(String sliceProfileStr) {
232 String snssaiListStr = jsonUtil.getJsonValue(sliceProfileStr, "snssaiList")
233 String snssai = jsonUtil.StringArrayToList(snssaiListStr).get(0)
238 String getFirstPlmnIdFromSliceProfile(String sliceProfileStr) {
239 String plmnListStr = jsonUtil.getJsonValue(sliceProfileStr, "plmnIdList")
240 String res = jsonUtil.StringArrayToList(plmnListStr).get(0)