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.onap.so.bpmn.infrastructure.scripts;
23 import static org.apache.commons.lang3.StringUtils.*;
25 import org.apache.commons.lang3.*
26 import org.camunda.bpm.engine.delegate.BpmnError
27 import org.camunda.bpm.engine.delegate.DelegateExecution
28 import org.onap.so.bpmn.common.scripts.AaiUtil
29 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
30 import org.onap.so.bpmn.common.scripts.CatalogDbUtils;
31 import org.onap.so.bpmn.common.scripts.ExceptionUtil
32 import org.onap.so.bpmn.common.scripts.MsoUtils
33 import org.onap.so.bpmn.core.RollbackData
34 import org.onap.so.bpmn.core.WorkflowException
35 import org.onap.so.bpmn.core.domain.Resource
36 import org.onap.so.bpmn.core.domain.ServiceDecomposition
37 import org.onap.so.bpmn.core.json.JsonUtils
38 import org.onap.so.logger.MessageEnum
39 import org.onap.so.logger.MsoLogger
40 import org.springframework.web.util.UriUtils;
47 * This groovy class supports the <class>DoCreateServiceInstance.bpmn</class> process.
50 * @param - msoRequestId
51 * @param - globalSubscriberId
52 * @param - subscriptionServiceType
53 * @param - serviceInstanceId
54 * @param - serviceInstanceName - O
55 * @param - serviceModelInfo
56 * @param - productFamilyId
57 * @param - disableRollback
58 * @param - failExists - TODO
59 * @param - serviceInputParams (should contain aic_zone for serviceTypes TRANSPORT,ATM)
60 * @param - sdncVersion ("1610")
61 * @param - serviceDecomposition - Decomposition for R1710
62 * (if macro provides serviceDecompsition then serviceModelInfo, serviceInstanceId & serviceInstanceName will be ignored)
65 * @param - rollbackData (localRB->null)
66 * @param - rolledBack (no localRB->null, localRB F->false, localRB S->true)
67 * @param - WorkflowException
68 * @param - serviceInstanceName - (GET from AAI if null in input)
71 public class DoCreateE2EServiceInstance extends AbstractServiceTaskProcessor {
72 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoCreateE2EServiceInstance.class);
75 String Prefix="DCRESI_"
76 ExceptionUtil exceptionUtil = new ExceptionUtil()
77 JsonUtils jsonUtil = new JsonUtils()
78 CatalogDbUtils cutils = new CatalogDbUtils()
80 public void preProcessRequest (DelegateExecution execution) {
82 msoLogger.trace("preProcessRequest ")
85 execution.setVariable("prefix", Prefix)
87 //requestDetails.subscriberInfo. for AAI GET & PUT & SDNC assignToplology
88 String globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId
89 msoLogger.info(" ***** globalSubscriberId *****" + globalSubscriberId)
90 //requestDetails.requestParameters. for AAI PUT & SDNC assignTopology
91 String serviceType = execution.getVariable("serviceType")
92 msoLogger.info(" ***** serviceType *****" + serviceType)
93 //requestDetails.requestParameters. for SDNC assignTopology
94 String productFamilyId = execution.getVariable("productFamilyId") //AAI productFamilyId
96 if (isBlank(globalSubscriberId)) {
97 msg = "Input globalSubscriberId is null"
99 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
102 if (isBlank(serviceType)) {
103 msg = "Input serviceType is null"
105 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
108 if (productFamilyId == null) {
109 execution.setVariable("productFamilyId", "")
112 String sdncCallbackUrl = execution.getVariable('URN_mso_workflow_sdncadapter_callback')
113 if (isBlank(sdncCallbackUrl)) {
114 msg = "URN_mso_workflow_sdncadapter_callback is null"
116 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
118 execution.setVariable("sdncCallbackUrl", sdncCallbackUrl)
119 msoLogger.info("SDNC Callback URL: " + sdncCallbackUrl)
121 //requestDetails.modelInfo.for AAI PUT servieInstanceData
122 //requestDetails.requestInfo. for AAI GET/PUT serviceInstanceData
123 String serviceInstanceName = execution.getVariable("serviceInstanceName")
124 String serviceInstanceId = execution.getVariable("serviceInstanceId")
125 String uuiRequest = execution.getVariable("uuiRequest")
126 String modelInvariantUuid = jsonUtil.getJsonValue(uuiRequest, "service.serviceInvariantUuid")
127 String modelUuid = jsonUtil.getJsonValue(uuiRequest, "service.serviceUuid")
128 String serviceModelName = jsonUtil.getJsonValue(uuiRequest, "service.parameters.templateName")
129 execution.setVariable("serviceModelName", serviceModelName)
130 //aai serviceType and Role can be setted as fixed value now.
131 String aaiServiceType = "E2E Service"
132 String aaiServiceRole = "E2E Service"
134 execution.setVariable("modelInvariantUuid", modelInvariantUuid)
135 execution.setVariable("modelUuid", modelUuid)
138 String oStatus = execution.getVariable("initialStatus") ?: ""
139 if ("TRANSPORT".equalsIgnoreCase(serviceType))
144 String statusLine = isBlank(oStatus) ? "" : "<orchestration-status>${MsoUtils.xmlEscape(oStatus)}</orchestration-status>"
146 AaiUtil aaiUriUtil = new AaiUtil(this)
147 String aai_uri = aaiUriUtil.getBusinessCustomerUri(execution)
148 String namespace = aaiUriUtil.getNamespaceFromUri(aai_uri)
149 String serviceInstanceData =
150 """<service-instance xmlns=\"${namespace}\">
151 <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceId)}</service-instance-id>
152 <service-instance-name>${MsoUtils.xmlEscape(serviceInstanceName)}</service-instance-name>
153 <service-type>${MsoUtils.xmlEscape(aaiServiceType)}</service-type>
154 <service-role>${MsoUtils.xmlEscape(aaiServiceRole)}</service-role>
156 <model-invariant-id>${MsoUtils.xmlEscape(modelInvariantUuid)}</model-invariant-id>
157 <model-version-id>${MsoUtils.xmlEscape(modelUuid)}</model-version-id>
158 </service-instance>""".trim()
159 execution.setVariable("serviceInstanceData", serviceInstanceData)
160 msoLogger.debug(serviceInstanceData)
161 msoLogger.info(" aai_uri " + aai_uri + " namespace:" + namespace)
162 msoLogger.info(" 'payload' to create Service Instance in AAI - " + "\n" + serviceInstanceData)
164 } catch (BpmnError e) {
166 } catch (Exception ex){
167 msg = "Exception in preProcessRequest " + ex.getMessage()
169 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
171 msoLogger.trace("Exit preProcessRequest ")
174 public void prepareDecomposeService(DelegateExecution execution) {
176 msoLogger.trace("Inside prepareDecomposeService of create generic e2e service ")
177 String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
178 String modelUuid = execution.getVariable("modelUuid")
179 //here modelVersion is not set, we use modelUuid to decompose the service.
180 String serviceModelInfo = """{
181 "modelInvariantUuid":"${modelInvariantUuid}",
182 "modelUuid":"${modelUuid}",
185 execution.setVariable("serviceModelInfo", serviceModelInfo)
187 msoLogger.trace("Completed prepareDecomposeService of create generic e2e service ")
188 } catch (Exception ex) {
189 // try error in method block
190 String exceptionMessage = "Bpmn error encountered in create generic e2e service flow. Unexpected Error from method prepareDecomposeService() - " + ex.getMessage()
191 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
195 public void processDecomposition(DelegateExecution execution) {
196 msoLogger.trace("Inside processDecomposition() of create generic e2e service flow ")
198 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
199 } catch (Exception ex) {
200 String exceptionMessage = "Bpmn error encountered in create generic e2e service flow. processDecomposition() - " + ex.getMessage()
201 msoLogger.debug(exceptionMessage)
202 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
206 public void doServicePreOperation(DelegateExecution execution){
207 //we need a service plugin platform here.
208 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
209 String uuiRequest = execution.getVariable("uuiRequest")
210 String newUuiRequest = ServicePluginFactory.getInstance().preProcessService(serviceDecomposition, uuiRequest);
211 execution.setVariable("uuiRequest", newUuiRequest)
214 public void doServiceHoming(DelegateExecution execution) {
215 //we need a service plugin platform here.
216 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
217 String uuiRequest = execution.getVariable("uuiRequest")
218 String newUuiRequest = ServicePluginFactory.getInstance().doServiceHoming(serviceDecomposition, uuiRequest);
219 execution.setVariable("uuiRequest", newUuiRequest)
222 public void postProcessAAIGET(DelegateExecution execution) {
223 msoLogger.trace("postProcessAAIGET ")
227 String serviceInstanceName = execution.getVariable("serviceInstanceName")
228 boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")
230 msoLogger.info("Error getting Service-instance from AAI", + serviceInstanceName)
231 WorkflowException workflowException = execution.getVariable("WorkflowException")
232 msoLogger.debug("workflowException: " + workflowException)
233 if(workflowException != null){
234 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
238 msg = "Failure in postProcessAAIGET GENGS_SuccessIndicator:" + succInAAI
240 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
245 boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")
247 msoLogger.info("Found Service-instance in AAI")
248 msg = "ServiceInstance already exists in AAI:" + serviceInstanceName
250 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
253 } catch (BpmnError e) {
255 } catch (Exception ex) {
256 msg = "Exception in DoCreateServiceInstance.postProcessAAIGET. " + ex.getMessage()
258 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
260 msoLogger.trace("Exit postProcessAAIGET ")
263 public void postProcessAAIPUT(DelegateExecution execution) {
264 msoLogger.trace("postProcessAAIPUT ")
267 String serviceInstanceId = execution.getVariable("serviceInstanceId")
268 boolean succInAAI = execution.getVariable("GENPS_SuccessIndicator")
270 msoLogger.info("Error putting Service-instance in AAI", + serviceInstanceId)
271 WorkflowException workflowException = execution.getVariable("WorkflowException")
272 msoLogger.debug("workflowException: " + workflowException)
273 if(workflowException != null){
274 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
279 //start rollback set up
280 RollbackData rollbackData = new RollbackData()
281 def disableRollback = execution.getVariable("disableRollback")
282 rollbackData.put("SERVICEINSTANCE", "disableRollback", disableRollback.toString())
283 rollbackData.put("SERVICEINSTANCE", "rollbackAAI", "true")
284 rollbackData.put("SERVICEINSTANCE", "serviceInstanceId", serviceInstanceId)
285 rollbackData.put("SERVICEINSTANCE", "subscriptionServiceType", execution.getVariable("subscriptionServiceType"))
286 rollbackData.put("SERVICEINSTANCE", "globalSubscriberId", execution.getVariable("globalSubscriberId"))
287 execution.setVariable("rollbackData", rollbackData)
290 } catch (BpmnError e) {
292 } catch (Exception ex) {
293 msg = "Exception in DoCreateServiceInstance.postProcessAAIDEL. " + ex.getMessage()
295 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
297 msoLogger.trace("Exit postProcessAAIPUT ")
300 public void postProcessAAIGET2(DelegateExecution execution) {
301 msoLogger.trace("postProcessAAIGET2 ")
305 String serviceInstanceName = execution.getVariable("serviceInstanceName")
306 boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")
308 msoLogger.info("Error getting Service-instance from AAI in postProcessAAIGET2", + serviceInstanceName)
309 WorkflowException workflowException = execution.getVariable("WorkflowException")
310 msoLogger.debug("workflowException: " + workflowException)
311 if(workflowException != null){
312 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
316 msg = "Failure in postProcessAAIGET2 GENGS_SuccessIndicator:" + succInAAI
318 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
323 boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")
325 String aaiService = execution.getVariable("GENGS_service")
326 if (!isBlank(aaiService) && (utils.nodeExists(aaiService, "service-instance-name"))) {
327 execution.setVariable("serviceInstanceName", utils.getNodeText(aaiService, "service-instance-name"))
328 msoLogger.info("Found Service-instance in AAI.serviceInstanceName:" + execution.getVariable("serviceInstanceName"))
332 } catch (BpmnError e) {
334 } catch (Exception ex) {
335 msg = "Exception in DoCreateServiceInstance.postProcessAAIGET2 " + ex.getMessage()
337 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
339 msoLogger.trace("Exit postProcessAAIGET2 ")
342 public void preProcessRollback (DelegateExecution execution) {
343 msoLogger.trace("preProcessRollback ")
346 Object workflowException = execution.getVariable("WorkflowException");
348 if (workflowException instanceof WorkflowException) {
349 msoLogger.info("Prev workflowException: " + workflowException.getErrorMessage())
350 execution.setVariable("prevWorkflowException", workflowException);
351 //execution.setVariable("WorkflowException", null);
353 } catch (BpmnError e) {
354 msoLogger.info("BPMN Error during preProcessRollback")
355 } catch(Exception ex) {
356 String msg = "Exception in preProcessRollback. " + ex.getMessage()
359 msoLogger.trace("Exit preProcessRollback ")
362 public void postProcessRollback (DelegateExecution execution) {
363 msoLogger.trace("postProcessRollback ")
366 Object workflowException = execution.getVariable("prevWorkflowException");
367 if (workflowException instanceof WorkflowException) {
368 msoLogger.info("Setting prevException to WorkflowException: ")
369 execution.setVariable("WorkflowException", workflowException);
371 execution.setVariable("rollbackData", null)
372 } catch (BpmnError b) {
373 msoLogger.info("BPMN Error during postProcessRollback")
375 } catch(Exception ex) {
376 msg = "Exception in postProcessRollback. " + ex.getMessage()
379 msoLogger.trace("Exit postProcessRollback ")
382 public void preInitResourcesOperStatus(DelegateExecution execution){
383 msoLogger.trace("STARTED preInitResourcesOperStatus Process ")
385 String serviceId = execution.getVariable("serviceInstanceId")
386 String operationId = execution.getVariable("operationId")
387 String operationType = execution.getVariable("operationType")
388 String resourceTemplateUUIDs = ""
389 String result = "processing"
390 String progress = "0"
392 String operationContent = "Prepare service creation"
393 msoLogger.info("Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId + " operationType:" + operationType)
394 serviceId = UriUtils.encode(serviceId,"UTF-8")
395 execution.setVariable("serviceInstanceId", serviceId)
396 execution.setVariable("operationId", operationId)
397 execution.setVariable("operationType", operationType)
398 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
399 List<Resource> resourceList = serviceDecomposition.getServiceResources()
401 for(Resource resource : resourceList){
402 resourceTemplateUUIDs = resourceTemplateUUIDs + resource.getModelInfo().getModelCustomizationUuid() + ":"
405 def dbAdapterEndpoint = "http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter"
406 execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
407 msoLogger.info("DB Adapter Endpoint is: " + dbAdapterEndpoint)
410 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
411 xmlns:ns="http://org.onap.so/requestsdb">
414 <ns:initResourceOperationStatus xmlns:ns="http://org.onap.so/requestsdb">
415 <serviceId>${MsoUtils.xmlEscape(serviceId)}</serviceId>
416 <operationId>${MsoUtils.xmlEscape(operationId)}</operationId>
417 <operationType>${MsoUtils.xmlEscape(operationType)}</operationType>
418 <resourceTemplateUUIDs>${MsoUtils.xmlEscape(resourceTemplateUUIDs)}</resourceTemplateUUIDs>
419 </ns:initResourceOperationStatus>
421 </soapenv:Envelope>"""
423 payload = utils.formatXml(payload)
424 execution.setVariable("CVFMI_initResOperStatusRequest", payload)
425 msoLogger.info("Outgoing initResourceOperationStatus: \n" + payload)
426 msoLogger.debug("CreateVfModuleInfra Outgoing initResourceOperationStatus Request: " + payload)
429 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occured Processing preInitResourcesOperStatus.", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e);
430 execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during preInitResourcesOperStatus Method:\n" + e.getMessage())
432 msoLogger.trace("COMPLETED preInitResourcesOperStatus Process ")
435 // prepare input param for using DoCreateResources.bpmn
436 public void preProcessForAddResource(DelegateExecution execution) {
437 msoLogger.trace("STARTED preProcessForAddResource Process ")
439 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
440 List<Resource> addResourceList = serviceDecomposition.getServiceResources()
441 execution.setVariable("addResourceList", addResourceList)
443 msoLogger.trace("COMPLETED preProcessForAddResource Process ")
446 public void postProcessForAddResource(DelegateExecution execution) {