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.logger.MessageEnum
39 import org.onap.so.logger.MsoLogger
41 import org.springframework.web.util.UriUtils;
42 import org.onap.so.client.aai.AAIResourcesClient
43 import org.onap.so.client.aai.AAIObjectType
44 import org.onap.so.client.aai.entities.AAIResultWrapper
45 import org.onap.so.client.aai.entities.uri.AAIResourceUri
46 import org.onap.so.client.aai.entities.uri.AAIUriFactory
47 import org.json.JSONObject
48 import javax.ws.rs.NotFoundException
54 * This groovy class supports the <class>DoDeleteE2EServiceInstance.bpmn</class> process.
57 * @param - msoRequestId
58 * @param - globalSubscriberId - O
59 * @param - subscriptionServiceType - O
60 * @param - serviceInstanceId
61 * @param - serviceInstanceName - O
62 * @param - serviceInputParams (should contain aic_zone for serviceTypes TRANSPORT,ATM)
63 * @param - sdncVersion
64 * @param - failNotFound - TODO
65 * @param - serviceInputParams - TODO
68 * @param - WorkflowException
72 public class DoCustomDeleteE2EServiceInstanceV2 extends AbstractServiceTaskProcessor {
73 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoCustomDeleteE2EServiceInstanceV2.class);
76 String Prefix="DDELSI_"
77 private static final String DebugFlag = "isDebugEnabled"
78 ExceptionUtil exceptionUtil = new ExceptionUtil()
79 JsonUtils jsonUtil = new JsonUtils()
81 public void preProcessRequest (DelegateExecution execution) {
83 def method = getClass().getSimpleName() + '.buildAPPCRequest(' +'execution=' + execution.getId() +')'
84 msoLogger.info("Entered " + method)
85 msoLogger.trace("preProcessRequest ")
89 String requestId = execution.getVariable("msoRequestId")
90 execution.setVariable("prefix",Prefix)
93 //requestDetails.subscriberInfo. for AAI GET & PUT & SDNC assignToplology
94 String globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId
95 if (globalSubscriberId == null)
97 execution.setVariable("globalSubscriberId", "")
100 //requestDetails.requestParameters. for AAI PUT & SDNC assignTopology
101 String serviceType = execution.getVariable("serviceType")
102 if (serviceType == null)
104 execution.setVariable("serviceType", "")
107 //Generated in parent for AAI PUT
108 String serviceInstanceId = execution.getVariable("serviceInstanceId")
109 if (isBlank(serviceInstanceId)){
110 msg = "Input serviceInstanceId is null"
112 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
115 String sdncCallbackUrl = execution.getVariable('URN_mso_workflow_sdncadapter_callback')
116 if (isBlank(sdncCallbackUrl)) {
117 msg = "URN_mso_workflow_sdncadapter_callback is null"
119 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
121 execution.setVariable("sdncCallbackUrl", sdncCallbackUrl)
122 msoLogger.info("SDNC Callback URL: " + sdncCallbackUrl)
124 StringBuilder sbParams = new StringBuilder()
125 Map<String, String> paramsMap = execution.getVariable("serviceInputParams")
126 if (paramsMap != null)
128 sbParams.append("<service-input-parameters>")
129 for (Map.Entry<String, String> entry : paramsMap.entrySet()) {
131 String paramName = entry.getKey()
132 String paramValue = entry.getValue()
135 <name>${MsoUtils.xmlEscape(paramName)}</name>
136 <value>${MsoUtils.xmlEscape(paramValue)}</value>
139 sbParams.append(paramsXml)
141 sbParams.append("</service-input-parameters>")
143 String siParamsXml = sbParams.toString()
144 if (siParamsXml == null)
146 execution.setVariable("siParamsXml", siParamsXml)
147 execution.setVariable("operationStatus", "Waiting delete resource...")
148 execution.setVariable("progress", "0")
150 } catch (BpmnError e) {
152 } catch (Exception ex){
153 msg = "Exception in preProcessRequest " + ex.getMessage()
155 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
157 msoLogger.info("Exited " + method)
161 * Gets the service instance and its relationships from aai
165 public void getServiceInstance(DelegateExecution execution) {
167 String serviceInstanceId = execution.getVariable('serviceInstanceId')
168 String globalSubscriberId = execution.getVariable('globalSubscriberId')
169 String serviceType = execution.getVariable('serviceType')
171 AAIResourcesClient resourceClient = new AAIResourcesClient()
172 AAIResourceUri serviceInstanceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, globalSubscriberId, serviceType, serviceInstanceId)
173 AAIResultWrapper wrapper = resourceClient.get(serviceInstanceUri, NotFoundException.class)
174 String json = wrapper.getJson()
176 execution.setVariable("serviceInstance", json)
178 }catch(BpmnError e) {
180 }catch(NotFoundException e) {
181 msoLogger.info("SI not found in aai. Silent Success ")
182 }catch(Exception ex) {
183 String msg = "Internal Error in getServiceInstance: " + ex.getMessage()
184 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
188 private void loadResourcesProperties(DelegateExecution execution) {
189 def method = getClass().getSimpleName() + '.loadResourcesProperties(' +'execution=' + execution.getId() +')'
190 def isDebugEnabled = execution.getVariable("isDebugEnabled")
191 msoLogger.info("Entered " + method)
192 String loadFilePath = "/etc/mso/config.d/reources.json"
194 def jsonPayload = new File(loadFilePath).text
195 msoLogger.info("jsonPayload: " + jsonPayload)
197 String resourcesProperties = jsonUtil.prettyJson(jsonPayload.toString())
198 msoLogger.info("resourcesProperties: " + resourcesProperties)
200 String createResourceSort = jsonUtil.getJsonValue(resourcesProperties, "CreateResourceSort")
201 msoLogger.info("createResourceSort: " + createResourceSort)
202 execution.setVariable("createResourceSort", createResourceSort)
204 String deleteResourceSort = jsonUtil.getJsonValue(resourcesProperties, "DeleteResourceSort")
205 msoLogger.info("deleteResourceSort: " + deleteResourceSort)
206 execution.setVariable("deleteResourceSort", deleteResourceSort)
209 String resourceControllerType = jsonUtil.getJsonValue(resourcesProperties, "ResourceControllerType")
210 msoLogger.info("resourceControllerType: " + resourceControllerType)
211 execution.setVariable("resourceControllerType", resourceControllerType)
214 }catch(Exception ex){
215 // try error in method block
216 String exceptionMessage = "Bpmn error encountered in " + method + " - " + ex.getMessage()
217 msoLogger.debug(exceptionMessage)
218 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
220 msoLogger.info("Exited " + method)
222 private void sortDeleteResource(DelegateExecution execution) {
223 def method = getClass().getSimpleName() + '.sortDeleteResource(' +'execution=' + execution.getId() +')'
224 def isDebugEnabled = execution.getVariable("isDebugEnabled")
225 msoLogger.info("Entered " + method)
226 String deleteResourceSortDef = """[
228 "resourceType":"GRE_SAR"
231 "resourceType":"VPN_SAR"
234 "resourceType":"APN_AAR"
237 "resourceType":"GRE_AAR"
240 "resourceType":"Overlay"
243 "resourceType":"Underlay"
246 "resourceType":"vIMS"
249 "resourceType":"vCPE"
255 "resourceType":"vEPC"
262 loadResourcesProperties(execution)
263 String deleteResourceSort = execution.getVariable("deleteResourceSort")
264 if (isBlank(deleteResourceSort)) {
265 deleteResourceSort = deleteResourceSortDef;
268 List<String> sortResourceList = jsonUtil.StringArrayToList(execution, deleteResourceSort)
269 msoLogger.info("sortResourceList : " + sortResourceList)
271 JSONArray newResourceList = new JSONArray()
272 int resSortCount = sortResourceList.size()
274 for ( int currentResource = 0 ; currentResource < resSortCount ; currentResource++ ) {
275 String currentSortResource = sortResourceList[currentResource]
276 String sortResourceType = jsonUtil.getJsonValue(currentSortResource, "resourceType")
277 List<String> resourceList = execution.getVariable(Prefix+"resourceList")
279 for (String resource : resourceList) {
280 msoLogger.info("resource : " + resource)
281 String resourceType = jsonUtil.getJsonValue(resource, "resourceType")
283 if (StringUtils.containsIgnoreCase(resourceType, sortResourceType)) {
284 JSONObject jsonObj = new JSONObject(resource)
285 newResourceList.put(jsonObj)
287 msoLogger.info("Get next sort type " )
291 String newResourceStr = newResourceList.toString()
292 List<String> newResourceListStr = jsonUtil.StringArrayToList(execution, newResourceStr)
294 execution.setVariable(Prefix+"resourceList", newResourceListStr)
295 msoLogger.info("newResourceList : " + newResourceListStr)
297 }catch(Exception ex){
298 // try error in method block
299 String exceptionMessage = "Bpmn error encountered in " + method + " - " + ex.getMessage()
300 msoLogger.debug(exceptionMessage)
301 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
303 msoLogger.info("Exited " + method)
306 public void prepareServiceDeleteResource(DelegateExecution execution) {
307 def method = getClass().getSimpleName() + '.prepareServiceDeleteResource(' +'execution=' + execution.getId() +')'
308 msoLogger.info("Entered " + method)
312 String serviceInstanceId = execution.getVariable("serviceInstanceId")
315 execution.setVariable(Prefix+"resourceList", "")
316 execution.setVariable(Prefix+"resourceCount", 0)
317 execution.setVariable(Prefix+"nextResource", 0)
318 execution.setVariable(Prefix+"resourceFinish", true)
320 String aaiJsonRecord = execution.getVariable("serviceInstance");
321 msoLogger.info("serviceInstanceAaiRecord: " +aaiJsonRecord)
323 msoLogger.info("aaiJsonRecord: " +aaiJsonRecord)
324 def serviceInstanceName = jsonUtil.getJsonValue(aaiJsonRecord, "service-instance.service-instance-name")
325 execution.setVariable("serviceInstanceName",serviceInstanceName)
327 def serviceType = jsonUtil.getJsonValue(aaiJsonRecord, "service-instance.service-type")
328 execution.setVariable("serviceType",serviceType)
331 String relationshipList = jsonUtil.getJsonValue(aaiJsonRecord, "service-instance.relationship-list")
332 msoLogger.info("relationship-list:" + relationshipList)
333 if (! isBlank(relationshipList)){
334 msoLogger.info("relationship-list exists" )
335 String relationShip = jsonUtil.getJsonValue(relationshipList, "relationship")
336 msoLogger.info("relationship: " + relationShip)
337 JSONArray allResources = new JSONArray()
338 JSONArray serviceResources = new JSONArray()
339 JSONArray networkResources = new JSONArray()
340 JSONArray allottedResources = new JSONArray()
343 if (! isBlank(relationShip)){
344 JSONArray jsonArray = new JSONArray();
345 if (relationShip.startsWith("{") && relationShip.endsWith("}")) {
346 JSONObject jsonObject = new JSONObject(relationShip);
347 jsonArray.put(jsonObject);
348 } else if (relationShip.startsWith("[") && relationShip.endsWith("]")) {
349 jsonArray = new JSONArray(relationShip);
351 msoLogger.info("The relationShip fomart is error" )
354 List<String> relationList = jsonUtil.StringArrayToList(execution, jsonArray.toString())
356 msoLogger.info("relationList: " + relationList)
358 int relationNum =relationList.size()
359 msoLogger.info("**************relationList size: " + relationNum)
361 for ( int currentRelation = 0 ; currentRelation < relationNum ; currentRelation++ ) {
362 msoLogger.info("current Relation num: " + currentRelation)
363 String relation = relationList[currentRelation]
364 msoLogger.info("relation: " + relation)
366 String relatedTo = jsonUtil.getJsonValue(relation, "related-to")
367 msoLogger.info("relatedTo: " + relatedTo)
369 String relatedLink = jsonUtil.getJsonValue(relation, "related-link")
370 msoLogger.info("relatedLink: " + relatedLink)
372 if (StringUtils.equalsIgnoreCase(relatedTo, "allotted-resource")) {
373 msoLogger.info("allotted-resource exists ")
375 Optional<AllottedResource> aaiArRsp = getAaiAr(execution, relatedLink)
376 msoLogger.info("aaiArRsp: " + aaiArRsp)
377 if (aaiArRsp.isPresent()) {
379 JSONObject jObject = new JSONObject()
380 jObject.put("resourceType", aaiArRsp.get().getType())
381 jObject.put("resourceInstanceId", aaiArRsp.get().getId())
382 jObject.put("resourceRole", aaiArRsp.get().getRole())
383 jObject.put("resourceVersion", aaiArRsp.get().getResourceVersion())
385 allResources.put(jObject)
386 msoLogger.info("allResources: " + allResources)
387 allottedResources.put(jObject)
388 msoLogger.info("allottedResources: " + allottedResources)
391 else if (StringUtils.equalsIgnoreCase(relatedTo, "service-instance")){
392 msoLogger.info("service-instance exists ")
393 JSONObject jObject = new JSONObject()
396 String rsDataStr = jsonUtil.getJsonValue(relation, "relationship-data")
397 msoLogger.info("rsDataStr: " + rsDataStr)
398 List<String> rsDataList = jsonUtil.StringArrayToList(execution, rsDataStr)
399 msoLogger.info("rsDataList: " + rsDataList)
400 for(String rsData : rsDataList){
401 msoLogger.info("rsData: " + rsData)
402 def eKey = jsonUtil.getJsonValue(rsData, "relationship-key")
403 def eValue = jsonUtil.getJsonValue(rsData, "relationship-value")
404 if(eKey.equals("service-instance.service-instance-id")){
405 jObject.put("resourceInstanceId", eValue)
407 if(eKey.equals("service-subscription.service-type")){
408 jObject.put("resourceType", eValue)
412 //related-to-property
413 String rPropertyStr = jsonUtil.getJsonValue(relation, "related-to-property")
414 msoLogger.info("related-to-property: " + rPropertyStr)
415 if (rPropertyStr instanceof JSONArray){
416 List<String> rPropertyList = jsonUtil.StringArrayToList(execution, rPropertyStr)
417 for (String rProperty : rPropertyList) {
418 msoLogger.info("rProperty: " + rProperty)
419 def eKey = jsonUtil.getJsonValue(rProperty, "property-key")
420 def eValue = jsonUtil.getJsonValue(rProperty, "property-value")
421 if(eKey.equals("service-instance.service-instance-name")){
422 jObject.put("resourceName", eValue)
427 String rProperty = rPropertyStr
428 msoLogger.info("rProperty: " + rProperty)
429 def eKey = jsonUtil.getJsonValue(rProperty, "property-key")
430 def eValue = jsonUtil.getJsonValue(rProperty, "property-value")
431 if (eKey.equals("service-instance.service-instance-name")) {
432 jObject.put("resourceName", eValue)
436 allResources.put(jObject)
437 msoLogger.info("allResources: " + allResources)
439 serviceResources.put(jObject)
440 msoLogger.info("serviceResources: " + serviceResources)
442 else if (StringUtils.equalsIgnoreCase(relatedTo, "configuration")) {
443 msoLogger.info("configuration ")
444 JSONObject jObject = new JSONObject()
447 String rsDataStr = jsonUtil.getJsonValue(relation, "relationship-data")
448 msoLogger.info("rsDataStr: " + rsDataStr)
449 List<String> rsDataList = jsonUtil.StringArrayToList(execution, rsDataStr)
450 msoLogger.info("rsDataList: " + rsDataList)
451 for (String rsData : rsDataList) {
452 msoLogger.info("rsData: " + rsData)
453 def eKey = jsonUtil.getJsonValue(rsData, "relationship-key")
454 def eValue = jsonUtil.getJsonValue(rsData, "relationship-value")
455 if(eKey.equals("configuration.configuration-id")){
456 jObject.put("resourceInstanceId", eValue)
461 //related-to-property
462 String rPropertyStr = jsonUtil.getJsonValue(relation, "related-to-property")
463 msoLogger.info("related-to-property: " + rPropertyStr)
464 if (rPropertyStr instanceof JSONArray){
465 List<String> rPropertyList = jsonUtil.StringArrayToList(execution, rPropertyStr)
466 for(String rProperty : rPropertyList){
467 msoLogger.info("rProperty: " + rProperty)
468 def eKey = jsonUtil.getJsonValue(rProperty, "property-key")
469 def eValue = jsonUtil.getJsonValue(rProperty, "property-value")
470 if(eKey.equals("configuration.configuration-type")){
471 jObject.put("resourceType", eValue)
476 String rProperty = rPropertyStr
477 msoLogger.info("rProperty: " + rProperty)
478 def eKey = jsonUtil.getJsonValue(rProperty, "property-key")
479 def eValue = jsonUtil.getJsonValue(rProperty, "property-value")
480 if(eKey.equals("configuration.configuration-type")){
481 jObject.put("resourceType", eValue)
484 allResources.put(jObject)
485 msoLogger.info("allResources: " + allResources)
487 networkResources.put(jObject)
488 msoLogger.info("networkResources: " + networkResources)
490 msoLogger.info("Get Next releation resource " )
493 msoLogger.info("Get releation finished. " )
496 execution.setVariable("serviceRelationShip", allResources.toString())
497 msoLogger.info("allResources: " + allResources.toString())
498 String serviceRelationShip = execution.getVariable("serviceRelationShip")
499 msoLogger.info("serviceRelationShip: " + serviceRelationShip)
500 if ((! isBlank(serviceRelationShip)) && (! serviceRelationShip.isEmpty())) {
502 List<String> relationShipList = jsonUtil.StringArrayToList(execution, serviceRelationShip)
503 msoLogger.info("relationShipList: " + relationShipList)
504 execution.setVariable(Prefix+"resourceList", relationShipList)
506 int resourceCount = relationShipList.size()
507 msoLogger.info("resourceCount: " + resourceCount)
508 execution.setVariable(Prefix+"resourceCount",resourceCount )
511 execution.setVariable(Prefix+"nextResource", resourceNum)
512 msoLogger.info("start sort delete resource: ")
513 sortDeleteResource(execution)
516 if (resourceNum < resourceCount) {
517 execution.setVariable(Prefix+"resourceFinish", false)
520 execution.setVariable(Prefix+"resourceFinish", true)
522 msoLogger.info("Resource list set end : " + resourceCount)
525 execution.setVariable("serviceResources", serviceResources.toString())
526 msoLogger.info("serviceResources: " + serviceResources)
527 String serviceResourcesShip = execution.getVariable("serviceResources")
528 msoLogger.info("serviceResourcesShip: " + serviceResourcesShip)
530 if ((! isBlank(serviceResourcesShip)) && (! serviceResourcesShip.isEmpty())) {
531 List<String> serviceResourcesList = jsonUtil.StringArrayToList(execution, serviceResourcesShip)
532 msoLogger.info("serviceResourcesList: " + serviceResourcesList)
533 execution.setVariable(Prefix+"serviceResourceList", serviceResourcesList)
534 execution.setVariable(Prefix+"serviceResourceCount", serviceResourcesList.size())
535 execution.setVariable(Prefix+"nextServiceResource", 0)
536 msoLogger.info("Service Resource list set end : " + serviceResourcesList.size())
540 execution.setVariable("allottedResources", allottedResources.toString())
541 msoLogger.info("allottedResources: " + allottedResources)
542 String allottedResourcesShip = execution.getVariable("allottedResources")
543 msoLogger.info("allottedResourcesShip: " + allottedResourcesShip)
544 if ((! isBlank(allottedResourcesShip)) && (! allottedResourcesShip.isEmpty())) {
545 List<String> allottedResourcesList = jsonUtil.StringArrayToList(execution, allottedResourcesShip)
546 msoLogger.info("allottedResourcesList: " + allottedResourcesList)
547 execution.setVariable(Prefix+"allottedResourcesList", allottedResourcesList)
548 execution.setVariable(Prefix+"allottedResourcesListCount", allottedResourcesList.size())
549 execution.setVariable(Prefix+"nextAllottedResourcesList", 0)
550 msoLogger.info("Allotted Resource list set end : " + allottedResourcesList.size())
553 execution.setVariable("networkResources", networkResources.toString())
554 msoLogger.info("networkResources: " + networkResources)
555 String networkResourcesShip = execution.getVariable("networkResources")
556 msoLogger.info("networkResourcesShip: " + networkResourcesShip)
557 if ((! isBlank(networkResourcesShip)) && (! networkResourcesShip.isEmpty())) {
558 List<String> networkResourcesList = jsonUtil.StringArrayToList(execution, networkResourcesShip)
559 msoLogger.info("networkResourcesList: " + networkResourcesList)
560 execution.setVariable(Prefix+"networkResourcesList", networkResourcesList)
561 execution.setVariable(Prefix+"networkResourcesListCount", networkResourcesList.size())
562 execution.setVariable(Prefix+"nextNetworkResourcesList", 0)
563 msoLogger.info("Network Resource list set end : " + networkResourcesList.size())
567 } catch (BpmnError e){
569 } catch (Exception ex) {
570 String exceptionMessage = "Bpmn error encountered in DeleteMobileAPNCustService flow. prepareServiceDeleteResource() - " + ex.getMessage()
571 msoLogger.debug(exceptionMessage)
572 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
574 msoLogger.info("Exited " + method)
577 private Optional<AllottedResource> getAaiAr(DelegateExecution execution, String relink) {
578 def method = getClass().getSimpleName() + '.getAaiAr(' +'execution=' + execution.getId() +')'
579 msoLogger.info("Entered " + method)
580 AAIResourceUri uri = AAIUriFactory.createResourceFromExistingURI(AAIObjectType.ALLOTTED_RESOURCE, UriBuilder.fromPath(relink).build())
581 return getAAIClient().get(AllottedResource.class,uri)
584 * prepare Decompose next resource to create request
586 public void preProcessDecomposeNextResource(DelegateExecution execution){
587 def method = getClass().getSimpleName() + '.getAaiAr(' +'execution=' + execution.getId() +')'
588 msoLogger.info("Entered " + method)
589 msoLogger.trace("STARTED preProcessDecomposeNextResource Process ")
591 int resourceNum = execution.getVariable(Prefix+"nextServiceResource")
592 List<String> serviceResourceList = execution.getVariable(Prefix+"serviceResourceList")
593 msoLogger.info("Service Resource List : " + serviceResourceList)
595 String serviceResource = serviceResourceList[resourceNum]
596 execution.setVariable(Prefix+"serviceResource", serviceResource)
597 msoLogger.info("Current Service Resource : " + serviceResource)
599 String resourceType = jsonUtil.getJsonValue(serviceResource, "resourceType")
600 execution.setVariable("resourceType", resourceType)
601 msoLogger.info("resourceType : " + resourceType)
603 String resourceInstanceId = jsonUtil.getJsonValue(serviceResource, "resourceInstanceId")
604 execution.setVariable("resourceInstanceId", resourceInstanceId)
605 msoLogger.info("resourceInstanceId : " + resourceInstanceId)
607 String resourceRole = jsonUtil.getJsonValue(serviceResource, "resourceRole")
608 execution.setVariable("resourceRole", resourceRole)
609 msoLogger.info("resourceRole : " + resourceRole)
611 String resourceVersion = jsonUtil.getJsonValue(serviceResource, "resourceVersion")
612 execution.setVariable("resourceVersion", resourceVersion)
613 msoLogger.info("resourceVersion : " + resourceVersion)
615 String resourceName = jsonUtil.getJsonValue(serviceResource, "resourceName")
616 if (isBlank(resourceName)){
617 resourceName = resourceInstanceId
619 execution.setVariable(Prefix+"resourceName", resourceName)
620 msoLogger.info("resource Name : " + resourceName)
623 execution.setVariable(Prefix+"nextServiceResource", resourceNum + 1)
625 int serviceResourceCount = execution.getVariable(Prefix+"serviceResourceCount")
626 if (serviceResourceCount >0 ){
627 int progress = (resourceNum*100) / serviceResourceCount
628 execution.setVariable("progress", progress.toString() )
630 execution.setVariable("operationStatus", resourceName )
633 // try error in method block
634 String exceptionMessage = "Bpmn error encountered in CreateMobileAPNCustService flow. Unexpected Error from method preProcessDecomposeNextResource() - " + ex.getMessage()
635 msoLogger.debug(exceptionMessage)
636 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
638 msoLogger.info("Exited " + method)
641 * post Decompose next resource to create request
643 public void postProcessDecomposeNextResource(DelegateExecution execution){
644 def method = getClass().getSimpleName() + '.postProcessDecomposeNextResource(' +'execution=' + execution.getId() +')'
645 msoLogger.info("Entered " + method)
646 msoLogger.trace("STARTED postProcessDecomposeNextResource Process ")
648 String resourceName = execution.getVariable(Prefix+"resourceName")
649 int resourceNum = execution.getVariable(Prefix+"nextServiceResource")
650 msoLogger.debug("Current Resource count:"+ execution.getVariable(Prefix+"nextServiceResource"))
652 int resourceCount = execution.getVariable(Prefix+"serviceResourceCount")
653 msoLogger.debug("Total Resource count:"+ execution.getVariable(Prefix+"serviceResourceCount"))
655 if (resourceNum < resourceCount) {
656 execution.setVariable(Prefix+"resourceFinish", false)
659 execution.setVariable(Prefix+"resourceFinish", true)
662 msoLogger.debug("Resource Finished:"+ execution.getVariable(Prefix+"resourceFinish"))
664 if (resourceCount >0 ){
665 int progress = (resourceNum*100) / resourceCount
667 execution.setVariable("progress", progress.toString() )
668 msoLogger.trace(":"+ execution.getVariable(""))
670 execution.setVariable("operationStatus", resourceName )
674 // try error in method block
675 String exceptionMessage = "Bpmn error encountered in CreateMobileAPNCustService flow. Unexpected Error from method postProcessDecomposeNextResource() - " + ex.getMessage()
676 msoLogger.debug(exceptionMessage)
677 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
679 msoLogger.info("Exited " + method)
682 * prepare post Unkown Resource Type
684 public void postOtherControllerType(DelegateExecution execution){
685 def method = getClass().getSimpleName() + '.postOtherControllerType(' +'execution=' + execution.getId() +')'
686 def isDebugEnabled = execution.getVariable("isDebugEnabled")
687 msoLogger.info("Entered " + method)
691 String resourceName = execution.getVariable(Prefix+"resourceName")
692 String resourceType = execution.getVariable(Prefix+"resourceType")
693 String controllerType = execution.getVariable("controllerType")
695 String msg = "Resource name: "+ resourceName + " resource Type: " + resourceType+ " controller Type: " + controllerType + " can not be processed n the workflow"
699 // try error in method block
700 String exceptionMessage = "Bpmn error encountered in DoCreateMobileAPNServiceInstance flow. Unexpected Error from method postOtherControllerType() - " + ex.getMessage()
701 msoLogger.debug(exceptionMessage)
702 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
704 msoLogger.info("Exited " + method)
708 * prepare delete parameters
710 public void preSDNCResourceDelete(execution, resourceName){
711 // we use resource instance ids for delete flow as resourceTemplateUUIDs
713 def method = getClass().getSimpleName() + '.preSDNCResourceDelete(' +'execution=' + execution.getId() +')'
714 msoLogger.info("Entered " + method)
716 msoLogger.trace("STARTED preSDNCResourceDelete Process ")
717 String networkResources = execution.getVariable("networkResources")
720 execution.setVariable("foundResource", false)
721 if (networkResources != null) {
722 def jsonSlurper = new JsonSlurper()
723 List relationShipList = jsonSlurper.parseText(networkResources)
724 relationShipList.each {
725 if(StringUtils.containsIgnoreCase(it.resourceType, resourceName)) {
726 String resourceInstanceUUID = it.resourceInstanceId
727 String resourceTemplateUUID = it.resourceInstanceId
728 execution.setVariable("resourceTemplateId", resourceTemplateUUID)
729 execution.setVariable("resourceInstanceId", resourceInstanceUUID)
730 execution.setVariable("resourceType", resourceName)
731 execution.setVariable("foundResource", true)
732 msoLogger.info("Delete Resource Info resourceTemplate Id :" + resourceTemplateUUID + " resourceInstanceId: " + resourceInstanceUUID + " resourceType: " + resourceName)
736 msoLogger.info("Exited " + method)
738 public void preProcessSDNCDelete (DelegateExecution execution) {
739 def method = getClass().getSimpleName() + '.preProcessSDNCDelete(' +'execution=' + execution.getId() +')'
740 msoLogger.info("Entered " + method)
741 msoLogger.trace("preProcessSDNCDelete ")
745 def serviceInstanceId = execution.getVariable("serviceInstanceId")
746 def serviceInstanceName = execution.getVariable("serviceInstanceName")
747 def callbackURL = execution.getVariable("sdncCallbackUrl")
748 def requestId = execution.getVariable("msoRequestId")
749 def serviceId = execution.getVariable("productFamilyId")
750 def subscriptionServiceType = execution.getVariable("subscriptionServiceType")
751 def globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId
753 String serviceModelInfo = execution.getVariable("serviceModelInfo")
754 def modelInvariantUuid = ""
755 def modelVersion = ""
758 if (!isBlank(serviceModelInfo))
760 modelInvariantUuid = jsonUtil.getJsonValue(serviceModelInfo, "modelInvariantUuid")
761 modelVersion = jsonUtil.getJsonValue(serviceModelInfo, "modelVersion")
762 modelUuid = jsonUtil.getJsonValue(serviceModelInfo, "modelUuid")
763 modelName = jsonUtil.getJsonValue(serviceModelInfo, "modelName")
765 if (modelInvariantUuid == null) {
766 modelInvariantUuid = ""
768 if (modelVersion == null) {
771 if (modelUuid == null) {
774 if (modelName == null) {
778 if (serviceInstanceName == null) {
779 serviceInstanceName = ""
781 if (serviceId == null) {
785 def siParamsXml = execution.getVariable("siParamsXml")
786 def serviceType = execution.getVariable("serviceType")
787 if (serviceType == null)
792 def sdncRequestId = UUID.randomUUID().toString()
795 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
796 xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
797 xmlns:sdncadapter="http://org.onap/workflow/sdnc/adapter/schema/v1">
798 <sdncadapter:RequestHeader>
799 <sdncadapter:RequestId>${MsoUtils.xmlEscape(sdncRequestId)}</sdncadapter:RequestId>
800 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(serviceInstanceId)}</sdncadapter:SvcInstanceId>
801 <sdncadapter:SvcAction>delete</sdncadapter:SvcAction>
802 <sdncadapter:SvcOperation>service-topology-operation</sdncadapter:SvcOperation>
803 <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackURL)}</sdncadapter:CallbackUrl>
804 <sdncadapter:MsoAction>${MsoUtils.xmlEscape(serviceType)}</sdncadapter:MsoAction>
805 </sdncadapter:RequestHeader>
806 <sdncadapterworkflow:SDNCRequestData>
807 <request-information>
808 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
813 <request-action>DeleteServiceInstance</request-action>
814 </request-information>
815 <service-information>
816 <service-id>${MsoUtils.xmlEscape(serviceId)}</service-id>
817 <subscription-service-type>${MsoUtils.xmlEscape(subscriptionServiceType)}</subscription-service-type>
818 <onap-model-information>
819 <model-invariant-uuid>${MsoUtils.xmlEscape(modelInvariantUuid)}</model-invariant-uuid>
820 <model-uuid>${MsoUtils.xmlEscape(modelUuid)}</model-uuid>
821 <model-version>${MsoUtils.xmlEscape(modelVersion)}</model-version>
822 <model-name>${MsoUtils.xmlEscape(modelName)}</model-name>
823 </onap-model-information>
824 <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceId)}</service-instance-id>
826 <global-customer-id>${MsoUtils.xmlEscape(globalSubscriberId)}</global-customer-id>
827 </service-information>
828 <service-request-input>
829 <service-instance-name>${MsoUtils.xmlEscape(serviceInstanceName)}</service-instance-name>
831 </service-request-input>
832 </sdncadapterworkflow:SDNCRequestData>
833 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
835 sdncDelete = utils.formatXml(sdncDelete)
836 def sdncRequestId2 = UUID.randomUUID().toString()
837 String sdncDeactivate = sdncDelete.replace(">delete<", ">deactivate<").replace(">${sdncRequestId}<", ">${sdncRequestId2}<")
838 execution.setVariable("sdncDelete", sdncDelete)
839 execution.setVariable("sdncDeactivate", sdncDeactivate)
840 msoLogger.info("sdncDeactivate:\n" + sdncDeactivate)
841 msoLogger.info("sdncDelete:\n" + sdncDelete)
843 } catch (BpmnError e) {
845 } catch(Exception ex) {
846 msg = "Exception in preProcessSDNCDelete. " + ex.getMessage()
848 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "Exception Occured in preProcessSDNCDelete.\n" + ex.getMessage())
850 msoLogger.info("Exited " + method)
853 public void postProcessSDNCDelete(DelegateExecution execution, String response, String action) {
855 def method = getClass().getSimpleName() + '.postProcessSDNCDelete(' +'execution=' + execution.getId() +')'
856 msoLogger.info("Entered " + method)
857 msoLogger.trace("postProcessSDNC " + action + " ")
861 WorkflowException workflowException = execution.getVariable("WorkflowException")
862 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
863 msoLogger.info("SDNCResponse: " + response)
864 msoLogger.info("workflowException: " + workflowException)
866 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
867 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
868 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == "true"){
869 msoLogger.info("Good response from SDNC Adapter for service-instance " + action + "response:\n" + response)
872 msg = "Bad Response from SDNC Adapter for service-instance " + action
874 exceptionUtil.buildAndThrowWorkflowException(execution, 3500, msg)
876 } catch (BpmnError e) {
878 } catch(Exception ex) {
879 msg = "Exception in postProcessSDNC " + action + " Exception:" + ex.getMessage()
881 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
883 msoLogger.info("Exited " + method)
887 * Init the service Operation Status
889 public void preUpdateServiceOperationStatus(DelegateExecution execution){
890 def method = getClass().getSimpleName() + '.preUpdateServiceOperationStatus(' +'execution=' + execution.getId() +')'
891 msoLogger.info("Entered " + method)
894 String serviceId = execution.getVariable("serviceInstanceId")
895 String operationId = execution.getVariable("operationId")
896 String serviceName = execution.getVariable("serviceInstanceName")
897 String operationType = "DELETE"
899 String result = "processing"
900 String progress = execution.getVariable("progress")
901 msoLogger.info("progress: " + progress )
902 if ("100".equalsIgnoreCase(progress))
907 String operationContent = "Prepare service delete: " + execution.getVariable("operationStatus")
908 msoLogger.info("Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId)
909 serviceId = UriUtils.encode(serviceId,"UTF-8")
910 execution.setVariable("serviceInstanceId", serviceId)
911 execution.setVariable("operationId", operationId)
912 execution.setVariable("operationType", operationType)
914 def dbAdapterEndpoint = execution.getVariable("URN_mso_adapters_openecomp_db_endpoint")
915 execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
916 msoLogger.info("DB Adapter Endpoint is: " + dbAdapterEndpoint)
918 execution.setVariable("URN_mso_openecomp_adapters_db_endpoint","http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter")
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 msoLogger.info("Outgoing preUpdateServiceOperationStatus: \n" + payload)
945 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occured Processing preUpdateServiceOperationStatus.", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e);
946 execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during preUpdateServiceOperationStatus Method:\n" + e.getMessage())
948 msoLogger.trace("COMPLETED preUpdateServiceOperationStatus Process ")
949 msoLogger.info("Exited " + method)
952 public void preInitResourcesOperStatus(DelegateExecution execution){
953 def method = getClass().getSimpleName() + '.preInitResourcesOperStatus(' +'execution=' + execution.getId() +')'
954 msoLogger.info("Entered " + method)
956 msoLogger.trace("STARTED preInitResourcesOperStatus Process ")
959 String serviceId = execution.getVariable("serviceInstanceId")
960 String operationId = execution.getVariable("operationId")
961 String operationType = "DELETE"
962 String resourceTemplateUUIDs = ""
963 String result = "processing"
964 String progress = "0"
966 String operationContent = "Prepare service delete"
967 msoLogger.info("Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId + " operationType:" + operationType)
968 serviceId = UriUtils.encode(serviceId,"UTF-8")
969 execution.setVariable("serviceInstanceId", serviceId)
970 execution.setVariable("operationId", operationId)
971 execution.setVariable("operationType", operationType)
973 String serviceRelationShip = execution.getVariable("serviceRelationShip")
974 msoLogger.info("serviceRelationShip: " + serviceRelationShip)
975 if (! isBlank(serviceRelationShip)) {
976 def jsonSlurper = new JsonSlurper()
977 def jsonOutput = new JsonOutput()
978 List relationShipList = jsonSlurper.parseText(serviceRelationShip)
980 if (relationShipList != null) {
981 relationShipList.each {
982 resourceTemplateUUIDs = resourceTemplateUUIDs + it.resourceInstanceId + ":"
986 def dbAdapterEndpoint = "http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter"
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)