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
21 import org.onap.so.client.aai.AAIResourcesClient
22 import org.onap.so.client.aai.entities.uri.AAIResourceUri;
24 import static org.apache.commons.lang3.StringUtils.*;
26 import org.apache.commons.lang3.*
27 import org.camunda.bpm.engine.delegate.BpmnError
28 import org.camunda.bpm.engine.delegate.DelegateExecution
29 import org.onap.aai.domain.yang.ServiceInstance;
30 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
31 import org.onap.so.bpmn.common.scripts.ExceptionUtil
32 import org.onap.so.bpmn.common.scripts.MsoUtils
33 import org.onap.so.bpmn.core.RollbackData
34 import org.onap.so.bpmn.core.WorkflowException
35 import org.onap.so.bpmn.core.domain.Resource
36 import org.onap.so.bpmn.core.json.JsonUtils
37 import org.onap.so.client.aai.AAIObjectType
38 import org.onap.so.client.aai.AAIResourcesClient
39 import org.onap.so.client.aai.entities.AAIResultWrapper
40 import org.onap.so.client.aai.entities.uri.AAIResourceUri
41 import org.onap.so.client.aai.entities.uri.AAIUriFactory
42 import org.springframework.web.util.UriUtils;
48 * This groovy class supports the <class>DoUpdateE2EServiceInstance.bpmn</class> process.
51 * @param - msoRequestId
52 * @param - globalSubscriberId
53 * @param - serviceType
54 * @param - serviceInstanceId
55 * @param - serviceInstanceName
56 * @param - serviceModelInfo
57 * @param - productFamilyId
59 * @param - serviceDecomposition_Target
60 * @param - serviceDecomposition_Original
61 * @param - addResourceList
62 * @param - delResourceList
65 * @param - rollbackData (localRB->null)
66 * @param - rolledBack (no localRB->null, localRB F->false, localRB S->true)
67 * @param - WorkflowException
69 public class DoUpdateE2EServiceInstance extends AbstractServiceTaskProcessor {
71 String Prefix="DUPDSI_"
72 private static final String DebugFlag = "isDebugEnabled"
74 ExceptionUtil exceptionUtil = new ExceptionUtil()
75 JsonUtils jsonUtil = new JsonUtils()
77 public void preProcessRequest (DelegateExecution execution) {
78 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
79 utils.log("INFO"," ***** Enter DoUpdateE2EServiceInstance preProcessRequest *****", isDebugEnabled)
84 execution.setVariable("prefix", Prefix)
86 //for AAI GET & PUT & SDNC assignToplology
87 String globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId
88 utils.log("INFO"," ***** globalSubscriberId *****" + globalSubscriberId, isDebugEnabled)
90 //for AAI PUT & SDNC assignTopology
91 String serviceType = execution.getVariable("serviceType")
92 utils.log("INFO"," ***** serviceType *****" + serviceType, isDebugEnabled)
94 //for SDNC assignTopology
95 String productFamilyId = execution.getVariable("productFamilyId") //AAI productFamilyId
97 if (isBlank(globalSubscriberId)) {
98 msg = "Input globalSubscriberId is null"
99 utils.log("INFO", msg, isDebugEnabled)
100 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
103 if (isBlank(serviceType)) {
104 msg = "Input serviceType is null"
105 utils.log("INFO", msg, isDebugEnabled)
106 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
109 //Generated in parent for AAI
110 String serviceInstanceId = execution.getVariable("serviceInstanceId")
111 if (isBlank(serviceInstanceId)){
112 msg = "Input serviceInstanceId is null"
113 utils.log("INFO", msg, isDebugEnabled)
114 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
117 String serviceInstanceName = execution.getVariable("serviceInstanceName")
120 String uuiRequest = execution.getVariable("uuiRequest")
122 // target model Invariant uuid
123 String modelInvariantUuid = jsonUtil.getJsonValue(uuiRequest, "service.serviceInvariantUuid")
124 execution.setVariable("modelInvariantUuid", modelInvariantUuid)
125 utils.log("INFO", "modelInvariantUuid: " + modelInvariantUuid, isDebugEnabled)
128 String modelUuid = jsonUtil.getJsonValue(uuiRequest, "service.serviceUuid")
129 execution.setVariable("modelUuid", modelUuid)
131 utils.log("INFO","modelUuid: " + modelUuid, isDebugEnabled)
133 } catch (BpmnError e) {
135 } catch (Exception ex){
136 msg = "Exception in preProcessRequest " + ex.getMessage()
137 utils.log("INFO", msg, isDebugEnabled)
138 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
140 utils.log("INFO", "======== COMPLETED preProcessRequest Process ======== ", isDebugEnabled)
144 public void preInitResourcesOperStatus(DelegateExecution execution){
145 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
147 utils.log("INFO", " ======== STARTED preInitResourcesOperStatus Process ======== ", isDebugEnabled)
149 String serviceId = execution.getVariable("serviceInstanceId")
150 String operationId = execution.getVariable("operationId")
151 String operationType = execution.getVariable("operationType")
152 String resourceTemplateUUIDs = ""
153 String result = "processing"
154 String progress = "0"
156 String operationContent = "Prepare service updating"
157 utils.log("INFO", "Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId + " operationType:" + operationType, isDebugEnabled)
158 serviceId = UriUtils.encode(serviceId,"UTF-8")
159 execution.setVariable("serviceInstanceId", serviceId)
160 execution.setVariable("operationId", operationId)
161 execution.setVariable("operationType", operationType)
163 List<Resource> resourceList = new ArrayList<String>()
164 List<Resource> addResourceList = execution.getVariable("addResourceList")
165 List<Resource> delResourceList = execution.getVariable("delResourceList")
166 resourceList.addAll(addResourceList)
167 resourceList.addAll(delResourceList)
168 for(Resource resource : resourceList){
169 resourceTemplateUUIDs = resourceTemplateUUIDs + resource.getModelInfo().getModelCustomizationUuid() + ":"
172 def dbAdapterEndpoint = "http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter"
173 execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
174 utils.log("INFO", "DB Adapter Endpoint is: " + dbAdapterEndpoint, isDebugEnabled)
177 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
178 xmlns:ns="http://org.onap.so/requestsdb">
181 <ns:initResourceOperationStatus xmlns:ns="http://org.onap.so/requestsdb">
182 <serviceId>${MsoUtils.xmlEscape(serviceId)}</serviceId>
183 <operationId>${MsoUtils.xmlEscape(operationId)}</operationId>
184 <operationType>${MsoUtils.xmlEscape(operationType)}</operationType>
185 <resourceTemplateUUIDs>${MsoUtils.xmlEscape(resourceTemplateUUIDs)}</resourceTemplateUUIDs>
186 </ns:initResourceOperationStatus>
188 </soapenv:Envelope>"""
190 payload = utils.formatXml(payload)
191 execution.setVariable("CVFMI_initResOperStatusRequest", payload)
192 utils.log("INFO", "Outgoing initResourceOperationStatus: \n" + payload, isDebugEnabled)
193 utils.logAudit("CreateVfModuleInfra Outgoing initResourceOperationStatus Request: " + payload)
196 utils.log("ERROR", "Exception Occured Processing preInitResourcesOperStatus. Exception is:\n" + e, isDebugEnabled)
197 execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during preInitResourcesOperStatus Method:\n" + e.getMessage())
199 utils.log("INFO", "======== COMPLETED preInitResourcesOperStatus Process ======== ", isDebugEnabled)
203 public void preProcessForAddResource(DelegateExecution execution) {
204 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
205 utils.log("INFO"," ***** preProcessForAddResource ***** ", isDebugEnabled)
207 execution.setVariable("operationType", "create")
209 execution.setVariable("hasResourcetoAdd", false)
210 List<Resource> addResourceList = execution.getVariable("addResourceList")
211 if(addResourceList != null && !addResourceList.isEmpty()) {
212 execution.setVariable("hasResourcetoAdd", true)
215 utils.log("INFO"," *** Exit preProcessForAddResource *** ", isDebugEnabled)
218 public void postProcessForAddResource(DelegateExecution execution) {
219 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
220 utils.log("INFO"," ***** postProcessForAddResource ***** ", isDebugEnabled)
222 execution.setVariable("operationType", "update")
224 utils.log("INFO"," *** Exit postProcessForAddResource *** ", isDebugEnabled)
227 public void preProcessForDeleteResource(DelegateExecution execution) {
228 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
229 utils.log("INFO"," ***** preProcessForDeleteResource ***** ", isDebugEnabled)
231 execution.setVariable("operationType", "delete")
233 def hasResourcetoDelete = false
234 List<Resource> delResourceList = execution.getVariable("delResourceList")
235 if(delResourceList != null && !delResourceList.isEmpty()) {
236 hasResourcetoDelete = true
238 execution.setVariable("hasResourcetoDelete", hasResourcetoDelete)
240 if(hasResourcetoDelete) {
241 def jsonSlurper = new JsonSlurper()
242 String serviceRelationShip = execution.getVariable("serviceRelationShip")
243 List relationShipList = jsonSlurper.parseText(serviceRelationShip)
245 //Set the real resource instance id to the decomosed resource list
246 for(Resource resource: delResourceList){
247 //reset the resource instance id , because in the decompose flow ,its a random one.
248 resource.setResourceId("");
249 //match the resource-instance-name and the model name
250 if (relationShipList != null) {
251 relationShipList.each {
252 if(StringUtils.containsIgnoreCase(it.resourceType, resource.getModelInfo().getModelName())){
253 resource.setResourceId(it.resourceInstanceId);
260 execution.setVariable("deleteResourceList", delResourceList)
262 utils.log("INFO"," *** Exit preProcessForDeleteResource *** ", isDebugEnabled)
265 public void postProcessForDeleteResource(DelegateExecution execution) {
266 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
267 utils.log("INFO"," ***** postProcessForDeleteResource ***** ", isDebugEnabled)
269 execution.setVariable("operationType", "update")
271 utils.log("INFO"," *** Exit postProcessForDeleteResource *** ", isDebugEnabled)
274 public void preProcessAAIPUT(DelegateExecution execution) {
275 def method = getClass().getSimpleName() + '.preProcessRequest(' +'execution=' + execution.getId() +')'
276 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
277 utils.log("INFO","Entered " + method, isDebugEnabled)
280 String serviceInstanceVersion = execution.getVariable("serviceInstanceVersion")
282 //requestDetails.modelInfo.for AAI PUT servieInstanceData
283 //requestDetails.requestInfo. for AAI GET/PUT serviceInstanceData
284 String serviceInstanceName = execution.getVariable("serviceInstanceName")
285 String serviceInstanceId = execution.getVariable("serviceInstanceId")
286 //aai serviceType and Role can be setted as fixed value now.
287 String aaiServiceType = "E2E Service"
288 String aaiServiceRole = "E2E Service"
289 String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
290 String modelUuid = execution.getVariable("modelUuid")
292 org.onap.aai.domain.yang.ServiceInstance si = new org.onap.aai.domain.yang.ServiceInstance()
293 si.setServiceInstanceId(serviceInstanceId)
294 si.setServiceInstanceName(serviceInstanceName)
295 si.setServiceType(aaiServiceType)
296 si.setServiceRole(aaiServiceRole)
297 si.setModelInvariantId(modelInvariantUuid)
298 si.setModelVersionId(modelUuid)
300 execution.setVariable("serviceInstanceData", si)
302 utils.log("INFO", "Exited " + method, isDebugEnabled)
305 public void updateServiceInstance(DelegateExecution execution) {
306 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
307 utils.log("INFO"," ***** createServiceInstance ***** ", isDebugEnabled)
309 String serviceInstanceId = execution.getVariable("serviceInstanceId")
311 org.onap.aai.domain.yang.ServiceInstance si = execution.getVariable("serviceInstanceData")
313 AAIResourcesClient client = new AAIResourcesClient()
314 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId)
315 client.update(uri, si)
317 } catch (BpmnError e) {
319 } catch (Exception ex) {
320 RollbackData rollbackData = new RollbackData()
321 def disableRollback = execution.getVariable("disableRollback")
322 rollbackData.put("SERVICEINSTANCE", "disableRollback", disableRollback.toString())
323 rollbackData.put("SERVICEINSTANCE", "rollbackAAI", "true")
324 rollbackData.put("SERVICEINSTANCE", "serviceInstanceId", serviceInstanceId)
325 rollbackData.put("SERVICEINSTANCE", "serviceType", execution.getVariable("serviceType"))
326 rollbackData.put("SERVICEINSTANCE", "globalSubscriberId", execution.getVariable("globalSubscriberId"))
327 execution.setVariable("rollbackData", rollbackData)
329 msg = "Exception in DoCreateServiceInstance.createServiceInstance. " + ex.getMessage()
330 utils.log("INFO", msg, isDebugEnabled)
331 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
333 utils.log("INFO"," *** Exit createServiceInstance *** ", isDebugEnabled)
336 public void preProcessRollback (DelegateExecution execution) {
337 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
338 utils.log("INFO"," ***** preProcessRollback ***** ", isDebugEnabled)
341 Object workflowException = execution.getVariable("WorkflowException");
343 if (workflowException instanceof WorkflowException) {
344 utils.log("INFO", "Prev workflowException: " + workflowException.getErrorMessage(), isDebugEnabled)
345 execution.setVariable("prevWorkflowException", workflowException);
346 //execution.setVariable("WorkflowException", null);
348 } catch (BpmnError e) {
349 utils.log("INFO", "BPMN Error during preProcessRollback", isDebugEnabled)
350 } catch(Exception ex) {
351 String msg = "Exception in preProcessRollback. " + ex.getMessage()
352 utils.log("INFO", msg, isDebugEnabled)
354 utils.log("INFO"," *** Exit preProcessRollback *** ", isDebugEnabled)
357 public void postProcessRollback (DelegateExecution execution) {
358 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
359 utils.log("INFO"," ***** postProcessRollback ***** ", isDebugEnabled)
362 Object workflowException = execution.getVariable("prevWorkflowException");
363 if (workflowException instanceof WorkflowException) {
364 utils.log("INFO", "Setting prevException to WorkflowException: ", isDebugEnabled)
365 execution.setVariable("WorkflowException", workflowException);
367 execution.setVariable("rollbackData", null)
368 } catch (BpmnError b) {
369 utils.log("INFO", "BPMN Error during postProcessRollback", isDebugEnabled)
371 } catch(Exception ex) {
372 msg = "Exception in postProcessRollback. " + ex.getMessage()
373 utils.log("INFO", msg, isDebugEnabled)
375 utils.log("INFO"," *** Exit postProcessRollback *** ", isDebugEnabled)
379 public void postConfigRequest(execution){