From ee75b19ee79f49b28a3137b6dcfdf02d6120f3de Mon Sep 17 00:00:00 2001 From: Michael Dürre Date: Wed, 26 Feb 2020 06:41:50 +0100 Subject: add data migration tool MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit add tool for data migration and initialization Issue-ID: SDNC-1085 Signed-off-by: Michael Dürre Change-Id: Ibd1ffeffa95d2897ae65f7d964e98941d810ffcb Signed-off-by: Michael Dürre --- .../sdnr/wt/common/database/DatabaseClient.java | 10 + .../sdnr/wt/common/database/ExtRestClient.java | 507 +++++++++++---------- .../sdnr/wt/common/database/HtDatabaseClient.java | 31 +- .../sdnr/wt/common/database/data/AliasesEntry.java | 34 +- .../wt/common/database/data/AliasesEntryList.java | 46 +- .../sdnr/wt/common/database/data/IndicesEntry.java | 80 ++-- .../wt/common/database/data/IndicesEntryList.java | 49 +- 7 files changed, 433 insertions(+), 324 deletions(-) (limited to 'sdnr/wt/common') 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 doReadAllJsonData(String dataTypeName, boolean ignoreException); + /** + * @param alias + * @param dataTypeName + * @param queryBuilder + * @param ignoreException + * @return + */ + SearchResult 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 doReadByQueryJsonData(String dataTypeName,QueryBuilder queryBuilder, boolean ignoreException) { + public @Nonnull SearchResult doReadByQueryJsonData( String dataTypeName,QueryBuilder queryBuilder, boolean ignoreException) { + return this.doReadByQueryJsonData(dataTypeName, dataTypeName,queryBuilder,ignoreException); + } + @Override + public @Nonnull SearchResult 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 doReadAllJsonData( String dataTypeName, boolean ignoreException) { - // Use query - return doReadByQueryJsonData( dataTypeName, QueryBuilders.matchAllQuery(),ignoreException); + return doReadByQueryJsonData( dataTypeName, QueryBuilders.matchAllQuery(),ignoreException); } - + public @Nonnull SearchResult 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{ return null; } + /** + * @return + */ + public List getLinkedIndices() { + List list = new ArrayList(); + 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{ return null; } + /** + * @param indices + * @return + */ + public IndicesEntryList subList(List indices) { + IndicesEntryList sublist = new IndicesEntryList(); + for(IndicesEntry e:this) { + if(indices.contains(e.getName())) { + sublist.add(e); + } + } + return sublist; + } + } -- cgit 1.2.3-korg