aboutsummaryrefslogtreecommitdiffstats
path: root/sdnr/wt/common/src/main/java
diff options
context:
space:
mode:
authorMichael Dürre <michael.duerre@highstreet-technologies.com>2020-02-26 06:41:50 +0100
committerKAPIL SINGAL <ks220y@att.com>2020-02-27 14:52:20 +0000
commitee75b19ee79f49b28a3137b6dcfdf02d6120f3de (patch)
tree49a6a7b10578ee5f9780ea38f8a9408cf4cf14c7 /sdnr/wt/common/src/main/java
parent8f762f215f49fd4b1d498adc2cc4f98093f0ddf3 (diff)
add data migration tool
add tool for data migration and initialization Issue-ID: SDNC-1085 Signed-off-by: Michael Dürre <michael.duerre@highstreet-technologies.com> Change-Id: Ibd1ffeffa95d2897ae65f7d964e98941d810ffcb Signed-off-by: Michael Dürre <michael.duerre@highstreet-technologies.com>
Diffstat (limited to 'sdnr/wt/common/src/main/java')
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/DatabaseClient.java10
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/ExtRestClient.java507
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/HtDatabaseClient.java31
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/AliasesEntry.java34
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/AliasesEntryList.java46
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/IndicesEntry.java80
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/IndicesEntryList.java49
7 files changed, 433 insertions, 324 deletions
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 63e265bd1..59579c856 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
@@ -167,6 +167,16 @@ public interface DatabaseClient {
*/
SearchResult<SearchHit> doReadAllJsonData(String dataTypeName, boolean ignoreException);
+ /**
+ * @param alias
+ * @param dataTypeName
+ * @param queryBuilder
+ * @param ignoreException
+ * @return
+ */
+ SearchResult<SearchHit> doReadByQueryJsonData(String alias, String dataTypeName, QueryBuilder queryBuilder,
+ boolean ignoreException);
+
}
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 5ef326f41..a64b56bef 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
@@ -18,18 +18,28 @@
package org.onap.ccsdk.features.sdnr.wt.common.database;
import java.io.IOException;
+import java.security.KeyManagementException;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.UnrecoverableKeyException;
+import java.security.cert.CertificateException;
+import java.security.spec.InvalidKeySpecException;
import java.text.ParseException;
+import javax.net.ssl.SSLContext;
+
import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
+import org.apache.http.client.config.RequestConfig.Builder;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.nio.client.HttpAsyncClientBuilder;
import org.elasticsearch.client.Response;
import org.elasticsearch.client.ResponseException;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder.HttpClientConfigCallback;
+import org.elasticsearch.client.RestClientBuilder.RequestConfigCallback;
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;
@@ -70,252 +80,275 @@ import org.onap.ccsdk.features.sdnr.wt.common.database.responses.RefreshIndexRes
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ExtRestClient {
- private static final Logger LOG = LoggerFactory.getLogger(ExtRestClient.class);
-
- private class BasicAuthHttpClientConfigCallback implements HttpClientConfigCallback {
-
- private final String basicAuthUsername;
- private final String basicAuthPassword;
-
- BasicAuthHttpClientConfigCallback(String username, String password) {
- this.basicAuthUsername = username;
- this.basicAuthPassword = password;
- }
-
- @Override
- public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
- if (basicAuthPassword == null || basicAuthUsername == null) {
- return httpClientBuilder;
- }
- final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
- credentialsProvider.setCredentials(AuthScope.ANY,
- new UsernamePasswordCredentials(basicAuthUsername, basicAuthPassword));
-
- return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
- }
-
- }
-// private class SSLCercAuthHttpClientConfigCallback implements HttpClientConfigCallback {
-//
-// private final String certFilename;
-//
-// SSLCercAuthHttpClientConfigCallback(String certfile) {
-// this.certFilename = certfile;
-// }
-//
-// @Override
-// public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
-// if (this.certFilename == null) {
-// return httpClientBuilder;
-// }
-//
-// char[] keystorePass = "MY PASSWORD".toCharArray();
-//
-// FileInputStream fis = null;
-//
-// // Loading KEYSTORE in JKS format
-// KeyStore keyStorePci = null;
-// try {
-// keyStorePci = KeyStore.getInstance(KeyStore.getDefaultType());
-// } catch (KeyStoreException e1) {
-// LOG.warn("unable to load keystore: {}",e1);
-// }
-// if (keyStorePci != null) {
-// try {
-// fis = new FileInputStream(this.certFilename);
-// keyStorePci.load(fis, keystorePass);
-// } catch (Exception e) {
-// LOG.error("Error loading keystore: " + this.certFilename);
-// } finally {
-// if (fis != null) {
-// try {
-// fis.close();
-// } catch (IOException e) {
-//
-// }
-// }
-// }
-// }
-// SSLContext sslcontext=null;
-// try {
-// sslcontext = SSLContexts.custom().loadKeyMaterial(keyStorePci, keystorePass).build();
-// } catch (KeyManagementException | UnrecoverableKeyException | NoSuchAlgorithmException
-// | KeyStoreException e) {
-// LOG.warn("unable to load sslcontext: {}",e);
-// }
-// return httpClientBuilder.setSSLContext(sslcontext);
-// }
-// }
-
- private final RestClient client;
-
- protected ExtRestClient(HostInfo[] hosts) {
- this(hosts, null, null);
- }
- protected ExtRestClient(HostInfo[] hosts,String username,String password) {
- this.client = RestClient.builder(get(hosts)).setHttpClientConfigCallback(new BasicAuthHttpClientConfigCallback(username, password) ).build();
- }
-
- public ClusterHealthResponse health(ClusterHealthRequest request)
- throws UnsupportedOperationException, IOException, JSONException {
- return new ClusterHealthResponse(this.client.performRequest(request.getInner()));
- }
-
- public void close() throws IOException {
- this.client.close();
-
- }
- //
- public boolean indicesExists(GetIndexRequest request) throws IOException {
- Response response = this.client.performRequest(request.getInner());
- return response.getStatusLine().getStatusCode()==200;
- }
-
- public AcknowledgedResponse updateAliases(IndicesAliasesRequest request) throws IOException{
- return new AcknowledgedResponse(this.client.performRequest(request.getInner()));
- }
-
- public CreateIndexResponse createIndex(CreateIndexRequest request) throws IOException {
- return new CreateIndexResponse(this.client.performRequest(request.getInner()));
- }
- public CreateAliasResponse createAlias(CreateAliasRequest request) throws IOException {
+ private static final Logger LOG = LoggerFactory.getLogger(ExtRestClient.class);
+
+ private class BasicAuthHttpClientConfigCallback implements HttpClientConfigCallback {
+
+ private final String basicAuthUsername;
+ private final String basicAuthPassword;
+ private final boolean trustAll;
+
+ BasicAuthHttpClientConfigCallback(String username, String password, boolean trustAll) {
+ this.basicAuthUsername = username;
+ this.basicAuthPassword = password;
+ this.trustAll = trustAll;
+ }
+
+ @Override
+ public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
+ HttpAsyncClientBuilder httpAsyncClientBuilder = null;
+ try {
+ httpAsyncClientBuilder = httpClientBuilder.setSSLContext(BaseHTTPClient.setupSsl(this.trustAll));
+ } catch (NoSuchAlgorithmException | KeyManagementException | UnrecoverableKeyException | CertificateException | KeyStoreException | InvalidKeySpecException | IOException e) {
+ LOG.warn("unable to init ssl context for db client: {}",e.getMessage());
+ }
+ if (basicAuthPassword == null || basicAuthUsername == null) {
+ return httpAsyncClientBuilder;
+ }
+ final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
+ credentialsProvider.setCredentials(AuthScope.ANY,
+ new UsernamePasswordCredentials(basicAuthUsername, basicAuthPassword));
+
+ return httpAsyncClientBuilder == null ? httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider)
+ : httpAsyncClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
+ }
+
+ }
+ // private class SSLCercAuthHttpClientConfigCallback implements HttpClientConfigCallback {
+ //
+ // private final String certFilename;
+ //
+ // SSLCercAuthHttpClientConfigCallback(String certfile) {
+ // this.certFilename = certfile;
+ // }
+ //
+ // @Override
+ // public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
+ // if (this.certFilename == null) {
+ // return httpClientBuilder;
+ // }
+ //
+ // char[] keystorePass = "MY PASSWORD".toCharArray();
+ //
+ // FileInputStream fis = null;
+ //
+ // // Loading KEYSTORE in JKS format
+ // KeyStore keyStorePci = null;
+ // try {
+ // keyStorePci = KeyStore.getInstance(KeyStore.getDefaultType());
+ // } catch (KeyStoreException e1) {
+ // LOG.warn("unable to load keystore: {}",e1);
+ // }
+ // if (keyStorePci != null) {
+ // try {
+ // fis = new FileInputStream(this.certFilename);
+ // keyStorePci.load(fis, keystorePass);
+ // } catch (Exception e) {
+ // LOG.error("Error loading keystore: " + this.certFilename);
+ // } finally {
+ // if (fis != null) {
+ // try {
+ // fis.close();
+ // } catch (IOException e) {
+ //
+ // }
+ // }
+ // }
+ // }
+ // SSLContext sslcontext=null;
+ // try {
+ // sslcontext = SSLContexts.custom().loadKeyMaterial(keyStorePci, keystorePass).build();
+ // } catch (KeyManagementException | UnrecoverableKeyException | NoSuchAlgorithmException
+ // | KeyStoreException e) {
+ // LOG.warn("unable to load sslcontext: {}",e);
+ // }
+ // return httpClientBuilder.setSSLContext(sslcontext);
+ // }
+ // }
+
+ private final RestClient client;
+
+ protected ExtRestClient(HostInfo[] hosts) {
+ this(hosts, null, null,false);
+ }
+
+ protected ExtRestClient(HostInfo[] hosts, String username, String password, boolean trustAll) {
+ this.client = RestClient.builder(get(hosts))
+ .setHttpClientConfigCallback(new BasicAuthHttpClientConfigCallback(username, password,trustAll))
+ .build();
+ }
+
+ public ClusterHealthResponse health(ClusterHealthRequest request)
+ throws UnsupportedOperationException, IOException, JSONException {
+ return new ClusterHealthResponse(this.client.performRequest(request.getInner()));
+ }
+
+ public void close() throws IOException {
+ this.client.close();
+
+ }
+
+ //
+ public boolean indicesExists(GetIndexRequest request) throws IOException {
+ Response response = this.client.performRequest(request.getInner());
+ return response.getStatusLine().getStatusCode() == 200;
+ }
+
+ public AcknowledgedResponse updateAliases(IndicesAliasesRequest request) throws IOException {
+ return new AcknowledgedResponse(this.client.performRequest(request.getInner()));
+ }
+
+ public CreateIndexResponse createIndex(CreateIndexRequest request) throws IOException {
+ return new CreateIndexResponse(this.client.performRequest(request.getInner()));
+ }
+
+ public CreateAliasResponse createAlias(CreateAliasRequest request) throws IOException {
return new CreateAliasResponse(this.client.performRequest(request.getInner()));
}
- public DeleteAliasResponse deleteAlias(DeleteAliasRequest request) throws IOException {
+
+ public DeleteAliasResponse deleteAlias(DeleteAliasRequest request) throws IOException {
return new DeleteAliasResponse(this.client.performRequest(request.getInner()));
}
- public DeleteIndexResponse deleteIndex(DeleteIndexRequest request) throws IOException {
- return new DeleteIndexResponse(this.client.performRequest(request.getInner()));
- }
- public IndexResponse index(IndexRequest request) throws IOException{
- return new IndexResponse(this.client.performRequest(request.getInner()));
- }
-
- public DeleteResponse delete(DeleteRequest request) throws IOException{
- Response response=null;
- try {
- response = this.client.performRequest(request.getInner());
- }
- catch(ResponseException e) {
- new DeleteResponse(e.getResponse());
- }
- return new DeleteResponse(response);
- }
- public DeleteByQueryResponse deleteByQuery(DeleteByQueryRequest request) throws IOException {
- Response response=null;
- try {
- response = this.client.performRequest(request.getInner());
- }
- catch(ResponseException e) {
- new DeleteResponse(e.getResponse());
- }
- return new DeleteByQueryResponse(response);
- }
- public SearchResponse search(SearchRequest request) throws IOException{
- return this.search(request,false);
- }
-
- /**
- * Search for database entries
- * @param request inputRequest
- * @param ignoreParseException especially for usercreated filters which may cause ES server response exceptions
- * @return Response with related entries
- * @throws IOException of client
- */
- public SearchResponse search(SearchRequest request, boolean ignoreParseException) throws IOException {
- if (ignoreParseException) {
- try {
- return new SearchResponse(this.client.performRequest(request.getInner()));
- } catch (ResponseException e) {
- LOG.debug("ignoring Exception for request {}: {}",request,e.getMessage());
- return new SearchResponse(e.getResponse());
- }
- } else {
- return new SearchResponse(this.client.performRequest(request.getInner()));
- }
- }
-
- public GetResponse get(GetRequest request) throws IOException{
- try {
- return new GetResponse(this.client.performRequest(request.getInner()));
- }
- catch (ResponseException e) {
- return new GetResponse(e.getResponse());
- }
- }
-
-
- public UpdateByQueryResponse update(UpdateByQueryRequest request) throws IOException {
- return new UpdateByQueryResponse(this.client.performRequest(request.getInner()));
-
- }
- public UpdateResponse update(UpdateRequest request) throws IOException {
- return new UpdateResponse(this.client.performRequest(request.getInner()));
-
- }
- public RefreshIndexResponse refreshIndex(RefreshIndexRequest request) throws IOException{
- return new RefreshIndexResponse(this.client.performRequest(request.getInner()));
- }
-
- public NodeStatsResponse stats(NodeStatsRequest request) throws IOException{
- return new NodeStatsResponse(this.client.performRequest(request.getInner()));
- }
- public ListIndicesResponse getIndices() throws ParseException, IOException {
- return new ListIndicesResponse(this.client.performRequest(new ListIndicesRequest().getInner()));
- }
- public ListAliasesResponse getAliases() throws ParseException, IOException {
- return new ListAliasesResponse(this.client.performRequest(new ListAliasesRequest().getInner()));
- }
- public GetInfoResponse getInfo() throws IOException, Exception {
- return new GetInfoResponse(this.client.performRequest(new GetInfoRequest().getInner()));
- }
- public boolean waitForYellowStatus(long timeoutms) {
-
- ClusterHealthRequest request = new ClusterHealthRequest();
- request.timeout(timeoutms/1000);
- ClusterHealthResponse response = null;
- String status="";
- try {
- response = this.health(request);
-
- } catch (UnsupportedOperationException | IOException | JSONException e) {
- LOG.error(e.getMessage());
- }
- if(response!=null) {
- status=response.getStatus();
- LOG.debug("Elasticsearch service started with status {}", response.getStatus());
-
- }
- else {
- LOG.warn("Elasticsearch service not started yet with status {}. current status is {}",status,"none");
- return false;
- }
- return response.isStatusMinimal(ClusterHealthResponse.HEALTHSTATUS_YELLOW);
-
- }
-
- private static HttpHost[] get(HostInfo[] hosts) {
- HttpHost[] httphosts = new HttpHost[hosts.length];
- for(int i=0;i<hosts.length;i++) {
- httphosts[i]=new HttpHost(hosts[i].hostname, hosts[i].port, hosts[i].protocol.toString());
- }
- return httphosts;
- }
- public static ExtRestClient createInstance(HostInfo[] hosts) {
- return new ExtRestClient(hosts);
- }
- public static ExtRestClient createInstance(HostInfo[] hosts,String username,String password) {
- return new ExtRestClient(hosts,username,password);
- }
- public static ExtRestClient createInstance(String hostname, int port, Protocol protocol){
- return createInstance(new HostInfo[] {new HostInfo(hostname,port,protocol)});
-
- }
+ public DeleteIndexResponse deleteIndex(DeleteIndexRequest request) throws IOException {
+ return new DeleteIndexResponse(this.client.performRequest(request.getInner()));
+ }
+
+ public IndexResponse index(IndexRequest request) throws IOException {
+ return new IndexResponse(this.client.performRequest(request.getInner()));
+ }
+
+ public DeleteResponse delete(DeleteRequest request) throws IOException {
+ Response response = null;
+ try {
+ response = this.client.performRequest(request.getInner());
+ } catch (ResponseException e) {
+ new DeleteResponse(e.getResponse());
+ }
+ return new DeleteResponse(response);
+ }
+
+ public DeleteByQueryResponse deleteByQuery(DeleteByQueryRequest request) throws IOException {
+ Response response = null;
+ try {
+ response = this.client.performRequest(request.getInner());
+ } catch (ResponseException e) {
+ new DeleteResponse(e.getResponse());
+ }
+ return new DeleteByQueryResponse(response);
+ }
+
+ public SearchResponse search(SearchRequest request) throws IOException {
+ return this.search(request, false);
+ }
+
+ /**
+ * Search for database entries
+ * @param request inputRequest
+ * @param ignoreParseException especially for usercreated filters which may cause ES server response exceptions
+ * @return Response with related entries
+ * @throws IOException of client
+ */
+ public SearchResponse search(SearchRequest request, boolean ignoreParseException) throws IOException {
+ if (ignoreParseException) {
+ try {
+ return new SearchResponse(this.client.performRequest(request.getInner()));
+ } catch (ResponseException e) {
+ LOG.debug("ignoring Exception for request {}: {}", request, e.getMessage());
+ return new SearchResponse(e.getResponse());
+ }
+ } else {
+ return new SearchResponse(this.client.performRequest(request.getInner()));
+ }
+ }
+
+ public GetResponse get(GetRequest request) throws IOException {
+ try {
+ return new GetResponse(this.client.performRequest(request.getInner()));
+ } catch (ResponseException e) {
+ return new GetResponse(e.getResponse());
+ }
+ }
+
+ public UpdateByQueryResponse update(UpdateByQueryRequest request) throws IOException {
+ return new UpdateByQueryResponse(this.client.performRequest(request.getInner()));
+
+ }
+
+ public UpdateResponse update(UpdateRequest request) throws IOException {
+ return new UpdateResponse(this.client.performRequest(request.getInner()));
+
+ }
+
+ public RefreshIndexResponse refreshIndex(RefreshIndexRequest request) throws IOException {
+ return new RefreshIndexResponse(this.client.performRequest(request.getInner()));
+ }
+
+ public NodeStatsResponse stats(NodeStatsRequest request) throws IOException {
+ return new NodeStatsResponse(this.client.performRequest(request.getInner()));
+ }
+
+ public ListIndicesResponse getIndices() throws ParseException, IOException {
+ return new ListIndicesResponse(this.client.performRequest(new ListIndicesRequest().getInner()));
+ }
+
+ public ListAliasesResponse getAliases() throws ParseException, IOException {
+ return new ListAliasesResponse(this.client.performRequest(new ListAliasesRequest().getInner()));
+ }
+
+ public GetInfoResponse getInfo() throws IOException, Exception {
+ return new GetInfoResponse(this.client.performRequest(new GetInfoRequest().getInner()));
+ }
+
+ public boolean waitForYellowStatus(long timeoutms) {
+
+ ClusterHealthRequest request = new ClusterHealthRequest();
+ request.timeout(timeoutms / 1000);
+ ClusterHealthResponse response = null;
+ String status = "";
+ try {
+ response = this.health(request);
+
+ } catch (UnsupportedOperationException | IOException | JSONException e) {
+ LOG.error(e.getMessage());
+ }
+ if (response != null) {
+ status = response.getStatus();
+ LOG.debug("Elasticsearch service started with status {}", response.getStatus());
+
+ } else {
+ LOG.warn("Elasticsearch service not started yet with status {}. current status is {}", status, "none");
+ return false;
+ }
+ return response.isStatusMinimal(ClusterHealthResponse.HEALTHSTATUS_YELLOW);
+
+ }
+
+ private static HttpHost[] get(HostInfo[] hosts) {
+ HttpHost[] httphosts = new HttpHost[hosts.length];
+ for (int i = 0; i < hosts.length; i++) {
+ httphosts[i] = new HttpHost(hosts[i].hostname, hosts[i].port, hosts[i].protocol.toString());
+ }
+ return httphosts;
+ }
+
+ public static ExtRestClient createInstance(HostInfo[] hosts) {
+ return new ExtRestClient(hosts);
+ }
+
+ public static ExtRestClient createInstance(HostInfo[] hosts, String username, String password,boolean trustAll) {
+ return new ExtRestClient(hosts, username, password, trustAll);
+ }
+
+ public static ExtRestClient createInstance(String hostname, int port, Protocol protocol) {
+ 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 d64f7cc01..0ec8b1fa7 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
@@ -26,7 +26,6 @@ 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;
import org.onap.ccsdk.features.sdnr.wt.common.database.queries.QueryBuilders;
-import org.onap.ccsdk.features.sdnr.wt.common.database.requests.CreateAliasRequest;
import org.onap.ccsdk.features.sdnr.wt.common.database.requests.DeleteByQueryRequest;
import org.onap.ccsdk.features.sdnr.wt.common.database.requests.DeleteRequest;
import org.onap.ccsdk.features.sdnr.wt.common.database.requests.GetIndexRequest;
@@ -36,7 +35,6 @@ import org.onap.ccsdk.features.sdnr.wt.common.database.requests.RefreshIndexRequ
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;
-import org.onap.ccsdk.features.sdnr.wt.common.database.responses.CreateIndexResponse;
import org.onap.ccsdk.features.sdnr.wt.common.database.responses.DeleteByQueryResponse;
import org.onap.ccsdk.features.sdnr.wt.common.database.responses.DeleteResponse;
import org.onap.ccsdk.features.sdnr.wt.common.database.responses.GetResponse;
@@ -58,6 +56,7 @@ 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;
private final Logger LOG = LoggerFactory.getLogger(HtDatabaseClient.class);
@@ -66,13 +65,16 @@ public class HtDatabaseClient extends ExtRestClient implements DatabaseClient, A
this(hosts,REFRESH_AFTER_REWRITE_DEFAULT);
}
public HtDatabaseClient(HostInfo[] hosts, boolean refreshAfterWrite) {
- this(hosts,refreshAfterWrite,null,null);
+ this(hosts,refreshAfterWrite,null,null,TRUSTALL_DEFAULT);
}
public HtDatabaseClient(HostInfo[] hosts,String username,String password) {
- this(hosts,REFRESH_AFTER_REWRITE_DEFAULT,username,password);
+ this(hosts,username,password,TRUSTALL_DEFAULT);
+ }
+ public HtDatabaseClient(HostInfo[] hosts,String username,String password, boolean trustAll) {
+ this(hosts,REFRESH_AFTER_REWRITE_DEFAULT,username,password,trustAll);
}
- public HtDatabaseClient(HostInfo[] hosts, boolean refreshAfterWrite,String username,String password) {
- super(hosts,username,password);
+ public HtDatabaseClient(HostInfo[] hosts, boolean refreshAfterWrite,String username,String password, boolean trustAll) {
+ super(hosts,username,password,trustAll);
this.doRefreshAfterWrite = refreshAfterWrite;
}
@@ -203,14 +205,17 @@ public class HtDatabaseClient extends ExtRestClient implements DatabaseClient, A
return this.doReadByQueryJsonData(dataTypeName, queryBuilder, false);
}
-
@Override
- public @Nonnull SearchResult<SearchHit> doReadByQueryJsonData(String dataTypeName,QueryBuilder queryBuilder, boolean ignoreException) {
+ public @Nonnull SearchResult<SearchHit> doReadByQueryJsonData( String dataTypeName,QueryBuilder queryBuilder, boolean ignoreException) {
+ return this.doReadByQueryJsonData(dataTypeName, dataTypeName,queryBuilder,ignoreException);
+ }
+ @Override
+ public @Nonnull SearchResult<SearchHit> doReadByQueryJsonData(String alias, String dataTypeName,QueryBuilder queryBuilder, boolean ignoreException) {
long total = 0;
LOG.debug("NetworkIndex query and read: {}", dataTypeName);
- SearchRequest searchRequest = new SearchRequest(dataTypeName, dataTypeName);
+ SearchRequest searchRequest = new SearchRequest(alias, dataTypeName);
searchRequest.setQuery(queryBuilder);
SearchResponse response = null;
try {
@@ -228,11 +233,12 @@ public class HtDatabaseClient extends ExtRestClient implements DatabaseClient, A
}
@Override
public @Nonnull SearchResult<SearchHit> doReadAllJsonData( String dataTypeName, boolean ignoreException) {
- // Use query
- return doReadByQueryJsonData( dataTypeName, QueryBuilders.matchAllQuery(),ignoreException);
+ return doReadByQueryJsonData( dataTypeName, QueryBuilders.matchAllQuery(),ignoreException);
}
-
+ public @Nonnull SearchResult<SearchHit> doReadAllJsonData(String alias, String dataType, boolean ignoreException) {
+ return doReadByQueryJsonData( alias, dataType, QueryBuilders.matchAllQuery(),ignoreException);
+ }
@Override
public String doUpdateOrCreate(String dataTypeName, String esId, String json) {
return this.doUpdateOrCreate(dataTypeName, esId, json,null);
@@ -296,4 +302,5 @@ public class HtDatabaseClient extends ExtRestClient implements DatabaseClient, A
return del;
}
+
}
diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/AliasesEntry.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/AliasesEntry.java
index 73d50db83..1c1c4ecd3 100644
--- a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/AliasesEntry.java
+++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/AliasesEntry.java
@@ -1,20 +1,24 @@
-/*******************************************************************************
- * ============LICENSE_START========================================================================
- * ONAP : ccsdk feature sdnr wt
- * =================================================================================================
- * 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
+/*
+ * ============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.data;
import java.text.ParseException;
diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/AliasesEntryList.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/AliasesEntryList.java
index a3a8e728d..3891ecfb7 100644
--- a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/AliasesEntryList.java
+++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/AliasesEntryList.java
@@ -1,23 +1,28 @@
-/*******************************************************************************
- * ============LICENSE_START========================================================================
- * ONAP : ccsdk feature sdnr wt
- * =================================================================================================
- * 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
+/*
+ * ============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.data;
import java.util.ArrayList;
+import java.util.List;
/**
* @author Michael Dürre
@@ -43,4 +48,15 @@ public class AliasesEntryList extends ArrayList<AliasesEntry>{
return null;
}
+ /**
+ * @return
+ */
+ public List<String> getLinkedIndices() {
+ List<String> list = new ArrayList<String>();
+ for(AliasesEntry e:this) {
+ list.add(e.getIndex());
+ }
+ return list;
+ }
+
}
diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/IndicesEntry.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/IndicesEntry.java
index 760f9ff70..26e088d3f 100644
--- a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/IndicesEntry.java
+++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/IndicesEntry.java
@@ -1,20 +1,24 @@
-/*******************************************************************************
- * ============LICENSE_START========================================================================
- * ONAP : ccsdk feature sdnr wt
- * =================================================================================================
- * 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
+/*
+ * ============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.data;
import java.text.ParseException;
@@ -32,7 +36,10 @@ public class IndicesEntry {
private static final String regex = "^(yellow|red|green)[\\ ]+([^\\ ]*)[\\ ]+([^\\ ]*)[\\ ]+([^\\ ]*)[\\ ]+([0-9]+)[\\ ]+([0-9]+)[\\ ]+([0-9]+)[\\ ]+([0-9]+)[\\ ]+([^\\ ]+)[\\ ]+([^\\ ]+)$";
private static final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
-
+ //for ES 2.2.0
+ private static final String regexOld = "^(yellow|red|green)[\\ ]+([^\\ ]*)[\\ ]+([^\\ ]*)[\\ ]+([0-9]+)[\\ ]+([0-9]+)[\\ ]+([0-9]+)[\\ ]+([0-9]+)[\\ ]+([^\\ ]+)[\\ ]+([^\\ ]+)$";
+ private static final Pattern patternOld = Pattern.compile(regexOld, Pattern.MULTILINE);
+
private final String status;
private final String status2;
private final String name;
@@ -85,20 +92,33 @@ public class IndicesEntry {
}
public IndicesEntry(String line) throws ParseException {
- final Matcher matcher = pattern.matcher(line);
- if(!matcher.find() || matcher.groupCount()<10) {
- throw new ParseException("unable to parse string:" +line,0);
+ Matcher matcher = pattern.matcher(line.trim());
+ if (!matcher.find() || matcher.groupCount() < 10) {
+ matcher = patternOld.matcher(line.trim());
+ if (!matcher.find() || matcher.groupCount() < 9) {
+ throw new ParseException("unable to parse string:" + line, 0);
+ }
+ this.status = matcher.group(1);
+ this.status2 = matcher.group(2);
+ this.name = matcher.group(3);
+ this.hash = "";
+ this.shards = Integer.parseInt(matcher.group(4));
+ this.replicas = Integer.parseInt(matcher.group(5));
+ this.c1 = Integer.parseInt(matcher.group(6));
+ this.c2 = Integer.parseInt(matcher.group(7));
+ this.size1 = matcher.group(8);
+ this.size2 = matcher.group(9);
+ } else {
+ this.status = matcher.group(1);
+ this.status2 = matcher.group(2);
+ this.name = matcher.group(3);
+ this.hash = matcher.group(4);
+ this.shards = Integer.parseInt(matcher.group(5));
+ this.replicas = Integer.parseInt(matcher.group(6));
+ this.c1 = Integer.parseInt(matcher.group(7));
+ this.c2 = Integer.parseInt(matcher.group(8));
+ this.size1 = matcher.group(9);
+ this.size2 = matcher.group(10);
}
- this.status = matcher.group(1);
- this.status2 = matcher.group(2);
- this.name = matcher.group(3);
- this.hash = matcher.group(4);
- this.shards = Integer.parseInt(matcher.group(5));
- this.replicas = Integer.parseInt(matcher.group(6));
- this.c1 = Integer.parseInt(matcher.group(7));
- this.c2 = Integer.parseInt(matcher.group(8));
- this.size1 = matcher.group(9);
- this.size2 = matcher.group(10);
-
}
}
diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/IndicesEntryList.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/IndicesEntryList.java
index 0931b44a5..5431db9e7 100644
--- a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/IndicesEntryList.java
+++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/IndicesEntryList.java
@@ -1,23 +1,28 @@
-/*******************************************************************************
- * ============LICENSE_START========================================================================
- * ONAP : ccsdk feature sdnr wt
- * =================================================================================================
- * 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
+/*
+ * ============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.data;
import java.util.ArrayList;
+import java.util.List;
/**
* @author Michael Dürre
@@ -43,4 +48,18 @@ public class IndicesEntryList extends ArrayList<IndicesEntry>{
return null;
}
+ /**
+ * @param indices
+ * @return
+ */
+ public IndicesEntryList subList(List<String> indices) {
+ IndicesEntryList sublist = new IndicesEntryList();
+ for(IndicesEntry e:this) {
+ if(indices.contains(e.getName())) {
+ sublist.add(e);
+ }
+ }
+ return sublist;
+ }
+
}