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.client.aai.entities.uri.AAIUriFactory
46 import org.onap.so.logger.MessageEnum
47 import org.onap.so.logger.MsoLogger
48 import org.springframework.web.util.UriUtils;
55 * This groovy class supports the <class>DoCreateServiceInstance.bpmn</class> process.
58 * @param - msoRequestId
59 * @param - globalSubscriberId
60 * @param - subscriptionServiceType
61 * @param - serviceInstanceId
62 * @param - serviceInstanceName - O
63 * @param - serviceModelInfo
64 * @param - productFamilyId
65 * @param - disableRollback
66 * @param - failExists - TODO
67 * @param - serviceInputParams (should contain aic_zone for serviceTypes TRANSPORT,ATM)
68 * @param - sdncVersion ("1610")
69 * @param - serviceDecomposition - Decomposition for R1710
70 * (if macro provides serviceDecompsition then serviceModelInfo, serviceInstanceId & serviceInstanceName will be ignored)
73 * @param - rollbackData (localRB->null)
74 * @param - rolledBack (no localRB->null, localRB F->false, localRB S->true)
75 * @param - WorkflowException
76 * @param - serviceInstanceName - (GET from AAI if null in input)
79 public class DoCreateE2EServiceInstance extends AbstractServiceTaskProcessor {
80 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoCreateE2EServiceInstance.class);
83 String Prefix="DCRESI_"
84 ExceptionUtil exceptionUtil = new ExceptionUtil()
85 JsonUtils jsonUtil = new JsonUtils()
86 CatalogDbUtils cutils = new CatalogDbUtils()
88 public void preProcessRequest (DelegateExecution execution) {
90 msoLogger.trace("preProcessRequest ")
93 execution.setVariable("prefix", Prefix)
95 //requestDetails.subscriberInfo. for AAI GET & PUT & SDNC assignToplology
96 String globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId
97 msoLogger.info(" ***** globalSubscriberId *****" + globalSubscriberId)
98 //requestDetails.requestParameters. for AAI PUT & SDNC assignTopology
99 String serviceType = execution.getVariable("serviceType")
100 msoLogger.info(" ***** serviceType *****" + serviceType)
101 //requestDetails.requestParameters. for SDNC assignTopology
102 String productFamilyId = execution.getVariable("productFamilyId") //AAI productFamilyId
104 if (isBlank(globalSubscriberId)) {
105 msg = "Input globalSubscriberId is null"
107 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
110 if (isBlank(serviceType)) {
111 msg = "Input serviceType is null"
113 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
116 if (productFamilyId == null) {
117 execution.setVariable("productFamilyId", "")
120 String sdncCallbackUrl = execution.getVariable('URN_mso_workflow_sdncadapter_callback')
121 if (isBlank(sdncCallbackUrl)) {
122 msg = "URN_mso_workflow_sdncadapter_callback is null"
124 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
126 execution.setVariable("sdncCallbackUrl", sdncCallbackUrl)
127 msoLogger.info("SDNC Callback URL: " + sdncCallbackUrl)
129 //requestDetails.modelInfo.for AAI PUT servieInstanceData
130 //requestDetails.requestInfo. for AAI GET/PUT serviceInstanceData
131 String serviceInstanceName = execution.getVariable("serviceInstanceName")
132 String serviceInstanceId = execution.getVariable("serviceInstanceId")
133 String uuiRequest = execution.getVariable("uuiRequest")
134 String modelInvariantUuid = jsonUtil.getJsonValue(uuiRequest, "service.serviceInvariantUuid")
135 String modelUuid = jsonUtil.getJsonValue(uuiRequest, "service.serviceUuid")
136 String serviceModelName = jsonUtil.getJsonValue(uuiRequest, "service.parameters.templateName")
137 execution.setVariable("serviceModelName", serviceModelName)
138 //aai serviceType and Role can be setted as fixed value now.
139 String aaiServiceType = "E2E Service"
140 String aaiServiceRole = "E2E Service"
142 execution.setVariable("modelInvariantUuid", modelInvariantUuid)
143 execution.setVariable("modelUuid", modelUuid)
146 String oStatus = execution.getVariable("initialStatus") ?: ""
147 if ("TRANSPORT".equalsIgnoreCase(serviceType))
152 String statusLine = isBlank(oStatus) ? "" : "<orchestration-status>${MsoUtils.xmlEscape(oStatus)}</orchestration-status>"
154 AaiUtil aaiUriUtil = new AaiUtil(this)
155 String aai_uri = aaiUriUtil.getBusinessCustomerUri(execution)
156 String namespace = aaiUriUtil.getNamespaceFromUri(aai_uri)
157 String serviceInstanceData =
158 """<service-instance xmlns=\"${namespace}\">
159 <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceId)}</service-instance-id>
160 <service-instance-name>${MsoUtils.xmlEscape(serviceInstanceName)}</service-instance-name>
161 <service-type>${MsoUtils.xmlEscape(aaiServiceType)}</service-type>
162 <service-role>${MsoUtils.xmlEscape(aaiServiceRole)}</service-role>
164 <model-invariant-id>${MsoUtils.xmlEscape(modelInvariantUuid)}</model-invariant-id>
165 <model-version-id>${MsoUtils.xmlEscape(modelUuid)}</model-version-id>
166 </service-instance>""".trim()
167 execution.setVariable("serviceInstanceData", serviceInstanceData)
168 msoLogger.debug(serviceInstanceData)
169 msoLogger.info(" aai_uri " + aai_uri + " namespace:" + namespace)
170 msoLogger.info(" 'payload' to create Service Instance in AAI - " + "\n" + serviceInstanceData)
172 } catch (BpmnError e) {
174 } catch (Exception ex){
175 msg = "Exception in preProcessRequest " + ex.getMessage()
177 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
179 msoLogger.trace("Exit preProcessRequest ")
182 public void prepareDecomposeService(DelegateExecution execution) {
184 msoLogger.trace("Inside prepareDecomposeService of create generic e2e service ")
185 String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
186 String modelUuid = execution.getVariable("modelUuid")
187 //here modelVersion is not set, we use modelUuid to decompose the service.
188 String serviceModelInfo = """{
189 "modelInvariantUuid":"${modelInvariantUuid}",
190 "modelUuid":"${modelUuid}",
193 execution.setVariable("serviceModelInfo", serviceModelInfo)
195 msoLogger.trace("Completed prepareDecomposeService of create generic e2e service ")
196 } catch (Exception ex) {
197 // try error in method block
198 String exceptionMessage = "Bpmn error encountered in create generic e2e service flow. Unexpected Error from method prepareDecomposeService() - " + ex.getMessage()
199 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
203 public void processDecomposition(DelegateExecution execution) {
204 msoLogger.trace("Inside processDecomposition() of create generic e2e service flow ")
206 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
207 } catch (Exception ex) {
208 String exceptionMessage = "Bpmn error encountered in create generic e2e service flow. processDecomposition() - " + ex.getMessage()
209 msoLogger.debug(exceptionMessage)
210 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
214 public void doServicePreOperation(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().preProcessService(serviceDecomposition, uuiRequest);
219 execution.setVariable("uuiRequest", newUuiRequest)
222 public void doServiceHoming(DelegateExecution execution) {
223 //we need a service plugin platform here.
224 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
225 String uuiRequest = execution.getVariable("uuiRequest")
226 String newUuiRequest = ServicePluginFactory.getInstance().doServiceHoming(serviceDecomposition, uuiRequest);
227 execution.setVariable("uuiRequest", newUuiRequest)
230 public void postProcessAAIGET(DelegateExecution execution) {
231 msoLogger.trace("postProcessAAIGET ")
235 String serviceInstanceName = execution.getVariable("serviceInstanceName")
236 boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")
238 msoLogger.info("Error getting Service-instance from AAI", + serviceInstanceName)
239 WorkflowException workflowException = execution.getVariable("WorkflowException")
240 msoLogger.debug("workflowException: " + workflowException)
241 if(workflowException != null){
242 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
246 msg = "Failure in postProcessAAIGET GENGS_SuccessIndicator:" + succInAAI
248 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
253 boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")
255 msoLogger.info("Found Service-instance in AAI")
256 msg = "ServiceInstance already exists in AAI:" + serviceInstanceName
258 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
261 } catch (BpmnError e) {
263 } catch (Exception ex) {
264 msg = "Exception in DoCreateServiceInstance.postProcessAAIGET. " + ex.getMessage()
266 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
268 msoLogger.trace("Exit postProcessAAIGET ")
271 //TODO use create if not exist
272 public void postProcessAAIPUT(DelegateExecution execution) {
273 msoLogger.trace("postProcessAAIPUT ")
276 String serviceInstanceId = execution.getVariable("serviceInstanceId")
277 boolean succInAAI = execution.getVariable("GENPS_SuccessIndicator")
279 msoLogger.info("Error putting Service-instance in AAI", + serviceInstanceId)
280 WorkflowException workflowException = execution.getVariable("WorkflowException")
281 msoLogger.debug("workflowException: " + workflowException)
282 if(workflowException != null){
283 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
288 //start rollback set up
289 RollbackData rollbackData = new RollbackData()
290 def disableRollback = execution.getVariable("disableRollback")
291 rollbackData.put("SERVICEINSTANCE", "disableRollback", disableRollback.toString())
292 rollbackData.put("SERVICEINSTANCE", "rollbackAAI", "true")
293 rollbackData.put("SERVICEINSTANCE", "serviceInstanceId", serviceInstanceId)
294 rollbackData.put("SERVICEINSTANCE", "subscriptionServiceType", execution.getVariable("subscriptionServiceType"))
295 rollbackData.put("SERVICEINSTANCE", "globalSubscriberId", execution.getVariable("globalSubscriberId"))
296 execution.setVariable("rollbackData", rollbackData)
299 } catch (BpmnError e) {
301 } catch (Exception ex) {
302 msg = "Exception in DoCreateServiceInstance.postProcessAAIDEL. " + ex.getMessage()
304 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
306 msoLogger.trace("Exit postProcessAAIPUT ")
310 * Gets the service instance and its relationships from aai
312 public void getServiceInstance(DelegateExecution execution) {
314 String serviceInstanceId = execution.getVariable('serviceInstanceId')
315 String globalSubscriberId = execution.getVariable('globalSubscriberId')
316 String serviceType = execution.getVariable('subscriptionServiceType')
318 AAIResourcesClient resourceClient = new AAIResourcesClient()
319 AAIResourceUri serviceInstanceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, globalSubscriberId, serviceType, serviceInstanceId)
320 AAIResultWrapper wrapper = resourceClient.get(serviceInstanceUri, NotFoundException.class)
322 ServiceInstance si = wrapper.asBean(ServiceInstance.class)
323 execution.setVariable("serviceInstanceName", si.getServiceInstanceName())
325 }catch(BpmnError e) {
327 }catch(Exception ex) {
328 String msg = "Internal Error in getServiceInstance: " + ex.getMessage()
329 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
334 public void postProcessAAIGET2(DelegateExecution execution) {
335 msoLogger.trace("postProcessAAIGET2 ")
339 String serviceInstanceName = execution.getVariable("serviceInstanceName")
340 boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")
342 msoLogger.info("Error getting Service-instance from AAI in postProcessAAIGET2", + serviceInstanceName)
343 WorkflowException workflowException = execution.getVariable("WorkflowException")
344 msoLogger.debug("workflowException: " + workflowException)
345 if(workflowException != null){
346 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
350 msg = "Failure in postProcessAAIGET2 GENGS_SuccessIndicator:" + succInAAI
352 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
357 boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")
359 String aaiService = execution.getVariable("GENGS_service")
360 if (!isBlank(aaiService) && (utils.nodeExists(aaiService, "service-instance-name"))) {
361 execution.setVariable("serviceInstanceName", utils.getNodeText(aaiService, "service-instance-name"))
362 msoLogger.info("Found Service-instance in AAI.serviceInstanceName:" + execution.getVariable("serviceInstanceName"))
366 } catch (BpmnError e) {
368 } catch (Exception ex) {
369 msg = "Exception in DoCreateServiceInstance.postProcessAAIGET2 " + ex.getMessage()
371 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
373 msoLogger.trace("Exit postProcessAAIGET2 ")
376 public void preProcessRollback (DelegateExecution execution) {
377 msoLogger.trace("preProcessRollback ")
380 Object workflowException = execution.getVariable("WorkflowException");
382 if (workflowException instanceof WorkflowException) {
383 msoLogger.info("Prev workflowException: " + workflowException.getErrorMessage())
384 execution.setVariable("prevWorkflowException", workflowException);
385 //execution.setVariable("WorkflowException", null);
387 } catch (BpmnError e) {
388 msoLogger.info("BPMN Error during preProcessRollback")
389 } catch(Exception ex) {
390 String msg = "Exception in preProcessRollback. " + ex.getMessage()
393 msoLogger.trace("Exit preProcessRollback ")
396 public void postProcessRollback (DelegateExecution execution) {
397 msoLogger.trace("postProcessRollback ")
400 Object workflowException = execution.getVariable("prevWorkflowException");
401 if (workflowException instanceof WorkflowException) {
402 msoLogger.info("Setting prevException to WorkflowException: ")
403 execution.setVariable("WorkflowException", workflowException);
405 execution.setVariable("rollbackData", null)
406 } catch (BpmnError b) {
407 msoLogger.info("BPMN Error during postProcessRollback")
409 } catch(Exception ex) {
410 msg = "Exception in postProcessRollback. " + ex.getMessage()
413 msoLogger.trace("Exit postProcessRollback ")
416 public void preInitResourcesOperStatus(DelegateExecution execution){
417 msoLogger.trace("STARTED preInitResourcesOperStatus Process ")
419 String serviceId = execution.getVariable("serviceInstanceId")
420 String operationId = execution.getVariable("operationId")
421 String operationType = execution.getVariable("operationType")
422 String resourceTemplateUUIDs = ""
423 String result = "processing"
424 String progress = "0"
426 String operationContent = "Prepare service creation"
427 msoLogger.info("Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId + " operationType:" + operationType)
428 serviceId = UriUtils.encode(serviceId,"UTF-8")
429 execution.setVariable("serviceInstanceId", serviceId)
430 execution.setVariable("operationId", operationId)
431 execution.setVariable("operationType", operationType)
432 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
433 List<Resource> resourceList = serviceDecomposition.getServiceResources()
435 for(Resource resource : resourceList){
436 resourceTemplateUUIDs = resourceTemplateUUIDs + resource.getModelInfo().getModelCustomizationUuid() + ":"
439 def dbAdapterEndpoint = "http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter"
440 execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
441 msoLogger.info("DB Adapter Endpoint is: " + dbAdapterEndpoint)
444 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
445 xmlns:ns="http://org.onap.so/requestsdb">
448 <ns:initResourceOperationStatus xmlns:ns="http://org.onap.so/requestsdb">
449 <serviceId>${MsoUtils.xmlEscape(serviceId)}</serviceId>
450 <operationId>${MsoUtils.xmlEscape(operationId)}</operationId>
451 <operationType>${MsoUtils.xmlEscape(operationType)}</operationType>
452 <resourceTemplateUUIDs>${MsoUtils.xmlEscape(resourceTemplateUUIDs)}</resourceTemplateUUIDs>
453 </ns:initResourceOperationStatus>
455 </soapenv:Envelope>"""
457 payload = utils.formatXml(payload)
458 execution.setVariable("CVFMI_initResOperStatusRequest", payload)
459 msoLogger.info("Outgoing initResourceOperationStatus: \n" + payload)
460 msoLogger.debug("CreateVfModuleInfra Outgoing initResourceOperationStatus Request: " + payload)
463 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occured Processing preInitResourcesOperStatus.", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e);
464 execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during preInitResourcesOperStatus Method:\n" + e.getMessage())
466 msoLogger.trace("COMPLETED preInitResourcesOperStatus Process ")
469 // prepare input param for using DoCreateResources.bpmn
470 public void preProcessForAddResource(DelegateExecution execution) {
471 msoLogger.trace("STARTED preProcessForAddResource Process ")
473 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
474 List<Resource> addResourceList = serviceDecomposition.getServiceResources()
475 execution.setVariable("addResourceList", addResourceList)
477 msoLogger.trace("COMPLETED preProcessForAddResource Process ")
480 public void postProcessForAddResource(DelegateExecution execution) {