aboutsummaryrefslogtreecommitdiffstats
path: root/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoAllocateCoreNonSharedSlice.groovy
blob: 1ca0605ac84c7ab9e1bcf74e599732c6a8fa7739 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
/*-
 * ============LICENSE_START=======================================================
 * ONAP - SO
 * ================================================================================
 * Copyright (C) 2020  Tech Mahindra
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */

package org.onap.so.bpmn.infrastructure.scripts

import com.fasterxml.jackson.databind.ObjectMapper

import groovy.json.JsonOutput

import static org.hamcrest.CoreMatchers.instanceOf

import javax.json.JsonArray
import javax.ws.rs.core.Response
import org.apache.commons.collections.map.HashedMap
import org.apache.commons.lang.StringEscapeUtils
import org.camunda.bpm.engine.delegate.BpmnError
import org.camunda.bpm.engine.delegate.DelegateExecution
import org.json.JSONArray
import org.json.JSONObject
import org.onap.aaiclient.client.aai.AAIResourcesClient
import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
import org.onap.so.bpmn.common.scripts.CatalogDbUtils
import org.onap.so.bpmn.common.scripts.CatalogDbUtilsFactory
import org.onap.so.bpmn.common.scripts.ExceptionUtil
import org.onap.so.bpmn.common.scripts.ExternalAPIUtil
import org.onap.so.bpmn.common.scripts.ExternalAPIUtilFactory
import org.onap.so.bpmn.common.scripts.RequestDBUtil
import org.onap.so.db.request.beans.OperationStatus
import org.onap.so.db.request.beans.ResourceOperationStatus
import org.onap.so.client.HttpClient
import org.onap.so.client.HttpClientFactory
import org.onap.logging.filter.base.ONAPComponents
import org.onap.so.bpmn.core.UrnPropertiesReader
import org.onap.aai.domain.yang.NetworkRoute
import org.onap.aai.domain.yang.v19.ServiceInstance
import org.onap.aai.domain.yang.v20.Relationship
import org.onap.aaiclient.client.aai.AAIObjectType
import org.onap.aaiclient.client.aai.entities.AAIResultWrapper
import org.onap.aaiclient.client.aai.entities.AAIEdgeLabel
import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types
import org.onap.so.bpmn.core.domain.ServiceDecomposition
import org.onap.so.bpmn.core.domain.ServiceProxy
import org.onap.so.bpmn.core.json.JsonUtils
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.http.HttpEntity
import org.onap.aai.domain.yang.NetworkPolicy
import org.onap.aaiclient.client.aai.AAINamespaceConstants

import javax.ws.rs.NotFoundException

class DoAllocateCoreNonSharedSlice extends AbstractServiceTaskProcessor {
    String Prefix="DACNSNSSI_"
    private static final Logger logger = LoggerFactory.getLogger( DoAllocateCoreNonSharedSlice.class);
    private CatalogDbUtils catalogDbUtils = new CatalogDbUtilsFactory().create()
    private RequestDBUtil requestDBUtil = new RequestDBUtil()
    private ExceptionUtil exceptionUtil = new ExceptionUtil()
    private JsonUtils jsonUtil = new JsonUtils()

