summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openecomp/sparky/dal/aai/config/ActiveInventoryRestConfig.java
blob: d609f163994ba84b177447473c01116a8d2bc146 (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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
/**
 * ============LICENSE_START===================================================
 * SPARKY (AAI UI service)
 * ============================================================================
 * Copyright © 2017 AT&T Intellectual Property.
 * Copyright © 2017 Amdocs
 * All rights reserved.
 * ============================================================================
 * 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.
 * ============LICENSE_END=====================================================
 *
 * ECOMP and OpenECOMP are trademarks
 * and service marks of AT&T Intellectual Property.
 */

package org.openecomp.sparky.dal.aai.config;

import java.util.Arrays;
import java.util.List;
import java.util.Properties;

import org.openecomp.sparky.dal.aai.enums.RestAuthenticationMode;
import org.openecomp.sparky.util.ConfigHelper;

/**
 * The Class ActiveInventoryRestConfig.
 */
public class ActiveInventoryRestConfig {

  private String host;

  private String port;

  private int connectTimeoutInMs;

  private int readTimeoutInMs;

  private int numRequestRetries;

  private int numResolverWorkers;

  private boolean useCacheOnly;

  private boolean cacheEnabled;

  private boolean cacheFailures;

  private String storageFolderOverride;

  int numCacheWorkers;

  private long maxTimeToLiveInMs;

  private String resourceBasePath;

  private List<String> shallowEntities;
  
  private RestAuthenticationMode authenticationMode;

  public List<String> getShallowEntities() {
    return shallowEntities;
  }

  /**
   * Instantiates a new active inventory rest config.
   *
   * @param props the props
   */
  public ActiveInventoryRestConfig(Properties props) {

    if (props == null) {
      return;
    }

    Properties restProps = ConfigHelper.getConfigWithPrefix("aai.rest", props);

    resourceBasePath = restProps.getProperty("resourceBasePath", "/aai/v7");
    host = restProps.getProperty("host", "localhost");
    port = restProps.getProperty("port", "8443");
    numRequestRetries = Integer.parseInt(restProps.getProperty("numRequestRetries", "5"));
    numResolverWorkers = Integer.parseInt(restProps.getProperty("numResolverWorkers", "15"));

    connectTimeoutInMs = Integer.parseInt(restProps.getProperty("connectTimeoutInMs", "5000"));
    readTimeoutInMs = Integer.parseInt(restProps.getProperty("readTimeoutInMs", "10000"));

    String shallowEntitiesProperty = restProps.getProperty("shallowEntities", "");
    shallowEntities = Arrays.asList(shallowEntitiesProperty.split(","));

    Properties cacheProps = ConfigHelper.getConfigWithPrefix("aai.rest.cache", props);
    cacheEnabled = Boolean.parseBoolean(cacheProps.getProperty("enabled", "false"));
    storageFolderOverride = cacheProps.getProperty("storageFolderOverride", null);
    cacheFailures = Boolean.parseBoolean(cacheProps.getProperty("cacheFailures", "false"));
    useCacheOnly = Boolean.parseBoolean(cacheProps.getProperty("useCacheOnly", "false"));
    numCacheWorkers = Integer.parseInt(cacheProps.getProperty("numWorkers", "5"));


    if (storageFolderOverride != null && storageFolderOverride.length() == 0) {
      storageFolderOverride = null;
    }
    /*
     * The expectation of this parameter is that if the value > 0, then the cached resources will be
     * served back instead of dipping AAI/DataLayer as long as the current resource age from the
     * cached instance is < maxTimeToLiveInMs.
     */
    maxTimeToLiveInMs = Long.parseLong(cacheProps.getProperty("maxTimeToLiveInMs", "-1"));
    authenticationMode = RestAuthenticationMode.getRestAuthenticationMode(restProps.getProperty("authenticationMode", RestAuthenticationMode.SSL_CERT.getAuthenticationModeLabel()));

    /*
     * In any kind of error scenario, set the authentication mode to SSL_CERT as our default.
     * This is an arbitrary default, but was chosen based on the way this code worked before
     * introduction of the SSL Basic Auth settings.
     */
    if ( authenticationMode == RestAuthenticationMode.UNKNOWN_MODE) {
      authenticationMode = RestAuthenticationMode.SSL_CERT;
    }
    
  }

  public RestAuthenticationMode getAuthenticationMode() {
    return authenticationMode;
  }

  public void setAuthenticationMode(RestAuthenticationMode authenticationMode) {
    this.authenticationMode = authenticationMode;
  }

  public int getNumCacheWorkers() {
    return numCacheWorkers;
  }

  public void setNumCacheWorkers(int numCacheWorkers) {
    this.numCacheWorkers = numCacheWorkers;
  }

  /**
   * Should cache failures.
   *
   * @return true, if successful
   */
  public boolean shouldCacheFailures() {
    return cacheFailures;
  }

  public void setShouldCacheFailures(boolean enabled) {
    this.cacheFailures = enabled;
  }

  /**
   * Checks if is shallow entity.
   *
   * @param entityType the entity type
   * @return true, if is shallow entity
   */
  public boolean isShallowEntity(String entityType) {
    if (entityType == null) {
      return false;
    }

    for (String entity : shallowEntities) {
      if (entityType.equalsIgnoreCase(entity)) {
        return true;
      }
    }

    return false;
  }

  public boolean isUseCacheOnly() {
    return useCacheOnly;
  }

  public void setUseCacheOnly(boolean useCacheOnly) {
    this.useCacheOnly = useCacheOnly;
  }

  public int getNumResolverWorkers() {
    return numResolverWorkers;
  }

  public void setNumResolverWorkers(int numResolverWorkers) {
    this.numResolverWorkers = numResolverWorkers;
  }

  public long getMaxTimeToLiveInMs() {
    return maxTimeToLiveInMs;
  }

  public void setMaxTimeToLiveInMs(long maxTimeToLiveInMs) {
    this.maxTimeToLiveInMs = maxTimeToLiveInMs;
  }

  public boolean isCacheEnabled() {
    return cacheEnabled;
  }

  public void setCacheEnabled(boolean cacheEnabled) {
    this.cacheEnabled = cacheEnabled;
  }

  public String getStorageFolderOverride() {
    return storageFolderOverride;
  }

  public void setStorageFolderOverride(String storageFolderOverride) {
    this.storageFolderOverride = storageFolderOverride;
  }

  public String getHost() {
    return host;
  }

  public String getPort() {
    return port;
  }

  public String getResourceBasePath() {
    return resourceBasePath;
  }

  public void setHost(String host) {
    this.host = host;
  }

  public void setPort(String port) {
    this.port = port;
  }

  /* (non-Javadoc)
   * @see java.lang.Object#toString()
   */
 
 
  public void setResourceBasePath(String resourceBasePath) {
    this.resourceBasePath = resourceBasePath;
  }

  @Override
  public String toString() {
    return "ActiveInventoryRestConfig [host=" + host + ", port=" + port + ", connectTimeoutInMs="
        + connectTimeoutInMs + ", readTimeoutInMs=" + readTimeoutInMs + ", numRequestRetries="
        + numRequestRetries + ", numResolverWorkers=" + numResolverWorkers + ", useCacheOnly="
        + useCacheOnly + ", cacheEnabled=" + cacheEnabled + ", cacheFailures=" + cacheFailures
        + ", storageFolderOverride=" + storageFolderOverride + ", numCacheWorkers="
        + numCacheWorkers + ", maxTimeToLiveInMs=" + maxTimeToLiveInMs + ", resourceBasePath="
        + resourceBasePath + ", shallowEntities=" + shallowEntities + ", authenticationMode="
        + authenticationMode + "]";
  }

  public int getConnectTimeoutInMs() {
    return connectTimeoutInMs;
  }

  public void setConnectTimeoutInMs(int connectTimeoutInMs) {
    this.connectTimeoutInMs = connectTimeoutInMs;
  }

  public int getReadTimeoutInMs() {
    return readTimeoutInMs;
  }

  public void setReadTimeoutInMs(int readTimeoutInMs) {
    this.readTimeoutInMs = readTimeoutInMs;
  }

  public int getNumRequestRetries() {
    return numRequestRetries;
  }

  public void setNumRequestRetries(int numRequestRetries) {
    this.numRequestRetries = numRequestRetries;
  }

}