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;
46 * This groovy class supports the <class>DoDeleteE2EServiceInstance.bpmn</class> process.
49 * @param - msoRequestId
50 * @param - globalSubscriberId - O
51 * @param - subscriptionServiceType - O
52 * @param - serviceInstanceId
53 * @param - serviceInstanceName - O
54 * @param - serviceInputParams (should contain aic_zone for serviceTypes TRANSPORT,ATM)
55 * @param - sdncVersion
56 * @param - failNotFound - TODO
57 * @param - serviceInputParams - TODO
60 * @param - WorkflowException
64 public class DoCustomDeleteE2EServiceInstanceV2 extends AbstractServiceTaskProcessor {
65 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoCustomDeleteE2EServiceInstanceV2.class);
68 String Prefix="DDELSI_"
69 private static final String DebugFlag = "isDebugEnabled"
70 ExceptionUtil exceptionUtil = new ExceptionUtil()
71 JsonUtils jsonUtil = new JsonUtils()
73 public void preProcessRequest (DelegateExecution execution) {
75 def method = getClass().getSimpleName() + '.buildAPPCRequest(' +'execution=' + execution.getId() +')'
76 msoLogger.info("Entered " + method)
77 msoLogger.trace("preProcessRequest ")
81 String requestId = execution.getVariable("msoRequestId")
82 execution.setVariable("prefix",Prefix)
85 //requestDetails.subscriberInfo. for AAI GET & PUT & SDNC assignToplology
86 String globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId
87 if (globalSubscriberId == null)
89 execution.setVariable("globalSubscriberId", "")
92 //requestDetails.requestParameters. for AAI PUT & SDNC assignTopology
93 String serviceType = execution.getVariable("serviceType")
94 if (serviceType == null)
96 execution.setVariable("serviceType", "")
99 //Generated in parent for AAI PUT
100 String serviceInstanceId = execution.getVariable("serviceInstanceId")
101 if (isBlank(serviceInstanceId)){
102 msg = "Input serviceInstanceId is null"
104 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
107 String sdncCallbackUrl = execution.getVariable('URN_mso_workflow_sdncadapter_callback')
108 if (isBlank(sdncCallbackUrl)) {
109 msg = "URN_mso_workflow_sdncadapter_callback is null"
111 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
113 execution.setVariable("sdncCallbackUrl", sdncCallbackUrl)
114 msoLogger.info("SDNC Callback URL: " + sdncCallbackUrl)
116 StringBuilder sbParams = new StringBuilder()
117 Map<String, String> paramsMap = execution.getVariable("serviceInputParams")
118 if (paramsMap != null)
120 sbParams.append("<service-input-parameters>")
121 for (Map.Entry<String, String> entry : paramsMap.entrySet()) {
123 String paramName = entry.getKey()
124 String paramValue = entry.getValue()
127 <name>${MsoUtils.xmlEscape(paramName)}</name>
128 <value>${MsoUtils.xmlEscape(paramValue)}</value>
131 sbParams.append(paramsXml)
133 sbParams.append("</service-input-parameters>")
135 String siParamsXml = sbParams.toString()
136 if (siParamsXml == null)
138 execution.setVariable("siParamsXml", siParamsXml)
139 execution.setVariable("operationStatus", "Waiting delete resource...")
140 execution.setVariable("progress", "0")
142 } catch (BpmnError e) {
144 } catch (Exception ex){
145 msg = "Exception in preProcessRequest " + ex.getMessage()
147 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
149 msoLogger.info("Exited " + method)
154 public void postProcessAAIGET(DelegateExecution execution) {
155 def method = getClass().getSimpleName() + '.postProcessAAIGET(' +'execution=' + execution.getId() +')'
156 msoLogger.info("Entered " + method)
161 String serviceInstanceId = execution.getVariable("serviceInstanceId")
162 msoLogger.info("serviceInstanceId: "+serviceInstanceId)
164 boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")
165 msoLogger.info("foundInAAI: "+foundInAAI)
167 String serviceType = ""
171 msoLogger.info("Found Service-instance in AAI")
173 String siData = execution.getVariable("GENGS_service")
174 msoLogger.info("SI Data")
177 msg = "Could not retrive ServiceInstance data from AAI to delete id:" + serviceInstanceId
179 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
183 boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")
185 msoLogger.info("Error getting Service-instance from AAI", + serviceInstanceId)
186 WorkflowException workflowException = execution.getVariable("WorkflowException")
187 msoLogger.debug("workflowException: " + workflowException)
188 if(workflowException != null){
189 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
193 msg = "Failure in postProcessAAIGET GENGS_SuccessIndicator:" + succInAAI
195 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
199 msoLogger.info("Service-instance NOT found in AAI. Silent Success")
201 }catch (BpmnError e) {
203 } catch (Exception ex) {
204 msg = "Bpmn error encountered in " + method + "--" + ex.getMessage()
206 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
208 msoLogger.info("Exited " + method)
211 private void loadResourcesProperties(DelegateExecution execution) {
212 def method = getClass().getSimpleName() + '.loadResourcesProperties(' +'execution=' + execution.getId() +')'
213 def isDebugEnabled = execution.getVariable("isDebugEnabled")
214 msoLogger.info("Entered " + method)
215 String loadFilePath = "/etc/mso/config.d/reources.json"
217 def jsonPayload = new File(loadFilePath).text
218 msoLogger.info("jsonPayload: " + jsonPayload)
220 String resourcesProperties = jsonUtil.prettyJson(jsonPayload.toString())
221 msoLogger.info("resourcesProperties: " + resourcesProperties)
223 String createResourceSort = jsonUtil.getJsonValue(resourcesProperties, "CreateResourceSort")
224 msoLogger.info("createResourceSort: " + createResourceSort)
225 execution.setVariable("createResourceSort", createResourceSort)
227 String deleteResourceSort = jsonUtil.getJsonValue(resourcesProperties, "DeleteResourceSort")
228 msoLogger.info("deleteResourceSort: " + deleteResourceSort)
229 execution.setVariable("deleteResourceSort", deleteResourceSort)
232 String resourceControllerType = jsonUtil.getJsonValue(resourcesProperties, "ResourceControllerType")
233 msoLogger.info("resourceControllerType: " + resourceControllerType)
234 execution.setVariable("resourceControllerType", resourceControllerType)
237 }catch(Exception ex){
238 // try error in method block
239 String exceptionMessage = "Bpmn error encountered in " + method + " - " + ex.getMessage()
240 msoLogger.debug(exceptionMessage)
241 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
243 msoLogger.info("Exited " + method)
245 private void sortDeleteResource(DelegateExecution execution) {
246 def method = getClass().getSimpleName() + '.sortDeleteResource(' +'execution=' + execution.getId() +')'
247 def isDebugEnabled = execution.getVariable("isDebugEnabled")
248 msoLogger.info("Entered " + method)
249 String deleteResourceSortDef = """[
251 "resourceType":"GRE_SAR"
254 "resourceType":"VPN_SAR"
257 "resourceType":"APN_AAR"
260 "resourceType":"GRE_AAR"
263 "resourceType":"Overlay"
266 "resourceType":"Underlay"
269 "resourceType":"vIMS"
272 "resourceType":"vCPE"
278 "resourceType":"vEPC"
285 loadResourcesProperties(execution)
286 String deleteResourceSort = execution.getVariable("deleteResourceSort")
287 if (isBlank(deleteResourceSort)) {
288 deleteResourceSort = deleteResourceSortDef;
291 List<String> sortResourceList = jsonUtil.StringArrayToList(execution, deleteResourceSort)
292 msoLogger.info("sortResourceList : " + sortResourceList)
294 JSONArray newResourceList = new JSONArray()
295 int resSortCount = sortResourceList.size()
297 for ( int currentResource = 0 ; currentResource < resSortCount ; currentResource++ ) {
298 String currentSortResource = sortResourceList[currentResource]
299 String sortResourceType = jsonUtil.getJsonValue(currentSortResource, "resourceType")
300 List<String> resourceList = execution.getVariable(Prefix+"resourceList")
302 for (String resource : resourceList) {
303 msoLogger.info("resource : " + resource)
304 String resourceType = jsonUtil.getJsonValue(resource, "resourceType")
306 if (StringUtils.containsIgnoreCase(resourceType, sortResourceType)) {
307 JSONObject jsonObj = new JSONObject(resource)
308 newResourceList.put(jsonObj)
310 msoLogger.info("Get next sort type " )
314 String newResourceStr = newResourceList.toString()
315 List<String> newResourceListStr = jsonUtil.StringArrayToList(execution, newResourceStr)
317 execution.setVariable(Prefix+"resourceList", newResourceListStr)
318 msoLogger.info("newResourceList : " + newResourceListStr)
320 }catch(Exception ex){
321 // try error in method block
322 String exceptionMessage = "Bpmn error encountered in " + method + " - " + ex.getMessage()
323 msoLogger.debug(exceptionMessage)
324 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
326 msoLogger.info("Exited " + method)
329 public void prepareServiceDeleteResource(DelegateExecution execution) {
330 def method = getClass().getSimpleName() + '.prepareServiceDeleteResource(' +'execution=' + execution.getId() +')'
331 msoLogger.info("Entered " + method)
335 String serviceInstanceId = execution.getVariable("serviceInstanceId")
337 // confirm if ServiceInstance was found
338 if ( !execution.getVariable("GENGS_FoundIndicator") )
340 String exceptionMessage = "Bpmn error encountered in DeleteMobileAPNCustService flow. Service Instance was not found in AAI by id: " + serviceInstanceId
341 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
344 execution.setVariable(Prefix+"resourceList", "")
345 execution.setVariable(Prefix+"resourceCount", 0)
346 execution.setVariable(Prefix+"nextResource", 0)
347 execution.setVariable(Prefix+"resourceFinish", true)
349 // get SI extracted by GenericGetService
350 String serviceInstanceAaiRecord = execution.getVariable("GENGS_service");
351 msoLogger.info("serviceInstanceAaiRecord: " +serviceInstanceAaiRecord)
353 String aaiJsonRecord = jsonUtil.xml2json(serviceInstanceAaiRecord)
355 msoLogger.info("aaiJsonRecord: " +aaiJsonRecord)
356 def serviceInstanceName = jsonUtil.getJsonValue(aaiJsonRecord, "service-instance.service-instance-name")
357 execution.setVariable("serviceInstanceName",serviceInstanceName)
359 def serviceType = jsonUtil.getJsonValue(aaiJsonRecord, "service-instance.service-type")
360 execution.setVariable("serviceType",serviceType)
363 String relationshipList = jsonUtil.getJsonValue(aaiJsonRecord, "service-instance.relationship-list")
364 msoLogger.info("relationship-list:" + relationshipList)
365 if (! isBlank(relationshipList)){
366 msoLogger.info("relationship-list exists" )
367 String relationShip = jsonUtil.getJsonValue(relationshipList, "relationship")
368 msoLogger.info("relationship: " + relationShip)
369 JSONArray allResources = new JSONArray()
370 JSONArray serviceResources = new JSONArray()
371 JSONArray networkResources = new JSONArray()
372 JSONArray allottedResources = new JSONArray()
375 if (! isBlank(relationShip)){
376 JSONArray jsonArray = new JSONArray();
377 if (relationShip.startsWith("{") && relationShip.endsWith("}")) {
378 JSONObject jsonObject = new JSONObject(relationShip);
379 jsonArray.put(jsonObject);
380 } else if (relationShip.startsWith("[") && relationShip.endsWith("]")) {
381 jsonArray = new JSONArray(relationShip);
383 msoLogger.info("The relationShip fomart is error" )
386 List<String> relationList = jsonUtil.StringArrayToList(execution, jsonArray.toString())
388 msoLogger.info("relationList: " + relationList)
390 int relationNum =relationList.size()
391 msoLogger.info("**************relationList size: " + relationNum)
393 for ( int currentRelation = 0 ; currentRelation < relationNum ; currentRelation++ ) {
394 msoLogger.info("current Relation num: " + currentRelation)
395 String relation = relationList[currentRelation]
396 msoLogger.info("relation: " + relation)
398 String relatedTo = jsonUtil.getJsonValue(relation, "related-to")
399 msoLogger.info("relatedTo: " + relatedTo)
401 String relatedLink = jsonUtil.getJsonValue(relation, "related-link")
402 msoLogger.info("relatedLink: " + relatedLink)
404 if (StringUtils.equalsIgnoreCase(relatedTo, "allotted-resource")) {
405 msoLogger.info("allotted-resource exists ")
407 String aaiArRsp = getAaiAr(execution, relatedLink)
408 msoLogger.info("aaiArRsp: " + aaiArRsp)
409 if (! isBlank(aaiArRsp)) {
410 def type = utils.getNodeText(aaiArRsp, "type")
411 def id = utils.getNodeText(aaiArRsp, "id")
412 def role = utils.getNodeText(aaiArRsp, "role")
413 def resourceVersion = utils.getNodeText(aaiArRsp, "resource-version")
415 JSONObject jObject = new JSONObject()
416 jObject.put("resourceType", type)
417 jObject.put("resourceInstanceId", id)
418 jObject.put("resourceRole", role)
419 jObject.put("resourceVersion", resourceVersion)
421 allResources.put(jObject)
422 msoLogger.info("allResources: " + allResources)
423 allottedResources.put(jObject)
424 msoLogger.info("allottedResources: " + allottedResources)
427 else if (StringUtils.equalsIgnoreCase(relatedTo, "service-instance")){
428 msoLogger.info("service-instance exists ")
429 JSONObject jObject = new JSONObject()
432 String rsDataStr = jsonUtil.getJsonValue(relation, "relationship-data")
433 msoLogger.info("rsDataStr: " + rsDataStr)
434 List<String> rsDataList = jsonUtil.StringArrayToList(execution, rsDataStr)
435 msoLogger.info("rsDataList: " + rsDataList)
436 for(String rsData : rsDataList){
437 msoLogger.info("rsData: " + rsData)
438 def eKey = jsonUtil.getJsonValue(rsData, "relationship-key")
439 def eValue = jsonUtil.getJsonValue(rsData, "relationship-value")
440 if(eKey.equals("service-instance.service-instance-id")){
441 jObject.put("resourceInstanceId", eValue)
443 if(eKey.equals("service-subscription.service-type")){
444 jObject.put("resourceType", eValue)
448 //related-to-property
449 String rPropertyStr = jsonUtil.getJsonValue(relation, "related-to-property")
450 msoLogger.info("related-to-property: " + rPropertyStr)
451 if (rPropertyStr instanceof JSONArray){
452 List<String> rPropertyList = jsonUtil.StringArrayToList(execution, rPropertyStr)
453 for (String rProperty : rPropertyList) {
454 msoLogger.info("rProperty: " + rProperty)
455 def eKey = jsonUtil.getJsonValue(rProperty, "property-key")
456 def eValue = jsonUtil.getJsonValue(rProperty, "property-value")
457 if(eKey.equals("service-instance.service-instance-name")){
458 jObject.put("resourceName", eValue)
463 String rProperty = rPropertyStr
464 msoLogger.info("rProperty: " + rProperty)
465 def eKey = jsonUtil.getJsonValue(rProperty, "property-key")
466 def eValue = jsonUtil.getJsonValue(rProperty, "property-value")
467 if (eKey.equals("service-instance.service-instance-name")) {
468 jObject.put("resourceName", eValue)
472 allResources.put(jObject)
473 msoLogger.info("allResources: " + allResources)
475 serviceResources.put(jObject)
476 msoLogger.info("serviceResources: " + serviceResources)
478 else if (StringUtils.equalsIgnoreCase(relatedTo, "configuration")) {
479 msoLogger.info("configuration ")
480 JSONObject jObject = new JSONObject()
483 String rsDataStr = jsonUtil.getJsonValue(relation, "relationship-data")
484 msoLogger.info("rsDataStr: " + rsDataStr)
485 List<String> rsDataList = jsonUtil.StringArrayToList(execution, rsDataStr)
486 msoLogger.info("rsDataList: " + rsDataList)
487 for (String rsData : rsDataList) {
488 msoLogger.info("rsData: " + rsData)
489 def eKey = jsonUtil.getJsonValue(rsData, "relationship-key")
490 def eValue = jsonUtil.getJsonValue(rsData, "relationship-value")
491 if(eKey.equals("configuration.configuration-id")){
492 jObject.put("resourceInstanceId", eValue)
497 //related-to-property
498 String rPropertyStr = jsonUtil.getJsonValue(relation, "related-to-property")
499 msoLogger.info("related-to-property: " + rPropertyStr)
500 if (rPropertyStr instanceof JSONArray){
501 List<String> rPropertyList = jsonUtil.StringArrayToList(execution, rPropertyStr)
502 for(String rProperty : rPropertyList){
503 msoLogger.info("rProperty: " + rProperty)
504 def eKey = jsonUtil.getJsonValue(rProperty, "property-key")
505 def eValue = jsonUtil.getJsonValue(rProperty, "property-value")
506 if(eKey.equals("configuration.configuration-type")){
507 jObject.put("resourceType", eValue)
512 String rProperty = rPropertyStr
513 msoLogger.info("rProperty: " + rProperty)
514 def eKey = jsonUtil.getJsonValue(rProperty, "property-key")
515 def eValue = jsonUtil.getJsonValue(rProperty, "property-value")
516 if(eKey.equals("configuration.configuration-type")){
517 jObject.put("resourceType", eValue)
520 allResources.put(jObject)
521 msoLogger.info("allResources: " + allResources)
523 networkResources.put(jObject)
524 msoLogger.info("networkResources: " + networkResources)
526 msoLogger.info("Get Next releation resource " )
529 msoLogger.info("Get releation finished. " )
532 execution.setVariable("serviceRelationShip", allResources.toString())
533 msoLogger.info("allResources: " + allResources.toString())
534 String serviceRelationShip = execution.getVariable("serviceRelationShip")
535 msoLogger.info("serviceRelationShip: " + serviceRelationShip)
536 if ((! isBlank(serviceRelationShip)) && (! serviceRelationShip.isEmpty())) {
538 List<String> relationShipList = jsonUtil.StringArrayToList(execution, serviceRelationShip)
539 msoLogger.info("relationShipList: " + relationShipList)
540 execution.setVariable(Prefix+"resourceList", relationShipList)
542 int resourceCount = relationShipList.size()
543 msoLogger.info("resourceCount: " + resourceCount)
544 execution.setVariable(Prefix+"resourceCount",resourceCount )
547 execution.setVariable(Prefix+"nextResource", resourceNum)
548 msoLogger.info("start sort delete resource: ")
549 sortDeleteResource(execution)
552 if (resourceNum < resourceCount) {
553 execution.setVariable(Prefix+"resourceFinish", false)
556 execution.setVariable(Prefix+"resourceFinish", true)
558 msoLogger.info("Resource list set end : " + resourceCount)
561 execution.setVariable("serviceResources", serviceResources.toString())
562 msoLogger.info("serviceResources: " + serviceResources)
563 String serviceResourcesShip = execution.getVariable("serviceResources")
564 msoLogger.info("serviceResourcesShip: " + serviceResourcesShip)
566 if ((! isBlank(serviceResourcesShip)) && (! serviceResourcesShip.isEmpty())) {
567 List<String> serviceResourcesList = jsonUtil.StringArrayToList(execution, serviceResourcesShip)
568 msoLogger.info("serviceResourcesList: " + serviceResourcesList)
569 execution.setVariable(Prefix+"serviceResourceList", serviceResourcesList)
570 execution.setVariable(Prefix+"serviceResourceCount", serviceResourcesList.size())
571 execution.setVariable(Prefix+"nextServiceResource", 0)
572 msoLogger.info("Service Resource list set end : " + serviceResourcesList.size())
576 execution.setVariable("allottedResources", allottedResources.toString())
577 msoLogger.info("allottedResources: " + allottedResources)
578 String allottedResourcesShip = execution.getVariable("allottedResources")
579 msoLogger.info("allottedResourcesShip: " + allottedResourcesShip)
580 if ((! isBlank(allottedResourcesShip)) && (! allottedResourcesShip.isEmpty())) {
581 List<String> allottedResourcesList = jsonUtil.StringArrayToList(execution, allottedResourcesShip)
582 msoLogger.info("allottedResourcesList: " + allottedResourcesList)
583 execution.setVariable(Prefix+"allottedResourcesList", allottedResourcesList)
584 execution.setVariable(Prefix+"allottedResourcesListCount", allottedResourcesList.size())
585 execution.setVariable(Prefix+"nextAllottedResourcesList", 0)
586 msoLogger.info("Allotted Resource list set end : " + allottedResourcesList.size())
589 execution.setVariable("networkResources", networkResources.toString())
590 msoLogger.info("networkResources: " + networkResources)
591 String networkResourcesShip = execution.getVariable("networkResources")
592 msoLogger.info("networkResourcesShip: " + networkResourcesShip)
593 if ((! isBlank(networkResourcesShip)) && (! networkResourcesShip.isEmpty())) {
594 List<String> networkResourcesList = jsonUtil.StringArrayToList(execution, networkResourcesShip)
595 msoLogger.info("networkResourcesList: " + networkResourcesList)
596 execution.setVariable(Prefix+"networkResourcesList", networkResourcesList)
597 execution.setVariable(Prefix+"networkResourcesListCount", networkResourcesList.size())
598 execution.setVariable(Prefix+"nextNetworkResourcesList", 0)
599 msoLogger.info("Network Resource list set end : " + networkResourcesList.size())
603 } catch (BpmnError e){
605 } catch (Exception ex) {
606 String exceptionMessage = "Bpmn error encountered in DeleteMobileAPNCustService flow. prepareServiceDeleteResource() - " + ex.getMessage()
607 msoLogger.debug(exceptionMessage)
608 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
610 msoLogger.info("Exited " + method)
613 private String getAaiAr(DelegateExecution execution, String relink) {
614 def method = getClass().getSimpleName() + '.getAaiAr(' +'execution=' + execution.getId() +')'
615 msoLogger.info("Entered " + method)
616 AaiUtil aaiUtil = new AaiUtil(this)
617 String aaiEndpoint = execution.getVariable("URN_aai_endpoint") + relink
619 msoLogger.debug("get AR info " + aaiEndpoint)
620 APIResponse response = aaiUtil.executeAAIGetCall(execution, aaiEndpoint)
622 int responseCode = response.getStatusCode()
623 msoLogger.debug("get AR info responseCode:" + responseCode)
625 String aaiResponse = response.getResponseBodyAsString()
626 msoLogger.debug("get AR info " + aaiResponse)
628 if(responseCode < 200 || responseCode >= 300 || isBlank(aaiResponse)) {
632 msoLogger.info("Exited " + method)
636 * prepare Decompose next resource to create request
638 public void preProcessDecomposeNextResource(DelegateExecution execution){
639 def method = getClass().getSimpleName() + '.getAaiAr(' +'execution=' + execution.getId() +')'
640 msoLogger.info("Entered " + method)
641 msoLogger.trace("STARTED preProcessDecomposeNextResource Process ")
643 int resourceNum = execution.getVariable(Prefix+"nextServiceResource")
644 List<String> serviceResourceList = execution.getVariable(Prefix+"serviceResourceList")
645 msoLogger.info("Service Resource List : " + serviceResourceList)
647 String serviceResource = serviceResourceList[resourceNum]
648 execution.setVariable(Prefix+"serviceResource", serviceResource)
649 msoLogger.info("Current Service Resource : " + serviceResource)
651 String resourceType = jsonUtil.getJsonValue(serviceResource, "resourceType")
652 execution.setVariable("resourceType", resourceType)
653 msoLogger.info("resourceType : " + resourceType)
655 String resourceInstanceId = jsonUtil.getJsonValue(serviceResource, "resourceInstanceId")
656 execution.setVariable("resourceInstanceId", resourceInstanceId)
657 msoLogger.info("resourceInstanceId : " + resourceInstanceId)
659 String resourceRole = jsonUtil.getJsonValue(serviceResource, "resourceRole")
660 execution.setVariable("resourceRole", resourceRole)
661 msoLogger.info("resourceRole : " + resourceRole)
663 String resourceVersion = jsonUtil.getJsonValue(serviceResource, "resourceVersion")
664 execution.setVariable("resourceVersion", resourceVersion)
665 msoLogger.info("resourceVersion : " + resourceVersion)
667 String resourceName = jsonUtil.getJsonValue(serviceResource, "resourceName")
668 if (isBlank(resourceName)){
669 resourceName = resourceInstanceId
671 execution.setVariable(Prefix+"resourceName", resourceName)
672 msoLogger.info("resource Name : " + resourceName)
675 execution.setVariable(Prefix+"nextServiceResource", resourceNum + 1)
677 int serviceResourceCount = execution.getVariable(Prefix+"serviceResourceCount")
678 if (serviceResourceCount >0 ){
679 int progress = (resourceNum*100) / serviceResourceCount
680 execution.setVariable("progress", progress.toString() )
682 execution.setVariable("operationStatus", resourceName )
685 // try error in method block
686 String exceptionMessage = "Bpmn error encountered in CreateMobileAPNCustService flow. Unexpected Error from method preProcessDecomposeNextResource() - " + ex.getMessage()
687 msoLogger.debug(exceptionMessage)
688 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
690 msoLogger.info("Exited " + method)
693 * post Decompose next resource to create request
695 public void postProcessDecomposeNextResource(DelegateExecution execution){
696 def method = getClass().getSimpleName() + '.postProcessDecomposeNextResource(' +'execution=' + execution.getId() +')'
697 msoLogger.info("Entered " + method)
698 msoLogger.trace("STARTED postProcessDecomposeNextResource Process ")
700 String resourceName = execution.getVariable(Prefix+"resourceName")
701 int resourceNum = execution.getVariable(Prefix+"nextServiceResource")
702 msoLogger.debug("Current Resource count:"+ execution.getVariable(Prefix+"nextServiceResource"))
704 int resourceCount = execution.getVariable(Prefix+"serviceResourceCount")
705 msoLogger.debug("Total Resource count:"+ execution.getVariable(Prefix+"serviceResourceCount"))
707 if (resourceNum < resourceCount) {
708 execution.setVariable(Prefix+"resourceFinish", false)
711 execution.setVariable(Prefix+"resourceFinish", true)
714 msoLogger.debug("Resource Finished:"+ execution.getVariable(Prefix+"resourceFinish"))
716 if (resourceCount >0 ){
717 int progress = (resourceNum*100) / resourceCount
719 execution.setVariable("progress", progress.toString() )
720 msoLogger.trace(":"+ execution.getVariable(""))
722 execution.setVariable("operationStatus", resourceName )
726 // try error in method block
727 String exceptionMessage = "Bpmn error encountered in CreateMobileAPNCustService flow. Unexpected Error from method postProcessDecomposeNextResource() - " + ex.getMessage()
728 msoLogger.debug(exceptionMessage)
729 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
731 msoLogger.info("Exited " + method)
734 * prepare post Unkown Resource Type
736 public void postOtherControllerType(DelegateExecution execution){
737 def method = getClass().getSimpleName() + '.postOtherControllerType(' +'execution=' + execution.getId() +')'
738 def isDebugEnabled = execution.getVariable("isDebugEnabled")
739 msoLogger.info("Entered " + method)
743 String resourceName = execution.getVariable(Prefix+"resourceName")
744 String resourceType = execution.getVariable(Prefix+"resourceType")
745 String controllerType = execution.getVariable("controllerType")
747 String msg = "Resource name: "+ resourceName + " resource Type: " + resourceType+ " controller Type: " + controllerType + " can not be processed n the workflow"
751 // try error in method block
752 String exceptionMessage = "Bpmn error encountered in DoCreateMobileAPNServiceInstance flow. Unexpected Error from method postOtherControllerType() - " + ex.getMessage()
753 msoLogger.debug(exceptionMessage)
754 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
756 msoLogger.info("Exited " + method)
760 * prepare delete parameters
762 public void preSDNCResourceDelete(execution, resourceName){
763 // we use resource instance ids for delete flow as resourceTemplateUUIDs
765 def method = getClass().getSimpleName() + '.preSDNCResourceDelete(' +'execution=' + execution.getId() +')'
766 msoLogger.info("Entered " + method)
768 msoLogger.trace("STARTED preSDNCResourceDelete Process ")
769 String networkResources = execution.getVariable("networkResources")
772 execution.setVariable("foundResource", false)
773 if (networkResources != null) {
774 def jsonSlurper = new JsonSlurper()
775 List relationShipList = jsonSlurper.parseText(networkResources)
776 relationShipList.each {
777 if(StringUtils.containsIgnoreCase(it.resourceType, resourceName)) {
778 String resourceInstanceUUID = it.resourceInstanceId
779 String resourceTemplateUUID = it.resourceInstanceId
780 execution.setVariable("resourceTemplateId", resourceTemplateUUID)
781 execution.setVariable("resourceInstanceId", resourceInstanceUUID)
782 execution.setVariable("resourceType", resourceName)
783 execution.setVariable("foundResource", true)
784 msoLogger.info("Delete Resource Info resourceTemplate Id :" + resourceTemplateUUID + " resourceInstanceId: " + resourceInstanceUUID + " resourceType: " + resourceName)
788 msoLogger.info("Exited " + method)
790 public void preProcessSDNCDelete (DelegateExecution execution) {
791 def method = getClass().getSimpleName() + '.preProcessSDNCDelete(' +'execution=' + execution.getId() +')'
792 msoLogger.info("Entered " + method)
793 msoLogger.trace("preProcessSDNCDelete ")
797 def serviceInstanceId = execution.getVariable("serviceInstanceId")
798 def serviceInstanceName = execution.getVariable("serviceInstanceName")
799 def callbackURL = execution.getVariable("sdncCallbackUrl")
800 def requestId = execution.getVariable("msoRequestId")
801 def serviceId = execution.getVariable("productFamilyId")
802 def subscriptionServiceType = execution.getVariable("subscriptionServiceType")
803 def globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId
805 String serviceModelInfo = execution.getVariable("serviceModelInfo")
806 def modelInvariantUuid = ""
807 def modelVersion = ""
810 if (!isBlank(serviceModelInfo))
812 modelInvariantUuid = jsonUtil.getJsonValue(serviceModelInfo, "modelInvariantUuid")
813 modelVersion = jsonUtil.getJsonValue(serviceModelInfo, "modelVersion")
814 modelUuid = jsonUtil.getJsonValue(serviceModelInfo, "modelUuid")
815 modelName = jsonUtil.getJsonValue(serviceModelInfo, "modelName")
817 if (modelInvariantUuid == null) {
818 modelInvariantUuid = ""
820 if (modelVersion == null) {
823 if (modelUuid == null) {
826 if (modelName == null) {
830 if (serviceInstanceName == null) {
831 serviceInstanceName = ""
833 if (serviceId == null) {
837 def siParamsXml = execution.getVariable("siParamsXml")
838 def serviceType = execution.getVariable("serviceType")
839 if (serviceType == null)
844 def sdncRequestId = UUID.randomUUID().toString()
847 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
848 xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
849 xmlns:sdncadapter="http://org.onap/workflow/sdnc/adapter/schema/v1">
850 <sdncadapter:RequestHeader>
851 <sdncadapter:RequestId>${MsoUtils.xmlEscape(sdncRequestId)}</sdncadapter:RequestId>
852 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(serviceInstanceId)}</sdncadapter:SvcInstanceId>
853 <sdncadapter:SvcAction>delete</sdncadapter:SvcAction>
854 <sdncadapter:SvcOperation>service-topology-operation</sdncadapter:SvcOperation>
855 <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackURL)}</sdncadapter:CallbackUrl>
856 <sdncadapter:MsoAction>${MsoUtils.xmlEscape(serviceType)}</sdncadapter:MsoAction>
857 </sdncadapter:RequestHeader>
858 <sdncadapterworkflow:SDNCRequestData>
859 <request-information>
860 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
865 <request-action>DeleteServiceInstance</request-action>
866 </request-information>
867 <service-information>
868 <service-id>${MsoUtils.xmlEscape(serviceId)}</service-id>
869 <subscription-service-type>${MsoUtils.xmlEscape(subscriptionServiceType)}</subscription-service-type>
870 <onap-model-information>
871 <model-invariant-uuid>${MsoUtils.xmlEscape(modelInvariantUuid)}</model-invariant-uuid>
872 <model-uuid>${MsoUtils.xmlEscape(modelUuid)}</model-uuid>
873 <model-version>${MsoUtils.xmlEscape(modelVersion)}</model-version>
874 <model-name>${MsoUtils.xmlEscape(modelName)}</model-name>
875 </onap-model-information>
876 <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceId)}</service-instance-id>
878 <global-customer-id>${MsoUtils.xmlEscape(globalSubscriberId)}</global-customer-id>
879 </service-information>
880 <service-request-input>
881 <service-instance-name>${MsoUtils.xmlEscape(serviceInstanceName)}</service-instance-name>
883 </service-request-input>
884 </sdncadapterworkflow:SDNCRequestData>
885 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
887 sdncDelete = utils.formatXml(sdncDelete)
888 def sdncRequestId2 = UUID.randomUUID().toString()
889 String sdncDeactivate = sdncDelete.replace(">delete<", ">deactivate<").replace(">${sdncRequestId}<", ">${sdncRequestId2}<")
890 execution.setVariable("sdncDelete", sdncDelete)
891 execution.setVariable("sdncDeactivate", sdncDeactivate)
892 msoLogger.info("sdncDeactivate:\n" + sdncDeactivate)
893 msoLogger.info("sdncDelete:\n" + sdncDelete)
895 } catch (BpmnError e) {
897 } catch(Exception ex) {
898 msg = "Exception in preProcessSDNCDelete. " + ex.getMessage()
900 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "Exception Occured in preProcessSDNCDelete.\n" + ex.getMessage())
902 msoLogger.info("Exited " + method)
905 public void postProcessSDNCDelete(DelegateExecution execution, String response, String action) {
907 def method = getClass().getSimpleName() + '.postProcessSDNCDelete(' +'execution=' + execution.getId() +')'
908 msoLogger.info("Entered " + method)
909 msoLogger.trace("postProcessSDNC " + action + " ")
913 WorkflowException workflowException = execution.getVariable("WorkflowException")
914 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
915 msoLogger.info("SDNCResponse: " + response)
916 msoLogger.info("workflowException: " + workflowException)
918 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
919 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
920 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == "true"){
921 msoLogger.info("Good response from SDNC Adapter for service-instance " + action + "response:\n" + response)
924 msg = "Bad Response from SDNC Adapter for service-instance " + action
926 exceptionUtil.buildAndThrowWorkflowException(execution, 3500, msg)
928 } catch (BpmnError e) {
930 } catch(Exception ex) {
931 msg = "Exception in postProcessSDNC " + action + " Exception:" + ex.getMessage()
933 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
935 msoLogger.info("Exited " + method)
939 * Init the service Operation Status
941 public void preUpdateServiceOperationStatus(DelegateExecution execution){
942 def method = getClass().getSimpleName() + '.preUpdateServiceOperationStatus(' +'execution=' + execution.getId() +')'
943 msoLogger.info("Entered " + method)
946 String serviceId = execution.getVariable("serviceInstanceId")
947 String operationId = execution.getVariable("operationId")
948 String serviceName = execution.getVariable("serviceInstanceName")
949 String operationType = "DELETE"
951 String result = "processing"
952 String progress = execution.getVariable("progress")
953 msoLogger.info("progress: " + progress )
954 if ("100".equalsIgnoreCase(progress))
959 String operationContent = "Prepare service delete: " + execution.getVariable("operationStatus")
960 msoLogger.info("Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId)
961 serviceId = UriUtils.encode(serviceId,"UTF-8")
962 execution.setVariable("serviceInstanceId", serviceId)
963 execution.setVariable("operationId", operationId)
964 execution.setVariable("operationType", operationType)
966 def dbAdapterEndpoint = execution.getVariable("URN_mso_adapters_openecomp_db_endpoint")
967 execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
968 msoLogger.info("DB Adapter Endpoint is: " + dbAdapterEndpoint)
970 execution.setVariable("URN_mso_openecomp_adapters_db_endpoint","http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter")
973 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
974 xmlns:ns="http://org.onap.so/requestsdb">
977 <ns:updateServiceOperationStatus xmlns:ns="http://org.onap.so/requestsdb">
978 <serviceId>${MsoUtils.xmlEscape(serviceId)}</serviceId>
979 <operationId>${MsoUtils.xmlEscape(operationId)}</operationId>
980 <serviceName>${MsoUtils.xmlEscape(serviceName)}</serviceName>
981 <operationType>${MsoUtils.xmlEscape(operationType)}</operationType>
982 <userId>${MsoUtils.xmlEscape(userId)}</userId>
983 <result>${MsoUtils.xmlEscape(result)}</result>
984 <operationContent>${MsoUtils.xmlEscape(operationContent)}</operationContent>
985 <progress>${MsoUtils.xmlEscape(progress)}</progress>
986 <reason>${MsoUtils.xmlEscape(reason)}</reason>
987 </ns:updateServiceOperationStatus>
989 </soapenv:Envelope>"""
991 payload = utils.formatXml(payload)
992 execution.setVariable("CVFMI_updateServiceOperStatusRequest", payload)
993 msoLogger.info("Outgoing preUpdateServiceOperationStatus: \n" + payload)
997 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occured Processing preUpdateServiceOperationStatus.", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e);
998 execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during preUpdateServiceOperationStatus Method:\n" + e.getMessage())
1000 msoLogger.trace("COMPLETED preUpdateServiceOperationStatus Process ")
1001 msoLogger.info("Exited " + method)
1004 public void preInitResourcesOperStatus(DelegateExecution execution){
1005 def method = getClass().getSimpleName() + '.preInitResourcesOperStatus(' +'execution=' + execution.getId() +')'
1006 msoLogger.info("Entered " + method)
1008 msoLogger.trace("STARTED preInitResourcesOperStatus Process ")
1011 String serviceId = execution.getVariable("serviceInstanceId")
1012 String operationId = execution.getVariable("operationId")
1013 String operationType = "DELETE"
1014 String resourceTemplateUUIDs = ""
1015 String result = "processing"
1016 String progress = "0"
1018 String operationContent = "Prepare service delete"
1019 msoLogger.info("Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId + " operationType:" + operationType)
1020 serviceId = UriUtils.encode(serviceId,"UTF-8")
1021 execution.setVariable("serviceInstanceId", serviceId)
1022 execution.setVariable("operationId", operationId)
1023 execution.setVariable("operationType", operationType)
1025 String serviceRelationShip = execution.getVariable("serviceRelationShip")
1026 msoLogger.info("serviceRelationShip: " + serviceRelationShip)
1027 if (! isBlank(serviceRelationShip)) {
1028 def jsonSlurper = new JsonSlurper()
1029 def jsonOutput = new JsonOutput()
1030 List relationShipList = jsonSlurper.parseText(serviceRelationShip)
1032 if (relationShipList != null) {
1033 relationShipList.each {
1034 resourceTemplateUUIDs = resourceTemplateUUIDs + it.resourceInstanceId + ":"
1038 def dbAdapterEndpoint = "http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter"
1039 execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
1040 msoLogger.info("DB Adapter Endpoint is: " + dbAdapterEndpoint)
1043 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
1044 xmlns:ns="http://org.onap.so/requestsdb">
1047 <ns:initResourceOperationStatus xmlns:ns="http://org.onap.so/requestsdb">
1048 <serviceId>${MsoUtils.xmlEscape(serviceId)}</serviceId>
1049 <operationId>${MsoUtils.xmlEscape(operationId)}</operationId>
1050 <operationType>${MsoUtils.xmlEscape(operationType)}</operationType>
1051 <resourceTemplateUUIDs>${MsoUtils.xmlEscape(resourceTemplateUUIDs)}</resourceTemplateUUIDs>
1052 </ns:initResourceOperationStatus>
1054 </soapenv:Envelope>"""
1056 payload = utils.formatXml(payload)
1057 execution.setVariable("CVFMI_initResOperStatusRequest", payload)
1058 msoLogger.info("Outgoing initResourceOperationStatus: \n" + payload)
1059 msoLogger.debug("DoCustomDeleteE2EServiceInstanceV2 Outgoing initResourceOperationStatus Request: " + payload)
1061 }catch (BpmnError e) {
1063 } catch (Exception ex) {
1064 msg = "Exception in DoCustomDeleteE2EServiceInstanceV2.preInitResourcesOperStatus. " + ex.getMessage()
1066 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
1068 msoLogger.info("Exited " + method)
1074 * prepare delete parameters
1076 public void preProcessVFCResourceDelete(execution){
1077 // we use resource instance ids for delete flow as resourceTemplateUUIDs
1079 def method = getClass().getSimpleName() + '.preProcessVFCResourceDelete(' +'execution=' + execution.getId() +')'
1080 msoLogger.info("Entered " + method)
1082 msoLogger.trace("STARTED preProcessVFCResourceDelete Process ")
1084 String serviceResource = execution.getVariable("serviceResource")
1085 msoLogger.info("serviceResource : " + serviceResource)
1087 String resourceInstanceId = execution.getVariable("resourceInstanceId")
1088 msoLogger.info("resourceInstanceId : " + resourceInstanceId)
1090 execution.setVariable("resourceTemplateId", resourceInstanceId)
1091 msoLogger.info("resourceTemplateId : " + resourceInstanceId)
1093 String resourceType = execution.getVariable("resourceType")
1094 msoLogger.info("resourceType : " + resourceType)
1097 String resourceName = execution.getVariable(Prefix+"resourceName")
1098 if (isBlank(resourceName)){
1099 resourceName = resourceInstanceId
1101 execution.setVariable("resourceName", resourceName)
1102 msoLogger.info("resource Name : " + resourceName)
1104 msoLogger.info("Delete Resource Info: resourceInstanceId :" + resourceInstanceId + " resourceTemplateId: " + resourceInstanceId + " resourceType: " + resourceType)
1105 }catch (BpmnError e) {
1107 } catch (Exception ex) {
1108 msg = "Exception in DoDeleteE2EServiceInstance.preProcessVFCResourceDelete. " + ex.getMessage()
1110 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
1112 msoLogger.info("Exited " + method)
1115 public void postProcessVFCDelete(DelegateExecution execution, String response, String action) {
1116 def method = getClass().getSimpleName() + '.postProcessVFCDelete(' +'execution=' + execution.getId() +')'
1117 msoLogger.info("Entered " + method)
1119 msoLogger.trace("STARTED postProcessVFCDelete Process ")
1122 }catch (BpmnError e) {
1124 } catch (Exception ex) {
1125 msg = "Exception in DoDeleteE2EServiceInstance.postProcessVFCDelete. " + ex.getMessage()
1127 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
1129 msoLogger.info("Exited " + method)