    @Override
    public void preProcessRequest(DelegateExecution execution) {
        logger.debug(Prefix+ "**** Enter DoAllocateCoreNonSharedSlice:::  preProcessRequest ****")
        String nssiServiceInstanceId= execution.getVariable("serviceInstanceId")
        logger.debug("nssiServiceInstanceId:  "+nssiServiceInstanceId)
        execution.setVariable("nssiServiceInstanceId", nssiServiceInstanceId)
        //Set orchestration-status as created
        execution.setVariable("orchestrationStatus", "created")
        //networkServiceName
        String networkServiceName = jsonUtil.getJsonValue(execution.getVariable("networkServiceModelInfo"), "modelInfo.modelName") ?: ""
        execution.setVariable("networkServiceName", networkServiceName.replaceAll(" Service Proxy", ""))
        //networkServiceModelUuid
        logger.debug("networkServiceName:  "+networkServiceName)
        String networkServiceModelUuid = jsonUtil.getJsonValue(execution.getVariable("networkServiceModelInfo"), "sourceModelUuid") ?: ""
        execution.setVariable("networkServiceModelUuid", networkServiceModelUuid)
        String sliceParams = execution.getVariable("sliceParams")
        logger.debug("sliceParams "+sliceParams)
        List<String> bhEndPoints = jsonUtil.StringArrayToList(jsonUtil.getJsonValue(sliceParams, "endPoints"))
        if(bhEndPoints.empty) {
            logger.debug("End point info is empty")
            exceptionUtil.buildAndThrowWorkflowException(execution, 500, "End point info is empty")
        }else {
            execution.setVariable("bh_endpoint", bhEndPoints.get(0))
        }
        logger.debug(Prefix+ " **** Exit DoAllocateCoreNonSharedSlice:::  preProcessRequest ****")
    }

