2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. 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.vcpe.scripts;
23 import org.onap.so.bpmn.common.scripts.*;
24 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
25 import org.onap.so.bpmn.core.WorkflowException
26 import org.onap.so.bpmn.common.scripts.ExceptionUtil
27 import org.onap.so.bpmn.common.scripts.MsoUtils
28 import org.onap.so.bpmn.common.scripts.AaiUtil
29 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
30 import org.onap.so.rest.APIResponse
32 import java.util.UUID;
33 import org.camunda.bpm.engine.delegate.BpmnError
34 import org.camunda.bpm.engine.delegate.DelegateExecution
35 import org.apache.commons.lang3.*
36 import org.springframework.web.util.UriUtils;
37 import static org.apache.commons.lang3.StringUtils.*
38 import org.onap.so.bpmn.core.UrnPropertiesReader;
40 import org.onap.so.logger.MessageEnum
41 import org.onap.so.logger.MsoLogger
44 * This groovy class supports the <class>DoDeleteAllottedResourceBRG.bpmn</class> process.
49 * @param - msoRequestId
50 * @param - isDebugLogEnabled
51 * @param - disableRollback - O ignored
52 * @param - failNotfound - O
53 * @param - serviceInstanceId
54 * @param - globalCustomerId - O
55 * @param - subscriptionServiceType - O
56 * @param - parentServiceInstanceId
57 * @param - allottedResourceId
60 * @param - rollbackData - N/A
61 * @param - rolledBack - true if no deletions performed
62 * @param - WorkflowException - O
63 * @param - wasDeleted - O (ie not silentSuccess)
66 public class DoDeleteAllottedResourceBRG extends AbstractServiceTaskProcessor{
67 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoDeleteAllottedResourceBRG.class);
69 String Prefix="DDARBRG_"
70 ExceptionUtil exceptionUtil = new ExceptionUtil()
72 public void preProcessRequest (DelegateExecution execution) {
75 msoLogger.trace("start preProcessRequest")
78 execution.setVariable("prefix", Prefix)
81 String sdncCallbackUrl = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
82 if (isBlank(sdncCallbackUrl)) {
83 msg = "mso.workflow.sdncadapter.callback is null"
85 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
87 execution.setVariable("sdncCallbackUrl", sdncCallbackUrl)
88 msoLogger.debug("SDNC Callback URL: " + sdncCallbackUrl)
91 if (isBlank(execution.getVariable("serviceInstanceId"))){
92 msg = "Input serviceInstanceId is null"
94 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
96 if (isBlank(execution.getVariable("allottedResourceId"))){
97 msg = "Input allottedResourceId is null"
99 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
103 msoLogger.debug("Rethrowing MSOWorkflowException")
105 } catch (Exception ex){
106 msg = "Exception in preProcessRequest " + ex.getMessage()
108 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
110 msoLogger.trace("end preProcessRequest")
113 public void getAaiAR (DelegateExecution execution) {
115 msoLogger.trace("start getAaiAR end")
117 String allottedResourceId = execution.getVariable("allottedResourceId")
119 AllottedResourceUtils arUtils = new AllottedResourceUtils(this)
120 String ar = arUtils.getARbyId(execution, allottedResourceId)
123 if (isBlank(ar)) // AR was !found
125 errorMsg = "Allotted resource not found in AAI with AllottedResourceId:" + allottedResourceId
129 String aaiARPath = execution.getVariable("aaiARPath")
130 String parentServiceInstanceId = arUtils.getPSIFmARLink(execution, aaiARPath)
131 execution.setVariable("parentServiceInstanceId", parentServiceInstanceId)
133 if (!isBlank(errorMsg)) {
134 msoLogger.debug(errorMsg)
135 exceptionUtil.buildAndThrowWorkflowException(execution, 500, errorMsg)
137 msoLogger.trace("end getAaiAR")
141 // aaiARPath set during query (existing AR)
142 public void updateAaiAROrchStatus(DelegateExecution execution, String status){
143 msoLogger.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 msoLogger.trace("end updateAaiAROrchStatus")
150 public String buildSDNCRequest(DelegateExecution execution, String action, String sdncRequestId) {
153 msoLogger.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>brg-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>DeleteBRGInstance</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>brg</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>
222 </sdncadapterworkflow:SDNCRequestData>
223 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
225 msoLogger.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 msoLogger.trace("end buildSDNCRequest")
237 public void preProcessSDNCUnassign(DelegateExecution execution) {
240 msoLogger.trace("start preProcessSDNCUnassign")
243 String sdncRequestId = UUID.randomUUID().toString()
244 String sdncUnassignReq = buildSDNCRequest(execution, "unassign", sdncRequestId)
245 execution.setVariable("sdncUnassignRequest", sdncUnassignReq)
246 msoLogger.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 msoLogger.trace("end preProcessSDNCUnassign")
257 public void preProcessSDNCDelete(DelegateExecution execution) {
260 msoLogger.trace("start preProcessSDNCDelete")
263 String sdncRequestId = UUID.randomUUID().toString()
264 String sdncDeleteReq = buildSDNCRequest(execution, "delete", sdncRequestId)
265 execution.setVariable("sdncDeleteRequest", sdncDeleteReq)
266 msoLogger.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 msoLogger.trace("end preProcessSDNCDelete")
277 public void preProcessSDNCDeactivate(DelegateExecution execution) {
280 msoLogger.trace("start preProcessSDNCDeactivate")
283 String sdncRequestId = UUID.randomUUID().toString()
284 String sdncDeactivateReq = buildSDNCRequest(execution, "deactivate", sdncRequestId)
285 execution.setVariable("sdncDeactivateRequest", sdncDeactivateReq)
286 msoLogger.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 msoLogger.trace("end preProcessSDNCDeactivate")
297 public void validateSDNCResp(DelegateExecution execution, String response, String method){
299 msoLogger.trace("start ValidateSDNCResponse Process")
303 WorkflowException workflowException = execution.getVariable("WorkflowException")
304 msoLogger.debug("workflowException: " + workflowException)
306 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
307 msoLogger.debug("SDNCResponse: " + response)
309 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
310 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
312 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
313 msoLogger.debug("Received a Good Response from SDNC Adapter for " + method + " SDNC Call. Response is: \n" + response)
316 String sdncRespCode = execution.getVariable(Prefix + 'sdncRequestDataResponseCode')
317 msoLogger.debug(method + " AllottedResource received error response from SDNC. ResponseCode:" + sdncRespCode)
318 if (sdncRespCode.equals("404") && "deactivate".equals(method))
320 execution.setVariable("ARNotFoundInSDNC", true)
321 if ("true".equals(execution.getVariable("failNotFound")))
323 msg = "Allotted Resource Not found in SDNC"
325 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
329 execution.setVariable("wasDeleted", false)
334 throw new BpmnError("MSOWorkflowException")
337 } catch (BpmnError e) {
339 } catch(Exception ex) {
340 msg = "Exception in validateSDNCResp. " + ex.getMessage()
342 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
344 msoLogger.trace("end ValidateSDNCResp Process")
347 public void deleteAaiAR(DelegateExecution execution){
348 msoLogger.trace("start deleteAaiAR")
351 AllottedResourceUtils arUtils = new AllottedResourceUtils(this)
352 String ar = null //need to get resource-version again
353 String arLink = execution.getVariable("aaiARPath")
354 if (!isBlank(arLink))
356 ar = arUtils.getARbyLink(execution, arLink, "")
358 arUtils.deleteAR(execution, arLink + '?resource-version=' + UriUtils.encode(execution.getVariable("aaiARResourceVersion"),"UTF-8"))
359 } catch (BpmnError e) {
361 }catch(Exception ex){
362 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occurred Processing preProcessSDNCGetRequest." + ex, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:" + ex);
363 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during SDNC GET Method:\n" + ex.getMessage())
365 msoLogger.trace("end deleteAaiAR")