2801c11e474baba25d0c42c1d9c39640961cf8ed
[so.git] / bpmn / so-bpmn-infrastructure-common / src / main / groovy / org / onap / so / bpmn / infrastructure / scripts / DoAllocateCoreNonSharedSlice.groovy
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 import org.onap.aai.domain.yang.NetworkPolicy
68 import org.onap.aaiclient.client.aai.AAINamespaceConstants
69
70 import javax.ws.rs.NotFoundException
71
72 class DoAllocateCoreNonSharedSlice extends AbstractServiceTaskProcessor {
73     String Prefix="DACNSNSSI_"
74     private static final Logger logger = LoggerFactory.getLogger( DoAllocateCoreNonSharedSlice.class);
75     private CatalogDbUtils catalogDbUtils = new CatalogDbUtilsFactory().create()
76     private RequestDBUtil requestDBUtil = new RequestDBUtil()
77     private ExceptionUtil exceptionUtil = new ExceptionUtil()
78     private JsonUtils jsonUtil = new JsonUtils()
79
80     @Override
81     public void preProcessRequest(DelegateExecution execution) {
82         logger.debug(Prefix+ "**** Enter DoAllocateCoreNonSharedSlice:::  preProcessRequest ****")
83         String nssiServiceInstanceId= execution.getVariable("serviceInstanceId")
84         logger.debug("nssiServiceInstanceId:  "+nssiServiceInstanceId)
85         execution.setVariable("nssiServiceInstanceId", nssiServiceInstanceId)
86         //Set orchestration-status as created
87         execution.setVariable("orchestrationStatus", "created")
88         //networkServiceName
89         String networkServiceName = jsonUtil.getJsonValue(execution.getVariable("networkServiceModelInfo"), "modelInfo.modelName") ?: ""
90         execution.setVariable("networkServiceName", networkServiceName.replaceAll(" Service Proxy", ""))
91         //networkServiceModelUuid
92         logger.debug("networkServiceName:  "+networkServiceName)
93         String networkServiceModelUuid = jsonUtil.getJsonValue(execution.getVariable("networkServiceModelInfo"), "sourceModelUuid") ?: ""
94         execution.setVariable("networkServiceModelUuid", networkServiceModelUuid)
95         String sliceParams = execution.getVariable("sliceParams")
96         logger.debug("sliceParams "+sliceParams)
97         String bhEndPoints = jsonUtil.getJsonValue(sliceParams, "endPoint")
98         if(bhEndPoints.empty) {
99             logger.debug("End point info is empty")
100             exceptionUtil.buildAndThrowWorkflowException(execution, 500, "End point info is empty")
101         }else {
102             execution.setVariable("bh_endpoint", bhEndPoints)
103         }
104         logger.debug(Prefix+ " **** Exit DoAllocateCoreNonSharedSlice:::  preProcessRequest ****")
105     }
106
107     void createNSSIinAAI(DelegateExecution execution) {
108         logger.debug(Prefix+ " ****  Enter DoAllocateCoreNonSharedSlice ::: Enter createNSSIinAAI ****")
109         String msg=""
110         String serviceInstanceId= execution.getVariable("nssiServiceInstanceId")
111         logger.debug("ServiceInstanceId: "+serviceInstanceId)
112         try {
113             String serviceType = execution.getVariable("subscriptionServiceType")
114             String oStatus = execution.getVariable("orchestrationStatus")
115             //Get workload context and environment context from DB
116             String environmentContext = ""
117             String workloadContext =""
118             String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
119             try{
120                 String json = catalogDbUtils.getServiceResourcesByServiceModelInvariantUuidString(execution,modelInvariantUuid )
121                 logger.debug("JSON Response from DB: "+json)
122                 environmentContext = jsonUtil.getJsonValue(json, "serviceResources.environmentContext") ?: ""
123                 workloadContext = jsonUtil.getJsonValue(json, "serviceResources.workloadContext") ?: ""
124                 logger.debug("Env Context is: "+ environmentContext)
125                 logger.debug("Workload Context is: "+ workloadContext)
126             } catch(BpmnError e){
127                 throw e
128             } catch (Exception ex){
129                 msg = "Exception in createNSSIinAAI ::: DoAllocateCoreNonSharedSlice  " + ex.getMessage()
130                 logger.debug(msg)
131                 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
132             }
133             //set shared or non shared value from sliceProfile object in request
134             String additionalParams = execution.getVariable("sliceParams")
135             //Get resourceSharingLevel from sliceProfile
136             String serviceFunction = jsonUtil.getJsonValue(additionalParams, "sliceProfile.resourceSharingLevel")
137             String serviceInstanceName = "nssi_"+execution.getVariable("nsstName")
138             ServiceInstance si = new ServiceInstance()
139             si.setServiceInstanceId(execution.getVariable("nssiServiceInstanceId"))
140             si.setServiceInstanceName(serviceInstanceName)
141             si.setServiceType(serviceType)
142             si.setServiceRole("nssi")
143             si.setOrchestrationStatus(oStatus)
144             si.setModelInvariantId(modelInvariantUuid)
145             si.setModelVersionId(execution.getVariable("modelUuid"))
146             si.setEnvironmentContext(environmentContext)
147             si.setWorkloadContext(workloadContext)
148             si.setServiceFunction(serviceFunction)
149             logger.debug("AAI service Instance Request Payload : "+si.toString())
150             AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(execution.getVariable("globalSubscriberId")).serviceSubscription(serviceType).serviceInstance(serviceInstanceId))
151             getAAIClient().create(uri, si)
152
153             execution.setVariable("nssiServiceInstance", si)
154         } catch (BpmnError e) {
155             throw e;
156         } catch (Exception ex) {
157             msg = "Exception in create AAI Instance" + ex.getMessage()
158             logger.debug(msg)
159             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
160         }
161         getVnfInstanceName(execution)
162         logger.debug(Prefix+ " Exit DoAllocateCoreNonSharedSlice ::: Enter createNSSIinAAI ****")
163     }
164
165     public void prepareServiceOrderRequest(DelegateExecution execution) {
166         logger.debug("**** Enter DoAllocateCoreNonSharedSlice :::  prepareServiceOrderRequest ****")
167         //extAPI path hardcoded for testing purposes, will be updated in next patch
168         String extAPIPath = "https://nbi.onap:8443/nbi/api/v4" + "/serviceOrder"
169         execution.setVariable("ExternalAPIURL", extAPIPath)
170         ObjectMapper objectMapper = new ObjectMapper();
171         Map<String, Object> serviceOrder = new LinkedHashMap()
172         //ExternalId
173         serviceOrder.put("externalId", "ONAP001")
174         //Requested Start Date
175         String requestedStartDate = utils.generateCurrentTimeInUtc()
176         String requestedCompletionDate = utils.generateCurrentTimeInUtc()
177         serviceOrder.put("requestedStartDate", requestedStartDate)
178         serviceOrder.put("requestedCompletionDate", requestedCompletionDate)
179         //RelatedParty Fields
180         String relatedPartyId = execution.getVariable("globalSubscriberId")
181         String relatedPartyRole = "ONAPcustomer"
182         Map<String, String> relatedParty = new LinkedHashMap()
183         relatedParty.put("id", relatedPartyId)
184         relatedParty.put("role", relatedPartyRole)
185         List<Map<String, String>> relatedPartyList = new ArrayList()
186         relatedPartyList.add(relatedParty)
187         serviceOrder.put("relatedParty", relatedPartyList)
188         Map<String, Object> orderItem = new LinkedHashMap()
189         //orderItem id
190         String orderItemId = "1"
191         orderItem.put("id", orderItemId)
192         //order item action will always be add as we are triggering request for instantiation
193         String orderItemAction = "add"
194         orderItem.put("action", orderItemAction)
195         // service Details
196         Map<String, Object> service = new LinkedHashMap()
197         //ServiceName
198         String serviceName= "ns_"+execution.getVariable("networkServiceName")+"_"+execution.getVariable("serviceInstanceId")
199         service.put("name",  serviceName)
200         // Service Type
201         service.put("serviceType", execution.getVariable("subscriptionServiceType"))
202         //Service State
203         service.put("serviceState", "active")
204         Map<String, String> serviceSpecification = new LinkedHashMap()
205         serviceSpecification.put("id", execution.getVariable("networkServiceModelUuid"))
206         service.put("serviceSpecification", serviceSpecification)
207         //serviceCharacteristic List
208         List serviceCharacteristicList = new ArrayList()
209         Map<String, Object> serviceCharacteristic = objectMapper.readValue(execution.getVariable("sliceProfile"), Map.class);
210         List serviceCharacteristicListMap = retrieveServiceCharacteristicsAsKeyValue(execution, serviceCharacteristic)
211         logger.debug("serviceCharacteristicListMap  "+serviceCharacteristicListMap)
212         serviceCharacteristicList.add(serviceCharacteristic)
213         //service.put("serviceCharacteristic", serviceCharacteristicList)
214         service.put("serviceCharacteristic", serviceCharacteristicListMap)
215         orderItem.put("service", service)
216         List<Map<String, String>> orderItemList = new ArrayList()
217         orderItemList.add(orderItem)
218         serviceOrder.put("orderItem", orderItemList)
219         String jsonServiceOrder = objectMapper.writeValueAsString(serviceOrder);
220         logger.debug("******* ServiceOrder :: "+jsonServiceOrder)
221         execution.setVariable("serviceOrderRequest", jsonServiceOrder)
222         logger.debug(Prefix+ " **** Exit DoAllocateCoreNonSharedSlice ::: prepareServiceOrderRequest****")
223     }
224
225     private void getVnfInstanceName(DelegateExecution execution) {
226         //Get NetworkService modelInvariantUuid
227         String  networkServiceModelUuid = execution.getVariable("networkServiceModelUuid")
228         String json = catalogDbUtils.getServiceResourcesByServiceModelUuid(execution, networkServiceModelUuid, "v2")
229         logger.debug("json returned: "+json)
230         logger.debug(("Service Vnfs JSON: "+jsonUtil.getJsonValue(json, "serviceResources.serviceVnfs")))
231         List serviceVnfs = jsonUtil.StringArrayToList(jsonUtil.getJsonValue(json, "serviceResources.serviceVnfs"))
232         String networkServiceVnfJson = serviceVnfs.get(0)
233         String vnfInstanceName = (jsonUtil.getJsonValue(networkServiceVnfJson, "modelInfo.modelInstanceName")).replace(" ","") ?: ""
234         execution.setVariable("vnfInstanceName", vnfInstanceName)
235     }
236
237     private List retrieveServiceCharacteristicsAsKeyValue(DelegateExecution execution, Map serviceCharacteristics) {
238         logger.debug(Prefix+ " **** Enter DoAllocateCoreNonSharedSlice ::: retrieveServiceCharacteristicsAsKeyValue ****")
239         List serviceCharacteristicsList = new ArrayList()
240         ObjectMapper mapperObj = new ObjectMapper();
241         String vnfInstanceName = execution.getVariable("vnfInstanceName")
242         Map<String, Object> serviceCharacteristicsObject = new LinkedHashMap()
243         for (Map.Entry<String, Integer> entry : serviceCharacteristics.entrySet()) {
244             Map<String, Object> ServiceCharacteristicValueObject = new LinkedHashMap<>()
245             System.out.println(entry.getKey() + ":" + entry.getValue());
246             //For G Release we are sending single value from  snssaiList
247             if(entry.getKey().equals("snssaiList")) {
248                 List sNssaiValue = entry.getValue()
249                 serviceCharacteristicsObject.put("name", vnfInstanceName+"_snssai")
250                 ServiceCharacteristicValueObject.put("serviceCharacteristicValue", sNssaiValue.get(0))
251                 serviceCharacteristicsObject.put("value", ServiceCharacteristicValueObject)
252             }
253         }
254         serviceCharacteristicsList.add(serviceCharacteristicsObject)
255         logger.debug(Prefix+ " **** Exit DoAllocateCoreNonSharedSlice ::: retrieveServiceCharacteristicsAsKeyValue ****")
256         return serviceCharacteristicsList
257     }
258
259     public void postNBIServiceOrder(DelegateExecution execution) {
260         logger.debug(Prefix+ " **** Enter DoAllocateCoreNonSharedSlice ::: postNBIServiceOrder ****")
261         String msg=""
262         try {
263             String extAPIPath = execution.getVariable("ExternalAPIURL")
264             String payload = execution.getVariable("serviceOrderRequest")
265             logger.debug("externalAPIURL is: " + extAPIPath)
266             logger.debug("ServiceOrder payload is: " + payload)
267             ExternalAPIUtil externalAPIUtil = new ExternalAPIUtilFactory().create()
268             execution.setVariable("ServiceOrderId", "")
269             Response response = externalAPIUtil.executeExternalAPIPostCall(execution, extAPIPath, payload)
270             int responseCode = response.getStatus()
271             execution.setVariable("PostServiceOrderResponseCode", responseCode)
272             logger.debug("Post ServiceOrder response code is: " + responseCode)
273             String extApiResponse = response.readEntity(String.class)
274             JSONObject responseObj = new JSONObject(extApiResponse)
275             execution.setVariable("PostServiceOrderResponse", extApiResponse)
276             logger.debug("ServiceOrder response body is: " + extApiResponse)
277             //Process Response
278             if(responseCode == 200 || responseCode == 201 || responseCode == 202 )
279                 //200 OK 201 CREATED 202 ACCEPTED
280             {
281                 logger.debug("Post ServiceOrder Received a Good Response")
282                 String serviceOrderId = responseObj.get("id")
283                 execution.setVariable("ServiceOrderId", serviceOrderId)
284                 logger.info("Post ServiceOrderid is: " + serviceOrderId)
285             }
286             else{
287                 exceptionUtil.buildAndThrowWorkflowException(execution, responseCode, "Post ServiceOrder Received a bad response from extAPI serviceOrder API")
288             }
289         }catch (BpmnError e) {
290             throw e;
291         } catch (Exception ex) {
292             msg = "Exception in ServiceOrder ExtAPI" + ex.getMessage()
293             logger.debug(msg)
294             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
295         }
296         logger.debug("**** Exit DoAllocateCoreNonSharedSlice ::: postNBIServiceOrder ****")
297     }
298
299     public void getNBIServiceOrderProgress(DelegateExecution execution) {
300         logger.debug(Prefix+ " **** Enter DoAllocateCoreNonSharedSlice ::: getNBIServiceOrderProgress ****")
301         String msg=""
302         try {
303             String extAPIPath = execution.getVariable("ExternalAPIURL")
304             extAPIPath += "/" + execution.getVariable("ServiceOrderId")
305             logger.debug("getNBIServiceOrderProgress externalAPIURL is: " + extAPIPath)
306             ExternalAPIUtil externalAPIUtil = new ExternalAPIUtilFactory().create()
307             Response response = externalAPIUtil.executeExternalAPIGetCall(execution, extAPIPath)
308             int responseCode = response.getStatus()
309             execution.setVariable("GetServiceOrderResponseCode", responseCode)
310             logger.debug("Get ServiceOrder response code is: " + responseCode)
311             String extApiResponse = response.readEntity(String.class)
312             JSONObject responseObj = new JSONObject(extApiResponse)
313             execution.setVariable("GetServiceOrderResponse", extApiResponse)
314             logger.debug("Create response body is: " + extApiResponse)
315             //Process Response //200 OK 201 CREATED 202 ACCEPTED
316             if(responseCode == 200 || responseCode == 201 || responseCode == 202 )
317             {
318                 logger.debug("Get Create ServiceOrder Received a Good Response")
319                 String orderState = responseObj.get("state")
320                 if("REJECTED".equalsIgnoreCase(orderState)) {
321                     prepareFailedOperationStatusUpdate(execution)
322                     return
323                 }
324                 JSONArray items = responseObj.getJSONArray("orderItem")
325                 JSONObject item = items.get(0)
326                 JSONObject service = item.get("service")
327                 String networkServiceId = service.get("id")
328
329                 execution.setVariable("networkServiceId", networkServiceId)
330                 String serviceOrderState = item.get("state")
331                 execution.setVariable("ServiceOrderState", serviceOrderState)
332                 // Get serviceOrder State and process progress
333                 if("ACKNOWLEDGED".equalsIgnoreCase(serviceOrderState) || "INPROGRESS".equalsIgnoreCase(serviceOrderState)) {
334                     execution.setVariable("status", "processing")
335                 }
336                 else if("COMPLETED".equalsIgnoreCase(serviceOrderState)) {
337                     execution.setVariable("status", "completed")
338                 }
339                 else if("FAILED".equalsIgnoreCase(serviceOrderState)) {
340                     msg = "ServiceOrder failed"
341                     exceptionUtil.buildAndThrowWorkflowException(execution, 7000,  msg)
342                 }
343                 else {
344                     msg = "ServiceOrder failed"
345                     exceptionUtil.buildAndThrowWorkflowException(execution, 7000,  msg)
346                 }
347                 logger.debug("NBI serviceOrder state: "+serviceOrderState)
348             }
349             else{
350                 msg = "Get ServiceOrder Received a Bad Response Code. Response Code is: " + responseCode
351                 prepareFailedOperationStatusUpdate(execution)
352             }
353
354         }catch(Exception e){
355             exceptionUtil.buildAndThrowWorkflowException(execution, 7000,  e.getMessage())
356         }
357         logger.debug(Prefix+ " **** Exit DoAllocateCoreNonSharedSlice ::: getNBIServiceOrderProgress ****")
358     }
359
360     public void timeDelay(DelegateExecution execution) {
361         try {
362             logger.debug(Prefix+ " **** DoAllocateCoreNonSharedSlice ::: timeDelay going to sleep for 5 sec")
363             Thread.sleep(5000)
364             logger.debug("**** DoAllocateCoreNonSharedSlice ::: timeDelay wakeup after 5 sec")
365         } catch(InterruptedException e) {
366             logger.error(Prefix+ " **** DoAllocateCoreNonSharedSlice ::: timeDelay exception" + e)
367         }
368     }
369
370     void updateRelationship(DelegateExecution execution) {
371         logger.debug(Prefix+ " **** Enter DoAllocateCoreNonSharedSlice ::: updateRelationship ****")
372         String networkServiceInstanceId = execution.getVariable("networkServiceId")
373         String nssiId = execution.getVariable("nssiServiceInstanceId")
374         String globalCustId = execution.getVariable("globalSubscriberId")
375         String serviceType = execution.getVariable("subscriptionServiceType")
376         logger.debug("networkServiceInstanceId: {},  nssiId: {}, globalCustId: {}, serviceType: {}", networkServiceInstanceId, nssiId, globalCustId, serviceType)
377         try{
378             //Update NSSI orchestration status nssiServiceInstance
379             ServiceInstance si = execution.getVariable("nssiServiceInstance")
380             logger.debug("nssiServiceInstance "+si)
381             si.setOrchestrationStatus("activated")
382             AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalCustId).serviceSubscription(serviceType).serviceInstance(nssiId))
383             logger.debug("uri to call:  "+uri)
384
385             try {
386                 getAAIClient().update(uri, si)
387             } catch (Exception e) {
388                 logger.info("Update OrchestrationStatus in AAI failed")
389                 String msg = "Update OrchestrationStatus in AAI failed, " + e
390                 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
391             }
392             //URI for NSSI
393             AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId));
394             logger.debug("nssiUri to update RelationShip :  "+nssiUri)
395             //URI for Network Service Instance
396             AAIResourceUri networkServiceInstanceUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(networkServiceInstanceId))
397             logger.debug("networkServiceInstanceUri to update RelationShip :  "+networkServiceInstanceUri)
398             // Update Relationship in AAI
399             getAAIClient().connect(nssiUri, networkServiceInstanceUri, AAIEdgeLabel.COMPOSED_OF);
400             //end point update
401             createEndPointsInAai(execution)
402             execution.setVariable("progress", "100")
403             execution.setVariable("status", "finished")
404             execution.setVariable("statusDescription", "DoAllocateCoreNonSharedNSSI success")
405             setResourceOperationStatus(execution)
406         }catch(Exception ex) {
407             String msg = "Exception while creating relationship " + ex.getMessage()
408             logger.info(msg)
409             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
410         }
411         logger.debug(Prefix+ " **** Exit DoAllocateCoreNonSharedSlice ::: updateRelationship ****")
412     }
413
414     /**
415      * creates EndPoints in AAI
416      * @param execution
417      */
418     private void createEndPointsInAai(DelegateExecution execution) {
419         String type = "endpoint"
420         String function = "core_EP"
421         int prefixLength = 24
422         String addressFamily = "ipv4"
423         //BH end point update
424         String bh_endpoint = execution.getVariable("bh_endpoint")
425         String bh_routeId = UUID.randomUUID().toString()
426         execution.setVariable("coreEp_ID_bh", bh_routeId)
427         String role = "CN"
428         String cnIpAddress = jsonUtil.getJsonValue(bh_endpoint, "ipAddress")
429         String LogicalLinkId = jsonUtil.getJsonValue(bh_endpoint, "logicInterfaceId")
430         String nextHopInfo = jsonUtil.getJsonValue(bh_endpoint, "nextHopInfo")
431         NetworkRoute bh_ep = new NetworkRoute()
432         logger.debug("bh_endpoint: {}, bh_routeId: {}, cnIpAddress: {}, role: {}, LogicalLinkId: {}, nextHopInfo: {}, bh_ep: {}", bh_endpoint, bh_routeId, cnIpAddress, role, LogicalLinkId, nextHopInfo, bh_ep)
433         bh_ep.setRouteId(bh_routeId)
434         bh_ep.setFunction(function)
435         bh_ep.setRole(role)
436         bh_ep.setType(type)
437         bh_ep.setIpAddress(cnIpAddress)
438         bh_ep.setLogicalInterfaceId(LogicalLinkId)
439         bh_ep.setNextHop(nextHopInfo)
440         bh_ep.setPrefixLength(prefixLength)
441         bh_ep.setAddressFamily(addressFamily)
442         try {
443             AAIResourcesClient client = new AAIResourcesClient()
444             logger.debug("creating bh endpoint . ID : "+bh_routeId+" node details : "+bh_ep.toString())
445             AAIResourceUri networkRouteUri = AAIUriFactory.createResourceUri( new AAIObjectType(AAINamespaceConstants.NETWORK, NetworkRoute.class), bh_routeId)
446             client.create(networkRouteUri, bh_ep)
447             //relationship b/w bh_ep and Core NSSI
448             String coreNssi = execution.getVariable("nssiServiceInstanceId")
449             String globalSubscriberId = execution.getVariable("globalSubscriberId")
450             String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
451             Relationship relationship = new Relationship()
452             String relatedLink = "aai/v21/network/network-routes/network-route/${bh_routeId}"
453             relationship.setRelatedLink(relatedLink)
454             relationship.setRelatedTo("network-route")
455             relationship.setRelationshipLabel("org.onap.relationships.inventory.ComposedOf")
456             logger.debug("networkRouteUri: {}, relationship: {}",networkRouteUri,relationship)
457             try {
458                 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(coreNssi)).relationshipAPI()
459                 logger.debug("uri: "+uri)
460                 client.create(uri, relationship)
461             } catch (BpmnError e) {
462                 throw e
463             } catch (Exception ex) {
464                 String msg = "Exception in createRelationShipInAAI. " + ex.getMessage()
465                 logger.debug(msg+": "+ex)
466                 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
467             }
468         } catch (BpmnError e) {
469             throw e
470         } catch (Exception ex) {
471             String msg = "Exception in createEndPointsInAai " + ex.getMessage()
472             logger.info(msg)
473             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
474         }
475     }
476
477     private void setResourceOperationStatus(DelegateExecution execution) {
478         logger.debug(Prefix+ " **** Enter DoAllocateCoreNonSharedSlice ::: setResourceOperationStatus ****")
479         String serviceId = execution.getVariable("nsiId")
480         String jobId = execution.getVariable("jobId")
481         String nssiId = execution.getVariable("nssiServiceInstanceId")
482         String operationType = "ALLOCATE"
483         String modelUuid= execution.getVariable("modelUuid")
484         ResourceOperationStatus resourceOperationStatus = new ResourceOperationStatus()
485         resourceOperationStatus.setServiceId(serviceId)
486         resourceOperationStatus.setJobId(jobId)
487         resourceOperationStatus.setOperationId(jobId)
488         resourceOperationStatus.setResourceTemplateUUID(modelUuid)
489         resourceOperationStatus.setResourceInstanceID(nssiId)
490         resourceOperationStatus.setOperType(operationType)
491         resourceOperationStatus.setStatus(execution.getVariable("status"))
492         resourceOperationStatus.setProgress(execution.getVariable("progress"))
493         resourceOperationStatus.setStatusDescription(execution.getVariable("statusDescription"))
494         requestDBUtil.prepareUpdateResourceOperationStatus(execution, resourceOperationStatus)
495         logger.debug(Prefix+ " **** Exit DoAllocateCoreNonSharedSlice ::: setResourceOperationStatus ****")
496     }
497
498     void prepareFailedOperationStatusUpdate(DelegateExecution execution){
499         logger.debug(Prefix + " **** Enter DoAllocateCoreNonSharedSlice ::: prepareFailedOperationStatusUpdate ****")
500         String serviceId = execution.getVariable("nsiId")
501         String jobId = execution.getVariable("jobId")
502         String nssiId = execution.getVariable("nssiServiceInstanceId")
503         String operationType = "ALLOCATE"
504         //modelUuid
505         String modelUuid= execution.getVariable("modelUuid")
506         logger.debug("serviceId: {}, jobId: {}, nssiId: {}, operationType: {}.", serviceId, jobId, nssiId, operationType)
507         ResourceOperationStatus resourceOperationStatus = new ResourceOperationStatus()
508         resourceOperationStatus.setServiceId(serviceId)
509         resourceOperationStatus.setJobId(jobId)
510         resourceOperationStatus.setOperationId(jobId)
511         resourceOperationStatus.setResourceInstanceID(nssiId)
512         resourceOperationStatus.setResourceTemplateUUID(modelUuid)
513         resourceOperationStatus.setOperType(operationType)
514         resourceOperationStatus.setProgress("0")
515         resourceOperationStatus.setStatus("failed")
516         resourceOperationStatus.setStatusDescription("Core NSSI Allocate Failed")
517         requestDBUtil.prepareUpdateResourceOperationStatus(execution, resourceOperationStatus)
518         logger.debug(Prefix + " **** Exit DoAllocateCoreNonSharedSlice ::: prepareFailedOperationStatusUpdate ****")
519     }
520 }