aboutsummaryrefslogtreecommitdiffstats
path: root/sdnr/wt/common/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'sdnr/wt/common/src/main')
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/configuration/ConfigurationFileRepresentation.java2
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/ExtRestClient.java8
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/HtDatabaseClient.java6
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/AliasesEntry.java4
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/DatabaseVersion.java (renamed from sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/EsVersion.java)18
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/IndicesEntry.java16
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/queries/QueryBuilder.java13
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/responses/GetInfoResponse.java8
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/file/PomFile.java6
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/http/BaseHTTPClient.java17
10 files changed, 70 insertions, 28 deletions
diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/configuration/ConfigurationFileRepresentation.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/configuration/ConfigurationFileRepresentation.java
index 96bfa070b..54a5172a3 100644
--- a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/configuration/ConfigurationFileRepresentation.java
+++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/configuration/ConfigurationFileRepresentation.java
@@ -46,7 +46,7 @@ public class ConfigurationFileRepresentation implements IConfigChangedListener {
private static final Logger LOG = LoggerFactory.getLogger(ConfigurationFileRepresentation.class);
private static final long FILE_POLL_INTERVAL_MS = 1000;
- private static final String SECTIONNAME_ROOT = "";
+ public static final String SECTIONNAME_ROOT = "";
private static final String LR = "\n";
private static final String EMPTY = "";
// end of constants
diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/ExtRestClient.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/ExtRestClient.java
index 1f67e5ef8..8b2dbb004 100644
--- a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/ExtRestClient.java
+++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/ExtRestClient.java
@@ -44,7 +44,7 @@ import org.elasticsearch.client.RestClientBuilder.HttpClientConfigCallback;
import org.json.JSONException;
import org.onap.ccsdk.features.sdnr.wt.common.database.config.HostInfo;
import org.onap.ccsdk.features.sdnr.wt.common.database.config.HostInfo.Protocol;
-import org.onap.ccsdk.features.sdnr.wt.common.database.data.EsVersion;
+import org.onap.ccsdk.features.sdnr.wt.common.database.data.DatabaseVersion;
import org.onap.ccsdk.features.sdnr.wt.common.database.requests.ClusterHealthRequest;
import org.onap.ccsdk.features.sdnr.wt.common.database.requests.ClusterSettingsRequest;
import org.onap.ccsdk.features.sdnr.wt.common.database.requests.CreateAliasRequest;
@@ -150,9 +150,9 @@ public class ExtRestClient {
this.client = RestClient.builder(get(hosts))
.setHttpClientConfigCallback(new BasicAuthHttpClientConfigCallback(username, password, trustAll))
.build();
- EsVersion tmp = autoDetectVersion();
+ DatabaseVersion tmp = autoDetectVersion();
LOG.info("working with sdnrdb version {}", tmp.toString());
- this.isES7 = tmp.isNewerOrEqualThan(new EsVersion(7, 0, 0));
+ this.isES7 = tmp.isNewerOrEqualThan(new DatabaseVersion(7, 0, 0));
}
/**
@@ -160,7 +160,7 @@ public class ExtRestClient {
* @throws IOException
* @throws Exception
*/
- private EsVersion autoDetectVersion() throws IOException, Exception {
+ private DatabaseVersion autoDetectVersion() throws IOException, Exception {
GetInfoResponse infoResponse = this.getInfo();
return infoResponse.getVersion();
diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/HtDatabaseClient.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/HtDatabaseClient.java
index 232b68c73..e4b8893c5 100644
--- a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/HtDatabaseClient.java
+++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/HtDatabaseClient.java
@@ -60,6 +60,7 @@ public class HtDatabaseClient extends ExtRestClient implements DatabaseClient, A
private static final long TIMOUT_MS_DEFAULT = 30000;
private static final long READ_MAX_SIZE = 9999;
private final static long SLEEPTIMEMS = 5000;
+ private static final boolean FULLSIZEREQUEST_DEFAULT = false;
private final Logger LOG = LoggerFactory.getLogger(HtDatabaseClient.class);
@@ -90,7 +91,7 @@ public class HtDatabaseClient extends ExtRestClient implements DatabaseClient, A
}
static public HtDatabaseClient getClient(HostInfo[] hosts, String username, String password, boolean trustAll,
- long timeoutms) throws HtDatabaseClientException {
+ boolean doFullsizeRequests, long timeoutms) throws HtDatabaseClientException {
return getClient(hosts, REFRESH_AFTER_REWRITE_DEFAULT, username, password, trustAll, TIMOUT_MS_DEFAULT);
}
@@ -261,7 +262,8 @@ public class HtDatabaseClient extends ExtRestClient implements DatabaseClient, A
total = response.getTotal();
} catch (IOException e) {
- LOG.warn("Possible Database connection failure. If this error persists, please check Database connectivity");
+ LOG.warn(
+ "Possible Database connection failure. If this error persists, please check Database connectivity");
LOG.warn("error do search {}: {}", queryBuilder, e);
}
return new SearchResult<SearchHit>(response != null ? response.getHits() : new SearchHit[] {}, total);
diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/AliasesEntry.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/AliasesEntry.java
index d55e66d2e..118cf0282 100644
--- a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/AliasesEntry.java
+++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/AliasesEntry.java
@@ -45,6 +45,10 @@ public class AliasesEntry {
private final String alias;
private final String index;
+ public AliasesEntry(String index, String alias) {
+ this.alias = alias;
+ this.index = index;
+ }
public AliasesEntry(String line) throws ParseException {
final Matcher matcher = pattern.matcher(line);
if (!matcher.find() || matcher.groupCount() < 2) {
diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/EsVersion.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/DatabaseVersion.java
index e1fd02de0..e37b9d924 100644
--- a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/EsVersion.java
+++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/DatabaseVersion.java
@@ -29,14 +29,14 @@ import org.eclipse.jdt.annotation.NonNull;
* @author Michael Dürre
*
*/
-public class EsVersion {
+public class DatabaseVersion {
private final String raw;
private final int major;
private final int minor;
private final int revision;
- public EsVersion(@NonNull String version) throws ParseException {
+ public DatabaseVersion(@NonNull String version) throws ParseException {
String[] hlp = version.split("\\.");
if (hlp.length < 3) {
throw new ParseException("unable to parse version string: " + version, 0);
@@ -57,7 +57,7 @@ public class EsVersion {
* @param minor
* @param revision
*/
- public EsVersion(int major, int minor, int revision) {
+ public DatabaseVersion(int major, int minor, int revision) {
this.raw = String.format("%d.%d.%d", major, minor, revision);
this.major = major;
this.minor = minor;
@@ -87,10 +87,10 @@ public class EsVersion {
@Override
public boolean equals(Object obj) {
- if (!(obj instanceof EsVersion)) {
+ if (!(obj instanceof DatabaseVersion)) {
return false;
}
- EsVersion esobj = (EsVersion) obj;
+ DatabaseVersion esobj = (DatabaseVersion) obj;
return this.major == esobj.major && this.minor == esobj.minor && this.revision == esobj.revision;
}
@@ -99,13 +99,13 @@ public class EsVersion {
return this.raw.hashCode();
}
- public boolean isNewerOrEqualThan(EsVersion v) {
+ public boolean isNewerOrEqualThan(DatabaseVersion v) {
if (this.equals(v)) {
return true;
}
return this.isNewerThan(v);
}
- public boolean isNewerThan(EsVersion v) {
+ public boolean isNewerThan(DatabaseVersion v) {
if (this.major > v.major) {
return true;
} else if (this.major < v.major) {
@@ -122,14 +122,14 @@ public class EsVersion {
return false;
}
- public boolean isOlderOrEqualThan(EsVersion v) {
+ public boolean isOlderOrEqualThan(DatabaseVersion v) {
if (this.equals(v)) {
return true;
}
return this.isOlderThan(v);
}
- public boolean isOlderThan(EsVersion v) {
+ public boolean isOlderThan(DatabaseVersion v) {
if (this.major < v.major) {
return true;
} else if (this.major > v.major) {
diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/IndicesEntry.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/IndicesEntry.java
index b31ff4389..cc7fafb76 100644
--- a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/IndicesEntry.java
+++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/IndicesEntry.java
@@ -29,7 +29,7 @@ import java.util.regex.Pattern;
* @author Michael Dürre
*
* Entry of list indices http request (/_cat/indices)
- *
+ *
* yellow open inventoryequipment-v1 5nNPRbJ3T9arMxqxBbJKyQ 5 1 0 0 1.2kb 1.2kb
*/
public class IndicesEntry {
@@ -93,6 +93,20 @@ public class IndicesEntry {
return size2;
}
+ protected IndicesEntry(String name, String status, String status2, String hash, int shards, int replicas, int c1,
+ int c2, String size1, String size2) {
+ this.name = name;
+ this.status = status;
+ this.status2 = status2;
+ this.hash = hash;
+ this.shards = shards;
+ this.replicas = replicas;
+ this.c1 = c1;
+ this.c2 = c2;
+ this.size1 = size1;
+ this.size2 = size2;
+ }
+
public IndicesEntry(String line) throws ParseException {
Matcher matcher = pattern.matcher(line.trim());
if (!matcher.find() || matcher.groupCount() < 10) {
diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/queries/QueryBuilder.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/queries/QueryBuilder.java
index 519502efd..265c6f529 100644
--- a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/queries/QueryBuilder.java
+++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/queries/QueryBuilder.java
@@ -100,4 +100,17 @@ public class QueryBuilder {
public QueryBuilder aggregations(String key) {
return this.aggregations(key, null);
}
+
+ public void doFullsizeRequest() {
+ this.setFullsizeRequest(true);
+ }
+
+ public QueryBuilder setFullsizeRequest(boolean doFullsizeRequest) {
+ if (doFullsizeRequest) {
+ this.outerQuery.put("track_total_hits", doFullsizeRequest);
+ } else {
+ this.outerQuery.remove("track_total_hits");
+ }
+ return this;
+ }
}
diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/responses/GetInfoResponse.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/responses/GetInfoResponse.java
index 946a8fb4a..79172e01c 100644
--- a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/responses/GetInfoResponse.java
+++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/responses/GetInfoResponse.java
@@ -23,7 +23,7 @@ package org.onap.ccsdk.features.sdnr.wt.common.database.responses;
import org.elasticsearch.client.Response;
import org.json.JSONObject;
-import org.onap.ccsdk.features.sdnr.wt.common.database.data.EsVersion;
+import org.onap.ccsdk.features.sdnr.wt.common.database.data.DatabaseVersion;
public class GetInfoResponse extends BaseResponse {
@@ -37,7 +37,7 @@ public class GetInfoResponse extends BaseResponse {
private final String clusterName;
private final String name;
- private final EsVersion version;
+ private final DatabaseVersion version;
public GetInfoResponse(Response response) throws Exception {
super(response);
@@ -47,7 +47,7 @@ public class GetInfoResponse extends BaseResponse {
}
this.name = o.getString("name");
this.clusterName = o.getString("cluster_name");
- this.version = new EsVersion(o.getJSONObject("version").getString("number"));
+ this.version = new DatabaseVersion(o.getJSONObject("version").getString("number"));
}
public String getClusterName() {
@@ -58,7 +58,7 @@ public class GetInfoResponse extends BaseResponse {
return name;
}
- public EsVersion getVersion() {
+ public DatabaseVersion getVersion() {
return version;
}
diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/file/PomFile.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/file/PomFile.java
index c19cea08d..2e0701257 100644
--- a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/file/PomFile.java
+++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/file/PomFile.java
@@ -41,8 +41,10 @@ public class PomFile {
public PomFile(InputStream is) throws ParserConfigurationException, SAXException, IOException {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
- // Remediate XML external entity vulnerabilty - prohibit the use of all protocols by external entities:
- documentBuilderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
+ // documentBuilderFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
+ // documentBuilderFactory.setFeature(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
+ // documentBuilderFactory.setFeature(XMLInputFactory.SUPPORT_DTD, false);
+
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
this.xmlDoc = documentBuilder.parse(is);
}
diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/http/BaseHTTPClient.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/http/BaseHTTPClient.java
index ffb31c676..de878a5d5 100644
--- a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/http/BaseHTTPClient.java
+++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/http/BaseHTTPClient.java
@@ -113,7 +113,12 @@ public class BaseHTTPClient {
@Nonnull
public BaseHTTPResponse sendRequest(String uri, String method, String body, Map<String, String> headers)
throws IOException {
- return this.sendRequest(uri, method, body != null ? body.getBytes(CHARSET) : null, headers);
+ return this.sendRequest(uri, method, body != null ? body.getBytes(CHARSET) : null, headers, 0);
+ }
+ @Nonnull
+ public BaseHTTPResponse sendRequest(String uri, String method, String body, Map<String, String> headers, int timeoutMs)
+ throws IOException {
+ return this.sendRequest(uri, method, body != null ? body.getBytes(CHARSET) : null, headers, timeoutMs);
}
public BaseHTTPResponse sendRequest(HttpServletRequest req) throws IOException {
final String method = req.getMethod();
@@ -125,7 +130,7 @@ public class BaseHTTPClient {
is.close();
}
- return this.sendRequest(req.getRequestURI(), method, buffer,mapHeaders(req));
+ return this.sendRequest(req.getRequestURI(), method, buffer,mapHeaders(req), 0);
}
private Map<String, String> mapHeaders(HttpServletRequest req) {
@@ -138,8 +143,10 @@ public class BaseHTTPClient {
}
return headers;
}
-
- protected @Nonnull BaseHTTPResponse sendRequest(String uri, String method, byte[] body, Map<String, String> headers)
+ protected @Nonnull BaseHTTPResponse sendRequest(String uri, String method, byte[] body, Map<String, String> headers) throws IOException {
+ return this.sendRequest(uri, method, body, headers, 0);
+ }
+ protected @Nonnull BaseHTTPResponse sendRequest(String uri, String method, byte[] body, Map<String, String> headers, int timeoutMs)
throws IOException {
if (uri == null) {
uri = "";
@@ -156,7 +163,7 @@ public class BaseHTTPClient {
LOG.trace("body:" + (body == null ? "null" : new String(body, CHARSET)));
URL url = new URL(surl);
URLConnection http = url.openConnection();
- http.setConnectTimeout(this.timeout);
+ http.setConnectTimeout(timeoutMs>0?timeoutMs:this.timeout);
if (surl.toString().startsWith("https")) {
if (sc != null) {
((HttpsURLConnection) http).setSSLSocketFactory(sc.getSocketFactory());