From 64d0d3d599e0ea26ec1613b2befd411ad08f884d Mon Sep 17 00:00:00 2001 From: Michael Dürre Date: Mon, 24 Feb 2020 11:17:47 +0100 Subject: update common lib MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit add some more es functionality Issue-ID: SDNC-1082 Signed-off-by: Michael Dürre Change-Id: Ic7a9b0922ddd9d389e1ab6e1df3201874409a883 --- sdnr/wt/common/pom.xml | 23 -- .../wt/common/configuration/subtypes/Section.java | 38 +- .../sdnr/wt/common/database/ExtRestClient.java | 433 +++++++++++---------- .../sdnr/wt/common/database/HtDatabaseClient.java | 4 +- .../sdnr/wt/common/database/SearchHit.java | 64 ++- .../sdnr/wt/common/database/config/HostInfo.java | 24 ++ .../sdnr/wt/common/database/data/AliasesEntry.java | 49 +++ .../wt/common/database/data/AliasesEntryList.java | 46 +++ .../sdnr/wt/common/database/data/EsVersion.java | 135 +++++++ .../sdnr/wt/common/database/data/IndicesEntry.java | 104 +++++ .../wt/common/database/data/IndicesEntryList.java | 46 +++ .../database/requests/CreateAliasRequest.java | 29 ++ .../database/requests/CreateIndexRequest.java | 73 ++-- .../database/requests/DeleteAliasRequest.java | 27 ++ .../common/database/requests/GetInfoRequest.java | 29 ++ .../database/requests/ListAliasesRequest.java | 27 ++ .../database/requests/ListIndicesRequest.java | 27 ++ .../wt/common/database/responses/BaseResponse.java | 81 ++-- .../database/responses/ClusterHealthResponse.java | 87 +++-- .../common/database/responses/CountResponse.java | 30 -- .../database/responses/CreateAliasResponse.java | 28 ++ .../database/responses/DeleteAliasResponse.java | 28 ++ .../common/database/responses/GetInfoResponse.java | 72 ++++ .../database/responses/ListAliasesResponse.java | 63 +++ .../database/responses/ListIndicesResponse.java | 63 +++ .../features/sdnr/wt/common/file/FileWatchdog.java | 37 +- .../features/sdnr/wt/common/test/TestConfig.java | 24 ++ .../sdnr/wt/common/test/TestDbRequests.java | 59 +++ .../features/sdnr/wt/common/test/TestEsData.java | 111 ++++++ 29 files changed, 1430 insertions(+), 431 deletions(-) create mode 100644 sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/AliasesEntry.java create mode 100644 sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/AliasesEntryList.java create mode 100644 sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/EsVersion.java create mode 100644 sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/IndicesEntry.java create mode 100644 sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/IndicesEntryList.java create mode 100644 sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/CreateAliasRequest.java create mode 100644 sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/DeleteAliasRequest.java create mode 100644 sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/GetInfoRequest.java create mode 100644 sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/ListAliasesRequest.java create mode 100644 sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/ListIndicesRequest.java delete mode 100644 sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/responses/CountResponse.java create mode 100644 sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/responses/CreateAliasResponse.java create mode 100644 sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/responses/DeleteAliasResponse.java create mode 100644 sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/responses/GetInfoResponse.java create mode 100644 sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/responses/ListAliasesResponse.java create mode 100644 sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/responses/ListIndicesResponse.java create mode 100644 sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestEsData.java (limited to 'sdnr/wt/common') diff --git a/sdnr/wt/common/pom.xml b/sdnr/wt/common/pom.xml index 5719be168..7a414e5c9 100644 --- a/sdnr/wt/common/pom.xml +++ b/sdnr/wt/common/pom.xml @@ -108,28 +108,6 @@ - - org.codehaus.mojo - exec-maven-plugin - - - generateDTOs - generate-sources - - exec - - - bash - - ${basedir}/../data-provider/provider/src/main/resources/es-init.sh - initfile - -f - ${project.build.directory}/EsInit.script - - - - - com.github.alexcojocaru elasticsearch-maven-plugin @@ -141,7 +119,6 @@ ${databaseport} 6.5.0 120 - ${project.build.directory}/EsInit.script 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 094da6389..1160c281c 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 @@ -22,6 +22,8 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map.Entry; import java.util.Optional; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import org.onap.ccsdk.features.sdnr.wt.common.configuration.exception.ConversionException; import org.slf4j.Logger; @@ -53,12 +55,36 @@ public class Section { return this.getProperty(key, ""); } - public String getProperty(String key, String defValue) { - if (values.containsKey(key)) { - return values.get(key).getValue(); - } - return defValue; - } + public String getProperty(final String key, final String defValue) { + String value=defValue; + LOG.debug("try to get property for {} with def {}",key,defValue); + if (values.containsKey(key)) { + value = values.get(key).getValue(); + } + //try to read env var + if (value != null && value.contains("${")) { + + LOG.debug("try to find env var(s) for {}",value); + final String regex = "(\\$\\{[A-Z]+\\})"; + final Pattern pattern = Pattern.compile(regex); + final Matcher matcher = pattern.matcher(value); + String tmp=new String(value); + while(matcher.find() && matcher.groupCount()>0) { + final String mkey = matcher.group(1); + 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)); + tmp = tmp.replace(mkey, env==null?"":env ); + } catch (SecurityException e) { + LOG.warn("unable to read env {}: {}", value, e); + } + } + } + value=tmp; + } + return value; + } public String getName() { return name; 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 6fb26f541..5ef326f41 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,6 +18,8 @@ package org.onap.ccsdk.features.sdnr.wt.common.database; import java.io.IOException; +import java.text.ParseException; + import org.apache.http.HttpHost; import org.apache.http.auth.AuthScope; import org.apache.http.auth.UsernamePasswordCredentials; @@ -32,14 +34,19 @@ 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.requests.ClusterHealthRequest; +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.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.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.IndexRequest; import org.onap.ccsdk.features.sdnr.wt.common.database.requests.IndicesAliasesRequest; +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.SearchRequest; @@ -47,12 +54,17 @@ import org.onap.ccsdk.features.sdnr.wt.common.database.requests.UpdateByQueryReq import org.onap.ccsdk.features.sdnr.wt.common.database.requests.UpdateRequest; import org.onap.ccsdk.features.sdnr.wt.common.database.responses.AcknowledgedResponse; import org.onap.ccsdk.features.sdnr.wt.common.database.responses.ClusterHealthResponse; +import org.onap.ccsdk.features.sdnr.wt.common.database.responses.CreateAliasResponse; import org.onap.ccsdk.features.sdnr.wt.common.database.responses.CreateIndexResponse; +import org.onap.ccsdk.features.sdnr.wt.common.database.responses.DeleteAliasResponse; import org.onap.ccsdk.features.sdnr.wt.common.database.responses.DeleteByQueryResponse; import org.onap.ccsdk.features.sdnr.wt.common.database.responses.DeleteIndexResponse; import org.onap.ccsdk.features.sdnr.wt.common.database.responses.DeleteResponse; +import org.onap.ccsdk.features.sdnr.wt.common.database.responses.GetInfoResponse; 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.ListAliasesResponse; +import org.onap.ccsdk.features.sdnr.wt.common.database.responses.ListIndicesResponse; import org.onap.ccsdk.features.sdnr.wt.common.database.responses.NodeStatsResponse; import org.onap.ccsdk.features.sdnr.wt.common.database.responses.RefreshIndexResponse; import org.onap.ccsdk.features.sdnr.wt.common.database.responses.SearchResponse; @@ -63,234 +75,247 @@ import org.slf4j.LoggerFactory; public class ExtRestClient { - private static final Logger LOG = LoggerFactory.getLogger(ExtRestClient.class); + private static final Logger LOG = LoggerFactory.getLogger(ExtRestClient.class); - private class BasicAuthHttpClientConfigCallback implements HttpClientConfigCallback { + private class BasicAuthHttpClientConfigCallback implements HttpClientConfigCallback { - private final String basicAuthUsername; - private final String basicAuthPassword; + private final String basicAuthUsername; + private final String basicAuthPassword; - BasicAuthHttpClientConfigCallback(String username, String password) { - this.basicAuthUsername = username; - this.basicAuthPassword = password; - } + 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)); + @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); - } + return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider); + } - } -// private class SSLCercAuthHttpClientConfigCallback implements HttpClientConfigCallback { + } +// private class SSLCercAuthHttpClientConfigCallback implements HttpClientConfigCallback { // -// private final String certFilename; +// private final String certFilename; // -// SSLCercAuthHttpClientConfigCallback(String certfile) { -// this.certFilename = certfile; -// } +// SSLCercAuthHttpClientConfigCallback(String certfile) { +// this.certFilename = certfile; +// } // -// @Override -// public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) { -// if (this.certFilename == null) { -// return httpClientBuilder; -// } +// @Override +// public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) { +// if (this.certFilename == null) { +// return httpClientBuilder; +// } // -// char[] keystorePass = "MY PASSWORD".toCharArray(); +// char[] keystorePass = "MY PASSWORD".toCharArray(); // -// FileInputStream fis = null; +// 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) { +// // 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 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(); - } +// } +// } +// } +// } +// 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); +// } +// } - public ClusterHealthResponse health(ClusterHealthRequest request) - throws UnsupportedOperationException, IOException, JSONException { - return new ClusterHealthResponse(this.client.performRequest(request.getInner())); - } + private final RestClient client; - 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; - } + 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 AcknowledgedResponse updateAliases(IndicesAliasesRequest request) throws IOException{ - return new AcknowledgedResponse(this.client.performRequest(request.getInner())); - } + public ClusterHealthResponse health(ClusterHealthRequest request) + throws UnsupportedOperationException, IOException, JSONException { + return new ClusterHealthResponse(this.client.performRequest(request.getInner())); + } - public CreateIndexResponse createIndex(CreateIndexRequest request) throws IOException { - CreateIndexResponse response = new CreateIndexResponse(this.client.performRequest(request.getInner())); - return response; - } - 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 void close() throws IOException { + this.client.close(); - 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 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 SearchResponse search(SearchRequest request) throws IOException{ - return this.search(request,false); + 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())); + } - /** - * - * @param request - * @param ignoreParseException especially for usercreated filters which may cause ES server response exceptions - * @return - * @throws IOException - */ - 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 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); + } - public GetResponse get(GetRequest request) throws IOException{ - try { - return new GetResponse(this.client.performRequest(request.getInner())); - } - catch (ResponseException e) { - return new GetResponse(e.getResponse()); - } - } - + /** + * 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 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 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); + public GetResponse get(GetRequest request) throws IOException{ + try { + return new GetResponse(this.client.performRequest(request.getInner())); + } + catch (ResponseException e) { + return new GetResponse(e.getResponse()); + } + } - } - - private static HttpHost[] get(HostInfo[] hosts) { - HttpHost[] httphosts = new HttpHost[hosts.length]; - for(int i=0;i2) { + port=Integer.parseInt(matcher.group(3)); + } + return new HostInfo(host,port,p); + } } 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 new file mode 100644 index 000000000..73d50db83 --- /dev/null +++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/AliasesEntry.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * ============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 + * + * 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.data; + +import java.text.ParseException; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * @author Michael Dürre + * + */ +public class AliasesEntry { + private static final String regex = "^([^\\ ]+)[\\ ]+([^\\ ]+)[\\ ]+.*$"; + private static final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE); + + + public String getAlias() { + return alias; + } + public String getIndex() { + return index; + } + private final String alias; + private final String index; + public AliasesEntry(String line) throws ParseException { + final Matcher matcher = pattern.matcher(line); + if (!matcher.find() || matcher.groupCount() < 2) { + throw new ParseException("unable to parse string:" + line, 0); + } + this.alias = matcher.group(1); + this.index = matcher.group(2); + } +} 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 new file mode 100644 index 000000000..a3a8e728d --- /dev/null +++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/AliasesEntryList.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * ============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 + * + * 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.data; + +import java.util.ArrayList; + +/** + * @author Michael Dürre + * + */ +public class AliasesEntryList extends ArrayList{ + + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * @param alias + * @return + */ + public AliasesEntry findByAlias(String alias) { + for(AliasesEntry e:this) { + if(e.getAlias().equals(alias)) { + return e; + } + } + return null; + } + +} 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 new file mode 100644 index 000000000..8d5269115 --- /dev/null +++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/EsVersion.java @@ -0,0 +1,135 @@ +/******************************************************************************* + * ============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 + * + * 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.data; + +import java.text.ParseException; + +import org.eclipse.jdt.annotation.NonNull; + + +/** + * @author Michael Dürre + * + */ +public class EsVersion { + + private final String raw; + private final int major; + private final int minor; + private final int revision; + + public EsVersion(@NonNull String version) throws ParseException { + String[] hlp=version.split("\\."); + if(hlp.length<3) { + throw new ParseException("unable to parse version string: "+version, 0); + } + this.raw = version; + this.major = Integer.parseInt(hlp[0]); + this.minor = Integer.parseInt(hlp[1]); + this.revision = Integer.parseInt(hlp[2]); + } + + /** + * @param major + * @param minor + * @param revision + */ + public EsVersion(int major, int minor, int revision) { + this.raw = String.format("%d.%d.%d", major,minor,revision); + this.major = major; + this.minor = minor; + this.revision = revision; + } + + /** + * @return the revision + */ + public int getRevision() { + return revision; + } + + /** + * @return the minor + */ + public int getMinor() { + return minor; + } + + /** + * @return the major + */ + public int getMajor() { + return major; + } + + @Override + public boolean equals(Object obj) { + if(!(obj instanceof EsVersion)) { + return false; + } + EsVersion esobj = (EsVersion)obj; + return this.major==esobj.major && this.minor==esobj.minor && this.revision==esobj.revision; + } + @Override + public int hashCode() { + return this.raw.hashCode(); + } + public boolean isNewerOrEqualThan(EsVersion v) { + if(this.equals(v)) { + return true; + } + if(this.major>v.major) { + return true; + } + else if(this.majorv.minor) { + return true; + } + else if(this.minorv.revision) { + return true; + } + return false; + } + public boolean isOlderOrEqualThan(EsVersion v) { + if(this.equals(v)) { + return true; + } + if(this.majorv.major) { + return false; + } + if(this.minorv.minor) { + return false; + } + if(this.revision{ + + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * @param index + * @return + */ + public IndicesEntry findByIndex(String index) { + for(IndicesEntry e:this) { + if(e.getName().equals(index)) { + return e; + } + } + return null; + } + +} diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/CreateAliasRequest.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/CreateAliasRequest.java new file mode 100644 index 000000000..15132fda5 --- /dev/null +++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/CreateAliasRequest.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * ============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 + * + * 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; + +//https://github.com/elastic/elasticsearch/blob/6.4/rest-api-spec/src/main/resources/rest-api-spec/api/indices.put_alias.json +public class CreateAliasRequest extends BaseRequest{ + + + public CreateAliasRequest(String index,String alias) { + super("PUT","/"+index+"/_alias/"+alias); + } + + +} 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 c7e27ee4a..c08ee880b 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 @@ -23,41 +23,42 @@ import org.json.JSONObject; //https://github.com/elastic/elasticsearch/blob/6.4/rest-api-spec/src/main/resources/rest-api-spec/api/indices.put_mapping.json public class CreateIndexRequest extends BaseRequest{ - private JSONObject settings; - private JSONObject mappings; - - public CreateIndexRequest(String index) { - super("PUT","/"+index); - this.mappings=new JSONObject(); - } - - private void setRequest() { - - JSONObject o=new JSONObject(); - if(this.mappings!=null) { - o.put("mappings", this.mappings); - } - if(this.settings!=null) { - o.put("settings", this.settings); - } - super.setQuery(o); - } - public void mappings(JSONObject mappings) { - this.mappings=mappings; - this.setRequest(); - } - - public void settings(JSONObject settings) { - this.settings = settings; - this.setRequest(); - } - - public boolean hasMappings() { - return this.mappings!=null; - } - - public boolean hasSettings() { - return this.settings!=null; - } + private JSONObject settings; + private JSONObject mappings; + + public CreateIndexRequest(String index) { + super("PUT","/"+index); + this.mappings=new JSONObject(); + } + + private void setRequest() { + + JSONObject o=new JSONObject(); + if(this.mappings!=null) { + o.put("mappings", this.mappings); + } + if(this.settings!=null) { + o.put("settings", this.settings); + } + super.setQuery(o); + } + @SuppressWarnings("hiding") + public void mappings(JSONObject mappings) { + this.mappings=mappings; + this.setRequest(); + } + + public void settings(JSONObject settings) { + this.settings = settings; + this.setRequest(); + } + + public boolean hasMappings() { + return this.mappings!=null; + } + + public boolean hasSettings() { + return this.settings!=null; + } } diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/DeleteAliasRequest.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/DeleteAliasRequest.java new file mode 100644 index 000000000..b3d8877df --- /dev/null +++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/DeleteAliasRequest.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * ============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 + * + * 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; + +//https://github.com/elastic/elasticsearch/blob/6.4/rest-api-spec/src/main/resources/rest-api-spec/api/indices.delete_alias.json +public class DeleteAliasRequest extends BaseRequest{ + + public DeleteAliasRequest(String index,String alias) { + super("DELETE","/"+index+"/_alias/"+alias); + } + +} diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/GetInfoRequest.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/GetInfoRequest.java new file mode 100644 index 000000000..949444b35 --- /dev/null +++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/GetInfoRequest.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * ============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 + * + * 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; + +//https://github.com/elastic/elasticsearch/blob/6.4/rest-api-spec/src/main/resources/rest-api-spec/api/indices.exists.json +public class GetInfoRequest extends BaseRequest { + + public GetInfoRequest() { + super("GET","/"); + } + + + +} diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/ListAliasesRequest.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/ListAliasesRequest.java new file mode 100644 index 000000000..b538291b0 --- /dev/null +++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/ListAliasesRequest.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * ============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 + * + * 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; + +public class ListAliasesRequest extends BaseRequest{ + + + public ListAliasesRequest() { + super("GET","/_cat/aliases"); + } + +} diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/ListIndicesRequest.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/ListIndicesRequest.java new file mode 100644 index 000000000..d8b7d5fee --- /dev/null +++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/requests/ListIndicesRequest.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * ============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 + * + * 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; + +public class ListIndicesRequest extends BaseRequest{ + + + public ListIndicesRequest() { + super("GET","/_cat/indices"); + } + +} 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 49447f660..01219f0f0 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 @@ -18,9 +18,11 @@ package org.onap.ccsdk.features.sdnr.wt.common.database.responses; import java.io.IOException; -import java.io.InputStream; -import java.util.Scanner; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import org.apache.http.util.EntityUtils; import org.elasticsearch.client.Response; import org.json.JSONObject; import org.slf4j.Logger; @@ -28,48 +30,61 @@ import org.slf4j.LoggerFactory; public class BaseResponse { private static final Logger LOG = LoggerFactory.getLogger(BaseResponse.class); - private int responseCode; - public int getResponseCode() { + private final int responseCode; + + BaseResponse(Response response) { + this.responseCode = response != null ? response.getStatusLine().getStatusCode() : 0; + } + + int getResponseCode() { return this.responseCode; } + public boolean isResponseSucceeded() { - return this.responseCode<300; + return this.responseCode < 300; } - public BaseResponse() { - } - public BaseResponse(Response response) { - this.responseCode = response!=null?response.getStatusLine().getStatusCode():0; - } - protected JSONObject getJson(Response response) { - Scanner s; - JSONObject o=null; - try { - //input stream used because Scanner ignored whitespaces - InputStream is = response.getEntity().getContent(); - long len; - int BUFSIZE=1024; - byte[] buffer = new byte[BUFSIZE]; - StringBuffer sresponse = new StringBuffer(); - while (true) { - len = is.read(buffer, 0, BUFSIZE); - if (len <= 0) { - break; - } - - sresponse.append(new String(buffer)); - } - LOG.debug("parsing response={}",sresponse); - o = new JSONObject(sresponse.toString()); + JSONObject getJson(Response response) { + try { + String sresponse = EntityUtils.toString(response.getEntity()); + LOG.debug("parsing response={}", sresponse); + return new JSONObject(sresponse); } catch (UnsupportedOperationException | IOException e) { - LOG.warn("error parsing es response: {}",e.getMessage()); + LOG.warn("error parsing es response: {}", e.getMessage()); + return null; } - return o; } - protected JSONObject getJson(String json) { + + JSONObject getJson(String json) { return new JSONObject(json); } + /** + * @param response + * @return + */ + List getLines(Response response){ + return this.getLines(response,true); + } + List getLines(Response response,boolean ignoreEmpty) { + try { + String sresponse = EntityUtils.toString(response.getEntity()); + LOG.debug("parsing response={}", sresponse); + String[] hlp = sresponse.split("\n"); + List lines=new ArrayList(); + for(String h:hlp) { + if(ignoreEmpty && h.trim().length()==0) { + continue; + } + lines.add(h); + } + return lines; + } catch (UnsupportedOperationException | IOException e) { + LOG.warn("error parsing es response: {}", e.getMessage()); + return null; + } + + } } diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/responses/ClusterHealthResponse.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/responses/ClusterHealthResponse.java index 3f47ac286..b90bbbce2 100644 --- a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/responses/ClusterHealthResponse.java +++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/responses/ClusterHealthResponse.java @@ -24,53 +24,54 @@ import org.json.JSONObject; public class ClusterHealthResponse extends BaseResponse { - public static final String HEALTHSTATUS_GREEN = "green"; - public static final String HEALTHSTATUS_YELLOW = "yellow"; - public static final String HEALTSTATUS_RED = "red"; + public static final String HEALTHSTATUS_GREEN = "green"; + public static final String HEALTHSTATUS_YELLOW = "yellow"; + public static final String HEALTSTATUS_RED = "red"; - private String status; - private boolean timedOut; + private String status; + private boolean timedOut; - /* - * "cluster_name": "docker-cluster", "status": "yellow", "timed_out": false, - * "number_of_nodes": 1, "number_of_data_nodes": 1, "active_primary_shards": 5, - * "active_shards": 5, "relocating_shards": 0, "initializing_shards": 0, - * "unassigned_shards": 5, "delayed_unassigned_shards": 0, - * "number_of_pending_tasks": 0, "number_of_in_flight_fetch": 0, - * "task_max_waiting_in_queue_millis": 0, "active_shards_percent_as_number": 50 - */ - public ClusterHealthResponse(Response response) throws UnsupportedOperationException, IOException, JSONException { - super(response); - - JSONObject o = this.getJson(response); - if (o != null) { - this.status = o.getString("status"); - this.timedOut = o.getBoolean("timed_out"); - } - } + /* + * "cluster_name": "docker-cluster", "status": "yellow", "timed_out": false, + * "number_of_nodes": 1, "number_of_data_nodes": 1, "active_primary_shards": 5, + * "active_shards": 5, "relocating_shards": 0, "initializing_shards": 0, + * "unassigned_shards": 5, "delayed_unassigned_shards": 0, + * "number_of_pending_tasks": 0, "number_of_in_flight_fetch": 0, + * "task_max_waiting_in_queue_millis": 0, "active_shards_percent_as_number": 50 + */ + public ClusterHealthResponse(Response response) throws UnsupportedOperationException, IOException, JSONException { + super(response); - public boolean isTimedOut() { - return this.timedOut; - } - public boolean isStatusMinimal(String status) { - if (status == null) { - return true; - } - if (this.status.equals(HEALTHSTATUS_GREEN)) { - return true; - } - if (this.status.equals(HEALTHSTATUS_YELLOW) && !status.equals(HEALTHSTATUS_GREEN)) { - return true; - } - if (this.status.equals(status)) { - return true; - } - return false; + JSONObject o = this.getJson(response); + if (o != null) { + this.status = o.getString("status"); + this.timedOut = o.getBoolean("timed_out"); + } + } - } + public boolean isTimedOut() { + return this.timedOut; + } + @SuppressWarnings("hiding") + public boolean isStatusMinimal(String status) { + if (status == null) { + return true; + } + if (this.status.equals(HEALTHSTATUS_GREEN)) { + return true; + } + if (this.status.equals(HEALTHSTATUS_YELLOW) && !status.equals(HEALTHSTATUS_GREEN)) { + return true; + } + if (this.status.equals(status)) { + return true; + } + return false; - public String getStatus() { - return this.status; - } + } + + public String getStatus() { + return this.status; + } } diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/responses/CountResponse.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/responses/CountResponse.java deleted file mode 100644 index 429c3394d..000000000 --- a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/responses/CountResponse.java +++ /dev/null @@ -1,30 +0,0 @@ -/******************************************************************************* - * ============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 - * - * 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.responses; - -import org.elasticsearch.client.Response; - -public class CountResponse extends BaseResponse { - - private long count; - - public CountResponse(Response response) { - super(response); - - } -} diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/responses/CreateAliasResponse.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/responses/CreateAliasResponse.java new file mode 100644 index 000000000..280ce3999 --- /dev/null +++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/responses/CreateAliasResponse.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * ============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 + * + * 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.responses; + +import org.elasticsearch.client.Response; + +public class CreateAliasResponse extends AcknowledgedResponse { + + public CreateAliasResponse(Response response) { + super(response); + } + +} diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/responses/DeleteAliasResponse.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/responses/DeleteAliasResponse.java new file mode 100644 index 000000000..291aff0f5 --- /dev/null +++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/responses/DeleteAliasResponse.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * ============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 + * + * 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.responses; + +import org.elasticsearch.client.Response; + +public class DeleteAliasResponse extends AcknowledgedResponse { + + public DeleteAliasResponse(Response response) { + super(response); + } + +} \ No newline at end of file diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/responses/GetInfoResponse.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/responses/GetInfoResponse.java new file mode 100644 index 000000000..9b579f5c4 --- /dev/null +++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/responses/GetInfoResponse.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * ============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 + * + * 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.responses; + +import org.elasticsearch.client.Response; +import org.json.JSONObject; +import org.onap.ccsdk.features.sdnr.wt.common.database.data.EsVersion; + +public class GetInfoResponse extends BaseResponse { + + /** + * { + * "name" : "kpOdXt-", + * "cluster_name" : "docker-cluster", + * "cluster_uuid" : "qags6CGGTrS75iBhrAdsgg", + * "version" : { + * "number" : "6.4.3", + * "build_flavor" : "default", + * "build_type" : "tar", + * "build_hash" : "fe40335", + * "build_date" : "2018-10-30T23:17:19.084789Z", + * "build_snapshot" : false, + * "lucene_version" : "7.4.0", + * "minimum_wire_compatibility_version" : "5.6.0", + * "minimum_index_compatibility_version" : "5.0.0" + * }, + * "tagline" : "You Know, for Search" + *} + */ + private final String clusterName; + private final String name; + + private final EsVersion version; + public GetInfoResponse(Response response) throws Exception { + super(response); + JSONObject o = this.getJson(response); + if(o==null) { + throw new Exception("unable to read response"); + } + this.name = o.getString("name"); + this.clusterName = o.getString("cluster_name"); + this.version = new EsVersion(o.getJSONObject("version").getString("number")); + } + public String getClusterName() { + return clusterName; + } + public String getName() { + return name; + } + public EsVersion getVersion() { + return version; + } + + + + +} diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/responses/ListAliasesResponse.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/responses/ListAliasesResponse.java new file mode 100644 index 000000000..29e51fe8c --- /dev/null +++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/responses/ListAliasesResponse.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * ============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 + * + * 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.responses; + +import java.text.ParseException; +import java.util.ArrayList; +import java.util.List; + +import org.elasticsearch.client.Response; +import org.onap.ccsdk.features.sdnr.wt.common.database.data.AliasesEntry; +import org.onap.ccsdk.features.sdnr.wt.common.database.data.AliasesEntryList; + +public class ListAliasesResponse extends BaseResponse { + + /* + * eventlog eventlog-v1 - - - + * faultlog faultlog-v1 - - - + * inventoryequipment inventoryequipment-v1 - - - + * historicalperformance24h historicalperformance24h-v1 - - - + * mediator-server mediator-server-v1 - - - + * networkelement-connection networkelement-connection-v1 - - - + * maintenancemode maintenancemode-v1 - - - + * historicalperformance15min historicalperformance15min-v1 - - - + * faultcurrent faultcurrent-v1 - - - + * connectionlog connectionlog-v1 - - - + */ + private final AliasesEntryList entries; + public ListAliasesResponse(Response response) throws ParseException { + super(response); + List lines=this.getLines(response); + this.entries = new AliasesEntryList(); + if(lines!=null) { + for(String line:lines) { + this.entries.add(new AliasesEntry(line)); + } + } + } + /** + * + * @return null if parsing failed otherwise valid (=>no entries may also be valid) + */ + public AliasesEntryList getEntries(){ + return this.entries; + } + + + +} diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/responses/ListIndicesResponse.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/responses/ListIndicesResponse.java new file mode 100644 index 000000000..cfbe1599a --- /dev/null +++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/responses/ListIndicesResponse.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * ============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 + * + * 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.responses; + +import java.text.ParseException; +import java.util.List; + +import org.elasticsearch.client.Response; +import org.onap.ccsdk.features.sdnr.wt.common.database.data.IndicesEntry; +import org.onap.ccsdk.features.sdnr.wt.common.database.data.IndicesEntryList; + +public class ListIndicesResponse extends BaseResponse { + + /* + * yellow open inventoryequipment-v1 5nNPRbJ3T9arMxqxBbJKyQ 5 1 0 0 1.2kb 1.2kb + * yellow open eventlog-v1 8lkfX97iT86dZdUlgVAktg 5 1 0 0 1.2kb 1.2kb + * yellow open mediator-server-v1 8T4hNo61SgulupKntivY4Q 5 1 0 0 1.2kb 1.2kb + * yellow open historicalperformance24h-v1 fRCGb7JYRdiry23HKWg0Hw 5 1 0 0 1.2kb 1.2kb + * yellow open faultlog-v1 kjsb50boTPOAzXMYdnfv4A 5 1 0 0 1.2kb 1.2kb + * yellow open maintenancemode-v1 Q9ZsCgW0Q9m6nk49iOFNhA 5 1 0 0 1.2kb 1.2kb + * yellow open historicalperformance15min-v1 BdEOe7X2RK2o5yTwNH5QQg 5 1 0 0 1.2kb 1.2kb + * yellow open faultcurrent-v1 BdikWk9HQtS5aFpYEAac2g 5 1 0 0 1.2kb 1.2kb + * yellow open networkelement-connection-v1 YT3lj0AKRoOmtN30Zbdfqw 5 1 0 0 1.2kb 1.2kb + * yellow open connectionlog-v1 7yrVaaM1QjyO5eMsCUHNHQ 5 1 0 0 1.2kb 1.2kb + */ + private final IndicesEntryList entries; + public ListIndicesResponse(Response response) throws ParseException { + super(response); + List lines=this.getLines(response); + this.entries = new IndicesEntryList(); + if(lines!=null) { + for(String line:lines) { + this.entries.add(new IndicesEntry(line)); + } + } + + } + /** + * @return + */ + public IndicesEntryList getEntries() { + return this.entries; + } + + + + +} diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/file/FileWatchdog.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/file/FileWatchdog.java index 63c1f15ba..11e6cb877 100644 --- a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/file/FileWatchdog.java +++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/file/FileWatchdog.java @@ -1,26 +1,21 @@ -/* - * ============LICENSE_START======================================================= - * ONAP : ccsdk features - * ================================================================================ - * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. - * All rights reserved. - * ================================================================================ - * Update Copyright (C) 2020 AT&T 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 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 * - * 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.file; import java.io.File; 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 591ea49dd..fd0c255dd 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,9 +21,13 @@ import static org.junit.Assert.*; 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; import org.junit.Test; @@ -230,4 +234,24 @@ public class TestConfig { } } + @Test + public void testEnvPropert() { + final String KEY = "basada"; + Section section = new Section("test"); + section.addLine(KEY+"=${USER} in ${HOME}"); + section.parseLines(); + assertTrue(section.getProperty(KEY).length()>" in ".length()); + } + public static void setEnv(String key, String value) { + try { + Map env = System.getenv(); + Class cl = env.getClass(); + Field field = cl.getDeclaredField("m"); + field.setAccessible(true); + Map writableEnv = (Map) 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/TestDbRequests.java b/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestDbRequests.java index 36bbebefd..9fdfeb2d2 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 @@ -24,7 +24,9 @@ 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.common.database.queries.QueryBuilders; import org.onap.ccsdk.features.sdnr.wt.common.database.requests.ClusterHealthRequest; +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.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; @@ -36,12 +38,14 @@ 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.ClusterHealthResponse; +import org.onap.ccsdk.features.sdnr.wt.common.database.responses.CreateAliasResponse; 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.DeleteIndexResponse; 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.ListIndicesResponse; import org.onap.ccsdk.features.sdnr.wt.common.database.responses.NodeStatsResponse; import org.onap.ccsdk.features.sdnr.wt.common.database.responses.SearchResponse; import org.onap.ccsdk.features.sdnr.wt.common.database.responses.UpdateByQueryResponse; @@ -53,6 +57,7 @@ import static org.junit.Assert.assertNotNull; 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; @@ -96,6 +101,53 @@ public class TestDbRequests { public void testCount() { } + @Test + public void testIndexAndAliasList() { + final String ALIAS="asdoi32kmasd"; + final String IDX=ALIAS+"-v1"; + CreateIndexRequest request = new CreateIndexRequest(IDX); + CreateIndexResponse response = null; + try { + response = dbClient.createIndex(request); + } catch (IOException e) { + fail(e.getMessage()); + } + assertNotNull(response); + + CreateAliasRequest request3 = new CreateAliasRequest(IDX,ALIAS); + CreateAliasResponse response3 = null; + try { + response3 = dbClient.createAlias(request3); + } catch (IOException e) { + fail(e.getMessage()); + } + assertNotNull(response3); + assertTrue(response3.isResponseSucceeded()); + + assertTrue("index not existing", dbClient.isExistsIndex(IDX)); + ListIndicesResponse response2=null; + try { + response2 = dbClient.getIndices(); + } catch (ParseException | IOException e) { + fail(e.getMessage()); + } + assertNotNull(response2); + assertNotNull(response2.getEntries()); + assertTrue(response2.getEntries().size()>0); + + DeleteIndexRequest request11 = new DeleteIndexRequest(IDX); + + DeleteIndexResponse response11 = null; + try { + response11 = dbClient.deleteIndex(request11); + } catch (IOException e) { + fail(e.getMessage()); + } + assertNotNull(response11); + assertFalse("index still existing", dbClient.isExistsIndex(IDX)); + this.deleteAlias(IDX, ALIAS); + this.deleteIndex(IDX); + } @Test public void testCreateAndDeleteIndex() { @@ -401,6 +453,13 @@ public class TestDbRequests { System.out.println(stats.getNodesInfo()); System.out.println(stats.getNodeStatistics()); } + private void deleteAlias(String idx,String alias) { + try { + dbClient.deleteAlias( new DeleteAliasRequest(idx,alias)); + } catch (IOException e) { + + } + } private void deleteIndex(String idx) { try { dbClient.deleteIndex( new DeleteIndexRequest(idx)); diff --git a/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestEsData.java b/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestEsData.java new file mode 100644 index 000000000..d88df96a0 --- /dev/null +++ b/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestEsData.java @@ -0,0 +1,111 @@ +/******************************************************************************* + * ============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 + * + * 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.test; + +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.text.ParseException; + +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.common.database.data.AliasesEntry; +import org.onap.ccsdk.features.sdnr.wt.common.database.data.AliasesEntryList; +import org.onap.ccsdk.features.sdnr.wt.common.database.data.EsVersion; +import org.onap.ccsdk.features.sdnr.wt.common.database.data.IndicesEntry; +import org.onap.ccsdk.features.sdnr.wt.common.database.data.IndicesEntryList; + +/** + * @author Michael Dürre + * + */ +public class TestEsData { + + + @Test + public void testVersion() { + EsVersion version=null; + try { + version = new EsVersion("2.3.4"); + } catch (ParseException e) { + fail(e.getMessage()); + } + assertNotNull(version); + assertEquals(2, version.getMajor()); + assertEquals(3, version.getMinor()); + assertEquals(4, version.getRevision()); + + EsVersion versionNewer = new EsVersion(5,0,0); + EsVersion versionOlder = new EsVersion(2,2,0); + + assertTrue(version.isOlderOrEqualThan(versionNewer)); + assertTrue(version.isNewerOrEqualThan(versionOlder)); + + } + @Test + public void testIndices() { + IndicesEntryList list = new IndicesEntryList(); + IndicesEntry entry=null; + try { + entry=new IndicesEntry("yellow open inventoryequipment-v1 5nNPRbJ3T9arMxqxBbJKyQ 5 1 2 3 1.2kb 2.4kb"); + list.add(entry); + list.add(new IndicesEntry("yellow open networkelement-connection-v1 5nNPRbJ3T9arMxqxBbJKyQ 5 1 0 0 1.2kb 1.2kb")); + list.add(new IndicesEntry("yellow open faultlog-v1 5nNPRbJ3T9arMxqxBbJKyQ 5 1 0 0 1.2kb 1.2kb")); + list.add(new IndicesEntry("yellow open eventlog-v1 5nNPRbJ3T9arMxqxBbJKyQ 5 1 0 0 1.2kb 1.2kb")); + } catch (ParseException e) { + fail(e.getMessage()); + } + assertEquals(4, list.size()); + assertNotNull(list.findByIndex("eventlog-v1")); + assertNull(list.findByIndex("faultcurrent")); + assertNotNull(entry); + assertEquals("yellow",entry.getStatus()); + assertEquals("open", entry.getStatus2()); + assertEquals("inventoryequipment-v1", entry.getName()); + assertEquals("5nNPRbJ3T9arMxqxBbJKyQ", entry.getHash()); + assertEquals(5, entry.getShards()); + assertEquals(1, entry.getReplicas()); + assertEquals(2, entry.getC1()); + assertEquals(3, entry.getC2()); + assertEquals("1.2kb", entry.getSize1()); + assertEquals("2.4kb", entry.getSize2()); + + } + @Test + public void testAliases() { + AliasesEntryList list = new AliasesEntryList(); + AliasesEntry entry=null; + try { + entry=new AliasesEntry("networkelement-connection networkelement-connection-v1 - - -"); + list.add(entry); + list.add(new AliasesEntry("faultcurrent faultcurrent-v1 - - -")); + list.add(new AliasesEntry("faultlog faultlog-v1 - - -")); + list.add(new AliasesEntry("maintenancemode maintenancemode-v1 - - -")); + } catch (ParseException e) { + fail(e.getMessage()); + } + assertEquals(4, list.size()); + assertNotNull(list.findByAlias("faultcurrent")); + assertNull(list.findByAlias("eventlog")); + assertNotNull(entry); + assertEquals("networkelement-connection",entry.getAlias()); + assertEquals("networkelement-connection-v1", entry.getIndex()); + } +} -- cgit 1.2.3-korg