2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Huawei Technologies Co., Ltd. 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.infrastructure.scripts
23 import org.onap.so.logger.MsoLogger
25 import static org.apache.commons.lang3.StringUtils.*;
27 import org.apache.commons.lang3.*
28 import org.camunda.bpm.engine.delegate.BpmnError
29 import org.camunda.bpm.engine.delegate.DelegateExecution
30 import org.onap.so.bpmn.common.recipe.ResourceInput;
31 import org.onap.so.bpmn.common.resource.ResourceRequestBuilder
32 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
33 import org.onap.so.bpmn.common.scripts.ExceptionUtil
34 import org.onap.so.bpmn.common.scripts.MsoUtils
35 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
36 import org.onap.so.bpmn.core.json.JsonUtils
41 * This groovy class supports the <class>DeleteSDNCCNetworkResource.bpmn</class> process.
42 * flow for SDNC Network Resource
44 public class DeleteSDNCNetworkResource extends AbstractServiceTaskProcessor {
45 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL,
46 CreateSDNCNetworkResource.class);
48 String Prefix="DELSDNCRES_"
50 ExceptionUtil exceptionUtil = new ExceptionUtil()
52 JsonUtils jsonUtil = new JsonUtils()
54 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils()
56 public void preProcessRequest(DelegateExecution execution){
57 msoLogger.info("***** Started preProcessRequest *****")
60 //get bpmn inputs from resource request.
61 String requestId = execution.getVariable("mso-request-id")
62 String requestAction = execution.getVariable("requestAction")
63 msoLogger.info("The requestAction is: " + requestAction)
64 String recipeParamsFromRequest = execution.getVariable("recipeParams")
65 msoLogger.info("The recipeParams is: " + recipeParamsFromRequest)
66 String resourceInput = execution.getVariable("resourceInput")
67 msoLogger.info("The resourceInput is: " + resourceInput)
68 //Get ResourceInput Object
69 ResourceInput resourceInputObj = ResourceRequestBuilder.getJsonObject(resourceInput, ResourceInput.class)
70 execution.setVariable(Prefix + "resourceInput", resourceInputObj)
72 //Deal with recipeParams
73 String recipeParamsFromWf = execution.getVariable("recipeParamXsd")
74 String resourceModelName = resourceInputObj.getResourceModelInfo().getModelName()
75 //For sdnc requestAction default is "NetworkInstance"
76 String operationType = "Network"
77 if(!StringUtils.isBlank(recipeParamsFromRequest) && "null" != recipeParamsFromRequest){
78 //the operationType from worflow(first node) is second priority.
79 operationType = jsonUtil.getJsonValue(recipeParamsFromRequest, "operationType")
81 if(!StringUtils.isBlank(recipeParamsFromWf)){
82 //the operationType from worflow(first node) is highest priority.
83 operationType = jsonUtil.getJsonValue(recipeParamsFromWf, "operationType")
87 //For sdnc, generate svc_action and request_action
88 String sdnc_svcAction = "delete"
89 if(StringUtils.containsIgnoreCase(resourceModelName, "overlay")){
90 //This will be resolved in R3.
91 sdnc_svcAction ="deactivate"
92 operationType = "NCINetwork"
94 if(StringUtils.containsIgnoreCase(resourceModelName, "underlay")){
95 //This will be resolved in R3.
96 operationType ="Network"
98 String sdnc_requestAction = StringUtils.capitalize(sdnc_svcAction) + operationType +"Instance"
99 execution.setVariable(Prefix + "svcAction", sdnc_svcAction)
100 execution.setVariable(Prefix + "requestAction", sdnc_requestAction)
101 execution.setVariable(Prefix + "serviceInstanceId", resourceInputObj.getServiceInstanceId())
102 execution.setVariable("mso-request-id", requestId)
103 execution.setVariable("mso-service-instance-id", resourceInputObj.getServiceInstanceId())
104 //TODO Here build networkrequest
106 } catch (BpmnError e) {
108 } catch (Exception ex){
109 msg = "Exception in preProcessRequest " + ex.getMessage()
111 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
116 * Pre Process the BPMN Flow Request
118 * generate the nsOperationKey
119 * generate the nsParameters
121 public void prepareSDNCRequest (DelegateExecution execution) {
122 msoLogger.info("***** Started prepareSDNCRequest *****")
126 String sdnc_svcAction = execution.getVariable(Prefix + "svcAction")
127 String sdnc_requestAction = execution.getVariable(Prefix + "requestAction")
128 String sdncCallback = execution.getVariable("URN_mso_workflow_sdncadapter_callback")
129 String deleteNetworkInput = execution.getVariable(Prefix + "networkRequest")
131 String hdrRequestId = execution.getVariable("mso-request-id")
132 String serviceInstanceId = execution.getVariable(Prefix + "serviceInstanceId")
133 String source = execution.getVariable("source")
134 String sdnc_service_id = execution.getVariable(Prefix + "sdncServiceId")
135 ResourceInput resourceInputObj = execution.getVariable(Prefix + "resourceInput")
136 String serviceType = resourceInputObj.getServiceType()
137 String serviceModelInvariantUuid = resourceInputObj.getServiceModelInfo().getModelInvariantUuid()
138 String serviceModelUuid = resourceInputObj.getServiceModelInfo().getModelUuid()
139 String serviceModelVersion = resourceInputObj.getServiceModelInfo().getModelVersion()
140 String serviceModelName = resourceInputObj.getServiceModelInfo().getModelName()
141 String globalCustomerId = resourceInputObj.getGlobalSubscriberId()
142 String modelInvariantUuid = resourceInputObj.getResourceModelInfo().getModelInvariantUuid();
143 String modelCustomizationUuid = resourceInputObj.getResourceModelInfo().getModelCustomizationUuid()
144 String modelUuid = resourceInputObj.getResourceModelInfo().getModelUuid()
145 String modelName = resourceInputObj.getResourceModelInfo().getModelName()
146 String modelVersion = resourceInputObj.getResourceModelInfo().getModelVersion()
147 // 1. prepare assign topology via SDNC Adapter SUBFLOW call
148 String sndcTopologyDeleteRequest =
149 """<aetgt:SDNCAdapterWorkflowRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1"
150 xmlns:sdncadapter="http://org.onap.so/workflow/sdnc/adapter/schema/v1"
151 xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1">
152 <sdncadapter:RequestHeader>
153 <sdncadapter:RequestId>${MsoUtils.xmlEscape(hdrRequestId)}</sdncadapter:RequestId>
154 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(serviceInstanceId)}</sdncadapter:SvcInstanceId>
155 <sdncadapter:SvcAction>${MsoUtils.xmlEscape(sdnc_svcAction)}</sdncadapter:SvcAction>
156 <sdncadapter:SvcOperation>network-topology-operation</sdncadapter:SvcOperation>
157 <sdncadapter:CallbackUrl>sdncCallback</sdncadapter:CallbackUrl>
158 <sdncadapter:MsoAction>generic-resource</sdncadapter:MsoAction>
159 </sdncadapter:RequestHeader>
160 <sdncadapterworkflow:SDNCRequestData>
161 <request-information>
162 <request-id>${MsoUtils.xmlEscape(hdrRequestId)}</request-id>
163 <request-action>${MsoUtils.xmlEscape(sdnc_requestAction)}</request-action>
164 <source>${MsoUtils.xmlEscape(source)}</source>
165 <notification-url></notification-url>
166 <order-number></order-number>
167 <order-version></order-version>
168 </request-information>
169 <service-information>
170 <service-id>${MsoUtils.xmlEscape(serviceInstanceId)}</service-id>
171 <subscription-service-type>${MsoUtils.xmlEscape(serviceType)}</subscription-service-type>
172 <onap-model-information>
173 <model-invariant-uuid>${MsoUtils.xmlEscape(serviceModelInvariantUuid)}</model-invariant-uuid>
174 <model-uuid>${MsoUtils.xmlEscape(serviceModelUuid)}</model-uuid>
175 <model-version>${MsoUtils.xmlEscape(serviceModelVersion)}</model-version>
176 <model-name>${MsoUtils.xmlEscape(serviceModelName)}</model-name>
177 </onap-model-information>
178 <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceId)}</service-instance-id>
179 <global-customer-id>${MsoUtils.xmlEscape(globalCustomerId)}</global-customer-id>
180 </service-information>
181 <network-information>
182 <onap-model-information>
183 <model-invariant-uuid>${MsoUtils.xmlEscape(modelInvariantUuid)}</model-invariant-uuid>
184 <model-customization-uuid>${MsoUtils.xmlEscape(modelCustomizationUuid)}</model-customization-uuid>
185 <model-uuid>${MsoUtils.xmlEscape(modelUuid)}</model-uuid>
186 <model-version>${MsoUtils.xmlEscape(modelVersion)}</model-version>
187 <model-name>${MsoUtils.xmlEscape(modelName)}</model-name>
188 </onap-model-information>
189 </network-information>
190 <network-request-input>
191 <network-input-parameters></network-input-parameters>
192 </network-request-input>
193 </sdncadapterworkflow:SDNCRequestData>
194 </aetgt:SDNCAdapterWorkflowRequest>""".trim()
196 String sndcTopologyDeleteRequesAsString = utils.formatXml(sndcTopologyDeleteRequest)
197 utils.logAudit(sndcTopologyDeleteRequesAsString)
198 execution.setVariable("sdncAdapterWorkflowRequest", sndcTopologyDeleteRequesAsString)
199 msoLogger.info("sdncAdapterWorkflowRequest - " + "\n" + sndcTopologyDeleteRequesAsString)
201 } catch (Exception ex) {
202 String exceptionMessage = " Bpmn error encountered in DeleteSDNCCNetworkResource flow. prepareSDNCRequest() - " + ex.getMessage()
203 msoLogger.debug(exceptionMessage)
204 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
207 msoLogger.info(" ***** Exit prepareSDNCRequest *****")
210 private void setProgressUpdateVariables(DelegateExecution execution, String body) {
211 def dbAdapterEndpoint = execution.getVariable("URN_mso_adapters_openecomp_db_endpoint")
212 execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
213 execution.setVariable("CVFMI_updateResOperStatusRequest", body)
216 public void prepareUpdateBeforeDeleteSDNCResource(DelegateExecution execution) {
217 ResourceInput resourceInputObj = execution.getVariable(Prefix + "resourceInput")
218 String operType = resourceInputObj.getOperationType()
219 String resourceCustomizationUuid = resourceInputObj.getResourceModelInfo().getModelCustomizationUuid()
220 String serviceInstanceId = resourceInputObj.getServiceInstanceId()
221 String operationId = resourceInputObj.getOperationId()
222 String progress = "20"
223 String status = "processing"
224 String statusDescription = "SDCN resource delete invoked"
226 //String operationId = execution.getVariable("operationId")
229 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
230 xmlns:ns="http://org.onap.so/requestsdb">
233 <ns:updateResourceOperationStatus>
234 <operType>${MsoUtils.xmlEscape(operType)}</operType>
235 <operationId>${MsoUtils.xmlEscape(operationId)}</operationId>
236 <progress>${MsoUtils.xmlEscape(progress)}</progress>
237 <resourceTemplateUUID>${MsoUtils.xmlEscape(resourceCustomizationUuid)}</resourceTemplateUUID>
238 <serviceId>${MsoUtils.xmlEscape(serviceInstanceId)}</serviceId>
239 <status>${MsoUtils.xmlEscape(status)}</status>
240 <statusDescription>${MsoUtils.xmlEscape(statusDescription)}</statusDescription>
241 </ns:updateResourceOperationStatus>
243 </soapenv:Envelope>""";
245 setProgressUpdateVariables(execution, body)
249 public void prepareUpdateAfterDeleteSDNCResource(DelegateExecution execution) {
250 ResourceInput resourceInputObj = execution.getVariable(Prefix + "resourceInput")
251 String operType = resourceInputObj.getOperationType()
252 String resourceCustomizationUuid = resourceInputObj.getResourceModelInfo().getModelCustomizationUuid()
253 String serviceInstanceId = resourceInputObj.getServiceInstanceId()
254 String operationId = resourceInputObj.getOperationId()
255 String progress = "100"
256 String status = "finished"
257 String statusDescription = "SDCN resource delete completed"
259 //String operationId = execution.getVariable("operationId")
262 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
263 xmlns:ns="http://org.onap.so/requestsdb">
266 <ns:updateResourceOperationStatus>
267 <operType>${MsoUtils.xmlEscape(operType)}</operType>
268 <operationId>${MsoUtils.xmlEscape(operationId)}</operationId>
269 <progress>${MsoUtils.xmlEscape(progress)}</progress>
270 <resourceTemplateUUID>${MsoUtils.xmlEscape(resourceCustomizationUuid)}</resourceTemplateUUID>
271 <serviceId>${MsoUtils.xmlEscape(serviceInstanceId)}</serviceId>
272 <status>${MsoUtils.xmlEscape(status)}</status>
273 <statusDescription>${MsoUtils.xmlEscape(statusDescription)}</statusDescription>
274 </ns:updateResourceOperationStatus>
276 </soapenv:Envelope>""";
278 setProgressUpdateVariables(execution, body)
281 public void postDeleteSDNCCall(DelegateExecution execution){
282 msoLogger.info(" ***** Started prepareSDNCRequest *****")
283 String responseCode = execution.getVariable(Prefix + "sdncDeleteReturnCode")
284 String responseObj = execution.getVariable(Prefix + "SuccessIndicator")
286 msoLogger.info("response from sdnc, response code :" + responseCode + " response object :" + responseObj)
287 msoLogger.info(" ***** Exit prepareSDNCRequest *****")
290 public void sendSyncResponse (DelegateExecution execution) {
291 msoLogger.info(" *** sendSyncResponse *** ")
294 String operationStatus = "finished"
295 // RESTResponse for main flow
296 String resourceOperationResp = """{"operationStatus":"${operationStatus}"}""".trim()
297 utils.log("DEBUG", " sendSyncResponse to APIH:" + "\n" + resourceOperationResp, isDebugEnabled)
298 sendWorkflowResponse(execution, 202, resourceOperationResp)
299 execution.setVariable("sentSyncResponse", true)
301 } catch (Exception ex) {
302 String msg = "Exceptuion in sendSyncResponse:" + ex.getMessage()
304 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
306 msoLogger.info(" ***** Exit sendSyncResopnse *****")