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
41 import static org.apache.commons.lang3.StringUtils.isNotBlank
43 class DoCloudLeasedLineCreate extends AbstractServiceTaskProcessor {
45 private static final Logger logger = LoggerFactory.getLogger(DoCloudLeasedLineCreate.class);
46 JsonUtils jsonUtil = new JsonUtils()
47 RequestDBUtil requestDBUtil = new RequestDBUtil()
48 ServiceIntentUtils serviceIntentUtils = new ServiceIntentUtils()
49 ExceptionUtil exceptionUtil = new ExceptionUtil()
50 String Prefix = "CLLC_"
53 void preProcessRequest(DelegateExecution execution) {
54 logger.debug("Start preProcessRequest")
55 execution.setVariable("prefix", Prefix)
59 execution.setVariable("startTime", System.currentTimeMillis())
61 msg = serviceIntentUtils.getExecutionInputParams(execution)
62 logger.debug("Create CLL input parameters: " + msg)
64 serviceIntentUtils.setSdncCallbackUrl(execution, true)
65 logger.debug("SDNC Callback URL: " + execution.getVariable("sdncCallbackUrl"))
67 String additionalPropJsonStr = execution.getVariable("serviceIntentParams")
69 String cllId = jsonUtil.getJsonValue(additionalPropJsonStr, "serviceInstanceID") //for debug
71 cllId = UUID.randomUUID().toString()
74 String operationId = UUID.randomUUID().toString()
75 execution.setVariable("operationId", operationId)
77 logger.debug("Generate new CLL ID:" + cllId)
78 cllId = UriUtils.encode(cllId, "UTF-8")
79 execution.setVariable("cllId", cllId)
81 String cllName = execution.getVariable("servicename")
82 execution.setVariable("cllName", cllName)
84 String sst = execution.getVariable("sst")
85 execution.setVariable("sst", sst)
87 String transportNetworks = jsonUtil.getJsonValue(additionalPropJsonStr, "transportNetworks")
88 if (isBlank(transportNetworks)) {
89 msg = "ERROR: preProcessRequest: Input transportNetworks is null"
91 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
93 execution.setVariable("transportNetworks", transportNetworks)
95 logger.debug("transportNetworks: " + transportNetworks)
97 if (isBlank(serviceIntentUtils.setExecVarFromJsonIfExists(execution, additionalPropJsonStr,
98 "enableSdnc", "enableSdnc"))) {
99 serviceIntentUtils.setEnableSdncConfig(execution)
101 } catch (BpmnError e) {
103 } catch (Exception ex) {
104 msg = "Exception in preProcessRequest " + ex.getMessage()
106 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
108 logger.debug("Finish preProcessRequest")
111 void updateAAIOrchStatus(DelegateExecution execution) {
112 logger.debug("Start updateAAIOrchStatus")
113 String cllId = execution.getVariable("cllId")
114 String orchStatus = execution.getVariable("orchestrationStatus")
117 ServiceInstance si = new ServiceInstance()
118 si.setOrchestrationStatus(orchStatus)
119 AAIResourcesClient client = new AAIResourcesClient()
120 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.Types.SERVICE_INSTANCE.getFragment(cllId))
121 client.update(uri, si)
122 } catch (BpmnError e) {
124 } catch (Exception ex) {
125 String msg = "Exception in CreateSliceService.updateAAIOrchStatus " + ex.getMessage()
127 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
130 logger.debug("Finish updateAAIOrchStatus")
133 void prepareUpdateJobStatus(DelegateExecution execution,
136 String statusDescription) {
137 String cllId = execution.getVariable("cllId")
138 String modelUuid = execution.getVariable("modelUuid")
139 String jobId = execution.getVariable("jobId")
141 String operType = "CREATE"
143 ResourceOperationStatus roStatus = serviceIntentUtils.buildRoStatus(modelUuid, cllId,
144 jobId, nsiId, operType, status, progress, statusDescription)
146 logger.debug("prepareUpdateJobStatus: roStatus={}", roStatus)
147 requestDBUtil.prepareUpdateResourceOperationStatus(execution, roStatus)
151 void createServiceInstance(DelegateExecution execution) {
153 String serviceRole = "cll"
154 String serviceType = execution.getVariable("serviceType")
155 String cllId = execution.getVariable("cllId")
157 org.onap.aai.domain.yang.ServiceInstance ss = new org.onap.aai.domain.yang.ServiceInstance()
158 ss.setServiceInstanceId(cllId)
159 String cllName = execution.getVariable("cllName")
160 if (isBlank(cllName)) {
161 logger.error("ERROR: createServiceInstance: cllName is null")
164 ss.setServiceInstanceName(cllName)
165 ss.setServiceType(serviceType)
166 String serviceStatus = "created"
167 ss.setOrchestrationStatus(serviceStatus)
168 String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
169 String modelUuid = execution.getVariable("modelUuid")
170 ss.setModelInvariantId(modelInvariantUuid)
171 ss.setModelVersionId(modelUuid)
172 ss.setEnvironmentContext("cll")
173 ss.setServiceRole(serviceRole)
175 AAIResourcesClient client = getAAIClient()
177 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business()
178 .customer(execution.getVariable("globalSubscriberId"))
179 .serviceSubscription(execution.getVariable("subscriptionServiceType"))
180 .serviceInstance(cllId))
181 client.create(uri, ss)
182 } catch (BpmnError e) {
184 } catch (Exception ex) {
185 String msg = "Exception in DoCloudLeasedLineCreate.createServiceInstance: " + ex.getMessage()
187 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
192 void createAllottedResource(DelegateExecution execution) {
193 String cllId = execution.getVariable('cllId')
196 List<String> networkStrList = jsonUtil.StringArrayToList(execution.getVariable("transportNetworks"))
198 for (String networkStr : networkStrList) {
199 String networkId = jsonUtil.getJsonValue(networkStr, "id")
200 String allottedResourceId = isBlank(networkId) ? UUID.randomUUID().toString() : networkId
202 AAIResourceUri allottedResourceUri =
203 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business()
204 .customer(execution.getVariable("globalSubscriberId"))
205 .serviceSubscription(execution.getVariable("subscriptionServiceType"))
206 .serviceInstance(execution.getVariable("cllId"))
207 .allottedResource(allottedResourceId))
208 execution.setVariable("allottedResourceUri", allottedResourceUri)
209 String modelInvariantId = execution.getVariable("modelInvariantUuid")
210 String modelVersionId = execution.getVariable("modelUuid")
212 String slaStr = jsonUtil.getJsonValue(networkStr, "sla")
213 if (slaStr == null || slaStr.isEmpty()) {
214 String msg = "ERROR: createNetworkPolicy: SLA is null"
216 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
219 org.onap.aai.domain.yang.AllottedResource resource = new org.onap.aai.domain.yang.AllottedResource()
220 resource.setId(allottedResourceId)
221 resource.setType("TsciNetwork")
222 resource.setAllottedResourceName("network_" + allottedResourceId)
223 getAAIClient().create(allottedResourceUri, resource)
225 createNetworkPolicyForAllocatedResource(execution, cllId, allottedResourceId, slaStr)
227 String linkArrayStr = jsonUtil.getJsonValue(networkStr, "connectionLinks")
228 createLogicalLinksForAllocatedResource(execution, linkArrayStr, cllId, allottedResourceId)
230 } catch (BpmnError e) {
232 } catch (Exception ex) {
233 String msg = "Exception in DoCloudLeasedLineCreate.createAllottedResource: " + ex.getMessage()
235 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
239 void createNetworkPolicy(DelegateExecution execution, String cllId, String networkPolicyId, String slaStr) {
243 NetworkPolicy networkPolicy = new NetworkPolicy();
244 networkPolicy.setNetworkPolicyId(networkPolicyId)
245 networkPolicy.setName("TSCi policy")
246 networkPolicy.setType("SLA")
247 networkPolicy.setNetworkPolicyFqdn(cllId)
249 String latencyStr = jsonUtil.getJsonValue(slaStr, "latency")
250 if (latencyStr != null && !latencyStr.isEmpty()) {
251 networkPolicy.setLatency(Integer.parseInt(latencyStr))
254 String bwStr = jsonUtil.getJsonValue(slaStr, "maxBandwidth")
255 if (bwStr != null && !bwStr.isEmpty()) {
256 networkPolicy.setMaxBandwidth(Integer.parseInt(bwStr))
258 logger.debug("ERROR: createNetworkPolicy: maxBandwidth is null")
261 //networkPolicy.setReliability(new Object())
263 AAIResourceUri networkPolicyUri =
264 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().networkPolicy(networkPolicyId))
265 getAAIClient().create(networkPolicyUri, networkPolicy)
267 } catch (BpmnError e) {
269 } catch (Exception ex) {
270 String msg = "Exception in DoCreateSliceServiceInstance.instantiateSliceService. " + ex.getMessage()
272 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
276 void createNetworkPolicyForAllocatedResource(DelegateExecution execution,
278 String allottedResourceId, String slaStr) {
280 AAIResourceUri allottedResourceUri =
281 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business()
282 .customer(execution.getVariable("globalSubscriberId"))
283 .serviceSubscription(execution.getVariable("subscriptionServiceType"))
284 .serviceInstance(cllId)
285 .allottedResource(allottedResourceId))
287 if (!getAAIClient().exists(allottedResourceUri)) {
288 logger.info("ERROR: createLogicalLinksForAllocatedResource: allottedResource not exist: uri={}",
293 String networkPolicyId = UUID.randomUUID().toString()
294 createNetworkPolicy(execution, cllId, networkPolicyId, slaStr)
296 serviceIntentUtils.attachNetworkPolicyToAllottedResource(execution, serviceIntentUtils.AAI_VERSION,
300 } catch (BpmnError e) {
302 } catch (Exception ex) {
303 String msg = "Exception in DoCreateSliceServiceInstance.instantiateSliceService. " + ex.getMessage()
305 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
309 void createLogicalLinksForAllocatedResource(DelegateExecution execution,
310 String linkArrayStr, String cllId,
311 String allottedResourceId) {
313 AAIResourceUri allottedResourceUri =
314 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business()
315 .customer(execution.getVariable("globalSubscriberId"))
316 .serviceSubscription(execution.getVariable("subscriptionServiceType"))
317 .serviceInstance(cllId)
318 .allottedResource(allottedResourceId))
320 if (!getAAIClient().exists(allottedResourceUri)) {
321 logger.info("ERROR: createLogicalLinksForAllocatedResource: allottedResource not exist: uri={}",
326 List<String> linkStrList = jsonUtil.StringArrayToList(linkArrayStr)
328 for (String linkStr : linkStrList) {
329 String linkId = jsonUtil.getJsonValue(linkStr, "name")
330 if (isBlank(linkId)) {
331 linkId = "cll-" + UUID.randomUUID().toString()
333 logger.debug("createLogicalLinksForAllocatedResource: linkId=" + linkId)
335 String epA = jsonUtil.getJsonValue(linkStr, "transportEndpointA")
336 String epB = jsonUtil.getJsonValue(linkStr, "transportEndpointB")
337 String epBProtect = jsonUtil.getJsonValue(linkStr, "transportEndpointBProtection")
338 String modelInvariantId = execution.getVariable("modelInvariantUuid")
339 String modelVersionId = execution.getVariable("modelUuid")
341 org.onap.aai.domain.yang.LogicalLink resource = new org.onap.aai.domain.yang.LogicalLink()
342 resource.setLinkId(linkId)
343 resource.setLinkName(epA)
344 resource.setLinkName2(epB)
345 if (isNotBlank(epBProtect)) {
346 resource.setSegmentId(epBProtect)
348 resource.setLinkType("TsciConnectionLink")
349 resource.setInMaint(false)
352 AAIResourceUri logicalLinkUri =
353 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().logicalLink(epA))
354 getAAIClient().create(logicalLinkUri, resource)
356 serviceIntentUtils.attachLogicalLinkToAllottedResource(execution, serviceIntentUtils.AAI_VERSION,
357 allottedResourceUri, epA);
359 } catch (BpmnError e) {
361 } catch (Exception ex) {
362 String msg = "Exception in DoCloudLeasedLineCreate.createLogicalLinksForAllocatedResource: " + ex.getMessage()
364 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
368 void preprocessSdncCreateCllRequest(DelegateExecution execution) {
369 def method = getClass().getSimpleName() + '.preProcessSDNCActivateRequest(' +
370 'execution=' + execution.getId() +
372 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
373 logger.trace('Entered ' + method)
375 logger.trace("STARTED preProcessSDNCActivateRequest Process")
377 String serviceInstanceId = execution.getVariable("cllId")
379 String createSDNCRequest = serviceIntentUtils.buildSDNCRequest(execution, serviceInstanceId, "create")
381 execution.setVariable("CLL_SDNCRequest", createSDNCRequest)
382 logger.debug("Outgoing SDNCRequest is: \n" + createSDNCRequest)
384 } catch (Exception e) {
385 logger.debug("Exception Occured Processing preProcessSDNCActivateRequest. Exception is:\n" + e)
386 exceptionUtil.buildAndThrowWorkflowException(execution, 1002,
387 "Error Occured during preProcessSDNCActivateRequest Method:\n" + e.getMessage())
389 logger.trace("COMPLETED preProcessSDNCActivateRequest Process")
393 void validateSDNCResponse(DelegateExecution execution, String response, String method) {
394 serviceIntentUtils.validateSDNCResponse(execution, response, method)