1f25c733cdfa5534d2329bb1016cc2fc41abf1c0
[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.BpmnError
25 import org.camunda.bpm.engine.delegate.DelegateExecution
26 import org.onap.aai.domain.yang.CloudRegion
27 import org.onap.aai.domain.yang.Customer
28 import org.onap.aai.domain.yang.GenericVnf
29 import org.onap.aai.domain.yang.ModelVer
30 import org.onap.aai.domain.yang.ServiceInstance
31 import org.onap.aai.domain.yang.ServiceSubscription
32 import org.onap.aai.domain.yang.SliceProfile
33 import org.onap.aai.domain.yang.Tenant
34 import org.onap.aai.domain.yang.VfModule
35 import org.onap.aaiclient.client.aai.AAIObjectType
36 import org.onap.aaiclient.client.aai.AAIResourcesClient
37 import org.onap.aaiclient.client.aai.entities.AAIEdgeLabel
38 import org.onap.aaiclient.client.aai.entities.AAIResultWrapper
39 import org.onap.aaiclient.client.aai.entities.Relationships
40 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
41 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
42 import org.onap.logging.filter.base.ONAPComponents
43 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
44 import org.onap.so.bpmn.common.scripts.ExceptionUtil
45 import org.onap.so.bpmn.common.scripts.MsoUtils
46 import org.onap.so.bpmn.common.scripts.RequestDBUtil
47 import org.onap.so.bpmn.core.UrnPropertiesReader
48 import org.onap.so.bpmn.core.json.JsonUtils
49 import org.onap.so.client.HttpClient
50 import org.onap.so.db.request.beans.OperationStatus
51 import org.onap.so.requestsdb.RequestsDbConstant
52 import org.onap.so.serviceinstancebeans.CloudConfiguration
53 import org.onap.so.serviceinstancebeans.ModelInfo
54 import org.onap.so.serviceinstancebeans.ModelType
55 import org.onap.so.serviceinstancebeans.OwningEntity
56 import org.onap.so.serviceinstancebeans.Project
57 import org.onap.so.serviceinstancebeans.RequestDetails
58 import org.onap.so.serviceinstancebeans.RequestInfo
59 import org.onap.so.serviceinstancebeans.RequestParameters
60 import org.onap.so.serviceinstancebeans.Resources
61 import org.onap.so.serviceinstancebeans.Service
62 import org.onap.so.serviceinstancebeans.SubscriberInfo
63 import org.onap.so.serviceinstancebeans.VfModules
64 import org.onap.so.serviceinstancebeans.Vnfs
65 import org.slf4j.Logger
66 import org.slf4j.LoggerFactory
67
68 import javax.ws.rs.core.Response
69
70 class DoModifyCoreNSSI extends DoCommonCoreNSSI {
71
72     private final String PREFIX ="DoModifyCoreNSSI"
73
74     private ExceptionUtil exceptionUtil = new ExceptionUtil()
75     private RequestDBUtil requestDBUtil = new RequestDBUtil()
76     private MsoUtils utils = new MsoUtils()
77     private JsonUtils jsonUtil = new JsonUtils()
78
79     private static final Logger LOGGER = LoggerFactory.getLogger( DoModifyCoreNSSI.class)
80
81
82     /**
83      * Creates Slice Profile Instance
84      * @param execution
85      */
86     void createSliceProfileInstance(DelegateExecution execution) {
87         LOGGER.trace("${PREFIX} Start createSliceProfileInstance")
88
89         def currentNSSI = execution.getVariable("currentNSSI")
90
91         String sliceProfileID = execution.getVariable("sliceProfileID")
92         Map<String, Object> sliceProfileMap = execution.getVariable("sliceProfileCn")
93         Map<String, Object> serviceProfileMap = execution.getVariable("serviceProfile")
94
95         String globalSubscriberId = currentNSSI['globalSubscriberId']
96         String serviceType = currentNSSI['serviceType']
97         String nssiId = currentNSSI['nssiId']
98
99         SliceProfile sliceProfile = new SliceProfile()
100         sliceProfile.setServiceAreaDimension("")
101         sliceProfile.setPayloadSize(0)
102         sliceProfile.setJitter(0)
103         sliceProfile.setSurvivalTime(0)
104         sliceProfile.setExpDataRate(0)
105         sliceProfile.setTrafficDensity(0)
106         sliceProfile.setConnDensity(0)
107         sliceProfile.setSNssai(sliceProfileMap.get("sNSSAI").toString())
108         sliceProfile.setExpDataRateUL(Integer.parseInt(sliceProfileMap.get("expDataRateUL").toString()))
109         sliceProfile.setExpDataRateDL(Integer.parseInt(sliceProfileMap.get("expDataRateDL").toString()))
110         sliceProfile.setActivityFactor(Integer.parseInt(sliceProfileMap.get("activityFactor").toString()))
111         sliceProfile.setResourceSharingLevel(sliceProfileMap.get("activityFactor").toString())
112         sliceProfile.setUeMobilityLevel(serviceProfileMap.get("uEMobilityLevel").toString())
113         sliceProfile.setCoverageAreaTAList(serviceProfileMap.get("coverageAreaTAList").toString())
114         sliceProfile.setMaxNumberOfUEs(Integer.parseInt(sliceProfileMap.get("activityFactor").toString()))
115         sliceProfile.setLatency(Integer.parseInt(sliceProfileMap.get("latency").toString()))
116         sliceProfile.setProfileId(sliceProfileID)
117         sliceProfile.setE2ELatency(0)
118
119         try {
120             AAIResourcesClient client = getAAIClient()
121             AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SLICE_PROFILE, globalSubscriberId, serviceType, nssiId,  sliceProfileID)
122             client.create(uri, sliceProfile)
123
124             currentNSSI['createdSliceProfile'] = sliceProfile
125         } catch (Exception ex) {
126             exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while Slice Profile create call:" + ex.getMessage())
127         }
128
129         LOGGER.trace("${PREFIX} Exit createSliceProfileInstance")
130     }
131
132
133     /**
134      * Creates Slice Profile association with NSSI
135      * @param execution
136      */
137     void associateSliceProfileInstanceWithNSSI(DelegateExecution execution) {
138         LOGGER.trace("${PREFIX} Start associateSliceProfileInstanceWithNSSI")
139
140         String sliceProfileID = execution.getVariable("sliceProfileID")
141
142         def currentNSSI = execution.getVariable("currentNSSI")
143
144         String globalSubscriberId = currentNSSI['globalSubscriberId']
145         String serviceType = currentNSSI['serviceType']
146         String nssiId = currentNSSI['nssiId']
147
148         AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, nssiId)
149         AAIResourceUri sliceProfileUri = AAIUriFactory.createResourceUri(AAIObjectType.SLICE_PROFILE, globalSubscriberId, serviceType, nssiId, sliceProfileID)
150
151         try {
152             SliceProfile createdSliceProfile = (SliceProfile)currentNSSI['createdSliceProfile']
153             ServiceInstance nssi = (ServiceInstance)currentNSSI['nssi']
154             List<SliceProfile> associatedProfiles = nssi.getSliceProfiles().getSliceProfile()
155             associatedProfiles.add(createdSliceProfile)
156
157             getAAIClient().update(nssiUri, nssi)
158
159             getAAIClient().connect(sliceProfileUri, nssiUri, AAIEdgeLabel.BELONGS_TO)
160         }catch(Exception e){
161             exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while Slice Profile association with NSSI disconnect call: " + e.getMessage())
162         }
163
164         LOGGER.trace("${PREFIX} Exit associateSliceProfileInstanceWithNSSI")
165     }
166
167
168     @Override
169     String getPrefix() {
170         return PREFIX
171     }
172
173 }