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)
200 logger.info( "Exception Occured Processing preInitResourcesOperStatus. Exception is:\n" + e)
201 execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during preInitResourcesOperStatus Method:\n" + e.getMessage())
203 logger.info( "======== COMPLETED preInitResourcesOperStatus Process ======== ")
207 public void preProcessForAddResource(DelegateExecution execution) {
208 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
209 logger.info(" ***** preProcessForAddResource ***** ")
211 execution.setVariable("operationType", "create")
213 execution.setVariable("hasResourcetoAdd", false)
214 List<Resource> addResourceList = execution.getVariable("addResourceList")
215 if(addResourceList != null && !addResourceList.isEmpty()) {
216 execution.setVariable("hasResourcetoAdd", true)
219 logger.info(" *** Exit preProcessForAddResource *** ")
222 public void postProcessForAddResource(DelegateExecution execution) {
223 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
224 logger.info(" ***** postProcessForAddResource ***** ")
226 execution.setVariable("operationType", "update")
228 logger.info(" *** Exit postProcessForAddResource *** ")
231 public void preProcessForDeleteResource(DelegateExecution execution) {
232 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
233 logger.info(" ***** preProcessForDeleteResource ***** ")
235 execution.setVariable("operationType", "delete")
237 def hasResourcetoDelete = false
238 List<Resource> delResourceList = execution.getVariable("delResourceList")
239 if(delResourceList != null && !delResourceList.isEmpty()) {
240 hasResourcetoDelete = true
242 execution.setVariable("hasResourcetoDelete", hasResourcetoDelete)
244 if(hasResourcetoDelete) {
245 def jsonSlurper = new JsonSlurper()
246 String serviceRelationShip = execution.getVariable("serviceRelationShip")
247 List relationShipList = jsonSlurper.parseText(serviceRelationShip)
249 //Set the real resource instance id to the decomosed resource list
250 for(Resource resource: delResourceList){
251 //reset the resource instance id , because in the decompose flow ,its a random one.
252 resource.setResourceId("");
253 //match the resource-instance-name and the model name
254 if (relationShipList != null) {
255 relationShipList.each {
256 if(StringUtils.containsIgnoreCase(it.resourceType, resource.getModelInfo().getModelName())){
257 resource.setResourceId(it.resourceInstanceId);
264 execution.setVariable("deleteResourceList", delResourceList)
266 logger.info(" *** Exit preProcessForDeleteResource *** ")
269 public void postProcessForDeleteResource(DelegateExecution execution) {
270 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
271 logger.info(" ***** postProcessForDeleteResource ***** ")
273 execution.setVariable("operationType", "update")
275 logger.info(" *** Exit postProcessForDeleteResource *** ")
278 public void preProcessAAIPUT(DelegateExecution execution) {
279 def method = getClass().getSimpleName() + '.preProcessRequest(' +'execution=' + execution.getId() +')'
280 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
281 logger.info("Entered " + method)
284 String serviceInstanceVersion = execution.getVariable("serviceInstanceVersion")
286 //requestDetails.modelInfo.for AAI PUT servieInstanceData
287 //requestDetails.requestInfo. for AAI GET/PUT serviceInstanceData
288 String serviceInstanceName = execution.getVariable("serviceInstanceName")
289 String serviceInstanceId = execution.getVariable("serviceInstanceId")
290 //aai serviceType and Role can be setted as fixed value now.
291 String aaiServiceType = "E2E Service"
292 String aaiServiceRole = "E2E Service"
293 String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
294 String modelUuid = execution.getVariable("modelUuid")
296 org.onap.aai.domain.yang.ServiceInstance si = new org.onap.aai.domain.yang.ServiceInstance()
297 si.setServiceInstanceId(serviceInstanceId)
298 si.setServiceInstanceName(serviceInstanceName)
299 si.setServiceType(aaiServiceType)
300 si.setServiceRole(aaiServiceRole)
301 si.setModelInvariantId(modelInvariantUuid)
302 si.setModelVersionId(modelUuid)
304 execution.setVariable("serviceInstanceData", si)
306 logger.info( "Exited " + method)
309 public void updateServiceInstance(DelegateExecution execution) {
310 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
311 logger.info(" ***** createServiceInstance ***** ")
313 String serviceInstanceId = execution.getVariable("serviceInstanceId")
315 org.onap.aai.domain.yang.ServiceInstance si = execution.getVariable("serviceInstanceData")
317 AAIResourcesClient client = new AAIResourcesClient()
318 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId)
319 client.update(uri, si)
321 } catch (BpmnError e) {
323 } catch (Exception ex) {
324 RollbackData rollbackData = new RollbackData()
325 def disableRollback = execution.getVariable("disableRollback")
326 rollbackData.put("SERVICEINSTANCE", "disableRollback", disableRollback.toString())
327 rollbackData.put("SERVICEINSTANCE", "rollbackAAI", "true")
328 rollbackData.put("SERVICEINSTANCE", "serviceInstanceId", serviceInstanceId)
329 rollbackData.put("SERVICEINSTANCE", "serviceType", execution.getVariable("serviceType"))
330 rollbackData.put("SERVICEINSTANCE", "globalSubscriberId", execution.getVariable("globalSubscriberId"))
331 execution.setVariable("rollbackData", rollbackData)
333 msg = "Exception in DoCreateServiceInstance.createServiceInstance. " + ex.getMessage()
335 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
337 logger.info(" *** Exit createServiceInstance *** ")
340 public void preProcessRollback (DelegateExecution execution) {
341 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
342 logger.info(" ***** preProcessRollback ***** ")
345 Object workflowException = execution.getVariable("WorkflowException");
347 if (workflowException instanceof WorkflowException) {
348 logger.info( "Prev workflowException: " + workflowException.getErrorMessage())
349 execution.setVariable("prevWorkflowException", workflowException);
350 //execution.setVariable("WorkflowException", null);
352 } catch (BpmnError e) {
353 logger.info( "BPMN Error during preProcessRollback")
354 } catch(Exception ex) {
355 String msg = "Exception in preProcessRollback. " + ex.getMessage()
358 logger.info(" *** Exit preProcessRollback *** ")
361 public void postProcessRollback (DelegateExecution execution) {
362 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
363 logger.info(" ***** postProcessRollback ***** ")
366 Object workflowException = execution.getVariable("prevWorkflowException");
367 if (workflowException instanceof WorkflowException) {
368 logger.info( "Setting prevException to WorkflowException: ")
369 execution.setVariable("WorkflowException", workflowException);
371 execution.setVariable("rollbackData", null)
372 } catch (BpmnError b) {
373 logger.info( "BPMN Error during postProcessRollback")
375 } catch(Exception ex) {
376 msg = "Exception in postProcessRollback. " + ex.getMessage()
379 logger.info(" *** Exit postProcessRollback *** ")
383 public void postConfigRequest(execution){