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 org.onap.aai.domain.yang.AllottedResource
25 import javax.ws.rs.core.UriBuilder
27 import static org.apache.commons.lang3.StringUtils.*;
29 import org.apache.commons.lang3.*
30 import org.camunda.bpm.engine.delegate.BpmnError
31 import org.camunda.bpm.engine.delegate.DelegateExecution
32 import org.json.JSONArray;
33 import org.onap.so.bpmn.common.scripts.AaiUtil
34 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
35 import org.onap.so.bpmn.common.scripts.ExceptionUtil
36 import org.onap.so.bpmn.common.scripts.MsoUtils
37 import org.onap.so.bpmn.core.json.JsonUtils
38 import org.onap.so.bpmn.core.UrnPropertiesReader
39 import org.onap.so.logger.MessageEnum
40 import org.onap.so.logger.MsoLogger
42 import org.springframework.web.util.UriUtils;
43 import org.onap.so.client.aai.AAIResourcesClient
44 import org.onap.so.client.aai.AAIObjectType
45 import org.onap.so.client.aai.entities.AAIResultWrapper
46 import org.onap.so.client.aai.entities.uri.AAIResourceUri
47 import org.onap.so.client.aai.entities.uri.AAIUriFactory
48 import org.json.JSONObject
49 import javax.ws.rs.NotFoundException
55 * This groovy class supports the <class>DoDeleteE2EServiceInstance.bpmn</class> process.
58 * @param - msoRequestId
59 * @param - globalSubscriberId - O
60 * @param - subscriptionServiceType - O
61 * @param - serviceInstanceId
62 * @param - serviceInstanceName - O
63 * @param - serviceInputParams (should contain aic_zone for serviceTypes TRANSPORT,ATM)
64 * @param - sdncVersion
65 * @param - failNotFound - TODO
66 * @param - serviceInputParams - TODO
69 * @param - WorkflowException
73 public class DoCustomDeleteE2EServiceInstanceV2 extends AbstractServiceTaskProcessor {
74 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoCustomDeleteE2EServiceInstanceV2.class);
77 String Prefix="DDELSI_"
78 private static final String DebugFlag = "isDebugEnabled"
79 ExceptionUtil exceptionUtil = new ExceptionUtil()
80 JsonUtils jsonUtil = new JsonUtils()
82 public void preProcessRequest (DelegateExecution execution) {
84 def method = getClass().getSimpleName() + '.buildAPPCRequest(' +'execution=' + execution.getId() +')'
85 msoLogger.info("Entered " + method)
86 msoLogger.trace("preProcessRequest ")
90 String requestId = execution.getVariable("msoRequestId")
91 execution.setVariable("prefix",Prefix)
94 //requestDetails.subscriberInfo. for AAI GET & PUT & SDNC assignToplology
95 String globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId
96 if (globalSubscriberId == null)
98 execution.setVariable("globalSubscriberId", "")
101 //requestDetails.requestParameters. for AAI PUT & SDNC assignTopology
102 String serviceType = execution.getVariable("serviceType")
103 if (serviceType == null)
105 execution.setVariable("serviceType", "")
108 //Generated in parent for AAI PUT
109 String serviceInstanceId = execution.getVariable("serviceInstanceId")
110 if (isBlank(serviceInstanceId)){
111 msg = "Input serviceInstanceId is null"
113 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
116 String sdncCallbackUrl = execution.getVariable('URN_mso_workflow_sdncadapter_callback')
117 if (isBlank(sdncCallbackUrl)) {
118 msg = "URN_mso_workflow_sdncadapter_callback is null"
120 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
122 execution.setVariable("sdncCallbackUrl", sdncCallbackUrl)
123 msoLogger.info("SDNC Callback URL: " + sdncCallbackUrl)
125 StringBuilder sbParams = new StringBuilder()
126 Map<String, String> paramsMap = execution.getVariable("serviceInputParams")
127 if (paramsMap != null)
129 sbParams.append("<service-input-parameters>")
130 for (Map.Entry<String, String> entry : paramsMap.entrySet()) {
132 String paramName = entry.getKey()
133 String paramValue = entry.getValue()
136 <name>${MsoUtils.xmlEscape(paramName)}</name>
137 <value>${MsoUtils.xmlEscape(paramValue)}</value>
140 sbParams.append(paramsXml)
142 sbParams.append("</service-input-parameters>")
144 String siParamsXml = sbParams.toString()
145 if (siParamsXml == null)
147 execution.setVariable("siParamsXml", siParamsXml)
148 execution.setVariable("operationStatus", "Waiting delete resource...")
149 execution.setVariable("progress", "0")
151 } catch (BpmnError e) {
153 } catch (Exception ex){
154 msg = "Exception in preProcessRequest " + ex.getMessage()
156 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
158 msoLogger.info("Exited " + method)
162 * Gets the service instance and its relationships from aai
166 public void getServiceInstance(DelegateExecution execution) {
168 String serviceInstanceId = execution.getVariable('serviceInstanceId')
169 String globalSubscriberId = execution.getVariable('globalSubscriberId')
170 String serviceType = execution.getVariable('serviceType')
172 AAIResourcesClient resourceClient = new AAIResourcesClient()
173 AAIResourceUri serviceInstanceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, globalSubscriberId, serviceType, serviceInstanceId)
174 AAIResultWrapper wrapper = resourceClient.get(serviceInstanceUri, NotFoundException.class)
175 String json = wrapper.getJson()
177 execution.setVariable("serviceInstance", json)
179 }catch(BpmnError e) {
181 }catch(NotFoundException e) {
182 msoLogger.info("SI not found in aai. Silent Success ")
183 }catch(Exception ex) {
184 String msg = "Internal Error in getServiceInstance: " + ex.getMessage()
185 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
189 private void loadResourcesProperties(DelegateExecution execution) {
190 def method = getClass().getSimpleName() + '.loadResourcesProperties(' +'execution=' + execution.getId() +')'
191 def isDebugEnabled = execution.getVariable("isDebugEnabled")
192 msoLogger.info("Entered " + method)
193 String loadFilePath = "/etc/mso/config.d/reources.json"
195 def jsonPayload = new File(loadFilePath).text
196 msoLogger.info("jsonPayload: " + jsonPayload)
198 String resourcesProperties = jsonUtil.prettyJson(jsonPayload.toString())
199 msoLogger.info("resourcesProperties: " + resourcesProperties)
201 String createResourceSort = jsonUtil.getJsonValue(resourcesProperties, "CreateResourceSort")
202 msoLogger.info("createResourceSort: " + createResourceSort)
203 execution.setVariable("createResourceSort", createResourceSort)
205 String deleteResourceSort = jsonUtil.getJsonValue(resourcesProperties, "DeleteResourceSort")
206 msoLogger.info("deleteResourceSort: " + deleteResourceSort)
207 execution.setVariable("deleteResourceSort", deleteResourceSort)
210 String resourceControllerType = jsonUtil.getJsonValue(resourcesProperties, "ResourceControllerType")
211 msoLogger.info("resourceControllerType: " + resourceControllerType)
212 execution.setVariable("resourceControllerType", resourceControllerType)
215 }catch(Exception ex){
216 // try error in method block
217 String exceptionMessage = "Bpmn error encountered in " + method + " - " + ex.getMessage()
218 msoLogger.debug(exceptionMessage)
219 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
221 msoLogger.info("Exited " + method)
223 private void sortDeleteResource(DelegateExecution execution) {
224 def method = getClass().getSimpleName() + '.sortDeleteResource(' +'execution=' + execution.getId() +')'
225 def isDebugEnabled = execution.getVariable("isDebugEnabled")
226 msoLogger.info("Entered " + method)
227 String deleteResourceSortDef = """[
229 "resourceType":"GRE_SAR"
232 "resourceType":"VPN_SAR"
235 "resourceType":"APN_AAR"
238 "resourceType":"GRE_AAR"
241 "resourceType":"Overlay"
244 "resourceType":"Underlay"
247 "resourceType":"vIMS"
250 "resourceType":"vCPE"
256 "resourceType":"vEPC"
263 loadResourcesProperties(execution)
264 String deleteResourceSort = execution.getVariable("deleteResourceSort")
265 if (isBlank(deleteResourceSort)) {
266 deleteResourceSort = deleteResourceSortDef;
269 List<String> sortResourceList = jsonUtil.StringArrayToList(execution, deleteResourceSort)
270 msoLogger.info("sortResourceList : " + sortResourceList)
272 JSONArray newResourceList = new JSONArray()
273 int resSortCount = sortResourceList.size()
275 for ( int currentResource = 0 ; currentResource < resSortCount ; currentResource++ ) {
276 String currentSortResource = sortResourceList[currentResource]
277 String sortResourceType = jsonUtil.getJsonValue(currentSortResource, "resourceType")
278 List<String> resourceList = execution.getVariable(Prefix+"resourceList")
280 for (String resource : resourceList) {
281 msoLogger.info("resource : " + resource)
282 String resourceType = jsonUtil.getJsonValue(resource, "resourceType")
284 if (StringUtils.containsIgnoreCase(resourceType, sortResourceType)) {
285 JSONObject jsonObj = new JSONObject(resource)
286 newResourceList.put(jsonObj)
288 msoLogger.info("Get next sort type " )
292 String newResourceStr = newResourceList.toString()
293 List<String> newResourceListStr = jsonUtil.StringArrayToList(execution, newResourceStr)
295 execution.setVariable(Prefix+"resourceList", newResourceListStr)
296 msoLogger.info("newResourceList : " + newResourceListStr)
298 }catch(Exception ex){
299 // try error in method block
300 String exceptionMessage = "Bpmn error encountered in " + method + " - " + ex.getMessage()
301 msoLogger.debug(exceptionMessage)
302 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
304 msoLogger.info("Exited " + method)
307 public void prepareServiceDeleteResource(DelegateExecution execution) {
308 def method = getClass().getSimpleName() + '.prepareServiceDeleteResource(' +'execution=' + execution.getId() +')'
309 msoLogger.info("Entered " + method)
313 String serviceInstanceId = execution.getVariable("serviceInstanceId")
316 execution.setVariable(Prefix+"resourceList", "")
317 execution.setVariable(Prefix+"resourceCount", 0)
318 execution.setVariable(Prefix+"nextResource", 0)
319 execution.setVariable(Prefix+"resourceFinish", true)
321 String aaiJsonRecord = execution.getVariable("serviceInstance");
322 msoLogger.info("serviceInstanceAaiRecord: " +aaiJsonRecord)
324 msoLogger.info("aaiJsonRecord: " +aaiJsonRecord)
325 def serviceInstanceName = jsonUtil.getJsonValue(aaiJsonRecord, "service-instance.service-instance-name")
326 execution.setVariable("serviceInstanceName",serviceInstanceName)
328 def serviceType = jsonUtil.getJsonValue(aaiJsonRecord, "service-instance.service-type")
329 execution.setVariable("serviceType",serviceType)
332 String relationshipList = jsonUtil.getJsonValue(aaiJsonRecord, "service-instance.relationship-list")
333 msoLogger.info("relationship-list:" + relationshipList)
334 if (! isBlank(relationshipList)){
335 msoLogger.info("relationship-list exists" )
336 String relationShip = jsonUtil.getJsonValue(relationshipList, "relationship")
337 msoLogger.info("relationship: " + relationShip)
338 JSONArray allResources = new JSONArray()
339 JSONArray serviceResources = new JSONArray()
340 JSONArray networkResources = new JSONArray()
341 JSONArray allottedResources = new JSONArray()
344 if (! isBlank(relationShip)){
345 JSONArray jsonArray = new JSONArray();
346 if (relationShip.startsWith("{") && relationShip.endsWith("}")) {
347 JSONObject jsonObject = new JSONObject(relationShip);
348 jsonArray.put(jsonObject);
349 } else if (relationShip.startsWith("[") && relationShip.endsWith("]")) {
350 jsonArray = new JSONArray(relationShip);
352 msoLogger.info("The relationShip fomart is error" )
355 List<String> relationList = jsonUtil.StringArrayToList(execution, jsonArray.toString())
357 msoLogger.info("relationList: " + relationList)
359 int relationNum =relationList.size()
360 msoLogger.info("**************relationList size: " + relationNum)
362 for ( int currentRelation = 0 ; currentRelation < relationNum ; currentRelation++ ) {
363 msoLogger.info("current Relation num: " + currentRelation)
364 String relation = relationList[currentRelation]
365 msoLogger.info("relation: " + relation)
367 String relatedTo = jsonUtil.getJsonValue(relation, "related-to")
368 msoLogger.info("relatedTo: " + relatedTo)
370 String relatedLink = jsonUtil.getJsonValue(relation, "related-link")
371 msoLogger.info("relatedLink: " + relatedLink)
373 if (StringUtils.equalsIgnoreCase(relatedTo, "allotted-resource")) {
374 msoLogger.info("allotted-resource exists ")
376 Optional<AllottedResource> aaiArRsp = getAaiAr(execution, relatedLink)
377 msoLogger.info("aaiArRsp: " + aaiArRsp)
378 if (aaiArRsp.isPresent()) {
380 JSONObject jObject = new JSONObject()
381 jObject.put("resourceType", aaiArRsp.get().getType())
382 jObject.put("resourceInstanceId", aaiArRsp.get().getId())
383 jObject.put("resourceRole", aaiArRsp.get().getRole())
384 jObject.put("resourceVersion", aaiArRsp.get().getResourceVersion())
386 allResources.put(jObject)
387 msoLogger.info("allResources: " + allResources)
388 allottedResources.put(jObject)
389 msoLogger.info("allottedResources: " + allottedResources)
392 else if (StringUtils.equalsIgnoreCase(relatedTo, "service-instance")){
393 msoLogger.info("service-instance exists ")
394 JSONObject jObject = new JSONObject()
397 String rsDataStr = jsonUtil.getJsonValue(relation, "relationship-data")
398 msoLogger.info("rsDataStr: " + rsDataStr)
399 List<String> rsDataList = jsonUtil.StringArrayToList(execution, rsDataStr)
400 msoLogger.info("rsDataList: " + rsDataList)
401 for(String rsData : rsDataList){
402 msoLogger.info("rsData: " + rsData)
403 def eKey = jsonUtil.getJsonValue(rsData, "relationship-key")
404 def eValue = jsonUtil.getJsonValue(rsData, "relationship-value")
405 if(eKey.equals("service-instance.service-instance-id")){
406 jObject.put("resourceInstanceId", eValue)
408 if(eKey.equals("service-subscription.service-type")){
409 jObject.put("resourceType", eValue)
413 //related-to-property
414 String rPropertyStr = jsonUtil.getJsonValue(relation, "related-to-property")
415 msoLogger.info("related-to-property: " + rPropertyStr)
416 if (rPropertyStr instanceof JSONArray){
417 List<String> rPropertyList = jsonUtil.StringArrayToList(execution, rPropertyStr)
418 for (String rProperty : rPropertyList) {
419 msoLogger.info("rProperty: " + rProperty)
420 def eKey = jsonUtil.getJsonValue(rProperty, "property-key")
421 def eValue = jsonUtil.getJsonValue(rProperty, "property-value")
422 if(eKey.equals("service-instance.service-instance-name")){
423 jObject.put("resourceName", eValue)
428 String rProperty = rPropertyStr
429 msoLogger.info("rProperty: " + rProperty)
430 def eKey = jsonUtil.getJsonValue(rProperty, "property-key")
431 def eValue = jsonUtil.getJsonValue(rProperty, "property-value")
432 if (eKey.equals("service-instance.service-instance-name")) {
433 jObject.put("resourceName", eValue)
437 allResources.put(jObject)
438 msoLogger.info("allResources: " + allResources)
440 serviceResources.put(jObject)
441 msoLogger.info("serviceResources: " + serviceResources)
443 else if (StringUtils.equalsIgnoreCase(relatedTo, "configuration")) {
444 msoLogger.info("configuration ")
445 JSONObject jObject = new JSONObject()
448 String rsDataStr = jsonUtil.getJsonValue(relation, "relationship-data")
449 msoLogger.info("rsDataStr: " + rsDataStr)
450 List<String> rsDataList = jsonUtil.StringArrayToList(execution, rsDataStr)
451 msoLogger.info("rsDataList: " + rsDataList)
452 for (String rsData : rsDataList) {
453 msoLogger.info("rsData: " + rsData)
454 def eKey = jsonUtil.getJsonValue(rsData, "relationship-key")
455 def eValue = jsonUtil.getJsonValue(rsData, "relationship-value")
456 if(eKey.equals("configuration.configuration-id")){
457 jObject.put("resourceInstanceId", eValue)
462 //related-to-property
463 String rPropertyStr = jsonUtil.getJsonValue(relation, "related-to-property")
464 msoLogger.info("related-to-property: " + rPropertyStr)
465 if (rPropertyStr instanceof JSONArray){
466 List<String> rPropertyList = jsonUtil.StringArrayToList(execution, rPropertyStr)
467 for(String rProperty : rPropertyList){
468 msoLogger.info("rProperty: " + rProperty)
469 def eKey = jsonUtil.getJsonValue(rProperty, "property-key")
470 def eValue = jsonUtil.getJsonValue(rProperty, "property-value")
471 if(eKey.equals("configuration.configuration-type")){
472 jObject.put("resourceType", eValue)
477 String rProperty = rPropertyStr
478 msoLogger.info("rProperty: " + rProperty)
479 def eKey = jsonUtil.getJsonValue(rProperty, "property-key")
480 def eValue = jsonUtil.getJsonValue(rProperty, "property-value")
481 if(eKey.equals("configuration.configuration-type")){
482 jObject.put("resourceType", eValue)
485 allResources.put(jObject)
486 msoLogger.info("allResources: " + allResources)
488 networkResources.put(jObject)
489 msoLogger.info("networkResources: " + networkResources)
491 msoLogger.info("Get Next releation resource " )
494 msoLogger.info("Get releation finished. " )
497 execution.setVariable("serviceRelationShip", allResources.toString())
498 msoLogger.info("allResources: " + allResources.toString())
499 String serviceRelationShip = execution.getVariable("serviceRelationShip")
500 msoLogger.info("serviceRelationShip: " + serviceRelationShip)
501 if ((! isBlank(serviceRelationShip)) && (! serviceRelationShip.isEmpty())) {
503 List<String> relationShipList = jsonUtil.StringArrayToList(execution, serviceRelationShip)
504 msoLogger.info("relationShipList: " + relationShipList)
505 execution.setVariable(Prefix+"resourceList", relationShipList)
507 int resourceCount = relationShipList.size()
508 msoLogger.info("resourceCount: " + resourceCount)
509 execution.setVariable(Prefix+"resourceCount",resourceCount )
512 execution.setVariable(Prefix+"nextResource", resourceNum)
513 msoLogger.info("start sort delete resource: ")
514 sortDeleteResource(execution)
517 if (resourceNum < resourceCount) {
518 execution.setVariable(Prefix+"resourceFinish", false)
521 execution.setVariable(Prefix+"resourceFinish", true)
523 msoLogger.info("Resource list set end : " + resourceCount)
526 execution.setVariable("serviceResources", serviceResources.toString())
527 msoLogger.info("serviceResources: " + serviceResources)
528 String serviceResourcesShip = execution.getVariable("serviceResources")
529 msoLogger.info("serviceResourcesShip: " + serviceResourcesShip)
531 if ((! isBlank(serviceResourcesShip)) && (! serviceResourcesShip.isEmpty())) {
532 List<String> serviceResourcesList = jsonUtil.StringArrayToList(execution, serviceResourcesShip)
533 msoLogger.info("serviceResourcesList: " + serviceResourcesList)
534 execution.setVariable(Prefix+"serviceResourceList", serviceResourcesList)
535 execution.setVariable(Prefix+"serviceResourceCount", serviceResourcesList.size())
536 execution.setVariable(Prefix+"nextServiceResource", 0)
537 msoLogger.info("Service Resource list set end : " + serviceResourcesList.size())
541 execution.setVariable("allottedResources", allottedResources.toString())
542 msoLogger.info("allottedResources: " + allottedResources)
543 String allottedResourcesShip = execution.getVariable("allottedResources")
544 msoLogger.info("allottedResourcesShip: " + allottedResourcesShip)
545 if ((! isBlank(allottedResourcesShip)) && (! allottedResourcesShip.isEmpty())) {
546 List<String> allottedResourcesList = jsonUtil.StringArrayToList(execution, allottedResourcesShip)
547 msoLogger.info("allottedResourcesList: " + allottedResourcesList)
548 execution.setVariable(Prefix+"allottedResourcesList", allottedResourcesList)
549 execution.setVariable(Prefix+"allottedResourcesListCount", allottedResourcesList.size())
550 execution.setVariable(Prefix+"nextAllottedResourcesList", 0)
551 msoLogger.info("Allotted Resource list set end : " + allottedResourcesList.size())
554 execution.setVariable("networkResources", networkResources.toString())
555 msoLogger.info("networkResources: " + networkResources)
556 String networkResourcesShip = execution.getVariable("networkResources")
557 msoLogger.info("networkResourcesShip: " + networkResourcesShip)
558 if ((! isBlank(networkResourcesShip)) && (! networkResourcesShip.isEmpty())) {
559 List<String> networkResourcesList = jsonUtil.StringArrayToList(execution, networkResourcesShip)
560 msoLogger.info("networkResourcesList: " + networkResourcesList)
561 execution.setVariable(Prefix+"networkResourcesList", networkResourcesList)
562 execution.setVariable(Prefix+"networkResourcesListCount", networkResourcesList.size())
563 execution.setVariable(Prefix+"nextNetworkResourcesList", 0)
564 msoLogger.info("Network Resource list set end : " + networkResourcesList.size())
568 } catch (BpmnError e){
570 } catch (Exception ex) {
571 String exceptionMessage = "Bpmn error encountered in DeleteMobileAPNCustService flow. prepareServiceDeleteResource() - " + ex.getMessage()
572 msoLogger.debug(exceptionMessage)
573 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
575 msoLogger.info("Exited " + method)
578 private Optional<AllottedResource> getAaiAr(DelegateExecution execution, String relink) {
579 def method = getClass().getSimpleName() + '.getAaiAr(' +'execution=' + execution.getId() +')'
580 msoLogger.info("Entered " + method)
581 AAIResourceUri uri = AAIUriFactory.createResourceFromExistingURI(AAIObjectType.ALLOTTED_RESOURCE, UriBuilder.fromPath(relink).build())
582 return getAAIClient().get(AllottedResource.class,uri)
585 * prepare Decompose next resource to create request
587 public void preProcessDecomposeNextResource(DelegateExecution execution){
588 def method = getClass().getSimpleName() + '.getAaiAr(' +'execution=' + execution.getId() +')'
589 msoLogger.info("Entered " + method)
590 msoLogger.trace("STARTED preProcessDecomposeNextResource Process ")
592 int resourceNum = execution.getVariable(Prefix+"nextServiceResource")
593 List<String> serviceResourceList = execution.getVariable(Prefix+"serviceResourceList")
594 msoLogger.info("Service Resource List : " + serviceResourceList)
596 String serviceResource = serviceResourceList[resourceNum]
597 execution.setVariable(Prefix+"serviceResource", serviceResource)
598 msoLogger.info("Current Service Resource : " + serviceResource)
600 String resourceType = jsonUtil.getJsonValue(serviceResource, "resourceType")
601 execution.setVariable("resourceType", resourceType)
602 msoLogger.info("resourceType : " + resourceType)
604 String resourceInstanceId = jsonUtil.getJsonValue(serviceResource, "resourceInstanceId")
605 execution.setVariable("resourceInstanceId", resourceInstanceId)
606 msoLogger.info("resourceInstanceId : " + resourceInstanceId)
608 String resourceRole = jsonUtil.getJsonValue(serviceResource, "resourceRole")
609 execution.setVariable("resourceRole", resourceRole)
610 msoLogger.info("resourceRole : " + resourceRole)
612 String resourceVersion = jsonUtil.getJsonValue(serviceResource, "resourceVersion")
613 execution.setVariable("resourceVersion", resourceVersion)
614 msoLogger.info("resourceVersion : " + resourceVersion)
616 String resourceName = jsonUtil.getJsonValue(serviceResource, "resourceName")
617 if (isBlank(resourceName)){
618 resourceName = resourceInstanceId
620 execution.setVariable(Prefix+"resourceName", resourceName)
621 msoLogger.info("resource Name : " + resourceName)
624 execution.setVariable(Prefix+"nextServiceResource", resourceNum + 1)
626 int serviceResourceCount = execution.getVariable(Prefix+"serviceResourceCount")
627 if (serviceResourceCount >0 ){
628 int progress = (resourceNum*100) / serviceResourceCount
629 execution.setVariable("progress", progress.toString() )
631 execution.setVariable("operationStatus", resourceName )
634 // try error in method block
635 String exceptionMessage = "Bpmn error encountered in CreateMobileAPNCustService flow. Unexpected Error from method preProcessDecomposeNextResource() - " + ex.getMessage()
636 msoLogger.debug(exceptionMessage)
637 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
639 msoLogger.info("Exited " + method)
642 * post Decompose next resource to create request
644 public void postProcessDecomposeNextResource(DelegateExecution execution){
645 def method = getClass().getSimpleName() + '.postProcessDecomposeNextResource(' +'execution=' + execution.getId() +')'
646 msoLogger.info("Entered " + method)
647 msoLogger.trace("STARTED postProcessDecomposeNextResource Process ")
649 String resourceName = execution.getVariable(Prefix+"resourceName")
650 int resourceNum = execution.getVariable(Prefix+"nextServiceResource")
651 msoLogger.debug("Current Resource count:"+ execution.getVariable(Prefix+"nextServiceResource"))
653 int resourceCount = execution.getVariable(Prefix+"serviceResourceCount")
654 msoLogger.debug("Total Resource count:"+ execution.getVariable(Prefix+"serviceResourceCount"))
656 if (resourceNum < resourceCount) {
657 execution.setVariable(Prefix+"resourceFinish", false)
660 execution.setVariable(Prefix+"resourceFinish", true)
663 msoLogger.debug("Resource Finished:"+ execution.getVariable(Prefix+"resourceFinish"))
665 if (resourceCount >0 ){
666 int progress = (resourceNum*100) / resourceCount
668 execution.setVariable("progress", progress.toString() )
669 msoLogger.trace(":"+ execution.getVariable(""))
671 execution.setVariable("operationStatus", resourceName )
675 // try error in method block
676 String exceptionMessage = "Bpmn error encountered in CreateMobileAPNCustService flow. Unexpected Error from method postProcessDecomposeNextResource() - " + ex.getMessage()
677 msoLogger.debug(exceptionMessage)
678 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
680 msoLogger.info("Exited " + method)
683 * prepare post Unkown Resource Type
685 public void postOtherControllerType(DelegateExecution execution){
686 def method = getClass().getSimpleName() + '.postOtherControllerType(' +'execution=' + execution.getId() +')'
687 def isDebugEnabled = execution.getVariable("isDebugEnabled")
688 msoLogger.info("Entered " + method)
692 String resourceName = execution.getVariable(Prefix+"resourceName")
693 String resourceType = execution.getVariable(Prefix+"resourceType")
694 String controllerType = execution.getVariable("controllerType")
696 String msg = "Resource name: "+ resourceName + " resource Type: " + resourceType+ " controller Type: " + controllerType + " can not be processed n the workflow"
700 // try error in method block
701 String exceptionMessage = "Bpmn error encountered in DoCreateMobileAPNServiceInstance flow. Unexpected Error from method postOtherControllerType() - " + ex.getMessage()
702 msoLogger.debug(exceptionMessage)
703 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
705 msoLogger.info("Exited " + method)
709 * prepare delete parameters
711 public void preSDNCResourceDelete(execution, resourceName){
712 // we use resource instance ids for delete flow as resourceTemplateUUIDs
714 def method = getClass().getSimpleName() + '.preSDNCResourceDelete(' +'execution=' + execution.getId() +')'
715 msoLogger.info("Entered " + method)
717 msoLogger.trace("STARTED preSDNCResourceDelete Process ")
718 String networkResources = execution.getVariable("networkResources")
721 execution.setVariable("foundResource", false)
722 if (networkResources != null) {
723 def jsonSlurper = new JsonSlurper()
724 List relationShipList = jsonSlurper.parseText(networkResources)
725 relationShipList.each {
726 if(StringUtils.containsIgnoreCase(it.resourceType, resourceName)) {
727 String resourceInstanceUUID = it.resourceInstanceId
728 String resourceTemplateUUID = it.resourceInstanceId
729 execution.setVariable("resourceTemplateId", resourceTemplateUUID)
730 execution.setVariable("resourceInstanceId", resourceInstanceUUID)
731 execution.setVariable("resourceType", resourceName)
732 execution.setVariable("foundResource", true)
733 msoLogger.info("Delete Resource Info resourceTemplate Id :" + resourceTemplateUUID + " resourceInstanceId: " + resourceInstanceUUID + " resourceType: " + resourceName)
737 msoLogger.info("Exited " + method)
739 public void preProcessSDNCDelete (DelegateExecution execution) {
740 def method = getClass().getSimpleName() + '.preProcessSDNCDelete(' +'execution=' + execution.getId() +')'
741 msoLogger.info("Entered " + method)
742 msoLogger.trace("preProcessSDNCDelete ")
746 def serviceInstanceId = execution.getVariable("serviceInstanceId")
747 def serviceInstanceName = execution.getVariable("serviceInstanceName")
748 def callbackURL = execution.getVariable("sdncCallbackUrl")
749 def requestId = execution.getVariable("msoRequestId")
750 def serviceId = execution.getVariable("productFamilyId")
751 def subscriptionServiceType = execution.getVariable("subscriptionServiceType")
752 def globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId
754 String serviceModelInfo = execution.getVariable("serviceModelInfo")
755 def modelInvariantUuid = ""
756 def modelVersion = ""
759 if (!isBlank(serviceModelInfo))
761 modelInvariantUuid = jsonUtil.getJsonValue(serviceModelInfo, "modelInvariantUuid")
762 modelVersion = jsonUtil.getJsonValue(serviceModelInfo, "modelVersion")
763 modelUuid = jsonUtil.getJsonValue(serviceModelInfo, "modelUuid")
764 modelName = jsonUtil.getJsonValue(serviceModelInfo, "modelName")
766 if (modelInvariantUuid == null) {
767 modelInvariantUuid = ""
769 if (modelVersion == null) {
772 if (modelUuid == null) {
775 if (modelName == null) {
779 if (serviceInstanceName == null) {
780 serviceInstanceName = ""
782 if (serviceId == null) {
786 def siParamsXml = execution.getVariable("siParamsXml")
787 def serviceType = execution.getVariable("serviceType")
788 if (serviceType == null)
793 def sdncRequestId = UUID.randomUUID().toString()
796 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
797 xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
798 xmlns:sdncadapter="http://org.onap/workflow/sdnc/adapter/schema/v1">
799 <sdncadapter:RequestHeader>
800 <sdncadapter:RequestId>${MsoUtils.xmlEscape(sdncRequestId)}</sdncadapter:RequestId>
801 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(serviceInstanceId)}</sdncadapter:SvcInstanceId>
802 <sdncadapter:SvcAction>delete</sdncadapter:SvcAction>
803 <sdncadapter:SvcOperation>service-topology-operation</sdncadapter:SvcOperation>
804 <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackURL)}</sdncadapter:CallbackUrl>
805 <sdncadapter:MsoAction>${MsoUtils.xmlEscape(serviceType)}</sdncadapter:MsoAction>
806 </sdncadapter:RequestHeader>
807 <sdncadapterworkflow:SDNCRequestData>
808 <request-information>
809 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
814 <request-action>DeleteServiceInstance</request-action>
815 </request-information>
816 <service-information>
817 <service-id>${MsoUtils.xmlEscape(serviceId)}</service-id>
818 <subscription-service-type>${MsoUtils.xmlEscape(subscriptionServiceType)}</subscription-service-type>
819 <onap-model-information>
820 <model-invariant-uuid>${MsoUtils.xmlEscape(modelInvariantUuid)}</model-invariant-uuid>
821 <model-uuid>${MsoUtils.xmlEscape(modelUuid)}</model-uuid>
822 <model-version>${MsoUtils.xmlEscape(modelVersion)}</model-version>
823 <model-name>${MsoUtils.xmlEscape(modelName)}</model-name>
824 </onap-model-information>
825 <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceId)}</service-instance-id>
827 <global-customer-id>${MsoUtils.xmlEscape(globalSubscriberId)}</global-customer-id>
828 </service-information>
829 <service-request-input>
830 <service-instance-name>${MsoUtils.xmlEscape(serviceInstanceName)}</service-instance-name>
832 </service-request-input>
833 </sdncadapterworkflow:SDNCRequestData>
834 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
836 sdncDelete = utils.formatXml(sdncDelete)
837 def sdncRequestId2 = UUID.randomUUID().toString()
838 String sdncDeactivate = sdncDelete.replace(">delete<", ">deactivate<").replace(">${sdncRequestId}<", ">${sdncRequestId2}<")
839 execution.setVariable("sdncDelete", sdncDelete)
840 execution.setVariable("sdncDeactivate", sdncDeactivate)
841 msoLogger.info("sdncDeactivate:\n" + sdncDeactivate)
842 msoLogger.info("sdncDelete:\n" + sdncDelete)
844 } catch (BpmnError e) {
846 } catch(Exception ex) {
847 msg = "Exception in preProcessSDNCDelete. " + ex.getMessage()
849 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "Exception Occured in preProcessSDNCDelete.\n" + ex.getMessage())
851 msoLogger.info("Exited " + method)
854 public void postProcessSDNCDelete(DelegateExecution execution, String response, String action) {
856 def method = getClass().getSimpleName() + '.postProcessSDNCDelete(' +'execution=' + execution.getId() +')'
857 msoLogger.info("Entered " + method)
858 msoLogger.trace("postProcessSDNC " + action + " ")
862 WorkflowException workflowException = execution.getVariable("WorkflowException")
863 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
864 msoLogger.info("SDNCResponse: " + response)
865 msoLogger.info("workflowException: " + workflowException)
867 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
868 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
869 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == "true"){
870 msoLogger.info("Good response from SDNC Adapter for service-instance " + action + "response:\n" + response)
873 msg = "Bad Response from SDNC Adapter for service-instance " + action
875 exceptionUtil.buildAndThrowWorkflowException(execution, 3500, msg)
877 } catch (BpmnError e) {
879 } catch(Exception ex) {
880 msg = "Exception in postProcessSDNC " + action + " Exception:" + ex.getMessage()
882 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
884 msoLogger.info("Exited " + method)
888 * Init the service Operation Status
890 public void preUpdateServiceOperationStatus(DelegateExecution execution){
891 def method = getClass().getSimpleName() + '.preUpdateServiceOperationStatus(' +'execution=' + execution.getId() +')'
892 msoLogger.info("Entered " + method)
895 String serviceId = execution.getVariable("serviceInstanceId")
896 String operationId = execution.getVariable("operationId")
897 String serviceName = execution.getVariable("serviceInstanceName")
898 String operationType = "DELETE"
900 String result = "processing"
901 String progress = execution.getVariable("progress")
902 msoLogger.info("progress: " + progress )
903 if ("100".equalsIgnoreCase(progress))
908 String operationContent = "Prepare service delete: " + execution.getVariable("operationStatus")
909 msoLogger.info("Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId)
910 serviceId = UriUtils.encode(serviceId,"UTF-8")
911 execution.setVariable("serviceInstanceId", serviceId)
912 execution.setVariable("operationId", operationId)
913 execution.setVariable("operationType", operationType)
915 def dbAdapterEndpoint = UrnPropertiesReader.getVariable("mso.adapters.openecomp.db.endpoint", execution)
916 execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
917 msoLogger.info("DB Adapter Endpoint is: " + dbAdapterEndpoint)
920 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
921 xmlns:ns="http://org.onap.so/requestsdb">
924 <ns:updateServiceOperationStatus xmlns:ns="http://org.onap.so/requestsdb">
925 <serviceId>${MsoUtils.xmlEscape(serviceId)}</serviceId>
926 <operationId>${MsoUtils.xmlEscape(operationId)}</operationId>
927 <serviceName>${MsoUtils.xmlEscape(serviceName)}</serviceName>
928 <operationType>${MsoUtils.xmlEscape(operationType)}</operationType>
929 <userId>${MsoUtils.xmlEscape(userId)}</userId>
930 <result>${MsoUtils.xmlEscape(result)}</result>
931 <operationContent>${MsoUtils.xmlEscape(operationContent)}</operationContent>
932 <progress>${MsoUtils.xmlEscape(progress)}</progress>
933 <reason>${MsoUtils.xmlEscape(reason)}</reason>
934 </ns:updateServiceOperationStatus>
936 </soapenv:Envelope>"""
938 payload = utils.formatXml(payload)
939 execution.setVariable("CVFMI_updateServiceOperStatusRequest", payload)
940 msoLogger.info("Outgoing preUpdateServiceOperationStatus: \n" + payload)
944 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occured Processing preUpdateServiceOperationStatus.", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e);
945 execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during preUpdateServiceOperationStatus Method:\n" + e.getMessage())
947 msoLogger.trace("COMPLETED preUpdateServiceOperationStatus Process ")
948 msoLogger.info("Exited " + method)
951 public void preInitResourcesOperStatus(DelegateExecution execution){
952 def method = getClass().getSimpleName() + '.preInitResourcesOperStatus(' +'execution=' + execution.getId() +')'
953 msoLogger.info("Entered " + method)
955 msoLogger.trace("STARTED preInitResourcesOperStatus Process ")
958 String serviceId = execution.getVariable("serviceInstanceId")
959 String operationId = execution.getVariable("operationId")
960 String operationType = "DELETE"
961 String resourceTemplateUUIDs = ""
962 String result = "processing"
963 String progress = "0"
965 String operationContent = "Prepare service delete"
966 msoLogger.info("Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId + " operationType:" + operationType)
967 serviceId = UriUtils.encode(serviceId,"UTF-8")
968 execution.setVariable("serviceInstanceId", serviceId)
969 execution.setVariable("operationId", operationId)
970 execution.setVariable("operationType", operationType)
972 String serviceRelationShip = execution.getVariable("serviceRelationShip")
973 msoLogger.info("serviceRelationShip: " + serviceRelationShip)
974 if (! isBlank(serviceRelationShip)) {
975 def jsonSlurper = new JsonSlurper()
976 def jsonOutput = new JsonOutput()
977 List relationShipList = jsonSlurper.parseText(serviceRelationShip)
979 if (relationShipList != null) {
980 relationShipList.each {
981 resourceTemplateUUIDs = resourceTemplateUUIDs + it.resourceInstanceId + ":"
986 def dbAdapterEndpoint = UrnPropertiesReader.getVariable("mso.adapters.openecomp.db.endpoint", execution)
987 execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
988 msoLogger.info("DB Adapter Endpoint is: " + dbAdapterEndpoint)
991 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
992 xmlns:ns="http://org.onap.so/requestsdb">
995 <ns:initResourceOperationStatus xmlns:ns="http://org.onap.so/requestsdb">
996 <serviceId>${MsoUtils.xmlEscape(serviceId)}</serviceId>
997 <operationId>${MsoUtils.xmlEscape(operationId)}</operationId>
998 <operationType>${MsoUtils.xmlEscape(operationType)}</operationType>
999 <resourceTemplateUUIDs>${MsoUtils.xmlEscape(resourceTemplateUUIDs)}</resourceTemplateUUIDs>
1000 </ns:initResourceOperationStatus>
1002 </soapenv:Envelope>"""
1004 payload = utils.formatXml(payload)
1005 execution.setVariable("CVFMI_initResOperStatusRequest", payload)
1006 msoLogger.info("Outgoing initResourceOperationStatus: \n" + payload)
1007 msoLogger.debug("DoCustomDeleteE2EServiceInstanceV2 Outgoing initResourceOperationStatus Request: " + payload)
1009 }catch (BpmnError e) {
1011 } catch (Exception ex) {
1012 msg = "Exception in DoCustomDeleteE2EServiceInstanceV2.preInitResourcesOperStatus. " + ex.getMessage()
1014 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
1016 msoLogger.info("Exited " + method)
1022 * prepare delete parameters
1024 public void preProcessVFCResourceDelete(execution){
1025 // we use resource instance ids for delete flow as resourceTemplateUUIDs
1027 def method = getClass().getSimpleName() + '.preProcessVFCResourceDelete(' +'execution=' + execution.getId() +')'
1028 msoLogger.info("Entered " + method)
1030 msoLogger.trace("STARTED preProcessVFCResourceDelete Process ")
1032 String serviceResource = execution.getVariable("serviceResource")
1033 msoLogger.info("serviceResource : " + serviceResource)
1035 String resourceInstanceId = execution.getVariable("resourceInstanceId")
1036 msoLogger.info("resourceInstanceId : " + resourceInstanceId)
1038 execution.setVariable("resourceTemplateId", resourceInstanceId)
1039 msoLogger.info("resourceTemplateId : " + resourceInstanceId)
1041 String resourceType = execution.getVariable("resourceType")
1042 msoLogger.info("resourceType : " + resourceType)
1045 String resourceName = execution.getVariable(Prefix+"resourceName")
1046 if (isBlank(resourceName)){
1047 resourceName = resourceInstanceId
1049 execution.setVariable("resourceName", resourceName)
1050 msoLogger.info("resource Name : " + resourceName)
1052 msoLogger.info("Delete Resource Info: resourceInstanceId :" + resourceInstanceId + " resourceTemplateId: " + resourceInstanceId + " resourceType: " + resourceType)
1053 }catch (BpmnError e) {
1055 } catch (Exception ex) {
1056 msg = "Exception in DoDeleteE2EServiceInstance.preProcessVFCResourceDelete. " + ex.getMessage()
1058 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
1060 msoLogger.info("Exited " + method)
1063 public void postProcessVFCDelete(DelegateExecution execution, String response, String action) {
1064 def method = getClass().getSimpleName() + '.postProcessVFCDelete(' +'execution=' + execution.getId() +')'
1065 msoLogger.info("Entered " + method)
1067 msoLogger.trace("STARTED postProcessVFCDelete Process ")
1070 }catch (BpmnError e) {
1072 } catch (Exception ex) {
1073 msg = "Exception in DoDeleteE2EServiceInstance.postProcessVFCDelete. " + ex.getMessage()
1075 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
1077 msoLogger.info("Exited " + method)