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 org.onap.aai.domain.yang.AllottedResource
26 import org.onap.so.logger.ErrorCode
28 import javax.ws.rs.core.UriBuilder
30 import static org.apache.commons.lang3.StringUtils.*;
32 import org.apache.commons.lang3.*
33 import org.camunda.bpm.engine.delegate.BpmnError
34 import org.camunda.bpm.engine.delegate.DelegateExecution
35 import org.json.JSONArray
36 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
37 import org.onap.so.bpmn.common.scripts.ExceptionUtil
38 import org.onap.so.bpmn.common.scripts.MsoUtils
39 import org.onap.so.bpmn.core.json.JsonUtils
40 import org.onap.so.bpmn.core.UrnPropertiesReader
41 import org.onap.so.logger.MessageEnum
42 import org.slf4j.Logger
43 import org.slf4j.LoggerFactory
45 import org.springframework.web.util.UriUtils;
46 import org.onap.so.client.aai.AAIResourcesClient
47 import org.onap.so.client.aai.AAIObjectType
48 import org.onap.so.client.aai.entities.AAIResultWrapper
49 import org.onap.so.client.aai.entities.uri.AAIResourceUri
50 import org.onap.so.client.aai.entities.uri.AAIUriFactory
51 import org.json.JSONObject
52 import javax.ws.rs.NotFoundException
58 * This groovy class supports the <class>DoDeleteE2EServiceInstance.bpmn</class> process.
61 * @param - msoRequestId
62 * @param - globalSubscriberId - O
63 * @param - subscriptionServiceType - O
64 * @param - serviceInstanceId
65 * @param - serviceInstanceName - O
66 * @param - serviceInputParams (should contain aic_zone for serviceTypes TRANSPORT,ATM)
67 * @param - sdncVersion
68 * @param - failNotFound - TODO
69 * @param - serviceInputParams - TODO
72 * @param - WorkflowException
76 public class DoCustomDeleteE2EServiceInstanceV2 extends AbstractServiceTaskProcessor {
77 private static final Logger logger = LoggerFactory.getLogger( DoCustomDeleteE2EServiceInstanceV2.class);
80 String Prefix="DDELSI_"
81 private static final String DebugFlag = "isDebugEnabled"
82 ExceptionUtil exceptionUtil = new ExceptionUtil()
83 JsonUtils jsonUtil = new JsonUtils()
85 public void preProcessRequest (DelegateExecution execution) {
87 def method = getClass().getSimpleName() + '.buildAPPCRequest(' +'execution=' + execution.getId() +')'
88 logger.info("Entered " + method)
89 logger.trace("preProcessRequest ")
93 String requestId = execution.getVariable("msoRequestId")
94 execution.setVariable("prefix",Prefix)
97 //requestDetails.subscriberInfo. for AAI GET & PUT & SDNC assignToplology
98 String globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId
99 if (globalSubscriberId == null)
101 execution.setVariable("globalSubscriberId", "")
104 //requestDetails.requestParameters. for AAI PUT & SDNC assignTopology
105 String serviceType = execution.getVariable("serviceType")
106 if (serviceType == null)
108 execution.setVariable("serviceType", "")
111 //Generated in parent for AAI PUT
112 String serviceInstanceId = execution.getVariable("serviceInstanceId")
113 if (isBlank(serviceInstanceId)){
114 msg = "Input serviceInstanceId is null"
116 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
119 String sdncCallbackUrl = execution.getVariable('URN_mso_workflow_sdncadapter_callback')
120 if (isBlank(sdncCallbackUrl)) {
121 msg = "URN_mso_workflow_sdncadapter_callback is null"
123 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
125 execution.setVariable("sdncCallbackUrl", sdncCallbackUrl)
126 logger.info("SDNC Callback URL: " + sdncCallbackUrl)
128 StringBuilder sbParams = new StringBuilder()
129 Map<String, String> paramsMap = execution.getVariable("serviceInputParams")
130 if (paramsMap != null)
132 sbParams.append("<service-input-parameters>")
133 for (Map.Entry<String, String> entry : paramsMap.entrySet()) {
135 String paramName = entry.getKey()
136 String paramValue = entry.getValue()
139 <name>${MsoUtils.xmlEscape(paramName)}</name>
140 <value>${MsoUtils.xmlEscape(paramValue)}</value>
143 sbParams.append(paramsXml)
145 sbParams.append("</service-input-parameters>")
147 String siParamsXml = sbParams.toString()
148 if (siParamsXml == null)
150 execution.setVariable("siParamsXml", siParamsXml)
151 execution.setVariable("operationStatus", "Waiting delete resource...")
152 execution.setVariable("progress", "0")
154 } catch (BpmnError e) {
156 } catch (Exception ex){
157 msg = "Exception in preProcessRequest " + ex.getMessage()
159 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
161 logger.info("Exited " + method)
165 * Gets the service instance and its relationships from aai
169 public void getServiceInstance(DelegateExecution execution) {
171 String serviceInstanceId = execution.getVariable('serviceInstanceId')
172 String globalSubscriberId = execution.getVariable('globalSubscriberId')
173 String serviceType = execution.getVariable('serviceType')
175 AAIResourcesClient resourceClient = new AAIResourcesClient()
176 AAIResourceUri serviceInstanceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, globalSubscriberId, serviceType, serviceInstanceId)
177 AAIResultWrapper wrapper = resourceClient.get(serviceInstanceUri, NotFoundException.class)
178 String json = wrapper.getJson()
180 execution.setVariable("serviceInstance", json)
182 }catch(BpmnError e) {
184 }catch(NotFoundException e) {
185 logger.info("SI not found in aai. Silent Success ")
186 }catch(Exception ex) {
187 String msg = "Internal Error in getServiceInstance: " + ex.getMessage()
188 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
192 private void loadResourcesProperties(DelegateExecution execution) {
193 def method = getClass().getSimpleName() + '.loadResourcesProperties(' +'execution=' + execution.getId() +')'
194 def isDebugEnabled = execution.getVariable("isDebugEnabled")
195 logger.info("Entered " + method)
196 String loadFilePath = "/etc/mso/config.d/reources.json"
198 def jsonPayload = new File(loadFilePath).text
199 logger.info("jsonPayload: " + jsonPayload)
201 String resourcesProperties = jsonUtil.prettyJson(jsonPayload.toString())
202 logger.info("resourcesProperties: " + resourcesProperties)
204 String createResourceSort = jsonUtil.getJsonValue(resourcesProperties, "CreateResourceSort")
205 logger.info("createResourceSort: " + createResourceSort)
206 execution.setVariable("createResourceSort", createResourceSort)
208 String deleteResourceSort = jsonUtil.getJsonValue(resourcesProperties, "DeleteResourceSort")
209 logger.info("deleteResourceSort: " + deleteResourceSort)
210 execution.setVariable("deleteResourceSort", deleteResourceSort)
213 String resourceControllerType = jsonUtil.getJsonValue(resourcesProperties, "ResourceControllerType")
214 logger.info("resourceControllerType: " + resourceControllerType)
215 execution.setVariable("resourceControllerType", resourceControllerType)
218 }catch(Exception ex){
219 // try error in method block
220 String exceptionMessage = "Bpmn error encountered in " + method + " - " + ex.getMessage()
221 logger.debug(exceptionMessage)
222 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
224 logger.info("Exited " + method)
226 private void sortDeleteResource(DelegateExecution execution) {
227 def method = getClass().getSimpleName() + '.sortDeleteResource(' +'execution=' + execution.getId() +')'
228 def isDebugEnabled = execution.getVariable("isDebugEnabled")
229 logger.info("Entered " + method)
230 String deleteResourceSortDef = """[
232 "resourceType":"GRE_SAR"
235 "resourceType":"VPN_SAR"
238 "resourceType":"APN_AAR"
241 "resourceType":"GRE_AAR"
244 "resourceType":"Overlay"
247 "resourceType":"Underlay"
250 "resourceType":"vIMS"
253 "resourceType":"vCPE"
259 "resourceType":"vEPC"
266 loadResourcesProperties(execution)
267 String deleteResourceSort = execution.getVariable("deleteResourceSort")
268 if (isBlank(deleteResourceSort)) {
269 deleteResourceSort = deleteResourceSortDef;
272 List<String> sortResourceList = jsonUtil.StringArrayToList(execution, deleteResourceSort)
273 logger.info("sortResourceList : " + sortResourceList)
275 JSONArray newResourceList = new JSONArray()
276 int resSortCount = sortResourceList.size()
278 for ( int currentResource = 0 ; currentResource < resSortCount ; currentResource++ ) {
279 String currentSortResource = sortResourceList[currentResource]
280 String sortResourceType = jsonUtil.getJsonValue(currentSortResource, "resourceType")
281 List<String> resourceList = execution.getVariable(Prefix+"resourceList")
283 for (String resource : resourceList) {
284 logger.info("resource : " + resource)
285 String resourceType = jsonUtil.getJsonValue(resource, "resourceType")
287 if (StringUtils.containsIgnoreCase(resourceType, sortResourceType)) {
288 JSONObject jsonObj = new JSONObject(resource)
289 newResourceList.put(jsonObj)
291 logger.info("Get next sort type " )
295 String newResourceStr = newResourceList.toString()
296 List<String> newResourceListStr = jsonUtil.StringArrayToList(execution, newResourceStr)
298 execution.setVariable(Prefix+"resourceList", newResourceListStr)
299 logger.info("newResourceList : " + newResourceListStr)
301 }catch(Exception ex){
302 // try error in method block
303 String exceptionMessage = "Bpmn error encountered in " + method + " - " + ex.getMessage()
304 logger.debug(exceptionMessage)
305 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
307 logger.info("Exited " + method)
310 public void prepareServiceDeleteResource(DelegateExecution execution) {
311 def method = getClass().getSimpleName() + '.prepareServiceDeleteResource(' +'execution=' + execution.getId() +')'
312 logger.info("Entered " + method)
316 String serviceInstanceId = execution.getVariable("serviceInstanceId")
319 execution.setVariable(Prefix+"resourceList", "")
320 execution.setVariable(Prefix+"resourceCount", 0)
321 execution.setVariable(Prefix+"nextResource", 0)
322 execution.setVariable(Prefix+"resourceFinish", true)
324 String aaiJsonRecord = execution.getVariable("serviceInstance");
325 logger.info("serviceInstanceAaiRecord: " +aaiJsonRecord)
327 logger.info("aaiJsonRecord: " +aaiJsonRecord)
328 def serviceInstanceName = jsonUtil.getJsonValue(aaiJsonRecord, "service-instance.service-instance-name")
329 execution.setVariable("serviceInstanceName",serviceInstanceName)
331 def serviceType = jsonUtil.getJsonValue(aaiJsonRecord, "service-instance.service-type")
332 execution.setVariable("serviceType",serviceType)
335 String relationshipList = jsonUtil.getJsonValue(aaiJsonRecord, "service-instance.relationship-list")
336 logger.info("relationship-list:" + relationshipList)
337 if (! isBlank(relationshipList)){
338 logger.info("relationship-list exists" )
339 String relationShip = jsonUtil.getJsonValue(relationshipList, "relationship")
340 logger.info("relationship: " + relationShip)
341 JSONArray allResources = new JSONArray()
342 JSONArray serviceResources = new JSONArray()
343 JSONArray networkResources = new JSONArray()
344 JSONArray allottedResources = new JSONArray()
347 if (! isBlank(relationShip)){
348 JSONArray jsonArray = new JSONArray();
349 if (relationShip.startsWith("{") && relationShip.endsWith("}")) {
350 JSONObject jsonObject = new JSONObject(relationShip);
351 jsonArray.put(jsonObject);
352 } else if (relationShip.startsWith("[") && relationShip.endsWith("]")) {
353 jsonArray = new JSONArray(relationShip);
355 logger.info("The relationShip fomart is error" )
358 List<String> relationList = jsonUtil.StringArrayToList(execution, jsonArray.toString())
360 logger.info("relationList: " + relationList)
362 int relationNum =relationList.size()
363 logger.info("**************relationList size: " + relationNum)
365 for ( int currentRelation = 0 ; currentRelation < relationNum ; currentRelation++ ) {
366 logger.info("current Relation num: " + currentRelation)
367 String relation = relationList[currentRelation]
368 logger.info("relation: " + relation)
370 String relatedTo = jsonUtil.getJsonValue(relation, "related-to")
371 logger.info("relatedTo: " + relatedTo)
373 String relatedLink = jsonUtil.getJsonValue(relation, "related-link")
374 logger.info("relatedLink: " + relatedLink)
376 if (StringUtils.equalsIgnoreCase(relatedTo, "allotted-resource")) {
377 logger.info("allotted-resource exists ")
379 Optional<AllottedResource> aaiArRsp = getAaiAr(execution, relatedLink)
380 logger.info("aaiArRsp: " + aaiArRsp)
381 if (aaiArRsp.isPresent()) {
383 JSONObject jObject = new JSONObject()
384 jObject.put("resourceType", aaiArRsp.get().getType())
385 jObject.put("resourceInstanceId", aaiArRsp.get().getId())
386 jObject.put("resourceRole", aaiArRsp.get().getRole())
387 jObject.put("resourceVersion", aaiArRsp.get().getResourceVersion())
389 allResources.put(jObject)
390 logger.info("allResources: " + allResources)
391 allottedResources.put(jObject)
392 logger.info("allottedResources: " + allottedResources)
395 else if (StringUtils.equalsIgnoreCase(relatedTo, "service-instance")){
396 logger.info("service-instance exists ")
397 JSONObject jObject = new JSONObject()
400 String rsDataStr = jsonUtil.getJsonValue(relation, "relationship-data")
401 logger.info("rsDataStr: " + rsDataStr)
402 List<String> rsDataList = jsonUtil.StringArrayToList(execution, rsDataStr)
403 logger.info("rsDataList: " + rsDataList)
404 for(String rsData : rsDataList){
405 logger.info("rsData: " + rsData)
406 def eKey = jsonUtil.getJsonValue(rsData, "relationship-key")
407 def eValue = jsonUtil.getJsonValue(rsData, "relationship-value")
408 if(eKey.equals("service-instance.service-instance-id")){
409 jObject.put("resourceInstanceId", eValue)
411 if(eKey.equals("service-subscription.service-type")){
412 jObject.put("resourceType", eValue)
416 //related-to-property
417 String rPropertyStr = jsonUtil.getJsonValue(relation, "related-to-property")
418 logger.info("related-to-property: " + rPropertyStr)
419 if (rPropertyStr instanceof JSONArray){
420 List<String> rPropertyList = jsonUtil.StringArrayToList(execution, rPropertyStr)
421 for (String rProperty : rPropertyList) {
422 logger.info("rProperty: " + rProperty)
423 def eKey = jsonUtil.getJsonValue(rProperty, "property-key")
424 def eValue = jsonUtil.getJsonValue(rProperty, "property-value")
425 if(eKey.equals("service-instance.service-instance-name")){
426 jObject.put("resourceName", eValue)
431 String rProperty = rPropertyStr
432 logger.info("rProperty: " + rProperty)
433 def eKey = jsonUtil.getJsonValue(rProperty, "property-key")
434 def eValue = jsonUtil.getJsonValue(rProperty, "property-value")
435 if (eKey.equals("service-instance.service-instance-name")) {
436 jObject.put("resourceName", eValue)
440 allResources.put(jObject)
441 logger.info("allResources: " + allResources)
443 serviceResources.put(jObject)
444 logger.info("serviceResources: " + serviceResources)
446 else if (StringUtils.equalsIgnoreCase(relatedTo, "configuration")) {
447 logger.info("configuration ")
448 JSONObject jObject = new JSONObject()
451 String rsDataStr = jsonUtil.getJsonValue(relation, "relationship-data")
452 logger.info("rsDataStr: " + rsDataStr)
453 List<String> rsDataList = jsonUtil.StringArrayToList(execution, rsDataStr)
454 logger.info("rsDataList: " + rsDataList)
455 for (String rsData : rsDataList) {
456 logger.info("rsData: " + rsData)
457 def eKey = jsonUtil.getJsonValue(rsData, "relationship-key")
458 def eValue = jsonUtil.getJsonValue(rsData, "relationship-value")
459 if(eKey.equals("configuration.configuration-id")){
460 jObject.put("resourceInstanceId", eValue)
465 //related-to-property
466 String rPropertyStr = jsonUtil.getJsonValue(relation, "related-to-property")
467 logger.info("related-to-property: " + rPropertyStr)
468 if (rPropertyStr instanceof JSONArray){
469 List<String> rPropertyList = jsonUtil.StringArrayToList(execution, rPropertyStr)
470 for(String rProperty : rPropertyList){
471 logger.info("rProperty: " + rProperty)
472 def eKey = jsonUtil.getJsonValue(rProperty, "property-key")
473 def eValue = jsonUtil.getJsonValue(rProperty, "property-value")
474 if(eKey.equals("configuration.configuration-type")){
475 jObject.put("resourceType", eValue)
480 String rProperty = rPropertyStr
481 logger.info("rProperty: " + rProperty)
482 def eKey = jsonUtil.getJsonValue(rProperty, "property-key")
483 def eValue = jsonUtil.getJsonValue(rProperty, "property-value")
484 if(eKey.equals("configuration.configuration-type")){
485 jObject.put("resourceType", eValue)
488 allResources.put(jObject)
489 logger.info("allResources: " + allResources)
491 networkResources.put(jObject)
492 logger.info("networkResources: " + networkResources)
494 logger.info("Get Next releation resource " )
497 logger.info("Get releation finished. " )
500 execution.setVariable("serviceRelationShip", allResources.toString())
501 logger.info("allResources: " + allResources.toString())
502 String serviceRelationShip = execution.getVariable("serviceRelationShip")
503 logger.info("serviceRelationShip: " + serviceRelationShip)
504 if ((! isBlank(serviceRelationShip)) && (! serviceRelationShip.isEmpty())) {
506 List<String> relationShipList = jsonUtil.StringArrayToList(execution, serviceRelationShip)
507 logger.info("relationShipList: " + relationShipList)
508 execution.setVariable(Prefix+"resourceList", relationShipList)
510 int resourceCount = relationShipList.size()
511 logger.info("resourceCount: " + resourceCount)
512 execution.setVariable(Prefix+"resourceCount",resourceCount )
515 execution.setVariable(Prefix+"nextResource", resourceNum)
516 logger.info("start sort delete resource: ")
517 sortDeleteResource(execution)
520 if (resourceNum < resourceCount) {
521 execution.setVariable(Prefix+"resourceFinish", false)
524 execution.setVariable(Prefix+"resourceFinish", true)
526 logger.info("Resource list set end : " + resourceCount)
529 execution.setVariable("serviceResources", serviceResources.toString())
530 logger.info("serviceResources: " + serviceResources)
531 String serviceResourcesShip = execution.getVariable("serviceResources")
532 logger.info("serviceResourcesShip: " + serviceResourcesShip)
534 if ((! isBlank(serviceResourcesShip)) && (! serviceResourcesShip.isEmpty())) {
535 List<String> serviceResourcesList = jsonUtil.StringArrayToList(execution, serviceResourcesShip)
536 logger.info("serviceResourcesList: " + serviceResourcesList)
537 execution.setVariable(Prefix+"serviceResourceList", serviceResourcesList)
538 execution.setVariable(Prefix+"serviceResourceCount", serviceResourcesList.size())
539 execution.setVariable(Prefix+"nextServiceResource", 0)
540 logger.info("Service Resource list set end : " + serviceResourcesList.size())
544 execution.setVariable("allottedResources", allottedResources.toString())
545 logger.info("allottedResources: " + allottedResources)
546 String allottedResourcesShip = execution.getVariable("allottedResources")
547 logger.info("allottedResourcesShip: " + allottedResourcesShip)
548 if ((! isBlank(allottedResourcesShip)) && (! allottedResourcesShip.isEmpty())) {
549 List<String> allottedResourcesList = jsonUtil.StringArrayToList(execution, allottedResourcesShip)
550 logger.info("allottedResourcesList: " + allottedResourcesList)
551 execution.setVariable(Prefix+"allottedResourcesList", allottedResourcesList)
552 execution.setVariable(Prefix+"allottedResourcesListCount", allottedResourcesList.size())
553 execution.setVariable(Prefix+"nextAllottedResourcesList", 0)
554 logger.info("Allotted Resource list set end : " + allottedResourcesList.size())
557 execution.setVariable("networkResources", networkResources.toString())
558 logger.info("networkResources: " + networkResources)
559 String networkResourcesShip = execution.getVariable("networkResources")
560 logger.info("networkResourcesShip: " + networkResourcesShip)
561 if ((! isBlank(networkResourcesShip)) && (! networkResourcesShip.isEmpty())) {
562 List<String> networkResourcesList = jsonUtil.StringArrayToList(execution, networkResourcesShip)
563 logger.info("networkResourcesList: " + networkResourcesList)
564 execution.setVariable(Prefix+"networkResourcesList", networkResourcesList)
565 execution.setVariable(Prefix+"networkResourcesListCount", networkResourcesList.size())
566 execution.setVariable(Prefix+"nextNetworkResourcesList", 0)
567 logger.info("Network Resource list set end : " + networkResourcesList.size())
571 } catch (BpmnError e){
573 } catch (Exception ex) {
574 String exceptionMessage = "Bpmn error encountered in DeleteMobileAPNCustService flow. prepareServiceDeleteResource() - " + ex.getMessage()
575 logger.debug(exceptionMessage)
576 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
578 logger.info("Exited " + method)
581 private Optional<AllottedResource> getAaiAr(DelegateExecution execution, String relink) {
582 def method = getClass().getSimpleName() + '.getAaiAr(' +'execution=' + execution.getId() +')'
583 logger.info("Entered " + method)
584 AAIResourceUri uri = AAIUriFactory.createResourceFromExistingURI(AAIObjectType.ALLOTTED_RESOURCE, UriBuilder.fromPath(relink).build())
585 return getAAIClient().get(AllottedResource.class,uri)
588 * prepare Decompose next resource to create request
590 public void preProcessDecomposeNextResource(DelegateExecution execution){
591 def method = getClass().getSimpleName() + '.getAaiAr(' +'execution=' + execution.getId() +')'
592 logger.info("Entered " + method)
593 logger.trace("STARTED preProcessDecomposeNextResource Process ")
595 int resourceNum = execution.getVariable(Prefix+"nextServiceResource")
596 List<String> serviceResourceList = execution.getVariable(Prefix+"serviceResourceList")
597 logger.info("Service Resource List : " + serviceResourceList)
599 String serviceResource = serviceResourceList[resourceNum]
600 execution.setVariable(Prefix+"serviceResource", serviceResource)
601 logger.info("Current Service Resource : " + serviceResource)
603 String resourceType = jsonUtil.getJsonValue(serviceResource, "resourceType")
604 execution.setVariable("resourceType", resourceType)
605 logger.info("resourceType : " + resourceType)
607 String resourceInstanceId = jsonUtil.getJsonValue(serviceResource, "resourceInstanceId")
608 execution.setVariable("resourceInstanceId", resourceInstanceId)
609 logger.info("resourceInstanceId : " + resourceInstanceId)
611 String resourceRole = jsonUtil.getJsonValue(serviceResource, "resourceRole")
612 execution.setVariable("resourceRole", resourceRole)
613 logger.info("resourceRole : " + resourceRole)
615 String resourceVersion = jsonUtil.getJsonValue(serviceResource, "resourceVersion")
616 execution.setVariable("resourceVersion", resourceVersion)
617 logger.info("resourceVersion : " + resourceVersion)
619 String resourceName = jsonUtil.getJsonValue(serviceResource, "resourceName")
620 if (isBlank(resourceName)){
621 resourceName = resourceInstanceId
623 execution.setVariable(Prefix+"resourceName", resourceName)
624 logger.info("resource Name : " + resourceName)
627 execution.setVariable(Prefix+"nextServiceResource", resourceNum + 1)
629 int serviceResourceCount = execution.getVariable(Prefix+"serviceResourceCount")
630 if (serviceResourceCount >0 ){
631 int progress = (resourceNum*100) / serviceResourceCount
632 execution.setVariable("progress", progress.toString() )
634 execution.setVariable("operationStatus", resourceName )
637 // try error in method block
638 String exceptionMessage = "Bpmn error encountered in CreateMobileAPNCustService flow. Unexpected Error from method preProcessDecomposeNextResource() - " + ex.getMessage()
639 logger.debug(exceptionMessage)
640 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
642 logger.info("Exited " + method)
645 * post Decompose next resource to create request
647 public void postProcessDecomposeNextResource(DelegateExecution execution){
648 def method = getClass().getSimpleName() + '.postProcessDecomposeNextResource(' +'execution=' + execution.getId() +')'
649 logger.info("Entered " + method)
650 logger.trace("STARTED postProcessDecomposeNextResource Process ")
652 String resourceName = execution.getVariable(Prefix+"resourceName")
653 int resourceNum = execution.getVariable(Prefix+"nextServiceResource")
654 logger.debug("Current Resource count:"+ execution.getVariable(Prefix+"nextServiceResource"))
656 int resourceCount = execution.getVariable(Prefix+"serviceResourceCount")
657 logger.debug("Total Resource count:"+ execution.getVariable(Prefix+"serviceResourceCount"))
659 if (resourceNum < resourceCount) {
660 execution.setVariable(Prefix+"resourceFinish", false)
663 execution.setVariable(Prefix+"resourceFinish", true)
666 logger.debug("Resource Finished:"+ execution.getVariable(Prefix+"resourceFinish"))
668 if (resourceCount >0 ){
669 int progress = (resourceNum*100) / resourceCount
671 execution.setVariable("progress", progress.toString() )
672 logger.trace(":"+ execution.getVariable(""))
674 execution.setVariable("operationStatus", resourceName )
678 // try error in method block
679 String exceptionMessage = "Bpmn error encountered in CreateMobileAPNCustService flow. Unexpected Error from method postProcessDecomposeNextResource() - " + ex.getMessage()
680 logger.debug(exceptionMessage)
681 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
683 logger.info("Exited " + method)
686 * prepare post Unkown Resource Type
688 public void postOtherControllerType(DelegateExecution execution){
689 def method = getClass().getSimpleName() + '.postOtherControllerType(' +'execution=' + execution.getId() +')'
690 def isDebugEnabled = execution.getVariable("isDebugEnabled")
691 logger.info("Entered " + method)
695 String resourceName = execution.getVariable(Prefix+"resourceName")
696 String resourceType = execution.getVariable(Prefix+"resourceType")
697 String controllerType = execution.getVariable("controllerType")
699 String msg = "Resource name: "+ resourceName + " resource Type: " + resourceType+ " controller Type: " + controllerType + " can not be processed n the workflow"
703 // try error in method block
704 String exceptionMessage = "Bpmn error encountered in DoCreateMobileAPNServiceInstance flow. Unexpected Error from method postOtherControllerType() - " + ex.getMessage()
705 logger.debug(exceptionMessage)
706 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
708 logger.info("Exited " + method)
712 * prepare delete parameters
714 public void preSDNCResourceDelete(execution, resourceName){
715 // we use resource instance ids for delete flow as resourceTemplateUUIDs
717 def method = getClass().getSimpleName() + '.preSDNCResourceDelete(' +'execution=' + execution.getId() +')'
718 logger.info("Entered " + method)
720 logger.trace("STARTED preSDNCResourceDelete Process ")
721 String networkResources = execution.getVariable("networkResources")
724 execution.setVariable("foundResource", false)
725 if (networkResources != null) {
726 def jsonSlurper = new JsonSlurper()
727 List relationShipList = jsonSlurper.parseText(networkResources)
728 relationShipList.each {
729 if(StringUtils.containsIgnoreCase(it.resourceType, resourceName)) {
730 String resourceInstanceUUID = it.resourceInstanceId
731 String resourceTemplateUUID = it.resourceInstanceId
732 execution.setVariable("resourceTemplateId", resourceTemplateUUID)
733 execution.setVariable("resourceInstanceId", resourceInstanceUUID)
734 execution.setVariable("resourceType", resourceName)
735 execution.setVariable("foundResource", true)
736 logger.info("Delete Resource Info resourceTemplate Id :" + resourceTemplateUUID + " resourceInstanceId: " + resourceInstanceUUID + " resourceType: " + resourceName)
740 logger.info("Exited " + method)
742 public void preProcessSDNCDelete (DelegateExecution execution) {
743 def method = getClass().getSimpleName() + '.preProcessSDNCDelete(' +'execution=' + execution.getId() +')'
744 logger.info("Entered " + method)
745 logger.trace("preProcessSDNCDelete ")
749 def serviceInstanceId = execution.getVariable("serviceInstanceId")
750 def serviceInstanceName = execution.getVariable("serviceInstanceName")
751 def callbackURL = execution.getVariable("sdncCallbackUrl")
752 def requestId = execution.getVariable("msoRequestId")
753 def serviceId = execution.getVariable("productFamilyId")
754 def subscriptionServiceType = execution.getVariable("subscriptionServiceType")
755 def globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId
757 String serviceModelInfo = execution.getVariable("serviceModelInfo")
758 def modelInvariantUuid = ""
759 def modelVersion = ""
762 if (!isBlank(serviceModelInfo))
764 modelInvariantUuid = jsonUtil.getJsonValue(serviceModelInfo, "modelInvariantUuid")
765 modelVersion = jsonUtil.getJsonValue(serviceModelInfo, "modelVersion")
766 modelUuid = jsonUtil.getJsonValue(serviceModelInfo, "modelUuid")
767 modelName = jsonUtil.getJsonValue(serviceModelInfo, "modelName")
769 if (modelInvariantUuid == null) {
770 modelInvariantUuid = ""
772 if (modelVersion == null) {
775 if (modelUuid == null) {
778 if (modelName == null) {
782 if (serviceInstanceName == null) {
783 serviceInstanceName = ""
785 if (serviceId == null) {
789 def siParamsXml = execution.getVariable("siParamsXml")
790 def serviceType = execution.getVariable("serviceType")
791 if (serviceType == null)
796 def sdncRequestId = UUID.randomUUID().toString()
799 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
800 xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
801 xmlns:sdncadapter="http://org.onap/workflow/sdnc/adapter/schema/v1">
802 <sdncadapter:RequestHeader>
803 <sdncadapter:RequestId>${MsoUtils.xmlEscape(sdncRequestId)}</sdncadapter:RequestId>
804 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(serviceInstanceId)}</sdncadapter:SvcInstanceId>
805 <sdncadapter:SvcAction>delete</sdncadapter:SvcAction>
806 <sdncadapter:SvcOperation>service-topology-operation</sdncadapter:SvcOperation>
807 <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackURL)}</sdncadapter:CallbackUrl>
808 <sdncadapter:MsoAction>${MsoUtils.xmlEscape(serviceType)}</sdncadapter:MsoAction>
809 </sdncadapter:RequestHeader>
810 <sdncadapterworkflow:SDNCRequestData>
811 <request-information>
812 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
817 <request-action>DeleteServiceInstance</request-action>
818 </request-information>
819 <service-information>
820 <service-id>${MsoUtils.xmlEscape(serviceId)}</service-id>
821 <subscription-service-type>${MsoUtils.xmlEscape(subscriptionServiceType)}</subscription-service-type>
822 <onap-model-information>
823 <model-invariant-uuid>${MsoUtils.xmlEscape(modelInvariantUuid)}</model-invariant-uuid>
824 <model-uuid>${MsoUtils.xmlEscape(modelUuid)}</model-uuid>
825 <model-version>${MsoUtils.xmlEscape(modelVersion)}</model-version>
826 <model-name>${MsoUtils.xmlEscape(modelName)}</model-name>
827 </onap-model-information>
828 <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceId)}</service-instance-id>
830 <global-customer-id>${MsoUtils.xmlEscape(globalSubscriberId)}</global-customer-id>
831 </service-information>
832 <service-request-input>
833 <service-instance-name>${MsoUtils.xmlEscape(serviceInstanceName)}</service-instance-name>
835 </service-request-input>
836 </sdncadapterworkflow:SDNCRequestData>
837 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
839 sdncDelete = utils.formatXml(sdncDelete)
840 def sdncRequestId2 = UUID.randomUUID().toString()
841 String sdncDeactivate = sdncDelete.replace(">delete<", ">deactivate<").replace(">${sdncRequestId}<", ">${sdncRequestId2}<")
842 execution.setVariable("sdncDelete", sdncDelete)
843 execution.setVariable("sdncDeactivate", sdncDeactivate)
844 logger.info("sdncDeactivate:\n" + sdncDeactivate)
845 logger.info("sdncDelete:\n" + sdncDelete)
847 } catch (BpmnError e) {
849 } catch(Exception ex) {
850 msg = "Exception in preProcessSDNCDelete. " + ex.getMessage()
852 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "Exception Occured in preProcessSDNCDelete.\n" + ex.getMessage())
854 logger.info("Exited " + method)
857 public void postProcessSDNCDelete(DelegateExecution execution, String response, String action) {
859 def method = getClass().getSimpleName() + '.postProcessSDNCDelete(' +'execution=' + execution.getId() +')'
860 logger.info("Entered " + method)
861 logger.trace("postProcessSDNC " + action + " ")
865 WorkflowException workflowException = execution.getVariable("WorkflowException")
866 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
867 logger.info("SDNCResponse: " + response)
868 logger.info("workflowException: " + workflowException)
870 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
871 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
872 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == "true"){
873 logger.info("Good response from SDNC Adapter for service-instance " + action + "response:\n" + response)
876 msg = "Bad Response from SDNC Adapter for service-instance " + action
878 exceptionUtil.buildAndThrowWorkflowException(execution, 3500, msg)
880 } catch (BpmnError e) {
882 } catch(Exception ex) {
883 msg = "Exception in postProcessSDNC " + action + " Exception:" + ex.getMessage()
885 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
887 logger.info("Exited " + method)
891 * Init the service Operation Status
893 public void preUpdateServiceOperationStatus(DelegateExecution execution){
894 def method = getClass().getSimpleName() + '.preUpdateServiceOperationStatus(' +'execution=' + execution.getId() +')'
895 logger.info("Entered " + method)
898 String serviceId = execution.getVariable("serviceInstanceId")
899 String operationId = execution.getVariable("operationId")
900 String serviceName = execution.getVariable("serviceInstanceName")
901 String operationType = "DELETE"
903 String result = "processing"
904 String progress = execution.getVariable("progress")
905 logger.info("progress: " + progress )
906 if ("100".equalsIgnoreCase(progress))
911 String operationContent = "Prepare service delete: " + execution.getVariable("operationStatus")
912 logger.info("Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId)
913 serviceId = UriUtils.encode(serviceId,"UTF-8")
914 execution.setVariable("serviceInstanceId", serviceId)
915 execution.setVariable("operationId", operationId)
916 execution.setVariable("operationType", operationType)
918 def dbAdapterEndpoint = UrnPropertiesReader.getVariable("mso.adapters.openecomp.db.endpoint", execution)
919 execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
920 logger.info("DB Adapter Endpoint is: " + dbAdapterEndpoint)
923 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
924 xmlns:ns="http://org.onap.so/requestsdb">
927 <ns:updateServiceOperationStatus xmlns:ns="http://org.onap.so/requestsdb">
928 <serviceId>${MsoUtils.xmlEscape(serviceId)}</serviceId>
929 <operationId>${MsoUtils.xmlEscape(operationId)}</operationId>
930 <serviceName>${MsoUtils.xmlEscape(serviceName)}</serviceName>
931 <operationType>${MsoUtils.xmlEscape(operationType)}</operationType>
932 <userId>${MsoUtils.xmlEscape(userId)}</userId>
933 <result>${MsoUtils.xmlEscape(result)}</result>
934 <operationContent>${MsoUtils.xmlEscape(operationContent)}</operationContent>
935 <progress>${MsoUtils.xmlEscape(progress)}</progress>
936 <reason>${MsoUtils.xmlEscape(reason)}</reason>
937 </ns:updateServiceOperationStatus>
939 </soapenv:Envelope>"""
941 payload = utils.formatXml(payload)
942 execution.setVariable("CVFMI_updateServiceOperStatusRequest", payload)
943 logger.info("Outgoing preUpdateServiceOperationStatus: \n" + payload)
947 logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
948 "Exception Occured Processing preUpdateServiceOperationStatus.", "BPMN",
949 ErrorCode.UnknownError.getValue(), e);
950 execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during preUpdateServiceOperationStatus Method:\n" + e.getMessage())
952 logger.trace("COMPLETED preUpdateServiceOperationStatus Process ")
953 logger.info("Exited " + method)
956 public void preInitResourcesOperStatus(DelegateExecution execution){
957 def method = getClass().getSimpleName() + '.preInitResourcesOperStatus(' +'execution=' + execution.getId() +')'
958 logger.info("Entered " + method)
960 logger.trace("STARTED preInitResourcesOperStatus Process ")
963 String serviceId = execution.getVariable("serviceInstanceId")
964 String operationId = execution.getVariable("operationId")
965 String operationType = "DELETE"
966 String resourceTemplateUUIDs = ""
967 String result = "processing"
968 String progress = "0"
970 String operationContent = "Prepare service delete"
971 logger.info("Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId + " operationType:" + operationType)
972 serviceId = UriUtils.encode(serviceId,"UTF-8")
973 execution.setVariable("serviceInstanceId", serviceId)
974 execution.setVariable("operationId", operationId)
975 execution.setVariable("operationType", operationType)
977 String serviceRelationShip = execution.getVariable("serviceRelationShip")
978 logger.info("serviceRelationShip: " + serviceRelationShip)
979 if (! isBlank(serviceRelationShip)) {
980 def jsonSlurper = new JsonSlurper()
981 def jsonOutput = new JsonOutput()
982 List relationShipList = jsonSlurper.parseText(serviceRelationShip)
984 if (relationShipList != null) {
985 relationShipList.each {
986 resourceTemplateUUIDs = resourceTemplateUUIDs + it.resourceInstanceId + ":"
991 def dbAdapterEndpoint = UrnPropertiesReader.getVariable("mso.adapters.openecomp.db.endpoint", execution)
992 execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
993 logger.info("DB Adapter Endpoint is: " + dbAdapterEndpoint)
996 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
997 xmlns:ns="http://org.onap.so/requestsdb">
1000 <ns:initResourceOperationStatus xmlns:ns="http://org.onap.so/requestsdb">
1001 <serviceId>${MsoUtils.xmlEscape(serviceId)}</serviceId>
1002 <operationId>${MsoUtils.xmlEscape(operationId)}</operationId>
1003 <operationType>${MsoUtils.xmlEscape(operationType)}</operationType>
1004 <resourceTemplateUUIDs>${MsoUtils.xmlEscape(resourceTemplateUUIDs)}</resourceTemplateUUIDs>
1005 </ns:initResourceOperationStatus>
1007 </soapenv:Envelope>"""
1009 payload = utils.formatXml(payload)
1010 execution.setVariable("CVFMI_initResOperStatusRequest", payload)
1011 logger.info("Outgoing initResourceOperationStatus: \n" + payload)
1012 logger.debug("DoCustomDeleteE2EServiceInstanceV2 Outgoing initResourceOperationStatus Request: " + payload)
1014 }catch (BpmnError e) {
1016 } catch (Exception ex) {
1017 msg = "Exception in DoCustomDeleteE2EServiceInstanceV2.preInitResourcesOperStatus. " + ex.getMessage()
1019 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
1021 logger.info("Exited " + method)
1027 * prepare delete parameters
1029 public void preProcessVFCResourceDelete(execution){
1030 // we use resource instance ids for delete flow as resourceTemplateUUIDs
1032 def method = getClass().getSimpleName() + '.preProcessVFCResourceDelete(' +'execution=' + execution.getId() +')'
1033 logger.info("Entered " + method)
1035 logger.trace("STARTED preProcessVFCResourceDelete Process ")
1037 String serviceResource = execution.getVariable("serviceResource")
1038 logger.info("serviceResource : " + serviceResource)
1040 String resourceInstanceId = execution.getVariable("resourceInstanceId")
1041 logger.info("resourceInstanceId : " + resourceInstanceId)
1043 execution.setVariable("resourceTemplateId", resourceInstanceId)
1044 logger.info("resourceTemplateId : " + resourceInstanceId)
1046 String resourceType = execution.getVariable("resourceType")
1047 logger.info("resourceType : " + resourceType)
1050 String resourceName = execution.getVariable(Prefix+"resourceName")
1051 if (isBlank(resourceName)){
1052 resourceName = resourceInstanceId
1054 execution.setVariable("resourceName", resourceName)
1055 logger.info("resource Name : " + resourceName)
1057 logger.info("Delete Resource Info: resourceInstanceId :" + resourceInstanceId + " resourceTemplateId: " + resourceInstanceId + " resourceType: " + resourceType)
1058 }catch (BpmnError e) {
1060 } catch (Exception ex) {
1061 msg = "Exception in DoDeleteE2EServiceInstance.preProcessVFCResourceDelete. " + ex.getMessage()
1063 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
1065 logger.info("Exited " + method)
1068 public void postProcessVFCDelete(DelegateExecution execution, String response, String action) {
1069 def method = getClass().getSimpleName() + '.postProcessVFCDelete(' +'execution=' + execution.getId() +')'
1070 logger.info("Entered " + method)
1072 logger.trace("STARTED postProcessVFCDelete Process ")
1075 }catch (BpmnError e) {
1077 } catch (Exception ex) {
1078 msg = "Exception in DoDeleteE2EServiceInstance.postProcessVFCDelete. " + ex.getMessage()
1080 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
1082 logger.info("Exited " + method)