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 * Modifications Copyright (c) 2019 Samsung
9 * ================================================================================
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 * ============LICENSE_END=========================================================
23 package org.onap.so.bpmn.infrastructure.scripts
25 import com.google.common.base.Strings
26 import org.onap.so.logger.ErrorCode;
28 import static org.apache.commons.lang3.StringUtils.*;
30 import javax.ws.rs.NotFoundException
32 import org.camunda.bpm.engine.delegate.BpmnError
33 import org.camunda.bpm.engine.delegate.DelegateExecution
34 import org.onap.aai.domain.yang.ServiceInstance
35 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
36 import org.onap.so.bpmn.common.scripts.ExceptionUtil
37 import org.onap.so.bpmn.common.scripts.MsoUtils
38 import org.onap.so.bpmn.core.RollbackData
39 import org.onap.so.bpmn.core.WorkflowException
40 import org.onap.so.bpmn.core.domain.Resource
41 import org.onap.so.bpmn.core.domain.ServiceDecomposition
42 import org.onap.so.bpmn.core.json.JsonUtils
43 import org.onap.so.client.aai.AAIObjectType
44 import org.onap.so.client.aai.AAIResourcesClient
45 import org.onap.so.client.aai.entities.AAIResultWrapper
46 import org.onap.so.client.aai.entities.uri.AAIResourceUri
47 import org.onap.so.bpmn.infrastructure.workflow.service.ServicePluginFactory
48 import org.onap.so.client.aai.entities.uri.AAIUriFactory
49 import org.onap.so.logger.MessageEnum
50 import org.slf4j.Logger
51 import org.slf4j.LoggerFactory
53 import org.springframework.web.util.UriUtils
54 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 Logger logger = LoggerFactory.getLogger( DoCreateE2EServiceInstance.class);
85 String Prefix="DCRESI_"
86 ExceptionUtil exceptionUtil = new ExceptionUtil()
87 JsonUtils jsonUtil = new JsonUtils()
89 public void preProcessRequest (DelegateExecution execution) {
91 logger.trace("preProcessRequest ")
94 execution.setVariable("prefix", Prefix)
96 //requestDetails.subscriberInfo. for AAI GET & PUT & SDNC assignToplology
97 String globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId
98 logger.info(" ***** globalSubscriberId *****" + globalSubscriberId)
99 //requestDetails.requestParameters. for AAI PUT & SDNC assignTopology
100 String serviceType = execution.getVariable("serviceType")
101 logger.info(" ***** serviceType *****" + serviceType)
102 //requestDetails.requestParameters. for SDNC assignTopology
103 String productFamilyId = execution.getVariable("productFamilyId") //AAI productFamilyId
105 if (isBlank(globalSubscriberId)) {
106 msg = "Input globalSubscriberId is null"
108 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
111 if (isBlank(serviceType)) {
112 msg = "Input serviceType is null"
114 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
117 if (productFamilyId == null) {
118 execution.setVariable("productFamilyId", "")
121 String sdncCallbackUrl = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback", execution)
122 if (isBlank(sdncCallbackUrl)) {
123 msg = "URN_mso_workflow_sdncadapter_callback is null"
125 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
127 execution.setVariable("sdncCallbackUrl", sdncCallbackUrl)
128 logger.info("SDNC Callback URL: " + sdncCallbackUrl)
130 //requestDetails.modelInfo.for AAI PUT servieInstanceData
131 //requestDetails.requestInfo. for AAI GET/PUT serviceInstanceData
132 String serviceInstanceName = execution.getVariable("serviceInstanceName")
133 String serviceInstanceId = execution.getVariable("serviceInstanceId")
134 String uuiRequest = execution.getVariable("uuiRequest")
135 String modelInvariantUuid = jsonUtil.getJsonValue(uuiRequest, "service.serviceInvariantUuid")
136 String modelUuid = jsonUtil.getJsonValue(uuiRequest, "service.serviceUuid")
137 String serviceModelName = jsonUtil.getJsonValue(uuiRequest, "service.parameters.templateName")
138 execution.setVariable("serviceModelName", serviceModelName)
139 //aai serviceType and Role can be setted as fixed value now.
140 String aaiServiceType = "E2E Service"
141 String aaiServiceRole = "E2E Service"
143 execution.setVariable("modelInvariantUuid", modelInvariantUuid)
144 execution.setVariable("modelUuid", modelUuid)
147 String oStatus = execution.getVariable("initialStatus") ?: ""
148 if ("TRANSPORT".equalsIgnoreCase(serviceType))
153 org.onap.aai.domain.yang.ServiceInstance si = new org.onap.aai.domain.yang.ServiceInstance()
154 si.setServiceInstanceName(serviceInstanceName)
155 si.setServiceType(aaiServiceType)
156 si.setServiceRole(aaiServiceRole)
157 si.setOrchestrationStatus(oStatus)
158 si.setModelInvariantId(modelInvariantUuid)
159 si.setModelVersionId(modelUuid)
160 si.setInputParameters(uuiRequest)
161 execution.setVariable("serviceInstanceData", si)
163 } catch (BpmnError e) {
165 } catch (Exception ex){
166 msg = "Exception in preProcessRequest " + ex.getMessage()
168 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
170 logger.trace("Exit preProcessRequest ")
173 public void prepareDecomposeService(DelegateExecution execution) {
175 logger.trace("Inside prepareDecomposeService of create generic e2e service ")
176 String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
177 String modelUuid = execution.getVariable("modelUuid")
178 //here modelVersion is not set, we use modelUuid to decompose the service.
179 String serviceModelInfo = """{
180 "modelInvariantUuid":"${modelInvariantUuid}",
181 "modelUuid":"${modelUuid}",
184 execution.setVariable("serviceModelInfo", serviceModelInfo)
186 logger.trace("Completed prepareDecomposeService of create generic e2e service ")
187 } catch (Exception ex) {
188 // try error in method block
189 String exceptionMessage = "Bpmn error encountered in create generic e2e service flow. Unexpected Error from method prepareDecomposeService() - " + ex.getMessage()
190 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
194 public void processDecomposition(DelegateExecution execution) {
195 logger.trace("Inside processDecomposition() of create generic e2e service flow ")
197 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
198 } catch (Exception ex) {
199 String exceptionMessage = "Bpmn error encountered in create generic e2e service flow. processDecomposition() - " + ex.getMessage()
200 logger.debug(exceptionMessage)
201 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
205 public void doServicePreOperation(DelegateExecution execution){
206 //we need a service plugin platform here.
207 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
208 String uuiRequest = execution.getVariable("uuiRequest")
209 String newUuiRequest = ServicePluginFactory.getInstance().preProcessService(serviceDecomposition, uuiRequest);
210 execution.setVariable("uuiRequest", newUuiRequest)
213 public void doServiceHoming(DelegateExecution execution) {
214 //we need a service plugin platform here.
215 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
216 String uuiRequest = execution.getVariable("uuiRequest")
217 String newUuiRequest = ServicePluginFactory.getInstance().doServiceHoming(serviceDecomposition, uuiRequest);
218 execution.setVariable("uuiRequest", newUuiRequest)
221 public void postProcessAAIGET(DelegateExecution execution) {
222 logger.trace("postProcessAAIGET ")
226 String serviceInstanceName = execution.getVariable("serviceInstanceName")
227 boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")
229 logger.info("Error getting Service-instance from AAI", + serviceInstanceName)
230 WorkflowException workflowException = execution.getVariable("WorkflowException")
231 logger.debug("workflowException: " + workflowException)
232 if(workflowException != null){
233 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
237 msg = "Failure in postProcessAAIGET GENGS_SuccessIndicator:" + succInAAI
239 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
244 boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")
246 logger.info("Found Service-instance in AAI")
247 msg = "ServiceInstance already exists in AAI:" + serviceInstanceName
249 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
252 } catch (BpmnError e) {
254 } catch (Exception ex) {
255 msg = "Exception in DoCreateServiceInstance.postProcessAAIGET. " + ex.getMessage()
257 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
259 logger.trace("Exit postProcessAAIGET ")
262 //TODO use create if not exist
263 public void createServiceInstance(DelegateExecution execution) {
264 logger.trace("createServiceInstance ")
266 String serviceInstanceId = execution.getVariable("serviceInstanceId")
268 org.onap.aai.domain.yang.ServiceInstance si = execution.getVariable("serviceInstanceData")
270 AAIResourcesClient client = new AAIResourcesClient()
271 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, execution.getVariable("globalSubscriberId"), execution.getVariable("serviceType"), serviceInstanceId)
272 client.create(uri, si)
274 } catch (BpmnError e) {
276 } catch (Exception ex) {
277 //start rollback set up
278 RollbackData rollbackData = new RollbackData()
279 def disableRollback = execution.getVariable("disableRollback")
280 rollbackData.put("SERVICEINSTANCE", "disableRollback", disableRollback.toString())
281 rollbackData.put("SERVICEINSTANCE", "rollbackAAI", "true")
282 rollbackData.put("SERVICEINSTANCE", "serviceInstanceId", serviceInstanceId)
283 rollbackData.put("SERVICEINSTANCE", "subscriptionServiceType", execution.getVariable("subscriptionServiceType"))
284 rollbackData.put("SERVICEINSTANCE", "globalSubscriberId", execution.getVariable("globalSubscriberId"))
285 execution.setVariable("rollbackData", rollbackData)
287 msg = "Exception in DoCreateServiceInstance.createServiceInstance. " + ex.getMessage()
289 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
291 logger.trace("Exit createServiceInstance ")
295 * Gets the service instance and its relationships from aai
297 public void getServiceInstance(DelegateExecution execution) {
299 String serviceInstanceId = execution.getVariable('serviceInstanceId')
300 String globalSubscriberId = execution.getVariable('globalSubscriberId')
301 String serviceType = execution.getVariable('subscriptionServiceType')
303 AAIResourcesClient resourceClient = new AAIResourcesClient()
304 AAIResourceUri serviceInstanceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, globalSubscriberId, serviceType, serviceInstanceId)
305 AAIResultWrapper wrapper = resourceClient.get(serviceInstanceUri, NotFoundException.class)
307 Optional<ServiceInstance> si = wrapper.asBean(ServiceInstance.class)
308 execution.setVariable("serviceInstanceName", si.get().getServiceInstanceName())
310 }catch(BpmnError e) {
312 }catch(Exception ex) {
313 String msg = "Internal Error in getServiceInstance: " + ex.getMessage()
314 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
318 public void postProcessAAIGET2(DelegateExecution execution) {
319 logger.trace("postProcessAAIGET2 ")
323 String serviceInstanceName = execution.getVariable("serviceInstanceName")
324 boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")
326 logger.info("Error getting Service-instance from AAI in postProcessAAIGET2", + serviceInstanceName)
327 WorkflowException workflowException = execution.getVariable("WorkflowException")
328 logger.debug("workflowException: " + workflowException)
329 if(workflowException != null){
330 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
334 msg = "Failure in postProcessAAIGET2 GENGS_SuccessIndicator:" + succInAAI
336 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
341 boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")
343 String aaiService = execution.getVariable("GENGS_service")
344 if (!isBlank(aaiService) && (utils.nodeExists(aaiService, "service-instance-name"))) {
345 execution.setVariable("serviceInstanceName", utils.getNodeText(aaiService, "service-instance-name"))
346 logger.info("Found Service-instance in AAI.serviceInstanceName:" + execution.getVariable("serviceInstanceName"))
350 } catch (BpmnError e) {
352 } catch (Exception ex) {
353 msg = "Exception in DoCreateServiceInstance.postProcessAAIGET2 " + ex.getMessage()
355 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
357 logger.trace("Exit postProcessAAIGET2 ")
360 public void preProcessRollback (DelegateExecution execution) {
361 logger.trace("preProcessRollback ")
364 Object workflowException = execution.getVariable("WorkflowException");
366 if (workflowException instanceof WorkflowException) {
367 logger.info("Prev workflowException: " + workflowException.getErrorMessage())
368 execution.setVariable("prevWorkflowException", workflowException);
369 //execution.setVariable("WorkflowException", null);
371 } catch (BpmnError e) {
372 logger.info("BPMN Error during preProcessRollback")
373 } catch(Exception ex) {
374 String msg = "Exception in preProcessRollback. " + ex.getMessage()
377 logger.trace("Exit preProcessRollback ")
380 public void postProcessRollback (DelegateExecution execution) {
381 logger.trace("postProcessRollback ")
384 Object workflowException = execution.getVariable("prevWorkflowException");
385 if (workflowException instanceof WorkflowException) {
386 logger.info("Setting prevException to WorkflowException: ")
387 execution.setVariable("WorkflowException", workflowException);
389 execution.setVariable("rollbackData", null)
390 } catch (BpmnError b) {
391 logger.info("BPMN Error during postProcessRollback")
393 } catch(Exception ex) {
394 msg = "Exception in postProcessRollback. " + ex.getMessage()
397 logger.trace("Exit postProcessRollback ")
400 public void preInitResourcesOperStatus(DelegateExecution execution){
401 logger.trace("STARTED preInitResourcesOperStatus Process ")
403 String serviceId = execution.getVariable("serviceInstanceId")
404 String operationId = execution.getVariable("operationId")
405 String operationType = execution.getVariable("operationType")
406 String resourceTemplateUUIDs = ""
407 String result = "processing"
408 String progress = "0"
410 String operationContent = "Prepare service creation"
411 logger.info("Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId + " operationType:" + operationType)
412 serviceId = UriUtils.encode(serviceId,"UTF-8")
413 execution.setVariable("serviceInstanceId", serviceId)
414 execution.setVariable("operationId", operationId)
415 execution.setVariable("operationType", operationType)
416 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
417 List<Resource> resourceList = serviceDecomposition.getServiceResources()
419 for(Resource resource : resourceList){
420 resourceTemplateUUIDs = resourceTemplateUUIDs + resource.getModelInfo().getModelCustomizationUuid() + ":"
423 def dbAdapterEndpoint = UrnPropertiesReader.getVariable("mso.adapters.db.endpoint")
424 execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
425 logger.info("DB Adapter Endpoint is: " + dbAdapterEndpoint)
428 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
429 xmlns:ns="http://org.onap.so/requestsdb">
432 <ns:initResourceOperationStatus xmlns:ns="http://org.onap.so/requestsdb">
433 <serviceId>${MsoUtils.xmlEscape(serviceId)}</serviceId>
434 <operationId>${MsoUtils.xmlEscape(operationId)}</operationId>
435 <operationType>${MsoUtils.xmlEscape(operationType)}</operationType>
436 <resourceTemplateUUIDs>${MsoUtils.xmlEscape(resourceTemplateUUIDs)}</resourceTemplateUUIDs>
437 </ns:initResourceOperationStatus>
439 </soapenv:Envelope>"""
441 payload = utils.formatXml(payload)
442 execution.setVariable("CVFMI_initResOperStatusRequest", payload)
443 logger.info("Outgoing initResourceOperationStatus: \n" + payload)
444 logger.debug("CreateVfModuleInfra Outgoing initResourceOperationStatus Request: " + payload)
447 logger.error(Strings.repeat("{} ", 5), MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
448 "Exception Occured Processing preInitResourcesOperStatus.", "BPMN",
449 ErrorCode.UnknownError.getValue(), e);
450 execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during preInitResourcesOperStatus Method:\n" + e.getMessage())
452 logger.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 logger.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 logger.trace("======== COMPLETED doProcessSiteLocation Process ======== ")
468 // Allocate cross link TPs(terminal points) for sotn network only
469 public void doTPResourcesAllocation(DelegateExecution execution){
470 logger.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 logger.trace("======== COMPLETED doTPResourcesAllocation Process ======== ")
478 // prepare input param for using DoCreateResources.bpmn
479 public void preProcessForAddResource(DelegateExecution execution) {
480 logger.trace("STARTED preProcessForAddResource Process ")
482 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
483 List<Resource> addResourceList = serviceDecomposition.getServiceResources()
484 execution.setVariable("addResourceList", addResourceList)
486 logger.trace("COMPLETED preProcessForAddResource Process ")
489 public void postProcessForAddResource(DelegateExecution execution) {