2 * Copyright 2016-2017, Nokia Corporation
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core;
18 import com.google.common.cache.CacheLoader;
19 import com.google.common.cache.LoadingCache;
20 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.api.VimInfoProvider;
21 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.api.VnfmInfoProvider;
22 import org.onap.vnfmdriver.model.VnfmInfo;
23 import org.slf4j.Logger;
24 import org.springframework.beans.factory.InitializingBean;
25 import org.springframework.core.env.Environment;
27 import java.util.concurrent.TimeUnit;
29 import static com.google.common.cache.CacheBuilder.newBuilder;
30 import static java.lang.Long.valueOf;
31 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.fatalFailure;
32 import static org.slf4j.LoggerFactory.getLogger;
35 * Responsible for providing access to core systems
37 public abstract class GenericExternalSystemInfoProvider extends IpMappingProvider implements VnfmInfoProvider, VimInfoProvider, InitializingBean {
39 * The name of the VNFM info cache eviction in the properties file
41 public static final String VNFM_INFO_CACHE_EVICTION_IN_MS = "vnfmInfoCacheEvictionInMs";
43 * The default VNFM info cache eviction in milliseconds
45 public static final int DEFAULT_CACHE_EVICTION_TIMEOUT_IN_MS = 10 * 60 * 1000;
46 private static Logger logger = getLogger(GenericExternalSystemInfoProvider.class);
47 private final Environment environment;
48 private LoadingCache<String, VnfmInfo> vnfmInfoCache;
50 public GenericExternalSystemInfoProvider(Environment environment) {
52 this.environment = environment;
56 * After the Bean has been initialized the IP mapping and the VMFM cache is initialized
57 * It is done in this phase because the logic requires the the @Value anoted fields to
61 public void afterPropertiesSet() throws Exception {
62 super.afterPropertiesSet();
63 vnfmInfoCache = newBuilder().expireAfterWrite(environment.getProperty(VNFM_INFO_CACHE_EVICTION_IN_MS, Long.class, valueOf(DEFAULT_CACHE_EVICTION_TIMEOUT_IN_MS)), TimeUnit.MILLISECONDS).concurrencyLevel(1).build(new CacheLoader<String, VnfmInfo>() {
65 public VnfmInfo load(String vnfmId) throws Exception {
66 logger.info("Quering VNFM info from source with " + vnfmId + " identifier");
67 return queryVnfmInfoFromSource(vnfmId);
73 * @param vnfmId the identifier of the VNFM
74 * @return the cached VNFM
76 public VnfmInfo getVnfmInfo(String vnfmId) {
78 return vnfmInfoCache.get(vnfmId);
79 } catch (Exception e) {
80 throw fatalFailure(logger, "Unable to query VNFM info for " + vnfmId, e);
85 * Load the information related to the VNFM from the remote source
87 * @param vnfmId the identifier of the VNFM
88 * @return the description of the VNFM
90 public abstract VnfmInfo queryVnfmInfoFromSource(String vnfmId);