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;
40 import org.onap.sdnc.northbound.client.model.GenericResourceApiInstanceReference;
41 import org.onap.sdnc.northbound.client.model.GenericResourceApiLastActionEnumeration;
42 import org.onap.sdnc.northbound.client.model.GenericResourceApiLastRpcActionEnumeration;
43 import org.onap.sdnc.northbound.client.model.GenericResourceApiOnapmodelinformationOnapModelInformation;
44 import org.onap.sdnc.northbound.client.model.GenericResourceApiOperStatusData;
45 import org.onap.sdnc.northbound.client.model.GenericResourceApiOrderStatusEnumeration;
46 import org.onap.sdnc.northbound.client.model.GenericResourceApiRequestinformationRequestInformation;
47 import org.onap.sdnc.northbound.client.model.GenericResourceApiRpcActionEnumeration;
48 import org.onap.sdnc.northbound.client.model.GenericResourceApiSdncrequestheaderSdncRequestHeader;
49 import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceOperationInformation;
50 import org.onap.sdnc.northbound.client.model.GenericResourceApiServicedataServiceData;
51 import org.onap.sdnc.northbound.client.model.GenericResourceApiServicedataServicedataVnfs;
52 import org.onap.sdnc.northbound.client.model.GenericResourceApiServicedataServicedataVnfsVnf;
53 import org.onap.sdnc.northbound.client.model.GenericResourceApiServicedataServicedataVnfsVnfVnfData;
54 import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceinformationServiceInformation;
55 import org.onap.sdnc.northbound.client.model.GenericResourceApiServicemodelinfrastructureService;
56 import org.onap.sdnc.northbound.client.model.GenericResourceApiServicestatusServiceStatus;
57 import org.onap.sdnc.northbound.client.model.GenericResourceApiServicetopologyServiceTopology;
58 import org.onap.sdnc.northbound.client.model.GenericResourceApiServicetopologyidentifierServiceTopologyIdentifier;
59 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfOperationInformation;
60 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfinformationVnfInformation;
61 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfrequestinputVnfRequestInput;
62 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnftopologyVnfTopology;
63 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnftopologyidentifierstructureVnfTopologyIdentifierStructure;
65 import org.onap.sdnc.northbound.client.model.GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfmodulesVfmoduleVfModuleData;
66 import org.onap.sdnc.northbound.client.model.GenericResourceApiVfModuleTopology;
67 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfTopology;
68 import org.onap.sdnc.northbound.client.model.GenericResourceApiVfModuleOperationInformation;
69 import org.onap.sdnc.northbound.client.model.GenericResourceApiVfmoduleinformationVfModuleInformation;
70 import org.onap.sdnc.northbound.client.model.GenericResourceApiVfmoduletopologyVfModuleTopology;
71 import org.onap.sdnc.northbound.client.model.GenericResourceApiVfmoduletopologyidentifierVfModuleTopologyIdentifier;
72 import org.onap.sdnc.northbound.client.model.GenericResourceApiParam;
73 import org.onap.sdnc.northbound.client.model.GenericResourceApiParamParam;
75 import org.onap.so.sdncsimulator.models.Output;
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);
97 private static List<GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfmodulesVfmoduleVfModuleData> vfModuleList;
98 GenericResourceApiVfModuleTopology genericResourceApiVfModuleTopology = new GenericResourceApiVfModuleTopology();
99 GenericResourceApiVnfTopology genericResourceApiVnfTopology = new GenericResourceApiVnfTopology();
102 public ServiceOperationsCacheServiceProviderimpl(final CacheManager cacheManager) {
107 public Output putServiceOperationInformation(final GenericResourceApiServiceOperationInformation input) {
109 final GenericResourceApiSdncrequestheaderSdncRequestHeader requestHeader = input.getSdncRequestHeader();
110 final String svcRequestId = getSvcRequestId(requestHeader);
112 final GenericResourceApiServiceinformationServiceInformation serviceInformation = input.getServiceInformation();
113 if (serviceInformation != null && isValid(serviceInformation.getServiceInstanceId())) {
114 final String serviceInstanceId = serviceInformation.getServiceInstanceId();
116 if (isServiceOperationInformationNotExists(serviceInstanceId, input)) {
117 final Cache cache = getCache(SERVICE_TOPOLOGY_OPERATION_CACHE);
118 LOGGER.info("Adding GenericResourceApiServiceOperationInformation to cache with key: {}",
121 final GenericResourceApiServicemodelinfrastructureService service =
122 getServiceItem(input, serviceInstanceId);
123 cache.put(serviceInstanceId, service);
125 final GenericResourceApiServicestatusServiceStatus serviceStatus = service.getServiceStatus();
127 return new Output().ackFinalIndicator(serviceStatus.getFinalIndicator())
128 .responseCode(serviceStatus.getResponseCode())
129 .responseMessage(serviceStatus.getResponseMessage()).svcRequestId(svcRequestId)
130 .serviceResponseInformation(new GenericResourceApiInstanceReference()
131 .instanceId(serviceInstanceId).objectPath(getObjectPath(serviceInstanceId)));
133 LOGGER.error("serviceInstanceId: {} already exists", serviceInstanceId);
134 return new Output().ackFinalIndicator(YES).responseCode(HTTP_STATUS_BAD_REQUEST)
135 .responseMessage("serviceInstanceId: " + serviceInstanceId + " already exists")
136 .svcRequestId(svcRequestId);
140 "Unable to add GenericResourceApiServiceOperationInformation in cache due to invalid input: {}... ",
142 return new Output().ackFinalIndicator(YES).responseCode(HTTP_STATUS_BAD_REQUEST)
143 .responseMessage("Service instance not found").svcRequestId(svcRequestId);
148 public Output deleteServiceOperationInformation(final GenericResourceApiServiceOperationInformation input) {
149 final GenericResourceApiServiceinformationServiceInformation serviceInformation = input.getServiceInformation();
150 final String svcRequestId = getSvcRequestId(input.getSdncRequestHeader());
152 if (serviceInformation != null && isValid(serviceInformation.getServiceInstanceId())) {
153 final String serviceInstanceId = serviceInformation.getServiceInstanceId();
154 final Optional<GenericResourceApiServicemodelinfrastructureService> optional =
155 getGenericResourceApiServicemodelinfrastructureService(serviceInstanceId);
156 if (optional.isPresent()) {
157 final Cache cache = getCache(SERVICE_TOPOLOGY_OPERATION_CACHE);
158 LOGGER.info("Deleting GenericResourceApiServiceOperationInformation from cache using key: {}",
160 cache.evict(serviceInstanceId);
161 return new Output().ackFinalIndicator(YES).responseCode(HTTP_STATUS_OK)
162 .responseMessage(EMPTY_STRING).svcRequestId(svcRequestId).serviceResponseInformation(
163 new GenericResourceApiInstanceReference().instanceId(serviceInstanceId));
166 "Unable to find existing GenericResourceApiServiceModelInfrastructure in cache using service instance id: {}",
170 LOGGER.error("Unable to remove service instance from cache due to invalid input: {}... ", input);
171 return new Output().ackFinalIndicator(YES).responseCode(HTTP_STATUS_BAD_REQUEST)
172 .responseMessage("Unable to remove service").svcRequestId(svcRequestId);
176 public Optional<GenericResourceApiServicemodelinfrastructureService> getGenericResourceApiServicemodelinfrastructureService(
177 final String serviceInstanceId) {
178 final Cache cache = getCache(SERVICE_TOPOLOGY_OPERATION_CACHE);
180 final GenericResourceApiServicemodelinfrastructureService value =
181 cache.get(serviceInstanceId, GenericResourceApiServicemodelinfrastructureService.class);
183 LOGGER.info("Found {} in cahce for service instance id: {}", value, serviceInstanceId);
184 return Optional.of(value);
186 LOGGER.error("Unable to find GenericResourceApiServiceModelInfrastructure in cache for service instance id: {}",
188 return Optional.empty();
192 public Output putVnfOperationInformation(final GenericResourceApiVnfOperationInformation input) {
194 final GenericResourceApiServiceinformationServiceInformation serviceInformation = input.getServiceInformation();
195 final GenericResourceApiVnfinformationVnfInformation vnfInformation = input.getVnfInformation();
197 final GenericResourceApiSdncrequestheaderSdncRequestHeader requestHeader = input.getSdncRequestHeader();
198 final String svcRequestId = getSvcRequestId(requestHeader);
200 if (serviceInformation != null && isValid(serviceInformation.getServiceInstanceId()) && vnfInformation != null
201 && isValid(vnfInformation.getVnfId())) {
202 final String serviceInstanceId = serviceInformation.getServiceInstanceId();
203 final String vnfId = vnfInformation.getVnfId();
204 final Optional<GenericResourceApiServicemodelinfrastructureService> optional =
205 getGenericResourceApiServicemodelinfrastructureService(serviceInstanceId);
206 if (optional.isPresent()) {
207 final GenericResourceApiServicemodelinfrastructureService service = optional.get();
208 final GenericResourceApiServicedataServiceData serviceData = service.getServiceData();
209 if (serviceData != null) {
210 final List<GenericResourceApiServicedataServicedataVnfsVnf> vnfsList = getVnfs(serviceData);
211 final GenericResourceApiLastRpcActionEnumeration svcAction =
212 GenericResourceApiLastRpcActionEnumeration.fromValue(getSvcAction(requestHeader));
214 if (ifVnfNotExists(vnfId, svcAction, vnfsList)) {
215 vnfsList.add(getGenericResourceApiServicedataVnf(serviceInstanceId, vnfId, input));
216 getVnfsList(vnfsList);
217 final GenericResourceApiServicestatusServiceStatus serviceStatus = service.getServiceStatus();
219 return new Output().ackFinalIndicator(serviceStatus.getFinalIndicator())
220 .responseCode(serviceStatus.getResponseCode())
221 .responseMessage(serviceStatus.getResponseMessage()).svcRequestId(svcRequestId)
222 .serviceResponseInformation(new GenericResourceApiInstanceReference()
223 .instanceId(serviceInstanceId).objectPath(getObjectPath(serviceInstanceId)))
224 .vnfResponseInformation(new GenericResourceApiInstanceReference().instanceId(vnfId)
225 .objectPath(getObjectPath(serviceInstanceId, vnfId)));
227 LOGGER.error("vnfId: {} already exists with SVC Action: {}", vnfId, svcAction);
228 return new Output().ackFinalIndicator(YES).responseCode(HTTP_STATUS_BAD_REQUEST)
229 .responseMessage("vnfId: " + vnfId + " already exists").svcRequestId(svcRequestId);
233 "Unable to find existing GenericResourceApiServiceModelInfrastructure in cache using service instance id: {}",
238 "Unable to add GenericResourceApiServiceOperationInformation in cache due to invalid input: {}... ",
240 return new Output().ackFinalIndicator(YES).responseCode(HTTP_STATUS_BAD_REQUEST)
241 .responseMessage("Unable to add vnf").svcRequestId(svcRequestId);
245 public Output deleteVnfOperationInformation(final GenericResourceApiVnfOperationInformation input) {
246 final GenericResourceApiServiceinformationServiceInformation serviceInformation = input.getServiceInformation();
247 final GenericResourceApiVnfinformationVnfInformation vnfInformation = input.getVnfInformation();
249 final GenericResourceApiSdncrequestheaderSdncRequestHeader requestHeader = input.getSdncRequestHeader();
250 final String svcRequestId = getSvcRequestId(requestHeader);
252 if (serviceInformation != null && isValid(serviceInformation.getServiceInstanceId()) && vnfInformation != null
253 && isValid(vnfInformation.getVnfId())) {
254 final String serviceInstanceId = serviceInformation.getServiceInstanceId();
255 final String vnfId = vnfInformation.getVnfId();
256 final Optional<GenericResourceApiServicemodelinfrastructureService> optional =
257 getGenericResourceApiServicemodelinfrastructureService(serviceInstanceId);
258 if (optional.isPresent()) {
259 final GenericResourceApiServicemodelinfrastructureService service = optional.get();
260 final GenericResourceApiServicedataServiceData serviceData = service.getServiceData();
261 if (serviceData != null) {
262 final List<GenericResourceApiServicedataServicedataVnfsVnf> vnfsList = getVnfs(serviceData);
263 final Optional<GenericResourceApiServicedataServicedataVnfsVnf> vnfInstanceOptional =
264 getExistingVnf(vnfId, vnfsList);
266 if (vnfInstanceOptional.isPresent()) {
267 vnfsList.removeIf(vnf -> {
268 final String existingVnfId = vnf.getVnfId();
269 if (existingVnfId != null && existingVnfId.equals(vnfId)) {
270 LOGGER.info("Remove vnf with id: {} ... ", existingVnfId);
276 return new Output().ackFinalIndicator(YES).responseCode(HTTP_STATUS_OK)
277 .responseMessage(EMPTY_STRING).svcRequestId(svcRequestId)
278 .serviceResponseInformation(
279 new GenericResourceApiInstanceReference().instanceId(serviceInstanceId))
280 .vnfResponseInformation(new GenericResourceApiInstanceReference().instanceId(vnfId));
286 "Unable to find existing GenericResourceApiServiceModelInfrastructure in cache using service instance id: {}",
290 LOGGER.error("Unable to remove vnf instance from cache due to invalid input: {}... ", input);
291 return new Output().ackFinalIndicator(YES).responseCode(HTTP_STATUS_BAD_REQUEST)
292 .responseMessage("Unable to remove vnf").svcRequestId(svcRequestId);
296 private String getSvcRequestId(final GenericResourceApiSdncrequestheaderSdncRequestHeader requestHeader) {
297 return requestHeader != null ? requestHeader.getSvcRequestId() : null;
301 public void clearAll() {
302 clearCache(SERVICE_TOPOLOGY_OPERATION_CACHE);
305 private String getObjectPath(final String serviceInstanceId, final String vnfId) {
306 return getObjectPath(serviceInstanceId) + SERVICE_DATA_VNFS_VNF + vnfId + VNF_DATA_VNF_TOPOLOGY;
309 private String getObjectPath(final String serviceInstanceId) {
310 return RESTCONF_CONFIG_END_POINT + serviceInstanceId;
314 private boolean ifVnfNotExists(final String vnfId, final GenericResourceApiLastRpcActionEnumeration svcAction,
315 final List<GenericResourceApiServicedataServicedataVnfsVnf> vnfsList) {
316 final Optional<GenericResourceApiServicedataServicedataVnfsVnf> optional = getExistingVnf(vnfId, vnfsList);
317 if (optional.isPresent()) {
318 final GenericResourceApiServicedataServicedataVnfsVnf existingVnf = optional.get();
319 final GenericResourceApiServicedataServicedataVnfsVnfVnfData vnfData = existingVnf.getVnfData();
321 if (vnfData != null && vnfData.getVnfLevelOperStatus() != null
322 && vnfData.getVnfLevelOperStatus().getLastRpcAction() != null) {
323 final GenericResourceApiLastRpcActionEnumeration existingVnflastRpcAction =
324 vnfData.getVnfLevelOperStatus().getLastRpcAction();
325 if (existingVnflastRpcAction.equals(svcAction)) {
326 LOGGER.error("Found vnf with id: {} and LastRpcAction: {} same as SvcAction: {}", vnfId,
327 existingVnflastRpcAction, svcAction);
330 LOGGER.warn("Will remove and replace existing vnf with id: {} as SvcAction is changed from {} to {}",
331 vnfId, existingVnflastRpcAction, svcAction);
332 vnfsList.removeIf(vnf -> vnf.getVnfId() != null && vnf.getVnfId().equals(vnfId));
340 private Optional<GenericResourceApiServicedataServicedataVnfsVnf> getExistingVnf(final String vnfId,
341 final List<GenericResourceApiServicedataServicedataVnfsVnf> vnfsList) {
342 return vnfsList.stream().filter(vnf -> vnf.getVnfId() != null && vnf.getVnfId().equals(vnfId)).findFirst();
345 private List<GenericResourceApiServicedataServicedataVnfsVnf> getVnfs(
346 final GenericResourceApiServicedataServiceData serviceData) {
347 GenericResourceApiServicedataServicedataVnfs vnfs = serviceData.getVnfs();
349 vnfs = new GenericResourceApiServicedataServicedataVnfs();
350 serviceData.setVnfs(vnfs);
353 List<GenericResourceApiServicedataServicedataVnfsVnf> vnfsList = vnfs.getVnf();
354 if (vnfsList == null) {
355 vnfsList = new ArrayList<>();
356 vnfs.setVnf(vnfsList);
361 private GenericResourceApiServicedataServicedataVnfsVnf getGenericResourceApiServicedataVnf(
362 final String serviceInstanceId, final String vnfId, final GenericResourceApiVnfOperationInformation input) {
363 return new GenericResourceApiServicedataServicedataVnfsVnf().vnfId(vnfId).vnfData(getVnfData(input));
366 private GenericResourceApiServicedataServicedataVnfsVnfVnfData getVnfData(
367 final GenericResourceApiVnfOperationInformation input) {
369 final GenericResourceApiServicedataServicedataVnfsVnfVnfData vnfData =
370 new GenericResourceApiServicedataServicedataVnfsVnfVnfData();
372 vnfData.vnfLevelOperStatus(
373 getServiceLevelOperStatus(PENDINGCREATE, input.getRequestInformation(), input.getSdncRequestHeader()));
374 vnfData.serviceInformation(input.getServiceInformation());
375 vnfData.sdncRequestHeader(input.getSdncRequestHeader());
376 vnfData.vnfInformation(input.getVnfInformation());
377 vnfData.requestInformation(input.getRequestInformation());
378 vnfData.vnfRequestInput(input.getVnfRequestInput());
380 vnfData.vnfTopology(getVnfTopology(input.getVnfInformation(), input.getVnfRequestInput()));
385 private GenericResourceApiVnftopologyVnfTopology getVnfTopology(
386 final GenericResourceApiVnfinformationVnfInformation vnfInformation,
387 final GenericResourceApiVnfrequestinputVnfRequestInput vnfRequestInput) {
389 final GenericResourceApiVnftopologyVnfTopology apiVnftopologyVnfTopology =
390 new GenericResourceApiVnftopologyVnfTopology();
392 if (vnfInformation != null) {
393 apiVnftopologyVnfTopology.onapModelInformation(vnfInformation.getOnapModelInformation());
394 apiVnftopologyVnfTopology.vnfTopologyIdentifierStructure(getTopologyIdentifierStructure(vnfInformation));
396 if (vnfRequestInput != null) {
397 apiVnftopologyVnfTopology.tenant(vnfRequestInput.getTenant());
398 apiVnftopologyVnfTopology.aicClli(vnfRequestInput.getAicClli());
399 apiVnftopologyVnfTopology.aicCloudRegion(vnfRequestInput.getAicCloudRegion());
401 return apiVnftopologyVnfTopology;
404 private GenericResourceApiVnftopologyidentifierstructureVnfTopologyIdentifierStructure getTopologyIdentifierStructure(
405 @Valid final GenericResourceApiVnfinformationVnfInformation vnfInformation) {
406 return new GenericResourceApiVnftopologyidentifierstructureVnfTopologyIdentifierStructure()
407 .vnfId(vnfInformation.getVnfId()).vnfName(vnfInformation.getVnfName())
408 .vnfType(vnfInformation.getVnfType());
411 private GenericResourceApiServicemodelinfrastructureService getServiceItem(
412 final GenericResourceApiServiceOperationInformation input, final String serviceInstanceId) {
414 final GenericResourceApiServicedataServiceData apiServicedataServiceData =
415 new GenericResourceApiServicedataServiceData();
417 apiServicedataServiceData.requestInformation(input.getRequestInformation());
418 apiServicedataServiceData.serviceRequestInput(input.getServiceRequestInput());
419 apiServicedataServiceData.serviceInformation(input.getServiceInformation());
420 apiServicedataServiceData.serviceTopology(getServiceTopology(input));
421 apiServicedataServiceData.sdncRequestHeader(input.getSdncRequestHeader());
422 apiServicedataServiceData.serviceLevelOperStatus(getServiceLevelOperStatus(input));
424 final GenericResourceApiServicestatusServiceStatus serviceStatus =
425 getServiceStatus(getSvcAction(input.getSdncRequestHeader()),
426 getRequestAction(input.getRequestInformation()), HTTP_STATUS_OK);
428 return new GenericResourceApiServicemodelinfrastructureService().serviceData(apiServicedataServiceData)
429 .serviceStatus(serviceStatus).serviceInstanceId(serviceInstanceId);
432 private String getSvcAction(final GenericResourceApiSdncrequestheaderSdncRequestHeader input) {
433 return input != null ? getStringOrNull(input.getSvcAction()) : null;
436 private GenericResourceApiServicestatusServiceStatus getServiceStatus(final String rpcAction, final String action,
437 final String responseCode) {
438 return new GenericResourceApiServicestatusServiceStatus().finalIndicator(YES)
439 .rpcAction(GenericResourceApiRpcActionEnumeration.fromValue(rpcAction))
440 .rpcName(SERVICE_TOPOLOGY_OPERATION).responseTimestamp(LocalDateTime.now().toString())
441 .responseCode(responseCode).requestStatus(SYNCCOMPLETE).responseMessage(EMPTY_STRING).action(action);
444 private GenericResourceApiOperStatusData getServiceLevelOperStatus(
445 final GenericResourceApiServiceOperationInformation input) {
446 return getServiceLevelOperStatus(CREATED, input.getRequestInformation(), input.getSdncRequestHeader());
449 private GenericResourceApiOperStatusData getServiceLevelOperStatus(
450 final GenericResourceApiOrderStatusEnumeration statusEnumeration,
451 final GenericResourceApiRequestinformationRequestInformation requestInformation,
452 final GenericResourceApiSdncrequestheaderSdncRequestHeader sdncRequestHeader) {
453 return new GenericResourceApiOperStatusData().orderStatus(statusEnumeration)
454 .lastAction(GenericResourceApiLastActionEnumeration.fromValue(getRequestAction(requestInformation)))
455 .lastRpcAction(GenericResourceApiLastRpcActionEnumeration.fromValue(getSvcAction(sdncRequestHeader)));
458 private String getRequestAction(final GenericResourceApiRequestinformationRequestInformation input) {
459 return getRequestAction(input, EMPTY_STRING);
462 private String getRequestAction(final GenericResourceApiRequestinformationRequestInformation input,
463 final String defaultValue) {
464 return input != null ? getString(input.getRequestAction(), defaultValue) : defaultValue;
467 private GenericResourceApiServicetopologyServiceTopology getServiceTopology(
468 final GenericResourceApiServiceOperationInformation input) {
469 final GenericResourceApiOnapmodelinformationOnapModelInformation modelInformation =
470 input.getServiceInformation() != null ? input.getServiceInformation().getOnapModelInformation() : null;
471 return new GenericResourceApiServicetopologyServiceTopology().onapModelInformation(modelInformation)
472 .serviceTopologyIdentifier(getServiceTopologyIdentifier(input));
475 private GenericResourceApiServicetopologyidentifierServiceTopologyIdentifier getServiceTopologyIdentifier(
476 final GenericResourceApiServiceOperationInformation input) {
477 final GenericResourceApiServicetopologyidentifierServiceTopologyIdentifier identifier =
478 new GenericResourceApiServicetopologyidentifierServiceTopologyIdentifier();
480 if (input.getServiceInformation() != null) {
481 final GenericResourceApiServiceinformationServiceInformation serviceInformation =
482 input.getServiceInformation();
483 identifier.globalCustomerId(serviceInformation.getGlobalCustomerId())
484 .serviceType(input.getServiceInformation().getSubscriptionServiceType())
485 .serviceInstanceId(input.getServiceInformation().getServiceInstanceId());;
488 if (input.getServiceRequestInput() != null) {
489 identifier.serviceInstanceName(input.getServiceRequestInput().getServiceInstanceName());
496 private boolean isServiceOperationInformationNotExists(final String serviceInstanceId,
497 final GenericResourceApiServiceOperationInformation input) {
498 final GenericResourceApiSdncrequestheaderSdncRequestHeader requestHeader = input.getSdncRequestHeader();
499 final Optional<GenericResourceApiServicemodelinfrastructureService> optional =
500 getGenericResourceApiServicemodelinfrastructureService(serviceInstanceId);
502 if (optional.isPresent()) {
503 final GenericResourceApiServicemodelinfrastructureService existingService = optional.get();
504 final GenericResourceApiServicestatusServiceStatus serviceStatus = existingService.getServiceStatus();
505 if (serviceStatus != null) {
506 final GenericResourceApiRpcActionEnumeration rpcAction = serviceStatus.getRpcAction();
507 final String svcAction = getSvcAction(requestHeader);
508 if (rpcAction != null && rpcAction.toString().equals(svcAction)) {
509 LOGGER.error("Found Service with id: {} and RpcAction: {} same as SvcAction: {}",
510 serviceInstanceId, rpcAction, svcAction);
514 final Cache cache = getCache(SERVICE_TOPOLOGY_OPERATION_CACHE);
516 "Deleting existing GenericResourceApiServiceOperationInformation from cache using key: {} as SvcAction is changed from {} to {}",
517 serviceInstanceId, rpcAction, svcAction);
518 cache.evict(serviceInstanceId);
526 public Output putVfModuleOperationInformation(
527 GenericResourceApiVfModuleOperationInformation input) {
529 final GenericResourceApiServiceinformationServiceInformation serviceInformation = input.getServiceInformation();
530 final GenericResourceApiVnfinformationVnfInformation vnfInformation = input.getVnfInformation();
531 final GenericResourceApiVfmoduleinformationVfModuleInformation vfModuleInformation = input.getVfModuleInformation();
532 // Call getVfModule to make a vfList for get the vf-module-information while GET reqest
533 vfModuleList = getVfModule(input);
535 final GenericResourceApiSdncrequestheaderSdncRequestHeader requestHeader = input.getSdncRequestHeader();
536 final String svcRequestId = getSvcRequestId(requestHeader);
538 if (serviceInformation != null && isValid(serviceInformation.getServiceInstanceId()) && vnfInformation != null
539 && isValid(vnfInformation.getVnfId()) && vfModuleInformation !=null && isValid(vfModuleInformation.getVfModuleId())) {
542 final String serviceInstanceId = serviceInformation.getServiceInstanceId();
543 final String vnfId = vnfInformation.getVnfId();
544 final String vfModuleId = vfModuleInformation.getVfModuleId();
546 final Optional<GenericResourceApiServicemodelinfrastructureService> optional =
547 getGenericResourceApiServicemodelinfrastructureService(serviceInstanceId);
548 if (optional.isPresent()) {
549 final GenericResourceApiServicemodelinfrastructureService service = optional.get();
550 final GenericResourceApiServicedataServiceData serviceData = service.getServiceData();
551 if (serviceData != null) {
553 final GenericResourceApiServicestatusServiceStatus serviceStatus = service.getServiceStatus();
555 return new Output().ackFinalIndicator(serviceStatus.getFinalIndicator())
556 .responseCode(serviceStatus.getResponseCode())
557 .responseMessage(serviceStatus.getResponseMessage()).svcRequestId(svcRequestId)
558 .serviceResponseInformation(new GenericResourceApiInstanceReference()
559 .instanceId(serviceInstanceId).objectPath(getObjectPath(serviceInstanceId)))
560 .vnfResponseInformation(new GenericResourceApiInstanceReference().instanceId(vnfId)
561 .objectPath(getObjectPath(serviceInstanceId, vnfId)))
562 .vfModuleResponseInformation(new GenericResourceApiInstanceReference().instanceId(vfModuleId)
563 .objectPath(getObjectPath(vnfId, vfModuleId)));
567 "Unable to find existing GenericResourceApiServiceModelInfrastructure in cache using service instance id: {}",
571 "Unable to add GenericResourceApiServiceOperationInformation in cache due to invalid input: {}... ",
573 return new Output().ackFinalIndicator(YES).responseCode(HTTP_STATUS_BAD_REQUEST)
574 .responseMessage("Unable to add vfModule").svcRequestId(svcRequestId);
577 private List<GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfmodulesVfmoduleVfModuleData> getVfModule(GenericResourceApiVfModuleOperationInformation input) {
579 final GenericResourceApiVfmoduletopologyVfModuleTopology apiVfModuletopologyVfModuleTopology =
580 new GenericResourceApiVfmoduletopologyVfModuleTopology();
582 GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfmodulesVfmoduleVfModuleData vfModuleData =
583 new GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfmodulesVfmoduleVfModuleData();
584 vfModuleData.setVfModuleInformation(input.getVfModuleInformation());
585 vfModuleData.setVfModuleRequestInput(input.getVfModuleRequestInput());
587 GenericResourceApiVfmoduletopologyVfModuleTopology vfModuleTopology = new GenericResourceApiVfmoduletopologyVfModuleTopology();
589 vfModuleTopology.setSdncGeneratedCloudResources(true);
590 GenericResourceApiParam vfModuleParametersData = new GenericResourceApiParam();
591 List<GenericResourceApiParamParam> params = new ArrayList<GenericResourceApiParamParam>();
592 GenericResourceApiParamParam param = new GenericResourceApiParamParam();
593 param.setName("k8s-rb-profile-name");
594 param.setValue("k8s-rb-profile-value");
597 vfModuleParametersData.setParam(params);
598 vfModuleTopology.setVfModuleParameters(vfModuleParametersData);
600 vfModuleTopology.setOnapModelInformation(vfModuleData.getVfModuleInformation().getOnapModelInformation());
601 vfModuleTopology.setVfModuleParameters(vfModuleData.getVfModuleRequestInput().getVfModuleInputParameters());
602 vfModuleTopology.setAicClli(vfModuleData.getVfModuleRequestInput().getAicClli());
603 vfModuleTopology.setAicCloudRegion(vfModuleData.getVfModuleRequestInput().getAicCloudRegion());
604 vfModuleTopology.setCloudOwner(vfModuleData.getVfModuleRequestInput().getCloudOwner());
606 apiVfModuletopologyVfModuleTopology.vfModuleTopologyIdentifier(getVfModuleTopologyIdentifierStructure(input));
608 vfModuleTopology.setVfModuleTopologyIdentifier(apiVfModuletopologyVfModuleTopology.getVfModuleTopologyIdentifier());
609 vfModuleTopology.setTenant(vfModuleData.getVfModuleRequestInput().getTenant());
611 genericResourceApiVfModuleTopology.setVfModuleTopology(vfModuleTopology);
617 public GenericResourceApiVfModuleTopology getGenericResourceApiVfModuleTopology() {
618 return genericResourceApiVfModuleTopology;
621 private GenericResourceApiVfmoduletopologyidentifierVfModuleTopologyIdentifier getVfModuleTopologyIdentifierStructure(
622 @Valid final GenericResourceApiVfModuleOperationInformation input) {
624 final GenericResourceApiVfmoduleinformationVfModuleInformation vfModuleInformation = input.getVfModuleInformation();
625 return new GenericResourceApiVfmoduletopologyidentifierVfModuleTopologyIdentifier()
626 .vfModuleId(vfModuleInformation.getVfModuleId()).vfModuleType(vfModuleInformation.getVfModuleType()).vfModuleName(input.getVfModuleRequestInput().getVfModuleName());
629 public GenericResourceApiVnfTopology getGenericResourceApiVnfTopology() {
630 return genericResourceApiVnfTopology;
633 public void getVnfsList(List<GenericResourceApiServicedataServicedataVnfsVnf> vnfsList) {
635 GenericResourceApiVnftopologyVnfTopology vnfTopology = new GenericResourceApiVnftopologyVnfTopology();
636 LOGGER.info(String.valueOf(vnfsList));
637 vnfTopology.setOnapModelInformation(vnfsList.get(0).getVnfData().getVnfInformation().getOnapModelInformation());
638 vnfTopology.setAicClli(String.valueOf(vnfsList.get(0).getVnfData().getVnfRequestInput().getAicClli()));
639 vnfTopology.setAicCloudRegion(String.valueOf(vnfsList.get(0).getVnfData().getVnfRequestInput().getAicCloudRegion()));
640 vnfTopology.setCloudOwner(String.valueOf(vnfsList.get(0).getVnfData().getVnfRequestInput().getCloudOwner()));
641 vnfTopology.setTenant(String.valueOf(vnfsList.get(0).getVnfData().getVnfRequestInput().getTenant()));
642 vnfTopology.setVnfResourceAssignments(vnfsList.get(0).getVnfData().getVnfTopology().getVnfResourceAssignments());
643 vnfTopology.setVnfTopologyIdentifierStructure(vnfsList.get(0).getVnfData().getVnfTopology().getVnfTopologyIdentifierStructure());
644 vnfTopology.setVnfParametersData(vnfsList.get(0).getVnfData().getVnfTopology().getVnfParametersData());
645 vnfTopology.setSdncGeneratedCloudResources(vnfsList.get(0).getVnfData().getVnfTopology().getSdncGeneratedCloudResources());
647 genericResourceApiVnfTopology.setVnfTopology(vnfTopology);