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.onap.so.logger.LoggingAnchor
26 import org.camunda.bpm.engine.delegate.BpmnError
27 import org.camunda.bpm.engine.delegate.DelegateExecution
28 import org.onap.so.bpmn.common.scripts.AllottedResourceUtils
29 import org.onap.so.bpmn.common.scripts.ExceptionUtil
30 import org.onap.so.bpmn.common.scripts.MsoUtils
31 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
32 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
33 import org.onap.so.bpmn.core.UrnPropertiesReader
34 import org.onap.so.bpmn.core.WorkflowException
35 import org.onap.so.logger.ErrorCode
36 import org.onap.so.logger.MessageEnum
37 import org.slf4j.Logger
38 import org.slf4j.LoggerFactory
40 import static org.apache.commons.lang3.StringUtils.isBlank
43 * This groovy class supports the <class>DoDeleteAllottedResourceTXC.bpmn</class> process.
48 * @param - msoRequestId
49 * @param - isDebugLogEnabled
50 * @param - disableRollback - O ignored
51 * @param - failNotfound - O
52 * @param - serviceInstanceId
53 * @param - globalCustomerId - O
54 * @param - subscriptionServiceType - O
55 * @param - parentServiceInstanceId
56 * @param - allottedResourceId
59 * @param - rollbackData - N/A
60 * @param - rolledBack - true if no deletions performed
61 * @param - WorkflowException - O
62 * @param - wasDeleted - O (ie not silentSuccess)
65 public class DoDeleteAllottedResourceTXC extends AbstractServiceTaskProcessor{
66 private static final Logger logger = LoggerFactory.getLogger(DoDeleteAllottedResourceTXC.class);
68 String Prefix="DDARTXC_"
69 ExceptionUtil exceptionUtil = new ExceptionUtil()
71 public void preProcessRequest (DelegateExecution execution) {
74 logger.trace("start preProcessRequest")
77 execution.setVariable("prefix", Prefix)
80 String sdncCallbackUrl = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
81 if (isBlank(sdncCallbackUrl)) {
82 msg = "mso.workflow.sdncadapter.callback is null"
84 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
86 execution.setVariable("sdncCallbackUrl", sdncCallbackUrl)
87 logger.debug("SDNC Callback URL: " + sdncCallbackUrl)
90 if (isBlank(execution.getVariable("serviceInstanceId"))){
91 msg = "Input serviceInstanceId is null"
93 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
95 if (isBlank(execution.getVariable("allottedResourceId"))){
96 msg = "Input allottedResourceId is null"
98 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
102 logger.debug("Rethrowing MSOWorkflowException")
104 } catch (Exception ex){
105 msg = "Exception in preProcessRequest " + ex.getMessage()
107 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
109 logger.trace("end preProcessRequest")
112 public void getAaiAR (DelegateExecution execution) {
114 logger.trace("start getAaiAR")
116 String allottedResourceId = execution.getVariable("allottedResourceId")
118 AllottedResourceUtils arUtils = getAllottedResourceUtils()
119 boolean ifExistsAR = arUtils.ifExistsAR(execution, allottedResourceId)
123 String aaiARPath = execution.getVariable("aaiARPath")
124 String parentServiceInstanceId = arUtils.getPSIFmARLink(execution, aaiARPath)
125 execution.setVariable("parentServiceInstanceId", parentServiceInstanceId)
128 errorMsg = "Allotted resource not found in AAI with AllottedResourceId:" + allottedResourceId
130 if (!isBlank(errorMsg)) {
131 logger.debug(errorMsg)
132 exceptionUtil.buildAndThrowWorkflowException(execution, 500, errorMsg)
134 logger.trace("end getAaiAR")
138 public AllottedResourceUtils getAllottedResourceUtils(){
139 return new AllottedResourceUtils(this)
142 // aaiARPath set during query (existing AR)
143 public void updateAaiAROrchStatus(DelegateExecution execution, String status){
144 logger.trace("start updateAaiAROrchStatus")
145 AllottedResourceUtils arUtils = new AllottedResourceUtils(this)
146 String aaiARPath = execution.getVariable("aaiARPath") //set during query (existing AR)
147 String orchStatus = arUtils.updateAROrchStatus(execution, status, aaiARPath)
148 logger.trace("end updateAaiAROrchStatus")
151 public String buildSDNCRequest(DelegateExecution execution, String action, String sdncRequestId) {
154 logger.trace("start buildSDNCRequest")
155 String sdncReq = null
159 String allottedResourceId = execution.getVariable("allottedResourceId")
160 String serviceInstanceId = execution.getVariable("serviceInstanceId")
161 String parentServiceInstanceId = execution.getVariable("parentServiceInstanceId")
162 String globalCustomerId = execution.getVariable("globalCustomerId")
163 String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
165 String callbackUrl = execution.getVariable("sdncCallbackUrl")
166 String requestId = execution.getVariable("msoRequestId")
168 String serviceChainServiceInstanceId = ""
169 String sourceNetworkId = ""
170 String sourceNetworkRole = ""
171 String allottedResourceRole = ""
173 String arModelInfo = ""
174 String modelInvariantId = ""
175 String modelVersion = ""
176 String modelUUId = ""
177 String modelCustomizationId = ""
178 String modelName = ""
182 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
183 xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
184 xmlns:sdncadapter="http://org.onap/workflow/sdnc/adapter/schema/v1">
185 <sdncadapter:RequestHeader>
186 <sdncadapter:RequestId>${MsoUtils.xmlEscape(sdncRequestId)}</sdncadapter:RequestId>
187 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(serviceInstanceId)}</sdncadapter:SvcInstanceId>
188 <sdncadapter:SvcAction>${MsoUtils.xmlEscape(action)}</sdncadapter:SvcAction>
189 <sdncadapter:SvcOperation>tunnelxconn-topology-operation</sdncadapter:SvcOperation>
190 <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackUrl)}</sdncadapter:CallbackUrl>
191 </sdncadapter:RequestHeader>
192 <sdncadapterworkflow:SDNCRequestData>
193 <request-information>
194 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
195 <request-action>DeleteTunnelXConnInstance</request-action>
200 </request-information>
201 <service-information>
202 <service-id></service-id>
203 <subscription-service-type>${MsoUtils.xmlEscape(subscriptionServiceType)}</subscription-service-type>
204 <onap-model-information></onap-model-information>
205 <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceId)}</service-instance-id>
207 <global-customer-id>${MsoUtils.xmlEscape(globalCustomerId)}</global-customer-id>
208 </service-information>
209 <allotted-resource-information>
210 <allotted-resource-id>${MsoUtils.xmlEscape(allottedResourceId)}</allotted-resource-id>
211 <allotted-resource-type>tunnelxconn</allotted-resource-type>
212 <parent-service-instance-id>${MsoUtils.xmlEscape(parentServiceInstanceId)}</parent-service-instance-id>
213 <onap-model-information>
214 <model-invariant-uuid>${MsoUtils.xmlEscape(modelInvariantId)}</model-invariant-uuid>
215 <model-uuid>${MsoUtils.xmlEscape(modelUUId)}</model-uuid>
216 <model-customization-uuid>${MsoUtils.xmlEscape(modelCustomizationId)}</model-customization-uuid>
217 <model-version>${MsoUtils.xmlEscape(modelVersion)}</model-version>
218 <model-name>${MsoUtils.xmlEscape(modelName)}</model-name>
219 </onap-model-information>
220 </allotted-resource-information>
221 <tunnelxconn-request-input>
222 </tunnelxconn-request-input>
223 </sdncadapterworkflow:SDNCRequestData>
224 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
226 logger.debug("sdncRequest:\n" + sdncReq)
227 sdncReq = utils.formatXml(sdncReq)
229 } catch(Exception ex) {
230 msg = "Exception in buildSDNCRequest. " + ex.getMessage()
232 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
234 logger.trace("end buildSDNCRequest")
238 public void preProcessSDNCUnassign(DelegateExecution execution) {
241 logger.trace("start preProcessSDNCUnassign")
244 String sdncRequestId = UUID.randomUUID().toString()
245 String sdncUnassignReq = buildSDNCRequest(execution, "unassign", sdncRequestId)
246 execution.setVariable("sdncUnassignRequest", sdncUnassignReq)
247 logger.debug("sdncUnassignRequest: " + sdncUnassignReq)
248 } catch (BpmnError e) {
250 } catch(Exception ex) {
251 msg = "Exception in preProcessSDNCUnassign. " + ex.getMessage()
253 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
255 logger.trace("end preProcessSDNCUnassign")
258 public void preProcessSDNCDelete(DelegateExecution execution) {
261 logger.trace("start preProcessSDNCDelete")
264 String sdncRequestId = UUID.randomUUID().toString()
265 String sdncDeleteReq = buildSDNCRequest(execution, "delete", sdncRequestId)
266 execution.setVariable("sdncDeleteRequest", sdncDeleteReq)
267 logger.debug("sdncDeleteReq: " + sdncDeleteReq)
268 } catch (BpmnError e) {
270 } catch(Exception ex) {
271 msg = "Exception in preProcessSDNCDelete. " + ex.getMessage()
273 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
275 logger.trace("end preProcessSDNCDelete")
278 public void preProcessSDNCDeactivate(DelegateExecution execution) {
281 logger.trace("start preProcessSDNCDeactivate")
284 String sdncRequestId = UUID.randomUUID().toString()
285 String sdncDeactivateReq = buildSDNCRequest(execution, "deactivate", sdncRequestId)
286 execution.setVariable("sdncDeactivateRequest", sdncDeactivateReq)
287 logger.debug("sdncDeactivateReq: " + sdncDeactivateReq)
288 } catch (BpmnError e) {
290 } catch(Exception ex) {
291 msg = "Exception in preProcessSDNCDeactivate. " + ex.getMessage()
293 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
295 logger.trace("end preProcessSDNCDeactivate")
298 public void validateSDNCResp(DelegateExecution execution, String response, String method){
300 logger.trace("start ValidateSDNCResponse Process")
304 WorkflowException workflowException = execution.getVariable("WorkflowException")
305 logger.debug("workflowException: " + workflowException)
307 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
308 logger.debug("SDNCResponse: " + response)
310 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils()
311 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
313 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
314 logger.debug("Received a Good Response from SDNC Adapter for " + method + " SDNC Call. Response is: \n"
317 String sdncRespCode = execution.getVariable(Prefix + 'sdncRequestDataResponseCode')
318 logger.debug(method + " AllottedResource received error response from SDNC. ResponseCode:"
320 if (sdncRespCode.equals("404") && "deactivate".equals(method))
322 execution.setVariable("ARNotFoundInSDNC", true)
323 if ("true".equals(execution.getVariable("failNotFound")))
325 msg = "Allotted Resource Not found in SDNC"
327 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
331 execution.setVariable("wasDeleted", false)
336 throw new BpmnError("MSOWorkflowException")
339 } catch (BpmnError e) {
341 } catch(Exception ex) {
342 msg = "Exception in validateSDNCResp. " + ex.getMessage()
344 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
346 logger.trace("end Exit ValidateSDNCResp Process")
349 public void deleteAaiAR(DelegateExecution execution){
350 logger.trace("start deleteAaiAR")
353 AllottedResourceUtils arUtils = new AllottedResourceUtils(this)
354 String arLink = execution.getVariable("aaiARPath")
355 arUtils.deleteAR(execution, arLink)
356 } catch (BpmnError e) {
358 }catch(Exception ex){
359 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
360 "Exception Occurred Processing preProcessSDNCGetRequest.", "BPMN",
361 ErrorCode.UnknownError.getValue(), "Exception is:\n" + ex);
362 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during SDNC GET Method:\n" + ex.getMessage())
364 logger.trace("end deleteAaiAR")