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 List<String> shallowEntities;
51 private RestAuthenticationMode authenticationMode;
53 public List<String> getShallowEntities() {
54 return shallowEntities;
58 * Instantiates a new active inventory rest config.
60 * @param props the props
62 public ActiveInventoryRestConfig(Properties props) {
64 if (props == null || props.isEmpty()) {
68 Properties restProps = ConfigHelper.getConfigWithPrefix("aai.rest", props);
70 host = restProps.getProperty("host", "localhost");
71 port = restProps.getProperty("port", "8443");
72 numRequestRetries = Integer.parseInt(restProps.getProperty("numRequestRetries", "5"));
73 numResolverWorkers = Integer.parseInt(restProps.getProperty("numResolverWorkers", "15"));
75 connectTimeoutInMs = Integer.parseInt(restProps.getProperty("connectTimeoutInMs", "5000"));
76 readTimeoutInMs = Integer.parseInt(restProps.getProperty("readTimeoutInMs", "10000"));
78 String shallowEntitiesProperty = restProps.getProperty("shallowEntities", "");
79 shallowEntities = Arrays.asList(shallowEntitiesProperty.split(","));
82 RestAuthenticationMode.getRestAuthenticationMode(restProps.getProperty("authenticationMode",
83 RestAuthenticationMode.SSL_CERT.getAuthenticationModeLabel()));
86 * In any kind of error scenario, set the authentication mode to SSL_CERT as our default. This
87 * is an arbitrary default, but was chosen based on the way this code worked before introduction
88 * of the SSL Basic Auth settings.
90 if (authenticationMode == RestAuthenticationMode.UNKNOWN_MODE) {
91 authenticationMode = RestAuthenticationMode.SSL_CERT;
96 public RestAuthenticationMode getAuthenticationMode() {
97 return authenticationMode;
100 public void setAuthenticationMode(RestAuthenticationMode authenticationMode) {
101 this.authenticationMode = authenticationMode;
106 * Checks if is shallow entity.
108 * @param entityType the entity type
109 * @return true, if is shallow entity
111 public boolean isShallowEntity(String entityType) {
112 if (entityType == null) {
116 for (String entity : shallowEntities) {
117 if (entityType.equalsIgnoreCase(entity)) {
125 public int getNumResolverWorkers() {
126 return numResolverWorkers;
129 public void setNumResolverWorkers(int numResolverWorkers) {
130 this.numResolverWorkers = numResolverWorkers;
133 public String getHost() {
137 public String getPort() {
141 public void setHost(String host) {
145 public void setPort(String port) {
149 public int getConnectTimeoutInMs() {
150 return connectTimeoutInMs;
153 public void setConnectTimeoutInMs(int connectTimeoutInMs) {
154 this.connectTimeoutInMs = connectTimeoutInMs;
157 public int getReadTimeoutInMs() {
158 return readTimeoutInMs;
161 public void setReadTimeoutInMs(int readTimeoutInMs) {
162 this.readTimeoutInMs = readTimeoutInMs;
165 public int getNumRequestRetries() {
166 return numRequestRetries;
169 public void setNumRequestRetries(int numRequestRetries) {
170 this.numRequestRetries = numRequestRetries;