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.client.aai.AAIObjectType
41 import org.onap.so.client.aai.AAIResourcesClient
42 import org.onap.so.client.aai.entities.AAIResultWrapper
43 import org.onap.so.client.aai.entities.uri.AAIResourceUri
44 import org.onap.so.bpmn.infrastructure.workflow.service.ServicePluginFactory
45 import org.onap.so.client.aai.entities.uri.AAIUriFactory
46 import org.onap.so.logger.MessageEnum
47 import org.onap.so.logger.MsoLogger
49 import org.springframework.web.util.UriUtils
50 import org.onap.so.bpmn.core.UrnPropertiesReader
57 * This groovy class supports the <class>DoCreateServiceInstance.bpmn</class> process.
60 * @param - msoRequestId
61 * @param - globalSubscriberId
62 * @param - subscriptionServiceType
63 * @param - serviceInstanceId
64 * @param - serviceInstanceName - O
65 * @param - serviceModelInfo
66 * @param - productFamilyId
67 * @param - disableRollback
68 * @param - failExists - TODO
69 * @param - serviceInputParams (should contain aic_zone for serviceTypes TRANSPORT,ATM)
70 * @param - sdncVersion ("1610")
71 * @param - serviceDecomposition - Decomposition for R1710
72 * (if macro provides serviceDecompsition then serviceModelInfo, serviceInstanceId & serviceInstanceName will be ignored)
75 * @param - rollbackData (localRB->null)
76 * @param - rolledBack (no localRB->null, localRB F->false, localRB S->true)
77 * @param - WorkflowException
78 * @param - serviceInstanceName - (GET from AAI if null in input)
81 public class DoCreateE2EServiceInstance extends AbstractServiceTaskProcessor {
82 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoCreateE2EServiceInstance.class);
85 String Prefix="DCRESI_"
86 ExceptionUtil exceptionUtil = new ExceptionUtil()
87 JsonUtils jsonUtil = new JsonUtils()
88 CatalogDbUtils cutils = new CatalogDbUtils()
90 public void preProcessRequest (DelegateExecution execution) {
92 msoLogger.trace("preProcessRequest ")
95 execution.setVariable("prefix", Prefix)
97 //requestDetails.subscriberInfo. for AAI GET & PUT & SDNC assignToplology
98 String globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId
99 msoLogger.info(" ***** globalSubscriberId *****" + globalSubscriberId)
100 //requestDetails.requestParameters. for AAI PUT & SDNC assignTopology
101 String serviceType = execution.getVariable("serviceType")
102 msoLogger.info(" ***** serviceType *****" + serviceType)
103 //requestDetails.requestParameters. for SDNC assignTopology
104 String productFamilyId = execution.getVariable("productFamilyId") //AAI productFamilyId
106 if (isBlank(globalSubscriberId)) {
107 msg = "Input globalSubscriberId is null"
109 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
112 if (isBlank(serviceType)) {
113 msg = "Input serviceType is null"
115 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
118 if (productFamilyId == null) {
119 execution.setVariable("productFamilyId", "")
122 String sdncCallbackUrl = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback", execution)
123 if (isBlank(sdncCallbackUrl)) {
124 msg = "URN_mso_workflow_sdncadapter_callback is null"
126 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
128 execution.setVariable("sdncCallbackUrl", sdncCallbackUrl)
129 msoLogger.info("SDNC Callback URL: " + sdncCallbackUrl)
131 //requestDetails.modelInfo.for AAI PUT servieInstanceData
132 //requestDetails.requestInfo. for AAI GET/PUT serviceInstanceData
133 String serviceInstanceName = execution.getVariable("serviceInstanceName")
134 String serviceInstanceId = execution.getVariable("serviceInstanceId")
135 String uuiRequest = execution.getVariable("uuiRequest")
136 String modelInvariantUuid = jsonUtil.getJsonValue(uuiRequest, "service.serviceInvariantUuid")
137 String modelUuid = jsonUtil.getJsonValue(uuiRequest, "service.serviceUuid")
138 String serviceModelName = jsonUtil.getJsonValue(uuiRequest, "service.parameters.templateName")
139 execution.setVariable("serviceModelName", serviceModelName)
140 //aai serviceType and Role can be setted as fixed value now.
141 String aaiServiceType = "E2E Service"
142 String aaiServiceRole = "E2E Service"
144 execution.setVariable("modelInvariantUuid", modelInvariantUuid)
145 execution.setVariable("modelUuid", modelUuid)
148 String oStatus = execution.getVariable("initialStatus") ?: ""
149 if ("TRANSPORT".equalsIgnoreCase(serviceType))
154 org.onap.aai.domain.yang.ServiceInstance si = new org.onap.aai.domain.yang.ServiceInstance()
155 si.setServiceInstanceName(serviceInstanceName)
156 si.setServiceType(aaiServiceType)
157 si.setServiceRole(aaiServiceRole)
158 si.setOrchestrationStatus(oStatus)
159 si.setModelInvariantId(modelInvariantUuid)
160 si.setModelVersionId(modelUuid)
161 si.setInputParameters(uuiRequest)
162 execution.setVariable("serviceInstanceData", si)
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 //TODO use create if not exist
264 public void createServiceInstance(DelegateExecution execution) {
265 msoLogger.trace("createServiceInstance ")
267 String serviceInstanceId = UUID.randomUUID().toString()
269 org.onap.aai.domain.yang.ServiceInstance si = execution.getVariable("serviceInstanceData")
271 AAIResourcesClient client = new AAIResourcesClient()
272 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, execution.getVariable("globalSubscriberId"), execution.getVariable("serviceType"), serviceInstanceId)
273 client.create(uri, si)
275 } catch (BpmnError e) {
277 } catch (Exception ex) {
278 //start rollback set up
279 RollbackData rollbackData = new RollbackData()
280 def disableRollback = execution.getVariable("disableRollback")
281 rollbackData.put("SERVICEINSTANCE", "disableRollback", disableRollback.toString())
282 rollbackData.put("SERVICEINSTANCE", "rollbackAAI", "true")
283 rollbackData.put("SERVICEINSTANCE", "serviceInstanceId", serviceInstanceId)
284 rollbackData.put("SERVICEINSTANCE", "subscriptionServiceType", execution.getVariable("subscriptionServiceType"))
285 rollbackData.put("SERVICEINSTANCE", "globalSubscriberId", execution.getVariable("globalSubscriberId"))
286 execution.setVariable("rollbackData", rollbackData)
288 msg = "Exception in DoCreateServiceInstance.createServiceInstance. " + ex.getMessage()
290 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
292 msoLogger.trace("Exit createServiceInstance ")
296 * Gets the service instance and its relationships from aai
298 public void getServiceInstance(DelegateExecution execution) {
300 String serviceInstanceId = execution.getVariable('serviceInstanceId')
301 String globalSubscriberId = execution.getVariable('globalSubscriberId')
302 String serviceType = execution.getVariable('subscriptionServiceType')
304 AAIResourcesClient resourceClient = new AAIResourcesClient()
305 AAIResourceUri serviceInstanceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, globalSubscriberId, serviceType, serviceInstanceId)
306 AAIResultWrapper wrapper = resourceClient.get(serviceInstanceUri, NotFoundException.class)
308 Optional<ServiceInstance> si = wrapper.asBean(ServiceInstance.class)
309 execution.setVariable("serviceInstanceName", si.get().getServiceInstanceName())
311 }catch(BpmnError e) {
313 }catch(Exception ex) {
314 String msg = "Internal Error in getServiceInstance: " + ex.getMessage()
315 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
319 public void postProcessAAIGET2(DelegateExecution execution) {
320 msoLogger.trace("postProcessAAIGET2 ")
324 String serviceInstanceName = execution.getVariable("serviceInstanceName")
325 boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")
327 msoLogger.info("Error getting Service-instance from AAI in postProcessAAIGET2", + serviceInstanceName)
328 WorkflowException workflowException = execution.getVariable("WorkflowException")
329 msoLogger.debug("workflowException: " + workflowException)
330 if(workflowException != null){
331 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
335 msg = "Failure in postProcessAAIGET2 GENGS_SuccessIndicator:" + succInAAI
337 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
342 boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")
344 String aaiService = execution.getVariable("GENGS_service")
345 if (!isBlank(aaiService) && (utils.nodeExists(aaiService, "service-instance-name"))) {
346 execution.setVariable("serviceInstanceName", utils.getNodeText(aaiService, "service-instance-name"))
347 msoLogger.info("Found Service-instance in AAI.serviceInstanceName:" + execution.getVariable("serviceInstanceName"))
351 } catch (BpmnError e) {
353 } catch (Exception ex) {
354 msg = "Exception in DoCreateServiceInstance.postProcessAAIGET2 " + ex.getMessage()
356 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
358 msoLogger.trace("Exit postProcessAAIGET2 ")
361 public void preProcessRollback (DelegateExecution execution) {
362 msoLogger.trace("preProcessRollback ")
365 Object workflowException = execution.getVariable("WorkflowException");
367 if (workflowException instanceof WorkflowException) {
368 msoLogger.info("Prev workflowException: " + workflowException.getErrorMessage())
369 execution.setVariable("prevWorkflowException", workflowException);
370 //execution.setVariable("WorkflowException", null);
372 } catch (BpmnError e) {
373 msoLogger.info("BPMN Error during preProcessRollback")
374 } catch(Exception ex) {
375 String msg = "Exception in preProcessRollback. " + ex.getMessage()
378 msoLogger.trace("Exit preProcessRollback ")
381 public void postProcessRollback (DelegateExecution execution) {
382 msoLogger.trace("postProcessRollback ")
385 Object workflowException = execution.getVariable("prevWorkflowException");
386 if (workflowException instanceof WorkflowException) {
387 msoLogger.info("Setting prevException to WorkflowException: ")
388 execution.setVariable("WorkflowException", workflowException);
390 execution.setVariable("rollbackData", null)
391 } catch (BpmnError b) {
392 msoLogger.info("BPMN Error during postProcessRollback")
394 } catch(Exception ex) {
395 msg = "Exception in postProcessRollback. " + ex.getMessage()
398 msoLogger.trace("Exit postProcessRollback ")
401 public void preInitResourcesOperStatus(DelegateExecution execution){
402 msoLogger.trace("STARTED preInitResourcesOperStatus Process ")
404 String serviceId = execution.getVariable("serviceInstanceId")
405 String operationId = execution.getVariable("operationId")
406 String operationType = execution.getVariable("operationType")
407 String resourceTemplateUUIDs = ""
408 String result = "processing"
409 String progress = "0"
411 String operationContent = "Prepare service creation"
412 msoLogger.info("Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId + " operationType:" + operationType)
413 serviceId = UriUtils.encode(serviceId,"UTF-8")
414 execution.setVariable("serviceInstanceId", serviceId)
415 execution.setVariable("operationId", operationId)
416 execution.setVariable("operationType", operationType)
417 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
418 List<Resource> resourceList = serviceDecomposition.getServiceResources()
420 for(Resource resource : resourceList){
421 resourceTemplateUUIDs = resourceTemplateUUIDs + resource.getModelInfo().getModelCustomizationUuid() + ":"
424 def dbAdapterEndpoint = UrnPropertiesReader.getVariable("mso.adapters.db.endpoint")
425 execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
426 msoLogger.info("DB Adapter Endpoint is: " + dbAdapterEndpoint)
429 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
430 xmlns:ns="http://org.onap.so/requestsdb">
433 <ns:initResourceOperationStatus xmlns:ns="http://org.onap.so/requestsdb">
434 <serviceId>${MsoUtils.xmlEscape(serviceId)}</serviceId>
435 <operationId>${MsoUtils.xmlEscape(operationId)}</operationId>
436 <operationType>${MsoUtils.xmlEscape(operationType)}</operationType>
437 <resourceTemplateUUIDs>${MsoUtils.xmlEscape(resourceTemplateUUIDs)}</resourceTemplateUUIDs>
438 </ns:initResourceOperationStatus>
440 </soapenv:Envelope>"""
442 payload = utils.formatXml(payload)
443 execution.setVariable("CVFMI_initResOperStatusRequest", payload)
444 msoLogger.info("Outgoing initResourceOperationStatus: \n" + payload)
445 msoLogger.debug("CreateVfModuleInfra Outgoing initResourceOperationStatus Request: " + payload)
448 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occured Processing preInitResourcesOperStatus.", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e);
449 execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during preInitResourcesOperStatus Method:\n" + e.getMessage())
451 msoLogger.trace("COMPLETED preInitResourcesOperStatus Process ")
454 // if site location is in local Operator, create all resources in local ONAP;
455 // if site location is in 3rd Operator, only process sp-partner to create all resources in 3rd ONAP
456 public void doProcessSiteLocation(DelegateExecution execution){
457 msoLogger.trace("======== Start doProcessSiteLocation Process ======== ")
458 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
459 String uuiRequest = execution.getVariable("uuiRequest")
460 uuiRequest = ServicePluginFactory.getInstance().doProcessSiteLocation(serviceDecomposition, uuiRequest);
461 execution.setVariable("uuiRequest", uuiRequest)
462 execution.setVariable("serviceDecomposition", serviceDecomposition)
464 msoLogger.trace("======== COMPLETED doProcessSiteLocation Process ======== ")
467 // Allocate cross link TPs(terminal points) for sotn network only
468 public void doTPResourcesAllocation(DelegateExecution execution){
469 msoLogger.trace("======== Start doTPResourcesAllocation Process ======== ")
470 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
471 String uuiRequest = execution.getVariable("uuiRequest")
472 uuiRequest = ServicePluginFactory.getInstance().doTPResourcesAllocation(execution, uuiRequest);
473 execution.setVariable("uuiRequest", uuiRequest)
474 msoLogger.trace("======== COMPLETED doTPResourcesAllocation Process ======== ")
477 // prepare input param for using DoCreateResources.bpmn
478 public void preProcessForAddResource(DelegateExecution execution) {
479 msoLogger.trace("STARTED preProcessForAddResource Process ")
481 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
482 List<Resource> addResourceList = serviceDecomposition.getServiceResources()
483 execution.setVariable("addResourceList", addResourceList)
485 msoLogger.trace("COMPLETED preProcessForAddResource Process ")
488 public void postProcessForAddResource(DelegateExecution execution) {