2 * ============LICENSE_START===================================================
3 * SPARKY (AAI UI service)
4 * ============================================================================
5 * Copyright © 2017 AT&T Intellectual Property.
6 * Copyright © 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.
20 * ============LICENSE_END=====================================================
22 * ECOMP and OpenECOMP are trademarks
23 * and service marks of AT&T Intellectual Property.
26 package org.openecomp.sparky.dal.aai.config;
28 import java.util.Arrays;
29 import java.util.List;
30 import java.util.Properties;
32 import org.openecomp.sparky.dal.aai.enums.RestAuthenticationMode;
33 import org.openecomp.sparky.util.ConfigHelper;
36 * The Class ActiveInventoryRestConfig.
38 public class ActiveInventoryRestConfig {
44 private int connectTimeoutInMs;
46 private int readTimeoutInMs;
48 private int numRequestRetries;
50 private int numResolverWorkers;
52 private boolean useCacheOnly;
54 private boolean cacheEnabled;
56 private boolean cacheFailures;
58 private String storageFolderOverride;
62 private long maxTimeToLiveInMs;
64 private String resourceBasePath;
66 private List<String> shallowEntities;
68 private RestAuthenticationMode authenticationMode;
70 public List<String> getShallowEntities() {
71 return shallowEntities;
75 * Instantiates a new active inventory rest config.
77 * @param props the props
79 public ActiveInventoryRestConfig(Properties props) {
85 Properties restProps = ConfigHelper.getConfigWithPrefix("aai.rest", props);
87 resourceBasePath = restProps.getProperty("resourceBasePath", "/aai/v7");
88 host = restProps.getProperty("host", "localhost");
89 port = restProps.getProperty("port", "8443");
90 numRequestRetries = Integer.parseInt(restProps.getProperty("numRequestRetries", "5"));
91 numResolverWorkers = Integer.parseInt(restProps.getProperty("numResolverWorkers", "15"));
93 connectTimeoutInMs = Integer.parseInt(restProps.getProperty("connectTimeoutInMs", "5000"));
94 readTimeoutInMs = Integer.parseInt(restProps.getProperty("readTimeoutInMs", "10000"));
96 String shallowEntitiesProperty = restProps.getProperty("shallowEntities", "");
97 shallowEntities = Arrays.asList(shallowEntitiesProperty.split(","));
99 Properties cacheProps = ConfigHelper.getConfigWithPrefix("aai.rest.cache", props);
100 cacheEnabled = Boolean.parseBoolean(cacheProps.getProperty("enabled", "false"));
101 storageFolderOverride = cacheProps.getProperty("storageFolderOverride", null);
102 cacheFailures = Boolean.parseBoolean(cacheProps.getProperty("cacheFailures", "false"));
103 useCacheOnly = Boolean.parseBoolean(cacheProps.getProperty("useCacheOnly", "false"));
104 numCacheWorkers = Integer.parseInt(cacheProps.getProperty("numWorkers", "5"));
107 if (storageFolderOverride != null && storageFolderOverride.length() == 0) {
108 storageFolderOverride = null;
111 * The expectation of this parameter is that if the value > 0, then the cached resources will be
112 * served back instead of dipping AAI/DataLayer as long as the current resource age from the
113 * cached instance is < maxTimeToLiveInMs.
115 maxTimeToLiveInMs = Long.parseLong(cacheProps.getProperty("maxTimeToLiveInMs", "-1"));
116 authenticationMode = RestAuthenticationMode.getRestAuthenticationMode(restProps.getProperty("authenticationMode", RestAuthenticationMode.SSL_CERT.getAuthenticationModeLabel()));
119 * In any kind of error scenario, set the authentication mode to SSL_CERT as our default.
120 * This is an arbitrary default, but was chosen based on the way this code worked before
121 * introduction of the SSL Basic Auth settings.
123 if ( authenticationMode == RestAuthenticationMode.UNKNOWN_MODE) {
124 authenticationMode = RestAuthenticationMode.SSL_CERT;
129 public RestAuthenticationMode getAuthenticationMode() {
130 return authenticationMode;
133 public void setAuthenticationMode(RestAuthenticationMode authenticationMode) {
134 this.authenticationMode = authenticationMode;
137 public int getNumCacheWorkers() {
138 return numCacheWorkers;
141 public void setNumCacheWorkers(int numCacheWorkers) {
142 this.numCacheWorkers = numCacheWorkers;
146 * Should cache failures.
148 * @return true, if successful
150 public boolean shouldCacheFailures() {
151 return cacheFailures;
154 public void setShouldCacheFailures(boolean enabled) {
155 this.cacheFailures = enabled;
159 * Checks if is shallow entity.
161 * @param entityType the entity type
162 * @return true, if is shallow entity
164 public boolean isShallowEntity(String entityType) {
165 if (entityType == null) {
169 for (String entity : shallowEntities) {
170 if (entityType.equalsIgnoreCase(entity)) {
178 public boolean isUseCacheOnly() {
182 public void setUseCacheOnly(boolean useCacheOnly) {
183 this.useCacheOnly = useCacheOnly;
186 public int getNumResolverWorkers() {
187 return numResolverWorkers;
190 public void setNumResolverWorkers(int numResolverWorkers) {
191 this.numResolverWorkers = numResolverWorkers;
194 public long getMaxTimeToLiveInMs() {
195 return maxTimeToLiveInMs;
198 public void setMaxTimeToLiveInMs(long maxTimeToLiveInMs) {
199 this.maxTimeToLiveInMs = maxTimeToLiveInMs;
202 public boolean isCacheEnabled() {
206 public void setCacheEnabled(boolean cacheEnabled) {
207 this.cacheEnabled = cacheEnabled;
210 public String getStorageFolderOverride() {
211 return storageFolderOverride;
214 public void setStorageFolderOverride(String storageFolderOverride) {
215 this.storageFolderOverride = storageFolderOverride;
218 public String getHost() {
222 public String getPort() {
226 public String getResourceBasePath() {
227 return resourceBasePath;
230 public void setHost(String host) {
234 public void setPort(String port) {
239 * @see java.lang.Object#toString()
243 public void setResourceBasePath(String resourceBasePath) {
244 this.resourceBasePath = resourceBasePath;
248 public String toString() {
249 return "ActiveInventoryRestConfig [host=" + host + ", port=" + port + ", connectTimeoutInMs="
250 + connectTimeoutInMs + ", readTimeoutInMs=" + readTimeoutInMs + ", numRequestRetries="
251 + numRequestRetries + ", numResolverWorkers=" + numResolverWorkers + ", useCacheOnly="
252 + useCacheOnly + ", cacheEnabled=" + cacheEnabled + ", cacheFailures=" + cacheFailures
253 + ", storageFolderOverride=" + storageFolderOverride + ", numCacheWorkers="
254 + numCacheWorkers + ", maxTimeToLiveInMs=" + maxTimeToLiveInMs + ", resourceBasePath="
255 + resourceBasePath + ", shallowEntities=" + shallowEntities + ", authenticationMode="
256 + authenticationMode + "]";
259 public int getConnectTimeoutInMs() {
260 return connectTimeoutInMs;
263 public void setConnectTimeoutInMs(int connectTimeoutInMs) {
264 this.connectTimeoutInMs = connectTimeoutInMs;
267 public int getReadTimeoutInMs() {
268 return readTimeoutInMs;
271 public void setReadTimeoutInMs(int readTimeoutInMs) {
272 this.readTimeoutInMs = readTimeoutInMs;
275 public int getNumRequestRetries() {
276 return numRequestRetries;
279 public void setNumRequestRetries(int numRequestRetries) {
280 this.numRequestRetries = numRequestRetries;