2 * Copyright © 2017-2018 AT&T Intellectual Property.
\r
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
\r
5 * in compliance with the License. You may obtain a copy of the License at
\r
7 * http://www.apache.org/licenses/LICENSE-2.0
\r
9 * Unless required by applicable law or agreed to in writing, software distributed under the License
\r
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
\r
11 * or implied. See the License for the specific language governing permissions and limitations under
\r
15 package org.onap.ccsdk.config.data.adaptor.dao;
\r
17 import java.util.Map;
\r
18 import java.util.concurrent.ConcurrentHashMap;
\r
19 import java.util.concurrent.Executors;
\r
20 import java.util.concurrent.ScheduledExecutorService;
\r
21 import java.util.concurrent.TimeUnit;
\r
22 import org.apache.commons.lang3.StringUtils;
\r
23 import org.onap.ccsdk.config.data.adaptor.DataAdaptorConstants;
\r
24 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
\r
25 import org.springframework.jdbc.core.JdbcTemplate;
\r
26 import com.att.eelf.configuration.EELFLogger;
\r
27 import com.att.eelf.configuration.EELFManager;
\r
28 import com.google.common.base.Preconditions;
\r
30 public class ConfigPropertyMapDaoImpl implements ConfigPropertyMapDao {
\r
32 private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigPropertyMapDaoImpl.class);
\r
34 private JdbcTemplate jdbcTemplate;
\r
35 private Map<String, String> configPropertyMap = new ConcurrentHashMap<>();
\r
37 public ConfigPropertyMapDaoImpl(JdbcTemplate jdbcTemplate) {
\r
38 this.jdbcTemplate = jdbcTemplate;
\r
41 String envType = configPropertyMap.get(DataAdaptorConstants.PROPERTY_ENV_TYPE);
\r
42 if (!(DataAdaptorConstants.PROPERTY_ENV_PROD.equalsIgnoreCase(envType)
\r
43 || DataAdaptorConstants.PROPERTY_ENV_SOLO.equalsIgnoreCase(envType))) {
\r
44 ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
\r
45 Runnable task = () -> {
\r
48 executor.scheduleWithFixedDelay(task, 60, 15, TimeUnit.MINUTES);
\r
52 private void initializeMap() {
\r
53 String getPropQuery = "SELECT * FROM CONFIG_PROPERTY_MAP";
\r
54 jdbcTemplate.queryForList(getPropQuery).forEach(rows -> {
\r
55 String key = StringUtils.trimToEmpty((String) rows.get("reference_key"));
\r
56 String value = StringUtils.trimToEmpty((String) rows.get("reference_value"));
\r
57 configPropertyMap.put(key, value);
\r
59 logger.trace("loaded configPropertyMap : ({})", configPropertyMap);
\r
63 public String getConfigPropertyByKey(String key) throws SvcLogicException {
\r
64 Preconditions.checkArgument(StringUtils.isNotBlank(key), "missing property key");
\r
65 return configPropertyMap.get(key);
\r