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>DoDeleteAllottedResourceBRG.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 DoDeleteAllottedResourceBRG extends AbstractServiceTaskProcessor{
65 private static final Logger logger = LoggerFactory.getLogger(DoDeleteAllottedResourceBRG.class);
67 String Prefix="DDARBRG_"
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 end")
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 // aaiARPath set during query (existing AR)
138 public void updateAaiAROrchStatus(DelegateExecution execution, String status){
139 logger.trace("start updateAaiAROrchStatus")
140 AllottedResourceUtils arUtils = new AllottedResourceUtils(this)
141 String aaiARPath = execution.getVariable("aaiARPath") //set during query (existing AR)
142 String orchStatus = arUtils.updateAROrchStatus(execution, status, aaiARPath)
143 logger.trace("end updateAaiAROrchStatus")
146 public String buildSDNCRequest(DelegateExecution execution, String action, String sdncRequestId) {
149 logger.trace("start buildSDNCRequest")
150 String sdncReq = null
154 String allottedResourceId = execution.getVariable("allottedResourceId")
155 String serviceInstanceId = execution.getVariable("serviceInstanceId")
156 String parentServiceInstanceId = execution.getVariable("parentServiceInstanceId")
157 String globalCustomerId = execution.getVariable("globalCustomerId")
158 String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
160 String callbackUrl = execution.getVariable("sdncCallbackUrl")
161 String requestId = execution.getVariable("msoRequestId")
163 String serviceChainServiceInstanceId = ""
164 String sourceNetworkId = ""
165 String sourceNetworkRole = ""
166 String allottedResourceRole = ""
168 String arModelInfo = ""
169 String modelInvariantId = ""
170 String modelVersion = ""
171 String modelUUId = ""
172 String modelCustomizationId = ""
173 String modelName = ""
177 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
178 xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
179 xmlns:sdncadapter="http://org.onap/workflow/sdnc/adapter/schema/v1">
180 <sdncadapter:RequestHeader>
181 <sdncadapter:RequestId>${MsoUtils.xmlEscape(sdncRequestId)}</sdncadapter:RequestId>
182 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(serviceInstanceId)}</sdncadapter:SvcInstanceId>
183 <sdncadapter:SvcAction>${MsoUtils.xmlEscape(action)}</sdncadapter:SvcAction>
184 <sdncadapter:SvcOperation>brg-topology-operation</sdncadapter:SvcOperation>
185 <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackUrl)}</sdncadapter:CallbackUrl>
186 </sdncadapter:RequestHeader>
187 <sdncadapterworkflow:SDNCRequestData>
188 <request-information>
189 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
190 <request-action>DeleteBRGInstance</request-action>
195 </request-information>
196 <service-information>
197 <service-id></service-id>
198 <subscription-service-type>${MsoUtils.xmlEscape(subscriptionServiceType)}</subscription-service-type>
199 <onap-model-information></onap-model-information>
200 <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceId)}</service-instance-id>
202 <global-customer-id>${MsoUtils.xmlEscape(globalCustomerId)}</global-customer-id>
203 </service-information>
204 <allotted-resource-information>
205 <allotted-resource-id>${MsoUtils.xmlEscape(allottedResourceId)}</allotted-resource-id>
206 <allotted-resource-type>brg</allotted-resource-type>
207 <parent-service-instance-id>${MsoUtils.xmlEscape(parentServiceInstanceId)}</parent-service-instance-id>
208 <onap-model-information>
209 <model-invariant-uuid>${MsoUtils.xmlEscape(modelInvariantId)}</model-invariant-uuid>
210 <model-uuid>${MsoUtils.xmlEscape(modelUUId)}</model-uuid>
211 <model-customization-uuid>${MsoUtils.xmlEscape(modelCustomizationId)}</model-customization-uuid>
212 <model-version>${MsoUtils.xmlEscape(modelVersion)}</model-version>
213 <model-name>${MsoUtils.xmlEscape(modelName)}</model-name>
214 </onap-model-information>
215 </allotted-resource-information>
218 </sdncadapterworkflow:SDNCRequestData>
219 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
221 logger.debug("sdncRequest:\n" + sdncReq)
222 sdncReq = utils.formatXml(sdncReq)
224 } catch(Exception ex) {
225 msg = "Exception in buildSDNCRequest. " + ex.getMessage()
227 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
229 logger.trace("end buildSDNCRequest")
233 public void preProcessSDNCUnassign(DelegateExecution execution) {
236 logger.trace("start preProcessSDNCUnassign")
239 String sdncRequestId = UUID.randomUUID().toString()
240 String sdncUnassignReq = buildSDNCRequest(execution, "unassign", sdncRequestId)
241 execution.setVariable("sdncUnassignRequest", sdncUnassignReq)
242 logger.debug("sdncUnassignRequest: " + sdncUnassignReq)
243 } catch (BpmnError e) {
245 } catch(Exception ex) {
246 msg = "Exception in preProcessSDNCUnassign. " + ex.getMessage()
248 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
250 logger.trace("end preProcessSDNCUnassign")
253 public void preProcessSDNCDelete(DelegateExecution execution) {
256 logger.trace("start preProcessSDNCDelete")
259 String sdncRequestId = UUID.randomUUID().toString()
260 String sdncDeleteReq = buildSDNCRequest(execution, "delete", sdncRequestId)
261 execution.setVariable("sdncDeleteRequest", sdncDeleteReq)
262 logger.debug("sdncDeleteReq: " + sdncDeleteReq)
263 } catch (BpmnError e) {
265 } catch(Exception ex) {
266 msg = "Exception in preProcessSDNCDelete. " + ex.getMessage()
268 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
270 logger.trace("end preProcessSDNCDelete")
273 public void preProcessSDNCDeactivate(DelegateExecution execution) {
276 logger.trace("start preProcessSDNCDeactivate")
279 String sdncRequestId = UUID.randomUUID().toString()
280 String sdncDeactivateReq = buildSDNCRequest(execution, "deactivate", sdncRequestId)
281 execution.setVariable("sdncDeactivateRequest", sdncDeactivateReq)
282 logger.debug("sdncDeactivateReq: " + sdncDeactivateReq)
283 } catch (BpmnError e) {
285 } catch(Exception ex) {
286 msg = "Exception in preProcessSDNCDeactivate. " + ex.getMessage()
288 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
290 logger.trace("end preProcessSDNCDeactivate")
293 public void validateSDNCResp(DelegateExecution execution, String response, String method){
295 logger.trace("start ValidateSDNCResponse Process")
299 WorkflowException workflowException = execution.getVariable("WorkflowException")
300 logger.debug("workflowException: " + workflowException)
302 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
303 logger.debug("SDNCResponse: " + response)
305 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
306 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
308 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
309 logger.debug("Received a Good Response from SDNC Adapter for " + method + " SDNC Call. Response is: \n"
312 String sdncRespCode = execution.getVariable(Prefix + 'sdncRequestDataResponseCode')
313 logger.debug(method + " AllottedResource received error response from SDNC. ResponseCode:"
315 if (sdncRespCode.equals("404") && "deactivate".equals(method))
317 execution.setVariable("ARNotFoundInSDNC", true)
318 if ("true".equals(execution.getVariable("failNotFound")))
320 msg = "Allotted Resource Not found in SDNC"
322 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
326 execution.setVariable("wasDeleted", false)
331 throw new BpmnError("MSOWorkflowException")
334 } catch (BpmnError e) {
336 } catch(Exception ex) {
337 msg = "Exception in validateSDNCResp. " + ex.getMessage()
339 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
341 logger.trace("end ValidateSDNCResp Process")
344 public void deleteAaiAR(DelegateExecution execution){
345 logger.trace("start deleteAaiAR")
348 AllottedResourceUtils arUtils = new AllottedResourceUtils(this)
349 String arLink = execution.getVariable("aaiARPath")
350 arUtils.deleteAR(execution, arLink)
351 } catch (BpmnError e) {
353 }catch(Exception ex){
354 logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
355 "Exception Occurred Processing preProcessSDNCGetRequest." + ex, "BPMN",
356 MsoLogger.ErrorCode.UnknownError.getValue(), "Exception is:" + ex);
357 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during SDNC GET Method:\n" + ex.getMessage())
359 logger.trace("end deleteAaiAR")
362 public AllottedResourceUtils getAllottedResourceUtils(){
363 return new AllottedResourceUtils(this)