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.camunda.bpm.engine.delegate.BpmnError
28 import org.camunda.bpm.engine.delegate.DelegateExecution
29 import org.onap.aai.domain.yang.ServiceInstance
30 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
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.client.aai.AAIObjectType
39 import org.onap.so.client.aai.AAIResourcesClient
40 import org.onap.so.client.aai.entities.AAIResultWrapper
41 import org.onap.so.client.aai.entities.uri.AAIResourceUri
42 import org.onap.so.bpmn.infrastructure.workflow.service.ServicePluginFactory
43 import org.onap.so.client.aai.entities.uri.AAIUriFactory
44 import org.onap.so.logger.MessageEnum
45 import org.onap.so.logger.MsoLogger
47 import org.springframework.web.util.UriUtils
48 import org.onap.so.bpmn.core.UrnPropertiesReader
51 * This groovy class supports the <class>DoCreateServiceInstance.bpmn</class> process.
54 * @param - msoRequestId
55 * @param - globalSubscriberId
56 * @param - subscriptionServiceType
57 * @param - serviceInstanceId
58 * @param - serviceInstanceName - O
59 * @param - serviceModelInfo
60 * @param - productFamilyId
61 * @param - disableRollback
62 * @param - failExists - TODO
63 * @param - serviceInputParams (should contain aic_zone for serviceTypes TRANSPORT,ATM)
64 * @param - sdncVersion ("1610")
65 * @param - serviceDecomposition - Decomposition for R1710
66 * (if macro provides serviceDecompsition then serviceModelInfo, serviceInstanceId & serviceInstanceName will be ignored)
69 * @param - rollbackData (localRB->null)
70 * @param - rolledBack (no localRB->null, localRB F->false, localRB S->true)
71 * @param - WorkflowException
72 * @param - serviceInstanceName - (GET from AAI if null in input)
75 public class DoCreateE2EServiceInstance extends AbstractServiceTaskProcessor {
76 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoCreateE2EServiceInstance.class);
79 String Prefix="DCRESI_"
80 ExceptionUtil exceptionUtil = new ExceptionUtil()
81 JsonUtils jsonUtil = new JsonUtils()
83 public void preProcessRequest (DelegateExecution execution) {
85 msoLogger.trace("preProcessRequest ")
88 execution.setVariable("prefix", Prefix)
90 //requestDetails.subscriberInfo. for AAI GET & PUT & SDNC assignToplology
91 String globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId
92 msoLogger.info(" ***** globalSubscriberId *****" + globalSubscriberId)
93 //requestDetails.requestParameters. for AAI PUT & SDNC assignTopology
94 String serviceType = execution.getVariable("serviceType")
95 msoLogger.info(" ***** serviceType *****" + serviceType)
96 //requestDetails.requestParameters. for SDNC assignTopology
97 String productFamilyId = execution.getVariable("productFamilyId") //AAI productFamilyId
99 if (isBlank(globalSubscriberId)) {
100 msg = "Input globalSubscriberId is null"
102 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
105 if (isBlank(serviceType)) {
106 msg = "Input serviceType is null"
108 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
111 if (productFamilyId == null) {
112 execution.setVariable("productFamilyId", "")
115 String sdncCallbackUrl = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback", execution)
116 if (isBlank(sdncCallbackUrl)) {
117 msg = "URN_mso_workflow_sdncadapter_callback is null"
119 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
121 execution.setVariable("sdncCallbackUrl", sdncCallbackUrl)
122 msoLogger.info("SDNC Callback URL: " + sdncCallbackUrl)
124 //requestDetails.modelInfo.for AAI PUT servieInstanceData
125 //requestDetails.requestInfo. for AAI GET/PUT serviceInstanceData
126 String serviceInstanceName = execution.getVariable("serviceInstanceName")
127 String serviceInstanceId = execution.getVariable("serviceInstanceId")
128 String uuiRequest = execution.getVariable("uuiRequest")
129 String modelInvariantUuid = jsonUtil.getJsonValue(uuiRequest, "service.serviceInvariantUuid")
130 String modelUuid = jsonUtil.getJsonValue(uuiRequest, "service.serviceUuid")
131 String serviceModelName = jsonUtil.getJsonValue(uuiRequest, "service.parameters.templateName")
132 execution.setVariable("serviceModelName", serviceModelName)
133 //aai serviceType and Role can be setted as fixed value now.
134 String aaiServiceType = "E2E Service"
135 String aaiServiceRole = "E2E Service"
137 execution.setVariable("modelInvariantUuid", modelInvariantUuid)
138 execution.setVariable("modelUuid", modelUuid)
141 String oStatus = execution.getVariable("initialStatus") ?: ""
142 if ("TRANSPORT".equalsIgnoreCase(serviceType))
147 org.onap.aai.domain.yang.ServiceInstance si = new org.onap.aai.domain.yang.ServiceInstance()
148 si.setServiceInstanceName(serviceInstanceName)
149 si.setServiceType(aaiServiceType)
150 si.setServiceRole(aaiServiceRole)
151 si.setOrchestrationStatus(oStatus)
152 si.setModelInvariantId(modelInvariantUuid)
153 si.setModelVersionId(modelUuid)
154 si.setInputParameters(uuiRequest)
155 execution.setVariable("serviceInstanceData", si)
157 } catch (BpmnError e) {
159 } catch (Exception ex){
160 msg = "Exception in preProcessRequest " + ex.getMessage()
162 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
164 msoLogger.trace("Exit preProcessRequest ")
167 public void prepareDecomposeService(DelegateExecution execution) {
169 msoLogger.trace("Inside prepareDecomposeService of create generic e2e service ")
170 String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
171 String modelUuid = execution.getVariable("modelUuid")
172 //here modelVersion is not set, we use modelUuid to decompose the service.
173 String serviceModelInfo = """{
174 "modelInvariantUuid":"${modelInvariantUuid}",
175 "modelUuid":"${modelUuid}",
178 execution.setVariable("serviceModelInfo", serviceModelInfo)
180 msoLogger.trace("Completed prepareDecomposeService of create generic e2e service ")
181 } catch (Exception ex) {
182 // try error in method block
183 String exceptionMessage = "Bpmn error encountered in create generic e2e service flow. Unexpected Error from method prepareDecomposeService() - " + ex.getMessage()
184 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
188 public void processDecomposition(DelegateExecution execution) {
189 msoLogger.trace("Inside processDecomposition() of create generic e2e service flow ")
191 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
192 } catch (Exception ex) {
193 String exceptionMessage = "Bpmn error encountered in create generic e2e service flow. processDecomposition() - " + ex.getMessage()
194 msoLogger.debug(exceptionMessage)
195 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
199 public void doServicePreOperation(DelegateExecution execution){
200 //we need a service plugin platform here.
201 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
202 String uuiRequest = execution.getVariable("uuiRequest")
203 String newUuiRequest = ServicePluginFactory.getInstance().preProcessService(serviceDecomposition, uuiRequest);
204 execution.setVariable("uuiRequest", newUuiRequest)
207 public void doServiceHoming(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().doServiceHoming(serviceDecomposition, uuiRequest);
212 execution.setVariable("uuiRequest", newUuiRequest)
215 public void postProcessAAIGET(DelegateExecution execution) {
216 msoLogger.trace("postProcessAAIGET ")
220 String serviceInstanceName = execution.getVariable("serviceInstanceName")
221 boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")
223 msoLogger.info("Error getting Service-instance from AAI", + serviceInstanceName)
224 WorkflowException workflowException = execution.getVariable("WorkflowException")
225 msoLogger.debug("workflowException: " + workflowException)
226 if(workflowException != null){
227 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
231 msg = "Failure in postProcessAAIGET GENGS_SuccessIndicator:" + succInAAI
233 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
238 boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")
240 msoLogger.info("Found Service-instance in AAI")
241 msg = "ServiceInstance already exists in AAI:" + serviceInstanceName
243 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
246 } catch (BpmnError e) {
248 } catch (Exception ex) {
249 msg = "Exception in DoCreateServiceInstance.postProcessAAIGET. " + ex.getMessage()
251 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
253 msoLogger.trace("Exit postProcessAAIGET ")
256 //TODO use create if not exist
257 public void createServiceInstance(DelegateExecution execution) {
258 msoLogger.trace("createServiceInstance ")
260 String serviceInstanceId = execution.getVariable("serviceInstanceId")
262 org.onap.aai.domain.yang.ServiceInstance si = execution.getVariable("serviceInstanceData")
264 AAIResourcesClient client = new AAIResourcesClient()
265 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, execution.getVariable("globalSubscriberId"), execution.getVariable("serviceType"), serviceInstanceId)
266 client.create(uri, si)
268 } catch (BpmnError e) {
270 } catch (Exception ex) {
271 //start rollback set up
272 RollbackData rollbackData = new RollbackData()
273 def disableRollback = execution.getVariable("disableRollback")
274 rollbackData.put("SERVICEINSTANCE", "disableRollback", disableRollback.toString())
275 rollbackData.put("SERVICEINSTANCE", "rollbackAAI", "true")
276 rollbackData.put("SERVICEINSTANCE", "serviceInstanceId", serviceInstanceId)
277 rollbackData.put("SERVICEINSTANCE", "subscriptionServiceType", execution.getVariable("subscriptionServiceType"))
278 rollbackData.put("SERVICEINSTANCE", "globalSubscriberId", execution.getVariable("globalSubscriberId"))
279 execution.setVariable("rollbackData", rollbackData)
281 msg = "Exception in DoCreateServiceInstance.createServiceInstance. " + ex.getMessage()
283 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
285 msoLogger.trace("Exit createServiceInstance ")
289 * Gets the service instance and its relationships from aai
291 public void getServiceInstance(DelegateExecution execution) {
293 String serviceInstanceId = execution.getVariable('serviceInstanceId')
294 String globalSubscriberId = execution.getVariable('globalSubscriberId')
295 String serviceType = execution.getVariable('subscriptionServiceType')
297 AAIResourcesClient resourceClient = new AAIResourcesClient()
298 AAIResourceUri serviceInstanceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, globalSubscriberId, serviceType, serviceInstanceId)
299 AAIResultWrapper wrapper = resourceClient.get(serviceInstanceUri, NotFoundException.class)
301 Optional<ServiceInstance> si = wrapper.asBean(ServiceInstance.class)
302 execution.setVariable("serviceInstanceName", si.get().getServiceInstanceName())
304 }catch(BpmnError e) {
306 }catch(Exception ex) {
307 String msg = "Internal Error in getServiceInstance: " + ex.getMessage()
308 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
312 public void postProcessAAIGET2(DelegateExecution execution) {
313 msoLogger.trace("postProcessAAIGET2 ")
317 String serviceInstanceName = execution.getVariable("serviceInstanceName")
318 boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")
320 msoLogger.info("Error getting Service-instance from AAI in postProcessAAIGET2", + serviceInstanceName)
321 WorkflowException workflowException = execution.getVariable("WorkflowException")
322 msoLogger.debug("workflowException: " + workflowException)
323 if(workflowException != null){
324 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
328 msg = "Failure in postProcessAAIGET2 GENGS_SuccessIndicator:" + succInAAI
330 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
335 boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")
337 String aaiService = execution.getVariable("GENGS_service")
338 if (!isBlank(aaiService) && (utils.nodeExists(aaiService, "service-instance-name"))) {
339 execution.setVariable("serviceInstanceName", utils.getNodeText(aaiService, "service-instance-name"))
340 msoLogger.info("Found Service-instance in AAI.serviceInstanceName:" + execution.getVariable("serviceInstanceName"))
344 } catch (BpmnError e) {
346 } catch (Exception ex) {
347 msg = "Exception in DoCreateServiceInstance.postProcessAAIGET2 " + ex.getMessage()
349 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
351 msoLogger.trace("Exit postProcessAAIGET2 ")
354 public void preProcessRollback (DelegateExecution execution) {
355 msoLogger.trace("preProcessRollback ")
358 Object workflowException = execution.getVariable("WorkflowException");
360 if (workflowException instanceof WorkflowException) {
361 msoLogger.info("Prev workflowException: " + workflowException.getErrorMessage())
362 execution.setVariable("prevWorkflowException", workflowException);
363 //execution.setVariable("WorkflowException", null);
365 } catch (BpmnError e) {
366 msoLogger.info("BPMN Error during preProcessRollback")
367 } catch(Exception ex) {
368 String msg = "Exception in preProcessRollback. " + ex.getMessage()
371 msoLogger.trace("Exit preProcessRollback ")
374 public void postProcessRollback (DelegateExecution execution) {
375 msoLogger.trace("postProcessRollback ")
378 Object workflowException = execution.getVariable("prevWorkflowException");
379 if (workflowException instanceof WorkflowException) {
380 msoLogger.info("Setting prevException to WorkflowException: ")
381 execution.setVariable("WorkflowException", workflowException);
383 execution.setVariable("rollbackData", null)
384 } catch (BpmnError b) {
385 msoLogger.info("BPMN Error during postProcessRollback")
387 } catch(Exception ex) {
388 msg = "Exception in postProcessRollback. " + ex.getMessage()
391 msoLogger.trace("Exit postProcessRollback ")
394 public void preInitResourcesOperStatus(DelegateExecution execution){
395 msoLogger.trace("STARTED preInitResourcesOperStatus Process ")
397 String serviceId = execution.getVariable("serviceInstanceId")
398 String operationId = execution.getVariable("operationId")
399 String operationType = execution.getVariable("operationType")
400 String resourceTemplateUUIDs = ""
401 String result = "processing"
402 String progress = "0"
404 String operationContent = "Prepare service creation"
405 msoLogger.info("Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId + " operationType:" + operationType)
406 serviceId = UriUtils.encode(serviceId,"UTF-8")
407 execution.setVariable("serviceInstanceId", serviceId)
408 execution.setVariable("operationId", operationId)
409 execution.setVariable("operationType", operationType)
410 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
411 List<Resource> resourceList = serviceDecomposition.getServiceResources()
413 for(Resource resource : resourceList){
414 resourceTemplateUUIDs = resourceTemplateUUIDs + resource.getModelInfo().getModelCustomizationUuid() + ":"
417 def dbAdapterEndpoint = UrnPropertiesReader.getVariable("mso.adapters.db.endpoint")
418 execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
419 msoLogger.info("DB Adapter Endpoint is: " + dbAdapterEndpoint)
422 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
423 xmlns:ns="http://org.onap.so/requestsdb">
426 <ns:initResourceOperationStatus xmlns:ns="http://org.onap.so/requestsdb">
427 <serviceId>${MsoUtils.xmlEscape(serviceId)}</serviceId>
428 <operationId>${MsoUtils.xmlEscape(operationId)}</operationId>
429 <operationType>${MsoUtils.xmlEscape(operationType)}</operationType>
430 <resourceTemplateUUIDs>${MsoUtils.xmlEscape(resourceTemplateUUIDs)}</resourceTemplateUUIDs>
431 </ns:initResourceOperationStatus>
433 </soapenv:Envelope>"""
435 payload = utils.formatXml(payload)
436 execution.setVariable("CVFMI_initResOperStatusRequest", payload)
437 msoLogger.info("Outgoing initResourceOperationStatus: \n" + payload)
438 msoLogger.debug("CreateVfModuleInfra Outgoing initResourceOperationStatus Request: " + payload)
441 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occured Processing preInitResourcesOperStatus.", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e);
442 execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during preInitResourcesOperStatus Method:\n" + e.getMessage())
444 msoLogger.trace("COMPLETED preInitResourcesOperStatus Process ")
447 // if site location is in local Operator, create all resources in local ONAP;
448 // if site location is in 3rd Operator, only process sp-partner to create all resources in 3rd ONAP
449 public void doProcessSiteLocation(DelegateExecution execution){
450 msoLogger.trace("======== Start doProcessSiteLocation Process ======== ")
451 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
452 String uuiRequest = execution.getVariable("uuiRequest")
453 uuiRequest = ServicePluginFactory.getInstance().doProcessSiteLocation(serviceDecomposition, uuiRequest);
454 execution.setVariable("uuiRequest", uuiRequest)
455 execution.setVariable("serviceDecomposition", serviceDecomposition)
457 msoLogger.trace("======== COMPLETED doProcessSiteLocation Process ======== ")
460 // Allocate cross link TPs(terminal points) for sotn network only
461 public void doTPResourcesAllocation(DelegateExecution execution){
462 msoLogger.trace("======== Start doTPResourcesAllocation Process ======== ")
463 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
464 String uuiRequest = execution.getVariable("uuiRequest")
465 uuiRequest = ServicePluginFactory.getInstance().doTPResourcesAllocation(execution, uuiRequest);
466 execution.setVariable("uuiRequest", uuiRequest)
467 msoLogger.trace("======== COMPLETED doTPResourcesAllocation Process ======== ")
470 // prepare input param for using DoCreateResources.bpmn
471 public void preProcessForAddResource(DelegateExecution execution) {
472 msoLogger.trace("STARTED preProcessForAddResource Process ")
474 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
475 List<Resource> addResourceList = serviceDecomposition.getServiceResources()
476 execution.setVariable("addResourceList", addResourceList)
478 msoLogger.trace("COMPLETED preProcessForAddResource Process ")
481 public void postProcessForAddResource(DelegateExecution execution) {