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 {
40 * @return the cacheFailures
42 public boolean isCacheFailures() {
47 * @param cacheFailures the cacheFailures to set
49 public void setCacheFailures(boolean cacheFailures) {
50 this.cacheFailures = cacheFailures;
54 * @param shallowEntities the shallowEntities to set
56 public void setShallowEntities(List<String> shallowEntities) {
57 this.shallowEntities = shallowEntities;
62 private int connectTimeoutInMs;
64 private int readTimeoutInMs;
66 private int numRequestRetries;
68 private int numResolverWorkers;
70 private boolean useCacheOnly;
72 private boolean cacheEnabled;
74 private boolean cacheFailures;
76 private String storageFolderOverride;
80 private long maxTimeToLiveInMs;
82 private String resourceBasePath;
84 private List<String> shallowEntities;
86 private RestAuthenticationMode authenticationMode;
88 public List<String> getShallowEntities() {
89 return shallowEntities;
93 * Instantiates a new active inventory rest config.
95 * @param props the props
97 public ActiveInventoryRestConfig(Properties props) {
103 Properties restProps = ConfigHelper.getConfigWithPrefix("aai.rest", props);
105 resourceBasePath = restProps.getProperty("resourceBasePath", "/aai/v7");
106 host = restProps.getProperty("host", "localhost");
107 port = restProps.getProperty("port", "8443");
108 numRequestRetries = Integer.parseInt(restProps.getProperty("numRequestRetries", "5"));
109 numResolverWorkers = Integer.parseInt(restProps.getProperty("numResolverWorkers", "15"));
111 connectTimeoutInMs = Integer.parseInt(restProps.getProperty("connectTimeoutInMs", "5000"));
112 readTimeoutInMs = Integer.parseInt(restProps.getProperty("readTimeoutInMs", "10000"));
114 String shallowEntitiesProperty = restProps.getProperty("shallowEntities", "");
115 shallowEntities = Arrays.asList(shallowEntitiesProperty.split(","));
117 Properties cacheProps = ConfigHelper.getConfigWithPrefix("aai.rest.cache", props);
118 cacheEnabled = Boolean.parseBoolean(cacheProps.getProperty("enabled", "false"));
119 storageFolderOverride = cacheProps.getProperty("storageFolderOverride", null);
120 cacheFailures = Boolean.parseBoolean(cacheProps.getProperty("cacheFailures", "false"));
121 useCacheOnly = Boolean.parseBoolean(cacheProps.getProperty("useCacheOnly", "false"));
122 numCacheWorkers = Integer.parseInt(cacheProps.getProperty("numWorkers", "5"));
125 if (storageFolderOverride != null && storageFolderOverride.length() == 0) {
126 storageFolderOverride = null;
129 * The expectation of this parameter is that if the value > 0, then the cached resources will be
130 * served back instead of dipping AAI/DataLayer as long as the current resource age from the
131 * cached instance is < maxTimeToLiveInMs.
133 maxTimeToLiveInMs = Long.parseLong(cacheProps.getProperty("maxTimeToLiveInMs", "-1"));
134 authenticationMode = RestAuthenticationMode.getRestAuthenticationMode(restProps.getProperty("authenticationMode", RestAuthenticationMode.SSL_CERT.getAuthenticationModeLabel()));
137 * In any kind of error scenario, set the authentication mode to SSL_CERT as our default.
138 * This is an arbitrary default, but was chosen based on the way this code worked before
139 * introduction of the SSL Basic Auth settings.
141 if ( authenticationMode == RestAuthenticationMode.UNKNOWN_MODE) {
142 authenticationMode = RestAuthenticationMode.SSL_CERT;
147 public RestAuthenticationMode getAuthenticationMode() {
148 return authenticationMode;
151 public void setAuthenticationMode(RestAuthenticationMode authenticationMode) {
152 this.authenticationMode = authenticationMode;
155 public int getNumCacheWorkers() {
156 return numCacheWorkers;
159 public void setNumCacheWorkers(int numCacheWorkers) {
160 this.numCacheWorkers = numCacheWorkers;
164 * Should cache failures.
166 * @return true, if successful
168 public boolean shouldCacheFailures() {
169 return cacheFailures;
172 public void setShouldCacheFailures(boolean enabled) {
173 this.cacheFailures = enabled;
177 * Checks if is shallow entity.
179 * @param entityType the entity type
180 * @return true, if is shallow entity
182 public boolean isShallowEntity(String entityType) {
183 if (entityType == null) {
187 for (String entity : shallowEntities) {
188 if (entityType.equalsIgnoreCase(entity)) {
196 public boolean isUseCacheOnly() {
200 public void setUseCacheOnly(boolean useCacheOnly) {
201 this.useCacheOnly = useCacheOnly;
204 public int getNumResolverWorkers() {
205 return numResolverWorkers;
208 public void setNumResolverWorkers(int numResolverWorkers) {
209 this.numResolverWorkers = numResolverWorkers;
212 public long getMaxTimeToLiveInMs() {
213 return maxTimeToLiveInMs;
216 public void setMaxTimeToLiveInMs(long maxTimeToLiveInMs) {
217 this.maxTimeToLiveInMs = maxTimeToLiveInMs;
220 public boolean isCacheEnabled() {
224 public void setCacheEnabled(boolean cacheEnabled) {
225 this.cacheEnabled = cacheEnabled;
228 public String getStorageFolderOverride() {
229 return storageFolderOverride;
232 public void setStorageFolderOverride(String storageFolderOverride) {
233 this.storageFolderOverride = storageFolderOverride;
236 public String getHost() {
240 public String getPort() {
244 public String getResourceBasePath() {
245 return resourceBasePath;
248 public void setHost(String host) {
252 public void setPort(String port) {
257 * @see java.lang.Object#toString()
261 public void setResourceBasePath(String resourceBasePath) {
262 this.resourceBasePath = resourceBasePath;
266 public String toString() {
267 return "ActiveInventoryRestConfig [host=" + host + ", port=" + port + ", connectTimeoutInMs="
268 + connectTimeoutInMs + ", readTimeoutInMs=" + readTimeoutInMs + ", numRequestRetries="
269 + numRequestRetries + ", numResolverWorkers=" + numResolverWorkers + ", useCacheOnly="
270 + useCacheOnly + ", cacheEnabled=" + cacheEnabled + ", cacheFailures=" + cacheFailures
271 + ", storageFolderOverride=" + storageFolderOverride + ", numCacheWorkers="
272 + numCacheWorkers + ", maxTimeToLiveInMs=" + maxTimeToLiveInMs + ", resourceBasePath="
273 + resourceBasePath + ", shallowEntities=" + shallowEntities + ", authenticationMode="
274 + authenticationMode + "]";
277 public int getConnectTimeoutInMs() {
278 return connectTimeoutInMs;
281 public void setConnectTimeoutInMs(int connectTimeoutInMs) {
282 this.connectTimeoutInMs = connectTimeoutInMs;
285 public int getReadTimeoutInMs() {
286 return readTimeoutInMs;
289 public void setReadTimeoutInMs(int readTimeoutInMs) {
290 this.readTimeoutInMs = readTimeoutInMs;
293 public int getNumRequestRetries() {
294 return numRequestRetries;
297 public void setNumRequestRetries(int numRequestRetries) {
298 this.numRequestRetries = numRequestRetries;