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 org.apache.commons.lang3.*
26 import org.camunda.bpm.engine.delegate.BpmnError
27 import org.camunda.bpm.engine.delegate.DelegateExecution
28 import org.json.JSONArray;
29 import org.json.JSONObject;
30 import org.onap.so.bpmn.common.scripts.AaiUtil
31 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
32 import org.onap.so.bpmn.common.scripts.ExceptionUtil
33 import org.onap.so.bpmn.common.scripts.MsoUtils
34 import org.onap.so.bpmn.core.WorkflowException
35 import org.onap.so.bpmn.core.json.JsonUtils
36 import org.onap.so.logger.MessageEnum
37 import org.onap.so.logger.MsoLogger
38 import org.onap.so.rest.APIResponse;
39 import org.springframework.web.util.UriUtils;
40 import org.onap.so.client.aai.AAIResourcesClient
41 import org.onap.so.client.aai.AAIObjectType
42 import org.onap.so.client.aai.entities.AAIResultWrapper
43 import org.onap.so.client.aai.entities.Relationships
44 import org.onap.so.client.aai.entities.uri.AAIResourceUri
45 import org.onap.so.client.aai.entities.uri.AAIUriFactory
46 import org.json.JSONObject
47 import javax.ws.rs.NotFoundException
53 * This groovy class supports the <class>DoDeleteE2EServiceInstance.bpmn</class> process.
56 * @param - msoRequestId
57 * @param - globalSubscriberId - O
58 * @param - subscriptionServiceType - O
59 * @param - serviceInstanceId
60 * @param - serviceInstanceName - O
61 * @param - serviceInputParams (should contain aic_zone for serviceTypes TRANSPORT,ATM)
62 * @param - sdncVersion
63 * @param - failNotFound - TODO
64 * @param - serviceInputParams - TODO
67 * @param - WorkflowException
71 public class DoCustomDeleteE2EServiceInstanceV2 extends AbstractServiceTaskProcessor {
72 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoCustomDeleteE2EServiceInstanceV2.class);
75 String Prefix="DDELSI_"
76 private static final String DebugFlag = "isDebugEnabled"
77 ExceptionUtil exceptionUtil = new ExceptionUtil()
78 JsonUtils jsonUtil = new JsonUtils()
80 public void preProcessRequest (DelegateExecution execution) {
82 def method = getClass().getSimpleName() + '.buildAPPCRequest(' +'execution=' + execution.getId() +')'
83 msoLogger.info("Entered " + method)
84 msoLogger.trace("preProcessRequest ")
88 String requestId = execution.getVariable("msoRequestId")
89 execution.setVariable("prefix",Prefix)
92 //requestDetails.subscriberInfo. for AAI GET & PUT & SDNC assignToplology
93 String globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId
94 if (globalSubscriberId == null)
96 execution.setVariable("globalSubscriberId", "")
99 //requestDetails.requestParameters. for AAI PUT & SDNC assignTopology
100 String serviceType = execution.getVariable("serviceType")
101 if (serviceType == null)
103 execution.setVariable("serviceType", "")
106 //Generated in parent for AAI PUT
107 String serviceInstanceId = execution.getVariable("serviceInstanceId")
108 if (isBlank(serviceInstanceId)){
109 msg = "Input serviceInstanceId is null"
111 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
114 String sdncCallbackUrl = execution.getVariable('URN_mso_workflow_sdncadapter_callback')
115 if (isBlank(sdncCallbackUrl)) {
116 msg = "URN_mso_workflow_sdncadapter_callback is null"
118 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
120 execution.setVariable("sdncCallbackUrl", sdncCallbackUrl)
121 msoLogger.info("SDNC Callback URL: " + sdncCallbackUrl)
123 StringBuilder sbParams = new StringBuilder()
124 Map<String, String> paramsMap = execution.getVariable("serviceInputParams")
125 if (paramsMap != null)
127 sbParams.append("<service-input-parameters>")
128 for (Map.Entry<String, String> entry : paramsMap.entrySet()) {
130 String paramName = entry.getKey()
131 String paramValue = entry.getValue()
134 <name>${MsoUtils.xmlEscape(paramName)}</name>
135 <value>${MsoUtils.xmlEscape(paramValue)}</value>
138 sbParams.append(paramsXml)
140 sbParams.append("</service-input-parameters>")
142 String siParamsXml = sbParams.toString()
143 if (siParamsXml == null)
145 execution.setVariable("siParamsXml", siParamsXml)
146 execution.setVariable("operationStatus", "Waiting delete resource...")
147 execution.setVariable("progress", "0")
149 } catch (BpmnError e) {
151 } catch (Exception ex){
152 msg = "Exception in preProcessRequest " + ex.getMessage()
154 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
156 msoLogger.info("Exited " + method)
160 * Gets the service instance and its relationships from aai
164 public void getServiceInstance(DelegateExecution execution) {
166 String serviceInstanceId = execution.getVariable('serviceInstanceId')
167 String globalSubscriberId = execution.getVariable('globalSubscriberId')
168 String serviceType = execution.getVariable('serviceType')
170 AAIResourcesClient resourceClient = new AAIResourcesClient()
171 AAIResourceUri serviceInstanceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, globalSubscriberId, serviceType, serviceInstanceId)
172 AAIResultWrapper wrapper = resourceClient.get(serviceInstanceUri, NotFoundException.class)
173 String json = wrapper.getJson()
175 execution.setVariable("serviceInstance", json)
177 }catch(BpmnError e) {
179 }catch(NotFoundException e) {
180 msoLogger.info("SI not found in aai. Silent Success ")
181 }catch(Exception ex) {
182 String msg = "Internal Error in getServiceInstance: " + ex.getMessage()
183 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
187 private void loadResourcesProperties(DelegateExecution execution) {
188 def method = getClass().getSimpleName() + '.loadResourcesProperties(' +'execution=' + execution.getId() +')'
189 def isDebugEnabled = execution.getVariable("isDebugEnabled")
190 msoLogger.info("Entered " + method)
191 String loadFilePath = "/etc/mso/config.d/reources.json"
193 def jsonPayload = new File(loadFilePath).text
194 msoLogger.info("jsonPayload: " + jsonPayload)
196 String resourcesProperties = jsonUtil.prettyJson(jsonPayload.toString())
197 msoLogger.info("resourcesProperties: " + resourcesProperties)
199 String createResourceSort = jsonUtil.getJsonValue(resourcesProperties, "CreateResourceSort")
200 msoLogger.info("createResourceSort: " + createResourceSort)
201 execution.setVariable("createResourceSort", createResourceSort)
203 String deleteResourceSort = jsonUtil.getJsonValue(resourcesProperties, "DeleteResourceSort")
204 msoLogger.info("deleteResourceSort: " + deleteResourceSort)
205 execution.setVariable("deleteResourceSort", deleteResourceSort)
208 String resourceControllerType = jsonUtil.getJsonValue(resourcesProperties, "ResourceControllerType")
209 msoLogger.info("resourceControllerType: " + resourceControllerType)
210 execution.setVariable("resourceControllerType", resourceControllerType)
213 }catch(Exception ex){
214 // try error in method block
215 String exceptionMessage = "Bpmn error encountered in " + method + " - " + ex.getMessage()
216 msoLogger.debug(exceptionMessage)
217 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
219 msoLogger.info("Exited " + method)
221 private void sortDeleteResource(DelegateExecution execution) {
222 def method = getClass().getSimpleName() + '.sortDeleteResource(' +'execution=' + execution.getId() +')'
223 def isDebugEnabled = execution.getVariable("isDebugEnabled")
224 msoLogger.info("Entered " + method)
225 String deleteResourceSortDef = """[
227 "resourceType":"GRE_SAR"
230 "resourceType":"VPN_SAR"
233 "resourceType":"APN_AAR"
236 "resourceType":"GRE_AAR"
239 "resourceType":"Overlay"
242 "resourceType":"Underlay"
245 "resourceType":"vIMS"
248 "resourceType":"vCPE"
254 "resourceType":"vEPC"
261 loadResourcesProperties(execution)
262 String deleteResourceSort = execution.getVariable("deleteResourceSort")
263 if (isBlank(deleteResourceSort)) {
264 deleteResourceSort = deleteResourceSortDef;
267 List<String> sortResourceList = jsonUtil.StringArrayToList(execution, deleteResourceSort)
268 msoLogger.info("sortResourceList : " + sortResourceList)
270 JSONArray newResourceList = new JSONArray()
271 int resSortCount = sortResourceList.size()
273 for ( int currentResource = 0 ; currentResource < resSortCount ; currentResource++ ) {
274 String currentSortResource = sortResourceList[currentResource]
275 String sortResourceType = jsonUtil.getJsonValue(currentSortResource, "resourceType")
276 List<String> resourceList = execution.getVariable(Prefix+"resourceList")
278 for (String resource : resourceList) {
279 msoLogger.info("resource : " + resource)
280 String resourceType = jsonUtil.getJsonValue(resource, "resourceType")
282 if (StringUtils.containsIgnoreCase(resourceType, sortResourceType)) {
283 JSONObject jsonObj = new JSONObject(resource)
284 newResourceList.put(jsonObj)
286 msoLogger.info("Get next sort type " )
290 String newResourceStr = newResourceList.toString()
291 List<String> newResourceListStr = jsonUtil.StringArrayToList(execution, newResourceStr)
293 execution.setVariable(Prefix+"resourceList", newResourceListStr)
294 msoLogger.info("newResourceList : " + newResourceListStr)
296 }catch(Exception ex){
297 // try error in method block
298 String exceptionMessage = "Bpmn error encountered in " + method + " - " + ex.getMessage()
299 msoLogger.debug(exceptionMessage)
300 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
302 msoLogger.info("Exited " + method)
305 public void prepareServiceDeleteResource(DelegateExecution execution) {
306 def method = getClass().getSimpleName() + '.prepareServiceDeleteResource(' +'execution=' + execution.getId() +')'
307 msoLogger.info("Entered " + method)
311 String serviceInstanceId = execution.getVariable("serviceInstanceId")
314 execution.setVariable(Prefix+"resourceList", "")
315 execution.setVariable(Prefix+"resourceCount", 0)
316 execution.setVariable(Prefix+"nextResource", 0)
317 execution.setVariable(Prefix+"resourceFinish", true)
319 String aaiJsonRecord = execution.getVariable("serviceInstance");
320 msoLogger.info("serviceInstanceAaiRecord: " +aaiJsonRecord)
322 msoLogger.info("aaiJsonRecord: " +aaiJsonRecord)
323 def serviceInstanceName = jsonUtil.getJsonValue(aaiJsonRecord, "service-instance.service-instance-name")
324 execution.setVariable("serviceInstanceName",serviceInstanceName)
326 def serviceType = jsonUtil.getJsonValue(aaiJsonRecord, "service-instance.service-type")
327 execution.setVariable("serviceType",serviceType)
330 String relationshipList = jsonUtil.getJsonValue(aaiJsonRecord, "service-instance.relationship-list")
331 msoLogger.info("relationship-list:" + relationshipList)
332 if (! isBlank(relationshipList)){
333 msoLogger.info("relationship-list exists" )
334 String relationShip = jsonUtil.getJsonValue(relationshipList, "relationship")
335 msoLogger.info("relationship: " + relationShip)
336 JSONArray allResources = new JSONArray()
337 JSONArray serviceResources = new JSONArray()
338 JSONArray networkResources = new JSONArray()
339 JSONArray allottedResources = new JSONArray()
342 if (! isBlank(relationShip)){
343 JSONArray jsonArray = new JSONArray();
344 if (relationShip.startsWith("{") && relationShip.endsWith("}")) {
345 JSONObject jsonObject = new JSONObject(relationShip);
346 jsonArray.put(jsonObject);
347 } else if (relationShip.startsWith("[") && relationShip.endsWith("]")) {
348 jsonArray = new JSONArray(relationShip);
350 msoLogger.info("The relationShip fomart is error" )
353 List<String> relationList = jsonUtil.StringArrayToList(execution, jsonArray.toString())
355 msoLogger.info("relationList: " + relationList)
357 int relationNum =relationList.size()
358 msoLogger.info("**************relationList size: " + relationNum)
360 for ( int currentRelation = 0 ; currentRelation < relationNum ; currentRelation++ ) {
361 msoLogger.info("current Relation num: " + currentRelation)
362 String relation = relationList[currentRelation]
363 msoLogger.info("relation: " + relation)
365 String relatedTo = jsonUtil.getJsonValue(relation, "related-to")
366 msoLogger.info("relatedTo: " + relatedTo)
368 String relatedLink = jsonUtil.getJsonValue(relation, "related-link")
369 msoLogger.info("relatedLink: " + relatedLink)
371 if (StringUtils.equalsIgnoreCase(relatedTo, "allotted-resource")) {
372 msoLogger.info("allotted-resource exists ")
374 String aaiArRsp = getAaiAr(execution, relatedLink)
375 msoLogger.info("aaiArRsp: " + aaiArRsp)
376 if (! isBlank(aaiArRsp)) {
377 def type = utils.getNodeText(aaiArRsp, "type")
378 def id = utils.getNodeText(aaiArRsp, "id")
379 def role = utils.getNodeText(aaiArRsp, "role")
380 def resourceVersion = utils.getNodeText(aaiArRsp, "resource-version")
382 JSONObject jObject = new JSONObject()
383 jObject.put("resourceType", type)
384 jObject.put("resourceInstanceId", id)
385 jObject.put("resourceRole", role)
386 jObject.put("resourceVersion", resourceVersion)
388 allResources.put(jObject)
389 msoLogger.info("allResources: " + allResources)
390 allottedResources.put(jObject)
391 msoLogger.info("allottedResources: " + allottedResources)
394 else if (StringUtils.equalsIgnoreCase(relatedTo, "service-instance")){
395 msoLogger.info("service-instance exists ")
396 JSONObject jObject = new JSONObject()
399 String rsDataStr = jsonUtil.getJsonValue(relation, "relationship-data")
400 msoLogger.info("rsDataStr: " + rsDataStr)
401 List<String> rsDataList = jsonUtil.StringArrayToList(execution, rsDataStr)
402 msoLogger.info("rsDataList: " + rsDataList)
403 for(String rsData : rsDataList){
404 msoLogger.info("rsData: " + rsData)
405 def eKey = jsonUtil.getJsonValue(rsData, "relationship-key")
406 def eValue = jsonUtil.getJsonValue(rsData, "relationship-value")
407 if(eKey.equals("service-instance.service-instance-id")){
408 jObject.put("resourceInstanceId", eValue)
410 if(eKey.equals("service-subscription.service-type")){
411 jObject.put("resourceType", eValue)
415 //related-to-property
416 String rPropertyStr = jsonUtil.getJsonValue(relation, "related-to-property")
417 msoLogger.info("related-to-property: " + rPropertyStr)
418 if (rPropertyStr instanceof JSONArray){
419 List<String> rPropertyList = jsonUtil.StringArrayToList(execution, rPropertyStr)
420 for (String rProperty : rPropertyList) {
421 msoLogger.info("rProperty: " + rProperty)
422 def eKey = jsonUtil.getJsonValue(rProperty, "property-key")
423 def eValue = jsonUtil.getJsonValue(rProperty, "property-value")
424 if(eKey.equals("service-instance.service-instance-name")){
425 jObject.put("resourceName", eValue)
430 String rProperty = rPropertyStr
431 msoLogger.info("rProperty: " + rProperty)
432 def eKey = jsonUtil.getJsonValue(rProperty, "property-key")
433 def eValue = jsonUtil.getJsonValue(rProperty, "property-value")
434 if (eKey.equals("service-instance.service-instance-name")) {
435 jObject.put("resourceName", eValue)
439 allResources.put(jObject)
440 msoLogger.info("allResources: " + allResources)
442 serviceResources.put(jObject)
443 msoLogger.info("serviceResources: " + serviceResources)
445 else if (StringUtils.equalsIgnoreCase(relatedTo, "configuration")) {
446 msoLogger.info("configuration ")
447 JSONObject jObject = new JSONObject()
450 String rsDataStr = jsonUtil.getJsonValue(relation, "relationship-data")
451 msoLogger.info("rsDataStr: " + rsDataStr)
452 List<String> rsDataList = jsonUtil.StringArrayToList(execution, rsDataStr)
453 msoLogger.info("rsDataList: " + rsDataList)
454 for (String rsData : rsDataList) {
455 msoLogger.info("rsData: " + rsData)
456 def eKey = jsonUtil.getJsonValue(rsData, "relationship-key")
457 def eValue = jsonUtil.getJsonValue(rsData, "relationship-value")
458 if(eKey.equals("configuration.configuration-id")){
459 jObject.put("resourceInstanceId", eValue)
464 //related-to-property
465 String rPropertyStr = jsonUtil.getJsonValue(relation, "related-to-property")
466 msoLogger.info("related-to-property: " + rPropertyStr)
467 if (rPropertyStr instanceof JSONArray){
468 List<String> rPropertyList = jsonUtil.StringArrayToList(execution, rPropertyStr)
469 for(String rProperty : rPropertyList){
470 msoLogger.info("rProperty: " + rProperty)
471 def eKey = jsonUtil.getJsonValue(rProperty, "property-key")
472 def eValue = jsonUtil.getJsonValue(rProperty, "property-value")
473 if(eKey.equals("configuration.configuration-type")){
474 jObject.put("resourceType", eValue)
479 String rProperty = rPropertyStr
480 msoLogger.info("rProperty: " + rProperty)
481 def eKey = jsonUtil.getJsonValue(rProperty, "property-key")
482 def eValue = jsonUtil.getJsonValue(rProperty, "property-value")
483 if(eKey.equals("configuration.configuration-type")){
484 jObject.put("resourceType", eValue)
487 allResources.put(jObject)
488 msoLogger.info("allResources: " + allResources)
490 networkResources.put(jObject)
491 msoLogger.info("networkResources: " + networkResources)
493 msoLogger.info("Get Next releation resource " )
496 msoLogger.info("Get releation finished. " )
499 execution.setVariable("serviceRelationShip", allResources.toString())
500 msoLogger.info("allResources: " + allResources.toString())
501 String serviceRelationShip = execution.getVariable("serviceRelationShip")
502 msoLogger.info("serviceRelationShip: " + serviceRelationShip)
503 if ((! isBlank(serviceRelationShip)) && (! serviceRelationShip.isEmpty())) {
505 List<String> relationShipList = jsonUtil.StringArrayToList(execution, serviceRelationShip)
506 msoLogger.info("relationShipList: " + relationShipList)
507 execution.setVariable(Prefix+"resourceList", relationShipList)
509 int resourceCount = relationShipList.size()
510 msoLogger.info("resourceCount: " + resourceCount)
511 execution.setVariable(Prefix+"resourceCount",resourceCount )
514 execution.setVariable(Prefix+"nextResource", resourceNum)
515 msoLogger.info("start sort delete resource: ")
516 sortDeleteResource(execution)
519 if (resourceNum < resourceCount) {
520 execution.setVariable(Prefix+"resourceFinish", false)
523 execution.setVariable(Prefix+"resourceFinish", true)
525 msoLogger.info("Resource list set end : " + resourceCount)
528 execution.setVariable("serviceResources", serviceResources.toString())
529 msoLogger.info("serviceResources: " + serviceResources)
530 String serviceResourcesShip = execution.getVariable("serviceResources")
531 msoLogger.info("serviceResourcesShip: " + serviceResourcesShip)
533 if ((! isBlank(serviceResourcesShip)) && (! serviceResourcesShip.isEmpty())) {
534 List<String> serviceResourcesList = jsonUtil.StringArrayToList(execution, serviceResourcesShip)
535 msoLogger.info("serviceResourcesList: " + serviceResourcesList)
536 execution.setVariable(Prefix+"serviceResourceList", serviceResourcesList)
537 execution.setVariable(Prefix+"serviceResourceCount", serviceResourcesList.size())
538 execution.setVariable(Prefix+"nextServiceResource", 0)
539 msoLogger.info("Service Resource list set end : " + serviceResourcesList.size())
543 execution.setVariable("allottedResources", allottedResources.toString())
544 msoLogger.info("allottedResources: " + allottedResources)
545 String allottedResourcesShip = execution.getVariable("allottedResources")
546 msoLogger.info("allottedResourcesShip: " + allottedResourcesShip)
547 if ((! isBlank(allottedResourcesShip)) && (! allottedResourcesShip.isEmpty())) {
548 List<String> allottedResourcesList = jsonUtil.StringArrayToList(execution, allottedResourcesShip)
549 msoLogger.info("allottedResourcesList: " + allottedResourcesList)
550 execution.setVariable(Prefix+"allottedResourcesList", allottedResourcesList)
551 execution.setVariable(Prefix+"allottedResourcesListCount", allottedResourcesList.size())
552 execution.setVariable(Prefix+"nextAllottedResourcesList", 0)
553 msoLogger.info("Allotted Resource list set end : " + allottedResourcesList.size())
556 execution.setVariable("networkResources", networkResources.toString())
557 msoLogger.info("networkResources: " + networkResources)
558 String networkResourcesShip = execution.getVariable("networkResources")
559 msoLogger.info("networkResourcesShip: " + networkResourcesShip)
560 if ((! isBlank(networkResourcesShip)) && (! networkResourcesShip.isEmpty())) {
561 List<String> networkResourcesList = jsonUtil.StringArrayToList(execution, networkResourcesShip)
562 msoLogger.info("networkResourcesList: " + networkResourcesList)
563 execution.setVariable(Prefix+"networkResourcesList", networkResourcesList)
564 execution.setVariable(Prefix+"networkResourcesListCount", networkResourcesList.size())
565 execution.setVariable(Prefix+"nextNetworkResourcesList", 0)
566 msoLogger.info("Network Resource list set end : " + networkResourcesList.size())
570 } catch (BpmnError e){
572 } catch (Exception ex) {
573 String exceptionMessage = "Bpmn error encountered in DeleteMobileAPNCustService flow. prepareServiceDeleteResource() - " + ex.getMessage()
574 msoLogger.debug(exceptionMessage)
575 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
577 msoLogger.info("Exited " + method)
580 private String getAaiAr(DelegateExecution execution, String relink) {
581 def method = getClass().getSimpleName() + '.getAaiAr(' +'execution=' + execution.getId() +')'
582 msoLogger.info("Entered " + method)
583 AaiUtil aaiUtil = new AaiUtil(this)
584 String aaiEndpoint = execution.getVariable("URN_aai_endpoint") + relink
586 msoLogger.debug("get AR info " + aaiEndpoint)
587 APIResponse response = aaiUtil.executeAAIGetCall(execution, aaiEndpoint)
589 int responseCode = response.getStatusCode()
590 msoLogger.debug("get AR info responseCode:" + responseCode)
592 String aaiResponse = response.getResponseBodyAsString()
593 msoLogger.debug("get AR info " + aaiResponse)
595 if(responseCode < 200 || responseCode >= 300 || isBlank(aaiResponse)) {
599 msoLogger.info("Exited " + method)
603 * prepare Decompose next resource to create request
605 public void preProcessDecomposeNextResource(DelegateExecution execution){
606 def method = getClass().getSimpleName() + '.getAaiAr(' +'execution=' + execution.getId() +')'
607 msoLogger.info("Entered " + method)
608 msoLogger.trace("STARTED preProcessDecomposeNextResource Process ")
610 int resourceNum = execution.getVariable(Prefix+"nextServiceResource")
611 List<String> serviceResourceList = execution.getVariable(Prefix+"serviceResourceList")
612 msoLogger.info("Service Resource List : " + serviceResourceList)
614 String serviceResource = serviceResourceList[resourceNum]
615 execution.setVariable(Prefix+"serviceResource", serviceResource)
616 msoLogger.info("Current Service Resource : " + serviceResource)
618 String resourceType = jsonUtil.getJsonValue(serviceResource, "resourceType")
619 execution.setVariable("resourceType", resourceType)
620 msoLogger.info("resourceType : " + resourceType)
622 String resourceInstanceId = jsonUtil.getJsonValue(serviceResource, "resourceInstanceId")
623 execution.setVariable("resourceInstanceId", resourceInstanceId)
624 msoLogger.info("resourceInstanceId : " + resourceInstanceId)
626 String resourceRole = jsonUtil.getJsonValue(serviceResource, "resourceRole")
627 execution.setVariable("resourceRole", resourceRole)
628 msoLogger.info("resourceRole : " + resourceRole)
630 String resourceVersion = jsonUtil.getJsonValue(serviceResource, "resourceVersion")
631 execution.setVariable("resourceVersion", resourceVersion)
632 msoLogger.info("resourceVersion : " + resourceVersion)
634 String resourceName = jsonUtil.getJsonValue(serviceResource, "resourceName")
635 if (isBlank(resourceName)){
636 resourceName = resourceInstanceId
638 execution.setVariable(Prefix+"resourceName", resourceName)
639 msoLogger.info("resource Name : " + resourceName)
642 execution.setVariable(Prefix+"nextServiceResource", resourceNum + 1)
644 int serviceResourceCount = execution.getVariable(Prefix+"serviceResourceCount")
645 if (serviceResourceCount >0 ){
646 int progress = (resourceNum*100) / serviceResourceCount
647 execution.setVariable("progress", progress.toString() )
649 execution.setVariable("operationStatus", resourceName )
652 // try error in method block
653 String exceptionMessage = "Bpmn error encountered in CreateMobileAPNCustService flow. Unexpected Error from method preProcessDecomposeNextResource() - " + ex.getMessage()
654 msoLogger.debug(exceptionMessage)
655 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
657 msoLogger.info("Exited " + method)
660 * post Decompose next resource to create request
662 public void postProcessDecomposeNextResource(DelegateExecution execution){
663 def method = getClass().getSimpleName() + '.postProcessDecomposeNextResource(' +'execution=' + execution.getId() +')'
664 msoLogger.info("Entered " + method)
665 msoLogger.trace("STARTED postProcessDecomposeNextResource Process ")
667 String resourceName = execution.getVariable(Prefix+"resourceName")
668 int resourceNum = execution.getVariable(Prefix+"nextServiceResource")
669 msoLogger.debug("Current Resource count:"+ execution.getVariable(Prefix+"nextServiceResource"))
671 int resourceCount = execution.getVariable(Prefix+"serviceResourceCount")
672 msoLogger.debug("Total Resource count:"+ execution.getVariable(Prefix+"serviceResourceCount"))
674 if (resourceNum < resourceCount) {
675 execution.setVariable(Prefix+"resourceFinish", false)
678 execution.setVariable(Prefix+"resourceFinish", true)
681 msoLogger.debug("Resource Finished:"+ execution.getVariable(Prefix+"resourceFinish"))
683 if (resourceCount >0 ){
684 int progress = (resourceNum*100) / resourceCount
686 execution.setVariable("progress", progress.toString() )
687 msoLogger.trace(":"+ execution.getVariable(""))
689 execution.setVariable("operationStatus", resourceName )
693 // try error in method block
694 String exceptionMessage = "Bpmn error encountered in CreateMobileAPNCustService flow. Unexpected Error from method postProcessDecomposeNextResource() - " + ex.getMessage()
695 msoLogger.debug(exceptionMessage)
696 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
698 msoLogger.info("Exited " + method)
701 * prepare post Unkown Resource Type
703 public void postOtherControllerType(DelegateExecution execution){
704 def method = getClass().getSimpleName() + '.postOtherControllerType(' +'execution=' + execution.getId() +')'
705 def isDebugEnabled = execution.getVariable("isDebugEnabled")
706 msoLogger.info("Entered " + method)
710 String resourceName = execution.getVariable(Prefix+"resourceName")
711 String resourceType = execution.getVariable(Prefix+"resourceType")
712 String controllerType = execution.getVariable("controllerType")
714 String msg = "Resource name: "+ resourceName + " resource Type: " + resourceType+ " controller Type: " + controllerType + " can not be processed n the workflow"
718 // try error in method block
719 String exceptionMessage = "Bpmn error encountered in DoCreateMobileAPNServiceInstance flow. Unexpected Error from method postOtherControllerType() - " + ex.getMessage()
720 msoLogger.debug(exceptionMessage)
721 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
723 msoLogger.info("Exited " + method)
727 * prepare delete parameters
729 public void preSDNCResourceDelete(execution, resourceName){
730 // we use resource instance ids for delete flow as resourceTemplateUUIDs
732 def method = getClass().getSimpleName() + '.preSDNCResourceDelete(' +'execution=' + execution.getId() +')'
733 msoLogger.info("Entered " + method)
735 msoLogger.trace("STARTED preSDNCResourceDelete Process ")
736 String networkResources = execution.getVariable("networkResources")
739 execution.setVariable("foundResource", false)
740 if (networkResources != null) {
741 def jsonSlurper = new JsonSlurper()
742 List relationShipList = jsonSlurper.parseText(networkResources)
743 relationShipList.each {
744 if(StringUtils.containsIgnoreCase(it.resourceType, resourceName)) {
745 String resourceInstanceUUID = it.resourceInstanceId
746 String resourceTemplateUUID = it.resourceInstanceId
747 execution.setVariable("resourceTemplateId", resourceTemplateUUID)
748 execution.setVariable("resourceInstanceId", resourceInstanceUUID)
749 execution.setVariable("resourceType", resourceName)
750 execution.setVariable("foundResource", true)
751 msoLogger.info("Delete Resource Info resourceTemplate Id :" + resourceTemplateUUID + " resourceInstanceId: " + resourceInstanceUUID + " resourceType: " + resourceName)
755 msoLogger.info("Exited " + method)
757 public void preProcessSDNCDelete (DelegateExecution execution) {
758 def method = getClass().getSimpleName() + '.preProcessSDNCDelete(' +'execution=' + execution.getId() +')'
759 msoLogger.info("Entered " + method)
760 msoLogger.trace("preProcessSDNCDelete ")
764 def serviceInstanceId = execution.getVariable("serviceInstanceId")
765 def serviceInstanceName = execution.getVariable("serviceInstanceName")
766 def callbackURL = execution.getVariable("sdncCallbackUrl")
767 def requestId = execution.getVariable("msoRequestId")
768 def serviceId = execution.getVariable("productFamilyId")
769 def subscriptionServiceType = execution.getVariable("subscriptionServiceType")
770 def globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId
772 String serviceModelInfo = execution.getVariable("serviceModelInfo")
773 def modelInvariantUuid = ""
774 def modelVersion = ""
777 if (!isBlank(serviceModelInfo))
779 modelInvariantUuid = jsonUtil.getJsonValue(serviceModelInfo, "modelInvariantUuid")
780 modelVersion = jsonUtil.getJsonValue(serviceModelInfo, "modelVersion")
781 modelUuid = jsonUtil.getJsonValue(serviceModelInfo, "modelUuid")
782 modelName = jsonUtil.getJsonValue(serviceModelInfo, "modelName")
784 if (modelInvariantUuid == null) {
785 modelInvariantUuid = ""
787 if (modelVersion == null) {
790 if (modelUuid == null) {
793 if (modelName == null) {
797 if (serviceInstanceName == null) {
798 serviceInstanceName = ""
800 if (serviceId == null) {
804 def siParamsXml = execution.getVariable("siParamsXml")
805 def serviceType = execution.getVariable("serviceType")
806 if (serviceType == null)
811 def sdncRequestId = UUID.randomUUID().toString()
814 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
815 xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
816 xmlns:sdncadapter="http://org.onap/workflow/sdnc/adapter/schema/v1">
817 <sdncadapter:RequestHeader>
818 <sdncadapter:RequestId>${MsoUtils.xmlEscape(sdncRequestId)}</sdncadapter:RequestId>
819 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(serviceInstanceId)}</sdncadapter:SvcInstanceId>
820 <sdncadapter:SvcAction>delete</sdncadapter:SvcAction>
821 <sdncadapter:SvcOperation>service-topology-operation</sdncadapter:SvcOperation>
822 <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackURL)}</sdncadapter:CallbackUrl>
823 <sdncadapter:MsoAction>${MsoUtils.xmlEscape(serviceType)}</sdncadapter:MsoAction>
824 </sdncadapter:RequestHeader>
825 <sdncadapterworkflow:SDNCRequestData>
826 <request-information>
827 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
832 <request-action>DeleteServiceInstance</request-action>
833 </request-information>
834 <service-information>
835 <service-id>${MsoUtils.xmlEscape(serviceId)}</service-id>
836 <subscription-service-type>${MsoUtils.xmlEscape(subscriptionServiceType)}</subscription-service-type>
837 <onap-model-information>
838 <model-invariant-uuid>${MsoUtils.xmlEscape(modelInvariantUuid)}</model-invariant-uuid>
839 <model-uuid>${MsoUtils.xmlEscape(modelUuid)}</model-uuid>
840 <model-version>${MsoUtils.xmlEscape(modelVersion)}</model-version>
841 <model-name>${MsoUtils.xmlEscape(modelName)}</model-name>
842 </onap-model-information>
843 <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceId)}</service-instance-id>
845 <global-customer-id>${MsoUtils.xmlEscape(globalSubscriberId)}</global-customer-id>
846 </service-information>
847 <service-request-input>
848 <service-instance-name>${MsoUtils.xmlEscape(serviceInstanceName)}</service-instance-name>
850 </service-request-input>
851 </sdncadapterworkflow:SDNCRequestData>
852 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
854 sdncDelete = utils.formatXml(sdncDelete)
855 def sdncRequestId2 = UUID.randomUUID().toString()
856 String sdncDeactivate = sdncDelete.replace(">delete<", ">deactivate<").replace(">${sdncRequestId}<", ">${sdncRequestId2}<")
857 execution.setVariable("sdncDelete", sdncDelete)
858 execution.setVariable("sdncDeactivate", sdncDeactivate)
859 msoLogger.info("sdncDeactivate:\n" + sdncDeactivate)
860 msoLogger.info("sdncDelete:\n" + sdncDelete)
862 } catch (BpmnError e) {
864 } catch(Exception ex) {
865 msg = "Exception in preProcessSDNCDelete. " + ex.getMessage()
867 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "Exception Occured in preProcessSDNCDelete.\n" + ex.getMessage())
869 msoLogger.info("Exited " + method)
872 public void postProcessSDNCDelete(DelegateExecution execution, String response, String action) {
874 def method = getClass().getSimpleName() + '.postProcessSDNCDelete(' +'execution=' + execution.getId() +')'
875 msoLogger.info("Entered " + method)
876 msoLogger.trace("postProcessSDNC " + action + " ")
880 WorkflowException workflowException = execution.getVariable("WorkflowException")
881 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
882 msoLogger.info("SDNCResponse: " + response)
883 msoLogger.info("workflowException: " + workflowException)
885 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
886 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
887 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == "true"){
888 msoLogger.info("Good response from SDNC Adapter for service-instance " + action + "response:\n" + response)
891 msg = "Bad Response from SDNC Adapter for service-instance " + action
893 exceptionUtil.buildAndThrowWorkflowException(execution, 3500, msg)
895 } catch (BpmnError e) {
897 } catch(Exception ex) {
898 msg = "Exception in postProcessSDNC " + action + " Exception:" + ex.getMessage()
900 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
902 msoLogger.info("Exited " + method)
906 * Init the service Operation Status
908 public void preUpdateServiceOperationStatus(DelegateExecution execution){
909 def method = getClass().getSimpleName() + '.preUpdateServiceOperationStatus(' +'execution=' + execution.getId() +')'
910 msoLogger.info("Entered " + method)
913 String serviceId = execution.getVariable("serviceInstanceId")
914 String operationId = execution.getVariable("operationId")
915 String serviceName = execution.getVariable("serviceInstanceName")
916 String operationType = "DELETE"
918 String result = "processing"
919 String progress = execution.getVariable("progress")
920 msoLogger.info("progress: " + progress )
921 if ("100".equalsIgnoreCase(progress))
926 String operationContent = "Prepare service delete: " + execution.getVariable("operationStatus")
927 msoLogger.info("Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId)
928 serviceId = UriUtils.encode(serviceId,"UTF-8")
929 execution.setVariable("serviceInstanceId", serviceId)
930 execution.setVariable("operationId", operationId)
931 execution.setVariable("operationType", operationType)
933 def dbAdapterEndpoint = execution.getVariable("URN_mso_adapters_openecomp_db_endpoint")
934 execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
935 msoLogger.info("DB Adapter Endpoint is: " + dbAdapterEndpoint)
937 execution.setVariable("URN_mso_openecomp_adapters_db_endpoint","http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter")
940 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
941 xmlns:ns="http://org.onap.so/requestsdb">
944 <ns:updateServiceOperationStatus xmlns:ns="http://org.onap.so/requestsdb">
945 <serviceId>${MsoUtils.xmlEscape(serviceId)}</serviceId>
946 <operationId>${MsoUtils.xmlEscape(operationId)}</operationId>
947 <serviceName>${MsoUtils.xmlEscape(serviceName)}</serviceName>
948 <operationType>${MsoUtils.xmlEscape(operationType)}</operationType>
949 <userId>${MsoUtils.xmlEscape(userId)}</userId>
950 <result>${MsoUtils.xmlEscape(result)}</result>
951 <operationContent>${MsoUtils.xmlEscape(operationContent)}</operationContent>
952 <progress>${MsoUtils.xmlEscape(progress)}</progress>
953 <reason>${MsoUtils.xmlEscape(reason)}</reason>
954 </ns:updateServiceOperationStatus>
956 </soapenv:Envelope>"""
958 payload = utils.formatXml(payload)
959 execution.setVariable("CVFMI_updateServiceOperStatusRequest", payload)
960 msoLogger.info("Outgoing preUpdateServiceOperationStatus: \n" + payload)
964 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occured Processing preUpdateServiceOperationStatus.", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e);
965 execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during preUpdateServiceOperationStatus Method:\n" + e.getMessage())
967 msoLogger.trace("COMPLETED preUpdateServiceOperationStatus Process ")
968 msoLogger.info("Exited " + method)
971 public void preInitResourcesOperStatus(DelegateExecution execution){
972 def method = getClass().getSimpleName() + '.preInitResourcesOperStatus(' +'execution=' + execution.getId() +')'
973 msoLogger.info("Entered " + method)
975 msoLogger.trace("STARTED preInitResourcesOperStatus Process ")
978 String serviceId = execution.getVariable("serviceInstanceId")
979 String operationId = execution.getVariable("operationId")
980 String operationType = "DELETE"
981 String resourceTemplateUUIDs = ""
982 String result = "processing"
983 String progress = "0"
985 String operationContent = "Prepare service delete"
986 msoLogger.info("Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId + " operationType:" + operationType)
987 serviceId = UriUtils.encode(serviceId,"UTF-8")
988 execution.setVariable("serviceInstanceId", serviceId)
989 execution.setVariable("operationId", operationId)
990 execution.setVariable("operationType", operationType)
992 String serviceRelationShip = execution.getVariable("serviceRelationShip")
993 msoLogger.info("serviceRelationShip: " + serviceRelationShip)
994 if (! isBlank(serviceRelationShip)) {
995 def jsonSlurper = new JsonSlurper()
996 def jsonOutput = new JsonOutput()
997 List relationShipList = jsonSlurper.parseText(serviceRelationShip)
999 if (relationShipList != null) {
1000 relationShipList.each {
1001 resourceTemplateUUIDs = resourceTemplateUUIDs + it.resourceInstanceId + ":"
1005 def dbAdapterEndpoint = "http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter"
1006 execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
1007 msoLogger.info("DB Adapter Endpoint is: " + dbAdapterEndpoint)
1010 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
1011 xmlns:ns="http://org.onap.so/requestsdb">
1014 <ns:initResourceOperationStatus xmlns:ns="http://org.onap.so/requestsdb">
1015 <serviceId>${MsoUtils.xmlEscape(serviceId)}</serviceId>
1016 <operationId>${MsoUtils.xmlEscape(operationId)}</operationId>
1017 <operationType>${MsoUtils.xmlEscape(operationType)}</operationType>
1018 <resourceTemplateUUIDs>${MsoUtils.xmlEscape(resourceTemplateUUIDs)}</resourceTemplateUUIDs>
1019 </ns:initResourceOperationStatus>
1021 </soapenv:Envelope>"""
1023 payload = utils.formatXml(payload)
1024 execution.setVariable("CVFMI_initResOperStatusRequest", payload)
1025 msoLogger.info("Outgoing initResourceOperationStatus: \n" + payload)
1026 msoLogger.debug("DoCustomDeleteE2EServiceInstanceV2 Outgoing initResourceOperationStatus Request: " + payload)
1028 }catch (BpmnError e) {
1030 } catch (Exception ex) {
1031 msg = "Exception in DoCustomDeleteE2EServiceInstanceV2.preInitResourcesOperStatus. " + ex.getMessage()
1033 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
1035 msoLogger.info("Exited " + method)
1041 * prepare delete parameters
1043 public void preProcessVFCResourceDelete(execution){
1044 // we use resource instance ids for delete flow as resourceTemplateUUIDs
1046 def method = getClass().getSimpleName() + '.preProcessVFCResourceDelete(' +'execution=' + execution.getId() +')'
1047 msoLogger.info("Entered " + method)
1049 msoLogger.trace("STARTED preProcessVFCResourceDelete Process ")
1051 String serviceResource = execution.getVariable("serviceResource")
1052 msoLogger.info("serviceResource : " + serviceResource)
1054 String resourceInstanceId = execution.getVariable("resourceInstanceId")
1055 msoLogger.info("resourceInstanceId : " + resourceInstanceId)
1057 execution.setVariable("resourceTemplateId", resourceInstanceId)
1058 msoLogger.info("resourceTemplateId : " + resourceInstanceId)
1060 String resourceType = execution.getVariable("resourceType")
1061 msoLogger.info("resourceType : " + resourceType)
1064 String resourceName = execution.getVariable(Prefix+"resourceName")
1065 if (isBlank(resourceName)){
1066 resourceName = resourceInstanceId
1068 execution.setVariable("resourceName", resourceName)
1069 msoLogger.info("resource Name : " + resourceName)
1071 msoLogger.info("Delete Resource Info: resourceInstanceId :" + resourceInstanceId + " resourceTemplateId: " + resourceInstanceId + " resourceType: " + resourceType)
1072 }catch (BpmnError e) {
1074 } catch (Exception ex) {
1075 msg = "Exception in DoDeleteE2EServiceInstance.preProcessVFCResourceDelete. " + ex.getMessage()
1077 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
1079 msoLogger.info("Exited " + method)
1082 public void postProcessVFCDelete(DelegateExecution execution, String response, String action) {
1083 def method = getClass().getSimpleName() + '.postProcessVFCDelete(' +'execution=' + execution.getId() +')'
1084 msoLogger.info("Entered " + method)
1086 msoLogger.trace("STARTED postProcessVFCDelete Process ")
1089 }catch (BpmnError e) {
1091 } catch (Exception ex) {
1092 msg = "Exception in DoDeleteE2EServiceInstance.postProcessVFCDelete. " + ex.getMessage()
1094 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
1096 msoLogger.info("Exited " + method)