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
34 import static org.apache.commons.lang3.StringUtils.isBlank
37 * This groovy class supports the <class>DoDeleteAllottedResourceTXC.bpmn</class> process.
42 * @param - msoRequestId
43 * @param - isDebugLogEnabled
44 * @param - disableRollback - O ignored
45 * @param - failNotfound - O
46 * @param - serviceInstanceId
47 * @param - globalCustomerId - O
48 * @param - subscriptionServiceType - O
49 * @param - parentServiceInstanceId
50 * @param - allottedResourceId
53 * @param - rollbackData - N/A
54 * @param - rolledBack - true if no deletions performed
55 * @param - WorkflowException - O
56 * @param - wasDeleted - O (ie not silentSuccess)
59 public class DoDeleteAllottedResourceTXC extends AbstractServiceTaskProcessor{
60 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoDeleteAllottedResourceTXC.class);
62 String Prefix="DDARTXC_"
63 ExceptionUtil exceptionUtil = new ExceptionUtil()
65 public void preProcessRequest (DelegateExecution execution) {
68 msoLogger.trace("start preProcessRequest")
71 execution.setVariable("prefix", Prefix)
74 String sdncCallbackUrl = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
75 if (isBlank(sdncCallbackUrl)) {
76 msg = "mso.workflow.sdncadapter.callback is null"
78 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
80 execution.setVariable("sdncCallbackUrl", sdncCallbackUrl)
81 msoLogger.debug("SDNC Callback URL: " + sdncCallbackUrl)
84 if (isBlank(execution.getVariable("serviceInstanceId"))){
85 msg = "Input serviceInstanceId is null"
87 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
89 if (isBlank(execution.getVariable("allottedResourceId"))){
90 msg = "Input allottedResourceId is null"
92 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
96 msoLogger.debug("Rethrowing MSOWorkflowException")
98 } catch (Exception ex){
99 msg = "Exception in preProcessRequest " + ex.getMessage()
101 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
103 msoLogger.trace("end preProcessRequest")
106 public void getAaiAR (DelegateExecution execution) {
108 msoLogger.trace("start getAaiAR")
110 String allottedResourceId = execution.getVariable("allottedResourceId")
112 AllottedResourceUtils arUtils = getAllottedResourceUtils()
113 boolean ifExistsAR = arUtils.ifExistsAR(execution, allottedResourceId)
117 String aaiARPath = execution.getVariable("aaiARPath")
118 String parentServiceInstanceId = arUtils.getPSIFmARLink(execution, aaiARPath)
119 execution.setVariable("parentServiceInstanceId", parentServiceInstanceId)
122 errorMsg = "Allotted resource not found in AAI with AllottedResourceId:" + allottedResourceId
124 if (!isBlank(errorMsg)) {
125 msoLogger.debug(errorMsg)
126 exceptionUtil.buildAndThrowWorkflowException(execution, 500, errorMsg)
128 msoLogger.trace("end getAaiAR")
132 public AllottedResourceUtils getAllottedResourceUtils(){
133 return new AllottedResourceUtils(this)
136 // aaiARPath set during query (existing AR)
137 public void updateAaiAROrchStatus(DelegateExecution execution, String status){
138 msoLogger.trace("start updateAaiAROrchStatus")
139 AllottedResourceUtils arUtils = new AllottedResourceUtils(this)
140 String aaiARPath = execution.getVariable("aaiARPath") //set during query (existing AR)
141 String orchStatus = arUtils.updateAROrchStatus(execution, status, aaiARPath)
142 msoLogger.trace("end updateAaiAROrchStatus")
145 public String buildSDNCRequest(DelegateExecution execution, String action, String sdncRequestId) {
148 msoLogger.trace("start buildSDNCRequest")
149 String sdncReq = null
153 String allottedResourceId = execution.getVariable("allottedResourceId")
154 String serviceInstanceId = execution.getVariable("serviceInstanceId")
155 String parentServiceInstanceId = execution.getVariable("parentServiceInstanceId")
156 String globalCustomerId = execution.getVariable("globalCustomerId")
157 String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
159 String callbackUrl = execution.getVariable("sdncCallbackUrl")
160 String requestId = execution.getVariable("msoRequestId")
162 String serviceChainServiceInstanceId = ""
163 String sourceNetworkId = ""
164 String sourceNetworkRole = ""
165 String allottedResourceRole = ""
167 String arModelInfo = ""
168 String modelInvariantId = ""
169 String modelVersion = ""
170 String modelUUId = ""
171 String modelCustomizationId = ""
172 String modelName = ""
176 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
177 xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
178 xmlns:sdncadapter="http://org.onap/workflow/sdnc/adapter/schema/v1">
179 <sdncadapter:RequestHeader>
180 <sdncadapter:RequestId>${MsoUtils.xmlEscape(sdncRequestId)}</sdncadapter:RequestId>
181 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(serviceInstanceId)}</sdncadapter:SvcInstanceId>
182 <sdncadapter:SvcAction>${MsoUtils.xmlEscape(action)}</sdncadapter:SvcAction>
183 <sdncadapter:SvcOperation>tunnelxconn-topology-operation</sdncadapter:SvcOperation>
184 <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackUrl)}</sdncadapter:CallbackUrl>
185 </sdncadapter:RequestHeader>
186 <sdncadapterworkflow:SDNCRequestData>
187 <request-information>
188 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
189 <request-action>DeleteTunnelXConnInstance</request-action>
194 </request-information>
195 <service-information>
196 <service-id></service-id>
197 <subscription-service-type>${MsoUtils.xmlEscape(subscriptionServiceType)}</subscription-service-type>
198 <onap-model-information></onap-model-information>
199 <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceId)}</service-instance-id>
201 <global-customer-id>${MsoUtils.xmlEscape(globalCustomerId)}</global-customer-id>
202 </service-information>
203 <allotted-resource-information>
204 <allotted-resource-id>${MsoUtils.xmlEscape(allottedResourceId)}</allotted-resource-id>
205 <allotted-resource-type>tunnelxconn</allotted-resource-type>
206 <parent-service-instance-id>${MsoUtils.xmlEscape(parentServiceInstanceId)}</parent-service-instance-id>
207 <onap-model-information>
208 <model-invariant-uuid>${MsoUtils.xmlEscape(modelInvariantId)}</model-invariant-uuid>
209 <model-uuid>${MsoUtils.xmlEscape(modelUUId)}</model-uuid>
210 <model-customization-uuid>${MsoUtils.xmlEscape(modelCustomizationId)}</model-customization-uuid>
211 <model-version>${MsoUtils.xmlEscape(modelVersion)}</model-version>
212 <model-name>${MsoUtils.xmlEscape(modelName)}</model-name>
213 </onap-model-information>
214 </allotted-resource-information>
215 <tunnelxconn-request-input>
216 </tunnelxconn-request-input>
217 </sdncadapterworkflow:SDNCRequestData>
218 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
220 msoLogger.debug("sdncRequest:\n" + sdncReq)
221 sdncReq = utils.formatXml(sdncReq)
223 } catch(Exception ex) {
224 msg = "Exception in buildSDNCRequest. " + ex.getMessage()
226 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
228 msoLogger.trace("end buildSDNCRequest")
232 public void preProcessSDNCUnassign(DelegateExecution execution) {
235 msoLogger.trace("start preProcessSDNCUnassign")
238 String sdncRequestId = UUID.randomUUID().toString()
239 String sdncUnassignReq = buildSDNCRequest(execution, "unassign", sdncRequestId)
240 execution.setVariable("sdncUnassignRequest", sdncUnassignReq)
241 msoLogger.debug("sdncUnassignRequest: " + sdncUnassignReq)
242 } catch (BpmnError e) {
244 } catch(Exception ex) {
245 msg = "Exception in preProcessSDNCUnassign. " + ex.getMessage()
247 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
249 msoLogger.trace("end preProcessSDNCUnassign")
252 public void preProcessSDNCDelete(DelegateExecution execution) {
255 msoLogger.trace("start preProcessSDNCDelete")
258 String sdncRequestId = UUID.randomUUID().toString()
259 String sdncDeleteReq = buildSDNCRequest(execution, "delete", sdncRequestId)
260 execution.setVariable("sdncDeleteRequest", sdncDeleteReq)
261 msoLogger.debug("sdncDeleteReq: " + sdncDeleteReq)
262 } catch (BpmnError e) {
264 } catch(Exception ex) {
265 msg = "Exception in preProcessSDNCDelete. " + ex.getMessage()
267 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
269 msoLogger.trace("end preProcessSDNCDelete")
272 public void preProcessSDNCDeactivate(DelegateExecution execution) {
275 msoLogger.trace("start preProcessSDNCDeactivate")
278 String sdncRequestId = UUID.randomUUID().toString()
279 String sdncDeactivateReq = buildSDNCRequest(execution, "deactivate", sdncRequestId)
280 execution.setVariable("sdncDeactivateRequest", sdncDeactivateReq)
281 msoLogger.debug("sdncDeactivateReq: " + sdncDeactivateReq)
282 } catch (BpmnError e) {
284 } catch(Exception ex) {
285 msg = "Exception in preProcessSDNCDeactivate. " + ex.getMessage()
287 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
289 msoLogger.trace("end preProcessSDNCDeactivate")
292 public void validateSDNCResp(DelegateExecution execution, String response, String method){
294 msoLogger.trace("start ValidateSDNCResponse Process")
298 WorkflowException workflowException = execution.getVariable("WorkflowException")
299 msoLogger.debug("workflowException: " + workflowException)
301 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
302 msoLogger.debug("SDNCResponse: " + response)
304 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
305 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
307 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
308 msoLogger.debug("Received a Good Response from SDNC Adapter for " + method + " SDNC Call. Response is: \n" + response)
311 String sdncRespCode = execution.getVariable(Prefix + 'sdncRequestDataResponseCode')
312 msoLogger.debug(method + " AllottedResource received error response from SDNC. ResponseCode:" + sdncRespCode)
313 if (sdncRespCode.equals("404") && "deactivate".equals(method))
315 execution.setVariable("ARNotFoundInSDNC", true)
316 if ("true".equals(execution.getVariable("failNotFound")))
318 msg = "Allotted Resource Not found in SDNC"
320 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
324 execution.setVariable("wasDeleted", false)
329 throw new BpmnError("MSOWorkflowException")
332 } catch (BpmnError e) {
334 } catch(Exception ex) {
335 msg = "Exception in validateSDNCResp. " + ex.getMessage()
337 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
339 msoLogger.trace("end Exit ValidateSDNCResp Process")
342 public void deleteAaiAR(DelegateExecution execution){
343 msoLogger.trace("start deleteAaiAR")
346 AllottedResourceUtils arUtils = new AllottedResourceUtils(this)
347 String arLink = execution.getVariable("aaiARPath")
348 arUtils.deleteAR(execution, arLink)
349 } catch (BpmnError e) {
351 }catch(Exception ex){
352 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occurred Processing preProcessSDNCGetRequest.", "BPMN", MsoLogger.getServiceName(),
353 MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + ex);
354 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during SDNC GET Method:\n" + ex.getMessage())
356 msoLogger.trace("end deleteAaiAR")