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.slf4j.Logger
 
  35 import org.slf4j.LoggerFactory
 
  37 import static org.apache.commons.lang3.StringUtils.isBlank
 
  40  * This groovy class supports the <class>DoCreateCommunicationService.bpmn</class> process.
 
  41  * AlaCarte flow for 1702 ServiceInstance Create
 
  44 class DoCreateCommunicationService extends AbstractServiceTaskProcessor{
 
  46     ExceptionUtil exceptionUtil = new ExceptionUtil()
 
  47     JsonUtils jsonUtil = new JsonUtils()
 
  48     AAIResourcesClient client = new AAIResourcesClient()
 
  50     private static final Logger logger = LoggerFactory.getLogger( DoCreateCommunicationService.class)
 
  53      void preProcessRequest(DelegateExecution execution) {
 
  54         logger.trace("start preProcessRequest")
 
  55         execution.setVariable("prefix", Prefix)
 
  58             String serviceInstanceId = execution.getVariable("serviceInstanceId")
 
  59             if (isBlank(serviceInstanceId)) {
 
  60                 msg = "Input serviceInstanceId' is null"
 
  61                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
 
  64             String globalSubscriberId = execution.getVariable("globalSubscriberId")
 
  65             if (isBlank(globalSubscriberId)) {
 
  66                 msg = "Input globalSubscriberId' is null"
 
  67                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
 
  70             String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
 
  71             if (isBlank(subscriptionServiceType)) {
 
  72                 msg = "Input subscriptionServiceType' is null"
 
  73                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
 
  77         } catch(BpmnError e) {
 
  79         } catch(Exception ex) {
 
  80             msg = "Exception in preProcessRequest " + ex.getMessage()
 
  82             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
 
  84         logger.trace("Exit preProcessRequest")
 
  88      * create communication service, generate S-NSSAI Id and communication service profile
 
  89      * 1.create communication service profile
 
  92     def createCommunicationServiceProfile = { DelegateExecution execution ->
 
  93         logger.trace("createCSandServiceProfile")
 
  95         String serviceInstanceId = execution.getVariable("serviceInstanceId")
 
  96         String globalSubscriberId = execution.getVariable("globalSubscriberId")
 
  97         String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
 
  99             // String sNSSAI_id = execution.getVariable("sNSSAI_id")
 
 100             // create communication service profile
 
 101             String profileId = UUID.randomUUID().toString()
 
 102             execution.setVariable("communicationProfileId", profileId)
 
 104             def csInputMap = execution.getVariable("csInputMap") as Map<String, ?>
 
 105             Integer latency = csInputMap.get("latency") as Integer
 
 106             Integer maxNumberOfUEs = csInputMap.get("maxNumberofUEs") as Integer
 
 107             Integer expDataRateDL = csInputMap.get("expDataRateDL") as Integer
 
 108             Integer expDataRateUL = csInputMap.get("expDataRateUL") as Integer
 
 109             String coverageArea = csInputMap.get("coverageAreaTAList")
 
 110             String uEMobilityLevel = csInputMap.get("uEMobilityLevel")
 
 111             String resourceSharingLevel = csInputMap.get("resourceSharingLevel")
 
 113             CommunicationServiceProfile csp = new CommunicationServiceProfile()
 
 114             csp.setProfileId(profileId)
 
 116             csp.setLatency(latency)
 
 117             csp.setMaxNumberOfUEs(maxNumberOfUEs)
 
 118             csp.setUeMobilityLevel(uEMobilityLevel)
 
 119             csp.setResourceSharingLevel(resourceSharingLevel)
 
 120             csp.setExpDataRateDL(expDataRateDL)
 
 121             csp.setExpDataRateUL(expDataRateUL)
 
 122             csp.setCoverageAreaList(coverageArea)
 
 124             execution.setVariable("communicationServiceInstanceProfile", csp)
 
 126             AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.COMMUNICATION_SERVICE_PROFILE,
 
 128                     subscriptionServiceType,
 
 132             client.create(uri, csp)
 
 135         } catch (BpmnError e) {
 
 137         } catch (Exception ex) {
 
 138             msg = "Exception in createCSandServiceProfile " + ex.getMessage()
 
 140             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
 
 142         logger.trace("exit createCSandServiceProfile")
 
 147      * create communication service, generate S-NSSAI Id
 
 148      * 1.generate S-NSSAI Id
 
 149      * 2.create communication service
 
 152     def createCommunicationService = { DelegateExecution execution ->
 
 153         logger.trace("create communication service")
 
 155         String serviceInstanceId = execution.getVariable("serviceInstanceId")
 
 157             //generate S-NSSAI Id and communication service profile
 
 158             String sNSSAI_id = generateNSSAI(serviceInstanceId)
 
 160             execution.setVariable("sNSSAI_id", sNSSAI_id)
 
 161             // create communication service
 
 162             String serviceInstanceName = execution.getVariable("serviceInstanceName")
 
 163             String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
 
 164             String csServiceType = execution.getVariable("csServiceType")
 
 165             String aaiServiceRole = "communication-service"
 
 167             String oStatus = "processing"
 
 168             String uuiRequest = execution.getVariable("uuiRequest")
 
 169             String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
 
 170             String modelUuid = execution.getVariable("modelUuid")
 
 171             String useInterval = execution.getVariable("useInterval")
 
 172             String globalSubscriberId = execution.getVariable("globalSubscriberId")
 
 175             ServiceInstance csi = new ServiceInstance()
 
 176             csi.setServiceInstanceName(serviceInstanceName)
 
 177             csi.setServiceType(csServiceType)
 
 178             csi.setServiceRole(aaiServiceRole)
 
 179             csi.setOrchestrationStatus(oStatus)
 
 180             csi.setModelInvariantId(modelInvariantUuid)
 
 181             csi.setModelVersionId(modelUuid)
 
 182             csi.setInputParameters(uuiRequest)
 
 183             csi.setWorkloadContext(useInterval)
 
 184             csi.setEnvironmentContext(sNSSAI_id)
 
 186             //timestamp format YYYY-MM-DD hh:mm:ss
 
 187             csi.setCreatedAt(new Date(System.currentTimeMillis()).format("yyyy-MM-dd HH:mm:ss", TimeZone.getDefault()))
 
 189             execution.setVariable("communicationServiceInstance", csi)
 
 191             AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, globalSubscriberId, subscriptionServiceType, serviceInstanceId)
 
 192             client.create(uri, csi)
 
 194         } catch (BpmnError e) {
 
 196         } catch (Exception ex) {
 
 197             msg = "Exception in communication service " + ex.getMessage()
 
 199             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
 
 201         logger.trace("exit communication service")
 
 204     private static generateNSSAI = { final String instanceId ->
 
 206         res = (instanceId == null) ? 0 : (h = instanceId.hashCode()) ^ (h >>> 16)
 
 208         return "01-" + Integer.toHexString(res).toUpperCase()