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
130 // target model Invariant uuid
\r
131 String modelInvariantUuid = jsonUtil.getJsonValue(uuiRequest, "service.serviceInvariantUuid")
\r
132 execution.setVariable("modelInvariantUuid", modelInvariantUuid)
\r
133 utils.log("INFO", "modelInvariantUuid: " + modelInvariantUuid, isDebugEnabled)
\r
135 // target model uuid
\r
136 String modelUuid = jsonUtil.getJsonValue(uuiRequest, "service.serviceUuid")
\r
137 execution.setVariable("modelUuid", modelUuid)
\r
138 utils.log("INFO", "modelUuid: " + modelUuid, isDebugEnabled)
\r
140 } catch (BpmnError e) {
\r
142 } catch (Exception ex){
\r
143 msg = "Exception in preProcessRequest " + ex.getMessage()
\r
144 utils.log("INFO", msg, isDebugEnabled)
\r
145 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
\r
147 utils.log("INFO", "======== COMPLETED preProcessRequest Process ======== ", isDebugEnabled)
\r
151 public void preInitResourcesOperStatus(DelegateExecution execution){
\r
152 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
\r
154 utils.log("INFO", " ======== STARTED preInitResourcesOperStatus Process ======== ", isDebugEnabled)
\r
156 String serviceId = execution.getVariable("serviceInstanceId")
\r
157 String operationId = execution.getVariable("operationId")
\r
158 String operationType = execution.getVariable("operationType")
\r
159 String resourceTemplateUUIDs = ""
\r
160 String result = "processing"
\r
161 String progress = "0"
\r
163 String operationContent = "Prepare service updating"
\r
164 utils.log("INFO", "Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId + " operationType:" + operationType, isDebugEnabled)
\r
165 serviceId = UriUtils.encode(serviceId,"UTF-8")
\r
166 execution.setVariable("serviceInstanceId", serviceId)
\r
167 execution.setVariable("operationId", operationId)
\r
168 execution.setVariable("operationType", operationType)
\r
170 List<Resource> resourceList = new ArrayList<String>()
\r
171 List<Resource> addResourceList = execution.getVariable("addResourceList")
\r
172 List<Resource> delResourceList = execution.getVariable("delResourceList")
\r
173 resourceList.addAll(addResourceList)
\r
174 resourceList.addAll(delResourceList)
\r
175 for(Resource resource : resourceList){
\r
176 resourceTemplateUUIDs = resourceTemplateUUIDs + resource.getModelInfo().getModelCustomizationUuid() + ":"
\r
179 def dbAdapterEndpoint = "http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter"
\r
180 execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
\r
181 utils.log("INFO", "DB Adapter Endpoint is: " + dbAdapterEndpoint, isDebugEnabled)
\r
184 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
\r
185 xmlns:ns="http://org.openecomp.mso/requestsdb">
\r
188 <ns:initResourceOperationStatus xmlns:ns="http://org.openecomp.mso/requestsdb">
\r
189 <serviceId>${serviceId}</serviceId>
\r
190 <operationId>${operationId}</operationId>
\r
191 <operationType>${operationType}</operationType>
\r
192 <resourceTemplateUUIDs>${resourceTemplateUUIDs}</resourceTemplateUUIDs>
\r
193 </ns:initResourceOperationStatus>
\r
195 </soapenv:Envelope>"""
\r
197 payload = utils.formatXml(payload)
\r
198 execution.setVariable("CVFMI_initResOperStatusRequest", payload)
\r
199 utils.log("INFO", "Outgoing initResourceOperationStatus: \n" + payload, isDebugEnabled)
\r
200 utils.logAudit("CreateVfModuleInfra Outgoing initResourceOperationStatus Request: " + payload)
\r
202 }catch(Exception e){
\r
203 utils.log("ERROR", "Exception Occured Processing preInitResourcesOperStatus. Exception is:\n" + e, isDebugEnabled)
\r
204 execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during preInitResourcesOperStatus Method:\n" + e.getMessage())
\r
206 utils.log("INFO", "======== COMPLETED preInitResourcesOperStatus Process ======== ", isDebugEnabled)
\r
210 public void preProcessForAddResource(DelegateExecution execution) {
\r
211 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
212 utils.log("INFO"," ***** preProcessForAddResource ***** ", isDebugEnabled)
\r
214 execution.setVariable("operationType", "create")
\r
216 execution.setVariable("hasResourcetoAdd", false)
\r
217 List<Resource> addResourceList = execution.getVariable("addResourceList")
\r
218 if(addResourceList != null && !addResourceList.isEmpty()) {
\r
219 execution.setVariable("hasResourcetoAdd", true)
\r
222 utils.log("INFO"," *** Exit preProcessForAddResource *** ", isDebugEnabled)
\r
225 public void postProcessForAddResource(DelegateExecution execution) {
\r
226 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
227 utils.log("INFO"," ***** postProcessForAddResource ***** ", isDebugEnabled)
\r
229 execution.setVariable("operationType", "update")
\r
231 utils.log("INFO"," *** Exit postProcessForAddResource *** ", isDebugEnabled)
\r
234 public void preProcessForDeleteResource(DelegateExecution execution) {
\r
235 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
236 utils.log("INFO"," ***** preProcessForDeleteResource ***** ", isDebugEnabled)
\r
238 execution.setVariable("operationType", "delete")
\r
240 def hasResourcetoDelete = false
\r
241 List<Resource> delResourceList = execution.getVariable("delResourceList")
\r
242 if(delResourceList != null && !delResourceList.isEmpty()) {
\r
243 hasResourcetoDelete = true
\r
245 execution.setVariable("hasResourcetoDelete", hasResourcetoDelete)
\r
247 if(hasResourcetoDelete) {
\r
248 def jsonSlurper = new JsonSlurper()
\r
249 String serviceRelationShip = execution.getVariable("serviceRelationShip")
\r
250 List relationShipList = jsonSlurper.parseText(serviceRelationShip)
\r
252 //Set the real resource instance id to the decomosed resource list
\r
253 for(Resource resource: delResourceList){
\r
254 //reset the resource instance id , because in the decompose flow ,its a random one.
\r
255 resource.setResourceId("");
\r
256 //match the resource-instance-name and the model name
\r
257 if (relationShipList != null) {
\r
258 relationShipList.each {
\r
259 if(StringUtils.containsIgnoreCase(it.resourceType, resource.getModelInfo().getModelName())){
\r
260 resource.setResourceId(it.resourceInstanceId);
\r
267 execution.setVariable("deleteResourceList", delResourceList)
\r
269 utils.log("INFO"," *** Exit preProcessForDeleteResource *** ", isDebugEnabled)
\r
272 public void postProcessForDeleteResource(DelegateExecution execution) {
\r
273 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
274 utils.log("INFO"," ***** postProcessForDeleteResource ***** ", isDebugEnabled)
\r
276 execution.setVariable("operationType", "update")
\r
278 utils.log("INFO"," *** Exit postProcessForDeleteResource *** ", isDebugEnabled)
\r
281 public void preProcessAAIGET(DelegateExecution execution) {
\r
282 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
285 public void postProcessAAIGET(DelegateExecution execution) {
\r
286 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
287 utils.log("INFO"," ***** postProcessAAIGET ***** ", isDebugEnabled)
\r
291 String serviceInstanceName = execution.getVariable("serviceInstanceName")
\r
292 boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")
\r
294 utils.log("INFO","Error getting Service-instance from AAI in postProcessAAIGET", + serviceInstanceName, isDebugEnabled)
\r
295 WorkflowException workflowException = execution.getVariable("WorkflowException")
\r
296 utils.logAudit("workflowException: " + workflowException)
\r
297 if(workflowException != null){
\r
298 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
\r
302 msg = "Failure in postProcessAAIGET GENGS_SuccessIndicator:" + succInAAI
\r
303 utils.log("INFO", msg, isDebugEnabled)
\r
304 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
\r
309 boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")
\r
311 String aaiService = execution.getVariable("GENGS_service")
\r
312 if (!isBlank(aaiService) && (utils.nodeExists(aaiService, "resource-version"))) {
\r
313 execution.setVariable("serviceInstanceVersion", utils.getNodeText1(aaiService, "resource-version"))
\r
314 utils.log("INFO","Found Service-instance in AAI.serviceInstanceName:" + execution.getVariable("serviceInstanceName"), isDebugEnabled)
\r
318 } catch (BpmnError e) {
\r
320 } catch (Exception ex) {
\r
321 msg = "Exception in DoUpdateE2EServiceInstance.postProcessAAIGET " + ex.getMessage()
\r
322 utils.log("INFO", msg, isDebugEnabled)
\r
323 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
\r
325 utils.log("INFO"," *** Exit postProcessAAIGET *** ", isDebugEnabled)
\r
328 public void preProcessAAIPUT(DelegateExecution execution) {
\r
329 def method = getClass().getSimpleName() + '.preProcessRequest(' +'execution=' + execution.getId() +')'
\r
330 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
\r
331 utils.log("INFO","Entered " + method, isDebugEnabled)
\r
333 utils.log("INFO"," ***** preProcessAAIPUT *****", isDebugEnabled)
\r
336 String serviceInstanceVersion = execution.getVariable("serviceInstanceVersion")
\r
337 //execution.setVariable("GENPS_serviceResourceVersion", serviceInstanceVersion)
\r
339 //requestDetails.modelInfo.for AAI PUT servieInstanceData
\r
340 //requestDetails.requestInfo. for AAI GET/PUT serviceInstanceData
\r
341 String serviceInstanceName = execution.getVariable("serviceInstanceName")
\r
342 String serviceInstanceId = execution.getVariable("serviceInstanceId")
\r
343 //aai serviceType and Role can be setted as fixed value now.
\r
344 String aaiServiceType = "E2E Service"
\r
345 String aaiServiceRole = "E2E Service"
\r
346 String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
\r
347 String modelUuid = execution.getVariable("modelUuid")
\r
350 AaiUtil aaiUriUtil = new AaiUtil(this)
\r
351 utils.log("INFO","start create aai uri: " + aaiUriUtil, isDebugEnabled)
\r
352 String aai_uri = aaiUriUtil.getBusinessCustomerUri(execution)
\r
353 utils.log("INFO","aai_uri: " + aai_uri, isDebugEnabled)
\r
354 String namespace = aaiUriUtil.getNamespaceFromUri(aai_uri)
\r
355 utils.log("INFO","namespace: " + namespace, isDebugEnabled)
\r
357 //update target model to aai
\r
358 String serviceInstanceData =
\r
359 """<service-instance xmlns=\"${namespace}\">
\r
360 <service-instance-id>${serviceInstanceId}</service-instance-id>
\r
361 <service-instance-name>${serviceInstanceName}</service-instance-name>
\r
362 <service-type>${aaiServiceType}</service-type>
\r
363 <service-role>${aaiServiceRole}</service-role>
\r
364 <resource-version>${serviceInstanceVersion}</resource-version>
\r
365 <model-invariant-id>${modelInvariantUuid}</model-invariant-id>
\r
366 <model-version-id>${modelUuid}</model-version-id>
\r
367 </service-instance>""".trim()
\r
369 execution.setVariable("serviceInstanceData", serviceInstanceData)
\r
370 utils.log("INFO","serviceInstanceData: " + serviceInstanceData, isDebugEnabled)
\r
371 utils.logAudit(serviceInstanceData)
\r
372 utils.log("INFO", " aai_uri " + aai_uri + " namespace:" + namespace, isDebugEnabled)
\r
373 utils.log("INFO", " 'payload' to update Service Instance in AAI - " + "\n" + serviceInstanceData, isDebugEnabled)
\r
375 utils.log("INFO", "Exited " + method, isDebugEnabled)
\r
378 public void postProcessAAIPUT(DelegateExecution execution) {
\r
379 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
380 utils.log("INFO"," ***** postProcessAAIPUT ***** ", isDebugEnabled)
\r
383 String serviceInstanceId = execution.getVariable("serviceInstanceId")
\r
384 boolean succInAAI = execution.getVariable("GENPS_SuccessIndicator")
\r
386 utils.log("INFO","Error putting Service-instance in AAI", + serviceInstanceId, isDebugEnabled)
\r
387 WorkflowException workflowException = execution.getVariable("WorkflowException")
\r
388 utils.logAudit("workflowException: " + workflowException)
\r
389 if(workflowException != null){
\r
390 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
\r
395 //start rollback set up
\r
396 RollbackData rollbackData = new RollbackData()
\r
397 def disableRollback = execution.getVariable("disableRollback")
\r
398 rollbackData.put("SERVICEINSTANCE", "disableRollback", disableRollback.toString())
\r
399 rollbackData.put("SERVICEINSTANCE", "rollbackAAI", "true")
\r
400 rollbackData.put("SERVICEINSTANCE", "serviceInstanceId", serviceInstanceId)
\r
401 rollbackData.put("SERVICEINSTANCE", "serviceType", execution.getVariable("serviceType"))
\r
402 rollbackData.put("SERVICEINSTANCE", "globalSubscriberId", execution.getVariable("globalSubscriberId"))
\r
403 execution.setVariable("rollbackData", rollbackData)
\r
406 } catch (BpmnError e) {
\r
408 } catch (Exception ex) {
\r
409 msg = "Exception in DoCreateServiceInstance.postProcessAAIDEL. " + ex.getMessage()
\r
410 utils.log("INFO", msg, isDebugEnabled)
\r
411 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
\r
413 utils.log("INFO"," *** Exit postProcessAAIPUT *** ", isDebugEnabled)
\r
416 public void preProcessRollback (DelegateExecution execution) {
\r
417 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
418 utils.log("INFO"," ***** preProcessRollback ***** ", isDebugEnabled)
\r
421 Object workflowException = execution.getVariable("WorkflowException");
\r
423 if (workflowException instanceof WorkflowException) {
\r
424 utils.log("INFO", "Prev workflowException: " + workflowException.getErrorMessage(), isDebugEnabled)
\r
425 execution.setVariable("prevWorkflowException", workflowException);
\r
426 //execution.setVariable("WorkflowException", null);
\r
428 } catch (BpmnError e) {
\r
429 utils.log("INFO", "BPMN Error during preProcessRollback", isDebugEnabled)
\r
430 } catch(Exception ex) {
\r
431 String msg = "Exception in preProcessRollback. " + ex.getMessage()
\r
432 utils.log("INFO", msg, isDebugEnabled)
\r
434 utils.log("INFO"," *** Exit preProcessRollback *** ", isDebugEnabled)
\r
437 public void postProcessRollback (DelegateExecution execution) {
\r
438 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
439 utils.log("INFO"," ***** postProcessRollback ***** ", isDebugEnabled)
\r
442 Object workflowException = execution.getVariable("prevWorkflowException");
\r
443 if (workflowException instanceof WorkflowException) {
\r
444 utils.log("INFO", "Setting prevException to WorkflowException: ", isDebugEnabled)
\r
445 execution.setVariable("WorkflowException", workflowException);
\r
447 execution.setVariable("rollbackData", null)
\r
448 } catch (BpmnError b) {
\r
449 utils.log("INFO", "BPMN Error during postProcessRollback", isDebugEnabled)
\r
451 } catch(Exception ex) {
\r
452 msg = "Exception in postProcessRollback. " + ex.getMessage()
\r
453 utils.log("INFO", msg, isDebugEnabled)
\r
455 utils.log("INFO"," *** Exit postProcessRollback *** ", isDebugEnabled)
\r
459 public void postConfigRequest(execution){
\r