X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Faai%2Fdatarouter%2Futil%2FSearchServiceAgent.java;h=4baa81a2597d611e474a96c07e64d81f304ff7fb;hb=10c04810902a100fbeba93dda5b13329ada39117;hp=20d0981205bd90bb509d45d5c74e014b7bb398c2;hpb=2a5ff133471c5a69b0dfd760d2743f48112da9a0;p=aai%2Fdata-router.git diff --git a/src/main/java/org/onap/aai/datarouter/util/SearchServiceAgent.java b/src/main/java/org/onap/aai/datarouter/util/SearchServiceAgent.java index 20d0981..4baa81a 100644 --- a/src/main/java/org/onap/aai/datarouter/util/SearchServiceAgent.java +++ b/src/main/java/org/onap/aai/datarouter/util/SearchServiceAgent.java @@ -2,8 +2,8 @@ * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017 Amdocs + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017-2018 Amdocs * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,8 +17,6 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. */ package org.onap.aai.datarouter.util; @@ -98,14 +96,14 @@ public class SearchServiceAgent { String documentEndpoint, Logger logger) { + String deobfuscatedCertPassword = keystorePwd.startsWith("OBF:")?Password.deobfuscate(keystorePwd):keystorePwd; // Create REST client for search service searchClient = new RestClient() .authenticationMode(RestAuthenticationMode.SSL_CERT) .validateServerHostname(false) - .validateServerCertChain(true) + .validateServerCertChain(false) .clientCertFile(DataRouterConstants.DR_HOME_AUTH + certName) - .clientCertPassword(Password.deobfuscate(keystorePwd)) - .trustStore(DataRouterConstants.DR_HOME_AUTH + keystore); + .clientCertPassword(deobfuscatedCertPassword); this.searchUrl = searchUrl; this.documentEndpoint = documentEndpoint; @@ -129,6 +127,14 @@ public class SearchServiceAgent { createIndex(index, schemaLocation); } + public void createSearchIndex(String index, String schemaLocation, String endUrl) { + + // Create a mapping of the index name to schema location + indexSchemaMapping.put(index, schemaLocation); + + // Now, create the index. + createIndex(index, schemaLocation, endUrl); + } /** * This method performs the actual work of creating a search index. @@ -162,6 +168,30 @@ public class SearchServiceAgent { } } + private void createIndex(String index, String schemaLocation, String endUrl) { + + logger.debug("Creating search index, index name: = " + index + ", schemaLocation = " + schemaLocation); + + MultivaluedMap headers = new MultivaluedMapImpl(); + headers.put("Accept", Arrays.asList("application/json")); + headers.put(Headers.FROM_APP_ID, Arrays.asList("DL")); + headers.put(Headers.TRANSACTION_ID, Arrays.asList(UUID.randomUUID().toString())); + + String url = concatSubUri(searchUrl, endUrl, index); + try { + + OperationResult result = searchClient.put(url, loadFileData(schemaLocation), headers, + MediaType.APPLICATION_JSON_TYPE, null); + if (!HttpUtil.isHttpResponseClassSuccess(result.getResultCode())) { + logger.error(DataRouterMsgs.FAIL_TO_CREATE_SEARCH_INDEX, index, result.getFailureCause()); + } else { + logger.info(DataRouterMsgs.SEARCH_INDEX_CREATE_SUCCESS, index); + } + + } catch (Exception e) { + logger.error(DataRouterMsgs.FAIL_TO_CREATE_SEARCH_INDEX, index, e.getLocalizedMessage()); + } + } /** * Retrieves a document from the search service. @@ -290,8 +320,7 @@ public class SearchServiceAgent { * Removes a document from the Search Service. * * @param index - The index to create the document in. - * @param id - The identifier for the document. - * @param payload - The document contents. + * @param documentId - The identifier for the document. * @param headers - HTTP headers. */ public void deleteDocument(String index, String documentId, Map> headers) { @@ -310,12 +339,13 @@ public class SearchServiceAgent { */ protected String loadFileData(String filename) throws Exception { StringBuilder data = new StringBuilder(); - try { - BufferedReader in = new BufferedReader(new InputStreamReader( - EntityEventPolicy.class.getClassLoader().getResourceAsStream("/" + filename), - StandardCharsets.UTF_8)); - String line; + try (InputStreamReader inputStreamReader = new InputStreamReader(EntityEventPolicy.class.getClassLoader() + .getResourceAsStream("/" + filename), StandardCharsets.UTF_8); BufferedReader in = new BufferedReader( + inputStreamReader) + ) { + + String line; while ((line = in.readLine()) != null) { data.append(line); }