2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.openecomp.appc.oam.util;
27 import com.att.eelf.configuration.EELFLogger;
28 import org.apache.commons.lang3.ArrayUtils;
29 import org.openecomp.appc.Constants;
30 import org.openecomp.appc.configuration.Configuration;
31 import org.openecomp.appc.configuration.ConfigurationFactory;
33 import java.util.concurrent.TimeUnit;
36 * Utility class provides general configuration helps
38 public class ConfigurationHelper {
39 final static String PROP_KEY_APPC_NAME = Constants.PROPERTY_APPLICATION_NAME;
40 final static String PROP_KEY_METRIC_STATE = "metric.enabled";
41 private final String OAM_OPERATION_TIMEOUT_SECOND = "appc.OAM.api.timeout";
42 /** Default operation timeout set to 1 minute */
43 private final int DEFAULT_OAM_OPERATION_TIMEOUT = 60;
45 private final EELFLogger logger;
46 private Configuration configuration = ConfigurationFactory.getConfiguration();
48 public ConfigurationHelper(EELFLogger eelfLogger) {
52 public String getAppcName() {
53 return configuration.getProperty(PROP_KEY_APPC_NAME);
56 public boolean isMetricEnabled() {
57 return configuration.getBooleanProperty(PROP_KEY_METRIC_STATE, false);
60 public Configuration getConfig() {
65 * Read property value of a specified property key
67 * @param propertyKey string of the property key
68 * @return String[] of the property values associated with the propertyKey
70 String[] readProperty(String propertyKey) {
71 String propertyValue = configuration.getProperty(propertyKey);
72 if (propertyValue == null) {
73 return ArrayUtils.EMPTY_STRING_ARRAY;
76 if (logger.isDebugEnabled()) {
77 logger.debug(String.format("Property[%s] has value (%s).", propertyKey, propertyValue));
80 if (propertyValue.contains(",")) {
81 return propertyValue.split("\\s*,\\s*");
83 return new String[]{propertyValue};
91 * This method returns timeout in milliseconds. The source is chosen in the following order:
92 * The overrideTimeoutSeconds argument
93 * or {@link #OAM_OPERATION_TIMEOUT_SECOND} found in the configuration file
94 * or the {@link #DEFAULT_OAM_OPERATION_TIMEOUT}
95 * @param overrideTimeoutSeconds or null to us the other sources
96 * @return timeout in milliseconds
98 public long getOAMOperationTimeoutValue(Integer overrideTimeoutSeconds) {
99 return overrideTimeoutSeconds == null ?
100 getConfig().getIntegerProperty(OAM_OPERATION_TIMEOUT_SECOND, DEFAULT_OAM_OPERATION_TIMEOUT) * 1000
102 TimeUnit.MILLISECONDS.toMillis(overrideTimeoutSeconds);