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 org.camunda.bpm.engine.delegate.BpmnError
24 import org.camunda.bpm.engine.delegate.DelegateExecution
25 import org.onap.aai.domain.yang.NetworkPolicy
26 import org.onap.aai.domain.yang.ServiceInstance
27 import org.onap.aaiclient.client.aai.AAIResourcesClient
28 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
29 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
30 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
31 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
32 import org.onap.so.bpmn.common.scripts.ExceptionUtil
33 import org.onap.so.bpmn.common.scripts.RequestDBUtil
34 import org.onap.so.bpmn.core.json.JsonUtils
35 import org.onap.so.db.request.beans.ResourceOperationStatus
36 import org.slf4j.Logger
37 import org.slf4j.LoggerFactory
38 import org.springframework.web.util.UriUtils
40 import static org.apache.commons.lang3.StringUtils.isBlank
42 class DoCloudLeasedLineCreate extends AbstractServiceTaskProcessor {
44 private static final Logger logger = LoggerFactory.getLogger(DoCloudLeasedLineCreate.class);
45 JsonUtils jsonUtil = new JsonUtils()
46 RequestDBUtil requestDBUtil = new RequestDBUtil()
47 ServiceIntentUtils serviceIntentUtils = new ServiceIntentUtils()
48 ExceptionUtil exceptionUtil = new ExceptionUtil()
49 String Prefix = "CLLC_"
52 void preProcessRequest(DelegateExecution execution) {
53 logger.debug("Start preProcessRequest")
54 execution.setVariable("prefix", Prefix)
58 execution.setVariable("startTime", System.currentTimeMillis())
60 msg = serviceIntentUtils.getExecutionInputParams(execution)
61 logger.debug("Create CLL input parameters: " + msg)
63 serviceIntentUtils.setSdncCallbackUrl(execution, true)
64 logger.debug("SDNC Callback URL: " + execution.getVariable("sdncCallbackUrl"))
66 String additionalPropJsonStr = execution.getVariable("serviceIntentParams")
68 String cllId = jsonUtil.getJsonValue(additionalPropJsonStr, "serviceInstanceID") //for debug
70 cllId = UUID.randomUUID().toString()
73 String operationId = UUID.randomUUID().toString()
74 execution.setVariable("operationId", operationId)
76 logger.debug("Generate new CLL ID:" + cllId)
77 cllId = UriUtils.encode(cllId, "UTF-8")
78 execution.setVariable("cllId", cllId)
80 String cllName = execution.getVariable("servicename")
81 execution.setVariable("cllName", cllName)
83 String sst = execution.getVariable("sst")
84 execution.setVariable("sst", sst)
86 String transportNetworks = jsonUtil.getJsonValue(additionalPropJsonStr, "transportNetworks")
87 if (isBlank(transportNetworks)) {
88 msg = "ERROR: preProcessRequest: Input transportNetworks is null"
90 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
92 execution.setVariable("transportNetworks", transportNetworks)
94 logger.debug("transportNetworks: " + transportNetworks)
96 if (isBlank(serviceIntentUtils.setExecVarFromJsonIfExists(execution, additionalPropJsonStr,
97 "enableSdnc", "enableSdnc"))) {
98 serviceIntentUtils.setEnableSdncConfig(execution)
100 } catch (BpmnError e) {
102 } catch (Exception ex) {
103 msg = "Exception in preProcessRequest " + ex.getMessage()
105 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
107 logger.debug("Finish preProcessRequest")
110 void updateAAIOrchStatus(DelegateExecution execution) {
111 logger.debug("Start updateAAIOrchStatus")
112 String cllId = execution.getVariable("cllId")
113 String orchStatus = execution.getVariable("orchestrationStatus")
116 ServiceInstance si = new ServiceInstance()
117 si.setOrchestrationStatus(orchStatus)
118 AAIResourcesClient client = new AAIResourcesClient()
119 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.Types.SERVICE_INSTANCE.getFragment(cllId))
120 client.update(uri, si)
121 } catch (BpmnError e) {
123 } catch (Exception ex) {
124 String msg = "Exception in CreateSliceService.updateAAIOrchStatus " + ex.getMessage()
126 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
129 logger.debug("Finish updateAAIOrchStatus")
132 void prepareUpdateJobStatus(DelegateExecution execution,
135 String statusDescription) {
136 String cllId = execution.getVariable("cllId")
137 String modelUuid = execution.getVariable("modelUuid")
138 String jobId = execution.getVariable("jobId")
140 String operType = "CREATE"
142 ResourceOperationStatus roStatus = serviceIntentUtils.buildRoStatus(modelUuid, cllId,
143 jobId, nsiId, operType, status, progress, statusDescription)
145 logger.debug("prepareUpdateJobStatus: roStatus={}", roStatus)
146 requestDBUtil.prepareUpdateResourceOperationStatus(execution, roStatus)
150 void createServiceInstance(DelegateExecution execution) {
152 String serviceRole = "cll"
153 String serviceType = execution.getVariable("serviceType")
154 String cllId = execution.getVariable("cllId")
156 org.onap.aai.domain.yang.ServiceInstance ss = new org.onap.aai.domain.yang.ServiceInstance()
157 ss.setServiceInstanceId(cllId)
158 String cllName = execution.getVariable("cllName")
159 if (isBlank(cllName)) {
160 logger.error("ERROR: createServiceInstance: cllName is null")
163 ss.setServiceInstanceName(cllName)
164 ss.setServiceType(serviceType)
165 String serviceStatus = "created"
166 ss.setOrchestrationStatus(serviceStatus)
167 String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
168 String modelUuid = execution.getVariable("modelUuid")
169 ss.setModelInvariantId(modelInvariantUuid)
170 ss.setModelVersionId(modelUuid)
171 ss.setEnvironmentContext("cll")
172 ss.setServiceRole(serviceRole)
174 AAIResourcesClient client = getAAIClient()
176 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business()
177 .customer(execution.getVariable("globalSubscriberId"))
178 .serviceSubscription(execution.getVariable("subscriptionServiceType"))
179 .serviceInstance(cllId))
180 client.create(uri, ss)
181 } catch (BpmnError e) {
183 } catch (Exception ex) {
184 String msg = "Exception in DoCloudLeasedLineCreate.createServiceInstance: " + ex.getMessage()
186 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
191 void createAllottedResource(DelegateExecution execution) {
192 String cllId = execution.getVariable('cllId')
195 List<String> networkStrList = jsonUtil.StringArrayToList(execution.getVariable("transportNetworks"))
197 for (String networkStr : networkStrList) {
198 String networkId = jsonUtil.getJsonValue(networkStr, "id")
199 String allottedResourceId = isBlank(networkId) ? UUID.randomUUID().toString() : networkId
201 AAIResourceUri allottedResourceUri =
202 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business()
203 .customer(execution.getVariable("globalSubscriberId"))
204 .serviceSubscription(execution.getVariable("subscriptionServiceType"))
205 .serviceInstance(execution.getVariable("cllId"))
206 .allottedResource(allottedResourceId))
207 execution.setVariable("allottedResourceUri", allottedResourceUri)
208 String modelInvariantId = execution.getVariable("modelInvariantUuid")
209 String modelVersionId = execution.getVariable("modelUuid")
211 String slaStr = jsonUtil.getJsonValue(networkStr, "sla")
212 if (slaStr == null || slaStr.isEmpty()) {
213 String msg = "ERROR: createNetworkPolicy: SLA is null"
215 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
218 org.onap.aai.domain.yang.AllottedResource resource = new org.onap.aai.domain.yang.AllottedResource()
219 resource.setId(allottedResourceId)
220 resource.setType("TsciNetwork")
221 resource.setAllottedResourceName("network_" + allottedResourceId)
222 getAAIClient().create(allottedResourceUri, resource)
224 createNetworkPolicyForAllocatedResource(execution, cllId, allottedResourceId, slaStr)
226 String linkArrayStr = jsonUtil.getJsonValue(networkStr, "connectionLinks")
227 createLogicalLinksForAllocatedResource(execution, linkArrayStr, cllId, allottedResourceId)
229 } catch (BpmnError e) {
231 } catch (Exception ex) {
232 String msg = "Exception in DoCloudLeasedLineCreate.createAllottedResource: " + ex.getMessage()
234 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
238 void createNetworkPolicy(DelegateExecution execution, String cllId, String networkPolicyId, String slaStr) {
242 NetworkPolicy networkPolicy = new NetworkPolicy();
243 networkPolicy.setNetworkPolicyId(networkPolicyId)
244 networkPolicy.setName("TSCi policy")
245 networkPolicy.setType("SLA")
246 networkPolicy.setNetworkPolicyFqdn(cllId)
248 String latencyStr = jsonUtil.getJsonValue(slaStr, "latency")
249 if (latencyStr != null && !latencyStr.isEmpty()) {
250 networkPolicy.setLatency(Integer.parseInt(latencyStr))
253 String bwStr = jsonUtil.getJsonValue(slaStr, "maxBandwidth")
254 if (bwStr != null && !bwStr.isEmpty()) {
255 networkPolicy.setMaxBandwidth(Integer.parseInt(bwStr))
257 logger.debug("ERROR: createNetworkPolicy: maxBandwidth is null")
260 //networkPolicy.setReliability(new Object())
262 AAIResourceUri networkPolicyUri =
263 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().networkPolicy(networkPolicyId))
264 getAAIClient().create(networkPolicyUri, networkPolicy)
266 } catch (BpmnError e) {
268 } catch (Exception ex) {
269 String msg = "Exception in DoCreateSliceServiceInstance.instantiateSliceService. " + ex.getMessage()
271 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
275 void createNetworkPolicyForAllocatedResource(DelegateExecution execution,
277 String allottedResourceId, String slaStr) {
279 AAIResourceUri allottedResourceUri =
280 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business()
281 .customer(execution.getVariable("globalSubscriberId"))
282 .serviceSubscription(execution.getVariable("subscriptionServiceType"))
283 .serviceInstance(cllId)
284 .allottedResource(allottedResourceId))
286 if (!getAAIClient().exists(allottedResourceUri)) {
287 logger.info("ERROR: createLogicalLinksForAllocatedResource: allottedResource not exist: uri={}",
292 String networkPolicyId = UUID.randomUUID().toString()
293 createNetworkPolicy(execution, cllId, networkPolicyId, slaStr)
295 serviceIntentUtils.attachNetworkPolicyToAllottedResource(execution, serviceIntentUtils.AAI_VERSION,
299 } catch (BpmnError e) {
301 } catch (Exception ex) {
302 String msg = "Exception in DoCreateSliceServiceInstance.instantiateSliceService. " + ex.getMessage()
304 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
308 void createLogicalLinksForAllocatedResource(DelegateExecution execution,
309 String linkArrayStr, String cllId,
310 String allottedResourceId) {
312 AAIResourceUri allottedResourceUri =
313 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business()
314 .customer(execution.getVariable("globalSubscriberId"))
315 .serviceSubscription(execution.getVariable("subscriptionServiceType"))
316 .serviceInstance(cllId)
317 .allottedResource(allottedResourceId))
319 if (!getAAIClient().exists(allottedResourceUri)) {
320 logger.info("ERROR: createLogicalLinksForAllocatedResource: allottedResource not exist: uri={}",
325 List<String> linkStrList = jsonUtil.StringArrayToList(linkArrayStr)
327 for (String linkStr : linkStrList) {
328 String linkId = jsonUtil.getJsonValue(linkStr, "name")
329 if (isBlank(linkId)) {
330 linkId = "cll-" + UUID.randomUUID().toString()
332 logger.debug("createLogicalLinksForAllocatedResource: linkId=" + linkId)
334 String epA = jsonUtil.getJsonValue(linkStr, "transportEndpointA")
335 String epB = jsonUtil.getJsonValue(linkStr, "transportEndpointB")
336 String modelInvariantId = execution.getVariable("modelInvariantUuid")
337 String modelVersionId = execution.getVariable("modelUuid")
339 org.onap.aai.domain.yang.LogicalLink resource = new org.onap.aai.domain.yang.LogicalLink()
340 resource.setLinkId(linkId)
341 resource.setLinkName(epA)
342 resource.setLinkName2(epB)
343 resource.setLinkType("TsciConnectionLink")
344 resource.setInMaint(false)
347 AAIResourceUri logicalLinkUri =
348 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().logicalLink(epA))
349 getAAIClient().create(logicalLinkUri, resource)
351 serviceIntentUtils.attachLogicalLinkToAllottedResource(execution, serviceIntentUtils.AAI_VERSION,
352 allottedResourceUri, epA);
354 } catch (BpmnError e) {
356 } catch (Exception ex) {
357 String msg = "Exception in DoCloudLeasedLineCreate.createLogicalLinksForAllocatedResource: " + ex.getMessage()
359 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
363 void preprocessSdncCreateCllRequest(DelegateExecution execution) {
364 def method = getClass().getSimpleName() + '.preProcessSDNCActivateRequest(' +
365 'execution=' + execution.getId() +
367 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
368 logger.trace('Entered ' + method)
370 logger.trace("STARTED preProcessSDNCActivateRequest Process")
372 String serviceInstanceId = execution.getVariable("cllId")
374 String createSDNCRequest = serviceIntentUtils.buildSDNCRequest(execution, serviceInstanceId, "create")
376 execution.setVariable("CLL_SDNCRequest", createSDNCRequest)
377 logger.debug("Outgoing SDNCRequest is: \n" + createSDNCRequest)
379 } catch (Exception e) {
380 logger.debug("Exception Occured Processing preProcessSDNCActivateRequest. Exception is:\n" + e)
381 exceptionUtil.buildAndThrowWorkflowException(execution, 1002,
382 "Error Occured during preProcessSDNCActivateRequest Method:\n" + e.getMessage())
384 logger.trace("COMPLETED preProcessSDNCActivateRequest Process")
388 void validateSDNCResponse(DelegateExecution execution, String response, String method) {
389 serviceIntentUtils.validateSDNCResponse(execution, response, method)