@SuppressWarnings({ "unchecked", "static-access" }) @Test public void configureIndexAndTypesTest() throws Exception{ PowerMockito.mockStatic(ConfigManager.class); List<String> types = new ArrayList<>(); types.add("ds"); when(ConfigManager.getTypes(anyString())).thenReturn(new HashSet<>(types)); HttpEntity jsonEntity = new StringEntity("{}", ContentType.APPLICATION_JSON); when(response.getEntity()).thenReturn(jsonEntity); when(restClient.performRequest(anyString(), anyString(), anyMap(), any(HttpEntity.class), Matchers.<Header>anyVararg())).thenReturn(response); ReflectionTestUtils.setField(esManager, "restClient", restClient); when(sl.getStatusCode()).thenReturn(100); when(response.getStatusLine()).thenReturn(sl); esManager.configureIndexAndTypes("index",new ArrayList<>()); }
public static void configureIndexAndTypes(String ds, List<Map<String, String>> errorList) { String _payLoad = "{\"settings\" : { \"number_of_shards\" : 3,\"number_of_replicas\" : 1 },\"mappings\": {"; Set<String> types = ConfigManager.getTypes(ds); Iterator<String> it = types.iterator(); while (it.hasNext()) { String _type = it.next(); String indexName = ds+ "_" + _type; if (!indexExists(indexName)) { StringBuilder payLoad = new StringBuilder(_payLoad); payLoad.append("\"" + _type + "\":{},\"issue_" + _type + "\": { \"_parent\": {\"type\": \"" + _type + "\"}},\"issue_" + _type + "_audit\": { \"_parent\": {\"type\": \"issue_" + _type + "\"}},\"issue_" + _type + "_comment\": { \"_parent\": {\"type\": \"issue_" + _type + "\"}},\"issue_" + _type + "_exception\": { \"_parent\": {\"type\": \"issue_" + _type + "\"}}"); payLoad.append("}}"); try { invokeAPI("PUT", indexName, payLoad.toString()); } catch (IOException e) { LOGGER.error("Error in configureIndexAndTypes",e); Map<String,String> errorMap = new HashMap<>(); errorMap.put(ERROR, "Error in configureIndexAndTypes"); errorMap.put(ERROR_TYPE, WARN); errorMap.put(EXCEPTION, e.getMessage()); errorList.add(errorMap); } } try { invokeAPI("PUT", "/" + indexName + "/_alias/" + ds, null); invokeAPI("PUT", "/" + indexName + "/_alias/" + "ds-all", null); } catch (IOException e) { } } }
ESManager implements Constants { public static void configureIndexAndTypes(String ds, List<Map<String, String>> errorList) { String _payLoad = "{\"settings\" : { \"number_of_shards\" : 3,\"number_of_replicas\" : 1 },\"mappings\": {"; Set<String> types = ConfigManager.getTypes(ds); Iterator<String> it = types.iterator(); while (it.hasNext()) { String _type = it.next(); String indexName = ds+ "_" + _type; if (!indexExists(indexName)) { StringBuilder payLoad = new StringBuilder(_payLoad); payLoad.append("\"" + _type + "\":{},\"issue_" + _type + "\": { \"_parent\": {\"type\": \"" + _type + "\"}},\"issue_" + _type + "_audit\": { \"_parent\": {\"type\": \"issue_" + _type + "\"}},\"issue_" + _type + "_comment\": { \"_parent\": {\"type\": \"issue_" + _type + "\"}},\"issue_" + _type + "_exception\": { \"_parent\": {\"type\": \"issue_" + _type + "\"}}"); payLoad.append("}}"); try { invokeAPI("PUT", indexName, payLoad.toString()); } catch (IOException e) { LOGGER.error("Error in configureIndexAndTypes",e); Map<String,String> errorMap = new HashMap<>(); errorMap.put(ERROR, "Error in configureIndexAndTypes"); errorMap.put(ERROR_TYPE, WARN); errorMap.put(EXCEPTION, e.getMessage()); errorList.add(errorMap); } } try { invokeAPI("PUT", "/" + indexName + "/_alias/" + ds, null); invokeAPI("PUT", "/" + indexName + "/_alias/" + "ds-all", null); } catch (IOException e) { } } } }
ESManager implements Constants { public static void configureIndexAndTypes(String ds, List<Map<String, String>> errorList) { String _payLoad = "{\"settings\" : { \"number_of_shards\" : 3,\"number_of_replicas\" : 1 },\"mappings\": {"; Set<String> types = ConfigManager.getTypes(ds); Iterator<String> it = types.iterator(); while (it.hasNext()) { String _type = it.next(); String indexName = ds+ "_" + _type; if (!indexExists(indexName)) { StringBuilder payLoad = new StringBuilder(_payLoad); payLoad.append("\"" + _type + "\":{},\"issue_" + _type + "\": { \"_parent\": {\"type\": \"" + _type + "\"}},\"issue_" + _type + "_audit\": { \"_parent\": {\"type\": \"issue_" + _type + "\"}},\"issue_" + _type + "_comment\": { \"_parent\": {\"type\": \"issue_" + _type + "\"}},\"issue_" + _type + "_exception\": { \"_parent\": {\"type\": \"issue_" + _type + "\"}}"); payLoad.append("}}"); try { invokeAPI("PUT", indexName, payLoad.toString()); } catch (IOException e) { LOGGER.error("Error in configureIndexAndTypes",e); Map<String,String> errorMap = new HashMap<>(); errorMap.put(ERROR, "Error in configureIndexAndTypes"); errorMap.put(ERROR_TYPE, WARN); errorMap.put(EXCEPTION, e.getMessage()); errorList.add(errorMap); } } try { invokeAPI("PUT", "/" + indexName + "/_alias/" + ds, null); invokeAPI("PUT", "/" + indexName + "/_alias/" + "ds-all", null); } catch (IOException e) { } } }  }
ESManager implements Constants { public static void configureIndexAndTypes(String ds, List<Map<String, String>> errorList) { String _payLoad = "{\"settings\" : { \"number_of_shards\" : 3,\"number_of_replicas\" : 1 },\"mappings\": {"; Set<String> types = ConfigManager.getTypes(ds); Iterator<String> it = types.iterator(); while (it.hasNext()) { String _type = it.next(); String indexName = ds+ "_" + _type; if (!indexExists(indexName)) { StringBuilder payLoad = new StringBuilder(_payLoad); payLoad.append("\"" + _type + "\":{},\"issue_" + _type + "\": { \"_parent\": {\"type\": \"" + _type + "\"}},\"issue_" + _type + "_audit\": { \"_parent\": {\"type\": \"issue_" + _type + "\"}},\"issue_" + _type + "_comment\": { \"_parent\": {\"type\": \"issue_" + _type + "\"}},\"issue_" + _type + "_exception\": { \"_parent\": {\"type\": \"issue_" + _type + "\"}}"); payLoad.append("}}"); try { invokeAPI("PUT", indexName, payLoad.toString()); } catch (IOException e) { LOGGER.error("Error in configureIndexAndTypes",e); Map<String,String> errorMap = new HashMap<>(); errorMap.put(ERROR, "Error in configureIndexAndTypes"); errorMap.put(ERROR_TYPE, WARN); errorMap.put(EXCEPTION, e.getMessage()); errorList.add(errorMap); } } try { invokeAPI("PUT", "/" + indexName + "/_alias/" + ds, null); invokeAPI("PUT", "/" + indexName + "/_alias/" + "ds-all", null); } catch (IOException e) { } } }  static Map<String, Object> uploadData(String index, String type, List<Map<String, Object>> docs, String loaddate); static void refresh(String index); static void uploadData(String index, String type, List<Map<String, Object>> docs, String idKey,
            boolean refresh); static String createESDoc(Map<String, ?> doc); static Response invokeAPI(String method, String endpoint, String payLoad); static void configureIndexAndTypes(String ds, List<Map<String, String>> errorList); static Map<String, Map<String, String>> getExistingInfo(String indexName, String type,
            List<String> filters); @SuppressWarnings("unchecked") static Map<String, Map<String, Map<String, Object>>> fetchCurrentCountStatsForAssetGroups(String date); static void createIndex(String indexName, List<Map<String, String>> errorList); static void createType(String indexName, String typename, List<Map<String, String>> errorList); static void createType(String index, String type, String parent); static void uploadData(String index, String type, List<Map<String, Object>> docs, String[] parentKey); static void deleteOldDocuments(String index, String type, String field, String value); static long updateLoadDate(String index, String type, String accountId, String region, String loaddate,boolean checkLatest); }
