aboutsummaryrefslogtreecommitdiffstats
path: root/sdnr
diff options
context:
space:
mode:
Diffstat (limited to 'sdnr')
-rw-r--r--sdnr/wt/common/pom.xml7
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/HtAssert.java17
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/configuration/subtypes/Section.java41
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/DatabaseClient.java24
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/ExtRestClient.java57
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/HtDatabaseClient.java108
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/HtDatabaseClientException.java45
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/Portstatus.java45
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/config/HostInfo.java2
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/EsVersion.java5
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/BaseRequest.java2
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/ClusterSettingsRequest.java8
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/CreateIndexRequest.java3
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/Delete7Request.java42
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/Get7Request.java41
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/GetRequest.java12
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/Index7Request.java50
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/Search7Request.java46
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/SearchRequest.java14
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/Update7Request.java40
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/UpdateByQuery7Request.java39
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/responses/BaseResponse.java9
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/responses/DeleteResponse.java2
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/responses/SearchResponse.java16
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/responses/UpdateResponse.java2
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/http/BaseHTTPClient.java12
-rw-r--r--sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestConfig.java21
-rw-r--r--sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestDbClient.java10
-rw-r--r--sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestDbRequests.java74
-rw-r--r--sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestPortstatus.java29
-rw-r--r--sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/ElasticSearchDataProvider.java4
-rw-r--r--sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/MediatorServerDataProvider.java5
-rw-r--r--sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestCRUDforDatabase.java13
-rw-r--r--sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestConfig.java20
-rw-r--r--sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestDataMappings.java171
-rw-r--r--sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestEventService.java6
-rw-r--r--sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestMaintenanceServiceData.java10
-rw-r--r--sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestMediatorServerService.java5
-rw-r--r--sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangGenSalMapping.java164
-rw-r--r--sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/DataMigrationProviderImpl.java9
40 files changed, 839 insertions, 391 deletions
diff --git a/sdnr/wt/common/pom.xml b/sdnr/wt/common/pom.xml
index fd2bb46f3..6fba87af9 100644
--- a/sdnr/wt/common/pom.xml
+++ b/sdnr/wt/common/pom.xml
@@ -91,7 +91,10 @@
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
-
+ <dependency>
+ <groupId>com.google.code.findbugs</groupId>
+ <artifactId>annotations</artifactId>
+ </dependency>
</dependencies>
<build>
@@ -117,7 +120,7 @@
<clusterName>testCluster</clusterName>
<transportPort>9500</transportPort>
<httpPort>${databaseport}</httpPort>
- <version>6.5.0</version>
+ <version>7.1.1</version>
<timeout>120</timeout>
</configuration>
<executions>
diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/HtAssert.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/HtAssert.java
index 99a0aaa71..976213f6f 100644
--- a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/HtAssert.java
+++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/HtAssert.java
@@ -21,6 +21,8 @@
*/
package org.onap.ccsdk.features.sdnr.wt.common;
+import java.io.PrintWriter;
+import java.io.StringWriter;
import java.util.Arrays;
/**
@@ -45,7 +47,7 @@ public class HtAssert {
};
- private static String whoCalledMe() {
+ public static String whoCalledMe() {
StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();
StackTraceElement caller = stackTraceElements[3];
String classname = caller.getClassName();
@@ -54,4 +56,17 @@ public class HtAssert {
return classname + "." + methodName + ":" + lineNumber;
}
+ public static String whoCalledMeAll() {
+ // StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();
+ // StringBuilder line =new StringBuilder();
+ // for(StackTraceElement caller:stackTraceElements) {
+ // line.append(String.format("%s | %s:%d\n",caller.getClassName(),caller.getMethodName(),caller.getLineNumber()));
+ // }
+ // return line.toString();
+ StringWriter sw = new StringWriter();
+ PrintWriter pw = new PrintWriter(sw);
+ new Throwable().printStackTrace(pw);
+ return sw.toString();
+ }
+
}
diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/configuration/subtypes/Section.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/configuration/subtypes/Section.java
index 54ebd03ac..7fb58a165 100644
--- a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/configuration/subtypes/Section.java
+++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/configuration/subtypes/Section.java
@@ -25,29 +25,41 @@ import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map.Entry;
+import java.util.Objects;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.eclipse.jdt.annotation.NonNull;
import org.onap.ccsdk.features.sdnr.wt.common.configuration.exception.ConversionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- *
+ *
* @author Michael Dürre, Herbert Eiselt
*
* subset of configuration identified by its name
*/
public class Section {
+ //Interfaces
+ public interface EnvGetter {
+ String getenv(String substring);
+ }
+
// constants
private static final Logger LOG = LoggerFactory.getLogger(Section.class);
private static final String DELIMITER = "=";
private static final String COMMENTCHARS[] = {"#", ";"};
+ private static final String ENVVARIABLE = "${";
+ private static final String REGEXENVVARIABLE = "(\\$\\{[A-Z0-9_-]+\\})";
// end of constants
+ private final Pattern pattern;
+
+ // variables for test purpose
+ private static EnvGetter envGetter = (mkey) -> System.getenv(mkey);
- // variables
private final String name;
private final List<String> rawLines;
private final LinkedHashMap<String, SectionValue> values;
@@ -59,6 +71,7 @@ public class Section {
this.name = name;
this.rawLines = new ArrayList<>();
this.values = new LinkedHashMap<>();
+ this.pattern = Pattern.compile(REGEXENVVARIABLE);
}
//end of constructors
@@ -96,11 +109,9 @@ public class Section {
value = values.get(key).getValue();
}
//try to read env var
- if (value != null && value.contains("${")) {
+ if (value != null && value.contains(ENVVARIABLE)) {
LOG.debug("try to find env var(s) for {}", value);
- final String regex = "(\\$\\{[A-Z0-9_-]+\\})";
- final Pattern pattern = Pattern.compile(regex);
final Matcher matcher = pattern.matcher(value);
String tmp = new String(value);
while (matcher.find() && matcher.groupCount() > 0) {
@@ -108,7 +119,8 @@ public class Section {
if (mkey != null) {
try {
LOG.debug("match found for v={} and env key={}", tmp, mkey);
- String env = System.getenv(mkey.substring(2, mkey.length() - 1));
+ //String env=System.getenv(mkey.substring(2,mkey.length()-1));
+ String env = envGetter.getenv(mkey.substring(2, mkey.length() - 1));
tmp = tmp.replace(mkey, env == null ? "" : env);
} catch (SecurityException e) {
LOG.warn("unable to read env {}: {}", value, e);
@@ -120,8 +132,6 @@ public class Section {
return value;
}
-
-
public void setProperty(String key, String value) {
boolean isuncommented = this.isCommentLine(key);
if (isuncommented) {
@@ -170,8 +180,6 @@ public class Section {
}
}
-
-
public String[] toLines() {
List<String> lines = new ArrayList<>();
if (!this.name.isEmpty()) {
@@ -242,6 +250,19 @@ public class Section {
public String toString() {
return "Section [name=" + name + ", rawLines=" + rawLines + ", values=" + values + "]";
}
+
+ // static methods
+ public static void setEnvGetter(@NonNull EnvGetter newEnvGetter) {
+ if (Objects.nonNull(newEnvGetter)) {
+ envGetter = newEnvGetter;
+ } else {
+ throw new IllegalArgumentException("Null not allowed here");
+ }
+ }
+
+ public static EnvGetter getEnvGetter() {
+ return envGetter;
+ }
// end of public methods
}
diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/DatabaseClient.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/DatabaseClient.java
index 3a9c10514..fd7246605 100644
--- a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/DatabaseClient.java
+++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/DatabaseClient.java
@@ -101,6 +101,30 @@ public interface DatabaseClient {
public @Nullable String doWriteRaw(String indexName, String dataTypeName, @Nullable String esId, String json);
/**
+ * Write one object into Database
+ *
+ * @param indexName Name of index
+ * @param dataTypeName Name of datatype
+ * @param esId of object to be replaced or null for new entry.
+ * @param json String in JSON format.
+ * @param syncAfterRewrite trigger ES to sync after insert data
+ * @return esId String of the database object or null in case of write problems.
+ */
+ public @Nullable String doWriteRaw(String indexName, String dataTypeName, String esId, String json,
+ boolean syncAfterWrite);
+
+ /**
+ * Write one object into Database
+ *
+ * @param dataTypeName Name of datatype
+ * @param esId of object to be replaced or null for new entry.
+ * @param json String in JSON format.
+ * @param syncAfterRewrite trigger ES to sync after insert data
+ * @return esId String of the database object or null in case of write problems.
+ */
+ public @Nullable String doWriteRaw(String dataTypeName, String esId, String json, boolean syncAfterWrite);
+
+ /**
* Remove Object from database
*
* @param dataTypeName of object
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 9d5e9f648..836c0fae7 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
@@ -46,23 +46,30 @@ 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.requests.ClusterHealthRequest;
import org.onap.ccsdk.features.sdnr.wt.common.database.requests.ClusterSettingsRequest;
import org.onap.ccsdk.features.sdnr.wt.common.database.requests.CreateAliasRequest;
import org.onap.ccsdk.features.sdnr.wt.common.database.requests.CreateIndexRequest;
+import org.onap.ccsdk.features.sdnr.wt.common.database.requests.Delete7Request;
import org.onap.ccsdk.features.sdnr.wt.common.database.requests.DeleteAliasRequest;
import org.onap.ccsdk.features.sdnr.wt.common.database.requests.DeleteByQueryRequest;
import org.onap.ccsdk.features.sdnr.wt.common.database.requests.DeleteIndexRequest;
import org.onap.ccsdk.features.sdnr.wt.common.database.requests.DeleteRequest;
+import org.onap.ccsdk.features.sdnr.wt.common.database.requests.Get7Request;
import org.onap.ccsdk.features.sdnr.wt.common.database.requests.GetIndexRequest;
import org.onap.ccsdk.features.sdnr.wt.common.database.requests.GetInfoRequest;
import org.onap.ccsdk.features.sdnr.wt.common.database.requests.GetRequest;
+import org.onap.ccsdk.features.sdnr.wt.common.database.requests.Index7Request;
import org.onap.ccsdk.features.sdnr.wt.common.database.requests.IndexRequest;
import org.onap.ccsdk.features.sdnr.wt.common.database.requests.ListAliasesRequest;
import org.onap.ccsdk.features.sdnr.wt.common.database.requests.ListIndicesRequest;
import org.onap.ccsdk.features.sdnr.wt.common.database.requests.NodeStatsRequest;
import org.onap.ccsdk.features.sdnr.wt.common.database.requests.RefreshIndexRequest;
+import org.onap.ccsdk.features.sdnr.wt.common.database.requests.Search7Request;
import org.onap.ccsdk.features.sdnr.wt.common.database.requests.SearchRequest;
+import org.onap.ccsdk.features.sdnr.wt.common.database.requests.Update7Request;
+import org.onap.ccsdk.features.sdnr.wt.common.database.requests.UpdateByQuery7Request;
import org.onap.ccsdk.features.sdnr.wt.common.database.requests.UpdateByQueryRequest;
import org.onap.ccsdk.features.sdnr.wt.common.database.requests.UpdateRequest;
import org.onap.ccsdk.features.sdnr.wt.common.database.responses.ClusterHealthResponse;
@@ -84,6 +91,7 @@ import org.onap.ccsdk.features.sdnr.wt.common.database.responses.SearchResponse;
import org.onap.ccsdk.features.sdnr.wt.common.database.responses.UpdateByQueryResponse;
import org.onap.ccsdk.features.sdnr.wt.common.database.responses.UpdateResponse;
import org.onap.ccsdk.features.sdnr.wt.common.http.BaseHTTPClient;
+import org.osgi.framework.Version;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -186,15 +194,34 @@ public class ExtRestClient {
// }
private final RestClient client;
+ private final boolean isES7;
- protected ExtRestClient(HostInfo[] hosts) {
+ protected ExtRestClient(HostInfo[] hosts) throws Exception {
this(hosts, null, null, false);
}
- protected ExtRestClient(HostInfo[] hosts, String username, String password, boolean trustAll) {
+ protected ExtRestClient(HostInfo[] hosts, String username, String password, boolean trustAll) throws Exception {
this.client = RestClient.builder(get(hosts))
.setHttpClientConfigCallback(new BasicAuthHttpClientConfigCallback(username, password, trustAll))
.build();
+ EsVersion tmp = autoDetectVersion();
+ LOG.info("working with sdnrdb version {}", tmp.toString());
+ this.isES7 = tmp.isNewerOrEqualThan(new EsVersion(7, 0, 0));
+ }
+
+ /**
+ * @return
+ * @throws IOException
+ * @throws Exception
+ */
+ private EsVersion autoDetectVersion() throws IOException, Exception {
+ GetInfoResponse infoResponse = this.getInfo();
+ return infoResponse.getVersion();
+
+ }
+
+ public boolean isVersion7() {
+ return this.isES7;
}
public ClusterHealthResponse health(ClusterHealthRequest request)
@@ -207,7 +234,6 @@ public class ExtRestClient {
}
- //
public boolean indicesExists(GetIndexRequest request) throws IOException {
Response response = this.client.performRequest(request.getInner());
return response.getStatusLine().getStatusCode() == 200;
@@ -238,11 +264,17 @@ public class ExtRestClient {
}
public IndexResponse index(IndexRequest request) throws IOException {
+ if (this.isES7 && !(request instanceof Index7Request)) {
+ request = new Index7Request(request);
+ }
return new IndexResponse(this.client.performRequest(request.getInner()));
}
public DeleteResponse delete(DeleteRequest request) throws IOException {
Response response = null;
+ if (this.isES7 && !(request instanceof Delete7Request)) {
+ request = new Delete7Request(request);
+ }
try {
response = this.client.performRequest(request.getInner());
} catch (ResponseException e) {
@@ -274,6 +306,9 @@ public class ExtRestClient {
* @throws IOException of client
*/
public SearchResponse search(SearchRequest request, boolean ignoreParseException) throws IOException {
+ if (this.isES7 && !(request instanceof Search7Request)) {
+ request = new Search7Request(request);
+ }
if (ignoreParseException) {
try {
return new SearchResponse(this.client.performRequest(request.getInner()));
@@ -287,6 +322,9 @@ public class ExtRestClient {
}
public GetResponse get(GetRequest request) throws IOException {
+ if (this.isES7 && !(request instanceof Get7Request)) {
+ request = new Get7Request(request);
+ }
try {
return new GetResponse(this.client.performRequest(request.getInner()));
} catch (ResponseException e) {
@@ -295,11 +333,17 @@ public class ExtRestClient {
}
public UpdateByQueryResponse update(UpdateByQueryRequest request) throws IOException {
+ if (this.isES7 && !(request instanceof UpdateByQuery7Request)) {
+ request = new UpdateByQuery7Request(request);
+ }
return new UpdateByQueryResponse(this.client.performRequest(request.getInner()));
}
public UpdateResponse update(UpdateRequest request) throws IOException {
+ if (this.isES7 && !(request instanceof Update7Request)) {
+ request = new Update7Request(request);
+ }
return new UpdateResponse(this.client.performRequest(request.getInner()));
}
@@ -356,15 +400,16 @@ public class ExtRestClient {
return httphosts;
}
- public static ExtRestClient createInstance(HostInfo[] hosts) {
+ public static ExtRestClient createInstance(HostInfo[] hosts) throws Exception {
return new ExtRestClient(hosts);
}
- public static ExtRestClient createInstance(HostInfo[] hosts, String username, String password, boolean trustAll) {
+ public static ExtRestClient createInstance(HostInfo[] hosts, String username, String password, boolean trustAll)
+ throws Exception {
return new ExtRestClient(hosts, username, password, trustAll);
}
- public static ExtRestClient createInstance(String hostname, int port, Protocol protocol) {
+ public static ExtRestClient createInstance(String hostname, int port, Protocol protocol) throws Exception {
return createInstance(new HostInfo[] {new HostInfo(hostname, port, protocol)});
}
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 e8d86a925..1ae9f1e6c 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
@@ -25,7 +25,6 @@ import java.io.IOException;
import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
-
import org.json.JSONObject;
import org.onap.ccsdk.features.sdnr.wt.common.database.config.HostInfo;
import org.onap.ccsdk.features.sdnr.wt.common.database.queries.QueryBuilder;
@@ -35,7 +34,6 @@ import org.onap.ccsdk.features.sdnr.wt.common.database.requests.DeleteRequest;
import org.onap.ccsdk.features.sdnr.wt.common.database.requests.GetIndexRequest;
import org.onap.ccsdk.features.sdnr.wt.common.database.requests.GetRequest;
import org.onap.ccsdk.features.sdnr.wt.common.database.requests.IndexRequest;
-import org.onap.ccsdk.features.sdnr.wt.common.database.requests.RefreshIndexRequest;
import org.onap.ccsdk.features.sdnr.wt.common.database.requests.SearchRequest;
import org.onap.ccsdk.features.sdnr.wt.common.database.requests.UpdateByQueryRequest;
import org.onap.ccsdk.features.sdnr.wt.common.database.requests.UpdateRequest;
@@ -43,7 +41,6 @@ import org.onap.ccsdk.features.sdnr.wt.common.database.responses.DeleteByQueryRe
import org.onap.ccsdk.features.sdnr.wt.common.database.responses.DeleteResponse;
import org.onap.ccsdk.features.sdnr.wt.common.database.responses.GetResponse;
import org.onap.ccsdk.features.sdnr.wt.common.database.responses.IndexResponse;
-import org.onap.ccsdk.features.sdnr.wt.common.database.responses.RefreshIndexResponse;
import org.onap.ccsdk.features.sdnr.wt.common.database.responses.SearchResponse;
import org.onap.ccsdk.features.sdnr.wt.common.database.responses.UpdateByQueryResponse;
import org.onap.ccsdk.features.sdnr.wt.common.database.responses.UpdateResponse;
@@ -59,34 +56,69 @@ import org.slf4j.LoggerFactory;
public class HtDatabaseClient extends ExtRestClient implements DatabaseClient, AutoCloseable {
private static final boolean REFRESH_AFTER_REWRITE_DEFAULT = true;
- private static final boolean TRUSTALL_DEFAULT = false;
+ public static final boolean TRUSTALL_DEFAULT = false;
+ private static final long TIMOUT_MS_DEFAULT = 30000;
+ private static final long READ_MAX_SIZE = 9999;
+ private final static long SLEEPTIMEMS = 5000;
private final Logger LOG = LoggerFactory.getLogger(HtDatabaseClient.class);
private boolean doRefreshAfterWrite;
- public HtDatabaseClient(HostInfo[] hosts) {
- this(hosts, REFRESH_AFTER_REWRITE_DEFAULT);
+ private HtDatabaseClient(HostInfo[] hosts, boolean refreshAfterWrite, String username, String password,
+ boolean trustAll) throws Exception {
+ super(hosts, username, password, trustAll);
+ this.doRefreshAfterWrite = refreshAfterWrite;
}
- public HtDatabaseClient(HostInfo[] hosts, boolean refreshAfterWrite) {
- this(hosts, refreshAfterWrite, null, null, TRUSTALL_DEFAULT);
+ /*----------------------------------
+ * static factory function
+ */
+
+ static public HtDatabaseClient getClient(HostInfo[] hosts) throws HtDatabaseClientException {
+ return getClient(hosts, REFRESH_AFTER_REWRITE_DEFAULT, null, null, TRUSTALL_DEFAULT, TIMOUT_MS_DEFAULT);
}
- public HtDatabaseClient(HostInfo[] hosts, String username, String password) {
- this(hosts, username, password, TRUSTALL_DEFAULT);
+ static public HtDatabaseClient getClient(HostInfo[] hosts, String username, String password)
+ throws HtDatabaseClientException {
+ return getClient(hosts, REFRESH_AFTER_REWRITE_DEFAULT, username, password, TRUSTALL_DEFAULT, TIMOUT_MS_DEFAULT);
}
- public HtDatabaseClient(HostInfo[] hosts, String username, String password, boolean trustAll) {
- this(hosts, REFRESH_AFTER_REWRITE_DEFAULT, username, password, trustAll);
+ static public HtDatabaseClient getClient(HostInfo[] hosts, String username, String password, boolean trustAll)
+ throws HtDatabaseClientException {
+ return getClient(hosts, REFRESH_AFTER_REWRITE_DEFAULT, username, password, trustAll, TIMOUT_MS_DEFAULT);
}
- public HtDatabaseClient(HostInfo[] hosts, boolean refreshAfterWrite, String username, String password,
- boolean trustAll) {
- super(hosts, username, password, trustAll);
- this.doRefreshAfterWrite = refreshAfterWrite;
+ static public HtDatabaseClient getClient(HostInfo[] hosts, String username, String password, boolean trustAll,
+ long timeoutms) throws HtDatabaseClientException {
+ return getClient(hosts, REFRESH_AFTER_REWRITE_DEFAULT, username, password, trustAll, TIMOUT_MS_DEFAULT);
}
+ static public HtDatabaseClient getClient(HostInfo[] hosts, boolean refreshAfterWrite, String username,
+ String password, boolean trustAll, long timeoutms) throws HtDatabaseClientException {
+ long waiting = 0;
+ HtDatabaseClient client = null;
+ Exception exceptionWas = null;
+
+ do {
+ try {
+ client = new HtDatabaseClient(hosts, refreshAfterWrite, username, password, trustAll);
+ exceptionWas = null;
+ } catch (Exception e) {
+ try {
+ Thread.sleep(SLEEPTIMEMS);
+ } catch (InterruptedException e1) {
+ Thread.currentThread().interrupt();
+ }
+ waiting += SLEEPTIMEMS;
+ exceptionWas = e;
+ }
+ } while (client == null && waiting < timeoutms);
+ if (client == null) {
+ throw new HtDatabaseClientException("Can not reach database server. Client not started.", exceptionWas);
+ }
+ return client;
+ }
/*----------------------------------
* Functions
@@ -133,7 +165,17 @@ public class HtDatabaseClient extends ExtRestClient implements DatabaseClient, A
}
@Override
+ public String doWriteRaw(String dataTypeName, String esId, String json, boolean syncAfterWrite) {
+ return this.doWriteRaw(dataTypeName, dataTypeName, esId, json, syncAfterWrite);
+ }
+
+ @Override
public @Nullable String doWriteRaw(String indexName, String dataTypeName, @Nullable String esId, String json) {
+ return this.doWriteRaw(indexName, dataTypeName, esId, json, this.doRefreshAfterWrite);
+ }
+
+ @Override
+ public String doWriteRaw(String indexName, String dataTypeName, String esId, String json, boolean syncAfterWrite) {
IndexResponse response = null;
IndexRequest indexRequest = new IndexRequest(indexName, dataTypeName, esId, this.doRefreshAfterWrite);
@@ -148,24 +190,9 @@ public class HtDatabaseClient extends ExtRestClient implements DatabaseClient, A
LOG.warn("Response null during write: {} {}", esId, json);
return null;
}
- // if(this.doRefreshAfterWrite) {
- // this.doRefresh(dataTypeName);
- // }
return response.getId();
}
- private void doRefresh(String dataTypeName) {
- try {
- RefreshIndexResponse response = this.refreshIndex(new RefreshIndexRequest(dataTypeName));
- if (!response.succeeded()) {
- LOG.warn("seems that index {} was not refreshed", dataTypeName);
- }
- } catch (IOException e) {
- LOG.warn("problem with refreshing index: {}", e);
- }
-
- }
-
@Override
public boolean doRemove(String dataTypeName, IsEsObject esId) {
return doRemove(dataTypeName, esId.getEsId());
@@ -181,9 +208,6 @@ public class HtDatabaseClient extends ExtRestClient implements DatabaseClient, A
} catch (IOException e) {
LOG.warn("Problem deleting from db: {}", e.getMessage());
}
- // if(this.doRefreshAfterWrite) {
- // this.doRefresh(dataTypeName);
- // }
return response != null ? response.isDeleted() : false;
}
@@ -229,7 +253,6 @@ public class HtDatabaseClient extends ExtRestClient implements DatabaseClient, A
long total = 0;
LOG.debug("NetworkIndex query and read: {}", dataTypeName);
-
SearchRequest searchRequest = new SearchRequest(alias, dataTypeName);
searchRequest.setQuery(queryBuilder);
SearchResponse response = null;
@@ -250,7 +273,8 @@ public class HtDatabaseClient extends ExtRestClient implements DatabaseClient, A
@Override
public @Nonnull SearchResult<SearchHit> doReadAllJsonData(String dataTypeName, boolean ignoreException) {
- return doReadByQueryJsonData(dataTypeName, QueryBuilders.matchAllQuery(), ignoreException);
+ return doReadByQueryJsonData(dataTypeName, QueryBuilders.matchAllQuery().size(READ_MAX_SIZE).from(0),
+ ignoreException);
}
public @Nonnull SearchResult<SearchHit> doReadAllJsonData(String alias, String dataType, boolean ignoreException) {
@@ -277,11 +301,8 @@ public class HtDatabaseClient extends ExtRestClient implements DatabaseClient, A
UpdateResponse response = this.update(request);
success = response.succeeded();
} catch (IOException e) {
- LOG.warn("Problem updating {} with id {} and data {}: {}", dataTypeName, esId, json, e);
+ LOG.warn("Problem updating {} with id {} and data {}: '{}'", dataTypeName, esId, json, e.getMessage());
}
- // if(this.doRefreshAfterWrite) {
- // this.doRefresh(dataTypeName);
- // }
return success ? esId : null;
}
@@ -296,9 +317,6 @@ public class HtDatabaseClient extends ExtRestClient implements DatabaseClient, A
} catch (IOException e) {
LOG.warn("Problem updating items in {} with query {} and data {}: {}", dataTypeName, query, json, e);
}
- // if(this.doRefreshAfterWrite) {
- // this.doRefresh(dataTypeName);
- // }
return success;
}
@@ -315,11 +333,9 @@ public class HtDatabaseClient extends ExtRestClient implements DatabaseClient, A
} catch (IOException e) {
LOG.warn("Problem delete in {} with query {}:{} ", dataTypeName, query.toJSON(), e);
}
- // if(this.doRefreshAfterWrite) {
- // this.doRefresh(dataTypeName);
- // }
return del;
}
+
}
diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/HtDatabaseClientException.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/HtDatabaseClientException.java
new file mode 100644
index 000000000..b1b3f7275
--- /dev/null
+++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/HtDatabaseClientException.java
@@ -0,0 +1,45 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : ccsdk features
+ * ================================================================================
+ * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
+ * 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=========================================================
+ *
+ */
+package org.onap.ccsdk.features.sdnr.wt.common.database;
+
+public class HtDatabaseClientException extends Exception {
+ // constants
+ private static final long serialVersionUID = 1L;
+ // end of constants
+
+ // variables
+ private Throwable rootCause;
+ // end of variables
+
+ // constructors
+ public HtDatabaseClientException(String message, Throwable rootCause) {
+ super(message, rootCause);
+ this.rootCause = rootCause;
+ }
+ // end of constructors
+
+ // getters and setters
+ public Throwable getRootCause() {
+ return rootCause;
+ }
+ // end of getters and setters
+}
diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/Portstatus.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/Portstatus.java
index 250842e57..475178b4c 100644
--- a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/Portstatus.java
+++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/Portstatus.java
@@ -1,25 +1,30 @@
/*
- * ============LICENSE_START========================================================================
- * ONAP : ccsdk feature sdnr wt
- * =================================================================================================
- * Copyright (C) Apache Camel project
- * =================================================================================================
- * 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
+ * ============LICENSE_START=======================================================
+ * ONAP : ccsdk features
+ * ================================================================================
+ * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
+ * 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
+ * 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==========================================================================
+ * 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=========================================================
*/
-
package org.onap.ccsdk.features.sdnr.wt.common.database;
import java.io.IOException;
-import java.net.Socket;
+import java.net.InetSocketAddress;
+import java.net.SocketAddress;
+import java.nio.channels.SocketChannel;
+
import org.onap.ccsdk.features.sdnr.wt.common.database.config.HostInfo;
public class Portstatus {
@@ -37,16 +42,16 @@ public class Portstatus {
throw new IllegalArgumentException("Invalid start port: " + port);
}
- Socket ss = null;
+ SocketChannel channel = null;
+ SocketAddress socketAddress = new InetSocketAddress(dnsName, port);
try {
- ss = new Socket(dnsName, port);
- ss.setReuseAddress(true);
+ channel = SocketChannel.open(socketAddress);
return true;
} catch (IOException e) {
} finally {
- if (ss != null) {
+ if (channel != null) {
try {
- ss.close();
+ channel.close();
} catch (IOException e) {
/* should not be thrown */
}
diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/config/HostInfo.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/config/HostInfo.java
index cb0454361..2dd05c574 100644
--- a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/config/HostInfo.java
+++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/config/HostInfo.java
@@ -96,7 +96,7 @@ public class HostInfo {
final Pattern pattern = Pattern.compile(regex);
final Matcher matcher = pattern.matcher(dbUrl);
if (!matcher.find() || matcher.groupCount() < 2) {
- throw new ParseException("url " + dbUrl + " not parseable", 0);
+ throw new ParseException("url '" + dbUrl + "' not parseable. Expected http://xyz", 0);
}
Protocol p = Protocol.getValueOf(matcher.group(1));
String host = matcher.group(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/EsVersion.java
index 7d106dfec..1dd1c3d53 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/EsVersion.java
@@ -48,6 +48,11 @@ public class EsVersion {
this.revision = Integer.parseInt(hlp[2]);
}
+ @Override
+ public String toString() {
+ return String.format("%d.%d.%d", this.major, this.minor, this.revision);
+ }
+
/**
* @param major
* @param minor
diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/BaseRequest.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/BaseRequest.java
index 028de75d2..5e4467e74 100644
--- a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/BaseRequest.java
+++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/BaseRequest.java
@@ -35,7 +35,7 @@ public abstract class BaseRequest {
private static final Logger LOG = LoggerFactory.getLogger(BaseRequest.class);
- public static final int DEFAULT_RETRIES = 1;
+ public static final int DEFAULT_RETRIES = 3;
protected final Request request;
private String query;
diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/ClusterSettingsRequest.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/ClusterSettingsRequest.java
index 1379da5ad..a85227858 100644
--- a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/ClusterSettingsRequest.java
+++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/ClusterSettingsRequest.java
@@ -41,6 +41,7 @@ public class ClusterSettingsRequest extends BaseRequest {
this.persistent = new JSONObject();
this.data.put("persistent", this.persistent);
this.allowAutoCreateIndex(autoCreateIndex);
+
}
public ClusterSettingsRequest allowAutoCreateIndex(boolean allow) {
@@ -48,4 +49,11 @@ public class ClusterSettingsRequest extends BaseRequest {
this.setQuery(this.data);
return this;
}
+
+ public ClusterSettingsRequest maxCompilationsPerMinute(long executions) {
+ //this.persistent.put("script.max_compilations_per_minute" ,executions);
+ this.persistent.put("script.max_compilations_rate", String.format("%d/1m", executions));
+ this.setQuery(this.data);
+ return this;
+ }
}
diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/CreateIndexRequest.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/CreateIndexRequest.java
index 076032b29..2d14f2dca 100644
--- a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/CreateIndexRequest.java
+++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/CreateIndexRequest.java
@@ -54,9 +54,10 @@ public class CreateIndexRequest extends BaseRequest {
return this;
}
- public void settings(JSONObject settings) {
+ public CreateIndexRequest settings(JSONObject settings) {
this.settings = settings;
this.setRequest();
+ return this;
}
public boolean hasMappings() {
diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/Delete7Request.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/Delete7Request.java
new file mode 100644
index 000000000..923bb772a
--- /dev/null
+++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/Delete7Request.java
@@ -0,0 +1,42 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : ccsdk features
+ * ================================================================================
+ * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
+ * 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=========================================================
+ *
+ */
+package org.onap.ccsdk.features.sdnr.wt.common.database.requests;
+
+/**
+ * @author Michael Dürre
+ *
+ */
+public class Delete7Request extends DeleteRequest {
+
+ public Delete7Request(String alias, String esId) {
+ super(alias, "_doc", esId);
+ }
+
+ public Delete7Request(String alias, String esId, boolean refresh) {
+ super(alias, "_doc", esId, refresh);
+ }
+
+ public Delete7Request(DeleteRequest request) {
+ this(request.getAlias(), request.getEsId(), request.doRefresh());
+ }
+
+}
diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/Get7Request.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/Get7Request.java
new file mode 100644
index 000000000..3996a6fe7
--- /dev/null
+++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/Get7Request.java
@@ -0,0 +1,41 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : ccsdk features
+ * ================================================================================
+ * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
+ * 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=========================================================
+ *
+ */
+package org.onap.ccsdk.features.sdnr.wt.common.database.requests;
+
+/**
+ * @author Michael Dürre
+ *
+ */
+public class Get7Request extends GetRequest {
+
+ public Get7Request(String alias, String esId) {
+ super(alias, "_doc", esId);
+ }
+
+ /**
+ * @param request
+ */
+ public Get7Request(GetRequest request) {
+ this(request.getAlias(), request.getEsId());
+ }
+
+}
diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/GetRequest.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/GetRequest.java
index 6092d88b0..0ad74581b 100644
--- a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/GetRequest.java
+++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/GetRequest.java
@@ -25,10 +25,20 @@ import javax.annotation.Nonnull;
public class GetRequest extends BaseRequest {
+ private final String alias;
+ private final String esId;
+
public GetRequest(String alias, String dataType, @Nonnull String esId) {
super("GET", String.format("/%s/%s/%s", alias, dataType, BaseRequest.urlEncodeValue(esId)));
+ this.alias = alias;
+ this.esId = esId;
}
+ protected String getAlias() {
+ return this.alias;
+ }
-
+ protected String getEsId() {
+ return this.esId;
+ }
}
diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/Index7Request.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/Index7Request.java
new file mode 100644
index 000000000..f399032d4
--- /dev/null
+++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/Index7Request.java
@@ -0,0 +1,50 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : ccsdk features
+ * ================================================================================
+ * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
+ * 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=========================================================
+ *
+ */
+package org.onap.ccsdk.features.sdnr.wt.common.database.requests;
+
+/**
+ * @author Michael Dürre
+ *
+ */
+public class Index7Request extends IndexRequest {
+
+ public Index7Request(String alias) {
+ super(alias, "_doc");
+ }
+
+ public Index7Request(String alias, String esId) {
+ super(alias, "_doc", esId);
+ }
+
+ public Index7Request(String alias, String esId, boolean refresh) {
+ super(alias, "_doc", esId, refresh);
+ }
+
+ /**
+ * @param request
+ */
+ public Index7Request(IndexRequest request) {
+ this(request.getAlias(), request.getEsId(), request.doRefresh());
+ this.setQuery(request.getQuery());
+ }
+
+}
diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/Search7Request.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/Search7Request.java
new file mode 100644
index 000000000..9c4424fde
--- /dev/null
+++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/Search7Request.java
@@ -0,0 +1,46 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : ccsdk features
+ * ================================================================================
+ * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
+ * 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=========================================================
+ *
+ */
+package org.onap.ccsdk.features.sdnr.wt.common.database.requests;
+
+/**
+ * @author Michael Dürre
+ *
+ */
+public class Search7Request extends SearchRequest {
+
+ /**
+ * @param alias
+ * @param dataType
+ */
+ public Search7Request(String alias) {
+ super(String.format("/%s/_search", alias));
+ }
+
+ /**
+ * @param request
+ */
+ public Search7Request(SearchRequest request) {
+ this(request.getAlias());
+ this.setQuery(request.getQuery());
+ }
+
+}
diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/SearchRequest.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/SearchRequest.java
index 113cb4e1e..f90889418 100644
--- a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/SearchRequest.java
+++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/SearchRequest.java
@@ -25,8 +25,16 @@ import org.onap.ccsdk.features.sdnr.wt.common.database.queries.QueryBuilder;
public class SearchRequest extends BaseRequest {
+ private final String alias;
+
+ public SearchRequest(String uri) {
+ super("POST", uri);
+ this.alias = null;
+ }
+
public SearchRequest(String alias, String dataType) {
super("POST", String.format("/%s/%s/_search", alias, dataType));
+ this.alias = alias;
}
@Override
@@ -34,4 +42,10 @@ public class SearchRequest extends BaseRequest {
super.setQuery(query);
}
+ public String getAlias() {
+ return this.alias;
+ }
+
+
+
}
diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/Update7Request.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/Update7Request.java
new file mode 100644
index 000000000..6cff93319
--- /dev/null
+++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/Update7Request.java
@@ -0,0 +1,40 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : ccsdk features
+ * ================================================================================
+ * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
+ * 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=========================================================
+ *
+ */
+package org.onap.ccsdk.features.sdnr.wt.common.database.requests;
+
+/**
+ * @author Michael Dürre
+ *
+ * https://github.com/elastic/elasticsearch/blob/7.1/rest-api-spec/src/main/resources/rest-api-spec/api/update.json
+ */
+public class Update7Request extends UpdateRequest {
+
+ public Update7Request(String alias, String esId, int retries, boolean refresh) {
+ super(String.format("/%s/_update/%s", alias, BaseRequest.urlEncodeValue(esId), retries), refresh);
+ }
+
+ public Update7Request(UpdateRequest request) {
+ this(request.getAlias(), request.getEsId(), request.getRetries(), request.doRefresh());
+ this.setQuery(request.getQuery());
+ }
+
+}
diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/UpdateByQuery7Request.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/UpdateByQuery7Request.java
new file mode 100644
index 000000000..14a45be6e
--- /dev/null
+++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/UpdateByQuery7Request.java
@@ -0,0 +1,39 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : ccsdk features
+ * ================================================================================
+ * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
+ * 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=========================================================
+ *
+ */
+package org.onap.ccsdk.features.sdnr.wt.common.database.requests;
+
+/**
+ * @author Michael Dürre
+ *
+ */
+public class UpdateByQuery7Request extends UpdateByQueryRequest {
+
+ public UpdateByQuery7Request(String alias, boolean refresh) {
+ super(alias, "_doc", refresh);
+ }
+
+ public UpdateByQuery7Request(UpdateByQueryRequest request) {
+ this(request.getAlias(), request.doRefresh());
+ this.setQuery(request.getQuery());
+ }
+
+}
diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/responses/BaseResponse.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/responses/BaseResponse.java
index 2746be4a4..27916459f 100644
--- a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/responses/BaseResponse.java
+++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/responses/BaseResponse.java
@@ -32,6 +32,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class BaseResponse {
+
private static final Logger LOG = LoggerFactory.getLogger(BaseResponse.class);
private final int responseCode;
@@ -45,14 +46,10 @@ public class BaseResponse {
}
public boolean isResponseSucceeded() {
- return this.responseCode < 300;
+ return this.responseCode < 300 && this.responseCode >= 200;
}
JSONObject getJson(Response response) {
- if (response == null) {
- LOG.warn("unable to parse response. response is null.");
- return null;
- }
try {
String sresponse = EntityUtils.toString(response.getEntity());
LOG.debug("parsing response={}", sresponse);
@@ -95,4 +92,6 @@ public class BaseResponse {
}
}
+
+
}
diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/responses/DeleteResponse.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/responses/DeleteResponse.java
index f6202d009..46ef1b9f8 100644
--- a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/responses/DeleteResponse.java
+++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/responses/DeleteResponse.java
@@ -35,8 +35,6 @@ public class DeleteResponse extends BaseResponse {
JSONObject o = this.getJson(response);
if (o != null) {
this.isDeleted = "deleted".equals(o.getString("result"));
- } else {
- this.isDeleted = false;
}
} else {
this.isDeleted = false;
diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/responses/SearchResponse.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/responses/SearchResponse.java
index 6a7ed0d06..88a14c6d1 100644
--- a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/responses/SearchResponse.java
+++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/responses/SearchResponse.java
@@ -45,7 +45,7 @@ public class SearchResponse extends BaseResponse {
private void handleResult(JSONObject result) {
if (result != null && this.isResponseSucceeded()) {
JSONObject hitsouter = result.getJSONObject("hits");
- this.total = hitsouter.getLong("total");
+ this.total = this.getTotalFromHits(hitsouter);
JSONArray a = hitsouter.getJSONArray("hits");
SearchHit[] hits = new SearchHit[a.length()];
for (int i = 0; i < a.length(); i++) {
@@ -84,4 +84,18 @@ public class SearchResponse extends BaseResponse {
}
return entries;
}
+
+ /**
+ * @param hits
+ * @return
+ */
+ private long getTotalFromHits(JSONObject hits) {
+ Object o = hits.get("total");
+ if (o instanceof Long || o instanceof Integer) {
+ return hits.getLong("total");
+ } else if (o instanceof JSONObject) {
+ return hits.getJSONObject("total").getLong("value");
+ }
+ return 0;
+ }
}
diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/responses/UpdateResponse.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/responses/UpdateResponse.java
index 80cb24872..2c9fee675 100644
--- a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/responses/UpdateResponse.java
+++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/responses/UpdateResponse.java
@@ -39,7 +39,7 @@ public class UpdateResponse extends BaseResponse {
super(response);
JSONObject o = this.getJson(response);
- this.result = o.getString("result");
+ this.result = o == null ? null : o.getString("result");
}
public boolean succeeded() {
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 fdba374c7..87a376538 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
@@ -72,7 +72,7 @@ public class BaseHTTPClient {
private static final int DEFAULT_HTTP_TIMEOUT_MS = 30000; // in ms
private final boolean trustAll;
- private final String baseUrl;
+ private String baseUrl;
private int timeout = DEFAULT_HTTP_TIMEOUT_MS;
private SSLContext sc = null;
@@ -99,7 +99,15 @@ public class BaseHTTPClient {
}
}
- protected @Nonnull BaseHTTPResponse sendRequest(String uri, String method, String body, Map<String, String> headers)
+ public void setBaseUrl(String base) {
+ if (!base.endsWith("/")) {
+ base += "/";
+ }
+ this.baseUrl = base;
+ }
+
+ @Nonnull
+ protected 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);
}
diff --git a/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestConfig.java b/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestConfig.java
index 415620415..cbe0b9c4d 100644
--- a/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestConfig.java
+++ b/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestConfig.java
@@ -21,16 +21,16 @@
*/
package org.onap.ccsdk.features.sdnr.wt.common.test;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.io.File;
import java.io.IOException;
-import java.lang.reflect.Field;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Files;
-import java.util.Collections;
-import java.util.Map;
import org.junit.After;
import org.junit.Before;
@@ -249,17 +249,4 @@ public class TestConfig {
section.parseLines();
assertTrue(section.getProperty(KEY).length() > " in ".length());
}
-
- public static void setEnv(String key, String value) {
- try {
- Map<String, String> env = System.getenv();
- Class<?> cl = env.getClass();
- Field field = cl.getDeclaredField("m");
- field.setAccessible(true);
- Map<String, String> writableEnv = (Map<String, String>) field.get(env);
- writableEnv.put(key, value);
- } catch (Exception e) {
- throw new IllegalStateException("Failed to set environment variable", e);
- }
- }
}
diff --git a/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestDbClient.java b/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestDbClient.java
index cf9d93052..421a2229c 100644
--- a/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestDbClient.java
+++ b/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestDbClient.java
@@ -21,10 +21,12 @@
*/
package org.onap.ccsdk.features.sdnr.wt.common.test;
-import static org.junit.Assert.*;
-
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.io.IOException;
-
import org.junit.BeforeClass;
import org.junit.Test;
import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient;
@@ -47,7 +49,7 @@ public class TestDbClient {
@BeforeClass
public static void init() throws Exception {
- dbClient = new HtDatabaseClient(hosts);
+ dbClient = HtDatabaseClient.getClient(hosts);
dbClient.waitForYellowStatus(20000);
}
diff --git a/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestDbRequests.java b/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestDbRequests.java
index 756d70c85..492dfa96e 100644
--- a/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestDbRequests.java
+++ b/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestDbRequests.java
@@ -21,6 +21,18 @@
*/
package org.onap.ccsdk.features.sdnr.wt.common.test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import java.io.IOException;
+import java.text.ParseException;
+import java.util.Arrays;
+import java.util.List;
+import org.json.JSONException;
+import org.json.JSONObject;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -57,20 +69,6 @@ import org.onap.ccsdk.features.sdnr.wt.common.database.responses.SearchResponse;
import org.onap.ccsdk.features.sdnr.wt.common.database.responses.UpdateByQueryResponse;
import org.onap.ccsdk.features.sdnr.wt.common.database.responses.UpdateResponse;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import java.io.IOException;
-import java.text.ParseException;
-import java.util.Arrays;
-import java.util.List;
-
-import org.json.JSONException;
-import org.json.JSONObject;
-
public class TestDbRequests {
private static HtDatabaseClient dbClient;
@@ -80,7 +78,7 @@ public class TestDbRequests {
@BeforeClass
public static void init() throws Exception {
- dbClient = new HtDatabaseClient(hosts);
+ dbClient = HtDatabaseClient.getClient(hosts);
}
@@ -200,7 +198,7 @@ public class TestDbRequests {
}
this.insert(IDX, ID, JSON);
// delete data
- DeleteRequest request2 = new DeleteRequest(IDX, IDX, ID);
+ DeleteRequest request2 = new DeleteRequest(IDX, dbClient.isVersion7() ? "_doc" : IDX, ID);
DeleteResponse response2 = null;
try {
response2 = dbClient.delete(request2);
@@ -215,7 +213,7 @@ public class TestDbRequests {
fail(e.getMessage());
}
// verify data deleted
- GetRequest request4 = new GetRequest(IDX, IDX, ID);
+ GetRequest request4 = new GetRequest(IDX, dbClient.isVersion7() ? "_doc" : IDX, ID);
GetResponse response4 = null;
try {
response4 = dbClient.get(request4);
@@ -233,8 +231,11 @@ public class TestDbRequests {
*/
private JSONObject defaultMappings(String idx, boolean useStrict) {
String mapping = "{}";
- return new JSONObject(String.format("{\"%s\":{%s\"properties\":%s}}", idx,
- useStrict ? "\"dynamic\": false," : "\"dynamic\": true,", mapping));
+ return dbClient.isVersion7()
+ ? new JSONObject(String.format("{%s\"properties\":%s}",
+ useStrict ? "\"dynamic\": false," : "\"dynamic\": true,", mapping))
+ : new JSONObject(String.format("{\"%s\":{%s\"properties\":%s}}", idx,
+ useStrict ? "\"dynamic\": false," : "\"dynamic\": true,", mapping));
}
@Test
@@ -325,7 +326,7 @@ public class TestDbRequests {
this.insert(IDX, ID, JSON);
this.insert(IDX, ID2, JSON2);
this.insert(IDX, ID3, JSON3);
- SearchRequest request = new SearchRequest(IDX, IDX);
+ SearchRequest request = new SearchRequest(IDX, dbClient.isVersion7() ? "_doc" : IDX);
request.setQuery(QueryBuilders.matchAllQuery());
SearchResponse response = null;
try {
@@ -336,7 +337,7 @@ public class TestDbRequests {
assertNotNull(response);
assertEquals("not all items found", 3, response.getHits().length);
assertEquals("incorrect index", IDX, response.getHits()[0].getIndex());
- assertEquals("incorrect type", IDX, response.getHits()[0].getType());
+ assertEquals("incorrect type", dbClient.isVersion7() ? "_doc" : IDX, response.getHits()[0].getType());
this.deleteIndex(IDX);
}
@@ -354,7 +355,7 @@ public class TestDbRequests {
fail("unable to create index");
}
this.insert(IDX, ID, JSON);
- UpdateRequest request = new UpdateRequest(IDX, IDX, ID);
+ UpdateRequest request = new UpdateRequest(IDX, dbClient.isVersion7() ? "_doc" : IDX, ID);
UpdateResponse response = null;
try {
request.source(new JSONObject(JSON2));
@@ -371,7 +372,7 @@ public class TestDbRequests {
fail(e.getMessage());
}
// verify update
- GetRequest request3 = new GetRequest(IDX, IDX, ID);
+ GetRequest request3 = new GetRequest(IDX, dbClient.isVersion7() ? "_doc" : IDX, ID);
GetResponse response3 = null;
try {
response3 = dbClient.get(request3);
@@ -397,7 +398,7 @@ public class TestDbRequests {
fail("unable to create index");
}
this.insert(IDX, ID, JSON);
- UpdateByQueryRequest request = new UpdateByQueryRequest(IDX, IDX);
+ UpdateByQueryRequest request = new UpdateByQueryRequest(IDX, dbClient.isVersion7() ? "_doc" : IDX);
UpdateByQueryResponse response = null;
try {
request.source(ID, new JSONObject(JSON2));
@@ -414,7 +415,7 @@ public class TestDbRequests {
fail(e.getMessage());
}
// verify update
- GetRequest request3 = new GetRequest(IDX, IDX, ID);
+ GetRequest request3 = new GetRequest(IDX, dbClient.isVersion7() ? "_doc" : IDX, ID);
GetResponse response3 = null;
try {
response3 = dbClient.get(request3);
@@ -434,9 +435,10 @@ public class TestDbRequests {
final String JSON3 = "{ \"node-id\":\"sim3\",\"severity\":\"minor\"}";
final String JSON4 = "{ \"node-id\":\"sim4\",\"severity\":\"warning\"}";
final String JSON5 = "{ \"node-id\":\"sim5\",\"severity\":\"major\"}";
- final String MAPPINGS = String.format("{\"" + IDX + "\":{\"properties\":%s}}",
- "{\"node-id\":{\"type\": \"keyword\"},\"severity\": {\"type\": \"keyword\"}}");
- // create index with mapping keyword
+ final String MAPPINGS =
+ String.format(dbClient.isVersion7() ? "{\"properties\":%s}" : "{\"" + IDX + "\":{\"properties\":%s}}",
+ "{\"node-id\":{\"type\": \"keyword\"},\"severity\": {\"type\": \"keyword\"}}");
+ //create index with mapping keyword
CreateIndexResponse iresponse = null;
try {
if (!dbClient.isExistsIndex(IDX)) {
@@ -449,6 +451,7 @@ public class TestDbRequests {
fail("unable to create index: " + e1.getMessage());
}
+
// fill index
this.insert(IDX, null, JSON);
this.insert(IDX, null, JSON2);
@@ -462,7 +465,7 @@ public class TestDbRequests {
fail(e.getMessage());
}
- SearchRequest request = new SearchRequest(IDX, IDX);
+ SearchRequest request = new SearchRequest(IDX, dbClient.isVersion7() ? "_doc" : IDX);
request.setQuery(QueryBuilders.matchAllQuery().aggregations("severity").size(0));
SearchResponse response = null;
try {
@@ -501,7 +504,7 @@ public class TestDbRequests {
System.out.println(stats.getNodeStatistics());
}
- // @Test
+ //@Test
public void testPreventAutoCreateIndex() {
final String IDX1 = "acidx1";
final String ID1 = "acid1";
@@ -511,7 +514,7 @@ public class TestDbRequests {
ClusterSettingsResponse settingsResponse = null;
String esId = null;
- // set setting to allow autocreate
+ //set setting to allow autocreate
try {
settingsResponse = dbClient.setupClusterSettings(new ClusterSettingsRequest(true));
} catch (IOException e) {
@@ -519,10 +522,10 @@ public class TestDbRequests {
}
assertNotNull(settingsResponse);
assertTrue(settingsResponse.isAcknowledged());
- // test if something new can be created
+ //test if something new can be created
esId = dbClient.doWriteRaw(IDX1, IDX1, ID1, OBJ);
assertEquals(ID1, esId);
- // set setting to deny autocreate
+ //set setting to deny autocreate
try {
settingsResponse = dbClient.setupClusterSettings(new ClusterSettingsRequest(false));
} catch (IOException e) {
@@ -530,10 +533,10 @@ public class TestDbRequests {
}
assertNotNull(settingsResponse);
assertTrue(settingsResponse.isAcknowledged());
- // test if something new cannot be created
+ //test if something new cannot be created
esId = dbClient.doWriteRaw(IDX2, IDX2, ID2, OBJ);
assertNull(esId);
- // set setting to allow autocreate
+ //set setting to allow autocreate
try {
settingsResponse = dbClient.setupClusterSettings(new ClusterSettingsRequest(true));
} catch (IOException e) {
@@ -560,4 +563,5 @@ public class TestDbRequests {
}
}
+
}
diff --git a/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestPortstatus.java b/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestPortstatus.java
index d073043c2..3ddbcebd0 100644
--- a/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestPortstatus.java
+++ b/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestPortstatus.java
@@ -1,19 +1,22 @@
/*
- * ============LICENSE_START========================================================================
- * ONAP : ccsdk feature sdnr wt
- * =================================================================================================
- * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. 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
+ * ============LICENSE_START=======================================================
+ * ONAP : ccsdk features
+ * ================================================================================
+ * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
+ * 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
+ * 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==========================================================================
+ * 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=========================================================
*/
package org.onap.ccsdk.features.sdnr.wt.common.test;
diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/ElasticSearchDataProvider.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/ElasticSearchDataProvider.java
index 08db03475..76d47e3e0 100644
--- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/ElasticSearchDataProvider.java
+++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/ElasticSearchDataProvider.java
@@ -23,14 +23,12 @@ package org.onap.ccsdk.features.sdnr.wt.dataprovider.data;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
-
import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient;
import org.onap.ccsdk.features.sdnr.wt.common.database.config.HostInfo;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.DataObjectAcessorPm.Intervall;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.HtDatabaseMaintenance;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.CreateMaintenanceInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.CreateMaintenanceInputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.CreateMaintenanceOutputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.CreateMediatorServerInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.CreateMediatorServerOutputBuilder;
@@ -110,7 +108,7 @@ public class ElasticSearchDataProvider /*extends BaseStatusProvider /* implement
super();
LOG.info("Start {}", this.getClass().getName());
- this.dbClient = new HtDatabaseClient(hosts, authUsername, authPassword, trustAllCerts);
+ this.dbClient = HtDatabaseClient.getClient(hosts, authUsername, authPassword, trustAllCerts);
this.mediatorserverRW = new DataObjectAcessor<>(dbClient, Entity.MediatorServer,
org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.mediator.server.list.output.Data.class);
this.mediatorserverRW.setWriteInterface(MediatorServerEntity.class);
diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/MediatorServerDataProvider.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/MediatorServerDataProvider.java
index 38e5b13e2..258104db4 100644
--- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/MediatorServerDataProvider.java
+++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/MediatorServerDataProvider.java
@@ -27,7 +27,6 @@ import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
-
import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient;
import org.onap.ccsdk.features.sdnr.wt.common.database.SearchResult;
import org.onap.ccsdk.features.sdnr.wt.common.database.config.HostInfo;
@@ -55,7 +54,7 @@ public class MediatorServerDataProvider implements AutoCloseable {
super();
LOG.info("Start {}", this.getClass().getName());
this.entries = new HashMap<>();
- this.dbClient = new HtDatabaseClient(hosts, authUsername, authPassword);
+ this.dbClient = HtDatabaseClient.getClient(hosts, authUsername, authPassword);
this.mediatorserverRW = new DataObjectAcessor<>(dbClient, Entity.MediatorServer, Data.class);
this.scheduler.scheduleAtFixedRate(onTick, this.REFRESH_INTERVAL, this.REFRESH_INTERVAL, TimeUnit.SECONDS);
}
@@ -80,7 +79,7 @@ public class MediatorServerDataProvider implements AutoCloseable {
}
/**
- *
+ *
* @param dbServerId
* @return url or null if not exists
*/
diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestCRUDforDatabase.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestCRUDforDatabase.java
index 0294c6e50..5cf2f0644 100644
--- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestCRUDforDatabase.java
+++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestCRUDforDatabase.java
@@ -21,14 +21,17 @@
*/
package org.onap.ccsdk.features.sdnr.wt.dataprovider.test;
-import static org.junit.Assert.*;
-
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.io.IOException;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;
-
import org.junit.BeforeClass;
import org.junit.Test;
import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient;
@@ -56,7 +59,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.pro
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.DeleteNetworkElementConnectionInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.DeleteNetworkElementConnectionInputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Entity;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.EntityInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Faultlog;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.FaultlogEntity;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.GranularityPeriodType;
@@ -112,7 +114,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.pro
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.UpdateNetworkElementConnectionInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.UpdateNetworkElementConnectionInputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.UpdateNetworkElementConnectionOutputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.entity.input.Filter;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.entity.input.FilterBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.entity.input.Pagination;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.entity.input.PaginationBuilder;
@@ -130,7 +131,7 @@ public class TestCRUDforDatabase {
dbProvider = new ElasticSearchDataProvider(hosts);
dbProvider.waitForYellowDatabaseStatus(30, TimeUnit.SECONDS);
- dbRawProvider = new HtDatabaseClient(hosts);
+ dbRawProvider = HtDatabaseClient.getClient(hosts);
}
public static void trySleep(long ms) {
diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestConfig.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestConfig.java
index c0234bfce..1275b0372 100644
--- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestConfig.java
+++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestConfig.java
@@ -21,12 +21,10 @@
*/
package org.onap.ccsdk.features.sdnr.wt.dataprovider.test;
-import static org.junit.Assert.*;
-
+import static org.junit.Assert.assertEquals;
import java.io.File;
import java.lang.reflect.Field;
import java.util.Map;
-
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -40,6 +38,7 @@ public class TestConfig {
private static final Logger LOG = LoggerFactory.getLogger(TestConfig.class);
private static final String TESTFILENAME = "testconfig.properties";
+ private static final String HOSTNAME = "localhost";
@After
@Before
@@ -53,18 +52,23 @@ public class TestConfig {
@Test
public void test() {
+ int databasePort = setSDNRDBURLEnv();
+
ConfigurationFileRepresentation configuration = new ConfigurationFileRepresentation(TESTFILENAME);
- setSDNRDBURLEnv();
EsConfig esConfig = new EsConfig(configuration);
LOG.info("Defaultconfiguration: {}", esConfig.toString());
assertEquals("http", esConfig.getHosts()[0].protocol.getValue());
- assertEquals(9200, esConfig.getHosts()[0].port);
- assertEquals("sdnrdb", esConfig.getHosts()[0].hostname);
+ assertEquals(databasePort, esConfig.getHosts()[0].port);
+ assertEquals(HOSTNAME, esConfig.getHosts()[0].hostname);
}
- public static void setSDNRDBURLEnv() {
- setEnv("SDNRDBURL", "http://sdnrdb:9200");
+ public static int setSDNRDBURLEnv() {
+ int databasePort = Integer
+ .valueOf(System.getProperty("databaseport") != null ? System.getProperty("databaseport") : "49200");
+ System.out.println("DB Port: " + databasePort);
+ setEnv("SDNRDBURL", "http://"+HOSTNAME+":"+databasePort);
+ return databasePort;
}
public static void setEnv(String key, String value) {
diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestDataMappings.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestDataMappings.java
index a4b284e4f..f63beee43 100644
--- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestDataMappings.java
+++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestDataMappings.java
@@ -22,122 +22,67 @@
package org.onap.ccsdk.features.sdnr.wt.dataprovider.test;
import java.io.IOException;
-import java.util.List;
import org.junit.Test;
-import org.onap.ccsdk.features.sdnr.wt.common.database.DatabaseClient;
-import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient;
-import org.onap.ccsdk.features.sdnr.wt.common.database.SearchHit;
-import org.onap.ccsdk.features.sdnr.wt.common.database.SearchResult;
-import org.onap.ccsdk.features.sdnr.wt.common.database.config.HostInfo;
-import org.onap.ccsdk.features.sdnr.wt.common.database.queries.QueryBuilder;
-import org.onap.ccsdk.features.sdnr.wt.common.database.responses.SearchResponse;
-import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.EsDataObjectReaderWriter;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.YangToolsMapper;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.pmdata._15m.list.output.Data;
-import org.opendaylight.yangtools.yang.binding.DataObject;
public class TestDataMappings {
- private static final HostInfo[] HOSTINFOS = new HostInfo[] {HostInfo.getDefault()};
- //public static final String ESDATATYPENAME = "faultcurrent";
-
- private static class HtDatabaseClientHelper extends HtDatabaseClient {
-
- private final String json;
-
- public HtDatabaseClientHelper(String jsonResponse, HostInfo[] hosts) {
- super(hosts);
- this.json = jsonResponse;
-
- }
-
- @Override
- public SearchResult<SearchHit> doReadByQueryJsonData(String dataTypeName, QueryBuilder qb) {
- return new SearchResult<>(new SearchResponse(this.json).getHits());
- }
- }
-
- private static class MapResult<T extends DataObject> {
- public final List<T> mappedData;
-
- public MapResult(String dataType, Class<T> cls, String dbJson) throws ClassNotFoundException {
- System.out.println(dbJson);
- DatabaseClient db = new HtDatabaseClientHelper(dbJson, HOSTINFOS);
- EsDataObjectReaderWriter<T> dbrw = new EsDataObjectReaderWriter<>(db, dataType, cls);
- this.mappedData = dbrw.doReadAll().getHits();
- }
- }
-
- private static final String SEARCHJSON_FORMAT = "{\n" + "\"took\": 0,\n" + "\"timed_out\": false,\n"
- + "\"_shards\": {\n" + "\"total\": 5,\n" + "\"successful\": 5,\n" + "\"skipped\": 0,\n" + "\"failed\": 0\n"
- + "},\n" + "\"hits\": {\n" + "\"total\": 1,\n" + "\"max_score\": 1,\n" + "\"hits\": [\n" + "{\n"
- + "\"_index\": \"%s\",\n" + "\"_type\": \"%s\",\n" + "\"_id\": \"%s\",\n" + "\"_score\": 1,\n"
- + "\"_source\": %s}\n" + "]\n" + "}\n" + "}";
-
- private static final String MEDIATORSERVER_DB_ID = "LumwSG0BFvcE3yf8MBM5";
- private static final String MEDIATOR_SERVERDB_JSON =
- "{\"url\":\"https://10.45.44.223:7590\",\"name\":\"test mediator server\"}";
-
- private static final String FAULTCURRENT_DB_ID = "LumwSG0BFvcE3yf8MBM5";
- private static final String FAULTCURRENT_DB_NODEID = "sim1";
- private static final int FAULTCURRENT_DB_COUNTER = 3;
- private static final String FAULTCURRENT_DB_OBJECTID = "LPS-MWT-01";
- private static final String FAULTCURRENT_DB_PROBLEM = "rlsExceeded";
- private static final String FAULTCURRENT_DB_SEVERITY = "critical";
- private static final DateAndTime FAULTCURRENT_DB_TIMESTAMP =
- DateAndTime.getDefaultInstance("2019-09-18T13:07:05.8Z");
-
- private static final String FAULTCURRENT_SERVERDB_JSON = "{\"node-id\":\"" + FAULTCURRENT_DB_NODEID + "\","
- + "\"counter\":" + FAULTCURRENT_DB_COUNTER + "," + "\"object-id\":\"" + FAULTCURRENT_DB_OBJECTID + "\","
- + "\"problem\":\"" + FAULTCURRENT_DB_PROBLEM + "\"," + "\"timestamp\":\""
- + FAULTCURRENT_DB_TIMESTAMP.getValue() + "\"," + "\"severity\":\"" + FAULTCURRENT_DB_SEVERITY + "\"" + "}";
-
-
- private static final String PMDATA15M_SERVERDB_JSON = "{\n" + "\"node-name\": \"sim2\",\n"
- + "\"uuid-interface\": \"LP-MWPS-TTP-01\",\n" + "\"layer-protocol-name\": \"MWPS\",\n"
- + "\"radio-signal-id\": \"Test11\",\n" + "\"time-stamp\": \"2017-07-04T14:00:00.0Z\",\n"
- + "\"granularity-period\": \"PERIOD_15MIN\",\n" + "\"scanner-id\": \"PM_RADIO_15M_9\",\n"
- + "\"performance-data\": {\n" + "\"es\": 0,\n" + "\"rx-level-avg\": -41,\n" + "\"time2-states\": -1,\n"
- + "\"time4-states-s\": 0,\n" + "\"time4-states\": 0,\n" + "\"time8-states\": 0,\n"
- + "\"time16-states-s\": -1,\n" + "\"time16-states\": 0,\n" + "\"time32-states\": 0,\n"
- + "\"time64-states\": 0,\n" + "\"time128-states\": 0,\n" + "\"time256-states\": 900,\n"
- + "\"time512-states\": -1,\n" + "\"time512-states-l\": -1,\n" + "\"time1024-states\": -1,\n"
- + "\"time1024-states-l\": -1,\n" + "\"time2048-states\": -1,\n" + "\"time2048-states-l\": -1,\n"
- + "\"time4096-states\": -1,\n" + "\"time4096-states-l\": -1,\n" + "\"time8192-states\": -1,\n"
- + "\"time8192-states-l\": -1,\n" + "\"snir-min\": -99,\n" + "\"snir-max\": -99,\n" + "\"snir-avg\": -99,\n"
- + "\"xpd-min\": -99,\n" + "\"xpd-max\": -99,\n" + "\"xpd-avg\": -99,\n" + "\"rf-temp-min\": -99,\n"
- + "\"rf-temp-max\": -99,\n" + "\"rf-temp-avg\": -99,\n" + "\"defect-blocks-sum\": -1,\n"
- + "\"time-period\": 900,\n" + "\"tx-level-min\": 25,\n" + "\"tx-level-max\": 25,\n"
- + "\"tx-level-avg\": 25,\n" + "\"rx-level-min\": -41,\n" + "\"rx-level-max\": -41,\n"
- + "\"unavailability\": 0,\n" + "\"ses\": 0,\n" + "\"cses\": 0\n" + "},\n"
- + "\"suspect-interval-flag\": false\n" + "}";
-
- //@Test
- // public void testMediatorServer() throws ClassNotFoundException {
- //
- // MapResult<EsMediatorServer> result = new MapResult<EsMediatorServer>(EsMediatorServer.ESDATATYPENAME,
- // EsMediatorServer.class,
- // getSearchJson(EsMediatorServer.ESDATATYPENAME,MEDIATORSERVER_DB_ID,MEDIATOR_SERVERDB_JSON));
- // assertEquals("test mediator server", result.mappedData.get(0).getName());
- // assertEquals("https://10.45.44.223:7590", result.mappedData.get(0).getUrl());
- // assertEquals(MEDIATORSERVER_DB_ID, result.mappedData.get(0).getId());
- //
- // }
- //@Test
- // public void testFaultCurrent() {
- //
- // MapResult<FaultcurrentEntity> result = new MapResult<FaultcurrentEntity>(ESDATATYPENAME, EsFaultCurrent.class,
- // getSearchJson(ESDATATYPENAME, FAULTCURRENT_DB_ID, FAULTCURRENT_SERVERDB_JSON));
- // assertEquals(FAULTCURRENT_DB_ID, result.mappedData.get(0).getId());
- // assertEquals(FAULTCURRENT_DB_NODEID, result.mappedData.get(0).getNodeId());
- // assertEquals(FAULTCURRENT_DB_COUNTER, result.mappedData.get(0).getCounter().intValue());
- // assertEquals(FAULTCURRENT_DB_OBJECTID, result.mappedData.get(0).getObjectId());
- // assertEquals(FAULTCURRENT_DB_PROBLEM, result.mappedData.get(0).getProblem());
- // assertEquals(FAULTCURRENT_DB_SEVERITY, result.mappedData.get(0).getSeverity());
- // assertEquals(FAULTCURRENT_DB_TIMESTAMP, result.mappedData.get(0).getTimestamp());
- // }
- //
+ // @formatter:off
+ private static final String PMDATA15M_SERVERDB_JSON = "{\n"
+ + "\"node-name\": \"sim2\",\n"
+ + "\"uuid-interface\": \"LP-MWPS-TTP-01\",\n"
+ + "\"layer-protocol-name\": \"MWPS\",\n"
+ + "\"radio-signal-id\": \"Test11\",\n"
+ + "\"time-stamp\": \"2017-07-04T14:00:00.0Z\",\n"
+ + "\"granularity-period\": \"PERIOD_15MIN\",\n"
+ + "\"scanner-id\": \"PM_RADIO_15M_9\",\n"
+ + "\"performance-data\": {\n"
+ + "\"es\": 0,\n"
+ + "\"rx-level-avg\": -41,\n"
+ + "\"time2-states\": -1,\n"
+ + "\"time4-states-s\": 0,\n"
+ + "\"time4-states\": 0,\n"
+ + "\"time8-states\": 0,\n"
+ + "\"time16-states-s\": -1,\n"
+ + "\"time16-states\": 0,\n"
+ + "\"time32-states\": 0,\n"
+ + "\"time64-states\": 0,\n"
+ + "\"time128-states\": 0,\n"
+ + "\"time256-states\": 900,\n"
+ + "\"time512-states\": -1,\n"
+ + "\"time512-states-l\": -1,\n"
+ + "\"time1024-states\": -1,\n"
+ + "\"time1024-states-l\": -1,\n"
+ + "\"time2048-states\": -1,\n"
+ + "\"time2048-states-l\": -1,\n"
+ + "\"time4096-states\": -1,\n"
+ + "\"time4096-states-l\": -1,\n"
+ + "\"time8192-states\": -1,\n"
+ + "\"time8192-states-l\": -1,\n"
+ + "\"snir-min\": -99,\n"
+ + "\"snir-max\": -99,\n"
+ + "\"snir-avg\": -99,\n"
+ + "\"xpd-min\": -99,\n"
+ + "\"xpd-max\": -99,\n"
+ + "\"xpd-avg\": -99,\n"
+ + "\"rf-temp-min\": -99,\n"
+ + "\"rf-temp-max\": -99,\n"
+ + "\"rf-temp-avg\": -99,\n"
+ + "\"defect-blocks-sum\": -1,\n"
+ + "\"time-period\": 900,\n"
+ + "\"tx-level-min\": 25,\n"
+ + "\"tx-level-max\": 25,\n"
+ + "\"tx-level-avg\": 25,\n"
+ + "\"rx-level-min\": -41,\n"
+ + "\"rx-level-max\": -41,\n"
+ + "\"unavailability\": 0,\n"
+ + "\"ses\": 0,\n"
+ + "\"cses\": 0\n"
+ + "},\n"
+ + "\"suspect-interval-flag\": false\n"
+ + "}";
+ // @formatter:on
@Test
public void testPmData15m() {
@@ -148,12 +93,6 @@ public class TestDataMappings {
} catch (IOException e) {
e.printStackTrace();
}
-
-
- }
-
- private String getSearchJson(String dataType, String dbId, String source) {
- return String.format(SEARCHJSON_FORMAT, dataType, dataType, dbId, source);
}
}
diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestEventService.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestEventService.java
index 308bbf663..6d54016cd 100644
--- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestEventService.java
+++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestEventService.java
@@ -24,22 +24,18 @@ package org.onap.ccsdk.features.sdnr.wt.dataprovider.test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
-
import java.io.IOException;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;
-
import org.junit.BeforeClass;
import org.junit.Test;
import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient;
import org.onap.ccsdk.features.sdnr.wt.common.database.SearchHit;
import org.onap.ccsdk.features.sdnr.wt.common.database.SearchResult;
-import org.onap.ccsdk.features.sdnr.wt.common.database.queries.QueryBuilder;
import org.onap.ccsdk.features.sdnr.wt.common.database.queries.QueryBuilders;
import org.onap.ccsdk.features.sdnr.wt.common.database.requests.DeleteByQueryRequest;
-import org.onap.ccsdk.features.sdnr.wt.common.database.requests.SearchRequest;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.ElasticSearchDataProvider;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.HtDatabaseEventsService;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.NetconfTimeStampImpl;
@@ -84,7 +80,7 @@ public class TestEventService {
dbProvider = new ElasticSearchDataProvider(TestCRUDforDatabase.hosts);
dbProvider.waitForYellowDatabaseStatus(30, TimeUnit.SECONDS);
- dbRawProvider = new HtDatabaseClient(TestCRUDforDatabase.hosts);
+ dbRawProvider = HtDatabaseClient.getClient(TestCRUDforDatabase.hosts);
try {
service = new HtDatabaseEventsService(dbRawProvider, dbProvider);
diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestMaintenanceServiceData.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestMaintenanceServiceData.java
index 6c22b0ea1..5839738e6 100644
--- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestMaintenanceServiceData.java
+++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestMaintenanceServiceData.java
@@ -21,12 +21,12 @@
*/
package org.onap.ccsdk.features.sdnr.wt.dataprovider.test;
-import static org.junit.Assert.*;
-
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.TimeUnit;
-
import org.junit.BeforeClass;
import org.junit.Test;
import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient;
@@ -55,7 +55,7 @@ public class TestMaintenanceServiceData {
dbProvider = new ElasticSearchDataProvider(TestCRUDforDatabase.hosts);
dbProvider.waitForYellowDatabaseStatus(30, TimeUnit.SECONDS);
- dbRawProvider = new HtDatabaseClient(TestCRUDforDatabase.hosts);
+ dbRawProvider = HtDatabaseClient.getClient(TestCRUDforDatabase.hosts);
service = dbProvider.getHtDatabaseMaintenance();
}
@@ -91,7 +91,7 @@ public class TestMaintenanceServiceData {
/**
* Delete
- *
+ *
* @param entity
*/
private static void clearDbEntity(Entity entity) {
diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestMediatorServerService.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestMediatorServerService.java
index edd0f9edb..83f8de89e 100644
--- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestMediatorServerService.java
+++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestMediatorServerService.java
@@ -24,10 +24,8 @@ package org.onap.ccsdk.features.sdnr.wt.dataprovider.test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
-
import java.io.IOException;
import java.util.concurrent.TimeUnit;
-
import org.junit.BeforeClass;
import org.junit.Test;
import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient;
@@ -35,7 +33,6 @@ import org.onap.ccsdk.features.sdnr.wt.common.database.queries.QueryBuilders;
import org.onap.ccsdk.features.sdnr.wt.common.database.requests.DeleteByQueryRequest;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.ElasticSearchDataProvider;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.MediatorServerDataProvider;
-import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.HtDatabaseMaintenance;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.CreateMediatorServerInputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.CreateMediatorServerOutputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Entity;
@@ -56,7 +53,7 @@ public class TestMediatorServerService {
dbProvider = new ElasticSearchDataProvider(TestCRUDforDatabase.hosts);
dbProvider.waitForYellowDatabaseStatus(30, TimeUnit.SECONDS);
- dbRawProvider = new HtDatabaseClient(TestCRUDforDatabase.hosts);
+ dbRawProvider = HtDatabaseClient.getClient(TestCRUDforDatabase.hosts);
service = new MediatorServerDataProvider(TestCRUDforDatabase.hosts);
diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangGenSalMapping.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangGenSalMapping.java
index 4a0834248..585f7dee2 100644
--- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangGenSalMapping.java
+++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangGenSalMapping.java
@@ -25,7 +25,6 @@ import java.io.IOException;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
-
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.json.JSONObject;
@@ -68,6 +67,13 @@ public class TestYangGenSalMapping {
// Create mapper for serialization and deserialization
YangToolsMapper mapper = new YangToolsMapper();
+ private static HostInfo[] getHostinfo() {
+ int databasePort = Integer
+ .valueOf(System.getProperty("databaseport") != null ? System.getProperty("databaseport") : "49200");
+ System.out.println("DB Port: " + databasePort);
+ return new HostInfo[] {new HostInfo("localhost", databasePort, Protocol.HTTP)};
+ }
+
@Test
public void test1() throws IOException {
@@ -80,10 +86,9 @@ public class TestYangGenSalMapping {
loginPasswordBuilder.setPassword("myTestPassword");
netconfNodeBuilder.setCredentials(loginPasswordBuilder.build());
- OdlHelloMessageCapabilitiesBuilder odlHelloMessageCapabilitiesBuilder =
- new OdlHelloMessageCapabilitiesBuilder();
+ OdlHelloMessageCapabilitiesBuilder odlHelloMessageCapabilitiesBuilder = new OdlHelloMessageCapabilitiesBuilder();
List<Uri> uriList = new ArrayList<>();
- uriList.add(new Uri("test.uri"));
+ uriList.add( new Uri("test.uri") );
odlHelloMessageCapabilitiesBuilder.setCapability(uriList);
netconfNodeBuilder.setOdlHelloMessageCapabilities(odlHelloMessageCapabilitiesBuilder.build());
@@ -99,7 +104,7 @@ public class TestYangGenSalMapping {
NetconfNode generatedNode = mapper.readValue(res.getBytes(), NetconfNode.class);
out(generatedNode.toString()); // Print it with specified indentation
// Compare result
- out("Equal? " + netconfNode.equals(generatedNode));
+ out("Equal? "+netconfNode.equals(generatedNode));
}
static class TestDataObjectBuilder implements Builder<TestDataObject> {
@@ -119,22 +124,20 @@ public class TestYangGenSalMapping {
}
@Test
- public void test2() throws ClassNotFoundException {
+ public void test2() throws Exception {
- int databasePort = Integer
- .valueOf(System.getProperty("databaseport") != null ? System.getProperty("databaseport") : "49200");
- System.out.println("DB Port: " + databasePort);
+ int databasePort = Integer.valueOf(System.getProperty("databaseport")!=null?System.getProperty("databaseport"):"49200");
+ System.out.println("DB Port: "+databasePort);
- HostInfo[] HOSTINFOS = new HostInfo[] {new HostInfo("localhost", databasePort, Protocol.HTTP)};
- DatabaseClient db = new HtDatabaseClient(HOSTINFOS);
+ HostInfo[] HOSTINFOS = new HostInfo[] { new HostInfo("localhost", databasePort ,Protocol.HTTP)};
+ DatabaseClient db = HtDatabaseClient.getClient(HOSTINFOS);
EsDataObjectReaderWriter<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.inventory.list.output.Data> dataRW =
- new EsDataObjectReaderWriter<>(db, "inventorytest",
- org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.inventory.list.output.Data.class);
+ new EsDataObjectReaderWriter<>(db, "inventorytest", org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.inventory.list.output.Data.class);
org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.inventory.list.output.Data d1;
d1 = getInventoryDataBuilder("MyDescription", 23L).build();
- String id = dataRW.write(d1, null);
+ String id = dataRW.write(d1,null);
org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.inventory.list.output.Data d2;
d2 = dataRW.read(id);
@@ -144,7 +147,7 @@ public class TestYangGenSalMapping {
}
@Test
- public void test3() throws IOException {
+ public void test3() throws IOException {
PerformanceDataBuilder performanceBuilder = new PerformanceDataBuilder();
performanceBuilder.setEs(99);
@@ -193,29 +196,59 @@ public class TestYangGenSalMapping {
@Test
public void test5() throws IOException {
- String jsonString = "{\n" + " \"time-stamp\": \"2017-03-01T06:45:00.0Z\",\n"
- + " \"node-name\": \"Sim2230\",\n" + " \"uuid-interface\": \"LP-MWPS-TTP-RADIO\",\n"
- + " \"scanner-id\": \"PM_RADIO_15M_14\",\n" + " \"layer-protocol-name\": \"MWPS\",\n"
- + " \"granularity-period\": \"Period15Min\",\n" + " \"radio-signal-id\": \"Test8\",\n"
- + " \"suspect-interval-flag\": false,\n" + " \"performance-data\": {\n"
- + " \"time4096-states-l\": -1,\n" + " \"time16-states-s\": -1,\n"
- + " \"tx-level-max\": 3,\n" + " \"snir-max\": -99,\n" + " \"time16-states\": 0,\n"
- + " \"time64-states\": 900,\n" + " \"unavailability\": 0,\n"
- + " \"time8192-states-l\": -1,\n" + " \"time512-states\": -1,\n"
- + " \"xpd-min\": -99,\n" + " \"xpd-avg\": -99,\n" + " \"tx-level-avg\": 3,\n"
- + " \"tx-level-min\": 3,\n" + " \"rf-temp-min\": -99,\n"
- + " \"rf-temp-avg\": -99,\n" + " \"snir-avg\": -99,\n" + " \"snir-min\": -99,\n"
- + " \"time-period\": 900,\n" + " \"time2-states\": 0,\n"
- + " \"time4-states\": 0,\n" + " \"time8-states\": -1,\n" + " \"ses\": 0,\n"
- + " \"time2048-states-l\": -1,\n" + " \"time2048-states\": -1,\n"
- + " \"xpd-max\": -99,\n" + " \"rf-temp-max\": -99,\n"
- + " \"time8192-states\": -1,\n" + " \"time128-states\": -1,\n"
- + " \"time256-states\": -1,\n" + " \"rx-level-min\": -44,\n"
- + " \"rx-level-avg\": -44,\n" + " \"time1024-states-l\": -1,\n" + " \"es\": 0,\n"
- + " \"cses\": 0,\n" + " \"time4-states-s\": 0,\n" + " \"time1024-states\": -1,\n"
- + " \"time512-states-l\": -1,\n" + " \"time4096-states\": -1,\n"
- + " \"rx-level-max\": -45,\n" + " \"defect-blocks-sum\": -1,\n"
- + " \"time32-states\": -1\n" + " }\n" + "}";
+ String jsonString = "{\n" +
+ " \"time-stamp\": \"2017-03-01T06:45:00.0Z\",\n" +
+ " \"node-name\": \"Sim2230\",\n" +
+ " \"uuid-interface\": \"LP-MWPS-TTP-RADIO\",\n" +
+ " \"scanner-id\": \"PM_RADIO_15M_14\",\n" +
+ " \"layer-protocol-name\": \"MWPS\",\n" +
+ " \"granularity-period\": \"Period15Min\",\n" +
+ " \"radio-signal-id\": \"Test8\",\n" +
+ " \"suspect-interval-flag\": false,\n" +
+ " \"performance-data\": {\n" +
+ " \"time4096-states-l\": -1,\n" +
+ " \"time16-states-s\": -1,\n" +
+ " \"tx-level-max\": 3,\n" +
+ " \"snir-max\": -99,\n" +
+ " \"time16-states\": 0,\n" +
+ " \"time64-states\": 900,\n" +
+ " \"unavailability\": 0,\n" +
+ " \"time8192-states-l\": -1,\n" +
+ " \"time512-states\": -1,\n" +
+ " \"xpd-min\": -99,\n" +
+ " \"xpd-avg\": -99,\n" +
+ " \"tx-level-avg\": 3,\n" +
+ " \"tx-level-min\": 3,\n" +
+ " \"rf-temp-min\": -99,\n" +
+ " \"rf-temp-avg\": -99,\n" +
+ " \"snir-avg\": -99,\n" +
+ " \"snir-min\": -99,\n" +
+ " \"time-period\": 900,\n" +
+ " \"time2-states\": 0,\n" +
+ " \"time4-states\": 0,\n" +
+ " \"time8-states\": -1,\n" +
+ " \"ses\": 0,\n" +
+ " \"time2048-states-l\": -1,\n" +
+ " \"time2048-states\": -1,\n" +
+ " \"xpd-max\": -99,\n" +
+ " \"rf-temp-max\": -99,\n" +
+ " \"time8192-states\": -1,\n" +
+ " \"time128-states\": -1,\n" +
+ " \"time256-states\": -1,\n" +
+ " \"rx-level-min\": -44,\n" +
+ " \"rx-level-avg\": -44,\n" +
+ " \"time1024-states-l\": -1,\n" +
+ " \"es\": 0,\n" +
+ " \"cses\": 0,\n" +
+ " \"time4-states-s\": 0,\n" +
+ " \"time1024-states\": -1,\n" +
+ " \"time512-states-l\": -1,\n" +
+ " \"time4096-states\": -1,\n" +
+ " \"rx-level-max\": -45,\n" +
+ " \"defect-blocks-sum\": -1,\n" +
+ " \"time32-states\": -1\n" +
+ " }\n" +
+ "}";
// Map to JSON String to Object
Data generatedNode = mapper.readValue(jsonString.getBytes(), Data.class);
@@ -225,14 +258,13 @@ public class TestYangGenSalMapping {
@Test
- public void test6() throws IOException, ClassNotFoundException {
+ public void test6() throws Exception {
out(method());
- HtDatabaseClient dbClient = new HtDatabaseClient(new HostInfo[] {new HostInfo("sdnrdb", 9200, Protocol.HTTP)});
+ HtDatabaseClient dbClient = HtDatabaseClient.getClient(getHostinfo());
String PMDATA15M_TYPE = "historicalperformance15min";
EsDataObjectReaderWriter<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.pmdata._15m.list.output.Data> pm15mRW =
- new EsDataObjectReaderWriter<>(dbClient, PMDATA15M_TYPE,
- org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.pmdata._15m.list.output.Data.class);
+ new EsDataObjectReaderWriter<>(dbClient, PMDATA15M_TYPE, org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.pmdata._15m.list.output.Data.class);
pm15mRW.setEsIdAttributeName("_nodeName");
ReadPmdata15mListInputBuilder inputBuilder = new ReadPmdata15mListInputBuilder();
@@ -251,36 +283,34 @@ public class TestYangGenSalMapping {
QueryBuilder query = fromFilter(input.getFilter()).from((page - 1) * pageSize).size(pageSize);
setSortOrder(query, input.getSortorder());
- SearchResult<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.pmdata._15m.list.output.Data> result =
- pm15mRW.doReadAll(query);
+ SearchResult<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.pmdata._15m.list.output.Data> result=pm15mRW.doReadAll(query);
- out("Found: " + result.getHits().size());
- int t = 0;
+ out("Found: "+result.getHits().size());
+ int t=0;
for (Data hit : result.getHits()) {
- out("Hit " + t++ + ":" + hit);
+ out("Hit "+t+++":"+hit);
}
setPagination(outputBuilder, page, pageSize, result.getTotal());
outputBuilder.setData(result.getHits());
}
@Test
- public void test7() throws IOException, ClassNotFoundException {
+ public void test7() throws Exception {
out(method());
String ESDATATYPE_MEDIATORSERVER = Entity.MediatorServer.getName();
- HtDatabaseClient dbClient = new HtDatabaseClient(new HostInfo[] {new HostInfo("sdnrdb", 9200, Protocol.HTTP)});
+ HtDatabaseClient dbClient = HtDatabaseClient.getClient(getHostinfo());
EsDataObjectReaderWriter<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.mediator.server.list.output.Data> mediatorserverRW;
mediatorserverRW = new EsDataObjectReaderWriter<>(dbClient, ESDATATYPE_MEDIATORSERVER,
org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.mediator.server.list.output.Data.class)
- .setWriteInterface(
- org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.MediatorServerEntity.class)
- .setEsIdAttributeName("_id");
+ .setWriteInterface(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.MediatorServerEntity.class)
+ .setEsIdAttributeName("_id");
CreateMediatorServerInputBuilder inputBuilder = new CreateMediatorServerInputBuilder();
inputBuilder.setName("Hans");
inputBuilder.setUrl("MyGreatUrl");
- String id = mediatorserverRW.write(inputBuilder.build(), "testid");
+ String id = mediatorserverRW.write(inputBuilder.build(),"testid");
System.out.println(id);
}
@@ -290,15 +320,15 @@ public class TestYangGenSalMapping {
out(method());
String input;
input = "id-dd-dd";
- System.out.println("Map " + input + " to " + YangToolsMapper.toCamelCaseAttributeName(input));
+ System.out.println("Map " + input + " to "+YangToolsMapper.toCamelCaseAttributeName(input));
input = "idDdGg";
- System.out.println("Map " + input + " to " + YangToolsMapper.toCamelCaseAttributeName(input));
+ System.out.println("Map " + input + " to "+YangToolsMapper.toCamelCaseAttributeName(input));
input = "_idDdGg";
- System.out.println("Map " + input + " to " + YangToolsMapper.toCamelCaseAttributeName(input));
+ System.out.println("Map " + input + " to "+YangToolsMapper.toCamelCaseAttributeName(input));
input = "--ff--gfg";
- System.out.println("Map " + input + " to " + YangToolsMapper.toCamelCaseAttributeName(input));
+ System.out.println("Map " + input + " to "+YangToolsMapper.toCamelCaseAttributeName(input));
input = "";
- System.out.println("Map " + input + " to " + YangToolsMapper.toCamelCaseAttributeName(input));
+ System.out.println("Map " + input + " to "+YangToolsMapper.toCamelCaseAttributeName(input));
}
/* ---------------------------------
@@ -309,8 +339,7 @@ public class TestYangGenSalMapping {
return nameofCurrMethod;
}
- private org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.inventory.list.output.DataBuilder getInventoryDataBuilder(
- String description, long treeLevel) {
+ private org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.inventory.list.output.DataBuilder getInventoryDataBuilder(String description, long treeLevel) {
org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.inventory.list.output.DataBuilder dataBuilder =
new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.inventory.list.output.DataBuilder();
dataBuilder.setDescription(description);
@@ -348,9 +377,10 @@ public class TestYangGenSalMapping {
if (filters == null || filters.size() == 0) {
return QueryBuilders.matchAllQuery();
- } else if (filters.size() == 1) {
+ } else if(filters.size()==1){
return QueryBuilders.matchQuery(filters.get(0).getProperty(), filters.get(0).getFiltervalue());
- } else {
+ }
+ else {
BoolQueryBuilder query = new BoolQueryBuilder();
for (Filter fi : filters) {
query.must(QueryBuilders.matchQuery((prefix != null ? prefix : "") + fi.getProperty(),
@@ -360,7 +390,6 @@ public class TestYangGenSalMapping {
}
}
-
private static QueryBuilder setSortOrder(QueryBuilder query, @Nullable List<Sortorder> sortorder) {
return setSortOrder(query, sortorder, "");
}
@@ -378,12 +407,9 @@ public class TestYangGenSalMapping {
}
- private static void setPagination(ReadPmdata15mListOutputBuilder outputBuilder, long page, long pageSize,
- long totalSize) {
- org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.pmdata._15m.list.output.Pagination value =
- new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.pmdata._15m.list.output.PaginationBuilder()
- .setPage(BigInteger.valueOf(page)).setSize(pageSize).setTotal(BigInteger.valueOf(totalSize))
- .build();
+ private static void setPagination(ReadPmdata15mListOutputBuilder outputBuilder, long page, long pageSize, long totalSize) {
+ org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.pmdata._15m.list.output.Pagination value = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.pmdata._15m.list.output.PaginationBuilder()
+ .setPage(BigInteger.valueOf(page)).setSize(pageSize).setTotal(BigInteger.valueOf(totalSize)).build();
outputBuilder.setPagination(value);
}
diff --git a/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/DataMigrationProviderImpl.java b/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/DataMigrationProviderImpl.java
index 821e3ec1e..dabe0047f 100644
--- a/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/DataMigrationProviderImpl.java
+++ b/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/DataMigrationProviderImpl.java
@@ -31,7 +31,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
-
import org.json.JSONObject;
import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient;
import org.onap.ccsdk.features.sdnr.wt.common.database.Portstatus;
@@ -53,8 +52,8 @@ import org.onap.ccsdk.features.sdnr.wt.common.database.responses.ListAliasesResp
import org.onap.ccsdk.features.sdnr.wt.common.database.responses.ListIndicesResponse;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.ComponentData;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.ComponentName;
-import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.DataMigrationReport;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.DataContainer;
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.DataMigrationReport;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.Release;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.SearchHitConverter;
import org.slf4j.Logger;
@@ -72,7 +71,11 @@ public class DataMigrationProviderImpl implements DataMigrationProviderService {
if (timeoutms > 0) {
Portstatus.waitSecondsTillAvailable(timeoutms / 1000, hosts);
}
- this.dbClient = new HtDatabaseClient(hosts, username, password, trustAll);
+ try {
+ this.dbClient = HtDatabaseClient.getClient(hosts, username, password, trustAll);
+ } catch (Exception e) {
+ throw new IllegalArgumentException("Can not reach database with parameters.",e);
+ }
}
@Override