2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (c) 2019 Samsung
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.so.bpmn.vcpe.scripts
25 import org.camunda.bpm.engine.delegate.BpmnError
26 import org.camunda.bpm.engine.delegate.DelegateExecution
27 import org.onap.so.bpmn.common.scripts.AllottedResourceUtils
28 import org.onap.so.bpmn.common.scripts.ExceptionUtil
29 import org.onap.so.bpmn.common.scripts.MsoUtils
30 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
31 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
32 import org.onap.so.bpmn.core.UrnPropertiesReader
33 import org.onap.so.bpmn.core.WorkflowException
34 import org.onap.so.logger.MessageEnum
35 import org.onap.so.logger.MsoLogger
36 import org.slf4j.Logger
37 import org.slf4j.LoggerFactory
39 import static org.apache.commons.lang3.StringUtils.isBlank
42 * This groovy class supports the <class>DoDeleteAllottedResourceTXC.bpmn</class> process.
47 * @param - msoRequestId
48 * @param - isDebugLogEnabled
49 * @param - disableRollback - O ignored
50 * @param - failNotfound - O
51 * @param - serviceInstanceId
52 * @param - globalCustomerId - O
53 * @param - subscriptionServiceType - O
54 * @param - parentServiceInstanceId
55 * @param - allottedResourceId
58 * @param - rollbackData - N/A
59 * @param - rolledBack - true if no deletions performed
60 * @param - WorkflowException - O
61 * @param - wasDeleted - O (ie not silentSuccess)
64 public class DoDeleteAllottedResourceTXC extends AbstractServiceTaskProcessor{
65 private static final Logger logger = LoggerFactory.getLogger(DoDeleteAllottedResourceTXC.class);
67 String Prefix="DDARTXC_"
68 ExceptionUtil exceptionUtil = new ExceptionUtil()
70 public void preProcessRequest (DelegateExecution execution) {
73 logger.trace("start preProcessRequest")
76 execution.setVariable("prefix", Prefix)
79 String sdncCallbackUrl = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
80 if (isBlank(sdncCallbackUrl)) {
81 msg = "mso.workflow.sdncadapter.callback is null"
83 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
85 execution.setVariable("sdncCallbackUrl", sdncCallbackUrl)
86 logger.debug("SDNC Callback URL: " + sdncCallbackUrl)
89 if (isBlank(execution.getVariable("serviceInstanceId"))){
90 msg = "Input serviceInstanceId is null"
92 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
94 if (isBlank(execution.getVariable("allottedResourceId"))){
95 msg = "Input allottedResourceId is null"
97 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
101 logger.debug("Rethrowing MSOWorkflowException")
103 } catch (Exception ex){
104 msg = "Exception in preProcessRequest " + ex.getMessage()
106 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
108 logger.trace("end preProcessRequest")
111 public void getAaiAR (DelegateExecution execution) {
113 logger.trace("start getAaiAR")
115 String allottedResourceId = execution.getVariable("allottedResourceId")
117 AllottedResourceUtils arUtils = getAllottedResourceUtils()
118 boolean ifExistsAR = arUtils.ifExistsAR(execution, allottedResourceId)
122 String aaiARPath = execution.getVariable("aaiARPath")
123 String parentServiceInstanceId = arUtils.getPSIFmARLink(execution, aaiARPath)
124 execution.setVariable("parentServiceInstanceId", parentServiceInstanceId)
127 errorMsg = "Allotted resource not found in AAI with AllottedResourceId:" + allottedResourceId
129 if (!isBlank(errorMsg)) {
130 logger.debug(errorMsg)
131 exceptionUtil.buildAndThrowWorkflowException(execution, 500, errorMsg)
133 logger.trace("end getAaiAR")
137 public AllottedResourceUtils getAllottedResourceUtils(){
138 return new AllottedResourceUtils(this)
141 // aaiARPath set during query (existing AR)
142 public void updateAaiAROrchStatus(DelegateExecution execution, String status){
143 logger.trace("start updateAaiAROrchStatus")
144 AllottedResourceUtils arUtils = new AllottedResourceUtils(this)
145 String aaiARPath = execution.getVariable("aaiARPath") //set during query (existing AR)
146 String orchStatus = arUtils.updateAROrchStatus(execution, status, aaiARPath)
147 logger.trace("end updateAaiAROrchStatus")
150 public String buildSDNCRequest(DelegateExecution execution, String action, String sdncRequestId) {
153 logger.trace("start buildSDNCRequest")
154 String sdncReq = null
158 String allottedResourceId = execution.getVariable("allottedResourceId")
159 String serviceInstanceId = execution.getVariable("serviceInstanceId")
160 String parentServiceInstanceId = execution.getVariable("parentServiceInstanceId")
161 String globalCustomerId = execution.getVariable("globalCustomerId")
162 String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
164 String callbackUrl = execution.getVariable("sdncCallbackUrl")
165 String requestId = execution.getVariable("msoRequestId")
167 String serviceChainServiceInstanceId = ""
168 String sourceNetworkId = ""
169 String sourceNetworkRole = ""
170 String allottedResourceRole = ""
172 String arModelInfo = ""
173 String modelInvariantId = ""
174 String modelVersion = ""
175 String modelUUId = ""
176 String modelCustomizationId = ""
177 String modelName = ""
181 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
182 xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
183 xmlns:sdncadapter="http://org.onap/workflow/sdnc/adapter/schema/v1">
184 <sdncadapter:RequestHeader>
185 <sdncadapter:RequestId>${MsoUtils.xmlEscape(sdncRequestId)}</sdncadapter:RequestId>
186 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(serviceInstanceId)}</sdncadapter:SvcInstanceId>
187 <sdncadapter:SvcAction>${MsoUtils.xmlEscape(action)}</sdncadapter:SvcAction>
188 <sdncadapter:SvcOperation>tunnelxconn-topology-operation</sdncadapter:SvcOperation>
189 <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackUrl)}</sdncadapter:CallbackUrl>
190 </sdncadapter:RequestHeader>
191 <sdncadapterworkflow:SDNCRequestData>
192 <request-information>
193 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
194 <request-action>DeleteTunnelXConnInstance</request-action>
199 </request-information>
200 <service-information>
201 <service-id></service-id>
202 <subscription-service-type>${MsoUtils.xmlEscape(subscriptionServiceType)}</subscription-service-type>
203 <onap-model-information></onap-model-information>
204 <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceId)}</service-instance-id>
206 <global-customer-id>${MsoUtils.xmlEscape(globalCustomerId)}</global-customer-id>
207 </service-information>
208 <allotted-resource-information>
209 <allotted-resource-id>${MsoUtils.xmlEscape(allottedResourceId)}</allotted-resource-id>
210 <allotted-resource-type>tunnelxconn</allotted-resource-type>
211 <parent-service-instance-id>${MsoUtils.xmlEscape(parentServiceInstanceId)}</parent-service-instance-id>
212 <onap-model-information>
213 <model-invariant-uuid>${MsoUtils.xmlEscape(modelInvariantId)}</model-invariant-uuid>
214 <model-uuid>${MsoUtils.xmlEscape(modelUUId)}</model-uuid>
215 <model-customization-uuid>${MsoUtils.xmlEscape(modelCustomizationId)}</model-customization-uuid>
216 <model-version>${MsoUtils.xmlEscape(modelVersion)}</model-version>
217 <model-name>${MsoUtils.xmlEscape(modelName)}</model-name>
218 </onap-model-information>
219 </allotted-resource-information>
220 <tunnelxconn-request-input>
221 </tunnelxconn-request-input>
222 </sdncadapterworkflow:SDNCRequestData>
223 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
225 logger.debug("sdncRequest:\n" + sdncReq)
226 sdncReq = utils.formatXml(sdncReq)
228 } catch(Exception ex) {
229 msg = "Exception in buildSDNCRequest. " + ex.getMessage()
231 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
233 logger.trace("end buildSDNCRequest")
237 public void preProcessSDNCUnassign(DelegateExecution execution) {
240 logger.trace("start preProcessSDNCUnassign")
243 String sdncRequestId = UUID.randomUUID().toString()
244 String sdncUnassignReq = buildSDNCRequest(execution, "unassign", sdncRequestId)
245 execution.setVariable("sdncUnassignRequest", sdncUnassignReq)
246 logger.debug("sdncUnassignRequest: " + sdncUnassignReq)
247 } catch (BpmnError e) {
249 } catch(Exception ex) {
250 msg = "Exception in preProcessSDNCUnassign. " + ex.getMessage()
252 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
254 logger.trace("end preProcessSDNCUnassign")
257 public void preProcessSDNCDelete(DelegateExecution execution) {
260 logger.trace("start preProcessSDNCDelete")
263 String sdncRequestId = UUID.randomUUID().toString()
264 String sdncDeleteReq = buildSDNCRequest(execution, "delete", sdncRequestId)
265 execution.setVariable("sdncDeleteRequest", sdncDeleteReq)
266 logger.debug("sdncDeleteReq: " + sdncDeleteReq)
267 } catch (BpmnError e) {
269 } catch(Exception ex) {
270 msg = "Exception in preProcessSDNCDelete. " + ex.getMessage()
272 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
274 logger.trace("end preProcessSDNCDelete")
277 public void preProcessSDNCDeactivate(DelegateExecution execution) {
280 logger.trace("start preProcessSDNCDeactivate")
283 String sdncRequestId = UUID.randomUUID().toString()
284 String sdncDeactivateReq = buildSDNCRequest(execution, "deactivate", sdncRequestId)
285 execution.setVariable("sdncDeactivateRequest", sdncDeactivateReq)
286 logger.debug("sdncDeactivateReq: " + sdncDeactivateReq)
287 } catch (BpmnError e) {
289 } catch(Exception ex) {
290 msg = "Exception in preProcessSDNCDeactivate. " + ex.getMessage()
292 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
294 logger.trace("end preProcessSDNCDeactivate")
297 public void validateSDNCResp(DelegateExecution execution, String response, String method){
299 logger.trace("start ValidateSDNCResponse Process")
303 WorkflowException workflowException = execution.getVariable("WorkflowException")
304 logger.debug("workflowException: " + workflowException)
306 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
307 logger.debug("SDNCResponse: " + response)
309 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
310 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
312 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
313 logger.debug("Received a Good Response from SDNC Adapter for " + method + " SDNC Call. Response is: \n"
316 String sdncRespCode = execution.getVariable(Prefix + 'sdncRequestDataResponseCode')
317 logger.debug(method + " AllottedResource received error response from SDNC. ResponseCode:"
319 if (sdncRespCode.equals("404") && "deactivate".equals(method))
321 execution.setVariable("ARNotFoundInSDNC", true)
322 if ("true".equals(execution.getVariable("failNotFound")))
324 msg = "Allotted Resource Not found in SDNC"
326 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
330 execution.setVariable("wasDeleted", false)
335 throw new BpmnError("MSOWorkflowException")
338 } catch (BpmnError e) {
340 } catch(Exception ex) {
341 msg = "Exception in validateSDNCResp. " + ex.getMessage()
343 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
345 logger.trace("end Exit ValidateSDNCResp Process")
348 public void deleteAaiAR(DelegateExecution execution){
349 logger.trace("start deleteAaiAR")
352 AllottedResourceUtils arUtils = new AllottedResourceUtils(this)
353 String arLink = execution.getVariable("aaiARPath")
354 arUtils.deleteAR(execution, arLink)
355 } catch (BpmnError e) {
357 }catch(Exception ex){
358 logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
359 "Exception Occurred Processing preProcessSDNCGetRequest.", "BPMN",
360 MsoLogger.ErrorCode.UnknownError.getValue(), "Exception is:\n" + ex);
361 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during SDNC GET Method:\n" + ex.getMessage())
363 logger.trace("end deleteAaiAR")