    void createNSSIinAAI(DelegateExecution execution) {
        logger.debug(Prefix+ " ****  Enter DoAllocateCoreNonSharedSlice ::: Enter createNSSIinAAI ****")
        String msg=""
        String serviceInstanceId= execution.getVariable("nssiServiceInstanceId")
        logger.debug("ServiceInstanceId: "+serviceInstanceId)
        try {
            String serviceType = execution.getVariable("subscriptionServiceType")
            String oStatus = execution.getVariable("orchestrationStatus")
            //Get workload context and environment context from DB
            String environmentContext = ""
            String workloadContext =""
            String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
            try{
                String json = catalogDbUtils.getServiceResourcesByServiceModelInvariantUuidString(execution,modelInvariantUuid )
                logger.debug("JSON Response from DB: "+json)
                environmentContext = jsonUtil.getJsonValue(json, "serviceResources.environmentContext") ?: ""
                workloadContext = jsonUtil.getJsonValue(json, "serviceResources.workloadContext") ?: ""
                logger.debug("Env Context is: "+ environmentContext)
                logger.debug("Workload Context is: "+ workloadContext)
            } catch(BpmnError e){
                throw e
            } catch (Exception ex){
                msg = "Exception in createNSSIinAAI ::: DoAllocateCoreNonSharedSlice  " + ex.getMessage()
                logger.debug(msg)
                exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
            }
            String serviceInstanceName = "nssi_"+execution.getVariable("nsstName")
            ServiceInstance si = new ServiceInstance()
            si.setServiceInstanceId(execution.getVariable("nssiServiceInstanceId"))
            si.setServiceInstanceName(serviceInstanceName)
            si.setServiceType(serviceType)
            si.setServiceRole("nssi")
            si.setOrchestrationStatus(oStatus)
            si.setModelInvariantId(modelInvariantUuid)
            si.setModelVersionId(execution.getVariable("modelUuid"))
            si.setEnvironmentContext(environmentContext)
            si.setWorkloadContext(workloadContext)
            logger.debug("AAI service Instance Request Payload : "+si.toString())
            AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(execution.getVariable("globalSubscriberId")).serviceSubscription(serviceType).serviceInstance(serviceInstanceId))
            getAAIClient().create(uri, si)

            execution.setVariable("nssiServiceInstance", si)
        } catch (BpmnError e) {
            throw e;
        } catch (Exception ex) {
            msg = "Exception in create AAI Instance" + ex.getMessage()
            logger.debug(msg)
            exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
        }
        getVnfInstanceName(execution)
        logger.debug(Prefix+ " Exit DoAllocateCoreNonSharedSlice ::: Enter createNSSIinAAI ****")
    }

    public void prepareServiceOrderRequest(DelegateExecution execution) {
        logger.debug("**** Enter DoAllocateCoreNonSharedSlice :::  prepareServiceOrderRequest ****")
        //extAPI path hardcoded for testing purposes, will be updated in next patch
        String extAPIPath = "https://nbi.onap:8443/nbi/api/v4" + "/serviceOrder"
        execution.setVariable("ExternalAPIURL", extAPIPath)
        ObjectMapper objectMapper = new ObjectMapper();
        Map<String, Object> serviceOrder = new LinkedHashMap()
        //ExternalId
        serviceOrder.put("externalId", "ONAP001")
        //Requested Start Date
        String requestedStartDate = utils.generateCurrentTimeInUtc()
        String requestedCompletionDate = utils.generateCurrentTimeInUtc()
        serviceOrder.put("requestedStartDate", requestedStartDate)
        serviceOrder.put("requestedCompletionDate", requestedCompletionDate)
        //RelatedParty Fields
        String relatedPartyId = execution.getVariable("globalSubscriberId")
        String relatedPartyRole = "ONAPcustomer"
        Map<String, String> relatedParty = new LinkedHashMap()
        relatedParty.put("id", relatedPartyId)
        relatedParty.put("role", relatedPartyRole)
        List<Map<String, String>> relatedPartyList = new ArrayList()
        relatedPartyList.add(relatedParty)
        serviceOrder.put("relatedParty", relatedPartyList)
        Map<String, Object> orderItem = new LinkedHashMap()
        //orderItem id
        String orderItemId = "1"
        orderItem.put("id", orderItemId)
        //order item action will always be add as we are triggering request for instantiation
        String orderItemAction = "add"
        orderItem.put("action", orderItemAction)
        // service Details
        Map<String, Object> service = new LinkedHashMap()
        //ServiceName
        String serviceName= "ns_"+execution.getVariable("networkServiceName")+"_"+execution.getVariable("serviceInstanceId")
        service.put("name",  serviceName)
        // Service Type
        service.put("serviceType", execution.getVariable("subscriptionServiceType"))
        //Service State
        service.put("serviceState", "active")
        Map<String, String> serviceSpecification = new LinkedHashMap()
        serviceSpecification.put("id", execution.getVariable("networkServiceModelUuid"))
        service.put("serviceSpecification", serviceSpecification)
        //serviceCharacteristic List
        List serviceCharacteristicList = new ArrayList()
        Map<String, Object> serviceCharacteristic = objectMapper.readValue(execution.getVariable("sliceProfile"), Map.class);
        List serviceCharacteristicListMap = retrieveServiceCharacteristicsAsKeyValue(execution, serviceCharacteristic)
        logger.debug("serviceCharacteristicListMap  "+serviceCharacteristicListMap)
        serviceCharacteristicList.add(serviceCharacteristic)
        //service.put("serviceCharacteristic", serviceCharacteristicList)
        service.put("serviceCharacteristic", serviceCharacteristicListMap)
        orderItem.put("service", service)
        List<Map<String, String>> orderItemList = new ArrayList()
        orderItemList.add(orderItem)
        serviceOrder.put("orderItem", orderItemList)
        String jsonServiceOrder = objectMapper.writeValueAsString(serviceOrder);
        logger.debug("******* ServiceOrder :: "+jsonServiceOrder)
        execution.setVariable("serviceOrderRequest", jsonServiceOrder)
        logger.debug(Prefix+ " **** Exit DoAllocateCoreNonSharedSlice ::: prepareServiceOrderRequest****")
    }

    private void getVnfInstanceName(DelegateExecution execution) {
        //Get NetworkService modelInvariantUuid
        String  networkServiceModelUuid = execution.getVariable("networkServiceModelUuid")
        String json = catalogDbUtils.getServiceResourcesByServiceModelUuid(execution, networkServiceModelUuid, "v2")
        logger.debug("json returned: "+json)
        logger.debug(("Service Vnfs JSON: "+jsonUtil.getJsonValue(json, "serviceResources.serviceVnfs")))
        List serviceVnfs = jsonUtil.StringArrayToList(jsonUtil.getJsonValue(json, "serviceResources.serviceVnfs"))
        String networkServiceVnfJson = serviceVnfs.get(0)
        String vnfInstanceName = (jsonUtil.getJsonValue(networkServiceVnfJson, "modelInfo.modelInstanceName")).trim() ?: ""
        execution.setVariable("vnfInstanceName", vnfInstanceName)
    }

    private List retrieveServiceCharacteristicsAsKeyValue(DelegateExecution execution, Map serviceCharacteristics) {
        logger.debug(Prefix+ " **** Enter DoAllocateCoreNonSharedSlice ::: retrieveServiceCharacteristicsAsKeyValue ****")
        List serviceCharacteristicsList = new ArrayList()
        ObjectMapper mapperObj = new ObjectMapper();
        String vnfInstanceName = execution.getVariable("vnfInstanceName")
        Map<String, Object> serviceCharacteristicsObject = new LinkedHashMap()
        for (Map.Entry<String, Integer> entry : serviceCharacteristics.entrySet()) {
            Map<String, Object> ServiceCharacteristicValueObject = new LinkedHashMap<>()
            System.out.println(entry.getKey() + ":" + entry.getValue());
            //For G Release we are sending single value from  snssaiList
            if(entry.getKey().equals("snssaiList")) {
                List sNssaiValue = entry.getValue()
                serviceCharacteristicsObject.put("name", vnfInstanceName+"_snssai")
                ServiceCharacteristicValueObject.put("serviceCharacteristicValue", sNssaiValue.get(0))
                serviceCharacteristicsObject.put("value", ServiceCharacteristicValueObject)
            }
        }
        serviceCharacteristicsList.add(serviceCharacteristicsObject)
        logger.debug(Prefix+ " **** Exit DoAllocateCoreNonSharedSlice ::: retrieveServiceCharacteristicsAsKeyValue ****")
        return serviceCharacteristicsList
    }

    public void postNBIServiceOrder(DelegateExecution execution) {
        logger.debug(Prefix+ " **** Enter DoAllocateCoreNonSharedSlice ::: postNBIServiceOrder ****")
        String msg=""
        try {
            String extAPIPath = execution.getVariable("ExternalAPIURL")
            String payload = execution.getVariable("serviceOrderRequest")
            logger.debug("externalAPIURL is: " + extAPIPath)
            logger.debug("ServiceOrder payload is: " + payload)
            ExternalAPIUtil externalAPIUtil = new ExternalAPIUtilFactory().create()
            execution.setVariable("ServiceOrderId", "")
            Response response = externalAPIUtil.executeExternalAPIPostCall(execution, extAPIPath, payload)
            int responseCode = response.getStatus()
            execution.setVariable("PostServiceOrderResponseCode", responseCode)
            logger.debug("Post ServiceOrder response code is: " + responseCode)
            String extApiResponse = response.readEntity(String.class)
            JSONObject responseObj = new JSONObject(extApiResponse)
            execution.setVariable("PostServiceOrderResponse", extApiResponse)
            logger.debug("ServiceOrder response body is: " + extApiResponse)
            //Process Response
            if(responseCode == 200 || responseCode == 201 || responseCode == 202 )
                //200 OK 201 CREATED 202 ACCEPTED
            {
                logger.debug("Post ServiceOrder Received a Good Response")
                String serviceOrderId = responseObj.get("id")
                execution.setVariable("ServiceOrderId", serviceOrderId)
                logger.info("Post ServiceOrderid is: " + serviceOrderId)
            }
            else{
                exceptionUtil.buildAndThrowWorkflowException(execution, responseCode, "Post ServiceOrder Received a bad response from extAPI serviceOrder API")
            }
        }catch (BpmnError e) {
            throw e;
        } catch (Exception ex) {
            msg = "Exception in ServiceOrder ExtAPI" + ex.getMessage()
            logger.debug(msg)
            exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
        }
        logger.debug("**** Exit DoAllocateCoreNonSharedSlice ::: postNBIServiceOrder ****")
    }

    public void getNBIServiceOrderProgress(DelegateExecution execution) {
        logger.debug(Prefix+ " **** Enter DoAllocateCoreNonSharedSlice ::: getNBIServiceOrderProgress ****")
        String msg=""
        try {
            String extAPIPath = execution.getVariable("ExternalAPIURL")
            extAPIPath += "/" + execution.getVariable("ServiceOrderId")
            logger.debug("getNBIServiceOrderProgress externalAPIURL is: " + extAPIPath)
            ExternalAPIUtil externalAPIUtil = new ExternalAPIUtilFactory().create()
            Response response = externalAPIUtil.executeExternalAPIGetCall(execution, extAPIPath)
            int responseCode = response.getStatus()
            execution.setVariable("GetServiceOrderResponseCode", responseCode)
            logger.debug("Get ServiceOrder response code is: " + responseCode)
            String extApiResponse = response.readEntity(String.class)
            JSONObject responseObj = new JSONObject(extApiResponse)
            execution.setVariable("GetServiceOrderResponse", extApiResponse)
            logger.debug("Create response body is: " + extApiResponse)
            //Process Response //200 OK 201 CREATED 202 ACCEPTED
            if(responseCode == 200 || responseCode == 201 || responseCode == 202 )
            {
                logger.debug("Get Create ServiceOrder Received a Good Response")
                String orderState = responseObj.get("state")
                if("REJECTED".equalsIgnoreCase(orderState)) {
                    prepareFailedOperationStatusUpdate(execution)
                    return
                }
                JSONArray items = responseObj.getJSONArray("orderItem")
                JSONObject item = items.get(0)
                JSONObject service = item.get("service")
                String networkServiceId = service.get("id")

                execution.setVariable("networkServiceId", networkServiceId)
                String serviceOrderState = item.get("state")
                execution.setVariable("ServiceOrderState", serviceOrderState)
                // Get serviceOrder State and process progress
                if("ACKNOWLEDGED".equalsIgnoreCase(serviceOrderState) || "INPROGRESS".equalsIgnoreCase(serviceOrderState)) {
                    execution.setVariable("status", "processing")
                }
                else if("COMPLETED".equalsIgnoreCase(serviceOrderState)) {
                    execution.setVariable("status", "completed")
                }
                else if("FAILED".equalsIgnoreCase(serviceOrderState)) {
                    msg = "ServiceOrder failed"
                    exceptionUtil.buildAndThrowWorkflowException(execution, 7000,  msg)
                }
                else {
                    msg = "ServiceOrder failed"
                    exceptionUtil.buildAndThrowWorkflowException(execution, 7000,  msg)
                }
                logger.debug("NBI serviceOrder state: "+serviceOrderState)
            }
            else{
                msg = "Get ServiceOrder Received a Bad Response Code. Response Code is: " + responseCode
                prepareFailedOperationStatusUpdate(execution)
            }

        }catch(Exception e){
            exceptionUtil.buildAndThrowWorkflowException(execution, 7000,  e.getMessage())
        }
        logger.debug(Prefix+ " **** Exit DoAllocateCoreNonSharedSlice ::: getNBIServiceOrderProgress ****")
    }

    public void timeDelay(DelegateExecution execution) {
        try {
            logger.debug(Prefix+ " **** DoAllocateCoreNonSharedSlice ::: timeDelay going to sleep for 5 sec")
            Thread.sleep(5000)
            logger.debug("**** DoAllocateCoreNonSharedSlice ::: timeDelay wakeup after 5 sec")
        } catch(InterruptedException e) {
            logger.error(Prefix+ " **** DoAllocateCoreNonSharedSlice ::: timeDelay exception" + e)
        }
    }

    void updateRelationship(DelegateExecution execution) {
        logger.debug(Prefix+ " **** Enter DoAllocateCoreNonSharedSlice ::: updateRelationship ****")
        String networkServiceInstanceId = execution.getVariable("networkServiceId")
        String nssiId = execution.getVariable("nssiServiceInstanceId")
        String globalCustId = execution.getVariable("globalSubscriberId")
        String serviceType = execution.getVariable("subscriptionServiceType")
        logger.debug("networkServiceInstanceId:  "+networkServiceInstanceId +" nssiId:  "+nssiId  +" globalCustId:  "+globalCustId+  " serviceType:  "+serviceType)
        try{
            //Update NSSI orchestration status nssiServiceInstance
            ServiceInstance si = execution.getVariable("nssiServiceInstance")
            logger.debug("nssiServiceInstance "+si)
            si.setOrchestrationStatus("activated")
            AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalCustId).serviceSubscription(serviceType).serviceInstance(nssiId))
            logger.debug("uri to call:  "+uri)

            try {
                getAAIClient().update(uri, si)
            } catch (Exception e) {
                logger.info("Update OrchestrationStatus in AAI failed")
                String msg = "Update OrchestrationStatus in AAI failed, " + e
                exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
            }
            //URI for NSSI
            AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId));
            logger.debug("nssiUri to update RelationShip :  "+nssiUri)
            //URI for Network Service Instance
            AAIResourceUri networkServiceInstanceUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(networkServiceInstanceId))
            logger.debug("networkServiceInstanceUri to update RelationShip :  "+networkServiceInstanceUri)
            // Update Relationship in AAI
            getAAIClient().connect(nssiUri, networkServiceInstanceUri, AAIEdgeLabel.COMPOSED_OF);
            //end point update
            createEndPointsInAai(execution)
            execution.setVariable("progress", "100")
            execution.setVariable("status", "finished")
            execution.setVariable("statusDescription", "DoAllocateCoreNonSharedNSSI success")
            setResourceOperationStatus(execution)
        }catch(Exception ex) {
            String msg = "Exception while creating relationship " + ex.getMessage()
            logger.info(msg)
            exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
        }
        logger.debug(Prefix+ " **** Exit DoAllocateCoreNonSharedSlice ::: updateRelationship ****")
    }

    /**
     * creates EndPoints in AAI
     * @param execution
     */
    private void createEndPointsInAai(DelegateExecution execution) {
        String type = "endpoint"
        String function = "core_EP"
        int prefixLength = 24
        String addressFamily = "ipv4"
        //BH end point update
        String bh_endpoint = execution.getVariable("bh_endpoint")
        String bh_routeId = UUID.randomUUID().toString()
        execution.setVariable("coreEp_ID_bh", bh_routeId)
        String role = "CN"
        String cnIpAddress = jsonUtil.getJsonValue(bh_endpoint, "IpAddress")
        String LogicalLinkId = jsonUtil.getJsonValue(bh_endpoint, "LogicalLinkId")
        String nextHopInfo = jsonUtil.getJsonValue(bh_endpoint, "nextHopInfo")
        NetworkRoute bh_ep = new NetworkRoute()
        logger.debug("bh_endpoint: "+bh_endpoint  +"  "+ "bh_routeId: "+bh_routeId  +"  "+ "cnIpAddress: "+cnIpAddress  +"   "+ "role: "+role  +"  "+  "cnIpAddress: "+cnIpAddress +"  "+ "LogicalLinkId: "+LogicalLinkId  +"  "+  "nextHopInfo: "+nextHopInfo  +"  "+  "bh_ep: "+bh_ep)
        bh_ep.setRouteId(bh_routeId)
        bh_ep.setFunction(function)
        bh_ep.setRole(role)
        bh_ep.setType(type)
        bh_ep.setIpAddress(cnIpAddress)
        bh_ep.setLogicalInterfaceId(LogicalLinkId)
        bh_ep.setNextHop(nextHopInfo)
        bh_ep.setPrefixLength(prefixLength)
        bh_ep.setAddressFamily(addressFamily)
        try {
            AAIResourcesClient client = new AAIResourcesClient()
            logger.debug("creating bh endpoint . ID : "+bh_routeId+" node details : "+bh_ep.toString())
            AAIResourceUri networkRouteUri = AAIUriFactory.createResourceUri( new AAIObjectType(AAINamespaceConstants.NETWORK, NetworkRoute.class), bh_routeId)
            client.create(networkRouteUri, bh_ep)
            //relationship b/w bh_ep and Core NSSI
            def coreNssi = execution.getVariable("nssiServiceInstanceId")
            Relationship relationship = new Relationship()
            String relatedLink = "aai/v21/network/network-routes/network-route/${bh_routeId}"
            relationship.setRelatedLink(relatedLink)
            relationship.setRelatedTo("network-route")
            relationship.setRelationshipLabel("org.onap.relationships.inventory.ComposedOf")
            logger.debug("networkRouteUri: "+networkRouteUri+"relationship: "+relationship)
            try {
                AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE,
                        execution.getVariable("globalSubscriberId"),
                        execution.getVariable("subscriptionServiceType"),
                        coreNssi).relationshipAPI()
                logger.debug("uri: "+uri)
                client.create(uri, relationship)
            } catch (BpmnError e) {
                throw e
            } catch (Exception ex) {
                String msg = "Exception in createRelationShipInAAI. " + ex.getMessage()
                logger.debug(msg+": "+ex)
                exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
            }
        } catch (BpmnError e) {
            throw e
        } catch (Exception ex) {
            String msg = "Exception in createEndPointsInAai " + ex.getMessage()
            logger.info(msg)
            exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
        }
    }

    private void setResourceOperationStatus(DelegateExecution execution) {
        logger.debug(Prefix+ " **** Enter DoAllocateCoreNonSharedSlice ::: setResourceOperationStatus ****")
        String serviceId = execution.getVariable("nsiId")
        String jobId = execution.getVariable("jobId")
        String nsiId = execution.getVariable("nsiId")
        String operationType = "ALLOCATE"
        ResourceOperationStatus resourceOperationStatus = new ResourceOperationStatus()
        resourceOperationStatus.setServiceId(serviceId)
        resourceOperationStatus.setOperationId(jobId)
        resourceOperationStatus.setResourceTemplateUUID(nsiId)
        resourceOperationStatus.setResourceInstanceID(nssiId)
        resourceOperationStatus.setOperType(operationType)
        resourceOperationStatus.setStatus(execution.getVariable("status"))
        resourceOperationStatus.setProgress(execution.getVariable("progress"))
        resourceOperationStatus.setStatusDescription(execution.getVariable("statusDescription"))
        requestDBUtil.prepareUpdateResourceOperationStatus(execution, resourceOperationStatus)
        logger.debug(Prefix+ " **** Exit DoAllocateCoreNonSharedSlice ::: setResourceOperationStatus ****")
    }

    void prepareFailedOperationStatusUpdate(DelegateExecution execution){
        logger.debug(Prefix + " **** Enter DoAllocateCoreNonSharedSlice ::: prepareFailedOperationStatusUpdate ****")
        String serviceId = execution.getVariable("nsiId")
        String jobId = execution.getVariable("jobId")
        String nsiId = execution.getVariable("nsiId")
        String nssiId = execution.getVariable("nssiId")
        String operationType = "ALLOCATE"
        //modelUuid
        String modelUuid= execution.getVariable("modelUuid")
        logger.debug("serviceId: "+serviceId +"  "+ "jobId: "+jobId   +"  "+  "nsiId: "+nsiId +"   "+  "operationType: "+operationType)
        ResourceOperationStatus resourceOperationStatus = new ResourceOperationStatus()
        resourceOperationStatus.setServiceId(serviceId)
        resourceOperationStatus.setJobId(jobId)
        resourceOperationStatus.setOperationId(jobId)
        resourceOperationStatus.setResourceTemplateUUID(modelUuid)
        resourceOperationStatus.setOperType(operationType)
        resourceOperationStatus.setProgress("0")
        resourceOperationStatus.setStatus("failed")
        resourceOperationStatus.setStatusDescription("Core NSSI Allocate Failed")
        requestDBUtil.prepareUpdateResourceOperationStatus(execution, resourceOperationStatus)
        logger.debug(Prefix + " **** Exit DoAllocateCoreNonSharedSlice ::: prepareFailedOperationStatusUpdate ****")
    }
}