2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 package org.openecomp.mso.bpmn.infrastructure.scripts;
23 import static org.apache.commons.lang3.StringUtils.*;
24 import org.apache.http.HttpResponse
25 import groovy.xml.XmlUtil
28 import org.openecomp.mso.bpmn.core.domain.ServiceDecomposition
29 import org.openecomp.mso.bpmn.core.domain.ServiceInstance
30 import org.openecomp.mso.bpmn.core.domain.ModelInfo
31 import org.openecomp.mso.bpmn.core.domain.Resource
32 import org.openecomp.mso.bpmn.core.domain.AllottedResource
33 import org.openecomp.mso.bpmn.core.domain.NetworkResource
34 import org.openecomp.mso.bpmn.core.domain.VnfResource
35 import org.openecomp.mso.bpmn.common.recipe.ResourceInput
36 import org.openecomp.mso.bpmn.common.resource.ResourceRequestBuilder;
37 import org.openecomp.mso.bpmn.common.recipe.BpmnRestClient
38 import org.openecomp.mso.bpmn.core.json.JsonUtils
39 import org.openecomp.mso.bpmn.common.scripts.AaiUtil
40 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
41 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
42 import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils
43 import org.openecomp.mso.bpmn.common.scripts.CatalogDbUtils;
44 import org.openecomp.mso.bpmn.core.RollbackData
45 import org.openecomp.mso.bpmn.core.WorkflowException
46 import org.openecomp.mso.rest.APIResponse;
47 import org.openecomp.mso.rest.RESTClient
48 import org.openecomp.mso.rest.RESTConfig
49 import org.openecomp.mso.bpmn.infrastructure.workflow.service.ServicePluginFactory
51 import java.util.List;
52 import java.util.UUID;
54 import org.camunda.bpm.engine.delegate.BpmnError
55 import org.camunda.bpm.engine.delegate.DelegateExecution
56 import org.json.JSONObject;
57 import org.json.JSONArray;
58 import org.apache.commons.lang3.*
59 import org.apache.commons.codec.binary.Base64;
60 import org.springframework.web.util.UriUtils;
63 * This groovy class supports the <class>DoCreateServiceInstance.bpmn</class> process.
66 * @param - msoRequestId
67 * @param - globalSubscriberId
68 * @param - subscriptionServiceType
69 * @param - serviceInstanceId
70 * @param - serviceInstanceName - O
71 * @param - serviceModelInfo
72 * @param - productFamilyId
73 * @param - disableRollback
74 * @param - failExists - TODO
75 * @param - serviceInputParams (should contain aic_zone for serviceTypes TRANSPORT,ATM)
76 * @param - sdncVersion ("1610")
77 * @param - serviceDecomposition - Decomposition for R1710
78 * (if macro provides serviceDecompsition then serviceModelInfo, serviceInstanceId & serviceInstanceName will be ignored)
81 * @param - rollbackData (localRB->null)
82 * @param - rolledBack (no localRB->null, localRB F->false, localRB S->true)
83 * @param - WorkflowException
84 * @param - serviceInstanceName - (GET from AAI if null in input)
87 public class DoCreateE2EServiceInstance extends AbstractServiceTaskProcessor {
89 String Prefix="DCRESI_"
90 ExceptionUtil exceptionUtil = new ExceptionUtil()
91 JsonUtils jsonUtil = new JsonUtils()
92 CatalogDbUtils cutils = new CatalogDbUtils()
94 public void preProcessRequest (DelegateExecution execution) {
95 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
97 utils.log("INFO"," ***** preProcessRequest *****", isDebugEnabled)
100 execution.setVariable("prefix", Prefix)
102 //requestDetails.subscriberInfo. for AAI GET & PUT & SDNC assignToplology
103 String globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId
104 utils.log("INFO"," ***** globalSubscriberId *****" + globalSubscriberId, isDebugEnabled)
105 //requestDetails.requestParameters. for AAI PUT & SDNC assignTopology
106 String serviceType = execution.getVariable("serviceType")
107 utils.log("INFO"," ***** serviceType *****" + serviceType, isDebugEnabled)
108 //requestDetails.requestParameters. for SDNC assignTopology
109 String productFamilyId = execution.getVariable("productFamilyId") //AAI productFamilyId
111 if (isBlank(globalSubscriberId)) {
112 msg = "Input globalSubscriberId is null"
113 utils.log("INFO", msg, isDebugEnabled)
114 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
117 if (isBlank(serviceType)) {
118 msg = "Input serviceType is null"
119 utils.log("INFO", msg, isDebugEnabled)
120 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
123 if (productFamilyId == null) {
124 execution.setVariable("productFamilyId", "")
127 String sdncCallbackUrl = execution.getVariable('URN_mso_workflow_sdncadapter_callback')
128 if (isBlank(sdncCallbackUrl)) {
129 msg = "URN_mso_workflow_sdncadapter_callback is null"
130 utils.log("INFO", msg, isDebugEnabled)
131 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
133 execution.setVariable("sdncCallbackUrl", sdncCallbackUrl)
134 utils.log("INFO","SDNC Callback URL: " + sdncCallbackUrl, isDebugEnabled)
136 //requestDetails.modelInfo.for AAI PUT servieInstanceData
137 //requestDetails.requestInfo. for AAI GET/PUT serviceInstanceData
138 String serviceInstanceName = execution.getVariable("serviceInstanceName")
139 String serviceInstanceId = execution.getVariable("serviceInstanceId")
140 String uuiRequest = execution.getVariable("uuiRequest")
141 String modelInvariantUuid = jsonUtil.getJsonValue(uuiRequest, "service.serviceInvariantUuid")
142 String modelUuid = jsonUtil.getJsonValue(uuiRequest, "service.serviceUuid")
143 String serviceModelName = jsonUtil.getJsonValue(uuiRequest, "service.parameters.templateName")
144 execution.setVariable("serviceModelName", serviceModelName)
145 //aai serviceType and Role can be setted as fixed value now.
146 String aaiServiceType = "E2E Service"
147 String aaiServiceRole = "E2E Service"
149 execution.setVariable("modelInvariantUuid", modelInvariantUuid)
150 execution.setVariable("modelUuid", modelUuid)
153 String oStatus = execution.getVariable("initialStatus") ?: ""
154 if ("TRANSPORT".equalsIgnoreCase(serviceType))
159 String statusLine = isBlank(oStatus) ? "" : "<orchestration-status>${oStatus}</orchestration-status>"
161 AaiUtil aaiUriUtil = new AaiUtil(this)
162 String aai_uri = aaiUriUtil.getBusinessCustomerUri(execution)
163 String namespace = aaiUriUtil.getNamespaceFromUri(aai_uri)
164 String serviceInstanceData =
165 """<service-instance xmlns=\"${namespace}\">
166 <service-instance-id>${serviceInstanceId}</service-instance-id>
167 <service-instance-name>${serviceInstanceName}</service-instance-name>
168 <service-type>${aaiServiceType}</service-type>
169 <service-role>${aaiServiceRole}</service-role>
171 <model-invariant-id>${modelInvariantUuid}</model-invariant-id>
172 <model-version-id>${modelUuid}</model-version-id>
173 </service-instance>""".trim()
174 execution.setVariable("serviceInstanceData", serviceInstanceData)
175 utils.logAudit(serviceInstanceData)
176 utils.log("INFO", " aai_uri " + aai_uri + " namespace:" + namespace, isDebugEnabled)
177 utils.log("INFO", " 'payload' to create Service Instance in AAI - " + "\n" + serviceInstanceData, isDebugEnabled)
179 } catch (BpmnError e) {
181 } catch (Exception ex){
182 msg = "Exception in preProcessRequest " + ex.getMessage()
183 utils.log("INFO", msg, isDebugEnabled)
184 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
186 utils.log("INFO"," ***** Exit preProcessRequest *****", isDebugEnabled)
189 public void prepareDecomposeService(DelegateExecution execution) {
190 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
193 utils.log("INFO", " ***** Inside prepareDecomposeService of create generic e2e service ***** ", isDebugEnabled)
194 String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
195 String modelUuid = execution.getVariable("modelUuid")
196 //here modelVersion is not set, we use modelUuid to decompose the service.
197 String serviceModelInfo = """{
198 "modelInvariantUuid":"${modelInvariantUuid}",
199 "modelUuid":"${modelUuid}",
202 execution.setVariable("serviceModelInfo", serviceModelInfo)
204 utils.log("DEBUG", " ***** Completed prepareDecomposeService of create generic e2e service ***** ", isDebugEnabled)
205 } catch (Exception ex) {
206 // try error in method block
207 String exceptionMessage = "Bpmn error encountered in create generic e2e service flow. Unexpected Error from method prepareDecomposeService() - " + ex.getMessage()
208 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
212 public void processDecomposition(DelegateExecution execution) {
213 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
215 utils.log("INFO", " ***** Inside processDecomposition() of create generic e2e service flow ***** ", isDebugEnabled)
217 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
218 } catch (Exception ex) {
219 String exceptionMessage = "Bpmn error encountered in create generic e2e service flow. processDecomposition() - " + ex.getMessage()
220 utils.log("INFO", exceptionMessage, isDebugEnabled)
221 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
225 public void doServicePreOperation(DelegateExecution execution){
226 //we need a service plugin platform here.
227 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
228 String uuiRequest = execution.getVariable("uuiRequest")
229 String newUuiRequest = ServicePluginFactory.getInstance().preProcessService(serviceDecomposition, uuiRequest);
230 execution.setVariable("uuiRequest", newUuiRequest)
233 public void doServiceHoming(DelegateExecution execution) {
234 //we need a service plugin platform here.
235 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
236 String uuiRequest = execution.getVariable("uuiRequest")
237 String newUuiRequest = ServicePluginFactory.getInstance().doServiceHoming(serviceDecomposition, uuiRequest);
238 execution.setVariable("uuiRequest", newUuiRequest)
241 public void postProcessAAIGET(DelegateExecution execution) {
242 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
243 utils.log("INFO"," ***** postProcessAAIGET ***** ", isDebugEnabled)
247 String serviceInstanceName = execution.getVariable("serviceInstanceName")
248 boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")
250 utils.log("INFO","Error getting Service-instance from AAI", + serviceInstanceName, isDebugEnabled)
251 WorkflowException workflowException = execution.getVariable("WorkflowException")
252 utils.logAudit("workflowException: " + workflowException)
253 if(workflowException != null){
254 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
258 msg = "Failure in postProcessAAIGET GENGS_SuccessIndicator:" + succInAAI
259 utils.log("INFO", msg, isDebugEnabled)
260 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
265 boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")
267 utils.log("INFO","Found Service-instance in AAI", isDebugEnabled)
268 msg = "ServiceInstance already exists in AAI:" + serviceInstanceName
269 utils.log("INFO", msg, isDebugEnabled)
270 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
273 } catch (BpmnError e) {
275 } catch (Exception ex) {
276 msg = "Exception in DoCreateServiceInstance.postProcessAAIGET. " + ex.getMessage()
277 utils.log("INFO", msg, isDebugEnabled)
278 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
280 utils.log("INFO"," *** Exit postProcessAAIGET *** ", isDebugEnabled)
283 public void postProcessAAIPUT(DelegateExecution execution) {
284 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
285 utils.log("INFO"," ***** postProcessAAIPUT ***** ", isDebugEnabled)
288 String serviceInstanceId = execution.getVariable("serviceInstanceId")
289 boolean succInAAI = execution.getVariable("GENPS_SuccessIndicator")
291 utils.log("INFO","Error putting Service-instance in AAI", + serviceInstanceId, isDebugEnabled)
292 WorkflowException workflowException = execution.getVariable("WorkflowException")
293 utils.logAudit("workflowException: " + workflowException)
294 if(workflowException != null){
295 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
300 //start rollback set up
301 RollbackData rollbackData = new RollbackData()
302 def disableRollback = execution.getVariable("disableRollback")
303 rollbackData.put("SERVICEINSTANCE", "disableRollback", disableRollback.toString())
304 rollbackData.put("SERVICEINSTANCE", "rollbackAAI", "true")
305 rollbackData.put("SERVICEINSTANCE", "serviceInstanceId", serviceInstanceId)
306 rollbackData.put("SERVICEINSTANCE", "subscriptionServiceType", execution.getVariable("subscriptionServiceType"))
307 rollbackData.put("SERVICEINSTANCE", "globalSubscriberId", execution.getVariable("globalSubscriberId"))
308 execution.setVariable("rollbackData", rollbackData)
311 } catch (BpmnError e) {
313 } catch (Exception ex) {
314 msg = "Exception in DoCreateServiceInstance.postProcessAAIDEL. " + ex.getMessage()
315 utils.log("INFO", msg, isDebugEnabled)
316 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
318 utils.log("INFO"," *** Exit postProcessAAIPUT *** ", isDebugEnabled)
321 public void postProcessAAIGET2(DelegateExecution execution) {
322 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
323 utils.log("INFO"," ***** postProcessAAIGET2 ***** ", isDebugEnabled)
327 String serviceInstanceName = execution.getVariable("serviceInstanceName")
328 boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")
330 utils.log("INFO","Error getting Service-instance from AAI in postProcessAAIGET2", + serviceInstanceName, isDebugEnabled)
331 WorkflowException workflowException = execution.getVariable("WorkflowException")
332 utils.logAudit("workflowException: " + workflowException)
333 if(workflowException != null){
334 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
338 msg = "Failure in postProcessAAIGET2 GENGS_SuccessIndicator:" + succInAAI
339 utils.log("INFO", msg, isDebugEnabled)
340 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
345 boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")
347 String aaiService = execution.getVariable("GENGS_service")
348 if (!isBlank(aaiService) && (utils.nodeExists(aaiService, "service-instance-name"))) {
349 execution.setVariable("serviceInstanceName", utils.getNodeText1(aaiService, "service-instance-name"))
350 utils.log("INFO","Found Service-instance in AAI.serviceInstanceName:" + execution.getVariable("serviceInstanceName"), isDebugEnabled)
354 } catch (BpmnError e) {
356 } catch (Exception ex) {
357 msg = "Exception in DoCreateServiceInstance.postProcessAAIGET2 " + ex.getMessage()
358 utils.log("INFO", msg, isDebugEnabled)
359 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
361 utils.log("INFO"," *** Exit postProcessAAIGET2 *** ", isDebugEnabled)
364 public void preProcessRollback (DelegateExecution execution) {
365 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
366 utils.log("INFO"," ***** preProcessRollback ***** ", isDebugEnabled)
369 Object workflowException = execution.getVariable("WorkflowException");
371 if (workflowException instanceof WorkflowException) {
372 utils.log("INFO", "Prev workflowException: " + workflowException.getErrorMessage(), isDebugEnabled)
373 execution.setVariable("prevWorkflowException", workflowException);
374 //execution.setVariable("WorkflowException", null);
376 } catch (BpmnError e) {
377 utils.log("INFO", "BPMN Error during preProcessRollback", isDebugEnabled)
378 } catch(Exception ex) {
379 String msg = "Exception in preProcessRollback. " + ex.getMessage()
380 utils.log("INFO", msg, isDebugEnabled)
382 utils.log("INFO"," *** Exit preProcessRollback *** ", isDebugEnabled)
385 public void postProcessRollback (DelegateExecution execution) {
386 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
387 utils.log("INFO"," ***** postProcessRollback ***** ", isDebugEnabled)
390 Object workflowException = execution.getVariable("prevWorkflowException");
391 if (workflowException instanceof WorkflowException) {
392 utils.log("INFO", "Setting prevException to WorkflowException: ", isDebugEnabled)
393 execution.setVariable("WorkflowException", workflowException);
395 execution.setVariable("rollbackData", null)
396 } catch (BpmnError b) {
397 utils.log("INFO", "BPMN Error during postProcessRollback", isDebugEnabled)
399 } catch(Exception ex) {
400 msg = "Exception in postProcessRollback. " + ex.getMessage()
401 utils.log("INFO", msg, isDebugEnabled)
403 utils.log("INFO"," *** Exit postProcessRollback *** ", isDebugEnabled)
406 public void preInitResourcesOperStatus(DelegateExecution execution){
407 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
409 utils.log("INFO", " ======== STARTED preInitResourcesOperStatus Process ======== ", isDebugEnabled)
411 String serviceId = execution.getVariable("serviceInstanceId")
412 String operationId = execution.getVariable("operationId")
413 String operationType = execution.getVariable("operationType")
414 String resourceTemplateUUIDs = ""
415 String result = "processing"
416 String progress = "0"
418 String operationContent = "Prepare service creation"
419 utils.log("INFO", "Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId + " operationType:" + operationType, isDebugEnabled)
420 serviceId = UriUtils.encode(serviceId,"UTF-8")
421 execution.setVariable("serviceInstanceId", serviceId)
422 execution.setVariable("operationId", operationId)
423 execution.setVariable("operationType", operationType)
424 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
425 List<Resource> resourceList = serviceDecomposition.getServiceResources()
427 for(Resource resource : resourceList){
428 resourceTemplateUUIDs = resourceTemplateUUIDs + resource.getModelInfo().getModelCustomizationUuid() + ":"
431 def dbAdapterEndpoint = "http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter"
432 execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
433 utils.log("INFO", "DB Adapter Endpoint is: " + dbAdapterEndpoint, isDebugEnabled)
436 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
437 xmlns:ns="http://org.openecomp.mso/requestsdb">
440 <ns:initResourceOperationStatus xmlns:ns="http://org.openecomp.mso/requestsdb">
441 <serviceId>${serviceId}</serviceId>
442 <operationId>${operationId}</operationId>
443 <operationType>${operationType}</operationType>
444 <resourceTemplateUUIDs>${resourceTemplateUUIDs}</resourceTemplateUUIDs>
445 </ns:initResourceOperationStatus>
447 </soapenv:Envelope>"""
449 payload = utils.formatXml(payload)
450 execution.setVariable("CVFMI_initResOperStatusRequest", payload)
451 utils.log("INFO", "Outgoing initResourceOperationStatus: \n" + payload, isDebugEnabled)
452 utils.logAudit("CreateVfModuleInfra Outgoing initResourceOperationStatus Request: " + payload)
455 utils.log("ERROR", "Exception Occured Processing preInitResourcesOperStatus. Exception is:\n" + e, isDebugEnabled)
456 execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during preInitResourcesOperStatus Method:\n" + e.getMessage())
458 utils.log("INFO", "======== COMPLETED preInitResourcesOperStatus Process ======== ", isDebugEnabled)
461 // prepare input param for using DoCreateResources.bpmn
462 public void preProcessForAddResource(DelegateExecution execution) {
463 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
464 utils.log("INFO", " ======== STARTED preProcessForAddResource Process ======== ", isDebugEnabled)
466 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
467 List<Resource> addResourceList = serviceDecomposition.getServiceResources()
468 execution.setVariable("addResourceList", addResourceList)
470 utils.log("INFO", "======== COMPLETED preProcessForAddResource Process ======== ", isDebugEnabled)
473 public void postProcessForAddResource(DelegateExecution execution) {
474 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")