@Test public void testIndex() { InterpreterResult res = interpreter.interpret("index /logs { \"date\": \"" + new Date() + "\", \"method\": \"PUT\", \"status\": \"500\" }", null); assertEquals(Code.ERROR, res.code()); res = interpreter.interpret("index /logs/http { \"date\": \"2015-12-06T14:54:23.368Z\", \"method\": \"PUT\", \"status\": \"500\" }", null); assertEquals(Code.SUCCESS, res.code()); }
@Override public InterpreterResult interpret(String cmd, InterpreterContext interpreterContext) { logger.info("Run Elasticsearch command '" + cmd + "'"); int currentResultSize = resultSize; if (client == null) { return new InterpreterResult(InterpreterResult.Code.ERROR, "Problem with the Elasticsearch client, please check your configuration (host, port,...)"); } String[] items = StringUtils.split(cmd.trim(), " ", 3); if ("help".equalsIgnoreCase(items[0])) { return processHelp(InterpreterResult.Code.SUCCESS, null); } if ("size".equalsIgnoreCase(items[0])) { final String[] lines = StringUtils.split(cmd.trim(), "\n", 2); if (lines.length < 2) { return processHelp(InterpreterResult.Code.ERROR, "Size cmd must be followed by a search"); } final String[] sizeLine = StringUtils.split(lines[0], " ", 2); if (sizeLine.length != 2) { return processHelp(InterpreterResult.Code.ERROR, "Right format is : size <value>"); } currentResultSize = Integer.parseInt(sizeLine[1]); items = StringUtils.split(lines[1].trim(), " ", 3); } if (items.length < 2) { return processHelp(InterpreterResult.Code.ERROR, "Arguments missing"); } final String method = items[0]; final String url = items[1]; final String data = items.length > 2 ? items[2].trim() : null; final String[] urlItems = StringUtils.split(url.trim(), "/"); try { if ("get".equalsIgnoreCase(method)) { return processGet(urlItems); } else if ("count".equalsIgnoreCase(method)) { return processCount(urlItems, data); } else if ("search".equalsIgnoreCase(method)) { return processSearch(urlItems, data, currentResultSize); } else if ("index".equalsIgnoreCase(method)) { return processIndex(urlItems, data); } else if ("delete".equalsIgnoreCase(method)) { return processDelete(urlItems); } return processHelp(InterpreterResult.Code.ERROR, "Unknown command"); } catch (Exception e) { return new InterpreterResult(InterpreterResult.Code.ERROR, "Error : " + e.getMessage()); } }
ElasticsearchInterpreter extends Interpreter { @Override public InterpreterResult interpret(String cmd, InterpreterContext interpreterContext) { logger.info("Run Elasticsearch command '" + cmd + "'"); int currentResultSize = resultSize; if (client == null) { return new InterpreterResult(InterpreterResult.Code.ERROR, "Problem with the Elasticsearch client, please check your configuration (host, port,...)"); } String[] items = StringUtils.split(cmd.trim(), " ", 3); if ("help".equalsIgnoreCase(items[0])) { return processHelp(InterpreterResult.Code.SUCCESS, null); } if ("size".equalsIgnoreCase(items[0])) { final String[] lines = StringUtils.split(cmd.trim(), "\n", 2); if (lines.length < 2) { return processHelp(InterpreterResult.Code.ERROR, "Size cmd must be followed by a search"); } final String[] sizeLine = StringUtils.split(lines[0], " ", 2); if (sizeLine.length != 2) { return processHelp(InterpreterResult.Code.ERROR, "Right format is : size <value>"); } currentResultSize = Integer.parseInt(sizeLine[1]); items = StringUtils.split(lines[1].trim(), " ", 3); } if (items.length < 2) { return processHelp(InterpreterResult.Code.ERROR, "Arguments missing"); } final String method = items[0]; final String url = items[1]; final String data = items.length > 2 ? items[2].trim() : null; final String[] urlItems = StringUtils.split(url.trim(), "/"); try { if ("get".equalsIgnoreCase(method)) { return processGet(urlItems); } else if ("count".equalsIgnoreCase(method)) { return processCount(urlItems, data); } else if ("search".equalsIgnoreCase(method)) { return processSearch(urlItems, data, currentResultSize); } else if ("index".equalsIgnoreCase(method)) { return processIndex(urlItems, data); } else if ("delete".equalsIgnoreCase(method)) { return processDelete(urlItems); } return processHelp(InterpreterResult.Code.ERROR, "Unknown command"); } catch (Exception e) { return new InterpreterResult(InterpreterResult.Code.ERROR, "Error : " + e.getMessage()); } } }
ElasticsearchInterpreter extends Interpreter { @Override public InterpreterResult interpret(String cmd, InterpreterContext interpreterContext) { logger.info("Run Elasticsearch command '" + cmd + "'"); int currentResultSize = resultSize; if (client == null) { return new InterpreterResult(InterpreterResult.Code.ERROR, "Problem with the Elasticsearch client, please check your configuration (host, port,...)"); } String[] items = StringUtils.split(cmd.trim(), " ", 3); if ("help".equalsIgnoreCase(items[0])) { return processHelp(InterpreterResult.Code.SUCCESS, null); } if ("size".equalsIgnoreCase(items[0])) { final String[] lines = StringUtils.split(cmd.trim(), "\n", 2); if (lines.length < 2) { return processHelp(InterpreterResult.Code.ERROR, "Size cmd must be followed by a search"); } final String[] sizeLine = StringUtils.split(lines[0], " ", 2); if (sizeLine.length != 2) { return processHelp(InterpreterResult.Code.ERROR, "Right format is : size <value>"); } currentResultSize = Integer.parseInt(sizeLine[1]); items = StringUtils.split(lines[1].trim(), " ", 3); } if (items.length < 2) { return processHelp(InterpreterResult.Code.ERROR, "Arguments missing"); } final String method = items[0]; final String url = items[1]; final String data = items.length > 2 ? items[2].trim() : null; final String[] urlItems = StringUtils.split(url.trim(), "/"); try { if ("get".equalsIgnoreCase(method)) { return processGet(urlItems); } else if ("count".equalsIgnoreCase(method)) { return processCount(urlItems, data); } else if ("search".equalsIgnoreCase(method)) { return processSearch(urlItems, data, currentResultSize); } else if ("index".equalsIgnoreCase(method)) { return processIndex(urlItems, data); } else if ("delete".equalsIgnoreCase(method)) { return processDelete(urlItems); } return processHelp(InterpreterResult.Code.ERROR, "Unknown command"); } catch (Exception e) { return new InterpreterResult(InterpreterResult.Code.ERROR, "Error : " + e.getMessage()); } } ElasticsearchInterpreter(Properties property); }
ElasticsearchInterpreter extends Interpreter { @Override public InterpreterResult interpret(String cmd, InterpreterContext interpreterContext) { logger.info("Run Elasticsearch command '" + cmd + "'"); int currentResultSize = resultSize; if (client == null) { return new InterpreterResult(InterpreterResult.Code.ERROR, "Problem with the Elasticsearch client, please check your configuration (host, port,...)"); } String[] items = StringUtils.split(cmd.trim(), " ", 3); if ("help".equalsIgnoreCase(items[0])) { return processHelp(InterpreterResult.Code.SUCCESS, null); } if ("size".equalsIgnoreCase(items[0])) { final String[] lines = StringUtils.split(cmd.trim(), "\n", 2); if (lines.length < 2) { return processHelp(InterpreterResult.Code.ERROR, "Size cmd must be followed by a search"); } final String[] sizeLine = StringUtils.split(lines[0], " ", 2); if (sizeLine.length != 2) { return processHelp(InterpreterResult.Code.ERROR, "Right format is : size <value>"); } currentResultSize = Integer.parseInt(sizeLine[1]); items = StringUtils.split(lines[1].trim(), " ", 3); } if (items.length < 2) { return processHelp(InterpreterResult.Code.ERROR, "Arguments missing"); } final String method = items[0]; final String url = items[1]; final String data = items.length > 2 ? items[2].trim() : null; final String[] urlItems = StringUtils.split(url.trim(), "/"); try { if ("get".equalsIgnoreCase(method)) { return processGet(urlItems); } else if ("count".equalsIgnoreCase(method)) { return processCount(urlItems, data); } else if ("search".equalsIgnoreCase(method)) { return processSearch(urlItems, data, currentResultSize); } else if ("index".equalsIgnoreCase(method)) { return processIndex(urlItems, data); } else if ("delete".equalsIgnoreCase(method)) { return processDelete(urlItems); } return processHelp(InterpreterResult.Code.ERROR, "Unknown command"); } catch (Exception e) { return new InterpreterResult(InterpreterResult.Code.ERROR, "Error : " + e.getMessage()); } } ElasticsearchInterpreter(Properties property); @Override void open(); @Override void close(); @Override InterpreterResult interpret(String cmd, InterpreterContext interpreterContext); @Override void cancel(InterpreterContext interpreterContext); @Override FormType getFormType(); @Override int getProgress(InterpreterContext interpreterContext); @Override List<String> completion(String s, int i); }
ElasticsearchInterpreter extends Interpreter { @Override public InterpreterResult interpret(String cmd, InterpreterContext interpreterContext) { logger.info("Run Elasticsearch command '" + cmd + "'"); int currentResultSize = resultSize; if (client == null) { return new InterpreterResult(InterpreterResult.Code.ERROR, "Problem with the Elasticsearch client, please check your configuration (host, port,...)"); } String[] items = StringUtils.split(cmd.trim(), " ", 3); if ("help".equalsIgnoreCase(items[0])) { return processHelp(InterpreterResult.Code.SUCCESS, null); } if ("size".equalsIgnoreCase(items[0])) { final String[] lines = StringUtils.split(cmd.trim(), "\n", 2); if (lines.length < 2) { return processHelp(InterpreterResult.Code.ERROR, "Size cmd must be followed by a search"); } final String[] sizeLine = StringUtils.split(lines[0], " ", 2); if (sizeLine.length != 2) { return processHelp(InterpreterResult.Code.ERROR, "Right format is : size <value>"); } currentResultSize = Integer.parseInt(sizeLine[1]); items = StringUtils.split(lines[1].trim(), " ", 3); } if (items.length < 2) { return processHelp(InterpreterResult.Code.ERROR, "Arguments missing"); } final String method = items[0]; final String url = items[1]; final String data = items.length > 2 ? items[2].trim() : null; final String[] urlItems = StringUtils.split(url.trim(), "/"); try { if ("get".equalsIgnoreCase(method)) { return processGet(urlItems); } else if ("count".equalsIgnoreCase(method)) { return processCount(urlItems, data); } else if ("search".equalsIgnoreCase(method)) { return processSearch(urlItems, data, currentResultSize); } else if ("index".equalsIgnoreCase(method)) { return processIndex(urlItems, data); } else if ("delete".equalsIgnoreCase(method)) { return processDelete(urlItems); } return processHelp(InterpreterResult.Code.ERROR, "Unknown command"); } catch (Exception e) { return new InterpreterResult(InterpreterResult.Code.ERROR, "Error : " + e.getMessage()); } } ElasticsearchInterpreter(Properties property); @Override void open(); @Override void close(); @Override InterpreterResult interpret(String cmd, InterpreterContext interpreterContext); @Override void cancel(InterpreterContext interpreterContext); @Override FormType getFormType(); @Override int getProgress(InterpreterContext interpreterContext); @Override List<String> completion(String s, int i); static final String ELASTICSEARCH_HOST; static final String ELASTICSEARCH_PORT; static final String ELASTICSEARCH_CLUSTER_NAME; static final String ELASTICSEARCH_RESULT_SIZE; }