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 javax.ws.rs.NotFoundException
27 import org.apache.commons.lang3.*
28 import org.camunda.bpm.engine.delegate.BpmnError
29 import org.camunda.bpm.engine.delegate.DelegateExecution
30 import org.onap.aai.domain.yang.ServiceInstance
31 import org.onap.so.bpmn.common.scripts.AaiUtil
32 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
33 import org.onap.so.bpmn.common.scripts.CatalogDbUtils;
34 import org.onap.so.bpmn.common.scripts.ExceptionUtil
35 import org.onap.so.bpmn.common.scripts.MsoUtils
36 import org.onap.so.bpmn.core.RollbackData
37 import org.onap.so.bpmn.core.WorkflowException
38 import org.onap.so.bpmn.core.domain.Resource
39 import org.onap.so.bpmn.core.domain.ServiceDecomposition
40 import org.onap.so.bpmn.core.json.JsonUtils
41 import org.onap.so.client.aai.AAIObjectType
42 import org.onap.so.client.aai.AAIResourcesClient
43 import org.onap.so.client.aai.entities.AAIResultWrapper
44 import org.onap.so.client.aai.entities.uri.AAIResourceUri
45 import org.onap.so.bpmn.infrastructure.workflow.service.ServicePluginFactory
46 import org.onap.so.client.aai.entities.uri.AAIUriFactory
47 import org.onap.so.logger.MessageEnum
48 import org.onap.so.logger.MsoLogger
49 import org.onap.so.rest.APIResponse
50 import org.springframework.web.util.UriUtils
51 import org.onap.so.bpmn.core.UrnPropertiesReader
58 * This groovy class supports the <class>DoCreateServiceInstance.bpmn</class> process.
61 * @param - msoRequestId
62 * @param - globalSubscriberId
63 * @param - subscriptionServiceType
64 * @param - serviceInstanceId
65 * @param - serviceInstanceName - O
66 * @param - serviceModelInfo
67 * @param - productFamilyId
68 * @param - disableRollback
69 * @param - failExists - TODO
70 * @param - serviceInputParams (should contain aic_zone for serviceTypes TRANSPORT,ATM)
71 * @param - sdncVersion ("1610")
72 * @param - serviceDecomposition - Decomposition for R1710
73 * (if macro provides serviceDecompsition then serviceModelInfo, serviceInstanceId & serviceInstanceName will be ignored)
76 * @param - rollbackData (localRB->null)
77 * @param - rolledBack (no localRB->null, localRB F->false, localRB S->true)
78 * @param - WorkflowException
79 * @param - serviceInstanceName - (GET from AAI if null in input)
82 public class DoCreateE2EServiceInstance extends AbstractServiceTaskProcessor {
83 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoCreateE2EServiceInstance.class);
86 String Prefix="DCRESI_"
87 ExceptionUtil exceptionUtil = new ExceptionUtil()
88 JsonUtils jsonUtil = new JsonUtils()
89 CatalogDbUtils cutils = new CatalogDbUtils()
91 public void preProcessRequest (DelegateExecution execution) {
93 msoLogger.trace("preProcessRequest ")
96 execution.setVariable("prefix", Prefix)
98 //requestDetails.subscriberInfo. for AAI GET & PUT & SDNC assignToplology
99 String globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId
100 msoLogger.info(" ***** globalSubscriberId *****" + globalSubscriberId)
101 //requestDetails.requestParameters. for AAI PUT & SDNC assignTopology
102 String serviceType = execution.getVariable("serviceType")
103 msoLogger.info(" ***** serviceType *****" + serviceType)
104 //requestDetails.requestParameters. for SDNC assignTopology
105 String productFamilyId = execution.getVariable("productFamilyId") //AAI productFamilyId
107 if (isBlank(globalSubscriberId)) {
108 msg = "Input globalSubscriberId is null"
110 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
113 if (isBlank(serviceType)) {
114 msg = "Input serviceType is null"
116 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
119 if (productFamilyId == null) {
120 execution.setVariable("productFamilyId", "")
123 String sdncCallbackUrl = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback", execution)
124 if (isBlank(sdncCallbackUrl)) {
125 msg = "URN_mso_workflow_sdncadapter_callback is null"
127 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
129 execution.setVariable("sdncCallbackUrl", sdncCallbackUrl)
130 msoLogger.info("SDNC Callback URL: " + sdncCallbackUrl)
132 //requestDetails.modelInfo.for AAI PUT servieInstanceData
133 //requestDetails.requestInfo. for AAI GET/PUT serviceInstanceData
134 String serviceInstanceName = execution.getVariable("serviceInstanceName")
135 String serviceInstanceId = execution.getVariable("serviceInstanceId")
136 String uuiRequest = execution.getVariable("uuiRequest")
137 String modelInvariantUuid = jsonUtil.getJsonValue(uuiRequest, "service.serviceInvariantUuid")
138 String modelUuid = jsonUtil.getJsonValue(uuiRequest, "service.serviceUuid")
139 String serviceModelName = jsonUtil.getJsonValue(uuiRequest, "service.parameters.templateName")
140 execution.setVariable("serviceModelName", serviceModelName)
141 //aai serviceType and Role can be setted as fixed value now.
142 String aaiServiceType = "E2E Service"
143 String aaiServiceRole = "E2E Service"
145 execution.setVariable("modelInvariantUuid", modelInvariantUuid)
146 execution.setVariable("modelUuid", modelUuid)
149 String oStatus = execution.getVariable("initialStatus") ?: ""
150 if ("TRANSPORT".equalsIgnoreCase(serviceType))
155 String statusLine = isBlank(oStatus) ? "" : "<orchestration-status>${MsoUtils.xmlEscape(oStatus)}</orchestration-status>"
157 AaiUtil aaiUriUtil = new AaiUtil(this)
158 String aai_uri = aaiUriUtil.getBusinessCustomerUri(execution)
159 String namespace = aaiUriUtil.getNamespaceFromUri(aai_uri)
160 String serviceInstanceData =
161 """<service-instance xmlns=\"${namespace}\">
162 <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceId)}</service-instance-id>
163 <service-instance-name>${MsoUtils.xmlEscape(serviceInstanceName)}</service-instance-name>
164 <service-type>${MsoUtils.xmlEscape(aaiServiceType)}</service-type>
165 <service-role>${MsoUtils.xmlEscape(aaiServiceRole)}</service-role>
167 <model-invariant-id>${MsoUtils.xmlEscape(modelInvariantUuid)}</model-invariant-id>
168 <model-version-id>${MsoUtils.xmlEscape(modelUuid)}</model-version-id>
169 <input-parameters>${MsoUtils.xmlEscape(uuiRequest)}</input-parameters>
170 </service-instance>""".trim()
171 execution.setVariable("serviceInstanceData", serviceInstanceData)
172 msoLogger.debug(serviceInstanceData)
173 msoLogger.info(" aai_uri " + aai_uri + " namespace:" + namespace)
174 msoLogger.info(" 'payload' to create Service Instance in AAI - " + "\n" + serviceInstanceData)
176 } catch (BpmnError e) {
178 } catch (Exception ex){
179 msg = "Exception in preProcessRequest " + ex.getMessage()
181 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
183 msoLogger.trace("Exit preProcessRequest ")
186 public void prepareDecomposeService(DelegateExecution execution) {
188 msoLogger.trace("Inside prepareDecomposeService of create generic e2e service ")
189 String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
190 String modelUuid = execution.getVariable("modelUuid")
191 //here modelVersion is not set, we use modelUuid to decompose the service.
192 String serviceModelInfo = """{
193 "modelInvariantUuid":"${modelInvariantUuid}",
194 "modelUuid":"${modelUuid}",
197 execution.setVariable("serviceModelInfo", serviceModelInfo)
199 msoLogger.trace("Completed prepareDecomposeService of create generic e2e service ")
200 } catch (Exception ex) {
201 // try error in method block
202 String exceptionMessage = "Bpmn error encountered in create generic e2e service flow. Unexpected Error from method prepareDecomposeService() - " + ex.getMessage()
203 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
207 public void processDecomposition(DelegateExecution execution) {
208 msoLogger.trace("Inside processDecomposition() of create generic e2e service flow ")
210 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
211 } catch (Exception ex) {
212 String exceptionMessage = "Bpmn error encountered in create generic e2e service flow. processDecomposition() - " + ex.getMessage()
213 msoLogger.debug(exceptionMessage)
214 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
218 public void doServicePreOperation(DelegateExecution execution){
219 //we need a service plugin platform here.
220 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
221 String uuiRequest = execution.getVariable("uuiRequest")
222 String newUuiRequest = ServicePluginFactory.getInstance().preProcessService(serviceDecomposition, uuiRequest);
223 execution.setVariable("uuiRequest", newUuiRequest)
226 public void doServiceHoming(DelegateExecution execution) {
227 //we need a service plugin platform here.
228 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
229 String uuiRequest = execution.getVariable("uuiRequest")
230 String newUuiRequest = ServicePluginFactory.getInstance().doServiceHoming(serviceDecomposition, uuiRequest);
231 execution.setVariable("uuiRequest", newUuiRequest)
234 public void postProcessAAIGET(DelegateExecution execution) {
235 msoLogger.trace("postProcessAAIGET ")
239 String serviceInstanceName = execution.getVariable("serviceInstanceName")
240 boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")
242 msoLogger.info("Error getting Service-instance from AAI", + serviceInstanceName)
243 WorkflowException workflowException = execution.getVariable("WorkflowException")
244 msoLogger.debug("workflowException: " + workflowException)
245 if(workflowException != null){
246 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
250 msg = "Failure in postProcessAAIGET GENGS_SuccessIndicator:" + succInAAI
252 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
257 boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")
259 msoLogger.info("Found Service-instance in AAI")
260 msg = "ServiceInstance already exists in AAI:" + serviceInstanceName
262 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
265 } catch (BpmnError e) {
267 } catch (Exception ex) {
268 msg = "Exception in DoCreateServiceInstance.postProcessAAIGET. " + ex.getMessage()
270 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
272 msoLogger.trace("Exit postProcessAAIGET ")
275 //TODO use create if not exist
276 public void postProcessAAIPUT(DelegateExecution execution) {
277 msoLogger.trace("postProcessAAIPUT ")
280 String serviceInstanceId = execution.getVariable("serviceInstanceId")
281 boolean succInAAI = execution.getVariable("GENPS_SuccessIndicator")
283 msoLogger.info("Error putting Service-instance in AAI", + serviceInstanceId)
284 WorkflowException workflowException = execution.getVariable("WorkflowException")
285 msoLogger.debug("workflowException: " + workflowException)
286 if(workflowException != null){
287 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
292 //start rollback set up
293 RollbackData rollbackData = new RollbackData()
294 def disableRollback = execution.getVariable("disableRollback")
295 rollbackData.put("SERVICEINSTANCE", "disableRollback", disableRollback.toString())
296 rollbackData.put("SERVICEINSTANCE", "rollbackAAI", "true")
297 rollbackData.put("SERVICEINSTANCE", "serviceInstanceId", serviceInstanceId)
298 rollbackData.put("SERVICEINSTANCE", "subscriptionServiceType", execution.getVariable("subscriptionServiceType"))
299 rollbackData.put("SERVICEINSTANCE", "globalSubscriberId", execution.getVariable("globalSubscriberId"))
300 execution.setVariable("rollbackData", rollbackData)
303 } catch (BpmnError e) {
305 } catch (Exception ex) {
306 msg = "Exception in DoCreateServiceInstance.postProcessAAIDEL. " + ex.getMessage()
308 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
310 msoLogger.trace("Exit postProcessAAIPUT ")
314 * Gets the service instance and its relationships from aai
316 public void getServiceInstance(DelegateExecution execution) {
318 String serviceInstanceId = execution.getVariable('serviceInstanceId')
319 String globalSubscriberId = execution.getVariable('globalSubscriberId')
320 String serviceType = execution.getVariable('subscriptionServiceType')
322 AAIResourcesClient resourceClient = new AAIResourcesClient()
323 AAIResourceUri serviceInstanceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, globalSubscriberId, serviceType, serviceInstanceId)
324 AAIResultWrapper wrapper = resourceClient.get(serviceInstanceUri, NotFoundException.class)
326 Optional<ServiceInstance> si = wrapper.asBean(ServiceInstance.class)
327 execution.setVariable("serviceInstanceName", si.get().getServiceInstanceName())
329 }catch(BpmnError e) {
331 }catch(Exception ex) {
332 String msg = "Internal Error in getServiceInstance: " + ex.getMessage()
333 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
337 public void postProcessAAIGET2(DelegateExecution execution) {
338 msoLogger.trace("postProcessAAIGET2 ")
342 String serviceInstanceName = execution.getVariable("serviceInstanceName")
343 boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")
345 msoLogger.info("Error getting Service-instance from AAI in postProcessAAIGET2", + serviceInstanceName)
346 WorkflowException workflowException = execution.getVariable("WorkflowException")
347 msoLogger.debug("workflowException: " + workflowException)
348 if(workflowException != null){
349 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
353 msg = "Failure in postProcessAAIGET2 GENGS_SuccessIndicator:" + succInAAI
355 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
360 boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")
362 String aaiService = execution.getVariable("GENGS_service")
363 if (!isBlank(aaiService) && (utils.nodeExists(aaiService, "service-instance-name"))) {
364 execution.setVariable("serviceInstanceName", utils.getNodeText(aaiService, "service-instance-name"))
365 msoLogger.info("Found Service-instance in AAI.serviceInstanceName:" + execution.getVariable("serviceInstanceName"))
369 } catch (BpmnError e) {
371 } catch (Exception ex) {
372 msg = "Exception in DoCreateServiceInstance.postProcessAAIGET2 " + ex.getMessage()
374 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
376 msoLogger.trace("Exit postProcessAAIGET2 ")
379 public void preProcessRollback (DelegateExecution execution) {
380 msoLogger.trace("preProcessRollback ")
383 Object workflowException = execution.getVariable("WorkflowException");
385 if (workflowException instanceof WorkflowException) {
386 msoLogger.info("Prev workflowException: " + workflowException.getErrorMessage())
387 execution.setVariable("prevWorkflowException", workflowException);
388 //execution.setVariable("WorkflowException", null);
390 } catch (BpmnError e) {
391 msoLogger.info("BPMN Error during preProcessRollback")
392 } catch(Exception ex) {
393 String msg = "Exception in preProcessRollback. " + ex.getMessage()
396 msoLogger.trace("Exit preProcessRollback ")
399 public void postProcessRollback (DelegateExecution execution) {
400 msoLogger.trace("postProcessRollback ")
403 Object workflowException = execution.getVariable("prevWorkflowException");
404 if (workflowException instanceof WorkflowException) {
405 msoLogger.info("Setting prevException to WorkflowException: ")
406 execution.setVariable("WorkflowException", workflowException);
408 execution.setVariable("rollbackData", null)
409 } catch (BpmnError b) {
410 msoLogger.info("BPMN Error during postProcessRollback")
412 } catch(Exception ex) {
413 msg = "Exception in postProcessRollback. " + ex.getMessage()
416 msoLogger.trace("Exit postProcessRollback ")
419 public void preInitResourcesOperStatus(DelegateExecution execution){
420 msoLogger.trace("STARTED preInitResourcesOperStatus Process ")
422 String serviceId = execution.getVariable("serviceInstanceId")
423 String operationId = execution.getVariable("operationId")
424 String operationType = execution.getVariable("operationType")
425 String resourceTemplateUUIDs = ""
426 String result = "processing"
427 String progress = "0"
429 String operationContent = "Prepare service creation"
430 msoLogger.info("Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId + " operationType:" + operationType)
431 serviceId = UriUtils.encode(serviceId,"UTF-8")
432 execution.setVariable("serviceInstanceId", serviceId)
433 execution.setVariable("operationId", operationId)
434 execution.setVariable("operationType", operationType)
435 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
436 List<Resource> resourceList = serviceDecomposition.getServiceResources()
438 for(Resource resource : resourceList){
439 resourceTemplateUUIDs = resourceTemplateUUIDs + resource.getModelInfo().getModelCustomizationUuid() + ":"
442 def dbAdapterEndpoint = "http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter"
443 execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
444 msoLogger.info("DB Adapter Endpoint is: " + dbAdapterEndpoint)
447 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
448 xmlns:ns="http://org.onap.so/requestsdb">
451 <ns:initResourceOperationStatus xmlns:ns="http://org.onap.so/requestsdb">
452 <serviceId>${MsoUtils.xmlEscape(serviceId)}</serviceId>
453 <operationId>${MsoUtils.xmlEscape(operationId)}</operationId>
454 <operationType>${MsoUtils.xmlEscape(operationType)}</operationType>
455 <resourceTemplateUUIDs>${MsoUtils.xmlEscape(resourceTemplateUUIDs)}</resourceTemplateUUIDs>
456 </ns:initResourceOperationStatus>
458 </soapenv:Envelope>"""
460 payload = utils.formatXml(payload)
461 execution.setVariable("CVFMI_initResOperStatusRequest", payload)
462 msoLogger.info("Outgoing initResourceOperationStatus: \n" + payload)
463 msoLogger.debug("CreateVfModuleInfra Outgoing initResourceOperationStatus Request: " + payload)
466 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occured Processing preInitResourcesOperStatus.", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e);
467 execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during preInitResourcesOperStatus Method:\n" + e.getMessage())
469 msoLogger.trace("COMPLETED preInitResourcesOperStatus Process ")
472 // if site location is in local Operator, create all resources in local ONAP;
473 // if site location is in 3rd Operator, only process sp-partner to create all resources in 3rd ONAP
474 public void doProcessSiteLocation(DelegateExecution execution){
475 msoLogger.trace("======== Start doProcessSiteLocation Process ======== ")
476 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
477 String uuiRequest = execution.getVariable("uuiRequest")
478 uuiRequest = ServicePluginFactory.getInstance().doProcessSiteLocation(serviceDecomposition, uuiRequest);
479 execution.setVariable("uuiRequest", uuiRequest)
480 execution.setVariable("serviceDecomposition", serviceDecomposition)
482 msoLogger.trace("======== COMPLETED doProcessSiteLocation Process ======== ")
485 // Allocate cross link TPs(terminal points) for sotn network only
486 public void doTPResourcesAllocation(DelegateExecution execution){
487 msoLogger.trace("======== Start doTPResourcesAllocation Process ======== ")
488 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
489 String uuiRequest = execution.getVariable("uuiRequest")
490 uuiRequest = ServicePluginFactory.getInstance().doTPResourcesAllocation(execution, uuiRequest);
491 execution.setVariable("uuiRequest", uuiRequest)
492 msoLogger.trace("======== COMPLETED doTPResourcesAllocation Process ======== ")
495 // prepare input param for using DoCreateResources.bpmn
496 public void preProcessForAddResource(DelegateExecution execution) {
497 msoLogger.trace("STARTED preProcessForAddResource Process ")
499 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
500 List<Resource> addResourceList = serviceDecomposition.getServiceResources()
501 execution.setVariable("addResourceList", addResourceList)
503 msoLogger.trace("COMPLETED preProcessForAddResource Process ")
506 public void postProcessForAddResource(DelegateExecution execution) {