2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
20 package org.onap.so.sdncsimulator.providers;
22 import static org.onap.sdnc.northbound.client.model.GenericResourceApiOrderStatusEnumeration.CREATED;
23 import static org.onap.sdnc.northbound.client.model.GenericResourceApiOrderStatusEnumeration.PENDINGCREATE;
24 import static org.onap.sdnc.northbound.client.model.GenericResourceApiRequestStatusEnumeration.SYNCCOMPLETE;
25 import static org.onap.so.sdncsimulator.utils.Constants.RESTCONF_CONFIG_END_POINT;
26 import static org.onap.so.sdncsimulator.utils.Constants.SERVICE_DATA_VNFS_VNF;
27 import static org.onap.so.sdncsimulator.utils.Constants.SERVICE_TOPOLOGY_OPERATION;
28 import static org.onap.so.sdncsimulator.utils.Constants.SERVICE_TOPOLOGY_OPERATION_CACHE;
29 import static org.onap.so.sdncsimulator.utils.Constants.VNF_DATA_VNF_TOPOLOGY;
30 import static org.onap.so.sdncsimulator.utils.Constants.YES;
31 import static org.onap.so.sdncsimulator.utils.ObjectUtils.getString;
32 import static org.onap.so.sdncsimulator.utils.ObjectUtils.getStringOrNull;
33 import static org.onap.so.sdncsimulator.utils.ObjectUtils.isValid;
34 import java.time.LocalDateTime;
35 import java.util.ArrayList;
36 import java.util.List;
37 import java.util.Optional;
38 import javax.validation.Valid;
39 import org.onap.sdnc.northbound.client.model.GenericResourceApiInstanceReference;
40 import org.onap.sdnc.northbound.client.model.GenericResourceApiLastActionEnumeration;
41 import org.onap.sdnc.northbound.client.model.GenericResourceApiLastRpcActionEnumeration;
42 import org.onap.sdnc.northbound.client.model.GenericResourceApiOnapmodelinformationOnapModelInformation;
43 import org.onap.sdnc.northbound.client.model.GenericResourceApiOperStatusData;
44 import org.onap.sdnc.northbound.client.model.GenericResourceApiOrderStatusEnumeration;
45 import org.onap.sdnc.northbound.client.model.GenericResourceApiRequestinformationRequestInformation;
46 import org.onap.sdnc.northbound.client.model.GenericResourceApiRpcActionEnumeration;
47 import org.onap.sdnc.northbound.client.model.GenericResourceApiSdncrequestheaderSdncRequestHeader;
48 import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceOperationInformation;
49 import org.onap.sdnc.northbound.client.model.GenericResourceApiServicedataServiceData;
50 import org.onap.sdnc.northbound.client.model.GenericResourceApiServicedataServicedataVnfs;
51 import org.onap.sdnc.northbound.client.model.GenericResourceApiServicedataServicedataVnfsVnf;
52 import org.onap.sdnc.northbound.client.model.GenericResourceApiServicedataServicedataVnfsVnfVnfData;
53 import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceinformationServiceInformation;
54 import org.onap.sdnc.northbound.client.model.GenericResourceApiServicemodelinfrastructureService;
55 import org.onap.sdnc.northbound.client.model.GenericResourceApiServicestatusServiceStatus;
56 import org.onap.sdnc.northbound.client.model.GenericResourceApiServicetopologyServiceTopology;
57 import org.onap.sdnc.northbound.client.model.GenericResourceApiServicetopologyidentifierServiceTopologyIdentifier;
58 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfOperationInformation;
59 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfinformationVnfInformation;
60 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfrequestinputVnfRequestInput;
61 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnftopologyVnfTopology;
62 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnftopologyidentifierstructureVnfTopologyIdentifierStructure;
64 import org.onap.sdnc.northbound.client.model.GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfmodulesVfmoduleVfModuleData;
65 import org.onap.sdnc.northbound.client.model.GenericResourceApiVfModuleTopology;
66 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfTopology;
67 import org.onap.sdnc.northbound.client.model.GenericResourceApiVfModuleOperationInformation;
68 import org.onap.sdnc.northbound.client.model.GenericResourceApiVfmoduleinformationVfModuleInformation;
69 import org.onap.sdnc.northbound.client.model.GenericResourceApiVfmoduletopologyVfModuleTopology;
70 import org.onap.sdnc.northbound.client.model.GenericResourceApiVfmoduletopologyidentifierVfModuleTopologyIdentifier;
71 import org.onap.sdnc.northbound.client.model.GenericResourceApiParam;
72 import org.onap.sdnc.northbound.client.model.GenericResourceApiParamParam;
74 import org.onap.so.sdncsimulator.models.Output;
75 import org.onap.so.sdncsimulator.utils.Constants;
76 import org.onap.so.simulator.cache.provider.AbstractCacheServiceProvider;
77 import org.slf4j.Logger;
78 import org.slf4j.LoggerFactory;
79 import org.springframework.beans.factory.annotation.Autowired;
80 import org.springframework.cache.Cache;
81 import org.springframework.cache.CacheManager;
82 import org.springframework.http.HttpStatus;
83 import org.springframework.stereotype.Service;
86 * @author Waqas Ikram (waqas.ikram@est.tech)
90 public class ServiceOperationsCacheServiceProviderimpl extends AbstractCacheServiceProvider
91 implements ServiceOperationsCacheServiceProvider {
93 private static final String HTTP_STATUS_BAD_REQUEST = Integer.toString(HttpStatus.BAD_REQUEST.value());
94 private static final String HTTP_STATUS_OK = Integer.toString(HttpStatus.OK.value());
95 private static final String EMPTY_STRING = "";
96 private static final Logger LOGGER = LoggerFactory.getLogger(ServiceOperationsCacheServiceProviderimpl.class);
99 public ServiceOperationsCacheServiceProviderimpl(final CacheManager cacheManager) {
104 public Output putServiceOperationInformation(final GenericResourceApiServiceOperationInformation input) {
106 final GenericResourceApiSdncrequestheaderSdncRequestHeader requestHeader = input.getSdncRequestHeader();
107 final String svcRequestId = getSvcRequestId(requestHeader);
109 final GenericResourceApiServiceinformationServiceInformation serviceInformation = input.getServiceInformation();
110 if (serviceInformation != null && isValid(serviceInformation.getServiceInstanceId())) {
111 final String serviceInstanceId = serviceInformation.getServiceInstanceId();
113 if (isServiceOperationInformationNotExists(serviceInstanceId, input)) {
114 final Cache cache = getCache(SERVICE_TOPOLOGY_OPERATION_CACHE);
115 LOGGER.info("Adding GenericResourceApiServiceOperationInformation to cache with key: {}",
118 final GenericResourceApiServicemodelinfrastructureService service =
119 getServiceItem(input, serviceInstanceId);
120 cache.put(serviceInstanceId, service);
122 final GenericResourceApiServicestatusServiceStatus serviceStatus = service.getServiceStatus();
124 return new Output().ackFinalIndicator(serviceStatus.getFinalIndicator())
125 .responseCode(serviceStatus.getResponseCode())
126 .responseMessage(serviceStatus.getResponseMessage()).svcRequestId(svcRequestId)
127 .serviceResponseInformation(new GenericResourceApiInstanceReference()
128 .instanceId(serviceInstanceId).objectPath(getObjectPath(serviceInstanceId)));
130 LOGGER.error("serviceInstanceId: {} already exists", serviceInstanceId);
131 return new Output().ackFinalIndicator(YES).responseCode(HTTP_STATUS_BAD_REQUEST)
132 .responseMessage("serviceInstanceId: " + serviceInstanceId + " already exists")
133 .svcRequestId(svcRequestId);
137 "Unable to add GenericResourceApiServiceOperationInformation in cache due to invalid input: {}... ",
139 return new Output().ackFinalIndicator(YES).responseCode(HTTP_STATUS_BAD_REQUEST)
140 .responseMessage("Service instance not found").svcRequestId(svcRequestId);
145 public Output deleteServiceOperationInformation(final GenericResourceApiServiceOperationInformation input) {
146 final GenericResourceApiServiceinformationServiceInformation serviceInformation = input.getServiceInformation();
147 final String svcRequestId = getSvcRequestId(input.getSdncRequestHeader());
149 if (serviceInformation != null && isValid(serviceInformation.getServiceInstanceId())) {
150 final String serviceInstanceId = serviceInformation.getServiceInstanceId();
151 final Optional<GenericResourceApiServicemodelinfrastructureService> optional =
152 getGenericResourceApiServicemodelinfrastructureService(serviceInstanceId);
153 if (optional.isPresent()) {
154 final Cache cache = getCache(SERVICE_TOPOLOGY_OPERATION_CACHE);
155 LOGGER.info("Deleting GenericResourceApiServiceOperationInformation from cache using key: {}",
157 cache.evict(serviceInstanceId);
158 return new Output().ackFinalIndicator(YES).responseCode(HTTP_STATUS_OK)
159 .responseMessage(EMPTY_STRING).svcRequestId(svcRequestId).serviceResponseInformation(
160 new GenericResourceApiInstanceReference().instanceId(serviceInstanceId));
163 "Unable to find existing GenericResourceApiServiceModelInfrastructure in cache using service instance id: {}",
167 LOGGER.error("Unable to remove service instance from cache due to invalid input: {}... ", input);
168 return new Output().ackFinalIndicator(YES).responseCode(HTTP_STATUS_BAD_REQUEST)
169 .responseMessage("Unable to remove service").svcRequestId(svcRequestId);
173 public Optional<GenericResourceApiServicemodelinfrastructureService> getGenericResourceApiServicemodelinfrastructureService(
174 final String serviceInstanceId) {
175 final Cache cache = getCache(SERVICE_TOPOLOGY_OPERATION_CACHE);
177 final GenericResourceApiServicemodelinfrastructureService value =
178 cache.get(serviceInstanceId, GenericResourceApiServicemodelinfrastructureService.class);
180 LOGGER.info("Found {} in cahce for service instance id: {}", value, serviceInstanceId);
181 return Optional.of(value);
183 LOGGER.error("Unable to find GenericResourceApiServiceModelInfrastructure in cache for service instance id: {}",
185 return Optional.empty();
189 public Output putVnfOperationInformation(final GenericResourceApiVnfOperationInformation input) {
191 final GenericResourceApiServiceinformationServiceInformation serviceInformation = input.getServiceInformation();
192 final GenericResourceApiVnfinformationVnfInformation vnfInformation = input.getVnfInformation();
194 final GenericResourceApiSdncrequestheaderSdncRequestHeader requestHeader = input.getSdncRequestHeader();
195 final String svcRequestId = getSvcRequestId(requestHeader);
197 if (serviceInformation != null && isValid(serviceInformation.getServiceInstanceId()) && vnfInformation != null
198 && isValid(vnfInformation.getVnfId())) {
199 final String serviceInstanceId = serviceInformation.getServiceInstanceId();
200 final String vnfId = vnfInformation.getVnfId();
201 final Optional<GenericResourceApiServicemodelinfrastructureService> optional =
202 getGenericResourceApiServicemodelinfrastructureService(serviceInstanceId);
203 if (optional.isPresent()) {
204 final GenericResourceApiServicemodelinfrastructureService service = optional.get();
205 final GenericResourceApiServicedataServiceData serviceData = service.getServiceData();
206 if (serviceData != null) {
207 final List<GenericResourceApiServicedataServicedataVnfsVnf> vnfsList = getVnfs(serviceData);
208 final GenericResourceApiLastRpcActionEnumeration svcAction =
209 GenericResourceApiLastRpcActionEnumeration.fromValue(getSvcAction(requestHeader));
211 if (ifVnfNotExists(vnfId, svcAction, vnfsList)) {
212 vnfsList.add(getGenericResourceApiServicedataVnf(serviceInstanceId, vnfId, input));
213 setVnfsData(vnfsList);
214 final GenericResourceApiServicestatusServiceStatus serviceStatus = service.getServiceStatus();
216 return new Output().ackFinalIndicator(serviceStatus.getFinalIndicator())
217 .responseCode(serviceStatus.getResponseCode())
218 .responseMessage(serviceStatus.getResponseMessage()).svcRequestId(svcRequestId)
219 .serviceResponseInformation(new GenericResourceApiInstanceReference()
220 .instanceId(serviceInstanceId).objectPath(getObjectPath(serviceInstanceId)))
221 .vnfResponseInformation(new GenericResourceApiInstanceReference().instanceId(vnfId)
222 .objectPath(getObjectPath(serviceInstanceId, vnfId)));
224 LOGGER.error("vnfId: {} already exists with SVC Action: {}", vnfId, svcAction);
225 return new Output().ackFinalIndicator(YES).responseCode(HTTP_STATUS_BAD_REQUEST)
226 .responseMessage("vnfId: " + vnfId + " already exists").svcRequestId(svcRequestId);
230 "Unable to find existing GenericResourceApiServiceModelInfrastructure in cache using service instance id: {}",
235 "Unable to add GenericResourceApiServiceOperationInformation in cache due to invalid input: {}... ",
237 return new Output().ackFinalIndicator(YES).responseCode(HTTP_STATUS_BAD_REQUEST)
238 .responseMessage("Unable to add vnf").svcRequestId(svcRequestId);
242 public Output deleteVnfOperationInformation(final GenericResourceApiVnfOperationInformation input) {
243 final GenericResourceApiServiceinformationServiceInformation serviceInformation = input.getServiceInformation();
244 final GenericResourceApiVnfinformationVnfInformation vnfInformation = input.getVnfInformation();
246 final GenericResourceApiSdncrequestheaderSdncRequestHeader requestHeader = input.getSdncRequestHeader();
247 final String svcRequestId = getSvcRequestId(requestHeader);
249 if (serviceInformation != null && isValid(serviceInformation.getServiceInstanceId()) && vnfInformation != null
250 && isValid(vnfInformation.getVnfId())) {
251 final String serviceInstanceId = serviceInformation.getServiceInstanceId();
252 final String vnfId = vnfInformation.getVnfId();
253 final Optional<GenericResourceApiServicemodelinfrastructureService> optional =
254 getGenericResourceApiServicemodelinfrastructureService(serviceInstanceId);
255 if (optional.isPresent()) {
256 final GenericResourceApiServicemodelinfrastructureService service = optional.get();
257 final GenericResourceApiServicedataServiceData serviceData = service.getServiceData();
258 if (serviceData != null) {
259 final List<GenericResourceApiServicedataServicedataVnfsVnf> vnfsList = getVnfs(serviceData);
260 final Optional<GenericResourceApiServicedataServicedataVnfsVnf> vnfInstanceOptional =
261 getExistingVnf(vnfId, vnfsList);
263 if (vnfInstanceOptional.isPresent()) {
264 vnfsList.removeIf(vnf -> {
265 final String existingVnfId = vnf.getVnfId();
266 if (existingVnfId != null && existingVnfId.equals(vnfId)) {
267 LOGGER.info("Remove vnf with id: {} ... ", existingVnfId);
273 return new Output().ackFinalIndicator(YES).responseCode(HTTP_STATUS_OK)
274 .responseMessage(EMPTY_STRING).svcRequestId(svcRequestId)
275 .serviceResponseInformation(
276 new GenericResourceApiInstanceReference().instanceId(serviceInstanceId))
277 .vnfResponseInformation(new GenericResourceApiInstanceReference().instanceId(vnfId));
283 "Unable to find existing GenericResourceApiServiceModelInfrastructure in cache using service instance id: {}",
287 LOGGER.error("Unable to remove vnf instance from cache due to invalid input: {}... ", input);
288 return new Output().ackFinalIndicator(YES).responseCode(HTTP_STATUS_BAD_REQUEST)
289 .responseMessage("Unable to remove vnf").svcRequestId(svcRequestId);
293 private String getSvcRequestId(final GenericResourceApiSdncrequestheaderSdncRequestHeader requestHeader) {
294 return requestHeader != null ? requestHeader.getSvcRequestId() : null;
298 public void clearAll() {
299 clearCache(SERVICE_TOPOLOGY_OPERATION_CACHE);
302 private String getObjectPath(final String serviceInstanceId, final String vnfId) {
303 return getObjectPath(serviceInstanceId) + SERVICE_DATA_VNFS_VNF + vnfId + VNF_DATA_VNF_TOPOLOGY;
306 private String getObjectPath(final String serviceInstanceId) {
307 return RESTCONF_CONFIG_END_POINT + serviceInstanceId;
311 private boolean ifVnfNotExists(final String vnfId, final GenericResourceApiLastRpcActionEnumeration svcAction,
312 final List<GenericResourceApiServicedataServicedataVnfsVnf> vnfsList) {
313 final Optional<GenericResourceApiServicedataServicedataVnfsVnf> optional = getExistingVnf(vnfId, vnfsList);
314 if (optional.isPresent()) {
315 final GenericResourceApiServicedataServicedataVnfsVnf existingVnf = optional.get();
316 final GenericResourceApiServicedataServicedataVnfsVnfVnfData vnfData = existingVnf.getVnfData();
318 if (vnfData != null && vnfData.getVnfLevelOperStatus() != null
319 && vnfData.getVnfLevelOperStatus().getLastRpcAction() != null) {
320 final GenericResourceApiLastRpcActionEnumeration existingVnflastRpcAction =
321 vnfData.getVnfLevelOperStatus().getLastRpcAction();
322 if (existingVnflastRpcAction.equals(svcAction)) {
323 LOGGER.error("Found vnf with id: {} and LastRpcAction: {} same as SvcAction: {}", vnfId,
324 existingVnflastRpcAction, svcAction);
327 LOGGER.warn("Will remove and replace existing vnf with id: {} as SvcAction is changed from {} to {}",
328 vnfId, existingVnflastRpcAction, svcAction);
329 vnfsList.removeIf(vnf -> vnf.getVnfId() != null && vnf.getVnfId().equals(vnfId));
337 private Optional<GenericResourceApiServicedataServicedataVnfsVnf> getExistingVnf(final String vnfId,
338 final List<GenericResourceApiServicedataServicedataVnfsVnf> vnfsList) {
339 return vnfsList.stream().filter(vnf -> vnf.getVnfId() != null && vnf.getVnfId().equals(vnfId)).findFirst();
342 private List<GenericResourceApiServicedataServicedataVnfsVnf> getVnfs(
343 final GenericResourceApiServicedataServiceData serviceData) {
344 GenericResourceApiServicedataServicedataVnfs vnfs = serviceData.getVnfs();
346 vnfs = new GenericResourceApiServicedataServicedataVnfs();
347 serviceData.setVnfs(vnfs);
350 List<GenericResourceApiServicedataServicedataVnfsVnf> vnfsList = vnfs.getVnf();
351 if (vnfsList == null) {
352 vnfsList = new ArrayList<>();
353 vnfs.setVnf(vnfsList);
358 private GenericResourceApiServicedataServicedataVnfsVnf getGenericResourceApiServicedataVnf(
359 final String serviceInstanceId, final String vnfId, final GenericResourceApiVnfOperationInformation input) {
360 return new GenericResourceApiServicedataServicedataVnfsVnf().vnfId(vnfId).vnfData(getVnfData(input));
363 private GenericResourceApiServicedataServicedataVnfsVnfVnfData getVnfData(
364 final GenericResourceApiVnfOperationInformation input) {
366 final GenericResourceApiServicedataServicedataVnfsVnfVnfData vnfData =
367 new GenericResourceApiServicedataServicedataVnfsVnfVnfData();
369 vnfData.vnfLevelOperStatus(
370 getServiceLevelOperStatus(PENDINGCREATE, input.getRequestInformation(), input.getSdncRequestHeader()));
371 vnfData.serviceInformation(input.getServiceInformation());
372 vnfData.sdncRequestHeader(input.getSdncRequestHeader());
373 vnfData.vnfInformation(input.getVnfInformation());
374 vnfData.requestInformation(input.getRequestInformation());
375 vnfData.vnfRequestInput(input.getVnfRequestInput());
377 vnfData.vnfTopology(getVnfTopology(input.getVnfInformation(), input.getVnfRequestInput()));
382 private GenericResourceApiVnftopologyVnfTopology getVnfTopology(
383 final GenericResourceApiVnfinformationVnfInformation vnfInformation,
384 final GenericResourceApiVnfrequestinputVnfRequestInput vnfRequestInput) {
386 final GenericResourceApiVnftopologyVnfTopology apiVnftopologyVnfTopology =
387 new GenericResourceApiVnftopologyVnfTopology();
389 if (vnfInformation != null) {
390 apiVnftopologyVnfTopology.onapModelInformation(vnfInformation.getOnapModelInformation());
391 apiVnftopologyVnfTopology.vnfTopologyIdentifierStructure(getTopologyIdentifierStructure(vnfInformation));
393 if (vnfRequestInput != null) {
394 apiVnftopologyVnfTopology.tenant(vnfRequestInput.getTenant());
395 apiVnftopologyVnfTopology.aicClli(vnfRequestInput.getAicClli());
396 apiVnftopologyVnfTopology.aicCloudRegion(vnfRequestInput.getAicCloudRegion());
398 return apiVnftopologyVnfTopology;
401 private GenericResourceApiVnftopologyidentifierstructureVnfTopologyIdentifierStructure getTopologyIdentifierStructure(
402 @Valid final GenericResourceApiVnfinformationVnfInformation vnfInformation) {
403 return new GenericResourceApiVnftopologyidentifierstructureVnfTopologyIdentifierStructure()
404 .vnfId(vnfInformation.getVnfId()).vnfName(vnfInformation.getVnfName())
405 .vnfType(vnfInformation.getVnfType());
408 private GenericResourceApiServicemodelinfrastructureService getServiceItem(
409 final GenericResourceApiServiceOperationInformation input, final String serviceInstanceId) {
411 final GenericResourceApiServicedataServiceData apiServicedataServiceData =
412 new GenericResourceApiServicedataServiceData();
414 apiServicedataServiceData.requestInformation(input.getRequestInformation());
415 apiServicedataServiceData.serviceRequestInput(input.getServiceRequestInput());
416 apiServicedataServiceData.serviceInformation(input.getServiceInformation());
417 apiServicedataServiceData.serviceTopology(getServiceTopology(input));
418 apiServicedataServiceData.sdncRequestHeader(input.getSdncRequestHeader());
419 apiServicedataServiceData.serviceLevelOperStatus(getServiceLevelOperStatus(input));
421 final GenericResourceApiServicestatusServiceStatus serviceStatus =
422 getServiceStatus(getSvcAction(input.getSdncRequestHeader()),
423 getRequestAction(input.getRequestInformation()), HTTP_STATUS_OK);
425 return new GenericResourceApiServicemodelinfrastructureService().serviceData(apiServicedataServiceData)
426 .serviceStatus(serviceStatus).serviceInstanceId(serviceInstanceId);
429 private String getSvcAction(final GenericResourceApiSdncrequestheaderSdncRequestHeader input) {
430 return input != null ? getStringOrNull(input.getSvcAction()) : null;
433 private GenericResourceApiServicestatusServiceStatus getServiceStatus(final String rpcAction, final String action,
434 final String responseCode) {
435 return new GenericResourceApiServicestatusServiceStatus().finalIndicator(YES)
436 .rpcAction(GenericResourceApiRpcActionEnumeration.fromValue(rpcAction))
437 .rpcName(SERVICE_TOPOLOGY_OPERATION).responseTimestamp(LocalDateTime.now().toString())
438 .responseCode(responseCode).requestStatus(SYNCCOMPLETE).responseMessage(EMPTY_STRING).action(action);
441 private GenericResourceApiOperStatusData getServiceLevelOperStatus(
442 final GenericResourceApiServiceOperationInformation input) {
443 return getServiceLevelOperStatus(CREATED, input.getRequestInformation(), input.getSdncRequestHeader());
446 private GenericResourceApiOperStatusData getServiceLevelOperStatus(
447 final GenericResourceApiOrderStatusEnumeration statusEnumeration,
448 final GenericResourceApiRequestinformationRequestInformation requestInformation,
449 final GenericResourceApiSdncrequestheaderSdncRequestHeader sdncRequestHeader) {
450 return new GenericResourceApiOperStatusData().orderStatus(statusEnumeration)
451 .lastAction(GenericResourceApiLastActionEnumeration.fromValue(getRequestAction(requestInformation)))
452 .lastRpcAction(GenericResourceApiLastRpcActionEnumeration.fromValue(getSvcAction(sdncRequestHeader)));
455 private String getRequestAction(final GenericResourceApiRequestinformationRequestInformation input) {
456 return getRequestAction(input, EMPTY_STRING);
459 private String getRequestAction(final GenericResourceApiRequestinformationRequestInformation input,
460 final String defaultValue) {
461 return input != null ? getString(input.getRequestAction(), defaultValue) : defaultValue;
464 private GenericResourceApiServicetopologyServiceTopology getServiceTopology(
465 final GenericResourceApiServiceOperationInformation input) {
466 final GenericResourceApiOnapmodelinformationOnapModelInformation modelInformation =
467 input.getServiceInformation() != null ? input.getServiceInformation().getOnapModelInformation() : null;
468 return new GenericResourceApiServicetopologyServiceTopology().onapModelInformation(modelInformation)
469 .serviceTopologyIdentifier(getServiceTopologyIdentifier(input));
472 private GenericResourceApiServicetopologyidentifierServiceTopologyIdentifier getServiceTopologyIdentifier(
473 final GenericResourceApiServiceOperationInformation input) {
474 final GenericResourceApiServicetopologyidentifierServiceTopologyIdentifier identifier =
475 new GenericResourceApiServicetopologyidentifierServiceTopologyIdentifier();
477 if (input.getServiceInformation() != null) {
478 final GenericResourceApiServiceinformationServiceInformation serviceInformation =
479 input.getServiceInformation();
480 identifier.globalCustomerId(serviceInformation.getGlobalCustomerId())
481 .serviceType(input.getServiceInformation().getSubscriptionServiceType())
482 .serviceInstanceId(input.getServiceInformation().getServiceInstanceId());;
485 if (input.getServiceRequestInput() != null) {
486 identifier.serviceInstanceName(input.getServiceRequestInput().getServiceInstanceName());
493 private boolean isServiceOperationInformationNotExists(final String serviceInstanceId,
494 final GenericResourceApiServiceOperationInformation input) {
495 final GenericResourceApiSdncrequestheaderSdncRequestHeader requestHeader = input.getSdncRequestHeader();
496 final Optional<GenericResourceApiServicemodelinfrastructureService> optional =
497 getGenericResourceApiServicemodelinfrastructureService(serviceInstanceId);
499 if (optional.isPresent()) {
500 final GenericResourceApiServicemodelinfrastructureService existingService = optional.get();
501 final GenericResourceApiServicestatusServiceStatus serviceStatus = existingService.getServiceStatus();
502 if (serviceStatus != null) {
503 final GenericResourceApiRpcActionEnumeration rpcAction = serviceStatus.getRpcAction();
504 final String svcAction = getSvcAction(requestHeader);
505 if (rpcAction != null && rpcAction.toString().equals(svcAction)) {
506 LOGGER.error("Found Service with id: {} and RpcAction: {} same as SvcAction: {}",
507 serviceInstanceId, rpcAction, svcAction);
511 final Cache cache = getCache(SERVICE_TOPOLOGY_OPERATION_CACHE);
513 "Deleting existing GenericResourceApiServiceOperationInformation from cache using key: {} as SvcAction is changed from {} to {}",
514 serviceInstanceId, rpcAction, svcAction);
515 cache.evict(serviceInstanceId);
523 public Output putVfModuleOperationInformation(
524 final GenericResourceApiVfModuleOperationInformation input) {
526 final GenericResourceApiServiceinformationServiceInformation serviceInformation = input.getServiceInformation();
527 final GenericResourceApiVnfinformationVnfInformation vnfInformation = input.getVnfInformation();
528 final GenericResourceApiVfmoduleinformationVfModuleInformation vfModuleInformation = input.getVfModuleInformation();
529 // Call getVfModule to make a vfList for get the vf-module-information while GET reqest
532 final GenericResourceApiSdncrequestheaderSdncRequestHeader requestHeader = input.getSdncRequestHeader();
533 final String svcRequestId = getSvcRequestId(requestHeader);
535 if (serviceInformation != null && isValid(serviceInformation.getServiceInstanceId()) && vnfInformation != null
536 && isValid(vnfInformation.getVnfId()) && vfModuleInformation !=null && isValid(vfModuleInformation.getVfModuleId())) {
539 final String serviceInstanceId = serviceInformation.getServiceInstanceId();
540 final String vnfId = vnfInformation.getVnfId();
541 final String vfModuleId = vfModuleInformation.getVfModuleId();
543 final Optional<GenericResourceApiServicemodelinfrastructureService> optional =
544 getGenericResourceApiServicemodelinfrastructureService(serviceInstanceId);
545 if (optional.isPresent()) {
546 final GenericResourceApiServicemodelinfrastructureService service = optional.get();
547 final GenericResourceApiServicedataServiceData serviceData = service.getServiceData();
548 if (serviceData != null) {
550 final GenericResourceApiServicestatusServiceStatus serviceStatus = service.getServiceStatus();
552 return new Output().ackFinalIndicator(serviceStatus.getFinalIndicator())
553 .responseCode(serviceStatus.getResponseCode())
554 .responseMessage(serviceStatus.getResponseMessage()).svcRequestId(svcRequestId)
555 .serviceResponseInformation(new GenericResourceApiInstanceReference()
556 .instanceId(serviceInstanceId).objectPath(getObjectPath(serviceInstanceId)))
557 .vnfResponseInformation(new GenericResourceApiInstanceReference().instanceId(vnfId)
558 .objectPath(getObjectPath(serviceInstanceId, vnfId)))
559 .vfModuleResponseInformation(new GenericResourceApiInstanceReference().instanceId(vfModuleId)
560 .objectPath(getObjectPath(vnfId, vfModuleId)));
564 "Unable to find existing GenericResourceApiServiceModelInfrastructure in cache using service instance id: {}",
568 "Unable to add GenericResourceApiServiceOperationInformation in cache due to invalid input: {}... ",
570 return new Output().ackFinalIndicator(YES).responseCode(HTTP_STATUS_BAD_REQUEST)
571 .responseMessage("Unable to add vfModule").svcRequestId(svcRequestId);
574 private void getVfModule
575 (final GenericResourceApiVfModuleOperationInformation input) {
577 final GenericResourceApiVfmoduletopologyVfModuleTopology apiVfModuletopologyVfModuleTopology =
578 new GenericResourceApiVfmoduletopologyVfModuleTopology();
580 final GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfmodulesVfmoduleVfModuleData vfModuleData =
581 new GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfmodulesVfmoduleVfModuleData();
583 final String vfModuleId = input.getVfModuleInformation().getVfModuleId();
585 vfModuleData.setVfModuleInformation(input.getVfModuleInformation());
586 vfModuleData.setVfModuleRequestInput(input.getVfModuleRequestInput());
588 final GenericResourceApiVfmoduletopologyVfModuleTopology vfModuleTopology =
589 new GenericResourceApiVfmoduletopologyVfModuleTopology();
591 vfModuleTopology.setSdncGeneratedCloudResources(true);
592 final GenericResourceApiParam vfModuleParametersData = new GenericResourceApiParam();
593 final List<GenericResourceApiParamParam> params = new ArrayList<GenericResourceApiParamParam>();
594 final GenericResourceApiParamParam param = new GenericResourceApiParamParam();
595 param.setName("k8s-rb-profile-name");
596 param.setValue("k8s-rb-profile-value");
599 vfModuleParametersData.setParam(params);
600 vfModuleTopology.setVfModuleParameters(vfModuleParametersData);
602 vfModuleTopology.setOnapModelInformation(vfModuleData.getVfModuleInformation().getOnapModelInformation());
603 vfModuleTopology.setVfModuleParameters(vfModuleData.getVfModuleRequestInput().getVfModuleInputParameters());
604 vfModuleTopology.setAicClli(vfModuleData.getVfModuleRequestInput().getAicClli());
605 vfModuleTopology.setAicCloudRegion(vfModuleData.getVfModuleRequestInput().getAicCloudRegion());
606 vfModuleTopology.setCloudOwner(vfModuleData.getVfModuleRequestInput().getCloudOwner());
608 apiVfModuletopologyVfModuleTopology.vfModuleTopologyIdentifier(getVfModuleTopologyIdentifierStructure(input));
610 vfModuleTopology.setVfModuleTopologyIdentifier(apiVfModuletopologyVfModuleTopology.getVfModuleTopologyIdentifier());
611 vfModuleTopology.setTenant(vfModuleData.getVfModuleRequestInput().getTenant());
613 final GenericResourceApiVfModuleTopology genericResourceApiVfModuleTopology = new GenericResourceApiVfModuleTopology();
614 genericResourceApiVfModuleTopology.setVfModuleTopology(vfModuleTopology);
616 final Cache cache = getCache(Constants.SERVICE_TOPOLOGY_OPERATION_CACHE);
617 cache.put(vfModuleId, genericResourceApiVfModuleTopology);
621 public Optional<GenericResourceApiVfModuleTopology> getGenericResourceApiVfModuleTopology(final String vfModueId) {
622 LOGGER.info("getting GenericResourceApiVfModuleTopology from cache using key: {}", vfModueId);
623 final Cache cache = getCache(Constants.SERVICE_TOPOLOGY_OPERATION_CACHE);
624 final GenericResourceApiVfModuleTopology value =
625 cache.get(vfModueId, GenericResourceApiVfModuleTopology.class);
627 return Optional.of(value);
629 LOGGER.error("Unable to find GenericResourceApiVfModuleTopology ...");
630 return Optional.empty();
633 private GenericResourceApiVfmoduletopologyidentifierVfModuleTopologyIdentifier getVfModuleTopologyIdentifierStructure(
634 @Valid final GenericResourceApiVfModuleOperationInformation input) {
636 final GenericResourceApiVfmoduleinformationVfModuleInformation vfModuleInformation = input.getVfModuleInformation();
637 return new GenericResourceApiVfmoduletopologyidentifierVfModuleTopologyIdentifier()
638 .vfModuleId(vfModuleInformation.getVfModuleId()).vfModuleType(vfModuleInformation.getVfModuleType()).vfModuleName(input.getVfModuleRequestInput().getVfModuleName());
642 public void setVnfsData(List<GenericResourceApiServicedataServicedataVnfsVnf> vnfsList) {
644 final GenericResourceApiVnftopologyVnfTopology vnfTopology = new GenericResourceApiVnftopologyVnfTopology();
645 LOGGER.info(String.valueOf(vnfsList));
646 final String vnfId = vnfsList.get(0).getVnfId();
647 vnfTopology.setOnapModelInformation(vnfsList.get(0).getVnfData().getVnfInformation().getOnapModelInformation());
648 vnfTopology.setAicClli(String.valueOf(vnfsList.get(0).getVnfData().getVnfRequestInput().getAicClli()));
649 vnfTopology.setAicCloudRegion(String.valueOf(vnfsList.get(0).getVnfData().getVnfRequestInput().getAicCloudRegion()));
650 vnfTopology.setCloudOwner(String.valueOf(vnfsList.get(0).getVnfData().getVnfRequestInput().getCloudOwner()));
651 vnfTopology.setTenant(String.valueOf(vnfsList.get(0).getVnfData().getVnfRequestInput().getTenant()));
652 vnfTopology.setVnfResourceAssignments(vnfsList.get(0).getVnfData().getVnfTopology().getVnfResourceAssignments());
653 vnfTopology.setVnfTopologyIdentifierStructure(vnfsList.get(0).getVnfData().getVnfTopology().getVnfTopologyIdentifierStructure());
654 vnfTopology.setVnfParametersData(vnfsList.get(0).getVnfData().getVnfTopology().getVnfParametersData());
655 vnfTopology.setSdncGeneratedCloudResources(vnfsList.get(0).getVnfData().getVnfTopology().getSdncGeneratedCloudResources());
657 final GenericResourceApiVnfTopology genericResourceApiVnfTopology = new GenericResourceApiVnfTopology();
658 genericResourceApiVnfTopology.setVnfTopology(vnfTopology);
660 final Cache cache = getCache(Constants.SERVICE_TOPOLOGY_OPERATION_CACHE);
661 cache.put(vnfId, genericResourceApiVnfTopology);
665 public Optional<GenericResourceApiVnfTopology> getGenericResourceApiVnfTopology(final String vnfId) {
666 LOGGER.info("getting GenericResourceApiVnfTopology from cache using key: {}", vnfId);
667 final Cache cache = getCache(Constants.SERVICE_TOPOLOGY_OPERATION_CACHE);
668 final GenericResourceApiVnfTopology value =
669 cache.get(vnfId, GenericResourceApiVnfTopology.class);
671 return Optional.of(value);
673 LOGGER.error("Unable to find GenericResourceApiVnfTopology ...");
674 return Optional.empty();