2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved.
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============LICENSE_END=========================================================
\r
20 package org.openecomp.mso.bpmn.infrastructure.scripts;
\r
22 import static org.apache.commons.lang3.StringUtils.*;
\r
23 import groovy.xml.XmlUtil
\r
24 import groovy.json.*
\r
25 import groovy.util.XmlParser
\r
27 import org.openecomp.mso.bpmn.core.domain.ServiceDecomposition
\r
28 import org.openecomp.mso.bpmn.core.domain.ServiceInstance
\r
29 import org.openecomp.mso.bpmn.core.domain.ModelInfo
\r
30 import org.openecomp.mso.bpmn.core.domain.Resource
\r
31 import org.openecomp.mso.bpmn.core.json.JsonUtils
\r
32 import org.openecomp.mso.bpmn.common.scripts.AaiUtil
\r
33 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
\r
34 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
\r
35 import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils
\r
36 import org.openecomp.mso.bpmn.core.RollbackData
\r
37 import org.openecomp.mso.bpmn.core.WorkflowException
\r
38 import org.openecomp.mso.rest.APIResponse;
\r
39 import org.openecomp.mso.rest.RESTClient
\r
40 import org.openecomp.mso.rest.RESTConfig
\r
42 import java.util.UUID;
\r
43 import javax.xml.parsers.DocumentBuilder
\r
44 import javax.xml.parsers.DocumentBuilderFactory
\r
46 import org.camunda.bpm.engine.delegate.BpmnError
\r
47 import org.camunda.bpm.engine.delegate.DelegateExecution
\r
48 import org.json.JSONObject;
\r
49 import org.json.JSONArray;
\r
50 import org.apache.commons.lang3.*
\r
51 import org.apache.commons.codec.binary.Base64;
\r
52 import org.springframework.web.util.UriUtils;
\r
56 * This groovy class supports the <class>DoUpdateE2EServiceInstance.bpmn</class> process.
\r
59 * @param - msoRequestId
\r
60 * @param - globalSubscriberId
\r
61 * @param - serviceType
\r
62 * @param - serviceInstanceId
\r
63 * @param - serviceInstanceName
\r
64 * @param - serviceModelInfo
\r
65 * @param - productFamilyId
\r
66 * @param - uuiRequest
\r
67 * @param - serviceDecomposition_Target
\r
68 * @param - serviceDecomposition_Original
\r
69 * @param - addResourceList
\r
70 * @param - delResourceList
\r
73 * @param - rollbackData (localRB->null)
\r
74 * @param - rolledBack (no localRB->null, localRB F->false, localRB S->true)
\r
75 * @param - WorkflowException
\r
77 public class DoUpdateE2EServiceInstance extends AbstractServiceTaskProcessor {
\r
79 String Prefix="DUPDSI_"
\r
80 private static final String DebugFlag = "isDebugEnabled"
\r
82 ExceptionUtil exceptionUtil = new ExceptionUtil()
\r
83 JsonUtils jsonUtil = new JsonUtils()
\r
85 public void preProcessRequest (DelegateExecution execution) {
\r
86 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
\r
87 utils.log("INFO"," ***** Enter DoUpdateE2EServiceInstance preProcessRequest *****", isDebugEnabled)
\r
92 execution.setVariable("prefix", Prefix)
\r
94 //for AAI GET & PUT & SDNC assignToplology
\r
95 String globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId
\r
96 utils.log("INFO"," ***** globalSubscriberId *****" + globalSubscriberId, isDebugEnabled)
\r
98 //for AAI PUT & SDNC assignTopology
\r
99 String serviceType = execution.getVariable("serviceType")
\r
100 utils.log("INFO"," ***** serviceType *****" + serviceType, isDebugEnabled)
\r
102 //for SDNC assignTopology
\r
103 String productFamilyId = execution.getVariable("productFamilyId") //AAI productFamilyId
\r
105 if (isBlank(globalSubscriberId)) {
\r
106 msg = "Input globalSubscriberId is null"
\r
107 utils.log("INFO", msg, isDebugEnabled)
\r
108 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
\r
111 if (isBlank(serviceType)) {
\r
112 msg = "Input serviceType is null"
\r
113 utils.log("INFO", msg, isDebugEnabled)
\r
114 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
\r
117 //Generated in parent for AAI
\r
118 String serviceInstanceId = execution.getVariable("serviceInstanceId")
\r
119 if (isBlank(serviceInstanceId)){
\r
120 msg = "Input serviceInstanceId is null"
\r
121 utils.log("INFO", msg, isDebugEnabled)
\r
122 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
\r
125 String serviceInstanceName = execution.getVariable("serviceInstanceName")
\r
128 String uuiRequest = execution.getVariable("uuiRequest")
\r
129 // target model uuid
\r
130 String modelUuid = jsonUtil.getJsonValue(uuiRequest, "service.serviceUuid")
\r
131 execution.setVariable("modelUuid", modelUuid)
\r
133 utils.log("INFO","modelUuid: " + modelUuid, isDebugEnabled)
\r
135 } catch (BpmnError e) {
\r
137 } catch (Exception ex){
\r
138 msg = "Exception in preProcessRequest " + ex.getMessage()
\r
139 utils.log("INFO", msg, isDebugEnabled)
\r
140 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
\r
142 utils.log("INFO", "======== COMPLETED preProcessRequest Process ======== ", isDebugEnabled)
\r
146 public void preInitResourcesOperStatus(DelegateExecution execution){
\r
147 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
\r
149 utils.log("INFO", " ======== STARTED preInitResourcesOperStatus Process ======== ", isDebugEnabled)
\r
151 String serviceId = execution.getVariable("serviceInstanceId")
\r
152 String operationId = execution.getVariable("operationId")
\r
153 String operationType = execution.getVariable("operationType")
\r
154 String resourceTemplateUUIDs = ""
\r
155 String result = "processing"
\r
156 String progress = "0"
\r
158 String operationContent = "Prepare service updating"
\r
159 utils.log("INFO", "Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId + " operationType:" + operationType, isDebugEnabled)
\r
160 serviceId = UriUtils.encode(serviceId,"UTF-8")
\r
161 execution.setVariable("serviceInstanceId", serviceId)
\r
162 execution.setVariable("operationId", operationId)
\r
163 execution.setVariable("operationType", operationType)
\r
165 List<Resource> resourceList = new ArrayList<String>()
\r
166 List<Resource> addResourceList = execution.getVariable("addResourceList")
\r
167 List<Resource> delResourceList = execution.getVariable("delResourceList")
\r
168 resourceList.addAll(addResourceList)
\r
169 resourceList.addAll(delResourceList)
\r
170 for(Resource resource : resourceList){
\r
171 resourceTemplateUUIDs = resourceTemplateUUIDs + resource.getModelInfo().getModelCustomizationUuid() + ":"
\r
174 def dbAdapterEndpoint = "http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter"
\r
175 execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
\r
176 utils.log("INFO", "DB Adapter Endpoint is: " + dbAdapterEndpoint, isDebugEnabled)
\r
179 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
\r
180 xmlns:ns="http://org.openecomp.mso/requestsdb">
\r
183 <ns:initResourceOperationStatus xmlns:ns="http://org.openecomp.mso/requestsdb">
\r
184 <serviceId>${serviceId}</serviceId>
\r
185 <operationId>${operationId}</operationId>
\r
186 <operationType>${operationType}</operationType>
\r
187 <resourceTemplateUUIDs>${resourceTemplateUUIDs}</resourceTemplateUUIDs>
\r
188 </ns:initResourceOperationStatus>
\r
190 </soapenv:Envelope>"""
\r
192 payload = utils.formatXml(payload)
\r
193 execution.setVariable("CVFMI_initResOperStatusRequest", payload)
\r
194 utils.log("INFO", "Outgoing initResourceOperationStatus: \n" + payload, isDebugEnabled)
\r
195 utils.logAudit("CreateVfModuleInfra Outgoing initResourceOperationStatus Request: " + payload)
\r
197 }catch(Exception e){
\r
198 utils.log("ERROR", "Exception Occured Processing preInitResourcesOperStatus. Exception is:\n" + e, isDebugEnabled)
\r
199 execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during preInitResourcesOperStatus Method:\n" + e.getMessage())
\r
201 utils.log("INFO", "======== COMPLETED preInitResourcesOperStatus Process ======== ", isDebugEnabled)
\r
205 public void preProcessForAddResource(DelegateExecution execution) {
\r
206 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
207 utils.log("INFO"," ***** preProcessForAddResource ***** ", isDebugEnabled)
\r
209 execution.setVariable("operationType", "create")
\r
211 execution.setVariable("hasResourcetoAdd", false)
\r
212 List<Resource> addResourceList = execution.getVariable("addResourceList")
\r
213 if(addResourceList != null && !addResourceList.isEmpty()) {
\r
214 execution.setVariable("hasResourcetoAdd", true)
\r
217 utils.log("INFO"," *** Exit preProcessForAddResource *** ", isDebugEnabled)
\r
220 public void postProcessForAddResource(DelegateExecution execution) {
\r
221 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
222 utils.log("INFO"," ***** postProcessForAddResource ***** ", isDebugEnabled)
\r
224 execution.setVariable("operationType", "update")
\r
226 utils.log("INFO"," *** Exit postProcessForAddResource *** ", isDebugEnabled)
\r
229 public void preProcessForDeleteResource(DelegateExecution execution) {
\r
230 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
231 utils.log("INFO"," ***** preProcessForDeleteResource ***** ", isDebugEnabled)
\r
233 execution.setVariable("operationType", "delete")
\r
235 def hasResourcetoDelete = false
\r
236 List<Resource> delResourceList = execution.getVariable("delResourceList")
\r
237 if(delResourceList != null && !delResourceList.isEmpty()) {
\r
238 hasResourcetoDelete = true
\r
240 execution.setVariable("hasResourcetoDelete", hasResourcetoDelete)
\r
242 if(hasResourcetoDelete) {
\r
243 def jsonSlurper = new JsonSlurper()
\r
244 String serviceRelationShip = execution.getVariable("serviceRelationShip")
\r
245 List relationShipList = jsonSlurper.parseText(serviceRelationShip)
\r
247 //Set the real resource instance id to the decomosed resource list
\r
248 for(Resource resource: delResourceList){
\r
249 //reset the resource instance id , because in the decompose flow ,its a random one.
\r
250 resource.setResourceId("");
\r
251 //match the resource-instance-name and the model name
\r
252 if (relationShipList != null) {
\r
253 relationShipList.each {
\r
254 if(StringUtils.containsIgnoreCase(it.resourceType, resource.getModelInfo().getModelName())){
\r
255 resource.setResourceId(it.resourceInstanceId);
\r
262 execution.setVariable("deleteResourceList", delResourceList)
\r
264 utils.log("INFO"," *** Exit preProcessForDeleteResource *** ", isDebugEnabled)
\r
267 public void postProcessForDeleteResource(DelegateExecution execution) {
\r
268 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
269 utils.log("INFO"," ***** postProcessForDeleteResource ***** ", isDebugEnabled)
\r
271 execution.setVariable("operationType", "update")
\r
273 utils.log("INFO"," *** Exit postProcessForDeleteResource *** ", isDebugEnabled)
\r
276 public void preProcessAAIGET(DelegateExecution execution) {
\r
277 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
280 public void postProcessAAIGET(DelegateExecution execution) {
\r
281 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
282 utils.log("INFO"," ***** postProcessAAIGET ***** ", isDebugEnabled)
\r
286 String serviceInstanceName = execution.getVariable("serviceInstanceName")
\r
287 boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")
\r
289 utils.log("INFO","Error getting Service-instance from AAI in postProcessAAIGET", + serviceInstanceName, isDebugEnabled)
\r
290 WorkflowException workflowException = execution.getVariable("WorkflowException")
\r
291 utils.logAudit("workflowException: " + workflowException)
\r
292 if(workflowException != null){
\r
293 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
\r
297 msg = "Failure in postProcessAAIGET GENGS_SuccessIndicator:" + succInAAI
\r
298 utils.log("INFO", msg, isDebugEnabled)
\r
299 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
\r
304 boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")
\r
306 String aaiService = execution.getVariable("GENGS_service")
\r
307 if (!isBlank(aaiService) && (utils.nodeExists(aaiService, "resource-version"))) {
\r
308 execution.setVariable("serviceInstanceVersion", utils.getNodeText1(aaiService, "resource-version"))
\r
309 utils.log("INFO","Found Service-instance in AAI.serviceInstanceName:" + execution.getVariable("serviceInstanceName"), isDebugEnabled)
\r
313 } catch (BpmnError e) {
\r
315 } catch (Exception ex) {
\r
316 msg = "Exception in DoUpdateE2EServiceInstance.postProcessAAIGET " + ex.getMessage()
\r
317 utils.log("INFO", msg, isDebugEnabled)
\r
318 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
\r
320 utils.log("INFO"," *** Exit postProcessAAIGET *** ", isDebugEnabled)
\r
323 public void preProcessAAIPUT(DelegateExecution execution) {
\r
324 def method = getClass().getSimpleName() + '.preProcessRequest(' +'execution=' + execution.getId() +')'
\r
325 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
\r
326 utils.log("INFO","Entered " + method, isDebugEnabled)
\r
328 utils.log("INFO"," ***** preProcessAAIPUT *****", isDebugEnabled)
\r
330 String modelUuid = execution.getVariable("modelUuid")
\r
331 String serviceInstanceVersion = execution.getVariable("serviceInstanceVersion")
\r
332 execution.setVariable("GENPS_serviceResourceVersion", serviceInstanceVersion)
\r
334 AaiUtil aaiUriUtil = new AaiUtil(this)
\r
335 utils.log("INFO","start create aai uri: " + aaiUriUtil, isDebugEnabled)
\r
336 String aai_uri = aaiUriUtil.getBusinessCustomerUri(execution)
\r
337 utils.log("INFO","aai_uri: " + aai_uri, isDebugEnabled)
\r
338 String namespace = aaiUriUtil.getNamespaceFromUri(aai_uri)
\r
339 utils.log("INFO","namespace: " + namespace, isDebugEnabled)
\r
341 //update target model to aai
\r
342 String serviceInstanceData =
\r
343 """<service-instance xmlns=\"${namespace}\">
\r
344 <model-version-id">${modelUuid}</model-version-id>
\r
345 </service-instance>""".trim()
\r
347 execution.setVariable("serviceInstanceData", serviceInstanceData)
\r
348 utils.log("INFO","serviceInstanceData: " + serviceInstanceData, isDebugEnabled)
\r
349 utils.logAudit(serviceInstanceData)
\r
350 utils.log("INFO", " aai_uri " + aai_uri + " namespace:" + namespace, isDebugEnabled)
\r
351 utils.log("INFO", " 'payload' to update Service Instance in AAI - " + "\n" + serviceInstanceData, isDebugEnabled)
\r
353 utils.log("INFO", "Exited " + method, isDebugEnabled)
\r
356 public void postProcessAAIPUT(DelegateExecution execution) {
\r
357 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
358 utils.log("INFO"," ***** postProcessAAIPUT ***** ", isDebugEnabled)
\r
361 String serviceInstanceId = execution.getVariable("serviceInstanceId")
\r
362 boolean succInAAI = execution.getVariable("GENPS_SuccessIndicator")
\r
364 utils.log("INFO","Error putting Service-instance in AAI", + serviceInstanceId, isDebugEnabled)
\r
365 WorkflowException workflowException = execution.getVariable("WorkflowException")
\r
366 utils.logAudit("workflowException: " + workflowException)
\r
367 if(workflowException != null){
\r
368 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
\r
373 //start rollback set up
\r
374 RollbackData rollbackData = new RollbackData()
\r
375 def disableRollback = execution.getVariable("disableRollback")
\r
376 rollbackData.put("SERVICEINSTANCE", "disableRollback", disableRollback.toString())
\r
377 rollbackData.put("SERVICEINSTANCE", "rollbackAAI", "true")
\r
378 rollbackData.put("SERVICEINSTANCE", "serviceInstanceId", serviceInstanceId)
\r
379 rollbackData.put("SERVICEINSTANCE", "serviceType", execution.getVariable("serviceType"))
\r
380 rollbackData.put("SERVICEINSTANCE", "globalSubscriberId", execution.getVariable("globalSubscriberId"))
\r
381 execution.setVariable("rollbackData", rollbackData)
\r
384 } catch (BpmnError e) {
\r
386 } catch (Exception ex) {
\r
387 msg = "Exception in DoCreateServiceInstance.postProcessAAIDEL. " + ex.getMessage()
\r
388 utils.log("INFO", msg, isDebugEnabled)
\r
389 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
\r
391 utils.log("INFO"," *** Exit postProcessAAIPUT *** ", isDebugEnabled)
\r
394 public void preProcessRollback (DelegateExecution execution) {
\r
395 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
396 utils.log("INFO"," ***** preProcessRollback ***** ", isDebugEnabled)
\r
399 Object workflowException = execution.getVariable("WorkflowException");
\r
401 if (workflowException instanceof WorkflowException) {
\r
402 utils.log("INFO", "Prev workflowException: " + workflowException.getErrorMessage(), isDebugEnabled)
\r
403 execution.setVariable("prevWorkflowException", workflowException);
\r
404 //execution.setVariable("WorkflowException", null);
\r
406 } catch (BpmnError e) {
\r
407 utils.log("INFO", "BPMN Error during preProcessRollback", isDebugEnabled)
\r
408 } catch(Exception ex) {
\r
409 String msg = "Exception in preProcessRollback. " + ex.getMessage()
\r
410 utils.log("INFO", msg, isDebugEnabled)
\r
412 utils.log("INFO"," *** Exit preProcessRollback *** ", isDebugEnabled)
\r
415 public void postProcessRollback (DelegateExecution execution) {
\r
416 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
417 utils.log("INFO"," ***** postProcessRollback ***** ", isDebugEnabled)
\r
420 Object workflowException = execution.getVariable("prevWorkflowException");
\r
421 if (workflowException instanceof WorkflowException) {
\r
422 utils.log("INFO", "Setting prevException to WorkflowException: ", isDebugEnabled)
\r
423 execution.setVariable("WorkflowException", workflowException);
\r
425 execution.setVariable("rollbackData", null)
\r
426 } catch (BpmnError b) {
\r
427 utils.log("INFO", "BPMN Error during postProcessRollback", isDebugEnabled)
\r
429 } catch(Exception ex) {
\r
430 msg = "Exception in postProcessRollback. " + ex.getMessage()
\r
431 utils.log("INFO", msg, isDebugEnabled)
\r
433 utils.log("INFO"," *** Exit postProcessRollback *** ", isDebugEnabled)
\r
437 public void postConfigRequest(execution){
\r