2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 # Copyright (c) 2019, CMCC Technologies Co., Ltd.
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.CommunicationServiceProfile
26 import org.onap.aai.domain.yang.ServiceInstance
27 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
28 import org.onap.so.bpmn.common.scripts.ExceptionUtil
29 import org.onap.so.bpmn.core.json.JsonUtils
30 import org.onap.aaiclient.client.aai.AAIObjectType
31 import org.onap.aaiclient.client.aai.AAIResourcesClient
32 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
33 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
34 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
35 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types
36 import org.slf4j.Logger
37 import org.slf4j.LoggerFactory
39 import static org.apache.commons.lang3.StringUtils.isBlank
42 * This groovy class supports the <class>DoCreateCommunicationService.bpmn</class> process.
43 * AlaCarte flow for 1702 ServiceInstance Create
46 class DoCreateCommunicationService extends AbstractServiceTaskProcessor{
48 ExceptionUtil exceptionUtil = new ExceptionUtil()
49 JsonUtils jsonUtil = new JsonUtils()
50 AAIResourcesClient client = new AAIResourcesClient()
52 private static final Logger logger = LoggerFactory.getLogger( DoCreateCommunicationService.class)
55 void preProcessRequest(DelegateExecution execution) {
56 logger.trace("start preProcessRequest")
57 execution.setVariable("prefix", Prefix)
60 String serviceInstanceId = execution.getVariable("serviceInstanceId")
61 if (isBlank(serviceInstanceId)) {
62 msg = "Input serviceInstanceId' is null"
63 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
66 String globalSubscriberId = execution.getVariable("globalSubscriberId")
67 if (isBlank(globalSubscriberId)) {
68 msg = "Input globalSubscriberId' is null"
69 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
72 String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
73 if (isBlank(subscriptionServiceType)) {
74 msg = "Input subscriptionServiceType' is null"
75 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
79 } catch(BpmnError e) {
81 } catch(Exception ex) {
82 msg = "Exception in preProcessRequest " + ex.getMessage()
84 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
86 logger.trace("Exit preProcessRequest")
90 * create communication service, generate S-NSSAI Id and communication service profile
91 * 1.create communication service profile
94 def createCommunicationServiceProfile = { DelegateExecution execution ->
95 logger.trace("createCSandServiceProfile")
97 String serviceInstanceId = execution.getVariable("serviceInstanceId")
98 String globalSubscriberId = execution.getVariable("globalSubscriberId")
99 String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
101 // String sNSSAI_id = execution.getVariable("sNSSAI_id")
102 // create communication service profile
103 String profileId = UUID.randomUUID().toString()
104 execution.setVariable("communicationProfileId", profileId)
106 def csInputMap = execution.getVariable("csInputMap") as Map<String, ?>
107 Integer latency = csInputMap.get("latency") as Integer
108 Integer maxNumberOfUEs = csInputMap.get("maxNumberofUEs") as Integer
109 Integer expDataRateDL = csInputMap.get("expDataRateDL") as Integer
110 Integer expDataRateUL = csInputMap.get("expDataRateUL") as Integer
111 String coverageArea = csInputMap.get("coverageAreaTAList")
112 String uEMobilityLevel = csInputMap.get("uEMobilityLevel")
113 String resourceSharingLevel = csInputMap.get("resourceSharingLevel")
115 CommunicationServiceProfile csp = new CommunicationServiceProfile()
116 csp.setProfileId(profileId)
118 csp.setLatency(latency)
119 csp.setMaxNumberOfUEs(maxNumberOfUEs)
120 csp.setUeMobilityLevel(uEMobilityLevel)
121 csp.setResourceSharingLevel(resourceSharingLevel)
122 csp.setExpDataRateDL(expDataRateDL)
123 csp.setExpDataRateUL(expDataRateUL)
124 csp.setCoverageAreaList(coverageArea)
126 execution.setVariable("communicationServiceInstanceProfile", csp)
128 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(serviceInstanceId).communicationServiceProfile(profileId))
129 client.create(uri, csp)
132 } catch (BpmnError e) {
134 } catch (Exception ex) {
135 msg = "Exception in createCSandServiceProfile " + ex.getMessage()
137 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
139 logger.trace("exit createCSandServiceProfile")
144 * create communication service, generate S-NSSAI Id
145 * 1.generate S-NSSAI Id
146 * 2.create communication service
149 def createCommunicationService = { DelegateExecution execution ->
150 logger.trace("create communication service")
152 String serviceInstanceId = execution.getVariable("serviceInstanceId")
154 //generate S-NSSAI Id and communication service profile
155 String sNSSAI_id = generateNSSAI(serviceInstanceId)
157 execution.setVariable("sNSSAI_id", sNSSAI_id)
158 // create communication service
159 String serviceInstanceName = execution.getVariable("serviceInstanceName")
160 String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
161 String csServiceType = execution.getVariable("csServiceType")
162 String aaiServiceRole = "communication-service"
164 String oStatus = "processing"
165 String uuiRequest = execution.getVariable("uuiRequest")
166 String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
167 String modelUuid = execution.getVariable("modelUuid")
168 String useInterval = execution.getVariable("useInterval")
169 String globalSubscriberId = execution.getVariable("globalSubscriberId")
172 ServiceInstance csi = new ServiceInstance()
173 csi.setServiceInstanceName(serviceInstanceName)
174 csi.setServiceType(csServiceType)
175 csi.setServiceRole(aaiServiceRole)
176 csi.setOrchestrationStatus(oStatus)
177 csi.setModelInvariantId(modelInvariantUuid)
178 csi.setModelVersionId(modelUuid)
179 csi.setInputParameters(uuiRequest)
180 csi.setWorkloadContext(useInterval)
181 csi.setEnvironmentContext(sNSSAI_id)
183 //timestamp format YYYY-MM-DD hh:mm:ss
184 csi.setCreatedAt(new Date(System.currentTimeMillis()).format("yyyy-MM-dd HH:mm:ss", TimeZone.getDefault()))
186 execution.setVariable("communicationServiceInstance", csi)
188 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(serviceInstanceId))
189 client.create(uri, csi)
191 } catch (BpmnError e) {
193 } catch (Exception ex) {
194 msg = "Exception in communication service " + ex.getMessage()
196 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
198 logger.trace("exit communication service")
201 private static generateNSSAI = { final String instanceId ->
203 res = (instanceId == null) ? 0 : (h = instanceId.hashCode()) ^ (h >>> 16)
205 return "01-" + Integer.toHexString(res).toUpperCase()