2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (c) 2022 Deutsche telekom
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=========================================================
22 package org.onap.so.bpmn.moi.tasks;
24 import com.fasterxml.jackson.databind.ObjectMapper;
25 import org.onap.aai.domain.yang.*;
26 import org.onap.aaiclient.client.aai.AAIRestClientImpl;
27 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri;
28 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory;
29 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder;
30 import org.onap.so.bpmn.common.BuildingBlockExecution;
31 import org.onap.so.bpmn.common.InjectionHelper;
32 import org.onap.so.bpmn.moi.util.AAISliceProfileUtil;
33 import org.onap.so.bpmn.moi.util.SliceProfileAaiToMoiMapperUtil;
34 import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
35 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance;
36 import org.onap.so.moi.Attributes;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
39 import org.springframework.beans.factory.annotation.Autowired;
40 import org.springframework.stereotype.Component;
42 import java.util.stream.Collectors;
45 public class AssignRANNssiBBTasks {
47 private static final Logger LOGGER = LoggerFactory.getLogger(AssignRANNssiBBTasks.class);
50 private InjectionHelper injectionHelper;
52 private ObjectMapper mapper = new ObjectMapper();
54 private AAIRestClientImpl aaiRestClient = new AAIRestClientImpl();
57 AAISliceProfileUtil aaiSliceProfileUtil;
60 private SliceProfileAaiToMoiMapperUtil mapperUtil;
62 public void createNssi(BuildingBlockExecution execution) throws Exception {
65 GeneralBuildingBlock gBB = execution.getGeneralBuildingBlock();
67 String serviceInstanceId = gBB.getServiceInstance().getServiceInstanceId();
69 ModelInfoServiceInstance modelInfoServiceInstance = gBB.getServiceInstance().getModelInfoServiceInstance();
71 // for NON-SHARED check if its Already present
72 if (checkNSSI(execution)) {
73 if (aaiSliceProfileUtil.getServiceInstance(execution).isPresent()) {
74 throw new RuntimeException("Invalid NSSI, Slice subnet already exists");
77 ServiceInstance serviceInstance = new ServiceInstance();
78 serviceInstance.setServiceInstanceId(serviceInstanceId);
79 serviceInstance.setServiceInstanceName("ran_" + serviceInstanceId);
80 serviceInstance.setOrchestrationStatus("Assigned");
81 serviceInstance.setServiceType("nssi");
82 serviceInstance.setModelInvariantId(modelInfoServiceInstance.getModelInvariantUuid());
83 serviceInstance.setModelVersionId(modelInfoServiceInstance.getModelUuid());
84 serviceInstance.setOperationalStatus("LOCKED");
86 Customer customer = getCustomer(execution);
88 AAIResourceUri serviceInstanceURI =
89 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(customer.getGlobalCustomerId())
91 customer.getServiceSubscriptions().getServiceSubscription().get(0).getServiceType())
92 .serviceInstance(serviceInstance.getServiceInstanceId()));
94 injectionHelper.getAaiClient().createIfNotExists(serviceInstanceURI, Optional.of(serviceInstance));
98 private boolean checkNSSI(BuildingBlockExecution execution) {
100 Optional<ServiceInstance> serviceInstance = aaiSliceProfileUtil.getServiceInstance(execution);
103 GeneralBuildingBlock gBB = execution.getGeneralBuildingBlock();
105 String serviceInstanceId = gBB.getServiceInstance().getServiceInstanceId();
107 List<Map<String, Object>> mapUserParams = gBB.getRequestContext().getRequestParameters().getUserParams();
110 Attributes attributes = null;
112 for (Map<String, Object> userParamData : mapUserParams) {
113 if (userParamData.get("nssi") != null) {
114 Map<String, Object> mapParam = (Map<String, Object>) userParamData.get("nssi");
115 attributes = mapper.convertValue(mapParam, Attributes.class);
118 if (attributes.getSliceProfileList().get(0).getRANSliceSubnetProfile().getResourceSharingLevel()
119 .equalsIgnoreCase("NON-SHARED"))
126 public void createSliceProfileInstance(BuildingBlockExecution execution) {
127 GeneralBuildingBlock gBB = execution.getGeneralBuildingBlock();
129 String serviceInstanceId = gBB.getServiceInstance().getServiceInstanceId();
131 Customer customer = getCustomer(execution);
133 List<Map<String, Object>> mapUserParams = gBB.getRequestContext().getRequestParameters().getUserParams();
136 Attributes attributes = null;
138 for (Map<String, Object> userParamData : mapUserParams) {
139 if (userParamData.get("nssi") != null) {
140 Map<String, Object> mapParam = (Map<String, Object>) userParamData.get("nssi");
141 attributes = mapper.convertValue(mapParam, Attributes.class);
144 // Create SliceProfile Instance
145 ServiceInstance sliceProfileServiceInstance = new ServiceInstance();
146 String sliceProfileInstanceId = UUID.randomUUID().toString();
147 sliceProfileServiceInstance.setServiceInstanceId(sliceProfileInstanceId);
148 sliceProfileServiceInstance.setServiceInstanceName("slice-profile-" + serviceInstanceId);
149 sliceProfileServiceInstance.setServiceRole("slice-profile");
151 sliceProfileServiceInstance =
152 mapperUtil.fillSliceProfileInstanceFromMoiRequest(attributes, sliceProfileServiceInstance);
154 AAIResourceUri serviceInstanceURI =
155 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(customer.getGlobalCustomerId())
156 .serviceSubscription(
157 customer.getServiceSubscriptions().getServiceSubscription().get(0).getServiceType())
158 .serviceInstance(sliceProfileServiceInstance.getServiceInstanceId()));
160 injectionHelper.getAaiClient().createIfNotExists(serviceInstanceURI, Optional.of(sliceProfileServiceInstance));
162 List<Map<String, Object>> sliceProfilesData = gBB.getRequestContext().getRequestParameters().getUserParams();
165 SliceProfile sliceProfile = mapperUtil.extractAaiSliceProfileFromMoiRequest(attributes);
166 String sliceProfileId = UUID.randomUUID().toString();
167 sliceProfile.setProfileId(sliceProfileId);
169 AAIResourceUri sliceProfileURI =
170 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(customer.getGlobalCustomerId())
171 .serviceSubscription(
172 customer.getServiceSubscriptions().getServiceSubscription().get(0).getServiceType())
173 .serviceInstance(sliceProfileInstanceId).sliceProfile(sliceProfile.getProfileId()));
175 injectionHelper.getAaiClient().createIfNotExists(sliceProfileURI, Optional.of(sliceProfile));
177 execution.setVariable("sliceProfileServiceInstanceId", sliceProfileServiceInstance.getServiceInstanceId());
180 public void allotResources(BuildingBlockExecution execution) {
182 GeneralBuildingBlock gBB = execution.getGeneralBuildingBlock();
184 String sliceProfileServiceInstanceId = execution.getVariable("sliceProfileServiceInstanceId");
186 LOGGER.debug("sliceProfileServiceInstanceId: {}", sliceProfileServiceInstanceId);
188 Customer customer = getCustomer(execution);
190 org.onap.aai.domain.yang.v23.AllottedResource allottedResource =
191 new org.onap.aai.domain.yang.v23.AllottedResource();
193 UUID allottedResourceUuid = UUID.randomUUID();
194 allottedResource.setId(allottedResourceUuid.toString());
196 AAIResourceUri allotedResourceURI =
197 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(customer.getGlobalCustomerId())
198 .serviceSubscription(
199 customer.getServiceSubscriptions().getServiceSubscription().get(0).getServiceType())
200 .serviceInstance(sliceProfileServiceInstanceId).allottedResource(allottedResource.getId()));
202 injectionHelper.getAaiClient().createIfNotExists(allotedResourceURI, Optional.of(allottedResource));
204 execution.setVariable("allottedResourceUuid", allottedResource.getId());
209 public void addSliceProfileToNssi(BuildingBlockExecution execution) {
210 LOGGER.info("Entering into addSliceProfileToNssi");
212 String sliceProfileServiceInstanceId = execution.getVariable("sliceProfileServiceInstanceId");
213 String allottedResourceUuid = execution.getVariable("allottedResourceUuid");
214 GeneralBuildingBlock gBB = execution.getGeneralBuildingBlock();
215 String serviceInstanceId = gBB.getServiceInstance().getServiceInstanceId();
217 Customer customer = getCustomer(execution);
220 AAIResourceUri nssiUri =
221 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(customer.getGlobalCustomerId())
222 .serviceSubscription(
223 customer.getServiceSubscriptions().getServiceSubscription().get(0).getServiceType())
224 .serviceInstance(serviceInstanceId));
226 AAIResourceUri allotedResourceURI =
227 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(customer.getGlobalCustomerId())
228 .serviceSubscription(
229 customer.getServiceSubscriptions().getServiceSubscription().get(0).getServiceType())
230 .serviceInstance(sliceProfileServiceInstanceId).allottedResource(allottedResourceUuid));
233 injectionHelper.getAaiClient().connect(allotedResourceURI, nssiUri);
234 } catch (Exception e) {
235 LOGGER.error(">>>>> Error in creating Relationship: {} ", e);
239 public void activateNssi(BuildingBlockExecution execution) {
240 GeneralBuildingBlock gBB = execution.getGeneralBuildingBlock();
241 String serviceInstanceId = gBB.getServiceInstance().getServiceInstanceId();
243 Customer customer = getCustomer(execution);
245 AAIResourceUri serviceInstanceURI =
246 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(customer.getGlobalCustomerId())
247 .serviceSubscription(
248 customer.getServiceSubscriptions().getServiceSubscription().get(0).getServiceType())
249 .serviceInstance(serviceInstanceId));
251 Optional<ServiceInstance> serviceInstanceReturned =
252 injectionHelper.getAaiClient().get(ServiceInstance.class, serviceInstanceURI);
254 ServiceInstance serviceInstance = null;
255 if (serviceInstanceReturned.isPresent()) {
256 serviceInstance = serviceInstanceReturned.get();
257 serviceInstance.setOperationalStatus("UNLOCKED");
258 serviceInstance.setOrchestrationStatus("Active");
261 injectionHelper.getAaiClient().update(serviceInstanceURI, serviceInstance);
262 } catch (Exception e) {
263 LOGGER.error("Nssi couldnot be activated: {}", e);
266 LOGGER.debug("Service Instance not present with Id: {}", serviceInstanceId);
270 List<org.onap.so.moi.SliceProfile> sliceProfileList = new ArrayList<org.onap.so.moi.SliceProfile>();
271 ServiceInstance serviceInstanceObj;
272 List<Relationship> listOfNssiRelationship = serviceInstance.getRelationshipList().getRelationship();
274 List<Relationship> listOfNssiRelationshipAR = listOfNssiRelationship.stream()
275 .filter(relationship -> relationship.getRelatedTo().equalsIgnoreCase("allotted-resource"))
276 .collect(Collectors.toList());
278 for (Relationship relationship : listOfNssiRelationshipAR) {
279 org.onap.so.moi.SliceProfile sliceProfile = new org.onap.so.moi.SliceProfile();
280 for (RelationshipData relationshipData : relationship.getRelationshipData()) {
281 if (relationshipData.getRelationshipKey().equalsIgnoreCase("service-instance.service-instance-id")) {
282 String sliceProfileInstanceId = relationshipData.getRelationshipValue();
284 Optional<ServiceInstance> sliceProfileServiceInstance =
285 aaiRestClient.getServiceInstanceById(sliceProfileInstanceId, "5G", "5GCustomer");
286 if (sliceProfileServiceInstance.isPresent()) {
287 ServiceInstance sliceProflieInstance = sliceProfileServiceInstance.get();
288 sliceProflieInstance.setOperationalStatus("UNLOCKED");
289 sliceProflieInstance.setOrchestrationStatus("ACTIVE");
291 AAIResourceUri sliceProfileInstanceURI = AAIUriFactory.createResourceUri(
292 AAIFluentTypeBuilder.business().customer(customer.getGlobalCustomerId())
293 .serviceSubscription(customer.getServiceSubscriptions().getServiceSubscription()
294 .get(0).getServiceType())
295 .serviceInstance(sliceProflieInstance.getServiceInstanceId()));
297 injectionHelper.getAaiClient().update(sliceProfileInstanceURI, sliceProflieInstance);
298 } catch (Exception e) {
299 LOGGER.error("SliceProfile couldnot be activated: {}", e);
302 LOGGER.debug("Slice Profile Instance not present with Id: {}", serviceInstanceId);
313 private Customer getCustomer(BuildingBlockExecution execution) {
315 GeneralBuildingBlock gBB = execution.getGeneralBuildingBlock();
317 String serviceType = gBB.getCustomer().getServiceSubscription().getServiceType();
319 String globalCustomerId = gBB.getCustomer().getGlobalCustomerId();
321 ServiceSubscription serviceSubscription = new ServiceSubscription();
322 serviceSubscription.setServiceType(serviceType);
324 ServiceSubscriptions serviceSubscriptions = new ServiceSubscriptions();
325 serviceSubscriptions.getServiceSubscription().add(serviceSubscription);
327 Customer customer = new Customer();
328 customer.setGlobalCustomerId(globalCustomerId);
329 customer.setServiceSubscriptions(serviceSubscriptions);