2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ============LICENSE_END=========================================================
24 package org.onap.appc.oam.util;
26 import com.att.eelf.configuration.EELFLogger;
27 import org.apache.commons.lang3.ArrayUtils;
28 import org.onap.appc.Constants;
29 import org.onap.appc.configuration.Configuration;
30 import org.onap.appc.configuration.ConfigurationFactory;
32 import java.util.concurrent.TimeUnit;
35 * Utility class provides general configuration helps
37 public class ConfigurationHelper {
38 final static String PROP_KEY_APPC_NAME = Constants.PROPERTY_APPLICATION_NAME;
39 final static String PROP_KEY_METRIC_STATE = "metric.enabled";
40 private final String OAM_OPERATION_TIMEOUT_SECOND = "appc.OAM.api.timeout";
41 /** Default operation timeout set to 1 minute */
42 private final int DEFAULT_OAM_OPERATION_TIMEOUT = 60;
44 private final EELFLogger logger;
45 private Configuration configuration = ConfigurationFactory.getConfiguration();
47 public ConfigurationHelper(EELFLogger eelfLogger) {
51 public String getAppcName() {
52 return configuration.getProperty(PROP_KEY_APPC_NAME);
55 public boolean isMetricEnabled() {
56 return configuration.getBooleanProperty(PROP_KEY_METRIC_STATE, false);
59 public Configuration getConfig() {
64 * Read property value of a specified property key
66 * @param propertyKey string of the property key
67 * @return String[] of the property values associated with the propertyKey
69 String[] readProperty(String propertyKey) {
70 String propertyValue = configuration.getProperty(propertyKey);
71 if (propertyValue == null) {
72 return ArrayUtils.EMPTY_STRING_ARRAY;
75 if (logger.isDebugEnabled()) {
76 logger.debug(String.format("Property[%s] has value (%s).", propertyKey, propertyValue));
79 if (propertyValue.contains(",")) {
80 return propertyValue.split("\\s*,\\s*");
82 return new String[]{propertyValue};
90 * This method returns timeout in milliseconds. The source is chosen in the following order:
91 * The overrideTimeoutSeconds argument
92 * or {@link #OAM_OPERATION_TIMEOUT_SECOND} found in the configuration file
93 * or the {@link #DEFAULT_OAM_OPERATION_TIMEOUT}
94 * @param overrideTimeoutSeconds or null to us the other sources
95 * @return timeout in milliseconds
97 public long getOAMOperationTimeoutValue(Integer overrideTimeoutSeconds) {
98 return TimeUnit.SECONDS.toMillis(
99 overrideTimeoutSeconds == null ?
100 getConfig().getIntegerProperty(OAM_OPERATION_TIMEOUT_SECOND, DEFAULT_OAM_OPERATION_TIMEOUT)
102 overrideTimeoutSeconds