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.AbstractServiceTaskProcessor
32 import org.onap.so.bpmn.common.scripts.CatalogDbUtils;
33 import org.onap.so.bpmn.common.scripts.ExceptionUtil
34 import org.onap.so.bpmn.common.scripts.MsoUtils
35 import org.onap.so.bpmn.core.RollbackData
36 import org.onap.so.bpmn.core.WorkflowException
37 import org.onap.so.bpmn.core.domain.Resource
38 import org.onap.so.bpmn.core.domain.ServiceDecomposition
39 import org.onap.so.bpmn.core.json.JsonUtils
40 import org.onap.so.bpmn.infrastructure.workflow.service.ServicePluginFactory
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
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 org.onap.aai.domain.yang.ServiceInstance si = new org.onap.aai.domain.yang.ServiceInstance()
156 si.setServiceInstanceName(serviceInstanceName)
157 si.setServiceType(aaiServiceType)
158 si.setServiceRole(aaiServiceRole)
159 si.setOrchestrationStatus(oStatus)
160 si.setModelInvariantId(modelInvariantUuid)
161 si.setModelVersionId(modelUuid)
162 si.setInputParameters(uuiRequest)
163 execution.setVariable("serviceInstanceData", si)
165 } catch (BpmnError e) {
167 } catch (Exception ex){
168 msg = "Exception in preProcessRequest " + ex.getMessage()
170 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
172 msoLogger.trace("Exit preProcessRequest ")
175 public void prepareDecomposeService(DelegateExecution execution) {
177 msoLogger.trace("Inside prepareDecomposeService of create generic e2e service ")
178 String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
179 String modelUuid = execution.getVariable("modelUuid")
180 //here modelVersion is not set, we use modelUuid to decompose the service.
181 String serviceModelInfo = """{
182 "modelInvariantUuid":"${modelInvariantUuid}",
183 "modelUuid":"${modelUuid}",
186 execution.setVariable("serviceModelInfo", serviceModelInfo)
188 msoLogger.trace("Completed prepareDecomposeService of create generic e2e service ")
189 } catch (Exception ex) {
190 // try error in method block
191 String exceptionMessage = "Bpmn error encountered in create generic e2e service flow. Unexpected Error from method prepareDecomposeService() - " + ex.getMessage()
192 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
196 public void processDecomposition(DelegateExecution execution) {
197 msoLogger.trace("Inside processDecomposition() of create generic e2e service flow ")
199 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
200 } catch (Exception ex) {
201 String exceptionMessage = "Bpmn error encountered in create generic e2e service flow. processDecomposition() - " + ex.getMessage()
202 msoLogger.debug(exceptionMessage)
203 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
207 public void doServicePreOperation(DelegateExecution execution){
208 //we need a service plugin platform here.
209 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
210 String uuiRequest = execution.getVariable("uuiRequest")
211 String newUuiRequest = ServicePluginFactory.getInstance().preProcessService(serviceDecomposition, uuiRequest);
212 execution.setVariable("uuiRequest", newUuiRequest)
215 public void doServiceHoming(DelegateExecution execution) {
216 //we need a service plugin platform here.
217 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
218 String uuiRequest = execution.getVariable("uuiRequest")
219 String newUuiRequest = ServicePluginFactory.getInstance().doServiceHoming(serviceDecomposition, uuiRequest);
220 execution.setVariable("uuiRequest", newUuiRequest)
223 public void postProcessAAIGET(DelegateExecution execution) {
224 msoLogger.trace("postProcessAAIGET ")
228 String serviceInstanceName = execution.getVariable("serviceInstanceName")
229 boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")
231 msoLogger.info("Error getting Service-instance from AAI", + serviceInstanceName)
232 WorkflowException workflowException = execution.getVariable("WorkflowException")
233 msoLogger.debug("workflowException: " + workflowException)
234 if(workflowException != null){
235 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
239 msg = "Failure in postProcessAAIGET GENGS_SuccessIndicator:" + succInAAI
241 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
246 boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")
248 msoLogger.info("Found Service-instance in AAI")
249 msg = "ServiceInstance already exists in AAI:" + serviceInstanceName
251 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
254 } catch (BpmnError e) {
256 } catch (Exception ex) {
257 msg = "Exception in DoCreateServiceInstance.postProcessAAIGET. " + ex.getMessage()
259 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
261 msoLogger.trace("Exit postProcessAAIGET ")
264 //TODO use create if not exist
265 public void createServiceInstance(DelegateExecution execution) {
266 msoLogger.trace("createServiceInstance ")
268 String serviceInstanceId = execution.getVariable("serviceInstanceId")
270 org.onap.aai.domain.yang.ServiceInstance si = execution.getVariable("serviceInstanceData")
272 AAIResourcesClient client = new AAIResourcesClient()
273 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, execution.getVariable("globalSubscriberId"), execution.getVariable("serviceType"), serviceInstanceId)
274 client.create(uri, si)
276 } catch (BpmnError e) {
278 } catch (Exception ex) {
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)
289 msg = "Exception in DoCreateServiceInstance.createServiceInstance. " + ex.getMessage()
291 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
293 msoLogger.trace("Exit createServiceInstance ")
297 * Gets the service instance and its relationships from aai
299 public void getServiceInstance(DelegateExecution execution) {
301 String serviceInstanceId = execution.getVariable('serviceInstanceId')
302 String globalSubscriberId = execution.getVariable('globalSubscriberId')
303 String serviceType = execution.getVariable('subscriptionServiceType')
305 AAIResourcesClient resourceClient = new AAIResourcesClient()
306 AAIResourceUri serviceInstanceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, globalSubscriberId, serviceType, serviceInstanceId)
307 AAIResultWrapper wrapper = resourceClient.get(serviceInstanceUri, NotFoundException.class)
309 Optional<ServiceInstance> si = wrapper.asBean(ServiceInstance.class)
310 execution.setVariable("serviceInstanceName", si.get().getServiceInstanceName())
312 }catch(BpmnError e) {
314 }catch(Exception ex) {
315 String msg = "Internal Error in getServiceInstance: " + ex.getMessage()
316 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
320 public void postProcessAAIGET2(DelegateExecution execution) {
321 msoLogger.trace("postProcessAAIGET2 ")
325 String serviceInstanceName = execution.getVariable("serviceInstanceName")
326 boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")
328 msoLogger.info("Error getting Service-instance from AAI in postProcessAAIGET2", + serviceInstanceName)
329 WorkflowException workflowException = execution.getVariable("WorkflowException")
330 msoLogger.debug("workflowException: " + workflowException)
331 if(workflowException != null){
332 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
336 msg = "Failure in postProcessAAIGET2 GENGS_SuccessIndicator:" + succInAAI
338 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
343 boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")
345 String aaiService = execution.getVariable("GENGS_service")
346 if (!isBlank(aaiService) && (utils.nodeExists(aaiService, "service-instance-name"))) {
347 execution.setVariable("serviceInstanceName", utils.getNodeText(aaiService, "service-instance-name"))
348 msoLogger.info("Found Service-instance in AAI.serviceInstanceName:" + execution.getVariable("serviceInstanceName"))
352 } catch (BpmnError e) {
354 } catch (Exception ex) {
355 msg = "Exception in DoCreateServiceInstance.postProcessAAIGET2 " + ex.getMessage()
357 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
359 msoLogger.trace("Exit postProcessAAIGET2 ")
362 public void preProcessRollback (DelegateExecution execution) {
363 msoLogger.trace("preProcessRollback ")
366 Object workflowException = execution.getVariable("WorkflowException");
368 if (workflowException instanceof WorkflowException) {
369 msoLogger.info("Prev workflowException: " + workflowException.getErrorMessage())
370 execution.setVariable("prevWorkflowException", workflowException);
371 //execution.setVariable("WorkflowException", null);
373 } catch (BpmnError e) {
374 msoLogger.info("BPMN Error during preProcessRollback")
375 } catch(Exception ex) {
376 String msg = "Exception in preProcessRollback. " + ex.getMessage()
379 msoLogger.trace("Exit preProcessRollback ")
382 public void postProcessRollback (DelegateExecution execution) {
383 msoLogger.trace("postProcessRollback ")
386 Object workflowException = execution.getVariable("prevWorkflowException");
387 if (workflowException instanceof WorkflowException) {
388 msoLogger.info("Setting prevException to WorkflowException: ")
389 execution.setVariable("WorkflowException", workflowException);
391 execution.setVariable("rollbackData", null)
392 } catch (BpmnError b) {
393 msoLogger.info("BPMN Error during postProcessRollback")
395 } catch(Exception ex) {
396 msg = "Exception in postProcessRollback. " + ex.getMessage()
399 msoLogger.trace("Exit postProcessRollback ")
402 public void preInitResourcesOperStatus(DelegateExecution execution){
403 msoLogger.trace("STARTED preInitResourcesOperStatus Process ")
405 String serviceId = execution.getVariable("serviceInstanceId")
406 String operationId = execution.getVariable("operationId")
407 String operationType = execution.getVariable("operationType")
408 String resourceTemplateUUIDs = ""
409 String result = "processing"
410 String progress = "0"
412 String operationContent = "Prepare service creation"
413 msoLogger.info("Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId + " operationType:" + operationType)
414 serviceId = UriUtils.encode(serviceId,"UTF-8")
415 execution.setVariable("serviceInstanceId", serviceId)
416 execution.setVariable("operationId", operationId)
417 execution.setVariable("operationType", operationType)
418 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
419 List<Resource> resourceList = serviceDecomposition.getServiceResources()
421 for(Resource resource : resourceList){
422 resourceTemplateUUIDs = resourceTemplateUUIDs + resource.getModelInfo().getModelCustomizationUuid() + ":"
425 def dbAdapterEndpoint = UrnPropertiesReader.getVariable("mso.adapters.db.endpoint")
426 execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
427 msoLogger.info("DB Adapter Endpoint is: " + dbAdapterEndpoint)
430 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
431 xmlns:ns="http://org.onap.so/requestsdb">
434 <ns:initResourceOperationStatus xmlns:ns="http://org.onap.so/requestsdb">
435 <serviceId>${MsoUtils.xmlEscape(serviceId)}</serviceId>
436 <operationId>${MsoUtils.xmlEscape(operationId)}</operationId>
437 <operationType>${MsoUtils.xmlEscape(operationType)}</operationType>
438 <resourceTemplateUUIDs>${MsoUtils.xmlEscape(resourceTemplateUUIDs)}</resourceTemplateUUIDs>
439 </ns:initResourceOperationStatus>
441 </soapenv:Envelope>"""
443 payload = utils.formatXml(payload)
444 execution.setVariable("CVFMI_initResOperStatusRequest", payload)
445 msoLogger.info("Outgoing initResourceOperationStatus: \n" + payload)
446 msoLogger.debug("CreateVfModuleInfra Outgoing initResourceOperationStatus Request: " + payload)
449 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occured Processing preInitResourcesOperStatus.", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e);
450 execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during preInitResourcesOperStatus Method:\n" + e.getMessage())
452 msoLogger.trace("COMPLETED preInitResourcesOperStatus Process ")
455 // if site location is in local Operator, create all resources in local ONAP;
456 // if site location is in 3rd Operator, only process sp-partner to create all resources in 3rd ONAP
457 public void doProcessSiteLocation(DelegateExecution execution){
458 msoLogger.trace("======== Start doProcessSiteLocation Process ======== ")
459 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
460 String uuiRequest = execution.getVariable("uuiRequest")
461 uuiRequest = ServicePluginFactory.getInstance().doProcessSiteLocation(serviceDecomposition, uuiRequest);
462 execution.setVariable("uuiRequest", uuiRequest)
463 execution.setVariable("serviceDecomposition", serviceDecomposition)
465 msoLogger.trace("======== COMPLETED doProcessSiteLocation Process ======== ")
468 // Allocate cross link TPs(terminal points) for sotn network only
469 public void doTPResourcesAllocation(DelegateExecution execution){
470 msoLogger.trace("======== Start doTPResourcesAllocation Process ======== ")
471 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
472 String uuiRequest = execution.getVariable("uuiRequest")
473 uuiRequest = ServicePluginFactory.getInstance().doTPResourcesAllocation(execution, uuiRequest);
474 execution.setVariable("uuiRequest", uuiRequest)
475 msoLogger.trace("======== COMPLETED doTPResourcesAllocation Process ======== ")
478 // prepare input param for using DoCreateResources.bpmn
479 public void preProcessForAddResource(DelegateExecution execution) {
480 msoLogger.trace("STARTED preProcessForAddResource Process ")
482 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
483 List<Resource> addResourceList = serviceDecomposition.getServiceResources()
484 execution.setVariable("addResourceList", addResourceList)
486 msoLogger.trace("COMPLETED preProcessForAddResource Process ")
489 public void postProcessForAddResource(DelegateExecution execution) {