ESManager implements Constants { public static void configureIndexAndTypes(String ds, List<Map<String, String>> errorList) { String _payLoad = "{\"settings\" : { \"number_of_shards\" : 3,\"number_of_replicas\" : 1 },\"mappings\": {"; Set<String> types = ConfigManager.getTypes(ds); Iterator<String> it = types.iterator(); while (it.hasNext()) { String _type = it.next(); String indexName = ds+ "_" + _type; if (!indexExists(indexName)) { StringBuilder payLoad = new StringBuilder(_payLoad); payLoad.append("\"" + _type + "\":{},\"issue_" + _type + "\": { \"_parent\": {\"type\": \"" + _type + "\"}},\"issue_" + _type + "_audit\": { \"_parent\": {\"type\": \"issue_" + _type + "\"}},\"issue_" + _type + "_comment\": { \"_parent\": {\"type\": \"issue_" + _type + "\"}},\"issue_" + _type + "_exception\": { \"_parent\": {\"type\": \"issue_" + _type + "\"}}"); payLoad.append("}}"); try { invokeAPI("PUT", indexName, payLoad.toString()); } catch (IOException e) { LOGGER.error("Error in configureIndexAndTypes",e); Map<String,String> errorMap = new HashMap<>(); errorMap.put(ERROR, "Error in configureIndexAndTypes"); errorMap.put(ERROR_TYPE, WARN); errorMap.put(EXCEPTION, e.getMessage()); errorList.add(errorMap); } } try { invokeAPI("PUT", "/" + indexName + "/_alias/" + ds, null); invokeAPI("PUT", "/" + indexName + "/_alias/" + "ds-all", null); } catch (IOException e) { } } }  static Map<String, Object> uploadData(String index, String type, List<Map<String, Object>> docs, String loaddate); static void refresh(String index); static void uploadData(String index, String type, List<Map<String, Object>> docs, String idKey,
            boolean refresh); static String createESDoc(Map<String, ?> doc); static Response invokeAPI(String method, String endpoint, String payLoad); static void configureIndexAndTypes(String ds, List<Map<String, String>> errorList); static Map<String, Map<String, String>> getExistingInfo(String indexName, String type,
            List<String> filters); @SuppressWarnings("unchecked") static Map<String, Map<String, Map<String, Object>>> fetchCurrentCountStatsForAssetGroups(String date); static void createIndex(String indexName, List<Map<String, String>> errorList); static void createType(String indexName, String typename, List<Map<String, String>> errorList); static void createType(String index, String type, String parent); static void uploadData(String index, String type, List<Map<String, Object>> docs, String[] parentKey); static void deleteOldDocuments(String index, String type, String field, String value); static long updateLoadDate(String index, String type, String accountId, String region, String loaddate,boolean checkLatest);  }