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