c5a928aaf91f80ed9a53bb12015758815aa5f527
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2020  Tech Mahindra
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.bpmn.infrastructure.scripts
22
23 import com.fasterxml.jackson.databind.ObjectMapper
24
25 import groovy.json.JsonOutput
26
27 import static org.hamcrest.CoreMatchers.instanceOf
28
29 import javax.json.JsonArray
30 import javax.ws.rs.core.Response
31 import org.apache.commons.collections.map.HashedMap
32 import org.apache.commons.lang.StringEscapeUtils
33 import org.camunda.bpm.engine.delegate.BpmnError
34 import org.camunda.bpm.engine.delegate.DelegateExecution
35 import org.json.JSONArray
36 import org.json.JSONObject
37 import org.onap.aaiclient.client.aai.AAIResourcesClient
38 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
39 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
40 import org.onap.so.bpmn.common.scripts.CatalogDbUtils
41 import org.onap.so.bpmn.common.scripts.CatalogDbUtilsFactory
42 import org.onap.so.bpmn.common.scripts.ExceptionUtil
43 import org.onap.so.bpmn.common.scripts.ExternalAPIUtil
44 import org.onap.so.bpmn.common.scripts.ExternalAPIUtilFactory
45 import org.onap.so.bpmn.common.scripts.RequestDBUtil
46 import org.onap.so.db.request.beans.OperationStatus
47 import org.onap.so.db.request.beans.ResourceOperationStatus
48 import org.onap.so.client.HttpClient
49 import org.onap.so.client.HttpClientFactory
50 import org.onap.logging.filter.base.ONAPComponents
51 import org.onap.so.bpmn.core.UrnPropertiesReader
52 import org.onap.aai.domain.yang.NetworkRoute
53 import org.onap.aai.domain.yang.v19.ServiceInstance
54 import org.onap.aai.domain.yang.v20.Relationship
55 import org.onap.aaiclient.client.aai.AAIObjectType
56 import org.onap.aaiclient.client.aai.entities.AAIResultWrapper
57 import org.onap.aaiclient.client.aai.entities.AAIEdgeLabel
58 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
59 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
60 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types
61 import org.onap.so.bpmn.core.domain.ServiceDecomposition
62 import org.onap.so.bpmn.core.domain.ServiceProxy
63 import org.onap.so.bpmn.core.json.JsonUtils
64 import org.slf4j.Logger
65 import org.slf4j.LoggerFactory
66 import org.springframework.http.HttpEntity
67
68 import javax.ws.rs.NotFoundException
69
70 class DoAllocateCoreNonSharedSlice extends AbstractServiceTaskProcessor {
71     String Prefix="DACNSNSSI_"
72     private static final Logger logger = LoggerFactory.getLogger( DoAllocateCoreNonSharedSlice.class);
73     private CatalogDbUtils catalogDbUtils = new CatalogDbUtilsFactory().create()
74     private RequestDBUtil requestDBUtil = new RequestDBUtil()
75     private ExceptionUtil exceptionUtil = new ExceptionUtil()
76     private JsonUtils jsonUtil = new JsonUtils()
77
78     @Override
79     public void preProcessRequest(DelegateExecution execution) {
80         logger.debug(Prefix+ "**** Enter DoAllocateCoreNonSharedSlice:::  preProcessRequest ****")
81         String nssiServiceInstanceId= execution.getVariable("serviceInstanceId")
82         execution.setVariable("nssiServiceInstanceId", nssiServiceInstanceId)
83         //Set orchestration-status as created
84         execution.setVariable("orchestrationStatus", "created")
85         //networkServiceName
86         String networkServiceName = jsonUtil.getJsonValue(execution.getVariable("networkServiceModelInfo"), "modelName") ?: ""
87         execution.setVariable("networkServiceName", networkServiceName.replaceAll(" Service Proxy", ""))
88         //networkServiceModelUuid
89         String networkServiceModelUuid = jsonUtil.getJsonValue(execution.getVariable("networkServiceModelInfo"), "modelUuid") ?: ""
90         execution.setVariable("networkServiceModelUuid", networkServiceModelUuid)
91                 String sliceParams = execution.getVariable("sliceParams")
92                 logger.debug("sliceParams "+sliceParams)
93                 List<String> bhEndPoints = jsonUtil.StringArrayToList(jsonUtil.getJsonValue(sliceParams, "endPoints"))
94                 if(bhEndPoints.empty) {
95                         logger.debug("End point info is empty")
96                         exceptionUtil.buildAndThrowWorkflowException(execution, 500, "End point info is empty")
97                 }else {
98                         execution.setVariable("bh_endpoint", bhEndPoints.get(0))
99                 }
100         logger.debug(Prefix+ " **** Exit DoAllocateCoreNonSharedSlice:::  preProcessRequest ****")
101     }
102
103     void createNSSIinAAI(DelegateExecution execution) {
104         logger.debug(Prefix+ " ****  Enter DoAllocateCoreNonSharedSlice ::: Enter createNSSIinAAI ****")
105         String msg=""
106         String serviceInstanceId= execution.getVariable("nssiServiceInstanceId")
107         logger.debug("ServiceInstanceId: "+serviceInstanceId)
108         try {
109             String serviceType = execution.getVariable("subscriptionServiceType")
110             String oStatus = execution.getVariable("orchestrationStatus")
111             //Get workload context and environment context from DB
112             String environmentContext = ""
113             String workloadContext =""
114             String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
115             try{
116                 String json = catalogDbUtils.getServiceResourcesByServiceModelInvariantUuidString(execution,modelInvariantUuid )
117                 logger.debug("JSON Response from DB: "+json)
118                 environmentContext = jsonUtil.getJsonValue(json, "serviceResources.environmentContext") ?: ""
119                 workloadContext = jsonUtil.getJsonValue(json, "serviceResources.workloadContext") ?: ""
120                 logger.debug("Env Context is: "+ environmentContext)
121                 logger.debug("Workload Context is: "+ workloadContext)
122             } catch(BpmnError e){
123                 throw e
124             } catch (Exception ex){
125                 msg = "Exception in createNSSIinAAI ::: DoAllocateCoreNonSharedSlice  " + ex.getMessage()
126                 logger.debug(msg)
127                 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
128             }
129             String serviceInstanceName = "nssi_"+execution.getVariable("nsstName")
130             ServiceInstance si = new ServiceInstance()
131             si.setServiceInstanceId(execution.getVariable("nssiServiceInstanceId"))
132             si.setServiceInstanceName(serviceInstanceName)
133             si.setServiceType(serviceType)
134             si.setServiceRole("nssi")
135             si.setOrchestrationStatus(oStatus)
136             si.setModelInvariantId(modelInvariantUuid)
137             si.setModelVersionId(execution.getVariable("modelUuid"))
138             si.setEnvironmentContext(environmentContext)
139             si.setWorkloadContext(workloadContext)
140             logger.debug("AAI service Instance Request Payload : "+si.toString())
141             AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(execution.getVariable("globalSubscriberId")).serviceSubscription(serviceType).serviceInstance(serviceInstanceId))
142             Response response = getAAIClient().create(uri, si)
143             if(response.getStatus()!=200) {
144                 exceptionUtil.buildAndThrowWorkflowException(execution, response.getStatus(), "AAI instance creation failed")
145             }
146             execution.setVariable("nssiServiceInstance", si)
147         } catch (BpmnError e) {
148             throw e;
149         } catch (Exception ex) {
150             msg = "Exception in create AAI Instance" + ex.getMessage()
151             logger.debug(msg)
152             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
153         }
154         logger.debug(Prefix+ " Exit DoAllocateCoreNonSharedSlice ::: Enter createNSSIinAAI ****")
155     }
156
157     public void prepareServiceOrderRequest(DelegateExecution execution) {
158         logger.debug("**** Enter DoAllocateCoreNonSharedSlice :::  prepareServiceOrderRequest ****")
159         String extAPIPath = UrnPropertiesReader.getVariable("extapi.endpoint", execution) + '/serviceOrder'
160         execution.setVariable("ExternalAPIURL", extAPIPath)
161         ObjectMapper objectMapper = new ObjectMapper();
162         Map<String, Object> serviceOrder = new LinkedHashMap()
163         //ExternalId
164         serviceOrder.put("externalId", "ONAP001")
165         //Requested Start Date
166         String requestedStartDate = utils.generateCurrentTimeInUtc()
167         String requestedCompletionDate = utils.generateCurrentTimeInUtc()
168         serviceOrder.put("requestedStartDate", requestedStartDate)
169         serviceOrder.put("requestedCompletionDate", requestedCompletionDate)
170         //RelatedParty Fields
171         String relatedPartyId = execution.getVariable("globalSubscriberId")
172         String relatedPartyRole = "ONAPcustomer"
173         Map<String, String> relatedParty = new LinkedHashMap()
174         relatedParty.put("id", relatedPartyId)
175         relatedParty.put("role", relatedPartyRole)
176         List<Map<String, String>> relatedPartyList = new ArrayList()
177         relatedPartyList.add(relatedParty)
178         serviceOrder.put("relatedParty", relatedPartyList)
179         Map<String, Object> orderItem = new LinkedHashMap()
180         //orderItem id
181         String orderItemId = "1"
182         orderItem.put("id", orderItemId)
183         //order item action will always be add as we are triggering request for instantiation
184         String orderItemAction = "add"
185         orderItem.put("action", orderItemAction)
186         // service Details
187         Map<String, Object> service = new LinkedHashMap()
188         //ServiceName
189         String serviceName= "nsi_"+execution.getVariable("networkServiceName")
190         service.put("name",  serviceName)
191         // Service Type
192         service.put("serviceType", execution.getVariable("serviceType"))
193         //Service State
194         service.put("serviceState", "active")
195         Map<String, String> serviceSpecification = new LinkedHashMap()
196         serviceSpecification.put("id", execution.getVariable("networkServiceModelUuid"))
197         service.put("serviceSpecification", serviceSpecification)
198         //serviceCharacteristic List
199         List serviceCharacteristicList = new ArrayList()
200         Map<String, Object> serviceCharacteristic = objectMapper.readValue(execution.getVariable("sliceProfile"), Map.class);
201         List serviceCharacteristicListMap = retrieveServiceCharacteristicsAsKeyValue(serviceCharacteristic)
202         logger.debug("serviceCharacteristicListMap  "+serviceCharacteristicListMap)
203         serviceCharacteristicList.add(serviceCharacteristic)
204         //service.put("serviceCharacteristic", serviceCharacteristicList)
205         service.put("serviceCharacteristic", serviceCharacteristicListMap)
206         orderItem.put("service", service)
207         List<Map<String, String>> orderItemList = new ArrayList()
208         orderItemList.add(orderItem)
209         serviceOrder.put("orderItem", orderItemList)
210         String jsonServiceOrder = objectMapper.writeValueAsString(serviceOrder);
211         logger.debug("******* ServiceOrder :: "+jsonServiceOrder)
212         execution.setVariable("serviceOrderRequest", jsonServiceOrder)
213         logger.debug(Prefix+ " **** Exit DoAllocateCoreNonSharedSlice ::: prepareServiceOrderRequest****")
214     }
215
216     private List retrieveServiceCharacteristicsAsKeyValue(Map serviceCharacteristics) {
217         logger.debug(Prefix+ " **** Enter DoAllocateCoreNonSharedSlice ::: retrieveServiceCharacteristicsAsKeyValue ****")
218         List serviceCharacteristicsList = new ArrayList()
219         ObjectMapper mapperObj = new ObjectMapper();
220         Map<String, Object> serviceCharacteristicsObject = new LinkedHashMap()
221         for (Map.Entry<String, Integer> entry : serviceCharacteristics.entrySet()) {
222             Map<String, Object> ServiceCharacteristicValueObject = new LinkedHashMap<>()
223             System.out.println(entry.getKey() + ":" + entry.getValue());
224             //For G Release we are sending single value from  snssaiList
225             if(entry.getKey().equals("snssaiList")) {
226                 List sNssaiValue = entry.getValue()
227                 serviceCharacteristicsObject.put("name", "snssai")
228                 ServiceCharacteristicValueObject.put("serviceCharacteristicValue", sNssaiValue.get(0))
229                 serviceCharacteristicsObject.put("value", ServiceCharacteristicValueObject)
230             }
231         }
232         serviceCharacteristicsList.add(serviceCharacteristicsObject)
233         logger.debug(Prefix+ " **** Exit DoAllocateCoreNonSharedSlice ::: retrieveServiceCharacteristicsAsKeyValue ****")
234         return serviceCharacteristicsList
235     }
236
237     public void postNBIServiceOrder(DelegateExecution execution) {
238         logger.debug(Prefix+ " **** Enter DoAllocateCoreNonSharedSlice ::: postNBIServiceOrder ****")
239         String msg=""
240         try {
241             String extAPIPath = execution.getVariable("ExternalAPIURL")
242             String payload = execution.getVariable("serviceOrderRequest")
243             logger.debug("externalAPIURL is: " + extAPIPath)
244             logger.debug("ServiceOrder payload is: " + payload)
245             ExternalAPIUtil externalAPIUtil = new ExternalAPIUtilFactory().create()
246             execution.setVariable("ServiceOrderId", "")
247             Response response = externalAPIUtil.executeExternalAPIPostCall(execution, extAPIPath, payload)
248             int responseCode = response.getStatus()
249             execution.setVariable("PostServiceOrderResponseCode", responseCode)
250             logger.debug("Post ServiceOrder response code is: " + responseCode)
251             String extApiResponse = response.readEntity(String.class)
252             JSONObject responseObj = new JSONObject(extApiResponse)
253             execution.setVariable("PostServiceOrderResponse", extApiResponse)
254             logger.debug("ServiceOrder response body is: " + extApiResponse)
255             //Process Response
256             if(responseCode == 200 || responseCode == 201 || responseCode == 202 )
257                 //200 OK 201 CREATED 202 ACCEPTED
258             {
259                 logger.debug("Post ServiceOrder Received a Good Response")
260                 String serviceOrderId = responseObj.get("id")
261                 execution.setVariable("ServiceOrderId", serviceOrderId)
262                 logger.info("Post ServiceOrderid is: " + serviceOrderId)
263             }
264             else{
265                 exceptionUtil.buildAndThrowWorkflowException(execution, responseCode, "Post ServiceOrder Received a bad response from extAPI serviceOrder API")
266             }
267         }catch (BpmnError e) {
268             throw e;
269         } catch (Exception ex) {
270             msg = "Exception in ServiceOrder ExtAPI" + ex.getMessage()
271             logger.debug(msg)
272             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
273         }
274         logger.debug("**** Exit DoAllocateCoreNonSharedSlice ::: postNBIServiceOrder ****")
275     }
276
277     public void getNBIServiceOrderProgress(DelegateExecution execution) {
278         logger.debug(Prefix+ " **** Enter DoAllocateCoreNonSharedSlice ::: getNBIServiceOrderProgress ****")
279         String msg=""
280         try {
281             String extAPIPath = execution.getVariable("ExternalAPIURL")
282             extAPIPath += "/" + execution.getVariable("ServiceOrderId")
283             logger.debug("getNBIServiceOrderProgress externalAPIURL is: " + extAPIPath)
284             ExternalAPIUtil externalAPIUtil = new ExternalAPIUtilFactory().create()
285             Response response = externalAPIUtil.executeExternalAPIGetCall(execution, extAPIPath)
286             int responseCode = response.getStatus()
287             execution.setVariable("GetServiceOrderResponseCode", responseCode)
288             logger.debug("Get ServiceOrder response code is: " + responseCode)
289             String extApiResponse = response.readEntity(String.class)
290             JSONObject responseObj = new JSONObject(extApiResponse)
291             execution.setVariable("GetServiceOrderResponse", extApiResponse)
292             logger.debug("Create response body is: " + extApiResponse)
293             //Process Response //200 OK 201 CREATED 202 ACCEPTED
294             if(responseCode == 200 || responseCode == 201 || responseCode == 202 )
295             {
296                 logger.debug("Get Create ServiceOrder Received a Good Response")
297                 String orderState = responseObj.get("state")
298                 if("REJECTED".equalsIgnoreCase(orderState)) {
299                     prepareFailedOperationStatusUpdate(execution)
300                     return
301                 }
302                 JSONArray items = responseObj.getJSONArray("orderItem")
303                 JSONObject item = items.get(0)
304                 JSONObject service = item.get("service")
305                 String networkServiceId = service.get("id")
306                 if (networkServiceId == null || networkServiceId.equals("null")) {
307                     prepareFailedOperationStatusUpdate(execution)
308                     return
309                 }
310                 execution.setVariable("networkServiceId", networkServiceId)
311                 String serviceOrderState = item.get("state")
312                 execution.setVariable("ServiceOrderState", serviceOrderState)
313                 // Get serviceOrder State and process progress
314                 if("ACKNOWLEDGED".equalsIgnoreCase(serviceOrderState)) {
315                     execution.setVariable("status", "processing")
316                 }
317                 else if("INPROGRESS".equalsIgnoreCase(serviceOrderState)) {
318                     execution.setVariable("status", "processing")
319                 }
320                 else if("COMPLETED".equalsIgnoreCase(serviceOrderState)) {
321                     execution.setVariable("status", "completed")
322                 }
323                 else if("FAILED".equalsIgnoreCase(serviceOrderState)) {
324                     msg = "ServiceOrder failed"
325                     exceptionUtil.buildAndThrowWorkflowException(execution, 7000,  msg)
326                 }
327                 else {
328                     msg = "ServiceOrder failed"
329                     exceptionUtil.buildAndThrowWorkflowException(execution, 7000,  msg)
330                 }
331             }
332             else{
333                 msg = "Get ServiceOrder Received a Bad Response Code. Response Code is: " + responseCode
334                 prepareFailedOperationStatusUpdate(execution)
335             }
336
337         }catch(Exception e){
338             exceptionUtil.buildAndThrowWorkflowException(execution, 7000,  e.getMessage())
339         }
340         logger.debug(Prefix+ " **** Exit DoAllocateCoreNonSharedSlice ::: getNBIServiceOrderProgress ****")
341     }
342
343     /**
344      * delay 5 sec
345      */
346     public void timeDelay(DelegateExecution execution) {
347         try {
348             logger.debug(Prefix+ " **** DoAllocateCoreNonSharedSlice ::: timeDelay going to sleep for 5 sec")
349             Thread.sleep(5000)
350             logger.debug("**** DoAllocateCoreNonSharedSlice ::: timeDelay wakeup after 5 sec")
351         } catch(InterruptedException e) {
352             logger.error(Prefix+ " **** DoAllocateCoreNonSharedSlice ::: timeDelay exception" + e)
353         }
354     }
355
356
357     void updateRelationship(DelegateExecution execution) {
358         logger.debug(Prefix+ " **** Enter DoAllocateCoreNonSharedSlice ::: updateRelationship ****")
359
360         String networkServiceInstanceId = execution.getVariable("networkServiceId")
361         String nssiId = execution.getVariable("nssiServiceInstanceId")
362         String globalCustId = execution.getVariable("globalSubscriberId")
363         String serviceType = execution.getVariable("serviceType")
364         try{
365             //Update NSSI orchestration status nssiServiceInstance
366             ServiceInstance si = execution.getVariable("nssiServiceInstance")
367             si.setOrchestrationStatus("activated")
368
369             AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalCustId).serviceSubscription(serviceType).serviceInstance(networkServiceInstanceId))
370             try {
371                 getAAIClient().update(uri, si)
372             } catch (Exception e) {
373                 logger.info("Update OrchestrationStatus in AAI failed")
374                 String msg = "Update OrchestrationStatus in AAI failed, " + e.getMessage()
375                 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
376             }
377
378             //URI for NSSI
379             AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId));
380
381             //URI for Network Service Instance
382             AAIResourceUri networkServiceInstanceUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(networkServiceInstanceId))
383
384             // Update Relationship in AAI
385             Response response = getAAIClient().connect(nssiUri, networkServiceInstanceUri, AAIEdgeLabel.COMPOSED_OF);
386
387             if(response.getStatus()!=200 || response.getStatus()!=201 || response.getStatus()!=202) {
388                 exceptionUtil.buildAndThrowWorkflowException(execution, response.getStatus(), "Set association of NSSI and Network service instance has failed in AAI")
389             } else {
390                                 //end point update
391                                 createEndPointsInAai(execution)
392                 execution.setVariable("progress", 100)
393                 execution.setVariable("status", "finished")
394                 execution.setVariable("statusDescription", "DoAllocateCoreNonSharedNSSI success")
395                 setResourceOperationStatus(execution)
396             }
397         }catch(Exception ex) {
398             String msg = "Exception while creating relationship " + ex.getMessage()
399             logger.info(msg)
400             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
401         }
402         logger.debug(Prefix+ " **** Exit DoAllocateCoreNonSharedSlice ::: updateRelationship ****")
403     }
404
405         private void createEndPointsInAai(DelegateExecution execution) {
406                 String type = "endpoint"
407                 String function = "core_EP"
408                 int prefixLength = 24
409                 String addressFamily = "ipv4"
410                 //BH RAN end point update
411                 String bh_endpoint = execution.getVariable("bhEndPoints")
412                 String bh_routeId = UUID.randomUUID().toString()
413                 execution.setVariable("coreEp_ID_bh", bh_routeId)
414                 String role = "CN"
415                 String cnIpAddress = jsonUtil.getJsonValue(bh_endpoint, "IpAddress")
416                 String LogicalLinkId = jsonUtil.getJsonValue(bh_endpoint, "LogicalLinkId")
417                 String nextHopInfo = jsonUtil.getJsonValue(bh_endpoint, "nextHopInfo")
418                 NetworkRoute bh_ep = new NetworkRoute()
419                 bh_ep.setRouteId(bh_routeId)
420                 bh_ep.setFunction(function)
421                 bh_ep.setRole(role)
422                 bh_ep.setType(type)
423                 bh_ep.setIpAddress(cnIpAddress)
424                 bh_ep.setLogicalInterfaceId(LogicalLinkId)
425                 bh_ep.setNextHop(nextHopInfo)
426                 bh_ep.setPrefixLength(prefixLength)
427                 bh_ep.setAddressFamily(addressFamily)
428                 try {
429                         AAIResourcesClient client = new AAIResourcesClient()
430                         logger.debug("creating bh endpoint . ID : "+bh_routeId+" node details : "+bh_ep.toString())
431                         AAIResourceUri networkRouteUri = AAIUriFactory.createResourceUri( new AAIObjectType(AAINamespaceConstants.NETWORK, NetworkRoute.class), bh_routeId)
432                         client.create(networkRouteUri, bh_ep)
433                         //relationship b/w bh_ep and Core NSSI
434                         def coreNssi = execution.getVariable("NSSIserviceInstanceId")
435                         Relationship relationship = new Relationship()
436                         String relatedLink = "aai/v21/network/network-routes/network-route/${bh_routeId}"
437                         relationship.setRelatedLink(relatedLink)
438                         relationship.setRelatedTo("network-route")
439                         relationship.setRelationshipLabel("org.onap.relationships.inventory.ComposedOf")
440                         try {
441                                 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE,
442                                                 execution.getVariable("globalSubscriberId"),
443                                                 execution.getVariable("subscriptionServiceType"),
444                                                 coreNssi).relationshipAPI()
445                                 client.create(uri, relationship)
446                         } catch (BpmnError e) {
447                                 throw e
448                         } catch (Exception ex) {
449                                 String msg = "Exception in CreateCommunicationService.createRelationShipInAAI. " + ex.getMessage()
450                                 logger.info(msg)
451                                 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
452                         }
453                 } catch (BpmnError e) {
454                         throw e
455                 } catch (Exception ex) {
456                         String msg = "Exception in createEndPointsInAai " + ex.getMessage()
457                         logger.info(msg)
458                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
459                 }
460         }
461
462     /**
463      * prepare ResourceOperation status
464      * @param execution
465      * @param operationType
466      */
467     private void setResourceOperationStatus(DelegateExecution execution) {
468         logger.debug(Prefix+ " **** Enter DoAllocateCoreNonSharedSlice ::: setResourceOperationStatus ****")
469         String serviceId = execution.getVariable("nssiId")
470         String jobId = execution.getVariable("jobId")
471         String nsiId = execution.getVariable("nsiId")
472         String operationType = execution.getVariable("operationType")
473         ResourceOperationStatus resourceOperationStatus = new ResourceOperationStatus()
474         resourceOperationStatus.setServiceId(serviceId)
475         resourceOperationStatus.setOperationId(jobId)
476         resourceOperationStatus.setResourceTemplateUUID(nsiId)
477         resourceOperationStatus.setOperType(operationType)
478         resourceOperationStatus.setStatus(execution.getVariable("status"))
479         resourceOperationStatus.setProgress(execution.getVariable("progress"))
480         resourceOperationStatus.setStatusDescription(execution.getVariable("statusDescription"))
481         requestDBUtil.prepareUpdateResourceOperationStatus(execution, resourceOperationStatus)
482         logger.debug(Prefix+ " **** Exit DoAllocateCoreNonSharedSlice ::: setResourceOperationStatus ****")
483     }
484
485     void prepareFailedOperationStatusUpdate(DelegateExecution execution){
486         logger.debug(Prefix + " **** Enter DoAllocateCoreNonSharedSlice ::: prepareFailedOperationStatusUpdate ****")
487         String serviceId = execution.getVariable("nssiId")
488         String jobId = execution.getVariable("jobId")
489         String nsiId = execution.getVariable("nsiId")
490         String operationType = execution.getVariable("operationType")
491
492         ResourceOperationStatus resourceOperationStatus = new ResourceOperationStatus()
493         resourceOperationStatus.setServiceId(serviceId)
494         resourceOperationStatus.setOperationId(jobId)
495         resourceOperationStatus.setResourceTemplateUUID(nsiId)
496         resourceOperationStatus.setOperType(operationType)
497         resourceOperationStatus.setProgress(0)
498         resourceOperationStatus.setStatus("failed")
499         resourceOperationStatus.setStatusDescription("Core NSSI Allocate Failed")
500         requestDBUtil.prepareUpdateResourceOperationStatus(execution, resourceOperationStatus)
501         logger.debug(Prefix + " **** Exit DoAllocateCoreNonSharedSlice ::: prepareFailedOperationStatusUpdate ****")
502     }
503 }