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.camunda.bpm.engine.delegate.BpmnError
24 import org.camunda.bpm.engine.delegate.DelegateExecution
25 import org.onap.so.bpmn.common.scripts.AllottedResourceUtils
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.AbstractServiceTaskProcessor
29 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
30 import org.onap.so.bpmn.core.UrnPropertiesReader
31 import org.onap.so.bpmn.core.WorkflowException
32 import org.onap.so.logger.MessageEnum
33 import org.onap.so.logger.MsoLogger
35 import static org.apache.commons.lang3.StringUtils.isBlank
38 * This groovy class supports the <class>DoDeleteAllottedResourceBRG.bpmn</class> process.
43 * @param - msoRequestId
44 * @param - isDebugLogEnabled
45 * @param - disableRollback - O ignored
46 * @param - failNotfound - O
47 * @param - serviceInstanceId
48 * @param - globalCustomerId - O
49 * @param - subscriptionServiceType - O
50 * @param - parentServiceInstanceId
51 * @param - allottedResourceId
54 * @param - rollbackData - N/A
55 * @param - rolledBack - true if no deletions performed
56 * @param - WorkflowException - O
57 * @param - wasDeleted - O (ie not silentSuccess)
60 public class DoDeleteAllottedResourceBRG extends AbstractServiceTaskProcessor{
61 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoDeleteAllottedResourceBRG.class);
63 String Prefix="DDARBRG_"
64 ExceptionUtil exceptionUtil = new ExceptionUtil()
66 public void preProcessRequest (DelegateExecution execution) {
69 msoLogger.trace("start preProcessRequest")
72 execution.setVariable("prefix", Prefix)
75 String sdncCallbackUrl = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
76 if (isBlank(sdncCallbackUrl)) {
77 msg = "mso.workflow.sdncadapter.callback is null"
79 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
81 execution.setVariable("sdncCallbackUrl", sdncCallbackUrl)
82 msoLogger.debug("SDNC Callback URL: " + sdncCallbackUrl)
85 if (isBlank(execution.getVariable("serviceInstanceId"))){
86 msg = "Input serviceInstanceId is null"
88 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
90 if (isBlank(execution.getVariable("allottedResourceId"))){
91 msg = "Input allottedResourceId is null"
93 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
97 msoLogger.debug("Rethrowing MSOWorkflowException")
99 } catch (Exception ex){
100 msg = "Exception in preProcessRequest " + ex.getMessage()
102 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
104 msoLogger.trace("end preProcessRequest")
107 public void getAaiAR (DelegateExecution execution) {
109 msoLogger.trace("start getAaiAR end")
111 String allottedResourceId = execution.getVariable("allottedResourceId")
113 AllottedResourceUtils arUtils = getAllottedResourceUtils()
114 boolean ifExistsAR = arUtils.ifExistsAR(execution, allottedResourceId)
118 String aaiARPath = execution.getVariable("aaiARPath")
119 String parentServiceInstanceId = arUtils.getPSIFmARLink(execution, aaiARPath)
120 execution.setVariable("parentServiceInstanceId", parentServiceInstanceId)
123 errorMsg = "Allotted resource not found in AAI with AllottedResourceId:" + allottedResourceId
125 if (!isBlank(errorMsg)) {
126 msoLogger.debug(errorMsg)
127 exceptionUtil.buildAndThrowWorkflowException(execution, 500, errorMsg)
129 msoLogger.trace("end getAaiAR")
133 // aaiARPath set during query (existing AR)
134 public void updateAaiAROrchStatus(DelegateExecution execution, String status){
135 msoLogger.trace("start updateAaiAROrchStatus")
136 AllottedResourceUtils arUtils = new AllottedResourceUtils(this)
137 String aaiARPath = execution.getVariable("aaiARPath") //set during query (existing AR)
138 String orchStatus = arUtils.updateAROrchStatus(execution, status, aaiARPath)
139 msoLogger.trace("end updateAaiAROrchStatus")
142 public String buildSDNCRequest(DelegateExecution execution, String action, String sdncRequestId) {
145 msoLogger.trace("start buildSDNCRequest")
146 String sdncReq = null
150 String allottedResourceId = execution.getVariable("allottedResourceId")
151 String serviceInstanceId = execution.getVariable("serviceInstanceId")
152 String parentServiceInstanceId = execution.getVariable("parentServiceInstanceId")
153 String globalCustomerId = execution.getVariable("globalCustomerId")
154 String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
156 String callbackUrl = execution.getVariable("sdncCallbackUrl")
157 String requestId = execution.getVariable("msoRequestId")
159 String serviceChainServiceInstanceId = ""
160 String sourceNetworkId = ""
161 String sourceNetworkRole = ""
162 String allottedResourceRole = ""
164 String arModelInfo = ""
165 String modelInvariantId = ""
166 String modelVersion = ""
167 String modelUUId = ""
168 String modelCustomizationId = ""
169 String modelName = ""
173 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
174 xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
175 xmlns:sdncadapter="http://org.onap/workflow/sdnc/adapter/schema/v1">
176 <sdncadapter:RequestHeader>
177 <sdncadapter:RequestId>${MsoUtils.xmlEscape(sdncRequestId)}</sdncadapter:RequestId>
178 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(serviceInstanceId)}</sdncadapter:SvcInstanceId>
179 <sdncadapter:SvcAction>${MsoUtils.xmlEscape(action)}</sdncadapter:SvcAction>
180 <sdncadapter:SvcOperation>brg-topology-operation</sdncadapter:SvcOperation>
181 <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackUrl)}</sdncadapter:CallbackUrl>
182 </sdncadapter:RequestHeader>
183 <sdncadapterworkflow:SDNCRequestData>
184 <request-information>
185 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
186 <request-action>DeleteBRGInstance</request-action>
191 </request-information>
192 <service-information>
193 <service-id></service-id>
194 <subscription-service-type>${MsoUtils.xmlEscape(subscriptionServiceType)}</subscription-service-type>
195 <onap-model-information></onap-model-information>
196 <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceId)}</service-instance-id>
198 <global-customer-id>${MsoUtils.xmlEscape(globalCustomerId)}</global-customer-id>
199 </service-information>
200 <allotted-resource-information>
201 <allotted-resource-id>${MsoUtils.xmlEscape(allottedResourceId)}</allotted-resource-id>
202 <allotted-resource-type>brg</allotted-resource-type>
203 <parent-service-instance-id>${MsoUtils.xmlEscape(parentServiceInstanceId)}</parent-service-instance-id>
204 <onap-model-information>
205 <model-invariant-uuid>${MsoUtils.xmlEscape(modelInvariantId)}</model-invariant-uuid>
206 <model-uuid>${MsoUtils.xmlEscape(modelUUId)}</model-uuid>
207 <model-customization-uuid>${MsoUtils.xmlEscape(modelCustomizationId)}</model-customization-uuid>
208 <model-version>${MsoUtils.xmlEscape(modelVersion)}</model-version>
209 <model-name>${MsoUtils.xmlEscape(modelName)}</model-name>
210 </onap-model-information>
211 </allotted-resource-information>
214 </sdncadapterworkflow:SDNCRequestData>
215 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
217 msoLogger.debug("sdncRequest:\n" + sdncReq)
218 sdncReq = utils.formatXml(sdncReq)
220 } catch(Exception ex) {
221 msg = "Exception in buildSDNCRequest. " + ex.getMessage()
223 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
225 msoLogger.trace("end buildSDNCRequest")
229 public void preProcessSDNCUnassign(DelegateExecution execution) {
232 msoLogger.trace("start preProcessSDNCUnassign")
235 String sdncRequestId = UUID.randomUUID().toString()
236 String sdncUnassignReq = buildSDNCRequest(execution, "unassign", sdncRequestId)
237 execution.setVariable("sdncUnassignRequest", sdncUnassignReq)
238 msoLogger.debug("sdncUnassignRequest: " + sdncUnassignReq)
239 } catch (BpmnError e) {
241 } catch(Exception ex) {
242 msg = "Exception in preProcessSDNCUnassign. " + ex.getMessage()
244 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
246 msoLogger.trace("end preProcessSDNCUnassign")
249 public void preProcessSDNCDelete(DelegateExecution execution) {
252 msoLogger.trace("start preProcessSDNCDelete")
255 String sdncRequestId = UUID.randomUUID().toString()
256 String sdncDeleteReq = buildSDNCRequest(execution, "delete", sdncRequestId)
257 execution.setVariable("sdncDeleteRequest", sdncDeleteReq)
258 msoLogger.debug("sdncDeleteReq: " + sdncDeleteReq)
259 } catch (BpmnError e) {
261 } catch(Exception ex) {
262 msg = "Exception in preProcessSDNCDelete. " + ex.getMessage()
264 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
266 msoLogger.trace("end preProcessSDNCDelete")
269 public void preProcessSDNCDeactivate(DelegateExecution execution) {
272 msoLogger.trace("start preProcessSDNCDeactivate")
275 String sdncRequestId = UUID.randomUUID().toString()
276 String sdncDeactivateReq = buildSDNCRequest(execution, "deactivate", sdncRequestId)
277 execution.setVariable("sdncDeactivateRequest", sdncDeactivateReq)
278 msoLogger.debug("sdncDeactivateReq: " + sdncDeactivateReq)
279 } catch (BpmnError e) {
281 } catch(Exception ex) {
282 msg = "Exception in preProcessSDNCDeactivate. " + ex.getMessage()
284 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
286 msoLogger.trace("end preProcessSDNCDeactivate")
289 public void validateSDNCResp(DelegateExecution execution, String response, String method){
291 msoLogger.trace("start ValidateSDNCResponse Process")
295 WorkflowException workflowException = execution.getVariable("WorkflowException")
296 msoLogger.debug("workflowException: " + workflowException)
298 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
299 msoLogger.debug("SDNCResponse: " + response)
301 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
302 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
304 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
305 msoLogger.debug("Received a Good Response from SDNC Adapter for " + method + " SDNC Call. Response is: \n" + response)
308 String sdncRespCode = execution.getVariable(Prefix + 'sdncRequestDataResponseCode')
309 msoLogger.debug(method + " AllottedResource received error response from SDNC. ResponseCode:" + sdncRespCode)
310 if (sdncRespCode.equals("404") && "deactivate".equals(method))
312 execution.setVariable("ARNotFoundInSDNC", true)
313 if ("true".equals(execution.getVariable("failNotFound")))
315 msg = "Allotted Resource Not found in SDNC"
317 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
321 execution.setVariable("wasDeleted", false)
326 throw new BpmnError("MSOWorkflowException")
329 } catch (BpmnError e) {
331 } catch(Exception ex) {
332 msg = "Exception in validateSDNCResp. " + ex.getMessage()
334 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
336 msoLogger.trace("end ValidateSDNCResp Process")
339 public void deleteAaiAR(DelegateExecution execution){
340 msoLogger.trace("start deleteAaiAR")
343 AllottedResourceUtils arUtils = new AllottedResourceUtils(this)
344 String arLink = execution.getVariable("aaiARPath")
345 arUtils.deleteAR(execution, arLink)
346 } catch (BpmnError e) {
348 }catch(Exception ex){
349 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occurred Processing preProcessSDNCGetRequest." + ex, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:" + ex);
350 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during SDNC GET Method:\n" + ex.getMessage())
352 msoLogger.trace("end deleteAaiAR")
355 public AllottedResourceUtils getAllottedResourceUtils(){
356 return new AllottedResourceUtils(this)