2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (c) 2019 Samsung
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
22 package org.onap.so.bpmn.infrastructure.scripts
23 import org.onap.so.client.aai.AAIResourcesClient
24 import org.onap.so.client.aai.entities.uri.AAIResourceUri;
26 import static org.apache.commons.lang3.StringUtils.*;
28 import org.apache.commons.lang3.*
29 import org.camunda.bpm.engine.delegate.BpmnError
30 import org.camunda.bpm.engine.delegate.DelegateExecution
31 import org.onap.aai.domain.yang.ServiceInstance;
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.core.RollbackData
36 import org.onap.so.bpmn.core.WorkflowException
37 import org.onap.so.bpmn.core.domain.Resource
38 import org.onap.so.bpmn.core.json.JsonUtils
39 import org.onap.so.client.aai.AAIObjectType
40 import org.onap.so.client.aai.AAIResourcesClient
41 import org.onap.so.client.aai.entities.AAIResultWrapper
42 import org.onap.so.client.aai.entities.uri.AAIResourceUri
43 import org.onap.so.client.aai.entities.uri.AAIUriFactory
44 import org.springframework.web.util.UriUtils;
45 import org.slf4j.Logger
46 import org.slf4j.LoggerFactory
52 * This groovy class supports the <class>DoUpdateE2EServiceInstance.bpmn</class> process.
55 * @param - msoRequestId
56 * @param - globalSubscriberId
57 * @param - serviceType
58 * @param - serviceInstanceId
59 * @param - serviceInstanceName
60 * @param - serviceModelInfo
61 * @param - productFamilyId
63 * @param - serviceDecomposition_Target
64 * @param - serviceDecomposition_Original
65 * @param - addResourceList
66 * @param - delResourceList
69 * @param - rollbackData (localRB->null)
70 * @param - rolledBack (no localRB->null, localRB F->false, localRB S->true)
71 * @param - WorkflowException
73 public class DoUpdateE2EServiceInstance extends AbstractServiceTaskProcessor {
74 private static final Logger logger = LoggerFactory.getLogger( DoUpdateE2EServiceInstance.class);
76 String Prefix="DUPDSI_"
77 private static final String DebugFlag = "isDebugEnabled"
79 ExceptionUtil exceptionUtil = new ExceptionUtil()
80 JsonUtils jsonUtil = new JsonUtils()
82 public void preProcessRequest (DelegateExecution execution) {
83 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
84 logger.info(" ***** Enter DoUpdateE2EServiceInstance preProcessRequest *****")
89 execution.setVariable("prefix", Prefix)
91 //for AAI GET & PUT & SDNC assignToplology
92 String globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId
93 logger.info(" ***** globalSubscriberId *****" + globalSubscriberId)
95 //for AAI PUT & SDNC assignTopology
96 String serviceType = execution.getVariable("serviceType")
97 logger.info(" ***** serviceType *****" + serviceType)
99 //for SDNC assignTopology
100 String productFamilyId = execution.getVariable("productFamilyId") //AAI productFamilyId
102 if (isBlank(globalSubscriberId)) {
103 msg = "Input globalSubscriberId is null"
105 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
108 if (isBlank(serviceType)) {
109 msg = "Input serviceType is null"
111 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
114 //Generated in parent for AAI
115 String serviceInstanceId = execution.getVariable("serviceInstanceId")
116 if (isBlank(serviceInstanceId)){
117 msg = "Input serviceInstanceId is null"
119 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
122 String serviceInstanceName = execution.getVariable("serviceInstanceName")
125 String uuiRequest = execution.getVariable("uuiRequest")
127 // target model Invariant uuid
128 String modelInvariantUuid = jsonUtil.getJsonValue(uuiRequest, "service.serviceInvariantUuid")
129 execution.setVariable("modelInvariantUuid", modelInvariantUuid)
130 logger.info( "modelInvariantUuid: " + modelInvariantUuid)
133 String modelUuid = jsonUtil.getJsonValue(uuiRequest, "service.serviceUuid")
134 execution.setVariable("modelUuid", modelUuid)
136 logger.info("modelUuid: " + modelUuid)
138 } catch (BpmnError e) {
140 } catch (Exception ex){
141 msg = "Exception in preProcessRequest " + ex.getMessage()
143 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
145 logger.info( "======== COMPLETED preProcessRequest Process ======== ")
149 public void preInitResourcesOperStatus(DelegateExecution execution){
150 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
152 logger.info( " ======== STARTED preInitResourcesOperStatus Process ======== ")
154 String serviceId = execution.getVariable("serviceInstanceId")
155 String operationId = execution.getVariable("operationId")
156 String operationType = execution.getVariable("operationType")
157 String resourceTemplateUUIDs = ""
158 String result = "processing"
159 String progress = "0"
161 String operationContent = "Prepare service updating"
162 logger.info( "Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId + " operationType:" + operationType)
163 serviceId = UriUtils.encode(serviceId,"UTF-8")
164 execution.setVariable("serviceInstanceId", serviceId)
165 execution.setVariable("operationId", operationId)
166 execution.setVariable("operationType", operationType)
168 List<Resource> resourceList = new ArrayList<String>()
169 List<Resource> addResourceList = execution.getVariable("addResourceList")
170 List<Resource> delResourceList = execution.getVariable("delResourceList")
171 resourceList.addAll(addResourceList)
172 resourceList.addAll(delResourceList)
173 for(Resource resource : resourceList){
174 resourceTemplateUUIDs = resourceTemplateUUIDs + resource.getModelInfo().getModelCustomizationUuid() + ":"
177 def dbAdapterEndpoint = UrnPropertiesReader.getVariable("mso.adapters.openecomp.db.endpoint", execution)
178 execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
179 logger.info( "DB Adapter Endpoint is: " + dbAdapterEndpoint)
182 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
183 xmlns:ns="http://org.onap.so/requestsdb">
186 <ns:initResourceOperationStatus xmlns:ns="http://org.onap.so/requestsdb">
187 <serviceId>${MsoUtils.xmlEscape(serviceId)}</serviceId>
188 <operationId>${MsoUtils.xmlEscape(operationId)}</operationId>
189 <operationType>${MsoUtils.xmlEscape(operationType)}</operationType>
190 <resourceTemplateUUIDs>${MsoUtils.xmlEscape(resourceTemplateUUIDs)}</resourceTemplateUUIDs>
191 </ns:initResourceOperationStatus>
193 </soapenv:Envelope>"""
195 payload = utils.formatXml(payload)
196 execution.setVariable("CVFMI_initResOperStatusRequest", payload)
197 logger.info( "Outgoing initResourceOperationStatus: \n" + payload)
198 utils.logAudit("CreateVfModuleInfra Outgoing initResourceOperationStatus Request: " + payload)
201 logger.info( "Exception Occured Processing preInitResourcesOperStatus. Exception is:\n" + e)
202 execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during preInitResourcesOperStatus Method:\n" + e.getMessage())
204 logger.info( "======== COMPLETED preInitResourcesOperStatus Process ======== ")
208 public void preProcessForAddResource(DelegateExecution execution) {
209 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
210 logger.info(" ***** preProcessForAddResource ***** ")
212 execution.setVariable("operationType", "create")
214 execution.setVariable("hasResourcetoAdd", false)
215 List<Resource> addResourceList = execution.getVariable("addResourceList")
216 if(addResourceList != null && !addResourceList.isEmpty()) {
217 execution.setVariable("hasResourcetoAdd", true)
220 logger.info(" *** Exit preProcessForAddResource *** ")
223 public void postProcessForAddResource(DelegateExecution execution) {
224 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
225 logger.info(" ***** postProcessForAddResource ***** ")
227 execution.setVariable("operationType", "update")
229 logger.info(" *** Exit postProcessForAddResource *** ")
232 public void preProcessForDeleteResource(DelegateExecution execution) {
233 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
234 logger.info(" ***** preProcessForDeleteResource ***** ")
236 execution.setVariable("operationType", "delete")
238 def hasResourcetoDelete = false
239 List<Resource> delResourceList = execution.getVariable("delResourceList")
240 if(delResourceList != null && !delResourceList.isEmpty()) {
241 hasResourcetoDelete = true
243 execution.setVariable("hasResourcetoDelete", hasResourcetoDelete)
245 if(hasResourcetoDelete) {
246 def jsonSlurper = new JsonSlurper()
247 String serviceRelationShip = execution.getVariable("serviceRelationShip")
248 List relationShipList = jsonSlurper.parseText(serviceRelationShip)
250 //Set the real resource instance id to the decomosed resource list
251 for(Resource resource: delResourceList){
252 //reset the resource instance id , because in the decompose flow ,its a random one.
253 resource.setResourceId("");
254 //match the resource-instance-name and the model name
255 if (relationShipList != null) {
256 relationShipList.each {
257 if(StringUtils.containsIgnoreCase(it.resourceType, resource.getModelInfo().getModelName())){
258 resource.setResourceId(it.resourceInstanceId);
265 execution.setVariable("deleteResourceList", delResourceList)
267 logger.info(" *** Exit preProcessForDeleteResource *** ")
270 public void postProcessForDeleteResource(DelegateExecution execution) {
271 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
272 logger.info(" ***** postProcessForDeleteResource ***** ")
274 execution.setVariable("operationType", "update")
276 logger.info(" *** Exit postProcessForDeleteResource *** ")
279 public void preProcessAAIPUT(DelegateExecution execution) {
280 def method = getClass().getSimpleName() + '.preProcessRequest(' +'execution=' + execution.getId() +')'
281 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
282 logger.info("Entered " + method)
285 String serviceInstanceVersion = execution.getVariable("serviceInstanceVersion")
287 //requestDetails.modelInfo.for AAI PUT servieInstanceData
288 //requestDetails.requestInfo. for AAI GET/PUT serviceInstanceData
289 String serviceInstanceName = execution.getVariable("serviceInstanceName")
290 String serviceInstanceId = execution.getVariable("serviceInstanceId")
291 //aai serviceType and Role can be setted as fixed value now.
292 String aaiServiceType = "E2E Service"
293 String aaiServiceRole = "E2E Service"
294 String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
295 String modelUuid = execution.getVariable("modelUuid")
297 org.onap.aai.domain.yang.ServiceInstance si = new org.onap.aai.domain.yang.ServiceInstance()
298 si.setServiceInstanceId(serviceInstanceId)
299 si.setServiceInstanceName(serviceInstanceName)
300 si.setServiceType(aaiServiceType)
301 si.setServiceRole(aaiServiceRole)
302 si.setModelInvariantId(modelInvariantUuid)
303 si.setModelVersionId(modelUuid)
305 execution.setVariable("serviceInstanceData", si)
307 logger.info( "Exited " + method)
310 public void updateServiceInstance(DelegateExecution execution) {
311 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
312 logger.info(" ***** createServiceInstance ***** ")
314 String serviceInstanceId = execution.getVariable("serviceInstanceId")
316 org.onap.aai.domain.yang.ServiceInstance si = execution.getVariable("serviceInstanceData")
318 AAIResourcesClient client = new AAIResourcesClient()
319 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId)
320 client.update(uri, si)
322 } catch (BpmnError e) {
324 } catch (Exception ex) {
325 RollbackData rollbackData = new RollbackData()
326 def disableRollback = execution.getVariable("disableRollback")
327 rollbackData.put("SERVICEINSTANCE", "disableRollback", disableRollback.toString())
328 rollbackData.put("SERVICEINSTANCE", "rollbackAAI", "true")
329 rollbackData.put("SERVICEINSTANCE", "serviceInstanceId", serviceInstanceId)
330 rollbackData.put("SERVICEINSTANCE", "serviceType", execution.getVariable("serviceType"))
331 rollbackData.put("SERVICEINSTANCE", "globalSubscriberId", execution.getVariable("globalSubscriberId"))
332 execution.setVariable("rollbackData", rollbackData)
334 msg = "Exception in DoCreateServiceInstance.createServiceInstance. " + ex.getMessage()
336 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
338 logger.info(" *** Exit createServiceInstance *** ")
341 public void preProcessRollback (DelegateExecution execution) {
342 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
343 logger.info(" ***** preProcessRollback ***** ")
346 Object workflowException = execution.getVariable("WorkflowException");
348 if (workflowException instanceof WorkflowException) {
349 logger.info( "Prev workflowException: " + workflowException.getErrorMessage())
350 execution.setVariable("prevWorkflowException", workflowException);
351 //execution.setVariable("WorkflowException", null);
353 } catch (BpmnError e) {
354 logger.info( "BPMN Error during preProcessRollback")
355 } catch(Exception ex) {
356 String msg = "Exception in preProcessRollback. " + ex.getMessage()
359 logger.info(" *** Exit preProcessRollback *** ")
362 public void postProcessRollback (DelegateExecution execution) {
363 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
364 logger.info(" ***** postProcessRollback ***** ")
367 Object workflowException = execution.getVariable("prevWorkflowException");
368 if (workflowException instanceof WorkflowException) {
369 logger.info( "Setting prevException to WorkflowException: ")
370 execution.setVariable("WorkflowException", workflowException);
372 execution.setVariable("rollbackData", null)
373 } catch (BpmnError b) {
374 logger.info( "BPMN Error during postProcessRollback")
376 } catch(Exception ex) {
377 msg = "Exception in postProcessRollback. " + ex.getMessage()
380 logger.info(" *** Exit postProcessRollback *** ")
384 public void postConfigRequest(execution){