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 * Modifications Copyright (c) 2019 Samsung
9 * ================================================================================
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 * ============LICENSE_END=========================================================
23 package org.onap.so.bpmn.infrastructure.scripts
25 import static org.apache.commons.lang3.StringUtils.*;
26 import javax.ws.rs.NotFoundException
27 import javax.ws.rs.core.UriBuilder
28 import org.apache.commons.lang3.*
29 import org.camunda.bpm.engine.delegate.BpmnError
30 import org.camunda.bpm.engine.delegate.DelegateExecution
31 import org.json.JSONArray
32 import org.json.JSONObject
33 import org.onap.aai.domain.yang.AllottedResource
34 import org.onap.aaiclient.client.aai.AAIResourcesClient
35 import org.onap.aaiclient.client.aai.entities.AAIResultWrapper
36 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
37 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
38 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
39 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types
40 import org.onap.logging.filter.base.ErrorCode
41 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
42 import org.onap.so.bpmn.common.scripts.ExceptionUtil
43 import org.onap.so.bpmn.common.scripts.MsoUtils
44 import org.onap.so.bpmn.core.UrnPropertiesReader
45 import org.onap.so.bpmn.core.json.JsonUtils
46 import org.onap.so.logger.LoggingAnchor
47 import org.onap.so.logger.MessageEnum
48 import org.slf4j.Logger
49 import org.slf4j.LoggerFactory
50 import org.springframework.web.util.UriUtils;
56 * This groovy class supports the <class>DoDeleteE2EServiceInstance.bpmn</class> process.
59 * @param - msoRequestId
60 * @param - globalSubscriberId - O
61 * @param - subscriptionServiceType - O
62 * @param - serviceInstanceId
63 * @param - serviceInstanceName - O
64 * @param - serviceInputParams (should contain aic_zone for serviceTypes TRANSPORT,ATM)
65 * @param - sdncVersion
66 * @param - failNotFound - TODO
67 * @param - serviceInputParams - TODO
70 * @param - WorkflowException
74 public class DoCustomDeleteE2EServiceInstanceV2 extends AbstractServiceTaskProcessor {
75 private static final Logger logger = LoggerFactory.getLogger( DoCustomDeleteE2EServiceInstanceV2.class);
78 String Prefix="DDELSI_"
79 private static final String DebugFlag = "isDebugEnabled"
80 ExceptionUtil exceptionUtil = new ExceptionUtil()
81 JsonUtils jsonUtil = new JsonUtils()
83 public void preProcessRequest (DelegateExecution execution) {
85 def method = getClass().getSimpleName() + '.buildAPPCRequest(' +'execution=' + execution.getId() +')'
86 logger.info("Entered " + method)
87 logger.trace("preProcessRequest ")
91 String requestId = execution.getVariable("msoRequestId")
92 execution.setVariable("prefix",Prefix)
95 //requestDetails.subscriberInfo. for AAI GET & PUT & SDNC assignToplology
96 String globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId
97 if (globalSubscriberId == null)
99 execution.setVariable("globalSubscriberId", "")
102 //requestDetails.requestParameters. for AAI PUT & SDNC assignTopology
103 String serviceType = execution.getVariable("serviceType")
104 if (serviceType == null)
106 execution.setVariable("serviceType", "")
109 //Generated in parent for AAI PUT
110 String serviceInstanceId = execution.getVariable("serviceInstanceId")
111 if (isBlank(serviceInstanceId)){
112 msg = "Input serviceInstanceId is null"
114 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
117 String sdncCallbackUrl = execution.getVariable('URN_mso_workflow_sdncadapter_callback')
118 if (isBlank(sdncCallbackUrl)) {
119 msg = "URN_mso_workflow_sdncadapter_callback is null"
121 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
123 execution.setVariable("sdncCallbackUrl", sdncCallbackUrl)
124 logger.info("SDNC Callback URL: " + sdncCallbackUrl)
126 StringBuilder sbParams = new StringBuilder()
127 Map<String, String> paramsMap = execution.getVariable("serviceInputParams")
128 if (paramsMap != null)
130 sbParams.append("<service-input-parameters>")
131 for (Map.Entry<String, String> entry : paramsMap.entrySet()) {
133 String paramName = entry.getKey()
134 String paramValue = entry.getValue()
137 <name>${MsoUtils.xmlEscape(paramName)}</name>
138 <value>${MsoUtils.xmlEscape(paramValue)}</value>
141 sbParams.append(paramsXml)
143 sbParams.append("</service-input-parameters>")
145 String siParamsXml = sbParams.toString()
146 if (siParamsXml == null)
148 execution.setVariable("siParamsXml", siParamsXml)
149 execution.setVariable("operationStatus", "Waiting delete resource...")
150 execution.setVariable("progress", "0")
152 } catch (BpmnError e) {
154 } catch (Exception ex){
155 msg = "Exception in preProcessRequest " + ex.getMessage()
157 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
159 logger.info("Exited " + method)
163 * Gets the service instance and its relationships from aai
167 public void getServiceInstance(DelegateExecution execution) {
169 String serviceInstanceId = execution.getVariable('serviceInstanceId')
170 String globalSubscriberId = execution.getVariable('globalSubscriberId')
171 String serviceType = execution.getVariable('serviceType')
173 AAIResourcesClient resourceClient = new AAIResourcesClient()
174 AAIResourceUri serviceInstanceUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(serviceType).serviceInstance(serviceInstanceId))
175 AAIResultWrapper wrapper = resourceClient.get(serviceInstanceUri, NotFoundException.class)
176 String json = wrapper.getJson()
178 execution.setVariable("serviceInstance", json)
180 }catch(BpmnError e) {
182 }catch(NotFoundException e) {
183 logger.info("SI not found in aai. Silent Success ")
184 }catch(Exception ex) {
185 String msg = "Internal Error in getServiceInstance: " + ex.getMessage()
186 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
190 private void loadResourcesProperties(DelegateExecution execution) {
191 def method = getClass().getSimpleName() + '.loadResourcesProperties(' +'execution=' + execution.getId() +')'
192 def isDebugEnabled = execution.getVariable("isDebugEnabled")
193 logger.info("Entered " + method)
194 String loadFilePath = "/etc/mso/config.d/reources.json"
196 def jsonPayload = new File(loadFilePath).text
197 logger.info("jsonPayload: " + jsonPayload)
199 String resourcesProperties = jsonUtil.prettyJson(jsonPayload.toString())
200 logger.info("resourcesProperties: " + resourcesProperties)
202 String createResourceSort = jsonUtil.getJsonValue(resourcesProperties, "CreateResourceSort")
203 logger.info("createResourceSort: " + createResourceSort)
204 execution.setVariable("createResourceSort", createResourceSort)
206 String deleteResourceSort = jsonUtil.getJsonValue(resourcesProperties, "DeleteResourceSort")
207 logger.info("deleteResourceSort: " + deleteResourceSort)
208 execution.setVariable("deleteResourceSort", deleteResourceSort)
211 String resourceControllerType = jsonUtil.getJsonValue(resourcesProperties, "ResourceControllerType")
212 logger.info("resourceControllerType: " + resourceControllerType)
213 execution.setVariable("resourceControllerType", resourceControllerType)
216 }catch(Exception ex){
217 // try error in method block
218 String exceptionMessage = "Bpmn error encountered in " + method + " - " + ex.getMessage()
219 logger.debug(exceptionMessage)
220 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
222 logger.info("Exited " + method)
224 private void sortDeleteResource(DelegateExecution execution) {
225 def method = getClass().getSimpleName() + '.sortDeleteResource(' +'execution=' + execution.getId() +')'
226 def isDebugEnabled = execution.getVariable("isDebugEnabled")
227 logger.info("Entered " + method)
228 String deleteResourceSortDef = """[
230 "resourceType":"GRE_SAR"
233 "resourceType":"VPN_SAR"
236 "resourceType":"APN_AAR"
239 "resourceType":"GRE_AAR"
242 "resourceType":"Overlay"
245 "resourceType":"Underlay"
248 "resourceType":"vIMS"
251 "resourceType":"vCPE"
257 "resourceType":"vEPC"
264 loadResourcesProperties(execution)
265 String deleteResourceSort = execution.getVariable("deleteResourceSort")
266 if (isBlank(deleteResourceSort)) {
267 deleteResourceSort = deleteResourceSortDef;
270 List<String> sortResourceList = jsonUtil.StringArrayToList(execution, deleteResourceSort)
271 logger.info("sortResourceList : " + sortResourceList)
273 JSONArray newResourceList = new JSONArray()
274 int resSortCount = sortResourceList.size()
276 for ( int currentResource = 0 ; currentResource < resSortCount ; currentResource++ ) {
277 String currentSortResource = sortResourceList[currentResource]
278 String sortResourceType = jsonUtil.getJsonValue(currentSortResource, "resourceType")
279 List<String> resourceList = execution.getVariable(Prefix+"resourceList")
281 for (String resource : resourceList) {
282 logger.info("resource : " + resource)
283 String resourceType = jsonUtil.getJsonValue(resource, "resourceType")
285 if (StringUtils.containsIgnoreCase(resourceType, sortResourceType)) {
286 JSONObject jsonObj = new JSONObject(resource)
287 newResourceList.put(jsonObj)
289 logger.info("Get next sort type " )
293 String newResourceStr = newResourceList.toString()
294 List<String> newResourceListStr = jsonUtil.StringArrayToList(execution, newResourceStr)
296 execution.setVariable(Prefix+"resourceList", newResourceListStr)
297 logger.info("newResourceList : " + newResourceListStr)
299 }catch(Exception ex){
300 // try error in method block
301 String exceptionMessage = "Bpmn error encountered in " + method + " - " + ex.getMessage()
302 logger.debug(exceptionMessage)
303 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
305 logger.info("Exited " + method)
308 public void prepareServiceDeleteResource(DelegateExecution execution) {
309 def method = getClass().getSimpleName() + '.prepareServiceDeleteResource(' +'execution=' + execution.getId() +')'
310 logger.info("Entered " + method)
314 String serviceInstanceId = execution.getVariable("serviceInstanceId")
317 execution.setVariable(Prefix+"resourceList", "")
318 execution.setVariable(Prefix+"resourceCount", 0)
319 execution.setVariable(Prefix+"nextResource", 0)
320 execution.setVariable(Prefix+"resourceFinish", true)
322 String aaiJsonRecord = execution.getVariable("serviceInstance");
323 logger.info("serviceInstanceAaiRecord: " +aaiJsonRecord)
325 logger.info("aaiJsonRecord: " +aaiJsonRecord)
326 def serviceInstanceName = jsonUtil.getJsonValue(aaiJsonRecord, "service-instance.service-instance-name")
327 execution.setVariable("serviceInstanceName",serviceInstanceName)
329 def serviceType = jsonUtil.getJsonValue(aaiJsonRecord, "service-instance.service-type")
330 execution.setVariable("serviceType",serviceType)
333 String relationshipList = jsonUtil.getJsonValue(aaiJsonRecord, "service-instance.relationship-list")
334 logger.info("relationship-list:" + relationshipList)
335 if (! isBlank(relationshipList)){
336 logger.info("relationship-list exists" )
337 String relationShip = jsonUtil.getJsonValue(relationshipList, "relationship")
338 logger.info("relationship: " + relationShip)
339 JSONArray allResources = new JSONArray()
340 JSONArray serviceResources = new JSONArray()
341 JSONArray networkResources = new JSONArray()
342 JSONArray allottedResources = new JSONArray()
345 if (! isBlank(relationShip)){
346 JSONArray jsonArray = new JSONArray();
347 if (relationShip.startsWith("{") && relationShip.endsWith("}")) {
348 JSONObject jsonObject = new JSONObject(relationShip);
349 jsonArray.put(jsonObject);
350 } else if (relationShip.startsWith("[") && relationShip.endsWith("]")) {
351 jsonArray = new JSONArray(relationShip);
353 logger.info("The relationShip fomart is error" )
356 List<String> relationList = jsonUtil.StringArrayToList(execution, jsonArray.toString())
358 logger.info("relationList: " + relationList)
360 int relationNum =relationList.size()
361 logger.info("**************relationList size: " + relationNum)
363 for ( int currentRelation = 0 ; currentRelation < relationNum ; currentRelation++ ) {
364 logger.info("current Relation num: " + currentRelation)
365 String relation = relationList[currentRelation]
366 logger.info("relation: " + relation)
368 String relatedTo = jsonUtil.getJsonValue(relation, "related-to")
369 logger.info("relatedTo: " + relatedTo)
371 String relatedLink = jsonUtil.getJsonValue(relation, "related-link")
372 logger.info("relatedLink: " + relatedLink)
374 if (StringUtils.equalsIgnoreCase(relatedTo, "allotted-resource")) {
375 logger.info("allotted-resource exists ")
377 Optional<AllottedResource> aaiArRsp = getAaiAr(execution, relatedLink)
378 logger.info("aaiArRsp: " + aaiArRsp)
379 if (aaiArRsp.isPresent()) {
381 JSONObject jObject = new JSONObject()
382 jObject.put("resourceType", aaiArRsp.get().getType())
383 jObject.put("resourceInstanceId", aaiArRsp.get().getId())
384 jObject.put("resourceRole", aaiArRsp.get().getRole())
385 jObject.put("resourceVersion", aaiArRsp.get().getResourceVersion())
387 allResources.put(jObject)
388 logger.info("allResources: " + allResources)
389 allottedResources.put(jObject)
390 logger.info("allottedResources: " + allottedResources)
393 else if (StringUtils.equalsIgnoreCase(relatedTo, "service-instance")){
394 logger.info("service-instance exists ")
395 JSONObject jObject = new JSONObject()
398 String rsDataStr = jsonUtil.getJsonValue(relation, "relationship-data")
399 logger.info("rsDataStr: " + rsDataStr)
400 List<String> rsDataList = jsonUtil.StringArrayToList(execution, rsDataStr)
401 logger.info("rsDataList: " + rsDataList)
402 for(String rsData : rsDataList){
403 logger.info("rsData: " + rsData)
404 def eKey = jsonUtil.getJsonValue(rsData, "relationship-key")
405 def eValue = jsonUtil.getJsonValue(rsData, "relationship-value")
406 if(eKey.equals("service-instance.service-instance-id")){
407 jObject.put("resourceInstanceId", eValue)
409 if(eKey.equals("service-subscription.service-type")){
410 jObject.put("resourceType", eValue)
414 //related-to-property
415 String rPropertyStr = jsonUtil.getJsonValue(relation, "related-to-property")
416 logger.info("related-to-property: " + rPropertyStr)
417 if (rPropertyStr instanceof JSONArray){
418 List<String> rPropertyList = jsonUtil.StringArrayToList(execution, rPropertyStr)
419 for (String rProperty : rPropertyList) {
420 logger.info("rProperty: " + rProperty)
421 def eKey = jsonUtil.getJsonValue(rProperty, "property-key")
422 def eValue = jsonUtil.getJsonValue(rProperty, "property-value")
423 if(eKey.equals("service-instance.service-instance-name")){
424 jObject.put("resourceName", eValue)
429 String rProperty = rPropertyStr
430 logger.info("rProperty: " + rProperty)
431 def eKey = jsonUtil.getJsonValue(rProperty, "property-key")
432 def eValue = jsonUtil.getJsonValue(rProperty, "property-value")
433 if (eKey.equals("service-instance.service-instance-name")) {
434 jObject.put("resourceName", eValue)
438 allResources.put(jObject)
439 logger.info("allResources: " + allResources)
441 serviceResources.put(jObject)
442 logger.info("serviceResources: " + serviceResources)
444 else if (StringUtils.equalsIgnoreCase(relatedTo, "configuration")) {
445 logger.info("configuration ")
446 JSONObject jObject = new JSONObject()
449 String rsDataStr = jsonUtil.getJsonValue(relation, "relationship-data")
450 logger.info("rsDataStr: " + rsDataStr)
451 List<String> rsDataList = jsonUtil.StringArrayToList(execution, rsDataStr)
452 logger.info("rsDataList: " + rsDataList)
453 for (String rsData : rsDataList) {
454 logger.info("rsData: " + rsData)
455 def eKey = jsonUtil.getJsonValue(rsData, "relationship-key")
456 def eValue = jsonUtil.getJsonValue(rsData, "relationship-value")
457 if(eKey.equals("configuration.configuration-id")){
458 jObject.put("resourceInstanceId", eValue)
463 //related-to-property
464 String rPropertyStr = jsonUtil.getJsonValue(relation, "related-to-property")
465 logger.info("related-to-property: " + rPropertyStr)
466 if (rPropertyStr instanceof JSONArray){
467 List<String> rPropertyList = jsonUtil.StringArrayToList(execution, rPropertyStr)
468 for(String rProperty : rPropertyList){
469 logger.info("rProperty: " + rProperty)
470 def eKey = jsonUtil.getJsonValue(rProperty, "property-key")
471 def eValue = jsonUtil.getJsonValue(rProperty, "property-value")
472 if(eKey.equals("configuration.configuration-type")){
473 jObject.put("resourceType", eValue)
478 String rProperty = rPropertyStr
479 logger.info("rProperty: " + rProperty)
480 def eKey = jsonUtil.getJsonValue(rProperty, "property-key")
481 def eValue = jsonUtil.getJsonValue(rProperty, "property-value")
482 if(eKey.equals("configuration.configuration-type")){
483 jObject.put("resourceType", eValue)
486 allResources.put(jObject)
487 logger.info("allResources: " + allResources)
489 networkResources.put(jObject)
490 logger.info("networkResources: " + networkResources)
492 logger.info("Get Next releation resource " )
495 logger.info("Get releation finished. " )
498 execution.setVariable("serviceRelationShip", allResources.toString())
499 logger.info("allResources: " + allResources.toString())
500 String serviceRelationShip = execution.getVariable("serviceRelationShip")
501 logger.info("serviceRelationShip: " + serviceRelationShip)
502 if ((! isBlank(serviceRelationShip)) && (! serviceRelationShip.isEmpty())) {
504 List<String> relationShipList = jsonUtil.StringArrayToList(execution, serviceRelationShip)
505 logger.info("relationShipList: " + relationShipList)
506 execution.setVariable(Prefix+"resourceList", relationShipList)
508 int resourceCount = relationShipList.size()
509 logger.info("resourceCount: " + resourceCount)
510 execution.setVariable(Prefix+"resourceCount",resourceCount )
513 execution.setVariable(Prefix+"nextResource", resourceNum)
514 logger.info("start sort delete resource: ")
515 sortDeleteResource(execution)
518 if (resourceNum < resourceCount) {
519 execution.setVariable(Prefix+"resourceFinish", false)
522 execution.setVariable(Prefix+"resourceFinish", true)
524 logger.info("Resource list set end : " + resourceCount)
527 execution.setVariable("serviceResources", serviceResources.toString())
528 logger.info("serviceResources: " + serviceResources)
529 String serviceResourcesShip = execution.getVariable("serviceResources")
530 logger.info("serviceResourcesShip: " + serviceResourcesShip)
532 if ((! isBlank(serviceResourcesShip)) && (! serviceResourcesShip.isEmpty())) {
533 List<String> serviceResourcesList = jsonUtil.StringArrayToList(execution, serviceResourcesShip)
534 logger.info("serviceResourcesList: " + serviceResourcesList)
535 execution.setVariable(Prefix+"serviceResourceList", serviceResourcesList)
536 execution.setVariable(Prefix+"serviceResourceCount", serviceResourcesList.size())
537 execution.setVariable(Prefix+"nextServiceResource", 0)
538 logger.info("Service Resource list set end : " + serviceResourcesList.size())
542 execution.setVariable("allottedResources", allottedResources.toString())
543 logger.info("allottedResources: " + allottedResources)
544 String allottedResourcesShip = execution.getVariable("allottedResources")
545 logger.info("allottedResourcesShip: " + allottedResourcesShip)
546 if ((! isBlank(allottedResourcesShip)) && (! allottedResourcesShip.isEmpty())) {
547 List<String> allottedResourcesList = jsonUtil.StringArrayToList(execution, allottedResourcesShip)
548 logger.info("allottedResourcesList: " + allottedResourcesList)
549 execution.setVariable(Prefix+"allottedResourcesList", allottedResourcesList)
550 execution.setVariable(Prefix+"allottedResourcesListCount", allottedResourcesList.size())
551 execution.setVariable(Prefix+"nextAllottedResourcesList", 0)
552 logger.info("Allotted Resource list set end : " + allottedResourcesList.size())
555 execution.setVariable("networkResources", networkResources.toString())
556 logger.info("networkResources: " + networkResources)
557 String networkResourcesShip = execution.getVariable("networkResources")
558 logger.info("networkResourcesShip: " + networkResourcesShip)
559 if ((! isBlank(networkResourcesShip)) && (! networkResourcesShip.isEmpty())) {
560 List<String> networkResourcesList = jsonUtil.StringArrayToList(execution, networkResourcesShip)
561 logger.info("networkResourcesList: " + networkResourcesList)
562 execution.setVariable(Prefix+"networkResourcesList", networkResourcesList)
563 execution.setVariable(Prefix+"networkResourcesListCount", networkResourcesList.size())
564 execution.setVariable(Prefix+"nextNetworkResourcesList", 0)
565 logger.info("Network Resource list set end : " + networkResourcesList.size())
569 } catch (BpmnError e){
571 } catch (Exception ex) {
572 String exceptionMessage = "Bpmn error encountered in DeleteMobileAPNCustService flow. prepareServiceDeleteResource() - " + ex.getMessage()
573 logger.debug(exceptionMessage)
574 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
576 logger.info("Exited " + method)
579 private Optional<AllottedResource> getAaiAr(DelegateExecution execution, String relink) {
580 def method = getClass().getSimpleName() + '.getAaiAr(' +'execution=' + execution.getId() +')'
581 logger.info("Entered " + method)
582 AAIResourceUri uri = AAIUriFactory.createResourceFromExistingURI(Types.ALLOTTED_RESOURCE, UriBuilder.fromPath(relink).build())
583 return getAAIClient().get(AllottedResource.class,uri)
586 * prepare Decompose next resource to create request
588 public void preProcessDecomposeNextResource(DelegateExecution execution){
589 def method = getClass().getSimpleName() + '.getAaiAr(' +'execution=' + execution.getId() +')'
590 logger.info("Entered " + method)
591 logger.trace("STARTED preProcessDecomposeNextResource Process ")
593 int resourceNum = execution.getVariable(Prefix+"nextServiceResource")
594 List<String> serviceResourceList = execution.getVariable(Prefix+"serviceResourceList")
595 logger.info("Service Resource List : " + serviceResourceList)
597 String serviceResource = serviceResourceList[resourceNum]
598 execution.setVariable(Prefix+"serviceResource", serviceResource)
599 logger.info("Current Service Resource : " + serviceResource)
601 String resourceType = jsonUtil.getJsonValue(serviceResource, "resourceType")
602 execution.setVariable("resourceType", resourceType)
603 logger.info("resourceType : " + resourceType)
605 String resourceInstanceId = jsonUtil.getJsonValue(serviceResource, "resourceInstanceId")
606 execution.setVariable("resourceInstanceId", resourceInstanceId)
607 logger.info("resourceInstanceId : " + resourceInstanceId)
609 String resourceRole = jsonUtil.getJsonValue(serviceResource, "resourceRole")
610 execution.setVariable("resourceRole", resourceRole)
611 logger.info("resourceRole : " + resourceRole)
613 String resourceVersion = jsonUtil.getJsonValue(serviceResource, "resourceVersion")
614 execution.setVariable("resourceVersion", resourceVersion)
615 logger.info("resourceVersion : " + resourceVersion)
617 String resourceName = jsonUtil.getJsonValue(serviceResource, "resourceName")
618 if (isBlank(resourceName)){
619 resourceName = resourceInstanceId
621 execution.setVariable(Prefix+"resourceName", resourceName)
622 logger.info("resource Name : " + resourceName)
625 execution.setVariable(Prefix+"nextServiceResource", resourceNum + 1)
627 int serviceResourceCount = execution.getVariable(Prefix+"serviceResourceCount")
628 if (serviceResourceCount >0 ){
629 int progress = (resourceNum*100) / serviceResourceCount
630 execution.setVariable("progress", progress.toString() )
632 execution.setVariable("operationStatus", resourceName )
635 // try error in method block
636 String exceptionMessage = "Bpmn error encountered in CreateMobileAPNCustService flow. Unexpected Error from method preProcessDecomposeNextResource() - " + ex.getMessage()
637 logger.debug(exceptionMessage)
638 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
640 logger.info("Exited " + method)
643 * post Decompose next resource to create request
645 public void postProcessDecomposeNextResource(DelegateExecution execution){
646 def method = getClass().getSimpleName() + '.postProcessDecomposeNextResource(' +'execution=' + execution.getId() +')'
647 logger.info("Entered " + method)
648 logger.trace("STARTED postProcessDecomposeNextResource Process ")
650 String resourceName = execution.getVariable(Prefix+"resourceName")
651 int resourceNum = execution.getVariable(Prefix+"nextServiceResource")
652 logger.debug("Current Resource count:"+ execution.getVariable(Prefix+"nextServiceResource"))
654 int resourceCount = execution.getVariable(Prefix+"serviceResourceCount")
655 logger.debug("Total Resource count:"+ execution.getVariable(Prefix+"serviceResourceCount"))
657 if (resourceNum < resourceCount) {
658 execution.setVariable(Prefix+"resourceFinish", false)
661 execution.setVariable(Prefix+"resourceFinish", true)
664 logger.debug("Resource Finished:"+ execution.getVariable(Prefix+"resourceFinish"))
666 if (resourceCount >0 ){
667 int progress = (resourceNum*100) / resourceCount
669 execution.setVariable("progress", progress.toString() )
670 logger.trace(":"+ execution.getVariable(""))
672 execution.setVariable("operationStatus", resourceName )
676 // try error in method block
677 String exceptionMessage = "Bpmn error encountered in CreateMobileAPNCustService flow. Unexpected Error from method postProcessDecomposeNextResource() - " + ex.getMessage()
678 logger.debug(exceptionMessage)
679 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
681 logger.info("Exited " + method)
684 * prepare post Unkown Resource Type
686 public void postOtherControllerType(DelegateExecution execution){
687 def method = getClass().getSimpleName() + '.postOtherControllerType(' +'execution=' + execution.getId() +')'
688 def isDebugEnabled = execution.getVariable("isDebugEnabled")
689 logger.info("Entered " + method)
693 String resourceName = execution.getVariable(Prefix+"resourceName")
694 String resourceType = execution.getVariable(Prefix+"resourceType")
695 String controllerType = execution.getVariable("controllerType")
697 String msg = "Resource name: "+ resourceName + " resource Type: " + resourceType+ " controller Type: " + controllerType + " can not be processed n the workflow"
701 // try error in method block
702 String exceptionMessage = "Bpmn error encountered in DoCreateMobileAPNServiceInstance flow. Unexpected Error from method postOtherControllerType() - " + ex.getMessage()
703 logger.debug(exceptionMessage)
704 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
706 logger.info("Exited " + method)
710 * prepare delete parameters
712 public void preSDNCResourceDelete(execution, resourceName){
713 // we use resource instance ids for delete flow as resourceTemplateUUIDs
715 def method = getClass().getSimpleName() + '.preSDNCResourceDelete(' +'execution=' + execution.getId() +')'
716 logger.info("Entered " + method)
718 logger.trace("STARTED preSDNCResourceDelete Process ")
719 String networkResources = execution.getVariable("networkResources")
722 execution.setVariable("foundResource", false)
723 if (networkResources != null) {
724 def jsonSlurper = new JsonSlurper()
725 List relationShipList = jsonSlurper.parseText(networkResources)
726 relationShipList.each {
727 if(StringUtils.containsIgnoreCase(it.resourceType, resourceName)) {
728 String resourceInstanceUUID = it.resourceInstanceId
729 String resourceTemplateUUID = it.resourceInstanceId
730 execution.setVariable("resourceTemplateId", resourceTemplateUUID)
731 execution.setVariable("resourceInstanceId", resourceInstanceUUID)
732 execution.setVariable("resourceType", resourceName)
733 execution.setVariable("foundResource", true)
734 logger.info("Delete Resource Info resourceTemplate Id :" + resourceTemplateUUID + " resourceInstanceId: " + resourceInstanceUUID + " resourceType: " + resourceName)
738 logger.info("Exited " + method)
740 public void preProcessSDNCDelete (DelegateExecution execution) {
741 def method = getClass().getSimpleName() + '.preProcessSDNCDelete(' +'execution=' + execution.getId() +')'
742 logger.info("Entered " + method)
743 logger.trace("preProcessSDNCDelete ")
747 def serviceInstanceId = execution.getVariable("serviceInstanceId")
748 def serviceInstanceName = execution.getVariable("serviceInstanceName")
749 def callbackURL = execution.getVariable("sdncCallbackUrl")
750 def requestId = execution.getVariable("msoRequestId")
751 def serviceId = execution.getVariable("productFamilyId")
752 def subscriptionServiceType = execution.getVariable("subscriptionServiceType")
753 def globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId
755 String serviceModelInfo = execution.getVariable("serviceModelInfo")
756 def modelInvariantUuid = ""
757 def modelVersion = ""
760 if (!isBlank(serviceModelInfo))
762 modelInvariantUuid = jsonUtil.getJsonValue(serviceModelInfo, "modelInvariantUuid")
763 modelVersion = jsonUtil.getJsonValue(serviceModelInfo, "modelVersion")
764 modelUuid = jsonUtil.getJsonValue(serviceModelInfo, "modelUuid")
765 modelName = jsonUtil.getJsonValue(serviceModelInfo, "modelName")
767 if (modelInvariantUuid == null) {
768 modelInvariantUuid = ""
770 if (modelVersion == null) {
773 if (modelUuid == null) {
776 if (modelName == null) {
780 if (serviceInstanceName == null) {
781 serviceInstanceName = ""
783 if (serviceId == null) {
787 def siParamsXml = execution.getVariable("siParamsXml")
788 def serviceType = execution.getVariable("serviceType")
789 if (serviceType == null)
794 def sdncRequestId = UUID.randomUUID().toString()
797 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
798 xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
799 xmlns:sdncadapter="http://org.onap/workflow/sdnc/adapter/schema/v1">
800 <sdncadapter:RequestHeader>
801 <sdncadapter:RequestId>${MsoUtils.xmlEscape(sdncRequestId)}</sdncadapter:RequestId>
802 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(serviceInstanceId)}</sdncadapter:SvcInstanceId>
803 <sdncadapter:SvcAction>delete</sdncadapter:SvcAction>
804 <sdncadapter:SvcOperation>service-topology-operation</sdncadapter:SvcOperation>
805 <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackURL)}</sdncadapter:CallbackUrl>
806 <sdncadapter:MsoAction>${MsoUtils.xmlEscape(serviceType)}</sdncadapter:MsoAction>
807 </sdncadapter:RequestHeader>
808 <sdncadapterworkflow:SDNCRequestData>
809 <request-information>
810 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
815 <request-action>DeleteServiceInstance</request-action>
816 </request-information>
817 <service-information>
818 <service-id>${MsoUtils.xmlEscape(serviceId)}</service-id>
819 <subscription-service-type>${MsoUtils.xmlEscape(subscriptionServiceType)}</subscription-service-type>
820 <onap-model-information>
821 <model-invariant-uuid>${MsoUtils.xmlEscape(modelInvariantUuid)}</model-invariant-uuid>
822 <model-uuid>${MsoUtils.xmlEscape(modelUuid)}</model-uuid>
823 <model-version>${MsoUtils.xmlEscape(modelVersion)}</model-version>
824 <model-name>${MsoUtils.xmlEscape(modelName)}</model-name>
825 </onap-model-information>
826 <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceId)}</service-instance-id>
828 <global-customer-id>${MsoUtils.xmlEscape(globalSubscriberId)}</global-customer-id>
829 </service-information>
830 <service-request-input>
831 <service-instance-name>${MsoUtils.xmlEscape(serviceInstanceName)}</service-instance-name>
833 </service-request-input>
834 </sdncadapterworkflow:SDNCRequestData>
835 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
837 sdncDelete = utils.formatXml(sdncDelete)
838 def sdncRequestId2 = UUID.randomUUID().toString()
839 String sdncDeactivate = sdncDelete.replace(">delete<", ">deactivate<").replace(">${sdncRequestId}<", ">${sdncRequestId2}<")
840 execution.setVariable("sdncDelete", sdncDelete)
841 execution.setVariable("sdncDeactivate", sdncDeactivate)
842 logger.info("sdncDeactivate:\n" + sdncDeactivate)
843 logger.info("sdncDelete:\n" + sdncDelete)
845 } catch (BpmnError e) {
847 } catch(Exception ex) {
848 msg = "Exception in preProcessSDNCDelete. " + ex.getMessage()
850 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "Exception Occured in preProcessSDNCDelete.\n" + ex.getMessage())
852 logger.info("Exited " + method)
855 public void postProcessSDNCDelete(DelegateExecution execution, String response, String action) {
857 def method = getClass().getSimpleName() + '.postProcessSDNCDelete(' +'execution=' + execution.getId() +')'
858 logger.info("Entered " + method)
859 logger.trace("postProcessSDNC " + action + " ")
863 WorkflowException workflowException = execution.getVariable("WorkflowException")
864 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
865 logger.info("SDNCResponse: " + response)
866 logger.info("workflowException: " + workflowException)
868 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
869 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
870 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == "true"){
871 logger.info("Good response from SDNC Adapter for service-instance " + action + "response:\n" + response)
874 msg = "Bad Response from SDNC Adapter for service-instance " + action
876 exceptionUtil.buildAndThrowWorkflowException(execution, 3500, msg)
878 } catch (BpmnError e) {
880 } catch(Exception ex) {
881 msg = "Exception in postProcessSDNC " + action + " Exception:" + ex.getMessage()
883 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
885 logger.info("Exited " + method)
889 * Init the service Operation Status
891 public void preUpdateServiceOperationStatus(DelegateExecution execution){
892 def method = getClass().getSimpleName() + '.preUpdateServiceOperationStatus(' +'execution=' + execution.getId() +')'
893 logger.info("Entered " + method)
896 String serviceId = execution.getVariable("serviceInstanceId")
897 String operationId = execution.getVariable("operationId")
898 String serviceName = execution.getVariable("serviceInstanceName")
899 String operationType = "DELETE"
901 String result = "processing"
902 String progress = execution.getVariable("progress")
903 logger.info("progress: " + progress )
904 if ("100".equalsIgnoreCase(progress))
909 String operationContent = "Prepare service delete: " + execution.getVariable("operationStatus")
910 logger.info("Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId)
911 serviceId = UriUtils.encode(serviceId,"UTF-8")
912 execution.setVariable("serviceInstanceId", serviceId)
913 execution.setVariable("operationId", operationId)
914 execution.setVariable("operationType", operationType)
916 def dbAdapterEndpoint = UrnPropertiesReader.getVariable("mso.adapters.openecomp.db.endpoint", execution)
917 execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
918 logger.info("DB Adapter Endpoint is: " + dbAdapterEndpoint)
921 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
922 xmlns:ns="http://org.onap.so/requestsdb">
925 <ns:updateServiceOperationStatus xmlns:ns="http://org.onap.so/requestsdb">
926 <serviceId>${MsoUtils.xmlEscape(serviceId)}</serviceId>
927 <operationId>${MsoUtils.xmlEscape(operationId)}</operationId>
928 <serviceName>${MsoUtils.xmlEscape(serviceName)}</serviceName>
929 <operationType>${MsoUtils.xmlEscape(operationType)}</operationType>
930 <userId>${MsoUtils.xmlEscape(userId)}</userId>
931 <result>${MsoUtils.xmlEscape(result)}</result>
932 <operationContent>${MsoUtils.xmlEscape(operationContent)}</operationContent>
933 <progress>${MsoUtils.xmlEscape(progress)}</progress>
934 <reason>${MsoUtils.xmlEscape(reason)}</reason>
935 </ns:updateServiceOperationStatus>
937 </soapenv:Envelope>"""
939 payload = utils.formatXml(payload)
940 execution.setVariable("CVFMI_updateServiceOperStatusRequest", payload)
941 logger.info("Outgoing preUpdateServiceOperationStatus: \n" + payload)
945 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
946 "Exception Occured Processing preUpdateServiceOperationStatus.", "BPMN",
947 ErrorCode.UnknownError.getValue(), e);
948 execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during preUpdateServiceOperationStatus Method:\n" + e.getMessage())
950 logger.trace("COMPLETED preUpdateServiceOperationStatus Process ")
951 logger.info("Exited " + method)
954 public void preInitResourcesOperStatus(DelegateExecution execution){
955 def method = getClass().getSimpleName() + '.preInitResourcesOperStatus(' +'execution=' + execution.getId() +')'
956 logger.info("Entered " + method)
958 logger.trace("STARTED preInitResourcesOperStatus Process ")
961 String serviceId = execution.getVariable("serviceInstanceId")
962 String operationId = execution.getVariable("operationId")
963 String operationType = "DELETE"
964 String resourceTemplateUUIDs = ""
965 String result = "processing"
966 String progress = "0"
968 String operationContent = "Prepare service delete"
969 logger.info("Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId + " operationType:" + operationType)
970 serviceId = UriUtils.encode(serviceId,"UTF-8")
971 execution.setVariable("serviceInstanceId", serviceId)
972 execution.setVariable("operationId", operationId)
973 execution.setVariable("operationType", operationType)
975 String serviceRelationShip = execution.getVariable("serviceRelationShip")
976 logger.info("serviceRelationShip: " + serviceRelationShip)
977 if (! isBlank(serviceRelationShip)) {
978 def jsonSlurper = new JsonSlurper()
979 def jsonOutput = new JsonOutput()
980 List relationShipList = jsonSlurper.parseText(serviceRelationShip)
982 if (relationShipList != null) {
983 relationShipList.each {
984 resourceTemplateUUIDs = resourceTemplateUUIDs + it.resourceInstanceId + ":"
989 def dbAdapterEndpoint = UrnPropertiesReader.getVariable("mso.adapters.openecomp.db.endpoint", execution)
990 execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
991 logger.info("DB Adapter Endpoint is: " + dbAdapterEndpoint)
994 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
995 xmlns:ns="http://org.onap.so/requestsdb">
998 <ns:initResourceOperationStatus xmlns:ns="http://org.onap.so/requestsdb">
999 <serviceId>${MsoUtils.xmlEscape(serviceId)}</serviceId>
1000 <operationId>${MsoUtils.xmlEscape(operationId)}</operationId>
1001 <operationType>${MsoUtils.xmlEscape(operationType)}</operationType>
1002 <resourceTemplateUUIDs>${MsoUtils.xmlEscape(resourceTemplateUUIDs)}</resourceTemplateUUIDs>
1003 </ns:initResourceOperationStatus>
1005 </soapenv:Envelope>"""
1007 payload = utils.formatXml(payload)
1008 execution.setVariable("CVFMI_initResOperStatusRequest", payload)
1009 logger.info("Outgoing initResourceOperationStatus: \n" + payload)
1010 logger.debug("DoCustomDeleteE2EServiceInstanceV2 Outgoing initResourceOperationStatus Request: " + payload)
1012 }catch (BpmnError e) {
1014 } catch (Exception ex) {
1015 msg = "Exception in DoCustomDeleteE2EServiceInstanceV2.preInitResourcesOperStatus. " + ex.getMessage()
1017 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
1019 logger.info("Exited " + method)
1025 * prepare delete parameters
1027 public void preProcessVFCResourceDelete(execution){
1028 // we use resource instance ids for delete flow as resourceTemplateUUIDs
1030 def method = getClass().getSimpleName() + '.preProcessVFCResourceDelete(' +'execution=' + execution.getId() +')'
1031 logger.info("Entered " + method)
1033 logger.trace("STARTED preProcessVFCResourceDelete Process ")
1035 String serviceResource = execution.getVariable("serviceResource")
1036 logger.info("serviceResource : " + serviceResource)
1038 String resourceInstanceId = execution.getVariable("resourceInstanceId")
1039 logger.info("resourceInstanceId : " + resourceInstanceId)
1041 execution.setVariable("resourceTemplateId", resourceInstanceId)
1042 logger.info("resourceTemplateId : " + resourceInstanceId)
1044 String resourceType = execution.getVariable("resourceType")
1045 logger.info("resourceType : " + resourceType)
1048 String resourceName = execution.getVariable(Prefix+"resourceName")
1049 if (isBlank(resourceName)){
1050 resourceName = resourceInstanceId
1052 execution.setVariable("resourceName", resourceName)
1053 logger.info("resource Name : " + resourceName)
1055 logger.info("Delete Resource Info: resourceInstanceId :" + resourceInstanceId + " resourceTemplateId: " + resourceInstanceId + " resourceType: " + resourceType)
1056 }catch (BpmnError e) {
1058 } catch (Exception ex) {
1059 msg = "Exception in DoDeleteE2EServiceInstance.preProcessVFCResourceDelete. " + ex.getMessage()
1061 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
1063 logger.info("Exited " + method)
1066 public void postProcessVFCDelete(DelegateExecution execution, String response, String action) {
1067 def method = getClass().getSimpleName() + '.postProcessVFCDelete(' +'execution=' + execution.getId() +')'
1068 logger.info("Entered " + method)
1070 logger.trace("STARTED postProcessVFCDelete Process ")
1073 }catch (BpmnError e) {
1075 } catch (Exception ex) {
1076 msg = "Exception in DoDeleteE2EServiceInstance.postProcessVFCDelete. " + ex.getMessage()
1078 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
1080 logger.info("Exited " + method)