2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017 Amdocs
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 package org.onap.aai.sparky.dal.aai.config;
25 import java.util.Arrays;
26 import java.util.List;
27 import java.util.Properties;
29 import org.onap.aai.sparky.dal.aai.enums.RestAuthenticationMode;
30 import org.onap.aai.sparky.util.ConfigHelper;
33 * The Class ActiveInventoryRestConfig.
35 public class ActiveInventoryRestConfig {
41 private int connectTimeoutInMs;
43 private int readTimeoutInMs;
45 private int numRequestRetries;
47 private int numResolverWorkers;
49 private boolean useCacheOnly;
51 private boolean cacheEnabled;
53 private boolean cacheFailures;
55 private String storageFolderOverride;
59 private long maxTimeToLiveInMs;
61 private String resourceBasePath;
63 private List<String> shallowEntities;
65 private RestAuthenticationMode authenticationMode;
67 public List<String> getShallowEntities() {
68 return shallowEntities;
72 * Instantiates a new active inventory rest config.
74 * @param props the props
76 public ActiveInventoryRestConfig(Properties props) {
82 Properties restProps = ConfigHelper.getConfigWithPrefix("aai.rest", props);
84 resourceBasePath = restProps.getProperty("resourceBasePath", "/aai/v7");
85 host = restProps.getProperty("host", "localhost");
86 port = restProps.getProperty("port", "8443");
87 numRequestRetries = Integer.parseInt(restProps.getProperty("numRequestRetries", "5"));
88 numResolverWorkers = Integer.parseInt(restProps.getProperty("numResolverWorkers", "15"));
90 connectTimeoutInMs = Integer.parseInt(restProps.getProperty("connectTimeoutInMs", "5000"));
91 readTimeoutInMs = Integer.parseInt(restProps.getProperty("readTimeoutInMs", "10000"));
93 String shallowEntitiesProperty = restProps.getProperty("shallowEntities", "");
94 shallowEntities = Arrays.asList(shallowEntitiesProperty.split(","));
96 Properties cacheProps = ConfigHelper.getConfigWithPrefix("aai.rest.cache", props);
97 cacheEnabled = Boolean.parseBoolean(cacheProps.getProperty("enabled", "false"));
98 storageFolderOverride = cacheProps.getProperty("storageFolderOverride", null);
99 cacheFailures = Boolean.parseBoolean(cacheProps.getProperty("cacheFailures", "false"));
100 useCacheOnly = Boolean.parseBoolean(cacheProps.getProperty("useCacheOnly", "false"));
101 numCacheWorkers = Integer.parseInt(cacheProps.getProperty("numWorkers", "5"));
104 if (storageFolderOverride != null && storageFolderOverride.length() == 0) {
105 storageFolderOverride = null;
108 * The expectation of this parameter is that if the value > 0, then the cached resources will be
109 * served back instead of dipping AAI/DataLayer as long as the current resource age from the
110 * cached instance is < maxTimeToLiveInMs.
112 maxTimeToLiveInMs = Long.parseLong(cacheProps.getProperty("maxTimeToLiveInMs", "-1"));
113 authenticationMode = RestAuthenticationMode.getRestAuthenticationMode(restProps.getProperty("authenticationMode", RestAuthenticationMode.SSL_CERT.getAuthenticationModeLabel()));
116 * In any kind of error scenario, set the authentication mode to SSL_CERT as our default.
117 * This is an arbitrary default, but was chosen based on the way this code worked before
118 * introduction of the SSL Basic Auth settings.
120 if ( authenticationMode == RestAuthenticationMode.UNKNOWN_MODE) {
121 authenticationMode = RestAuthenticationMode.SSL_CERT;
126 public RestAuthenticationMode getAuthenticationMode() {
127 return authenticationMode;
130 public void setAuthenticationMode(RestAuthenticationMode authenticationMode) {
131 this.authenticationMode = authenticationMode;
134 public int getNumCacheWorkers() {
135 return numCacheWorkers;
138 public void setNumCacheWorkers(int numCacheWorkers) {
139 this.numCacheWorkers = numCacheWorkers;
143 * Should cache failures.
145 * @return true, if successful
147 public boolean shouldCacheFailures() {
148 return cacheFailures;
151 public void setShouldCacheFailures(boolean enabled) {
152 this.cacheFailures = enabled;
156 * Checks if is shallow entity.
158 * @param entityType the entity type
159 * @return true, if is shallow entity
161 public boolean isShallowEntity(String entityType) {
162 if (entityType == null) {
166 for (String entity : shallowEntities) {
167 if (entityType.equalsIgnoreCase(entity)) {
175 public boolean isUseCacheOnly() {
179 public void setUseCacheOnly(boolean useCacheOnly) {
180 this.useCacheOnly = useCacheOnly;
183 public int getNumResolverWorkers() {
184 return numResolverWorkers;
187 public void setNumResolverWorkers(int numResolverWorkers) {
188 this.numResolverWorkers = numResolverWorkers;
191 public long getMaxTimeToLiveInMs() {
192 return maxTimeToLiveInMs;
195 public void setMaxTimeToLiveInMs(long maxTimeToLiveInMs) {
196 this.maxTimeToLiveInMs = maxTimeToLiveInMs;
199 public boolean isCacheEnabled() {
203 public void setCacheEnabled(boolean cacheEnabled) {
204 this.cacheEnabled = cacheEnabled;
207 public String getStorageFolderOverride() {
208 return storageFolderOverride;
211 public void setStorageFolderOverride(String storageFolderOverride) {
212 this.storageFolderOverride = storageFolderOverride;
215 public String getHost() {
219 public String getPort() {
223 public String getResourceBasePath() {
224 return resourceBasePath;
227 public void setHost(String host) {
231 public void setPort(String port) {
236 * @see java.lang.Object#toString()
240 public void setResourceBasePath(String resourceBasePath) {
241 this.resourceBasePath = resourceBasePath;
245 public String toString() {
246 return "ActiveInventoryRestConfig [host=" + host + ", port=" + port + ", connectTimeoutInMs="
247 + connectTimeoutInMs + ", readTimeoutInMs=" + readTimeoutInMs + ", numRequestRetries="
248 + numRequestRetries + ", numResolverWorkers=" + numResolverWorkers + ", useCacheOnly="
249 + useCacheOnly + ", cacheEnabled=" + cacheEnabled + ", cacheFailures=" + cacheFailures
250 + ", storageFolderOverride=" + storageFolderOverride + ", numCacheWorkers="
251 + numCacheWorkers + ", maxTimeToLiveInMs=" + maxTimeToLiveInMs + ", resourceBasePath="
252 + resourceBasePath + ", shallowEntities=" + shallowEntities + ", authenticationMode="
253 + authenticationMode + "]";
256 public int getConnectTimeoutInMs() {
257 return connectTimeoutInMs;
260 public void setConnectTimeoutInMs(int connectTimeoutInMs) {
261 this.connectTimeoutInMs = connectTimeoutInMs;
264 public int getReadTimeoutInMs() {
265 return readTimeoutInMs;
268 public void setReadTimeoutInMs(int readTimeoutInMs) {
269 this.readTimeoutInMs = readTimeoutInMs;
272 public int getNumRequestRetries() {
273 return numRequestRetries;
276 public void setNumRequestRetries(int numRequestRetries) {
277 this.numRequestRetries = numRequestRetries;