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 utils.log("INFO","uuiRequest: " + uuiRequest, isDebugEnabled)
\r
131 } catch (BpmnError e) {
\r
133 } catch (Exception ex){
\r
134 msg = "Exception in preProcessRequest " + ex.getMessage()
\r
135 utils.log("INFO", msg, isDebugEnabled)
\r
136 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
\r
138 utils.log("INFO", "======== COMPLETED preProcessRequest Process ======== ", isDebugEnabled)
\r
142 public void preInitResourcesOperStatus(DelegateExecution execution){
\r
143 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
\r
145 utils.log("INFO", " ======== STARTED preInitResourcesOperStatus Process ======== ", isDebugEnabled)
\r
147 String serviceId = execution.getVariable("serviceInstanceId")
\r
148 String operationId = execution.getVariable("operationId")
\r
149 String operationType = execution.getVariable("operationType")
\r
150 String resourceTemplateUUIDs = ""
\r
151 String result = "processing"
\r
152 String progress = "0"
\r
154 String operationContent = "Prepare service updating"
\r
155 utils.log("INFO", "Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId + " operationType:" + operationType, isDebugEnabled)
\r
156 serviceId = UriUtils.encode(serviceId,"UTF-8")
\r
157 execution.setVariable("serviceInstanceId", serviceId)
\r
158 execution.setVariable("operationId", operationId)
\r
159 execution.setVariable("operationType", operationType)
\r
161 List<Resource> resourceList = new ArrayList<String>()
\r
162 List<Resource> addResourceList = execution.getVariable("addResourceList")
\r
163 List<Resource> delResourceList = execution.getVariable("delResourceList")
\r
164 resourceList.addAll(addResourceList)
\r
165 resourceList.addAll(delResourceList)
\r
166 for(Resource resource : resourceList){
\r
167 resourceTemplateUUIDs = resourceTemplateUUIDs + resource.getModelInfo().getModelCustomizationUuid() + ":"
\r
170 def dbAdapterEndpoint = "http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter"
\r
171 execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
\r
172 utils.log("INFO", "DB Adapter Endpoint is: " + dbAdapterEndpoint, isDebugEnabled)
\r
175 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
\r
176 xmlns:ns="http://org.openecomp.mso/requestsdb">
\r
179 <ns:initResourceOperationStatus xmlns:ns="http://org.openecomp.mso/requestsdb">
\r
180 <serviceId>${serviceId}</serviceId>
\r
181 <operationId>${operationId}</operationId>
\r
182 <operationType>${operationType}</operationType>
\r
183 <resourceTemplateUUIDs>${resourceTemplateUUIDs}</resourceTemplateUUIDs>
\r
184 </ns:initResourceOperationStatus>
\r
186 </soapenv:Envelope>"""
\r
188 payload = utils.formatXml(payload)
\r
189 execution.setVariable("CVFMI_initResOperStatusRequest", payload)
\r
190 utils.log("INFO", "Outgoing initResourceOperationStatus: \n" + payload, isDebugEnabled)
\r
191 utils.logAudit("CreateVfModuleInfra Outgoing initResourceOperationStatus Request: " + payload)
\r
193 }catch(Exception e){
\r
194 utils.log("ERROR", "Exception Occured Processing preInitResourcesOperStatus. Exception is:\n" + e, isDebugEnabled)
\r
195 execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during preInitResourcesOperStatus Method:\n" + e.getMessage())
\r
197 utils.log("INFO", "======== COMPLETED preInitResourcesOperStatus Process ======== ", isDebugEnabled)
\r
201 public void preProcessForAddResource(DelegateExecution execution) {
\r
202 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
203 utils.log("INFO"," ***** preProcessForAddResource ***** ", isDebugEnabled)
\r
205 execution.setVariable("operationType", "create")
\r
207 def hasResourcetoAdd = false
\r
208 List<Resource> addResourceList = execution.getVariable("addResourceList")
\r
209 if(addResourceList != null && !addResourceList.isEmpty()) {
\r
210 hasResourcetoAdd = true
\r
212 execution.setVariable("hasResourcetoAdd", hasResourcetoAdd)
\r
215 utils.log("INFO"," *** Exit preProcessForAddResource *** ", isDebugEnabled)
\r
218 public void postProcessForAddResource(DelegateExecution execution) {
\r
219 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
220 utils.log("INFO"," ***** postProcessForAddResource ***** ", isDebugEnabled)
\r
222 execution.setVariable("operationType", "update")
\r
224 utils.log("INFO"," *** Exit postProcessForAddResource *** ", isDebugEnabled)
\r
227 public void preProcessForDeleteResource(DelegateExecution execution) {
\r
228 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
229 utils.log("INFO"," ***** preProcessForDeleteResource ***** ", isDebugEnabled)
\r
231 execution.setVariable("operationType", "delete")
\r
233 def hasResourcetoDelete = false
\r
234 List<Resource> delResourceList = execution.getVariable("delResourceList")
\r
235 if(delResourceList != null && !delResourceList.isEmpty()) {
\r
236 hasResourcetoDelete = true
\r
238 execution.setVariable("hasResourcetoDelete", hasResourcetoDelete)
\r
240 execution.setVariable("resourceInstanceIDs", execution.getVariable("serviceRelationShip"))
\r
242 utils.log("INFO"," *** Exit preProcessForDeleteResource *** ", isDebugEnabled)
\r
246 public void postProcessForDeleteResource(DelegateExecution execution) {
\r
247 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
248 utils.log("INFO"," ***** postProcessForDeleteResource ***** ", isDebugEnabled)
\r
250 execution.setVariable("operationType", "update")
\r
252 utils.log("INFO"," *** Exit postProcessForDeleteResource *** ", isDebugEnabled)
\r
255 public void preProcessAAIGET(DelegateExecution execution) {
\r
256 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
259 public void postProcessAAIGET(DelegateExecution execution) {
\r
260 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
261 utils.log("INFO"," ***** postProcessAAIGET ***** ", isDebugEnabled)
\r
265 String serviceInstanceName = execution.getVariable("serviceInstanceName")
\r
266 boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")
\r
268 utils.log("INFO","Error getting Service-instance from AAI in postProcessAAIGET", + serviceInstanceName, isDebugEnabled)
\r
269 WorkflowException workflowException = execution.getVariable("WorkflowException")
\r
270 utils.logAudit("workflowException: " + workflowException)
\r
271 if(workflowException != null){
\r
272 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
\r
276 msg = "Failure in postProcessAAIGET GENGS_SuccessIndicator:" + succInAAI
\r
277 utils.log("INFO", msg, isDebugEnabled)
\r
278 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
\r
283 boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")
\r
285 String aaiService = execution.getVariable("GENGS_service")
\r
286 if (!isBlank(aaiService) && (utils.nodeExists(aaiService, "resource-version"))) {
\r
287 execution.setVariable("serviceInstanceVersion", utils.getNodeText1(aaiService, "resource-version"))
\r
288 utils.log("INFO","Found Service-instance in AAI.serviceInstanceName:" + execution.getVariable("serviceInstanceName"), isDebugEnabled)
\r
292 } catch (BpmnError e) {
\r
294 } catch (Exception ex) {
\r
295 msg = "Exception in DoUpdateE2EServiceInstance.postProcessAAIGET " + ex.getMessage()
\r
296 utils.log("INFO", msg, isDebugEnabled)
\r
297 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
\r
299 utils.log("INFO"," *** Exit postProcessAAIGET *** ", isDebugEnabled)
\r
302 public void preProcessAAIPUT(DelegateExecution execution) {
\r
303 def method = getClass().getSimpleName() + '.preProcessRequest(' +'execution=' + execution.getId() +')'
\r
304 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
\r
305 utils.log("INFO","Entered " + method, isDebugEnabled)
\r
307 utils.log("INFO"," ***** preProcessAAIPUT *****", isDebugEnabled)
\r
309 String modelUuid = execution.getVariable("modelUuid")
\r
310 String serviceInstanceVersion = execution.getVariable("serviceInstanceVersion")
\r
311 execution.setVariable("GENPS_serviceResourceVersion", serviceInstanceVersion)
\r
313 AaiUtil aaiUriUtil = new AaiUtil(this)
\r
314 utils.log("INFO","start create aai uri: " + aaiUriUtil, isDebugEnabled)
\r
315 String aai_uri = aaiUriUtil.getBusinessCustomerUri(execution)
\r
316 utils.log("INFO","aai_uri: " + aai_uri, isDebugEnabled)
\r
317 String namespace = aaiUriUtil.getNamespaceFromUri(aai_uri)
\r
318 utils.log("INFO","namespace: " + namespace, isDebugEnabled)
\r
320 String serviceInstanceData =
\r
321 """<service-instance xmlns=\"${namespace}\">
\r
322 <model-version-id">${modelUuid}</model-version-id>
\r
323 </service-instance>""".trim()
\r
325 execution.setVariable("serviceInstanceData", serviceInstanceData)
\r
326 utils.log("INFO","serviceInstanceData: " + serviceInstanceData, isDebugEnabled)
\r
327 utils.logAudit(serviceInstanceData)
\r
328 utils.log("INFO", " aai_uri " + aai_uri + " namespace:" + namespace, isDebugEnabled)
\r
329 utils.log("INFO", " 'payload' to update Service Instance in AAI - " + "\n" + serviceInstanceData, isDebugEnabled)
\r
331 utils.log("INFO", "Exited " + method, isDebugEnabled)
\r
334 public void postProcessAAIPUT(DelegateExecution execution) {
\r
335 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
336 utils.log("INFO"," ***** postProcessAAIPUT ***** ", isDebugEnabled)
\r
339 String serviceInstanceId = execution.getVariable("serviceInstanceId")
\r
340 boolean succInAAI = execution.getVariable("GENPS_SuccessIndicator")
\r
342 utils.log("INFO","Error putting Service-instance in AAI", + serviceInstanceId, isDebugEnabled)
\r
343 WorkflowException workflowException = execution.getVariable("WorkflowException")
\r
344 utils.logAudit("workflowException: " + workflowException)
\r
345 if(workflowException != null){
\r
346 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
\r
351 //start rollback set up
\r
352 RollbackData rollbackData = new RollbackData()
\r
353 def disableRollback = execution.getVariable("disableRollback")
\r
354 rollbackData.put("SERVICEINSTANCE", "disableRollback", disableRollback.toString())
\r
355 rollbackData.put("SERVICEINSTANCE", "rollbackAAI", "true")
\r
356 rollbackData.put("SERVICEINSTANCE", "serviceInstanceId", serviceInstanceId)
\r
357 rollbackData.put("SERVICEINSTANCE", "serviceType", execution.getVariable("serviceType"))
\r
358 rollbackData.put("SERVICEINSTANCE", "globalSubscriberId", execution.getVariable("globalSubscriberId"))
\r
359 execution.setVariable("rollbackData", rollbackData)
\r
362 } catch (BpmnError e) {
\r
364 } catch (Exception ex) {
\r
365 msg = "Exception in DoCreateServiceInstance.postProcessAAIDEL. " + ex.getMessage()
\r
366 utils.log("INFO", msg, isDebugEnabled)
\r
367 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
\r
369 utils.log("INFO"," *** Exit postProcessAAIPUT *** ", isDebugEnabled)
\r
372 public void preProcessRollback (DelegateExecution execution) {
\r
373 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
374 utils.log("INFO"," ***** preProcessRollback ***** ", isDebugEnabled)
\r
377 Object workflowException = execution.getVariable("WorkflowException");
\r
379 if (workflowException instanceof WorkflowException) {
\r
380 utils.log("INFO", "Prev workflowException: " + workflowException.getErrorMessage(), isDebugEnabled)
\r
381 execution.setVariable("prevWorkflowException", workflowException);
\r
382 //execution.setVariable("WorkflowException", null);
\r
384 } catch (BpmnError e) {
\r
385 utils.log("INFO", "BPMN Error during preProcessRollback", isDebugEnabled)
\r
386 } catch(Exception ex) {
\r
387 String msg = "Exception in preProcessRollback. " + ex.getMessage()
\r
388 utils.log("INFO", msg, isDebugEnabled)
\r
390 utils.log("INFO"," *** Exit preProcessRollback *** ", isDebugEnabled)
\r
393 public void postProcessRollback (DelegateExecution execution) {
\r
394 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
395 utils.log("INFO"," ***** postProcessRollback ***** ", isDebugEnabled)
\r
398 Object workflowException = execution.getVariable("prevWorkflowException");
\r
399 if (workflowException instanceof WorkflowException) {
\r
400 utils.log("INFO", "Setting prevException to WorkflowException: ", isDebugEnabled)
\r
401 execution.setVariable("WorkflowException", workflowException);
\r
403 execution.setVariable("rollbackData", null)
\r
404 } catch (BpmnError b) {
\r
405 utils.log("INFO", "BPMN Error during postProcessRollback", isDebugEnabled)
\r
407 } catch(Exception ex) {
\r
408 msg = "Exception in postProcessRollback. " + ex.getMessage()
\r
409 utils.log("INFO", msg, isDebugEnabled)
\r
411 utils.log("INFO"," *** Exit postProcessRollback *** ", isDebugEnabled)
\r
415 public void postConfigRequest(execution){
\r