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>DoDeleteAllottedResourceBRG.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 DoDeleteAllottedResourceBRG extends AbstractServiceTaskProcessor{
66 private static final Logger logger = LoggerFactory.getLogger(DoDeleteAllottedResourceBRG.class);
68 String Prefix="DDARBRG_"
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 end")
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 // aaiARPath set during query (existing AR)
139 public void updateAaiAROrchStatus(DelegateExecution execution, String status){
140 logger.trace("start updateAaiAROrchStatus")
141 AllottedResourceUtils arUtils = new AllottedResourceUtils(this)
142 String aaiARPath = execution.getVariable("aaiARPath") //set during query (existing AR)
143 String orchStatus = arUtils.updateAROrchStatus(execution, status, aaiARPath)
144 logger.trace("end updateAaiAROrchStatus")
147 public String buildSDNCRequest(DelegateExecution execution, String action, String sdncRequestId) {
150 logger.trace("start buildSDNCRequest")
151 String sdncReq = null
155 String allottedResourceId = execution.getVariable("allottedResourceId")
156 String serviceInstanceId = execution.getVariable("serviceInstanceId")
157 String parentServiceInstanceId = execution.getVariable("parentServiceInstanceId")
158 String globalCustomerId = execution.getVariable("globalCustomerId")
159 String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
161 String callbackUrl = execution.getVariable("sdncCallbackUrl")
162 String requestId = execution.getVariable("msoRequestId")
164 String serviceChainServiceInstanceId = ""
165 String sourceNetworkId = ""
166 String sourceNetworkRole = ""
167 String allottedResourceRole = ""
169 String arModelInfo = ""
170 String modelInvariantId = ""
171 String modelVersion = ""
172 String modelUUId = ""
173 String modelCustomizationId = ""
174 String modelName = ""
178 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
179 xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
180 xmlns:sdncadapter="http://org.onap/workflow/sdnc/adapter/schema/v1">
181 <sdncadapter:RequestHeader>
182 <sdncadapter:RequestId>${MsoUtils.xmlEscape(sdncRequestId)}</sdncadapter:RequestId>
183 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(serviceInstanceId)}</sdncadapter:SvcInstanceId>
184 <sdncadapter:SvcAction>${MsoUtils.xmlEscape(action)}</sdncadapter:SvcAction>
185 <sdncadapter:SvcOperation>brg-topology-operation</sdncadapter:SvcOperation>
186 <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackUrl)}</sdncadapter:CallbackUrl>
187 </sdncadapter:RequestHeader>
188 <sdncadapterworkflow:SDNCRequestData>
189 <request-information>
190 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
191 <request-action>DeleteBRGInstance</request-action>
196 </request-information>
197 <service-information>
198 <service-id></service-id>
199 <subscription-service-type>${MsoUtils.xmlEscape(subscriptionServiceType)}</subscription-service-type>
200 <onap-model-information></onap-model-information>
201 <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceId)}</service-instance-id>
203 <global-customer-id>${MsoUtils.xmlEscape(globalCustomerId)}</global-customer-id>
204 </service-information>
205 <allotted-resource-information>
206 <allotted-resource-id>${MsoUtils.xmlEscape(allottedResourceId)}</allotted-resource-id>
207 <allotted-resource-type>brg</allotted-resource-type>
208 <parent-service-instance-id>${MsoUtils.xmlEscape(parentServiceInstanceId)}</parent-service-instance-id>
209 <onap-model-information>
210 <model-invariant-uuid>${MsoUtils.xmlEscape(modelInvariantId)}</model-invariant-uuid>
211 <model-uuid>${MsoUtils.xmlEscape(modelUUId)}</model-uuid>
212 <model-customization-uuid>${MsoUtils.xmlEscape(modelCustomizationId)}</model-customization-uuid>
213 <model-version>${MsoUtils.xmlEscape(modelVersion)}</model-version>
214 <model-name>${MsoUtils.xmlEscape(modelName)}</model-name>
215 </onap-model-information>
216 </allotted-resource-information>
219 </sdncadapterworkflow:SDNCRequestData>
220 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
222 logger.debug("sdncRequest:\n" + sdncReq)
223 sdncReq = utils.formatXml(sdncReq)
225 } catch(Exception ex) {
226 msg = "Exception in buildSDNCRequest. " + ex.getMessage()
228 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
230 logger.trace("end buildSDNCRequest")
234 public void preProcessSDNCUnassign(DelegateExecution execution) {
237 logger.trace("start preProcessSDNCUnassign")
240 String sdncRequestId = UUID.randomUUID().toString()
241 String sdncUnassignReq = buildSDNCRequest(execution, "unassign", sdncRequestId)
242 execution.setVariable("sdncUnassignRequest", sdncUnassignReq)
243 logger.debug("sdncUnassignRequest: " + sdncUnassignReq)
244 } catch (BpmnError e) {
246 } catch(Exception ex) {
247 msg = "Exception in preProcessSDNCUnassign. " + ex.getMessage()
249 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
251 logger.trace("end preProcessSDNCUnassign")
254 public void preProcessSDNCDelete(DelegateExecution execution) {
257 logger.trace("start preProcessSDNCDelete")
260 String sdncRequestId = UUID.randomUUID().toString()
261 String sdncDeleteReq = buildSDNCRequest(execution, "delete", sdncRequestId)
262 execution.setVariable("sdncDeleteRequest", sdncDeleteReq)
263 logger.debug("sdncDeleteReq: " + sdncDeleteReq)
264 } catch (BpmnError e) {
266 } catch(Exception ex) {
267 msg = "Exception in preProcessSDNCDelete. " + ex.getMessage()
269 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
271 logger.trace("end preProcessSDNCDelete")
274 public void preProcessSDNCDeactivate(DelegateExecution execution) {
277 logger.trace("start preProcessSDNCDeactivate")
280 String sdncRequestId = UUID.randomUUID().toString()
281 String sdncDeactivateReq = buildSDNCRequest(execution, "deactivate", sdncRequestId)
282 execution.setVariable("sdncDeactivateRequest", sdncDeactivateReq)
283 logger.debug("sdncDeactivateReq: " + sdncDeactivateReq)
284 } catch (BpmnError e) {
286 } catch(Exception ex) {
287 msg = "Exception in preProcessSDNCDeactivate. " + ex.getMessage()
289 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
291 logger.trace("end preProcessSDNCDeactivate")
294 public void validateSDNCResp(DelegateExecution execution, String response, String method){
296 logger.trace("start ValidateSDNCResponse Process")
300 WorkflowException workflowException = execution.getVariable("WorkflowException")
301 logger.debug("workflowException: " + workflowException)
303 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
304 logger.debug("SDNCResponse: " + response)
306 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils()
307 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
309 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
310 logger.debug("Received a Good Response from SDNC Adapter for " + method + " SDNC Call. Response is: \n"
313 String sdncRespCode = execution.getVariable(Prefix + 'sdncRequestDataResponseCode')
314 logger.debug(method + " AllottedResource received error response from SDNC. ResponseCode:"
316 if (sdncRespCode.equals("404") && "deactivate".equals(method))
318 execution.setVariable("ARNotFoundInSDNC", true)
319 if ("true".equals(execution.getVariable("failNotFound")))
321 msg = "Allotted Resource Not found in SDNC"
323 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
327 execution.setVariable("wasDeleted", false)
332 throw new BpmnError("MSOWorkflowException")
335 } catch (BpmnError e) {
337 } catch(Exception ex) {
338 msg = "Exception in validateSDNCResp. " + ex.getMessage()
340 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
342 logger.trace("end ValidateSDNCResp Process")
345 public void deleteAaiAR(DelegateExecution execution){
346 logger.trace("start deleteAaiAR")
349 AllottedResourceUtils arUtils = new AllottedResourceUtils(this)
350 String arLink = execution.getVariable("aaiARPath")
351 arUtils.deleteAR(execution, arLink)
352 } catch (BpmnError e) {
354 }catch(Exception ex){
355 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
356 "Exception Occurred Processing preProcessSDNCGetRequest." + ex, "BPMN",
357 ErrorCode.UnknownError.getValue(), "Exception is:" + ex);
358 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during SDNC GET Method:\n" + ex.getMessage())
360 logger.trace("end deleteAaiAR")
363 public AllottedResourceUtils getAllottedResourceUtils(){
364 return new AllottedResourceUtils(this)