2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.bpmn.infrastructure.scripts
23 import com.fasterxml.jackson.databind.ObjectMapper
24 import groovy.json.JsonSlurper
25 import org.camunda.bpm.engine.delegate.BpmnError
26 import org.camunda.bpm.engine.delegate.DelegateExecution
27 import org.onap.aai.domain.yang.ServiceInstance
28 import org.onap.aai.domain.yang.SliceProfile
29 import org.onap.aaiclient.client.aai.AAIObjectType
30 import org.onap.aaiclient.client.aai.AAIResourcesClient
31 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
32 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
33 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
34 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types
35 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
36 import org.onap.so.bpmn.common.scripts.ExceptionUtil
37 import org.onap.so.bpmn.common.scripts.RequestDBUtil
38 import org.onap.so.bpmn.core.json.JsonUtils
39 import org.onap.so.db.request.beans.ResourceOperationStatus
40 import org.slf4j.Logger
41 import org.slf4j.LoggerFactory
43 import static org.apache.commons.lang3.StringUtils.isBlank
45 public class DoModifyTnNssi extends AbstractServiceTaskProcessor {
46 String Prefix = "TNMOD_"
48 ExceptionUtil exceptionUtil = new ExceptionUtil()
49 JsonUtils jsonUtil = new JsonUtils()
50 RequestDBUtil requestDBUtil = new RequestDBUtil()
51 TnNssmfUtils tnNssmfUtils = new TnNssmfUtils()
52 JsonSlurper jsonSlurper = new JsonSlurper()
53 ObjectMapper objectMapper = new ObjectMapper()
54 private static final Logger logger = LoggerFactory.getLogger(DoModifyTnNssi.class)
57 void preProcessRequest(DelegateExecution execution) {
58 logger.debug("Start preProcessRequest")
59 execution.setVariable("prefix", Prefix)
63 execution.setVariable("startTime", System.currentTimeMillis())
64 msg = tnNssmfUtils.getExecutionInputParams(execution)
65 logger.debug("Modify TN NSSI input parameters: " + msg)
67 execution.setVariable("prefix", Prefix)
69 tnNssmfUtils.setSdncCallbackUrl(execution, true)
70 logger.debug("SDNC Callback URL: " + execution.getVariable("sdncCallbackUrl"))
72 String additionalPropJsonStr = execution.getVariable("sliceParams")
74 String sliceServiceInstanceId = execution.getVariable("serviceInstanceID")
75 execution.setVariable("sliceServiceInstanceId", sliceServiceInstanceId)
77 String sliceServiceInstanceName = execution.getVariable("servicename")
78 execution.setVariable("sliceServiceInstanceName", sliceServiceInstanceName)
80 String operationId = UUID.randomUUID().toString()
81 execution.setVariable("operationId", operationId)
83 String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
84 String modelUuid = execution.getVariable("modelUuid")
85 //here modelVersion is not set, we use modelUuid to decompose the service.
86 def isDebugLogEnabled = true
87 execution.setVariable("isDebugLogEnabled", isDebugLogEnabled)
88 String serviceModelInfo = """{
89 "modelInvariantUuid":"${modelInvariantUuid}",
90 "modelUuid":"${modelUuid}",
93 execution.setVariable("serviceModelInfo", serviceModelInfo)
95 //additional properties
96 String sliceProfile = jsonUtil.getJsonValue(additionalPropJsonStr, "sliceProfile")
97 if (isBlank(sliceProfile)) {
98 msg = "Input sliceProfile is null"
100 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
102 execution.setVariable("sliceProfile", sliceProfile)
105 String transportSliceNetworks = jsonUtil.getJsonValue(additionalPropJsonStr, "transportSliceNetworks")
106 if (isBlank(transportSliceNetworks)) {
107 msg = "Input transportSliceNetworks is null"
109 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
111 execution.setVariable("transportSliceNetworks", transportSliceNetworks)
113 logger.debug("transportSliceNetworks: " + transportSliceNetworks)
115 String nsiInfo = jsonUtil.getJsonValue(additionalPropJsonStr, "nsiInfo")
116 if (isBlank(nsiInfo)) {
117 msg = "Input nsiInfo is null"
119 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
121 execution.setVariable("nsiInfo", nsiInfo)
124 if (isBlank(tnNssmfUtils.setExecVarFromJsonIfExists(execution, additionalPropJsonStr,
125 "enableSdnc", "enableSdnc"))) {
126 tnNssmfUtils.setEnableSdncConfig(execution)
128 } catch (BpmnError e) {
130 } catch (Exception ex) {
131 msg = "Exception in preProcessRequest " + ex.getMessage()
133 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
135 logger.debug("Finish preProcessRequest")
139 void deleteServiceInstance(DelegateExecution execution) {
141 AAIResourcesClient client = getAAIClient()
142 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(execution.getVariable("globalSubscriberId")).serviceSubscription(execution.getVariable("subscriptionServiceType")).serviceInstance(execution.getVariable("serviceInstanceID")))
144 } catch (BpmnError e) {
146 } catch (Exception ex) {
147 String msg = "Exception in DoDeallocateTnNssi.deleteServiceInstance. " + ex.getMessage()
149 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
154 void getExistingServiceInstance(DelegateExecution execution) {
155 String serviceInstanceId = execution.getVariable("serviceInstanceID")
157 AAIResourcesClient resourceClient = getAAIClient()
158 AAIResourceUri ssServiceuri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(serviceInstanceId))
161 if (resourceClient.exists(ssServiceuri)) {
162 execution.setVariable("ssi_resourceLink", ssServiceuri.build().toString())
163 org.onap.aai.domain.yang.ServiceInstance ss =
164 resourceClient.get(org.onap.aai.domain.yang.ServiceInstance.class, ssServiceuri)
165 org.onap.aai.domain.yang.SliceProfile sliceProfile = ss.getSliceProfiles().getSliceProfile().get(0)
166 execution.setVariable("sliceProfileId", sliceProfile.getProfileId())
168 org.onap.aai.domain.yang.AllottedResources ars = ss.getAllottedResources()
169 List<org.onap.aai.domain.yang.AllottedResource> arList = ars.getAllottedResource()
170 List<String> arIdList = new ArrayList<>()
171 for (org.onap.aai.domain.yang.AllottedResource ar : arList) {
172 String arId = ar.getId()
175 execution.setVariable("arIdList", arIdList)
177 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Service instance was not found in aai to " +
178 "associate allotted resource for service :" + serviceInstanceId)
180 } catch (BpmnError e) {
182 } catch (Exception ex) {
183 String msg = "Exception in getServiceInstance. " + ex.getMessage()
185 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
190 public void updateTnNssiInAAI(DelegateExecution execution) {
191 getExistingServiceInstance(execution)
193 updateServiceInstance(execution)
194 updateSliceProfile(execution)
195 updateAllottedResource(execution)
198 void updateServiceInstance(DelegateExecution execution) {
199 String serviceRole = "TN"
200 String serviceType = execution.getVariable("subscriptionServiceType")
201 String sliceProfileStr = execution.getVariable("sliceProfile")
202 String ssInstanceId = execution.getVariable("sliceServiceInstanceId")
204 org.onap.aai.domain.yang.ServiceInstance ss = new org.onap.aai.domain.yang.ServiceInstance()
205 ss.setServiceInstanceId(ssInstanceId)
206 String sliceInstanceName = execution.getVariable("sliceServiceInstanceName")
207 ss.setServiceInstanceName(sliceInstanceName)
208 ss.setServiceType(serviceType)
209 String serviceStatus = "modified"
210 ss.setOrchestrationStatus(serviceStatus)
211 String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
212 String modelUuid = execution.getVariable("modelUuid")
213 ss.setModelInvariantId(modelInvariantUuid)
214 ss.setModelVersionId(modelUuid)
215 String serviceInstanceLocationid = tnNssmfUtils.getFirstPlmnIdFromSliceProfile(sliceProfileStr)
216 ss.setServiceInstanceLocationId(serviceInstanceLocationid)
217 String snssai = tnNssmfUtils.getFirstSnssaiFromSliceProfile(sliceProfileStr)
218 ss.setEnvironmentContext(snssai)
219 ss.setServiceRole(serviceRole)
220 AAIResourcesClient client = getAAIClient()
221 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(execution.getVariable("globalSubscriberId")).serviceSubscription(execution.getVariable("subscriptionServiceType")).serviceInstance(ssInstanceId))
222 client.update(uri, ss)
223 } catch (BpmnError e) {
225 } catch (Exception ex) {
226 String msg = "Exception in DoCreateTnNssiInstance.createServiceInstance. " + ex.getMessage()
228 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
232 void updateSliceProfile(DelegateExecution execution) {
234 String sliceserviceInstanceId = execution.getVariable("sliceServiceInstanceId")
235 String sliceProfileStr = execution.getVariable("sliceProfile")
236 String sliceProfileId = execution.getVariable("sliceProfileId")
237 SliceProfile sliceProfile = new SliceProfile();
238 sliceProfile.setProfileId(sliceProfileId)
239 sliceProfile.setLatency(Integer.parseInt(jsonUtil.getJsonValue(sliceProfileStr, "latency")))
240 sliceProfile.setResourceSharingLevel(jsonUtil.getJsonValue(sliceProfileStr, "resourceSharingLevel"))
241 sliceProfile.setSNssai(tnNssmfUtils.getFirstSnssaiFromSliceProfile(sliceProfileStr)) //TODO: should be list
243 sliceProfile.setE2ELatency(Integer.parseInt(jsonUtil.getJsonValue(sliceProfileStr, "latency")))
244 sliceProfile.setMaxBandwidth(Integer.parseInt(jsonUtil.getJsonValue(sliceProfileStr, "maxBandwidth")))
247 sliceProfile.setReliability(new Object())
249 AAIResourcesClient client = getAAIClient()
250 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(execution.getVariable("globalSubscriberId")).serviceSubscription(execution.getVariable("subscriptionServiceType")).serviceInstance(sliceserviceInstanceId).sliceProfile(sliceProfileId))
251 client.update(uri, sliceProfile)
253 } catch (BpmnError e) {
255 } catch (Exception ex) {
256 String msg = "Exception in updateSliceProfile. " + ex.getMessage()
258 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
262 void updateAllottedResource(DelegateExecution execution) {
263 String serviceInstanceId = execution.getVariable('serviceInstanceID')
265 List<String> arIdList = execution.getVariable("arIdList")
267 for (String arId : arIdList) {
268 AAIResourceUri arUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(execution.getVariable("globalSubscriberId")).serviceSubscription(execution.getVariable("subscriptionServiceType")).serviceInstance(serviceInstanceId).allottedResource(arId))
270 getAAIClient().delete(arUri)
273 List<String> networkStrList = jsonUtil.StringArrayToList(execution.getVariable("transportSliceNetworks"))
275 for (String networkStr : networkStrList) {
276 String allottedResourceId = UUID.randomUUID().toString()
277 AAIResourceUri allottedResourceUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(execution.getVariable("globalSubscriberId")).serviceSubscription(execution.getVariable("subscriptionServiceType")).serviceInstance(execution.getVariable("sliceserviceInstanceId")).allottedResource(allottedResourceId))
278 execution.setVariable("allottedResourceUri", allottedResourceUri)
279 String modelInvariantId = execution.getVariable("modelInvariantUuid")
280 String modelVersionId = execution.getVariable("modelUuid")
282 org.onap.aai.domain.yang.AllottedResource resource = new org.onap.aai.domain.yang.AllottedResource()
283 resource.setId(allottedResourceId)
284 resource.setType("TsciNetwork")
285 resource.setAllottedResourceName("network_" + execution.getVariable("sliceServiceInstanceName"))
286 resource.setModelInvariantId(modelInvariantId)
287 resource.setModelVersionId(modelVersionId)
288 getAAIClient().create(allottedResourceUri, resource)
290 String linkArrayStr = jsonUtil.getJsonValue(networkStr, "connectionLinks")
291 createLogicalLinksForAllocatedResource(execution, linkArrayStr, serviceInstanceId, allottedResourceId)
294 } catch (Exception ex) {
295 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "Exception in createAaiAR " + ex.getMessage())
299 void createLogicalLinksForAllocatedResource(DelegateExecution execution,
300 String linkArrayStr, String serviceInstanceId,
301 String allottedResourceId) {
304 List<String> linkStrList = jsonUtil.StringArrayToList(linkArrayStr)
306 for (String linkStr : linkStrList) {
307 String logicalLinkId = UUID.randomUUID().toString()
308 String epA = jsonUtil.getJsonValue(linkStr, "transportEndpointA")
309 String epB = jsonUtil.getJsonValue(linkStr, "transportEndpointB")
310 String modelInvariantId = execution.getVariable("modelInvariantUuid")
311 String modelVersionId = execution.getVariable("modelUuid")
313 org.onap.aai.domain.yang.LogicalLink resource = new org.onap.aai.domain.yang.LogicalLink()
314 resource.setLinkId(logicalLinkId)
315 resource.setLinkName(epA)
316 resource.setLinkName2(epB)
317 resource.setModelInvariantId(modelInvariantId)
318 resource.setModelVersionId(modelVersionId)
320 AAIResourceUri logicalLinkUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().logicalLink(logicalLinkId))
321 getAAIClient().create(logicalLinkUri, resource)
323 } catch (Exception ex) {
324 exceptionUtil.buildAndThrowWorkflowException(execution, 7000,
325 "Exception in createLogicalLinksForAllocatedResource" + ex.getMessage())
330 void preprocessSdncModifyTnNssiRequest(DelegateExecution execution) {
331 def method = getClass().getSimpleName() + '.preprocessSdncModifyTnNssiRequest(' +
332 'execution=' + execution.getId() + ')'
333 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
334 logger.trace('Entered ' + method)
337 String serviceInstanceId = execution.getVariable("serviceInstanceID")
339 String sdncRequest = tnNssmfUtils.buildSDNCRequest(execution, serviceInstanceId, "modify")
341 execution.setVariable("TNNSSMF_SDNCRequest", sdncRequest)
342 logger.debug("Outgoing SDNCRequest is: \n" + sdncRequest)
344 } catch (Exception e) {
345 logger.debug("Exception Occured Processing preprocessSdncModifyTnNssiRequest. Exception is:\n" + e)
346 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during preProcessSDNCActivateRequest Method:\n" + e.getMessage())
348 logger.trace("COMPLETED preprocessSdncModifyTnNssiRequest Process")
352 void validateSDNCResponse(DelegateExecution execution, String response, String method) {
353 tnNssmfUtils.validateSDNCResponse(execution, response, method)
357 void updateAAIOrchStatus(DelegateExecution execution) {
358 logger.debug("Start updateAAIOrchStatus")
359 String sliceServiceInstanceId = execution.getVariable("sliceServiceInstanceId")
360 String orchStatus = execution.getVariable("orchestrationStatus")
363 ServiceInstance si = new ServiceInstance()
364 si.setOrchestrationStatus(orchStatus)
365 AAIResourcesClient client = getAAIClient()
366 AAIResourceUri uri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(sliceServiceInstanceId))
367 client.update(uri, si)
368 } catch (BpmnError e) {
370 } catch (Exception ex) {
371 String msg = "Exception in CreateSliceService.updateAAIOrchStatus " + ex.getMessage()
373 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
376 logger.debug("Finish updateAAIOrchStatus")
379 void prepareUpdateJobStatus(DelegateExecution execution,
382 String statusDescription) {
383 String serviceId = execution.getVariable("serviceInstanceID")
384 String jobId = execution.getVariable("jobId")
385 String nsiId = execution.getVariable("nsiId")
387 ResourceOperationStatus roStatus = new ResourceOperationStatus()
388 roStatus.setServiceId(serviceId)
389 roStatus.setOperationId(jobId)
390 roStatus.setResourceTemplateUUID(nsiId)
391 roStatus.setOperType("Modify")
392 roStatus.setProgress(progress)
393 roStatus.setStatus(status)
394 roStatus.setStatusDescription(statusDescription)
395 requestDBUtil.prepareUpdateResourceOperationStatus(execution, roStatus)