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 preProcessAAIGET(DelegateExecution execution) {
268 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
271 public void postProcessAAIGET(DelegateExecution execution) {
272 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
273 utils.log("INFO"," ***** postProcessAAIGET ***** ", isDebugEnabled)
277 String serviceInstanceName = execution.getVariable("serviceInstanceName")
278 boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")
280 utils.log("INFO","Error getting Service-instance from AAI in postProcessAAIGET", + serviceInstanceName, isDebugEnabled)
281 WorkflowException workflowException = execution.getVariable("WorkflowException")
282 utils.logAudit("workflowException: " + workflowException)
283 if(workflowException != null){
284 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
288 msg = "Failure in postProcessAAIGET GENGS_SuccessIndicator:" + succInAAI
289 utils.log("INFO", msg, isDebugEnabled)
290 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
295 boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")
297 String aaiService = execution.getVariable("GENGS_service")
298 if (!isBlank(aaiService) && (utils.nodeExists(aaiService, "resource-version"))) {
299 execution.setVariable("serviceInstanceVersion", utils.getNodeText(aaiService, "resource-version"))
300 utils.log("INFO","Found Service-instance in AAI.serviceInstanceName:" + execution.getVariable("serviceInstanceName"), isDebugEnabled)
304 } catch (BpmnError e) {
306 } catch (Exception ex) {
307 msg = "Exception in DoUpdateE2EServiceInstance.postProcessAAIGET " + ex.getMessage()
308 utils.log("INFO", msg, isDebugEnabled)
309 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
311 utils.log("INFO"," *** Exit postProcessAAIGET *** ", isDebugEnabled)
314 public void preProcessAAIPUT(DelegateExecution execution) {
315 def method = getClass().getSimpleName() + '.preProcessRequest(' +'execution=' + execution.getId() +')'
316 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
317 utils.log("INFO","Entered " + method, isDebugEnabled)
319 utils.log("INFO"," ***** preProcessAAIPUT *****", isDebugEnabled)
322 String serviceInstanceVersion = execution.getVariable("serviceInstanceVersion")
323 //execution.setVariable("GENPS_serviceResourceVersion", serviceInstanceVersion)
325 //requestDetails.modelInfo.for AAI PUT servieInstanceData
326 //requestDetails.requestInfo. for AAI GET/PUT serviceInstanceData
327 String serviceInstanceName = execution.getVariable("serviceInstanceName")
328 String serviceInstanceId = execution.getVariable("serviceInstanceId")
329 //aai serviceType and Role can be setted as fixed value now.
330 String aaiServiceType = "E2E Service"
331 String aaiServiceRole = "E2E Service"
332 String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
333 String modelUuid = execution.getVariable("modelUuid")
336 AaiUtil aaiUriUtil = new AaiUtil(this)
337 utils.log("INFO","start create aai uri: " + aaiUriUtil, isDebugEnabled)
338 String aai_uri = aaiUriUtil.getBusinessCustomerUri(execution)
339 utils.log("INFO","aai_uri: " + aai_uri, isDebugEnabled)
340 String namespace = aaiUriUtil.getNamespaceFromUri(aai_uri)
341 utils.log("INFO","namespace: " + namespace, isDebugEnabled)
343 //update target model to aai
344 String serviceInstanceData =
345 """<service-instance xmlns=\"${namespace}\">
346 <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceId)}</service-instance-id>
347 <service-instance-name>${MsoUtils.xmlEscape(serviceInstanceName)}</service-instance-name>
348 <service-type>${MsoUtils.xmlEscape(aaiServiceType)}</service-type>
349 <service-role>${MsoUtils.xmlEscape(aaiServiceRole)}</service-role>
350 <resource-version>${MsoUtils.xmlEscape(serviceInstanceVersion)}</resource-version>
351 <model-invariant-id>${MsoUtils.xmlEscape(modelInvariantUuid)}</model-invariant-id>
352 <model-version-id>${MsoUtils.xmlEscape(modelUuid)}</model-version-id>
353 </service-instance>""".trim()
355 execution.setVariable("serviceInstanceData", serviceInstanceData)
356 utils.log("INFO","serviceInstanceData: " + serviceInstanceData, isDebugEnabled)
357 utils.logAudit(serviceInstanceData)
358 utils.log("INFO", " aai_uri " + aai_uri + " namespace:" + namespace, isDebugEnabled)
359 utils.log("INFO", " 'payload' to update Service Instance in AAI - " + "\n" + serviceInstanceData, isDebugEnabled)
361 utils.log("INFO", "Exited " + method, isDebugEnabled)
364 public void postProcessAAIPUT(DelegateExecution execution) {
365 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
366 utils.log("INFO"," ***** postProcessAAIPUT ***** ", isDebugEnabled)
369 String serviceInstanceId = execution.getVariable("serviceInstanceId")
370 boolean succInAAI = execution.getVariable("GENPS_SuccessIndicator")
372 utils.log("INFO","Error putting Service-instance in AAI", + serviceInstanceId, isDebugEnabled)
373 WorkflowException workflowException = execution.getVariable("WorkflowException")
374 utils.logAudit("workflowException: " + workflowException)
375 if(workflowException != null){
376 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
381 //start rollback set up
382 RollbackData rollbackData = new RollbackData()
383 def disableRollback = execution.getVariable("disableRollback")
384 rollbackData.put("SERVICEINSTANCE", "disableRollback", disableRollback.toString())
385 rollbackData.put("SERVICEINSTANCE", "rollbackAAI", "true")
386 rollbackData.put("SERVICEINSTANCE", "serviceInstanceId", serviceInstanceId)
387 rollbackData.put("SERVICEINSTANCE", "serviceType", execution.getVariable("serviceType"))
388 rollbackData.put("SERVICEINSTANCE", "globalSubscriberId", execution.getVariable("globalSubscriberId"))
389 execution.setVariable("rollbackData", rollbackData)
392 } catch (BpmnError e) {
394 } catch (Exception ex) {
395 msg = "Exception in DoCreateServiceInstance.postProcessAAIDEL. " + ex.getMessage()
396 utils.log("INFO", msg, isDebugEnabled)
397 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
399 utils.log("INFO"," *** Exit postProcessAAIPUT *** ", isDebugEnabled)
402 public void preProcessRollback (DelegateExecution execution) {
403 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
404 utils.log("INFO"," ***** preProcessRollback ***** ", isDebugEnabled)
407 Object workflowException = execution.getVariable("WorkflowException");
409 if (workflowException instanceof WorkflowException) {
410 utils.log("INFO", "Prev workflowException: " + workflowException.getErrorMessage(), isDebugEnabled)
411 execution.setVariable("prevWorkflowException", workflowException);
412 //execution.setVariable("WorkflowException", null);
414 } catch (BpmnError e) {
415 utils.log("INFO", "BPMN Error during preProcessRollback", isDebugEnabled)
416 } catch(Exception ex) {
417 String msg = "Exception in preProcessRollback. " + ex.getMessage()
418 utils.log("INFO", msg, isDebugEnabled)
420 utils.log("INFO"," *** Exit preProcessRollback *** ", isDebugEnabled)
423 public void postProcessRollback (DelegateExecution execution) {
424 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
425 utils.log("INFO"," ***** postProcessRollback ***** ", isDebugEnabled)
428 Object workflowException = execution.getVariable("prevWorkflowException");
429 if (workflowException instanceof WorkflowException) {
430 utils.log("INFO", "Setting prevException to WorkflowException: ", isDebugEnabled)
431 execution.setVariable("WorkflowException", workflowException);
433 execution.setVariable("rollbackData", null)
434 } catch (BpmnError b) {
435 utils.log("INFO", "BPMN Error during postProcessRollback", isDebugEnabled)
437 } catch(Exception ex) {
438 msg = "Exception in postProcessRollback. " + ex.getMessage()
439 utils.log("INFO", msg, isDebugEnabled)
441 utils.log("INFO"," *** Exit postProcessRollback *** ", isDebugEnabled)
445 public void postConfigRequest(execution){