/** * Pretty printing JSON object into CLI String. * * @param data to be formatted * @return cli formatted string */ public String formatJson(Object data) { try { if (data instanceof ToString || data instanceof ToXMLString) { return data.toString(); } String json = mapper.writer(pp).writeValueAsString(data); JsonNode tree = mapper.valueToTree(data); System.out.println(tree); if (getClient().getConf().getBoolean(LensCliConfigConstants.PRINT_PRETTY_JSON, LensCliConfigConstants.DEFAULT_PRINT_PRETTY_JSON)) { return json; } return json.replaceAll("\\[ \\{", "\n\n ").replaceAll("\\{", "").replaceAll("}", "").replaceAll("\\[", "") .replaceAll("]", "\n").replaceAll(",", "").replaceAll("\"", "").replaceAll("\n\n", "\n"); } catch (IOException e) { throw new IllegalArgumentException(e); } }
/** * Pretty printing JSON object into CLI String. * * @param data to be formatted * @return cli formatted string */ public String formatJson(Object data) { try { if (data instanceof ToString || data instanceof ToXMLString) { return data.toString(); } String json = mapper.writer(pp).writeValueAsString(data); JsonNode tree = mapper.valueToTree(data); System.out.println(tree); if (getClient().getConf().getBoolean(LensCliConfigConstants.PRINT_PRETTY_JSON, LensCliConfigConstants.DEFAULT_PRINT_PRETTY_JSON)) { return json; } return json.replaceAll("\\[ \\{", "\n\n ").replaceAll("\\{", "").replaceAll("}", "").replaceAll("\\[", "") .replaceAll("]", "\n").replaceAll(",", "").replaceAll("\"", "").replaceAll("\n\n", "\n"); } catch (IOException e) { throw new IllegalArgumentException(e); } }
/** * Sets the param. * * @param keyval the keyval * @return the string */ @CliCommand(value = "set", help = "Assign <value> to session parameter specified with <key> on lens server") public String setParam(@CliOption(key = {""}, mandatory = true, help = "<key>=<value>") String keyval) { String[] pair = keyval.split("="); if (pair.length != 2) { return "Error: Pass parameter as <key>=<value>"; } if (pair[0].startsWith(LensCliConfigConstants.LENS_CLI_PREFIX) || pair[0].startsWith(LensClientConfig.CLIENT_PFX)) { getClient().getConf().set(pair[0], pair[1]); return "Client side Set " + pair[0] + "=" + pair[1]; } else { APIResult result = getClient().setConnectionParam(pair[0], pair[1]); return result.getMessage(); } }
/** * Sets the param. * * @param keyval the keyval * @return the string */ @CliCommand(value = "set", help = "Assign <value> to session parameter specified with <key> on lens server") public String setParam(@CliOption(key = {""}, mandatory = true, help = "<key>=<value>") String keyval) { String[] pair = keyval.split("="); if (pair.length != 2) { return "Error: Pass parameter as <key>=<value>"; } if (pair[0].startsWith(LensCliConfigConstants.LENS_CLI_PREFIX) || pair[0].startsWith(LensClientConfig.CLIENT_PFX)) { getClient().getConf().set(pair[0], pair[1]); return "Client side Set " + pair[0] + "=" + pair[1]; } else { APIResult result = getClient().setConnectionParam(pair[0], pair[1]); return result.getMessage(); } }
client1.setConnectionParam("lens.query.enable.persistent.resultset", "false"); client1.setConnectionParam("lens.query.enable.metrics.per.query", "true"); client1.getConf().setLong(LensCliConfigConstants.QUERY_EXECUTE_TIMEOUT_MILLIS, 100); LensQueryCommands qCom1 = new LensQueryCommands(); qCom1.setClient(client1); client2.setConnectionParam("lens.query.enable.persistent.resultset.indriver", "false"); client2.setConnectionParam("lens.query.enable.persistent.resultset", "true"); client2.getConf().setLong(LensCliConfigConstants.QUERY_EXECUTE_TIMEOUT_MILLIS, 20000); LensQueryCommands qCom2 = new LensQueryCommands(); qCom2.setClient(client2); DeferredInMemoryResultFormatter.class.getName()); client3.setConnectionParam("deferPersistenceByMillis", "5000"); // property used for test only client3.getConf().setLong(LensCliConfigConstants.QUERY_EXECUTE_TIMEOUT_MILLIS, 20000); LensQueryCommands qCom3 = new LensQueryCommands(); qCom3.setClient(client3);
} else { LensClientResultSetWithStats resultWithStats; long timeOutMillis = getClient().getConf().getLong(LensCliConfigConstants.QUERY_EXECUTE_TIMEOUT_MILLIS, LensCliConfigConstants.DEFAULT_QUERY_EXECUTE_TIMEOUT_MILLIS); LensClient.getCliLogger().info("Executing query with timeout of {} milliseconds", timeOutMillis);
} else { LensClientResultSetWithStats resultWithStats; long timeOutMillis = getClient().getConf().getLong(LensCliConfigConstants.QUERY_EXECUTE_TIMEOUT_MILLIS, LensCliConfigConstants.DEFAULT_QUERY_EXECUTE_TIMEOUT_MILLIS); LensClient.getCliLogger().info("Executing query with timeout of {} milliseconds", timeOutMillis);