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.aaisimulator.service.providers;
22 import static org.onap.so.aaisimulator.utils.CacheName.GENERIC_VNF_CACHE;
23 import java.util.Optional;
24 import org.onap.aai.domain.yang.GenericVnf;
25 import org.onap.aai.domain.yang.Relationship;
26 import org.onap.aai.domain.yang.RelationshipList;
27 import org.onap.so.simulator.cache.provider.AbstractCacheServiceProvider;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30 import org.springframework.beans.factory.annotation.Autowired;
31 import org.springframework.cache.Cache;
32 import org.springframework.cache.CacheManager;
33 import org.springframework.stereotype.Service;
36 * @author Waqas Ikram (waqas.ikram@est.tech)
40 public class GenericVnfCacheServiceProviderImpl extends AbstractCacheServiceProvider
41 implements GenericVnfCacheServiceProvider {
43 private static final Logger LOGGER = LoggerFactory.getLogger(GenericVnfCacheServiceProviderImpl.class);
46 public GenericVnfCacheServiceProviderImpl(final CacheManager cacheManager) {
51 public void putGenericVnf(final String vnfId, final GenericVnf genericVnf) {
52 LOGGER.info("Adding customer: {} with key: {} in cache ...", genericVnf, vnfId);
53 final Cache cache = getCache(GENERIC_VNF_CACHE.getName());
54 cache.put(vnfId, genericVnf);
58 public Optional<GenericVnf> getGenericVnf(final String vnfId) {
59 LOGGER.info("getting GenericVnf from cache using key: {}", vnfId);
60 final Cache cache = getCache(GENERIC_VNF_CACHE.getName());
61 final GenericVnf value = cache.get(vnfId, GenericVnf.class);
63 return Optional.of(value);
65 LOGGER.error("Unable to find GenericVnf ...");
66 return Optional.empty();
70 public boolean addRelationShip(final String vnfId, final Relationship relationship) {
71 final Optional<GenericVnf> optional = getGenericVnf(vnfId);
72 if (optional.isPresent()) {
73 GenericVnf genericVnf = optional.get();
74 RelationshipList relationshipList = genericVnf.getRelationshipList();
75 if (relationshipList == null) {
76 relationshipList = new RelationshipList();
77 genericVnf.setRelationshipList(relationshipList);
79 return relationshipList.getRelationship().add(relationship);
81 LOGGER.error("Unable to find GenericVnf ...");
86 public void clearAll() {
87 clearCahce(GENERIC_VNF_CACHE.getName());