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=========================================================
20 package org.onap.so.bpmn.infrastructure.scripts;
22 import static org.apache.commons.lang3.StringUtils.*;
24 import org.apache.commons.lang3.*
25 import org.camunda.bpm.engine.delegate.BpmnError
26 import org.camunda.bpm.engine.delegate.DelegateExecution
27 import org.onap.so.bpmn.common.scripts.AaiUtil
28 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
29 import org.onap.so.bpmn.common.scripts.ExceptionUtil
30 import org.onap.so.bpmn.common.scripts.MsoUtils
31 import org.onap.so.bpmn.core.RollbackData
32 import org.onap.so.bpmn.core.WorkflowException
33 import org.onap.so.bpmn.core.domain.Resource
34 import org.onap.so.bpmn.core.json.JsonUtils
35 import org.springframework.web.util.UriUtils;
41 * This groovy class supports the <class>DoUpdateE2EServiceInstance.bpmn</class> process.
44 * @param - msoRequestId
45 * @param - globalSubscriberId
46 * @param - serviceType
47 * @param - serviceInstanceId
48 * @param - serviceInstanceName
49 * @param - serviceModelInfo
50 * @param - productFamilyId
52 * @param - serviceDecomposition_Target
53 * @param - serviceDecomposition_Original
54 * @param - addResourceList
55 * @param - delResourceList
58 * @param - rollbackData (localRB->null)
59 * @param - rolledBack (no localRB->null, localRB F->false, localRB S->true)
60 * @param - WorkflowException
62 public class DoUpdateE2EServiceInstance extends AbstractServiceTaskProcessor {
64 String Prefix="DUPDSI_"
65 private static final String DebugFlag = "isDebugEnabled"
67 ExceptionUtil exceptionUtil = new ExceptionUtil()
68 JsonUtils jsonUtil = new JsonUtils()
70 public void preProcessRequest (DelegateExecution execution) {
71 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
72 utils.log("INFO"," ***** Enter DoUpdateE2EServiceInstance preProcessRequest *****", isDebugEnabled)
77 execution.setVariable("prefix", Prefix)
79 //for AAI GET & PUT & SDNC assignToplology
80 String globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId
81 utils.log("INFO"," ***** globalSubscriberId *****" + globalSubscriberId, isDebugEnabled)
83 //for AAI PUT & SDNC assignTopology
84 String serviceType = execution.getVariable("serviceType")
85 utils.log("INFO"," ***** serviceType *****" + serviceType, isDebugEnabled)
87 //for SDNC assignTopology
88 String productFamilyId = execution.getVariable("productFamilyId") //AAI productFamilyId
90 if (isBlank(globalSubscriberId)) {
91 msg = "Input globalSubscriberId is null"
92 utils.log("INFO", msg, isDebugEnabled)
93 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
96 if (isBlank(serviceType)) {
97 msg = "Input serviceType is null"
98 utils.log("INFO", msg, isDebugEnabled)
99 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
102 //Generated in parent for AAI
103 String serviceInstanceId = execution.getVariable("serviceInstanceId")
104 if (isBlank(serviceInstanceId)){
105 msg = "Input serviceInstanceId is null"
106 utils.log("INFO", msg, isDebugEnabled)
107 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
110 String serviceInstanceName = execution.getVariable("serviceInstanceName")
113 String uuiRequest = execution.getVariable("uuiRequest")
115 // target model Invariant uuid
116 String modelInvariantUuid = jsonUtil.getJsonValue(uuiRequest, "service.serviceInvariantUuid")
117 execution.setVariable("modelInvariantUuid", modelInvariantUuid)
118 utils.log("INFO", "modelInvariantUuid: " + modelInvariantUuid, isDebugEnabled)
121 String modelUuid = jsonUtil.getJsonValue(uuiRequest, "service.serviceUuid")
122 execution.setVariable("modelUuid", modelUuid)
124 utils.log("INFO","modelUuid: " + modelUuid, isDebugEnabled)
126 } catch (BpmnError e) {
128 } catch (Exception ex){
129 msg = "Exception in preProcessRequest " + ex.getMessage()
130 utils.log("INFO", msg, isDebugEnabled)
131 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
133 utils.log("INFO", "======== COMPLETED preProcessRequest Process ======== ", isDebugEnabled)
137 public void preInitResourcesOperStatus(DelegateExecution execution){
138 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
140 utils.log("INFO", " ======== STARTED preInitResourcesOperStatus Process ======== ", isDebugEnabled)
142 String serviceId = execution.getVariable("serviceInstanceId")
143 String operationId = execution.getVariable("operationId")
144 String operationType = execution.getVariable("operationType")
145 String resourceTemplateUUIDs = ""
146 String result = "processing"
147 String progress = "0"
149 String operationContent = "Prepare service updating"
150 utils.log("INFO", "Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId + " operationType:" + operationType, isDebugEnabled)
151 serviceId = UriUtils.encode(serviceId,"UTF-8")
152 execution.setVariable("serviceInstanceId", serviceId)
153 execution.setVariable("operationId", operationId)
154 execution.setVariable("operationType", operationType)
156 List<Resource> resourceList = new ArrayList<String>()
157 List<Resource> addResourceList = execution.getVariable("addResourceList")
158 List<Resource> delResourceList = execution.getVariable("delResourceList")
159 resourceList.addAll(addResourceList)
160 resourceList.addAll(delResourceList)
161 for(Resource resource : resourceList){
162 resourceTemplateUUIDs = resourceTemplateUUIDs + resource.getModelInfo().getModelCustomizationUuid() + ":"
165 def dbAdapterEndpoint = "http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter"
166 execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
167 utils.log("INFO", "DB Adapter Endpoint is: " + dbAdapterEndpoint, isDebugEnabled)
170 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
171 xmlns:ns="http://org.onap.so/requestsdb">
174 <ns:initResourceOperationStatus xmlns:ns="http://org.onap.so/requestsdb">
175 <serviceId>${MsoUtils.xmlEscape(serviceId)}</serviceId>
176 <operationId>${MsoUtils.xmlEscape(operationId)}</operationId>
177 <operationType>${MsoUtils.xmlEscape(operationType)}</operationType>
178 <resourceTemplateUUIDs>${MsoUtils.xmlEscape(resourceTemplateUUIDs)}</resourceTemplateUUIDs>
179 </ns:initResourceOperationStatus>
181 </soapenv:Envelope>"""
183 payload = utils.formatXml(payload)
184 execution.setVariable("CVFMI_initResOperStatusRequest", payload)
185 utils.log("INFO", "Outgoing initResourceOperationStatus: \n" + payload, isDebugEnabled)
186 utils.logAudit("CreateVfModuleInfra Outgoing initResourceOperationStatus Request: " + payload)
189 utils.log("ERROR", "Exception Occured Processing preInitResourcesOperStatus. Exception is:\n" + e, isDebugEnabled)
190 execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during preInitResourcesOperStatus Method:\n" + e.getMessage())
192 utils.log("INFO", "======== COMPLETED preInitResourcesOperStatus Process ======== ", isDebugEnabled)
196 public void preProcessForAddResource(DelegateExecution execution) {
197 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
198 utils.log("INFO"," ***** preProcessForAddResource ***** ", isDebugEnabled)
200 execution.setVariable("operationType", "create")
202 execution.setVariable("hasResourcetoAdd", false)
203 List<Resource> addResourceList = execution.getVariable("addResourceList")
204 if(addResourceList != null && !addResourceList.isEmpty()) {
205 execution.setVariable("hasResourcetoAdd", true)
208 utils.log("INFO"," *** Exit preProcessForAddResource *** ", isDebugEnabled)
211 public void postProcessForAddResource(DelegateExecution execution) {
212 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
213 utils.log("INFO"," ***** postProcessForAddResource ***** ", isDebugEnabled)
215 execution.setVariable("operationType", "update")
217 utils.log("INFO"," *** Exit postProcessForAddResource *** ", isDebugEnabled)
220 public void preProcessForDeleteResource(DelegateExecution execution) {
221 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
222 utils.log("INFO"," ***** preProcessForDeleteResource ***** ", isDebugEnabled)
224 execution.setVariable("operationType", "delete")
226 def hasResourcetoDelete = false
227 List<Resource> delResourceList = execution.getVariable("delResourceList")
228 if(delResourceList != null && !delResourceList.isEmpty()) {
229 hasResourcetoDelete = true
231 execution.setVariable("hasResourcetoDelete", hasResourcetoDelete)
233 if(hasResourcetoDelete) {
234 def jsonSlurper = new JsonSlurper()
235 String serviceRelationShip = execution.getVariable("serviceRelationShip")
236 List relationShipList = jsonSlurper.parseText(serviceRelationShip)
238 //Set the real resource instance id to the decomosed resource list
239 for(Resource resource: delResourceList){
240 //reset the resource instance id , because in the decompose flow ,its a random one.
241 resource.setResourceId("");
242 //match the resource-instance-name and the model name
243 if (relationShipList != null) {
244 relationShipList.each {
245 if(StringUtils.containsIgnoreCase(it.resourceType, resource.getModelInfo().getModelName())){
246 resource.setResourceId(it.resourceInstanceId);
253 execution.setVariable("deleteResourceList", delResourceList)
255 utils.log("INFO"," *** Exit preProcessForDeleteResource *** ", isDebugEnabled)
258 public void postProcessForDeleteResource(DelegateExecution execution) {
259 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
260 utils.log("INFO"," ***** postProcessForDeleteResource ***** ", isDebugEnabled)
262 execution.setVariable("operationType", "update")
264 utils.log("INFO"," *** Exit postProcessForDeleteResource *** ", isDebugEnabled)
267 public void preProcessAAIPUT(DelegateExecution execution) {
268 def method = getClass().getSimpleName() + '.preProcessRequest(' +'execution=' + execution.getId() +')'
269 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
270 utils.log("INFO","Entered " + method, isDebugEnabled)
272 utils.log("INFO"," ***** preProcessAAIPUT *****", isDebugEnabled)
275 String serviceInstanceVersion = execution.getVariable("serviceInstanceVersion")
276 //execution.setVariable("GENPS_serviceResourceVersion", serviceInstanceVersion)
278 //requestDetails.modelInfo.for AAI PUT servieInstanceData
279 //requestDetails.requestInfo. for AAI GET/PUT serviceInstanceData
280 String serviceInstanceName = execution.getVariable("serviceInstanceName")
281 String serviceInstanceId = execution.getVariable("serviceInstanceId")
282 //aai serviceType and Role can be setted as fixed value now.
283 String aaiServiceType = "E2E Service"
284 String aaiServiceRole = "E2E Service"
285 String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
286 String modelUuid = execution.getVariable("modelUuid")
289 AaiUtil aaiUriUtil = new AaiUtil(this)
290 utils.log("INFO","start create aai uri: " + aaiUriUtil, isDebugEnabled)
291 String aai_uri = aaiUriUtil.getBusinessCustomerUri(execution)
292 utils.log("INFO","aai_uri: " + aai_uri, isDebugEnabled)
293 String namespace = aaiUriUtil.getNamespaceFromUri(aai_uri)
294 utils.log("INFO","namespace: " + namespace, isDebugEnabled)
296 //update target model to aai
297 String serviceInstanceData =
298 """<service-instance xmlns=\"${namespace}\">
299 <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceId)}</service-instance-id>
300 <service-instance-name>${MsoUtils.xmlEscape(serviceInstanceName)}</service-instance-name>
301 <service-type>${MsoUtils.xmlEscape(aaiServiceType)}</service-type>
302 <service-role>${MsoUtils.xmlEscape(aaiServiceRole)}</service-role>
303 <resource-version>${MsoUtils.xmlEscape(serviceInstanceVersion)}</resource-version>
304 <model-invariant-id>${MsoUtils.xmlEscape(modelInvariantUuid)}</model-invariant-id>
305 <model-version-id>${MsoUtils.xmlEscape(modelUuid)}</model-version-id>
306 </service-instance>""".trim()
308 execution.setVariable("serviceInstanceData", serviceInstanceData)
309 utils.log("INFO","serviceInstanceData: " + serviceInstanceData, isDebugEnabled)
310 utils.logAudit(serviceInstanceData)
311 utils.log("INFO", " aai_uri " + aai_uri + " namespace:" + namespace, isDebugEnabled)
312 utils.log("INFO", " 'payload' to update Service Instance in AAI - " + "\n" + serviceInstanceData, isDebugEnabled)
314 utils.log("INFO", "Exited " + method, isDebugEnabled)
317 public void postProcessAAIPUT(DelegateExecution execution) {
318 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
319 utils.log("INFO"," ***** postProcessAAIPUT ***** ", isDebugEnabled)
322 String serviceInstanceId = execution.getVariable("serviceInstanceId")
323 boolean succInAAI = execution.getVariable("GENPS_SuccessIndicator")
325 utils.log("INFO","Error putting Service-instance in AAI", + serviceInstanceId, isDebugEnabled)
326 WorkflowException workflowException = execution.getVariable("WorkflowException")
327 utils.logAudit("workflowException: " + workflowException)
328 if(workflowException != null){
329 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
334 //start rollback set up
335 RollbackData rollbackData = new RollbackData()
336 def disableRollback = execution.getVariable("disableRollback")
337 rollbackData.put("SERVICEINSTANCE", "disableRollback", disableRollback.toString())
338 rollbackData.put("SERVICEINSTANCE", "rollbackAAI", "true")
339 rollbackData.put("SERVICEINSTANCE", "serviceInstanceId", serviceInstanceId)
340 rollbackData.put("SERVICEINSTANCE", "serviceType", execution.getVariable("serviceType"))
341 rollbackData.put("SERVICEINSTANCE", "globalSubscriberId", execution.getVariable("globalSubscriberId"))
342 execution.setVariable("rollbackData", rollbackData)
345 } catch (BpmnError e) {
347 } catch (Exception ex) {
348 msg = "Exception in DoCreateServiceInstance.postProcessAAIDEL. " + ex.getMessage()
349 utils.log("INFO", msg, isDebugEnabled)
350 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
352 utils.log("INFO"," *** Exit postProcessAAIPUT *** ", isDebugEnabled)
355 public void preProcessRollback (DelegateExecution execution) {
356 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
357 utils.log("INFO"," ***** preProcessRollback ***** ", isDebugEnabled)
360 Object workflowException = execution.getVariable("WorkflowException");
362 if (workflowException instanceof WorkflowException) {
363 utils.log("INFO", "Prev workflowException: " + workflowException.getErrorMessage(), isDebugEnabled)
364 execution.setVariable("prevWorkflowException", workflowException);
365 //execution.setVariable("WorkflowException", null);
367 } catch (BpmnError e) {
368 utils.log("INFO", "BPMN Error during preProcessRollback", isDebugEnabled)
369 } catch(Exception ex) {
370 String msg = "Exception in preProcessRollback. " + ex.getMessage()
371 utils.log("INFO", msg, isDebugEnabled)
373 utils.log("INFO"," *** Exit preProcessRollback *** ", isDebugEnabled)
376 public void postProcessRollback (DelegateExecution execution) {
377 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
378 utils.log("INFO"," ***** postProcessRollback ***** ", isDebugEnabled)
381 Object workflowException = execution.getVariable("prevWorkflowException");
382 if (workflowException instanceof WorkflowException) {
383 utils.log("INFO", "Setting prevException to WorkflowException: ", isDebugEnabled)
384 execution.setVariable("WorkflowException", workflowException);
386 execution.setVariable("rollbackData", null)
387 } catch (BpmnError b) {
388 utils.log("INFO", "BPMN Error during postProcessRollback", isDebugEnabled)
390 } catch(Exception ex) {
391 msg = "Exception in postProcessRollback. " + ex.getMessage()
392 utils.log("INFO", msg, isDebugEnabled)
394 utils.log("INFO"," *** Exit postProcessRollback *** ", isDebugEnabled)
398 public void postConfigRequest(execution){