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;
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 = execution.getVariable('URN_mso_workflow_sdncadapter_callback')
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 String statusLine = isBlank(oStatus) ? "" : "<orchestration-status>${MsoUtils.xmlEscape(oStatus)}</orchestration-status>"
156 AaiUtil aaiUriUtil = new AaiUtil(this)
157 String aai_uri = aaiUriUtil.getBusinessCustomerUri(execution)
158 String namespace = aaiUriUtil.getNamespaceFromUri(aai_uri)
159 String serviceInstanceData =
160 """<service-instance xmlns=\"${namespace}\">
161 <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceId)}</service-instance-id>
162 <service-instance-name>${MsoUtils.xmlEscape(serviceInstanceName)}</service-instance-name>
163 <service-type>${MsoUtils.xmlEscape(aaiServiceType)}</service-type>
164 <service-role>${MsoUtils.xmlEscape(aaiServiceRole)}</service-role>
166 <model-invariant-id>${MsoUtils.xmlEscape(modelInvariantUuid)}</model-invariant-id>
167 <model-version-id>${MsoUtils.xmlEscape(modelUuid)}</model-version-id>
168 </service-instance>""".trim()
169 execution.setVariable("serviceInstanceData", serviceInstanceData)
170 msoLogger.debug(serviceInstanceData)
171 msoLogger.info(" aai_uri " + aai_uri + " namespace:" + namespace)
172 msoLogger.info(" 'payload' to create Service Instance in AAI - " + "\n" + serviceInstanceData)
174 } catch (BpmnError e) {
176 } catch (Exception ex){
177 msg = "Exception in preProcessRequest " + ex.getMessage()
179 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
181 msoLogger.trace("Exit preProcessRequest ")
184 public void prepareDecomposeService(DelegateExecution execution) {
186 msoLogger.trace("Inside prepareDecomposeService of create generic e2e service ")
187 String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
188 String modelUuid = execution.getVariable("modelUuid")
189 //here modelVersion is not set, we use modelUuid to decompose the service.
190 String serviceModelInfo = """{
191 "modelInvariantUuid":"${modelInvariantUuid}",
192 "modelUuid":"${modelUuid}",
195 execution.setVariable("serviceModelInfo", serviceModelInfo)
197 msoLogger.trace("Completed prepareDecomposeService of create generic e2e service ")
198 } catch (Exception ex) {
199 // try error in method block
200 String exceptionMessage = "Bpmn error encountered in create generic e2e service flow. Unexpected Error from method prepareDecomposeService() - " + ex.getMessage()
201 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
205 public void processDecomposition(DelegateExecution execution) {
206 msoLogger.trace("Inside processDecomposition() of create generic e2e service flow ")
208 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
209 } catch (Exception ex) {
210 String exceptionMessage = "Bpmn error encountered in create generic e2e service flow. processDecomposition() - " + ex.getMessage()
211 msoLogger.debug(exceptionMessage)
212 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
216 public void doServicePreOperation(DelegateExecution execution){
217 //we need a service plugin platform here.
218 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
219 String uuiRequest = execution.getVariable("uuiRequest")
220 String newUuiRequest = ServicePluginFactory.getInstance().preProcessService(serviceDecomposition, uuiRequest);
221 execution.setVariable("uuiRequest", newUuiRequest)
224 public void doServiceHoming(DelegateExecution execution) {
225 //we need a service plugin platform here.
226 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
227 String uuiRequest = execution.getVariable("uuiRequest")
228 String newUuiRequest = ServicePluginFactory.getInstance().doServiceHoming(serviceDecomposition, uuiRequest);
229 execution.setVariable("uuiRequest", newUuiRequest)
232 public void postProcessAAIGET(DelegateExecution execution) {
233 msoLogger.trace("postProcessAAIGET ")
237 String serviceInstanceName = execution.getVariable("serviceInstanceName")
238 boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")
240 msoLogger.info("Error getting Service-instance from AAI", + serviceInstanceName)
241 WorkflowException workflowException = execution.getVariable("WorkflowException")
242 msoLogger.debug("workflowException: " + workflowException)
243 if(workflowException != null){
244 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
248 msg = "Failure in postProcessAAIGET GENGS_SuccessIndicator:" + succInAAI
250 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
255 boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")
257 msoLogger.info("Found Service-instance in AAI")
258 msg = "ServiceInstance already exists in AAI:" + serviceInstanceName
260 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
263 } catch (BpmnError e) {
265 } catch (Exception ex) {
266 msg = "Exception in DoCreateServiceInstance.postProcessAAIGET. " + ex.getMessage()
268 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
270 msoLogger.trace("Exit postProcessAAIGET ")
273 //TODO use create if not exist
274 public void postProcessAAIPUT(DelegateExecution execution) {
275 msoLogger.trace("postProcessAAIPUT ")
278 String serviceInstanceId = execution.getVariable("serviceInstanceId")
279 boolean succInAAI = execution.getVariable("GENPS_SuccessIndicator")
281 msoLogger.info("Error putting Service-instance in AAI", + serviceInstanceId)
282 WorkflowException workflowException = execution.getVariable("WorkflowException")
283 msoLogger.debug("workflowException: " + workflowException)
284 if(workflowException != null){
285 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
290 //start rollback set up
291 RollbackData rollbackData = new RollbackData()
292 def disableRollback = execution.getVariable("disableRollback")
293 rollbackData.put("SERVICEINSTANCE", "disableRollback", disableRollback.toString())
294 rollbackData.put("SERVICEINSTANCE", "rollbackAAI", "true")
295 rollbackData.put("SERVICEINSTANCE", "serviceInstanceId", serviceInstanceId)
296 rollbackData.put("SERVICEINSTANCE", "subscriptionServiceType", execution.getVariable("subscriptionServiceType"))
297 rollbackData.put("SERVICEINSTANCE", "globalSubscriberId", execution.getVariable("globalSubscriberId"))
298 execution.setVariable("rollbackData", rollbackData)
301 } catch (BpmnError e) {
303 } catch (Exception ex) {
304 msg = "Exception in DoCreateServiceInstance.postProcessAAIDEL. " + ex.getMessage()
306 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
308 msoLogger.trace("Exit postProcessAAIPUT ")
312 * Gets the service instance and its relationships from aai
314 public void getServiceInstance(DelegateExecution execution) {
316 String serviceInstanceId = execution.getVariable('serviceInstanceId')
317 String globalSubscriberId = execution.getVariable('globalSubscriberId')
318 String serviceType = execution.getVariable('subscriptionServiceType')
320 AAIResourcesClient resourceClient = new AAIResourcesClient()
321 AAIResourceUri serviceInstanceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, globalSubscriberId, serviceType, serviceInstanceId)
322 AAIResultWrapper wrapper = resourceClient.get(serviceInstanceUri, NotFoundException.class)
324 Optional<ServiceInstance> si = wrapper.asBean(ServiceInstance.class)
325 execution.setVariable("serviceInstanceName", si.get().getServiceInstanceName())
327 }catch(BpmnError e) {
329 }catch(Exception ex) {
330 String msg = "Internal Error in getServiceInstance: " + ex.getMessage()
331 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
335 public void postProcessAAIGET2(DelegateExecution execution) {
336 msoLogger.trace("postProcessAAIGET2 ")
340 String serviceInstanceName = execution.getVariable("serviceInstanceName")
341 boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")
343 msoLogger.info("Error getting Service-instance from AAI in postProcessAAIGET2", + serviceInstanceName)
344 WorkflowException workflowException = execution.getVariable("WorkflowException")
345 msoLogger.debug("workflowException: " + workflowException)
346 if(workflowException != null){
347 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
351 msg = "Failure in postProcessAAIGET2 GENGS_SuccessIndicator:" + succInAAI
353 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
358 boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")
360 String aaiService = execution.getVariable("GENGS_service")
361 if (!isBlank(aaiService) && (utils.nodeExists(aaiService, "service-instance-name"))) {
362 execution.setVariable("serviceInstanceName", utils.getNodeText(aaiService, "service-instance-name"))
363 msoLogger.info("Found Service-instance in AAI.serviceInstanceName:" + execution.getVariable("serviceInstanceName"))
367 } catch (BpmnError e) {
369 } catch (Exception ex) {
370 msg = "Exception in DoCreateServiceInstance.postProcessAAIGET2 " + ex.getMessage()
372 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
374 msoLogger.trace("Exit postProcessAAIGET2 ")
377 public void preProcessRollback (DelegateExecution execution) {
378 msoLogger.trace("preProcessRollback ")
381 Object workflowException = execution.getVariable("WorkflowException");
383 if (workflowException instanceof WorkflowException) {
384 msoLogger.info("Prev workflowException: " + workflowException.getErrorMessage())
385 execution.setVariable("prevWorkflowException", workflowException);
386 //execution.setVariable("WorkflowException", null);
388 } catch (BpmnError e) {
389 msoLogger.info("BPMN Error during preProcessRollback")
390 } catch(Exception ex) {
391 String msg = "Exception in preProcessRollback. " + ex.getMessage()
394 msoLogger.trace("Exit preProcessRollback ")
397 public void postProcessRollback (DelegateExecution execution) {
398 msoLogger.trace("postProcessRollback ")
401 Object workflowException = execution.getVariable("prevWorkflowException");
402 if (workflowException instanceof WorkflowException) {
403 msoLogger.info("Setting prevException to WorkflowException: ")
404 execution.setVariable("WorkflowException", workflowException);
406 execution.setVariable("rollbackData", null)
407 } catch (BpmnError b) {
408 msoLogger.info("BPMN Error during postProcessRollback")
410 } catch(Exception ex) {
411 msg = "Exception in postProcessRollback. " + ex.getMessage()
414 msoLogger.trace("Exit postProcessRollback ")
417 public void preInitResourcesOperStatus(DelegateExecution execution){
418 msoLogger.trace("STARTED preInitResourcesOperStatus Process ")
420 String serviceId = execution.getVariable("serviceInstanceId")
421 String operationId = execution.getVariable("operationId")
422 String operationType = execution.getVariable("operationType")
423 String resourceTemplateUUIDs = ""
424 String result = "processing"
425 String progress = "0"
427 String operationContent = "Prepare service creation"
428 msoLogger.info("Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId + " operationType:" + operationType)
429 serviceId = UriUtils.encode(serviceId,"UTF-8")
430 execution.setVariable("serviceInstanceId", serviceId)
431 execution.setVariable("operationId", operationId)
432 execution.setVariable("operationType", operationType)
433 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
434 List<Resource> resourceList = serviceDecomposition.getServiceResources()
436 for(Resource resource : resourceList){
437 resourceTemplateUUIDs = resourceTemplateUUIDs + resource.getModelInfo().getModelCustomizationUuid() + ":"
440 def dbAdapterEndpoint = "http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter"
441 execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
442 msoLogger.info("DB Adapter Endpoint is: " + dbAdapterEndpoint)
445 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
446 xmlns:ns="http://org.onap.so/requestsdb">
449 <ns:initResourceOperationStatus xmlns:ns="http://org.onap.so/requestsdb">
450 <serviceId>${MsoUtils.xmlEscape(serviceId)}</serviceId>
451 <operationId>${MsoUtils.xmlEscape(operationId)}</operationId>
452 <operationType>${MsoUtils.xmlEscape(operationType)}</operationType>
453 <resourceTemplateUUIDs>${MsoUtils.xmlEscape(resourceTemplateUUIDs)}</resourceTemplateUUIDs>
454 </ns:initResourceOperationStatus>
456 </soapenv:Envelope>"""
458 payload = utils.formatXml(payload)
459 execution.setVariable("CVFMI_initResOperStatusRequest", payload)
460 msoLogger.info("Outgoing initResourceOperationStatus: \n" + payload)
461 msoLogger.debug("CreateVfModuleInfra Outgoing initResourceOperationStatus Request: " + payload)
464 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occured Processing preInitResourcesOperStatus.", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e);
465 execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during preInitResourcesOperStatus Method:\n" + e.getMessage())
467 msoLogger.trace("COMPLETED preInitResourcesOperStatus Process ")
470 // if site location is in local Operator, create all resources in local ONAP;
471 // if site location is in 3rd Operator, only process sp-partner to create all resources in 3rd ONAP
472 public void doProcessSiteLocation(DelegateExecution execution){
473 msoLogger.trace("======== Start doProcessSiteLocation Process ======== ")
474 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
475 String uuiRequest = execution.getVariable("uuiRequest")
476 uuiRequest = ServicePluginFactory.getInstance().doProcessSiteLocation(serviceDecomposition, uuiRequest);
477 execution.setVariable("uuiRequest", uuiRequest)
478 execution.setVariable("serviceDecomposition", serviceDecomposition)
480 msoLogger.trace("======== COMPLETED doProcessSiteLocation Process ======== ")
483 // Allocate cross link TPs(terminal points) for sotn network only
484 public void doTPResourcesAllocation(DelegateExecution execution){
485 msoLogger.trace("======== Start doTPResourcesAllocation Process ======== ")
486 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
487 String uuiRequest = execution.getVariable("uuiRequest")
488 uuiRequest = ServicePluginFactory.getInstance().doTPResourcesAllocation(execution, uuiRequest);
489 execution.setVariable("uuiRequest", uuiRequest)
490 msoLogger.trace("======== COMPLETED doTPResourcesAllocation Process ======== ")
493 // prepare input param for using DoCreateResources.bpmn
494 public void preProcessForAddResource(DelegateExecution execution) {
495 msoLogger.trace("STARTED preProcessForAddResource Process ")
497 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
498 List<Resource> addResourceList = serviceDecomposition.getServiceResources()
499 execution.setVariable("addResourceList", addResourceList)
501 msoLogger.trace("COMPLETED preProcessForAddResource Process ")
504 public void postProcessForAddResource(DelegateExecution execution) {