4ccea61ed43746516cfa00b8db0d965711b4b141
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2020  Telecom Italia
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.so.bpmn.infrastructure.scripts
22
23 import com.fasterxml.jackson.databind.ObjectMapper
24 import org.camunda.bpm.engine.delegate.DelegateExecution
25 import org.onap.aai.domain.yang.v19.ServiceInstance
26 import org.onap.aai.domain.yang.v19.SliceProfile
27 import org.onap.aaiclient.client.aai.AAIResourcesClient
28 import org.onap.aaiclient.client.aai.entities.AAIEdgeLabel
29 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
30 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
31 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
32 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types
33 import org.onap.so.bpmn.common.scripts.ExceptionUtil
34 import org.onap.so.bpmn.common.scripts.MsoUtils
35 import org.onap.so.bpmn.common.scripts.RequestDBUtil
36 import org.onap.so.bpmn.core.json.JsonUtils
37 import org.slf4j.Logger
38 import org.slf4j.LoggerFactory
39
40 import static org.apache.commons.lang3.StringUtils.isBlank
41
42 class DoModifyCoreNSSI extends DoCommonCoreNSSI {
43
44     private final String PREFIX ="DoModifyCoreNSSI"
45     private final String ACTION = "Modify"
46
47     private ExceptionUtil exceptionUtil = new ExceptionUtil()
48     private RequestDBUtil requestDBUtil = new RequestDBUtil()
49     private MsoUtils utils = new MsoUtils()
50     private JsonUtils jsonUtil = new JsonUtils()
51
52     private static final Logger LOGGER = LoggerFactory.getLogger( DoModifyCoreNSSI.class)
53
54     /**
55      * Creates Slice Profile Instance
56      * @param execution
57      */
58     void createSliceProfileInstance(DelegateExecution execution) {
59         LOGGER.trace("${PREFIX} Start createSliceProfileInstance")
60
61         def currentNSSI = execution.getVariable("currentNSSI")
62
63         String sliceProfileID = currentNSSI['sliceProfileId']
64         Map<String,Object> sliceProfileMap = new ObjectMapper().readValue(currentNSSI['sliceProfile'], Map.class)
65
66         String globalSubscriberId = execution.getVariable("globalSubscriberId")
67         String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
68         String nssiId = currentNSSI['nssiId']
69
70         SliceProfile sliceProfile = new SliceProfile()
71         sliceProfile.setServiceAreaDimension("")
72         sliceProfile.setPayloadSize(0)
73         sliceProfile.setJitter(0)
74         sliceProfile.setSurvivalTime(0)
75         sliceProfile.setExpDataRate(0)
76         sliceProfile.setTrafficDensity(0)
77         sliceProfile.setConnDensity(0)
78         sliceProfile.setSNssai(currentNSSI['S-NSSAI'])
79
80         if(!isBlank(sliceProfileMap.get("expDataRateUL"))) {
81             sliceProfile.setExpDataRateUL(Integer.parseInt(sliceProfileMap.get("expDataRateUL").toString()))
82         }
83
84         if(!isBlank(sliceProfileMap.get("expDataRateDL"))) {
85             sliceProfile.setExpDataRateDL(Integer.parseInt(sliceProfileMap.get("expDataRateDL").toString()))
86         }
87
88         if(!isBlank(sliceProfileMap.get("activityFactor"))) {
89             sliceProfile.setActivityFactor(Integer.parseInt(sliceProfileMap.get("activityFactor").toString()))
90         }
91
92         if(!isBlank(sliceProfileMap.get("resourceSharingLevel"))) {
93             sliceProfile.setResourceSharingLevel(sliceProfileMap.get("resourceSharingLevel").toString())
94         }
95
96         if(!isBlank(sliceProfileMap.get("uEMobilityLevel"))) {
97             sliceProfile.setUeMobilityLevel(sliceProfileMap.get("uEMobilityLevel").toString())
98         }
99
100         if(!isBlank(sliceProfileMap.get("coverageAreaTAList"))) {
101             sliceProfile.setCoverageAreaTAList(sliceProfileMap.get("coverageAreaTAList").toString())
102         }
103
104         if(!isBlank(sliceProfileMap.get("maxNumberofUEs"))) {
105             sliceProfile.setMaxNumberOfUEs(Integer.parseInt(sliceProfileMap.get("maxNumberofUEs").toString()))
106         }
107
108         if(!isBlank(sliceProfileMap.get("latency"))) {
109             sliceProfile.setLatency(Integer.parseInt(sliceProfileMap.get("latency").toString()))
110         }
111
112         sliceProfile.setProfileId(sliceProfileID)
113         sliceProfile.setE2ELatency(0)
114
115         try {
116             AAIResourcesClient client = getAAIClient()
117             AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(nssiId).sliceProfile(sliceProfileID))
118             client.create(uri, sliceProfile)
119
120             currentNSSI['createdSliceProfile'] = sliceProfile
121         } catch (Exception ex) {
122             exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while Slice Profile create call:" + ex.getMessage())
123         }
124
125         LOGGER.trace("${PREFIX} Exit createSliceProfileInstance")
126     }
127
128
129     /**
130      * Creates Slice Profile association with NSSI
131      * @param execution
132      */
133     void associateSliceProfileInstanceWithNSSI(DelegateExecution execution) {
134         LOGGER.trace("${PREFIX} Start associateSliceProfileInstanceWithNSSI")
135
136         def currentNSSI = execution.getVariable("currentNSSI")
137
138         String sliceProfileID = currentNSSI['sliceProfileId']
139
140         String globalSubscriberId = execution.getVariable("globalSubscriberId")
141         String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
142         String nssiId = currentNSSI['nssiId']
143
144         AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId))
145         AAIResourceUri sliceProfileUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(nssiId).sliceProfile(sliceProfileID))
146
147         try {
148             SliceProfile createdSliceProfile = (SliceProfile)currentNSSI['createdSliceProfile']
149             ServiceInstance nssi = (ServiceInstance)currentNSSI['nssi']
150             List<SliceProfile> associatedProfiles = nssi.getSliceProfiles().getSliceProfile()
151             associatedProfiles.add(createdSliceProfile)
152
153             getAAIClient().update(nssiUri, nssi)
154
155             getAAIClient().connect(sliceProfileUri, nssiUri, AAIEdgeLabel.BELONGS_TO)
156         }catch(Exception e){
157             exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while Slice Profile association with NSSI disconnect call: " + e.getMessage())
158         }
159
160         LOGGER.trace("${PREFIX} Exit associateSliceProfileInstanceWithNSSI")
161     }
162
163
164     @Override
165     String getPrefix() {
166         return PREFIX
167     }
168
169
170     @Override
171     String getAction() {
172         return ACTION
173     }
174 }