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.onap.so.client.aai.AAIObjectType
36 import org.onap.so.client.aai.AAIResourcesClient
37 import org.onap.so.client.aai.entities.AAIResultWrapper
38 import org.onap.so.client.aai.entities.uri.AAIResourceUri
39 import org.onap.so.client.aai.entities.uri.AAIUriFactory
40 import org.springframework.web.util.UriUtils;
46 * This groovy class supports the <class>DoUpdateE2EServiceInstance.bpmn</class> process.
49 * @param - msoRequestId
50 * @param - globalSubscriberId
51 * @param - serviceType
52 * @param - serviceInstanceId
53 * @param - serviceInstanceName
54 * @param - serviceModelInfo
55 * @param - productFamilyId
57 * @param - serviceDecomposition_Target
58 * @param - serviceDecomposition_Original
59 * @param - addResourceList
60 * @param - delResourceList
63 * @param - rollbackData (localRB->null)
64 * @param - rolledBack (no localRB->null, localRB F->false, localRB S->true)
65 * @param - WorkflowException
67 public class DoUpdateE2EServiceInstance extends AbstractServiceTaskProcessor {
69 String Prefix="DUPDSI_"
70 private static final String DebugFlag = "isDebugEnabled"
72 ExceptionUtil exceptionUtil = new ExceptionUtil()
73 JsonUtils jsonUtil = new JsonUtils()
75 public void preProcessRequest (DelegateExecution execution) {
76 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
77 utils.log("INFO"," ***** Enter DoUpdateE2EServiceInstance preProcessRequest *****", isDebugEnabled)
82 execution.setVariable("prefix", Prefix)
84 //for AAI GET & PUT & SDNC assignToplology
85 String globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId
86 utils.log("INFO"," ***** globalSubscriberId *****" + globalSubscriberId, isDebugEnabled)
88 //for AAI PUT & SDNC assignTopology
89 String serviceType = execution.getVariable("serviceType")
90 utils.log("INFO"," ***** serviceType *****" + serviceType, isDebugEnabled)
92 //for SDNC assignTopology
93 String productFamilyId = execution.getVariable("productFamilyId") //AAI productFamilyId
95 if (isBlank(globalSubscriberId)) {
96 msg = "Input globalSubscriberId is null"
97 utils.log("INFO", msg, isDebugEnabled)
98 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
101 if (isBlank(serviceType)) {
102 msg = "Input serviceType is null"
103 utils.log("INFO", msg, isDebugEnabled)
104 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
107 //Generated in parent for AAI
108 String serviceInstanceId = execution.getVariable("serviceInstanceId")
109 if (isBlank(serviceInstanceId)){
110 msg = "Input serviceInstanceId is null"
111 utils.log("INFO", msg, isDebugEnabled)
112 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
115 String serviceInstanceName = execution.getVariable("serviceInstanceName")
118 String uuiRequest = execution.getVariable("uuiRequest")
120 // target model Invariant uuid
121 String modelInvariantUuid = jsonUtil.getJsonValue(uuiRequest, "service.serviceInvariantUuid")
122 execution.setVariable("modelInvariantUuid", modelInvariantUuid)
123 utils.log("INFO", "modelInvariantUuid: " + modelInvariantUuid, isDebugEnabled)
126 String modelUuid = jsonUtil.getJsonValue(uuiRequest, "service.serviceUuid")
127 execution.setVariable("modelUuid", modelUuid)
129 utils.log("INFO","modelUuid: " + modelUuid, isDebugEnabled)
131 } catch (BpmnError e) {
133 } catch (Exception ex){
134 msg = "Exception in preProcessRequest " + ex.getMessage()
135 utils.log("INFO", msg, isDebugEnabled)
136 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
138 utils.log("INFO", "======== COMPLETED preProcessRequest Process ======== ", isDebugEnabled)
142 public void preInitResourcesOperStatus(DelegateExecution execution){
143 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
145 utils.log("INFO", " ======== STARTED preInitResourcesOperStatus Process ======== ", isDebugEnabled)
147 String serviceId = execution.getVariable("serviceInstanceId")
148 String operationId = execution.getVariable("operationId")
149 String operationType = execution.getVariable("operationType")
150 String resourceTemplateUUIDs = ""
151 String result = "processing"
152 String progress = "0"
154 String operationContent = "Prepare service updating"
155 utils.log("INFO", "Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId + " operationType:" + operationType, isDebugEnabled)
156 serviceId = UriUtils.encode(serviceId,"UTF-8")
157 execution.setVariable("serviceInstanceId", serviceId)
158 execution.setVariable("operationId", operationId)
159 execution.setVariable("operationType", operationType)
161 List<Resource> resourceList = new ArrayList<String>()
162 List<Resource> addResourceList = execution.getVariable("addResourceList")
163 List<Resource> delResourceList = execution.getVariable("delResourceList")
164 resourceList.addAll(addResourceList)
165 resourceList.addAll(delResourceList)
166 for(Resource resource : resourceList){
167 resourceTemplateUUIDs = resourceTemplateUUIDs + resource.getModelInfo().getModelCustomizationUuid() + ":"
170 def dbAdapterEndpoint = "http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter"
171 execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
172 utils.log("INFO", "DB Adapter Endpoint is: " + dbAdapterEndpoint, isDebugEnabled)
175 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
176 xmlns:ns="http://org.onap.so/requestsdb">
179 <ns:initResourceOperationStatus xmlns:ns="http://org.onap.so/requestsdb">
180 <serviceId>${MsoUtils.xmlEscape(serviceId)}</serviceId>
181 <operationId>${MsoUtils.xmlEscape(operationId)}</operationId>
182 <operationType>${MsoUtils.xmlEscape(operationType)}</operationType>
183 <resourceTemplateUUIDs>${MsoUtils.xmlEscape(resourceTemplateUUIDs)}</resourceTemplateUUIDs>
184 </ns:initResourceOperationStatus>
186 </soapenv:Envelope>"""
188 payload = utils.formatXml(payload)
189 execution.setVariable("CVFMI_initResOperStatusRequest", payload)
190 utils.log("INFO", "Outgoing initResourceOperationStatus: \n" + payload, isDebugEnabled)
191 utils.logAudit("CreateVfModuleInfra Outgoing initResourceOperationStatus Request: " + payload)
194 utils.log("ERROR", "Exception Occured Processing preInitResourcesOperStatus. Exception is:\n" + e, isDebugEnabled)
195 execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during preInitResourcesOperStatus Method:\n" + e.getMessage())
197 utils.log("INFO", "======== COMPLETED preInitResourcesOperStatus Process ======== ", isDebugEnabled)
201 public void preProcessForAddResource(DelegateExecution execution) {
202 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
203 utils.log("INFO"," ***** preProcessForAddResource ***** ", isDebugEnabled)
205 execution.setVariable("operationType", "create")
207 execution.setVariable("hasResourcetoAdd", false)
208 List<Resource> addResourceList = execution.getVariable("addResourceList")
209 if(addResourceList != null && !addResourceList.isEmpty()) {
210 execution.setVariable("hasResourcetoAdd", true)
213 utils.log("INFO"," *** Exit preProcessForAddResource *** ", isDebugEnabled)
216 public void postProcessForAddResource(DelegateExecution execution) {
217 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
218 utils.log("INFO"," ***** postProcessForAddResource ***** ", isDebugEnabled)
220 execution.setVariable("operationType", "update")
222 utils.log("INFO"," *** Exit postProcessForAddResource *** ", isDebugEnabled)
225 public void preProcessForDeleteResource(DelegateExecution execution) {
226 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
227 utils.log("INFO"," ***** preProcessForDeleteResource ***** ", isDebugEnabled)
229 execution.setVariable("operationType", "delete")
231 def hasResourcetoDelete = false
232 List<Resource> delResourceList = execution.getVariable("delResourceList")
233 if(delResourceList != null && !delResourceList.isEmpty()) {
234 hasResourcetoDelete = true
236 execution.setVariable("hasResourcetoDelete", hasResourcetoDelete)
238 if(hasResourcetoDelete) {
239 def jsonSlurper = new JsonSlurper()
240 String serviceRelationShip = execution.getVariable("serviceRelationShip")
241 List relationShipList = jsonSlurper.parseText(serviceRelationShip)
243 //Set the real resource instance id to the decomosed resource list
244 for(Resource resource: delResourceList){
245 //reset the resource instance id , because in the decompose flow ,its a random one.
246 resource.setResourceId("");
247 //match the resource-instance-name and the model name
248 if (relationShipList != null) {
249 relationShipList.each {
250 if(StringUtils.containsIgnoreCase(it.resourceType, resource.getModelInfo().getModelName())){
251 resource.setResourceId(it.resourceInstanceId);
258 execution.setVariable("deleteResourceList", delResourceList)
260 utils.log("INFO"," *** Exit preProcessForDeleteResource *** ", isDebugEnabled)
263 public void postProcessForDeleteResource(DelegateExecution execution) {
264 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
265 utils.log("INFO"," ***** postProcessForDeleteResource ***** ", isDebugEnabled)
267 execution.setVariable("operationType", "update")
269 utils.log("INFO"," *** Exit postProcessForDeleteResource *** ", isDebugEnabled)
272 public void preProcessAAIPUT(DelegateExecution execution) {
273 def method = getClass().getSimpleName() + '.preProcessRequest(' +'execution=' + execution.getId() +')'
274 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
275 utils.log("INFO","Entered " + method, isDebugEnabled)
278 String serviceInstanceVersion = execution.getVariable("serviceInstanceVersion")
280 //requestDetails.modelInfo.for AAI PUT servieInstanceData
281 //requestDetails.requestInfo. for AAI GET/PUT serviceInstanceData
282 String serviceInstanceName = execution.getVariable("serviceInstanceName")
283 String serviceInstanceId = execution.getVariable("serviceInstanceId")
284 //aai serviceType and Role can be setted as fixed value now.
285 String aaiServiceType = "E2E Service"
286 String aaiServiceRole = "E2E Service"
287 String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
288 String modelUuid = execution.getVariable("modelUuid")
290 org.onap.aai.domain.yang.ServiceInstance si = new org.onap.aai.domain.yang.ServiceInstance()
291 si.setServiceInstanceId(serviceInstanceId)
292 si.setServiceInstanceName(serviceInstanceName)
293 si.setServiceType(aaiServiceType)
294 si.setServiceRole(aaiServiceRole)
295 si.setModelInvariantId(modelInvariantUuid)
296 si.setModelVersionId(modelUuid)
298 execution.setVariable("serviceInstanceData", si)
300 utils.log("INFO", "Exited " + method, isDebugEnabled)
303 public void updateServiceInstance(DelegateExecution execution) {
304 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
305 utils.log("INFO"," ***** createServiceInstance ***** ", isDebugEnabled)
307 String serviceInstanceId = execution.getVariable("serviceInstanceId")
309 org.onap.aai.domain.yang.ServiceInstance si = execution.getVariable("serviceInstanceData")
311 AAIResourcesClient client = new AAIResourcesClient()
312 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId)
313 client.update(uri, si)
315 } catch (BpmnError e) {
317 } catch (Exception ex) {
318 RollbackData rollbackData = new RollbackData()
319 def disableRollback = execution.getVariable("disableRollback")
320 rollbackData.put("SERVICEINSTANCE", "disableRollback", disableRollback.toString())
321 rollbackData.put("SERVICEINSTANCE", "rollbackAAI", "true")
322 rollbackData.put("SERVICEINSTANCE", "serviceInstanceId", serviceInstanceId)
323 rollbackData.put("SERVICEINSTANCE", "serviceType", execution.getVariable("serviceType"))
324 rollbackData.put("SERVICEINSTANCE", "globalSubscriberId", execution.getVariable("globalSubscriberId"))
325 execution.setVariable("rollbackData", rollbackData)
327 msg = "Exception in DoCreateServiceInstance.createServiceInstance. " + ex.getMessage()
328 utils.log("INFO", msg, isDebugEnabled)
329 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
331 utils.log("INFO"," *** Exit createServiceInstance *** ", isDebugEnabled)
334 public void preProcessRollback (DelegateExecution execution) {
335 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
336 utils.log("INFO"," ***** preProcessRollback ***** ", isDebugEnabled)
339 Object workflowException = execution.getVariable("WorkflowException");
341 if (workflowException instanceof WorkflowException) {
342 utils.log("INFO", "Prev workflowException: " + workflowException.getErrorMessage(), isDebugEnabled)
343 execution.setVariable("prevWorkflowException", workflowException);
344 //execution.setVariable("WorkflowException", null);
346 } catch (BpmnError e) {
347 utils.log("INFO", "BPMN Error during preProcessRollback", isDebugEnabled)
348 } catch(Exception ex) {
349 String msg = "Exception in preProcessRollback. " + ex.getMessage()
350 utils.log("INFO", msg, isDebugEnabled)
352 utils.log("INFO"," *** Exit preProcessRollback *** ", isDebugEnabled)
355 public void postProcessRollback (DelegateExecution execution) {
356 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
357 utils.log("INFO"," ***** postProcessRollback ***** ", isDebugEnabled)
360 Object workflowException = execution.getVariable("prevWorkflowException");
361 if (workflowException instanceof WorkflowException) {
362 utils.log("INFO", "Setting prevException to WorkflowException: ", isDebugEnabled)
363 execution.setVariable("WorkflowException", workflowException);
365 execution.setVariable("rollbackData", null)
366 } catch (BpmnError b) {
367 utils.log("INFO", "BPMN Error during postProcessRollback", isDebugEnabled)
369 } catch(Exception ex) {
370 msg = "Exception in postProcessRollback. " + ex.getMessage()
371 utils.log("INFO", msg, isDebugEnabled)
373 utils.log("INFO"," *** Exit postProcessRollback *** ", isDebugEnabled)
377 public void postConfigRequest(execution){